cancel
Showing results for 
Search instead for 
Did you mean: 

stm32f0xx_hal_can.c HAL CAN driver bug.

Beppo7
Associate

I use hal can modul for STM32F091 MCU. The generated code in the function HAL_CAN_Init (HAL_StatusTypeDef HAL_CAN_Init(CAN_HandleTypeDef *hcan)) try to wake up CAN module from sleep to initialize mode by CLEAR_BIT(hcan->Instance->MCR, CAN_MCR_SLEEP). This results a HAL_CAN_ERROR_TIMEOUT because first another bit should be set: SET_BIT(hcan->Instance->MCR, CAN_MCR_INRQ); By this way the experimented timeout doesn't occur. See: RM0091 A.11.1 bxCAN initialization mode code example

3 REPLIES 3
Bouraoui Chemli
ST Employee

Hi @Beppo7​ 

I catch your request. We will investigate this internally and I come back to you as soon as possible.

Bouraoui

Hi Bouraoui,
The mistery has solved. ☺
Can Rx pullup resistor was missing. (It was on another can location ☹ )
The phenomenon is real. If I set INRQ first then reset SLEEP bit the statemachine go from sleep to initialize in case of missing Rx pullup. Initialize to normal state change was failed (it’s timed out). When I pulled up Rx then sleep to initialize state change was independent of order of reset SLEEP/ set INRQ.
Regards,
Tibor

Hi @Beppo7​ 

Thank you for your feedback.

CAN Rx pin must be configured as pullup to ensure CAN Idle bus at high level. As developed in CAN example available in STM32CubeF0 firmware via this path STM32Cube_FW_F0_V1.11.0\Projects\STM32072B_EVAL\Examples\CAN

Bouraoui