Skip to main content
Visitor II
January 29, 2025
Question

stm32g4 FDCAN fiters problem

  • January 29, 2025
  • 1 reply
  • 492 views

Hi. I have a problem with can filers on a G4 board. With standard ids device worked well, but when i changed id to extended the filters stopped working.

// 5. FDCAN Filters configuration
// 5.1. Dual filter for broadcast messages
sFilterConfig.IdType = FDCAN_EXTENDED_ID; //FDCAN_STANDARD_ID;
sFilterConfig.FilterIndex = 0;
sFilterConfig.FilterType = FDCAN_FILTER_DUAL; //FDCAN_FILTER_MASK;
sFilterConfig.FilterConfig = FDCAN_FILTER_TO_RXFIFO0;
sFilterConfig.FilterID1 = 0x800 | 0xFF;
sFilterConfig.FilterID2 = 0x800 | 0xFF; // For acceptance, MessageID and FilterID1 must match exactly
if(HAL_FDCAN_ConfigFilter(&hfdcan, &sFilterConfig) != HAL_OK) {
 return -2;
}



// 5.1. Range filter
uint16_t canRcvHeaderMaskL = 0x00000803;
uint16_t canRcvHeaderMaskH = 0x00000806;

sFilterConfig.IdType = FDCAN_EXTENDED_ID; //FDCAN_STANDARD_ID;
sFilterConfig.FilterIndex = 1;
sFilterConfig.FilterType = FDCAN_FILTER_RANGE; //; FDCAN_FILTER_DUAL
sFilterConfig.FilterConfig = FDCAN_FILTER_TO_RXFIFO1;
sFilterConfig.FilterID1 = canRcvHeaderMaskL;
sFilterConfig.FilterID2 = canRcvHeaderMaskH;

if(HAL_FDCAN_ConfigFilter(&hfdcan, &sFilterConfig) != HAL_OK) {
return -2;
}
// Activate Rx FIFO 0 new message notification
if (HAL_FDCAN_ActivateNotification(&hfdcan, FDCAN_IT_RX_FIFO0_NEW_MESSAGE, 0) != HAL_OK) {
setTerminalMessage(error, "FDCAN filter notification alert failed");
return -3;
}
if (HAL_FDCAN_ActivateNotification(&hfdcan, FDCAN_IT_RX_FIFO1_NEW_MESSAGE, 0) != HAL_OK) {
setTerminalMessage(error, "FDCAN filter notification alert failed");
return -3;
}

HAL_FDCAN_ConfigGlobalFilter(&hfdcan, FDCAN_REJECT, FDCAN_REJECT, FDCAN_REJECT_REMOTE, FDCAN_REJECT_REMOTE);

If i comment HAL_FDCAN_ConfigGlobalFilter string - every input packet appears in fifo0. What can i do to make filter work?

 

    This topic has been closed for replies.

    1 reply

    Technical Moderator
    January 29, 2025

    Hello,


    @zemlemer wrote:

    Hi. I have a problem with can filers on a G4 board. With standard ids device worked well, but when i changed id to extended the filters stopped working.


    Are you sure you are sending Extended IDs? are you using Loopback mode?

    zemlemerAuthor
    Visitor II
    January 29, 2025

    Well, if i comment HAL_FDCAN_ConfigGlobalFilter string, i receive packet with id 0x803 and this is not 11-bit id, so it seems that it is an extended id. Device is not in loopback mode.

    Technical Moderator
    January 29, 2025

    If possible to try with the loopback mode (more easier to debug) and send your project so we could help efficiently + what STM32G4 part number are you using?