cancel
Showing results for 
Search instead for 
Did you mean: 

HAL_CAN_Init() returns error after firmware migration from V1.8.0 to V1.8.4 on STM32F103C8T6

JSchu.2
Associate

Hi,

i had a working STM32F1 (BluePill) CAN-Node with Cube firmware V1.8.0 before STMCube suggested me to automatically migrate the firmware to the latest V1.8.4.

Now HAL_CAN_Init() returns with an error which is caused by this code part within the Cube generated init function:

 /* Wait initialisation acknowledge */

 while ((hcan->Instance->MSR & CAN_MSR_INAK) == 0U)

 {

   if ((HAL_GetTick() - tickstart) > CAN_TIMEOUT_VALUE)

   {

     /* Update error code */

     hcan->ErrorCode |= HAL_CAN_ERROR_TIMEOUT;

     /* Change CAN state */

     hcan->State = HAL_CAN_STATE_ERROR;

     return HAL_ERROR;

   }

 }

obviously the "CAN_MSR_INAK" -bit in the MSR-register does not get set.

While testing the MCU is connected via TJA1050 tranceiver to a working can network.

Does anyone else encounter this problem ?

1 REPLY 1
CCatt.2
Associate II

Modifying the code in this way seems to be working:

 /* Request initialisation */

 SET_BIT(hcan->Instance->MCR, CAN_MCR_INRQ);

 /* Exit from sleep mode */

 CLEAR_BIT(hcan->Instance->MCR, CAN_MCR_SLEEP);

 /* Get tick */

 tickstart = HAL_GetTick();

 /* Wait initialisation acknowledge */

 while ((hcan->Instance->MSR & CAN_MSR_INAK) == 0U)

 {

   if ((HAL_GetTick() - tickstart) > CAN_TIMEOUT_VALUE)

   {

     /* Update error code */

     hcan->ErrorCode |= HAL_CAN_ERROR_TIMEOUT;

     /* Change CAN state */

     hcan->State = HAL_CAN_STATE_ERROR;

     return HAL_ERROR;

   }

 }

 /* Exit from sleep mode */

 //CLEAR_BIT(hcan->Instance->MCR, CAN_MCR_SLEEP); COMMENTED OUT

 /* Get tick */

 tickstart = HAL_GetTick();

 /* Check Sleep mode leave acknowledge */

 while ((hcan->Instance->MSR & CAN_MSR_SLAK) != 0U)

Nevertheless, if you look into 1.8.3 the two sections of code (i.e. "Exit from sleep mode" and "Request initialization") are reversed - with "Exit from sleep mode" being put first and only after "Request initialization" comes.