cancel
Showing results for 
Search instead for 
Did you mean: 

how to use CAN with CubeMX and STM32F1 / F4, UM1850 and other HAL+LL drivers documentation not up to date with new CAN Library since fall 2017

Hi everyone,

I want to use CAN with my STM32F103CB and STM32F429ZIT, but the CAN TX and RX Pins do not do anything on both boards. I am using CubeMX 5.3 and F1 Lib 1.8.0 / F4 Lib 1.24.1

From the CubeMX CAN example project for the STM32446E_Eval board I learned how to use the new CAN library:

  1. CAN_Init() ( done by CubeMX )
  2. CAN_ConfigFilter()
  3. CAN_Start()
  4. gather CAN header and CAN data
  5. CAN_AddTXMessage() - send CAN message
  6. CAN_GetTXMailboxesFreeLevel() - poll for send complete
  7. CAN_GetRXFifoFillLevel() - poll for incoming message
  8. CAN_GetRxMessage() - get incoming message

No matter what board ( F1 or F4) the RX and TX Pins of the uC are inactive. TX is low and RX is high. Can you provide me a up to date HAL+LL drivers documentation to learn how to use CAN correctly or am I just missing a step during initialisation of the CAN bus with CubeMX ?

Best regards,

Markus.

2 REPLIES 2
JoniS
Senior

Do you have can tranceivers connected? I believe you need to pull up the can rx/tx pins(internal pullups is fine) if not, since the tranceiver would drive those gpio pins if it was connected.

Other than that the STM32446E_Eval example code should be functional.

Got it working, took me 4 days of try and error by guessing how ST has intended to use the CAN Lib. Would be less of a pain in the *** with a proper documentation. I can not understand why the HAL API documentation is not updated 2 years after a major change. The example project of the STM32446E_Eval board was useful. It was also the template for the hardware design which is very simple ( just a MCP2562 and a 120Ohms resistor do the trick for the STM32F103CB). My Logic analyzer was very helpful to determine the right baud rate settings. The STM32F103CB is now underclocked to 40 MHz to get the best results @1Mbit, i do not want to overclock to 80MHz, calculating performance is not critical in my case ( just transmitting low sample rate sensor data). Nevertheless 80MHz works in Lab conditions, checked with a spectrum analyzer that the uC is running @80MHz despite CubeMX warnings in the clock tree settings. Now I will switch from polling to IRQ driven CAN communication.

Best regards,

Markus.