Skip to main content
Visitor II
June 27, 2024
Solved

FDCAN2 Rx callback never called (STM32H750)

  • June 27, 2024
  • 1 reply
  • 1566 views

Hello,

On my project, I use FDCAN1 and FDCAN2. FDCAN1 is working perfectly fine.

On FDCAN2, I can transmit data successfully (with the CAN ID 0xBEEF), but when I want do receive data, the Rx callback is never called, nor the IRQ handler (the CAN ID filter is set to 0xDEAD).

CAN ID is configured as extended ID mode.

Here's my FDCAN2 init function:

static void MX_FDCAN2_Init(void)
{

 /* USER CODE BEGIN FDCAN2_Init 0 */

 /* USER CODE END FDCAN2_Init 0 */

 /* USER CODE BEGIN FDCAN2_Init 1 */

 /* USER CODE END FDCAN2_Init 1 */
 hfdcan2.Instance = FDCAN2;
 hfdcan2.Init.FrameFormat = FDCAN_FRAME_CLASSIC;
 hfdcan2.Init.Mode = FDCAN_MODE_NORMAL;
 hfdcan2.Init.AutoRetransmission = ENABLE;
 hfdcan2.Init.TransmitPause = ENABLE;
 hfdcan2.Init.ProtocolException = ENABLE;
 hfdcan2.Init.NominalPrescaler = 32;
 hfdcan2.Init.NominalSyncJumpWidth = 2;
 hfdcan2.Init.NominalTimeSeg1 = 2;
 hfdcan2.Init.NominalTimeSeg2 = 2;
 hfdcan2.Init.DataPrescaler = 1;
 hfdcan2.Init.DataSyncJumpWidth = 12;
 hfdcan2.Init.DataTimeSeg1 = 12;
 hfdcan2.Init.DataTimeSeg2 = 12;
 hfdcan2.Init.MessageRAMOffset = 0;
 hfdcan2.Init.StdFiltersNbr = 0;
 hfdcan2.Init.ExtFiltersNbr = 1;
 hfdcan2.Init.RxFifo0ElmtsNbr = 1;
 hfdcan2.Init.RxFifo0ElmtSize = FDCAN_DATA_BYTES_8;
 hfdcan2.Init.RxFifo1ElmtsNbr = 1;
 hfdcan2.Init.RxFifo1ElmtSize = FDCAN_DATA_BYTES_8;
 hfdcan2.Init.RxBuffersNbr = 1;
 hfdcan2.Init.RxBufferSize = FDCAN_DATA_BYTES_8;
 hfdcan2.Init.TxEventsNbr = 0;
 hfdcan2.Init.TxBuffersNbr = 0;
 hfdcan2.Init.TxFifoQueueElmtsNbr = 1;
 hfdcan2.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION;
 hfdcan2.Init.TxElmtSize = FDCAN_DATA_BYTES_8;
 if (HAL_FDCAN_Init(&hfdcan2) != HAL_OK)
 {
 Error_Handler();
 }
 /* USER CODE BEGIN FDCAN2_Init 2 */
 
 //Rx filter config
 FDCAN_FilterTypeDef sFilterConfig;
 sFilterConfig.IdType = FDCAN_EXTENDED_ID;
 sFilterConfig.FilterIndex = 0;
 sFilterConfig.FilterType = FDCAN_FILTER_RANGE;
 sFilterConfig.FilterConfig = FDCAN_FILTER_TO_RXFIFO1;
 sFilterConfig.FilterID1 = 0xDEAD;
 sFilterConfig.FilterID2 = 0xDEAD;
 
 //Tx header config
 TxHeader2.Identifier = 0xBEEF;
 TxHeader2.IdType = FDCAN_EXTENDED_ID;
 TxHeader2.TxFrameType = FDCAN_DATA_FRAME;
 TxHeader2.DataLength = FDCAN_DLC_BYTES_8;
 TxHeader2.ErrorStateIndicator = FDCAN_ESI_ACTIVE;
 TxHeader2.BitRateSwitch = FDCAN_BRS_OFF;
 TxHeader2.FDFormat = FDCAN_CLASSIC_CAN;
 TxHeader2.TxEventFifoControl = FDCAN_NO_TX_EVENTS;
 TxHeader2.MessageMarker = 0;
 
 //Config filter
 if(HAL_FDCAN_ConfigFilter(&hfdcan2, &sFilterConfig) != HAL_OK)
 {
 Error_Handler();
 }
 
 //Config global filter
 if(HAL_FDCAN_ConfigGlobalFilter(&hfdcan2, FDCAN_REJECT, FDCAN_REJECT, FDCAN_FILTER_REMOTE, FDCAN_FILTER_REMOTE) != HAL_OK)
 {
 Error_Handler();
 }
 
 //Start CAN
 if(HAL_FDCAN_Start(&hfdcan2) != HAL_OK)
 {
 Error_Handler();
 }
 
 //Activate CAN notifications
 if(HAL_FDCAN_ActivateNotification(&hfdcan2, FDCAN_IT_RX_FIFO1_NEW_MESSAGE, 0) != HAL_OK)
 {
 Error_Handler();
 }

 /* USER CODE END FDCAN2_Init 2 */

}

 Here's my Rx callback function that is never called :

//FDCAN Rx callback
void HAL_FDCAN_RxFifo1Callback(FDCAN_HandleTypeDef *hfdcan, uint32_t RxFifo0ITs)
{
 //Retreive Rx messages from RX FIFO0
 HAL_FDCAN_GetRxMessage(hfdcan, FDCAN_RX_FIFO1, &RxHeader2, (uint8_t*)CAN_RxDataBuffer2);
 //Activate Rx notifications from RX FIFO0
 HAL_FDCAN_ActivateNotification(hfdcan, FDCAN_IT_RX_FIFO1_NEW_MESSAGE, 0); 
}

Of course the FDCAN2 interrupt 0 is activated on CubeMX :

DamienRatazy_0-1719496697177.png

What's wrong?

 

Best regards

    This topic has been closed for replies.
    Best answer by Damien Ratazy

    Yep, the callback is well implemented.

    I finally found the solution : I had to offset the RAM with 14 words to make the FDCAN2 working.

    Now both FDCAN1 and 2 are working well.

    Thank you anyways for your help :)

    1 reply

    Visitor II
    June 27, 2024

    Interesting fact : FDCAN2 Rx callback works when I disable FDCAN1, that proves that the hardware is okay and the filters are set correctly.

     

    Somehow FDCAN2 Rx callback don't work when the other FDCAN1 is enabled, I'm really struggling with this issue.

    Super User
    June 27, 2024

    Hi,

    just ...

    did you enable callback in Cube ?

    AScha3_0-1719516918579.png

    +

    in call back/int check, which fdcan is calling - you use 2 of them , so you need to know, which one is coming.

    Damien RatazyAuthorAnswer
    Visitor II
    June 28, 2024

    Yep, the callback is well implemented.

    I finally found the solution : I had to offset the RAM with 14 words to make the FDCAN2 working.

    Now both FDCAN1 and 2 are working well.

    Thank you anyways for your help :)