Blue pill and CANbus

Post here first, or if you can't find a relevant section!
stefan
Posts: 7
Joined: Wed Feb 02, 2022 12:31 am

Re: Blue pill and CANbus

Post by stefan »

Thanks for this clue.
I found the way to disable usb clock, so i dont have to care about disabling CDC and serial in settings in matter to have working CAN anymore...

Code: Select all

 void InhibitUSB ( void ){
  *((uint32_t*)0x40005c40) = 3 ;    // USB_CNTR
  *((uint32_t*)0x40005c44) = 0 ;    // USB_ISTR
  
  __HAL_RCC_USB_CLK_DISABLE();
}
i can go with this now...
One more question about this low level can example, it is working fine with STM32 official core, but when i try to switch to "Roger's" it doesnt compile, because there is no CAN1 defined in definition files. Is it possible to run this on Roger's with some mod to core or to code ? I have adafruit_dotstar library, which is only running on Roger's core, and i need these 2 things (CAN and Dotstar-APA102), on same core compiled.
Best regards
djix123
Posts: 8
Joined: Mon Oct 25, 2021 11:34 pm

Re: Blue pill and CANbus

Post by djix123 »

Does disabling the USB peripheral in the Arduino menu system achieve the same result, rather than having to write a function to do it? Maybe you tried that and it didn't work.

I've not used Roger's core, so can't comment on the difference, but have 'ported' various Adafruit libraries for use with other platforms (e.g. STM HAL, GD SPL etc ...). Taking a quick look at the GitHub version of Adafruit_DotStar, it looks like it uses Adafruit's helper class Adadfruit_SPIDevice for communication. This is a thin(ish) wrapper over the core SPI library. If this is the issue, either replace the helper class calls in the library itself, or create a new version of the helper class with appropriate SPI calls.

Apologies, if this is not the issue - including the compile errors would help with diagnosis.
stefan
Posts: 7
Joined: Wed Feb 02, 2022 12:31 am

Re: Blue pill and CANbus

Post by stefan »

Yes, disabling peripherals done the same.
Regarding LED library (adafruit_dotstar) it compiles with STM32 and Roger's core successfully, but it runs output only in Roger's, on official core compiler output is not flat-lined. I could use FastLed as well instead for my project, but it doesn't compile on official core. There is a ton of same problem with this library for STM32 mcu, i seem to try everything with no success. I have used fastled with STM32 few years ago with no problem, even with hw spi output, but i didn't know then that i should backup everything for the future problems, it seems straightforward then.
Do you have some solution for FastLed and official core?
stefan
Posts: 7
Joined: Wed Feb 02, 2022 12:31 am

Re: Blue pill and CANbus

Post by stefan »

djix123 wrote: Thu Feb 03, 2022 1:21 pm Apologies, if this is not the issue - including the compile errors would help with diagnosis.

This is compile error for FastLed example with official core in attachment :
Attachments
fastled compile error stm32.zip
i had to include txt file for error output, because it is too large
(17.34 KiB) Downloaded 262 times
djix123
Posts: 8
Joined: Mon Oct 25, 2021 11:34 pm

Re: Blue pill and CANbus

Post by djix123 »

I would be inclined to stick with the Adafruit Dotstar library since it compiles with no errors. That fact that it works with Roger's core makes me think there is some configuration issue that prevents it working with the 'official' core.

Which pins are you using for SPI? The official core allows you to configure the pins (for a hardware SPI peripheral) directly - assuming you're not using the default pins e.g.:

Code: Select all

SPI.setMOSI( PA7 );
SPI.setMISO( PA6 );
SPI.setSCLK( PA5 );
SPI.begin()
You could try this before initializing the DotStar library.

Alternatively, the DotStar library allows using generic pins for communication - by specifying them in the constructor - so you could also try that, by connecting the DotStars to other pins and reconfiguring the library.
stefan
Posts: 7
Joined: Wed Feb 02, 2022 12:31 am

Re: Blue pill and CANbus

Post by stefan »

