cancel
Showing results for 
Search instead for 
Did you mean: 

STM32G0B1, CANFD issues

ŁJura.1
Associate II

Hi guys!

I have a custom board with 2x CAN FD transcievers (TCAN1057) and STM32G0B1 MCU. Everything works fine until i try to use hardware filters build into STM32. Whatever i do, filters don't pass any frame to RxFifo0/RxFifo1. The only way to recieve anything is to configure global filter with FDCAN_ACCEPT_IN_RX_FIFO0 option. With code pasted below, HAL_FDCAN_IRQHandler  is never called. Temporary i used workaround with global filter and hardcoded frame ID check, but i would like to solve the issue anyway. Can someone give me some advice?

 

The code:

https://pastebin.com/p7GVU1F7

 

BR.

Łukasz

1 ACCEPTED SOLUTION

Accepted Solutions

Hello @ŁJura.1 ,

Any status on your progress in this case?

Edit:

Looking again at your code, the filters number in your config are set to 0.

      hfdcan1.Init.StdFiltersNbr = 0;
      hfdcan1.Init.ExtFiltersNbr = 0;

 You need to set at least one filter for each CAN frame type (Standard and Extended).

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.

View solution in original post

6 REPLIES 6
ŁJura.1
Associate II

Nobody?

nouirakh
ST Employee

Hello @ŁJura.1 

The link you shared with us is unreachable. Could you please share your code here by using the option "Insert/Edit code simple".
Otherwise, Can you ensure that the filter configuration is correctly set up. Here is an example of how to configure a filter:

FDCAN_FilterTypeDef sFilterConfig;

sFilterConfig.IdType = FDCAN_STANDARD_ID; // or FDCAN_EXTENDED_ID
sFilterConfig.FilterIndex = 0;
sFilterConfig.FilterType = FDCAN_FILTER_MASK;
sFilterConfig.FilterConfig = FDCAN_FILTER_TO_RXFIFO0; // or FDCAN_FILTER_TO_RXFIFO1
sFilterConfig.FilterID1 = 0x123; // Example ID
sFilterConfig.FilterID2 = 0x7FF; // Example Mask

if (HAL_FDCAN_ConfigFilter(&hfdcan, &sFilterConfig) != HAL_OK)
{
    // Filter configuration Error
    Error_Handler();
}

Also, you need to check Interrupt Configuration: 

HAL_NVIC_SetPriority(FDCAN1_IT0_IRQn, 0, 1);
HAL_NVIC_EnableIRQ(FDCAN1_IT0_IRQn);

Finaly, ensure that the FDCAN peripheral is correctly initialized before configuring filters and enabling interrupts:

if (HAL_FDCAN_Init(&hfdcan) != HAL_OK)
{
    // Initialization Error
    Error_Handler();
}

 

SofLit
ST Employee

Hello,

