Skip to main content
Explorer
August 28, 2023
Question

Help with FD-CAN filter

  • August 28, 2023
  • 4 replies
  • 6133 views

Hello,

I work with STM32G484, with FDCAN. I want to create filter so only messages with my own CAN_ID will reach HAL_FDCAN_RxFifo0Callback.

I started by define the filter:

filter.IdType = FDCAN_STANDARD_ID;
filter.FilterIndex = 0;
filter.FilterType = FDCAN_FILTER_MASK;
filter.FilterConfig = FDCAN_FILTER_TO_RXFIFO0;
filter.FilterID1 = CAN_ID;
filter.FilterID2 = 0x1FFFFFFF;
 
HAL_FDCAN_ConfigFilter(&hfdcan1, &filter);
 
At this point the filter not realy doing anything, and I still getting other nodes ID in the callback.
 
I tried to add a global filter with:
HAL_FDCAN_ConfigGlobalFilter(&hfdcan1, FDCAN_REJECT, FDCAN_REJECT, FDCAN_REJECT_REMOTE, FDCAN_REJECT_REMOTE);

but now i reject also my own ID.
 
What I miss here? what is the correct way to define the filter?
 
Thanks in advance,
Amit Prigozin
    This topic has been closed for replies.

    4 replies

    Graduate II
    August 28, 2023

    I'm unsure but I have HAL_FDCAN_Start and HAL_FDCAN_ActivateNotification with FDCAN_IT_RX_FIFO0_NEW_MESSAGE for active interrupt on every new message in HAL_FDCAN_RxFifo0Callback

    and you also need to have HAL_FDCAN_ActivateNotification in FDCAN RX callback too.

    prigo87Author
    Explorer
    August 28, 2023

    I did all of this of course.
    The problem is with the filter setting

    Thank you

    Graduate II
    August 28, 2023

    I had read your can config and your CAN id that I think that it's not oversize of Standard ID. I think it's an extended id.
    so you should try to change IdType to extended one.

    prigo87Author
    Explorer
    August 28, 2023

    i work with CAN-ID of 10 to 200. So its not a problem of ID length. Any way I changed the ID type to extend and it still not working - passing all with regular filter only, and block all with the global filter

    Visitor II
    February 27, 2024

    Hi prigo87!

    Did you solve the issue? Mine is related:

    H723 FDCAN1 and FDCAN2 - Page 2 - STMicroelectronics Community

     

    Cheers!

     

    Visitor II
    May 17, 2025

    I had this exact problem when trying to modify a project from extended IDs to standard IDs.  In my case it turned out I had the FDCAN peripheral configured incorrectly in the .ioc file:  it was set for 8 extended filter IDs and 0 standard filter IDs.

    Graduate
    August 8, 2025

    i has solved this issue as below

     // 设置接收过滤器
     FDCAN_FilterTypeDef sFilterConfig;
     sFilterConfig.IdType = FDCAN_STANDARD_ID;
     sFilterConfig.FilterIndex = 0;
     sFilterConfig.FilterType = FDCAN_FILTER_MASK;
     sFilterConfig.FilterConfig = FDCAN_FILTER_TO_RXFIFO0;
     sFilterConfig.FilterID1 = 0x002; // 设置过滤器ID1
     sFilterConfig.FilterID2 = 0x7ff; // 设置过滤器ID2
     if (HAL_FDCAN_ConfigFilter(&hfdcan1, &sFilterConfig) != HAL_OK)
     {
     Error_Handler();
     }
    
     if(HAL_FDCAN_ConfigGlobalFilter(&hfdcan1, FDCAN_REJECT, FDCAN_REJECT, FDCAN_REJECT_REMOTE, FDCAN_REJECT_REMOTE) != HAL_OK)
     {
     Error_Handler();
     }
    hfdcan1.Init.StdFiltersNbr = 1;

    you did not solve it, because you did not modify the stdFiltersNbr.

    hope this will help you.