Hello,
Does anyone had problem with receiving CAN message to STM32F1.
I have multiple devices on bus, some of them are ESP32(receiving and sending is working), STM32F1(only sending packet is working).
CDC is disabled. Core that I am using has added changes to support HardwareCAN library, just to say again, sending part is working with same init.
https://github.com/coddingtonbear/Ardui ... ardwareCAN
I am missing some important. IRQ or POLL mode maybe? Sending standard format ID.
Here is receiving code for stm:

Code: Select all

#include <HardwareCAN.h>
//#include "Changes.h"

HardwareCAN canBus(CAN1_BASE);
//CanMsg msg ;

void CANSetup(void)
{
  CAN_STATUS Stat ;

  // Initialize CAN module
canBus.map(CAN_GPIO_PA11_PA12);       // PA11-CRX/ PA12-CTX  
Stat = canBus.begin(CAN_SPEED_500, CAN_MODE_NORMAL ); 

canBus.filter(0, 0, 0);
canBus.set_irq_mode();              // Use irq mode (recommended), so the handling of incoming messages
                                      // will be performed at ease in a task or in the loop. The software fifo is 16 cells long, 
                                      // allowing at least 15 ms before processing the fifo is needed at 125 kbps
  Stat = canBus.status();
  if (Stat != CAN_OK) {
     /* Your own error processing here */ ;   // Initialization failed
  }
}



// Process incoming messages
// Note : frames are not fully checked for correctness: DLC value is not checked, neither are the IDE and RTR fields. However, the data is guaranteed to be corrrect.
void ProcessMessages(void)
{
CanMsg *r_msg;
if ((r_msg = canBus.recv()) != NULL){

  Serial2.print(r_msg->ID);
  Serial2.print("#");
  Serial2.print(r_msg->Data[0]);
  Serial2.print(".");
  Serial2.print(r_msg->Data[1]);
  Serial2.print(".");
  Serial2.print(r_msg->Data[2]);
  Serial2.print(".");
  Serial2.print(r_msg->Data[3]);
  Serial2.print(".");
  Serial2.print(r_msg->Data[4]);
  Serial2.print(".");
  Serial2.print(r_msg->Data[5]);
  Serial2.print(".");
  Serial2.print(r_msg->Data[6]);
  Serial2.print(".");
  Serial2.println(r_msg->Data[7]); 
  
 canBus.free();                          // Remove processed message from buffer, whatever the identifier
}  
}

// The application program starts here
void setup() {
*((uint32_t*)0x40005c40) = 3 ;    // USB_CNTR
*((uint32_t*)0x40005c44) = 0 ;    // USB_ISTR

CANSetup() ;        // Initialize the CAN module and prepare the message structures.

Serial2.begin(115200); //PA9 UART1 RX   //PA10 UART1 TX
Serial2.println("Serial2"); 
}

void loop() {
  ProcessMessages() ;          // Process all incoming messages, update local variables accordingly

 delay(20) ;    // The delay must not be greater than the time to overflow the incoming fifo (here about 15 ms)
}
BR,
Stefan
mack
Posts: 8
Joined: Sat Feb 08, 2020 2:33 am

Re: Blue pill and CANbus

Post by mack »

I've used the ExoCan library and it works pretty well for F103 bluepills. (and allows for alternate pins)

I extended and modified this library to suit F105/107 dual CAN ports.
https://github.com/mackelec/meCAN

I've got it working on L452 and when I can get chips again I'll get it going on F4 types and trio CAN on F413

I'd like to see the library re-done one day using stm HAL libraries.
User avatar
konczakp
Posts: 18
Joined: Sat Jul 25, 2020 8:22 pm

Re: Blue pill and CANbus

Post by konczakp »

@mack Hi, Did You managed to get the CAN BUS working on F413? I'm trying to set it up using Your library but when starting the can1 it freezes. Will You be able to help me to get this running? Before I saw this thread I started a new one dedicated to can bus and stm32f413 here : viewtopic.php?t=1747 If You could help with this please respond in the new thread. Thanks
mack
Posts: 8
Joined: Sat Feb 08, 2020 2:33 am

Re: Blue pill and CANbus

Post by mack »

Yes I did get the CAN bus going on the F413
Post Reply

Return to “General discussion”