Before using Normal mode, start by using Loopback mode to validate your filters config. If you face an issue share your project.

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.
 // 500kbps
      hfdcan1.Instance = FDCAN1;
      hfdcan1.Init.ClockDivider = FDCAN_CLOCK_DIV1;
      hfdcan1.Init.FrameFormat = FDCAN_FRAME_CLASSIC;
      hfdcan1.Init.Mode = FDCAN_MODE_NORMAL;
      hfdcan1.Init.AutoRetransmission = ENABLE;
      hfdcan1.Init.TransmitPause = DISABLE;
      hfdcan1.Init.ProtocolException = DISABLE;
      hfdcan1.Init.NominalPrescaler = 16;
      hfdcan1.Init.NominalSyncJumpWidth = 1;
      hfdcan1.Init.NominalTimeSeg1 = 3;
      hfdcan1.Init.NominalTimeSeg2 = 4;
      hfdcan1.Init.DataPrescaler = 1;
      hfdcan1.Init.DataSyncJumpWidth = 1;
      hfdcan1.Init.DataTimeSeg1 = 1;
      hfdcan1.Init.DataTimeSeg2 = 1;
      hfdcan1.Init.StdFiltersNbr = 0;
      hfdcan1.Init.ExtFiltersNbr = 0;
      hfdcan1.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION;
      if (HAL_FDCAN_Init(&hfdcan1) != HAL_OK)
      {
        Error_Handler();
      }
 
        // 667kbps
      hfdcan2.Instance = FDCAN2;
      hfdcan2.Init.ClockDivider = FDCAN_CLOCK_DIV1;
      hfdcan2.Init.FrameFormat = FDCAN_FRAME_CLASSIC;
      hfdcan2.Init.Mode = FDCAN_MODE_NORMAL;
      hfdcan2.Init.AutoRetransmission = ENABLE;
      hfdcan2.Init.TransmitPause = DISABLE;
      hfdcan2.Init.ProtocolException = DISABLE;
      hfdcan2.Init.NominalPrescaler = 8;
      hfdcan2.Init.NominalSyncJumpWidth = 1;
      hfdcan2.Init.NominalTimeSeg1 = 5;
      hfdcan2.Init.NominalTimeSeg2 = 6;
      hfdcan2.Init.DataPrescaler = 1;
      hfdcan2.Init.DataSyncJumpWidth = 1;
      hfdcan2.Init.DataTimeSeg1 = 1;
      hfdcan2.Init.DataTimeSeg2 = 1;
      hfdcan2.Init.StdFiltersNbr = 0;
      hfdcan2.Init.ExtFiltersNbr = 0;
      hfdcan2.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION;
      if (HAL_FDCAN_Init(&hfdcan2) != HAL_OK)
      {
        Error_Handler();
      }
 
      // pass anything from any can instance to fifo0
        // it also doeant work if i use values like 0x18FA0000 / 0x1FFF0000
      FDCAN_FilterTypeDef sFilterConfig;
      sFilterConfig.IdType = FDCAN_EXTENDED_ID;
      sFilterConfig.FilterIndex = 1;
      sFilterConfig.FilterType = FDCAN_FILTER_MASK;
      sFilterConfig.FilterConfig = FDCAN_FILTER_TO_RXFIFO0;
      sFilterConfig.FilterID1 = 0x0000000;
      sFilterConfig.FilterID2 = 0x0000000;
 
 
 
      if (HAL_FDCAN_ConfigFilter(&hfdcan1, &sFilterConfig) != HAL_OK)
      {
        /* Filter configuration Error */
        Error_Handler();
      }
      if (HAL_FDCAN_ConfigFilter(&hfdcan2, &sFilterConfig) != HAL_OK)
      {
        /* Filter configuration Error */
        Error_Handler();
      }
 
      // this works
//    HAL_FDCAN_ConfigGlobalFilter(&hfdcan1, FDCAN_ACCEPT_IN_RX_FIFO0, FDCAN_ACCEPT_IN_RX_FIFO0, FDCAN_FILTER_REMOTE, FDCAN_FILTER_REMOTE);
//    HAL_FDCAN_ConfigGlobalFilter(&hfdcan2, FDCAN_ACCEPT_IN_RX_FIFO0, FDCAN_ACCEPT_IN_RX_FIFO0, FDCAN_FILTER_REMOTE, FDCAN_FILTER_REMOTE);
 
 
      // this doesn't work
      HAL_FDCAN_ConfigGlobalFilter(&hfdcan1, FDCAN_REJECT, FDCAN_REJECT, FDCAN_FILTER_REMOTE, FDCAN_FILTER_REMOTE);
      HAL_FDCAN_ConfigGlobalFilter(&hfdcan2, FDCAN_REJECT, FDCAN_REJECT, FDCAN_FILTER_REMOTE, FDCAN_FILTER_REMOTE);
 
       // STart FDCAN1
      if(HAL_FDCAN_Start(&hfdcan1)!= HAL_OK)
      {
       Error_Handler();
      }
 
      // STart FDCAN2
      if(HAL_FDCAN_Start(&hfdcan2)!= HAL_OK)
      {
       Error_Handler();
      }
 
      // Activate the notification for new data in FIFO0 for FDCAN1
      if (HAL_FDCAN_ActivateNotification(&hfdcan1, FDCAN_IT_RX_FIFO0_NEW_MESSAGE, 0) != HAL_OK)
      {
        /* Notification Error */
        Error_Handler();
      }
 
 
      // Activate the notification for new data in FIFO0 for FDCAN2
      if (HAL_FDCAN_ActivateNotification(&hfdcan2, FDCAN_IT_RX_FIFO0_NEW_MESSAGE, 0) != HAL_OK)
      {
        /* Notification Error */
        Error_Handler();
      }

 

Here is the same code, hope now it's visible.
 

Ok, i'll try and report.

Hello @ŁJura.1 ,

Any status on your progress in this case?

Edit:

Looking again at your code, the filters number in your config are set to 0.

      hfdcan1.Init.StdFiltersNbr = 0;
      hfdcan1.Init.ExtFiltersNbr = 0;

 You need to set at least one filter for each CAN frame type (Standard and Extended).

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.