cancel
Showing results for 
Search instead for 
Did you mean: 

stm32f0xx_hal_can.h bug found, please fix it

RamiroGJ
Associate II
Hello friends,
 
I have been seeing the same bug in stm32f0xx_hal_can.h for some time, whenever I start a new project I correct it, but I would like you to leave it corrected to avoid correcting it each time I start a new project.
The bug prevents to send an address in extended format.
On line 1250, in the function:

 

HAL_StatusTypeDef HAL_CAN_AddTxMessage(CAN_HandleTypeDef *hcan, const CAN_TxHeaderTypeDef *pHeader, const uint8_t aData[], uint32_t *pTxMailbox)

 

replace the following line:

 

hcan->Instance->sTxMailBox[transmitmailbox].TIR = ((pHeader->ExtId << CAN_TI0R_EXID_Pos) | pHeader->IDE | pHeader->RTR);

 

by the following:

 

hcan->Instance->sTxMailBox[transmitmailbox].TIR = ((pHeader->ExtId << CAN_TI0R_EXID_Pos)|(pHeader->IDE<<<2)|pHeader->RTR);

 

1 ACCEPTED SOLUTION

Accepted Solutions
TDK
Guru

Lets look at the IDE parameter in HAL:

  uint32_t IDE;      /*!< Specifies the type of identifier for the message that will be transmitted.
                          This parameter can be a value of @ref CAN_identifier_type */

 Okay, so let's look at the CAN_identifier_type values:

/** @defgroup CAN_identifier_type CAN Identifier Type
  * @{
  */
#define CAN_ID_STD                  (0x00000000U)  /*!< Standard Id */
#define CAN_ID_EXT                  (0x00000004U)  /*!< Extended Id */

 So those are 0 or 4, which already accounts for the bit shift of 2.

No HAL bug here.

If you feel a post has answered your question, please click "Accept as Solution".

View solution in original post

2 REPLIES 2
TDK
Guru

Lets look at the IDE parameter in HAL:

  uint32_t IDE;      /*!< Specifies the type of identifier for the message that will be transmitted.
                          This parameter can be a value of @ref CAN_identifier_type */

 Okay, so let's look at the CAN_identifier_type values:

/** @defgroup CAN_identifier_type CAN Identifier Type
  * @{
  */
#define CAN_ID_STD                  (0x00000000U)  /*!< Standard Id */
#define CAN_ID_EXT                  (0x00000004U)  /*!< Extended Id */

 So those are 0 or 4, which already accounts for the bit shift of 2.

No HAL bug here.

If you feel a post has answered your question, please click "Accept as Solution".

Ok, thanks, I've been wrong all this time thinking that parameter was set to "1" and this wasn't working for me.
Sometimes the way is simpler than it seems :rolling_on_the_floor_laughing: