cancel
Showing results for 
Search instead for 
Did you mean: 

CAN Filter settings do not work properly.

SJ_KIM
Associate

void CAN_Filter(uint8_t filter_index, uint32_t Filter_ID)
{
CanFilter.FilterType = FDCAN_FILTER_MASK;
CanFilter.IdType = FDCAN_EXTENDED_ID;
CanFilter.FilterIndex = filter_index;
CanFilter.FilterConfig = FDCAN_FILTER_TO_RXFIFO0;
CanFilter.FilterID1 = Filter_ID;
CanFilter.FilterID2 = 0x1FFFFFFF;


if(HAL_FDCAN_ConfigFilter(&hfdcan1, &CanFilter) != HAL_OK)
{
Error_Handler();
}

}

 

The mcu is using g473. I would appreciate it if you could provide detailed information, from Cubemx settings to filter settings in the code. Thank you

3 REPLIES 3
EXUE.2
ST Employee

1. what's the details about "do not work properly"? can you give more information and debug it to look where or which line it stop running?

2. since the type of "CanFilter.FilterIndex" is uin32_t and it's range is [0-7], can you check it?

3. if you have enable the CAN clock in RCC?

nouirakh
ST Employee

Hello @SJ_KIM 

To set up a CAN filter using the HAL library on an STM32G473 MCU with CubeMX, you need to follow several steps from configuring the peripheral in CubeMX to writing the filter setup code:
Set the FDCAN parameters according to your application requirements. In the "Rx FIFO0" section, make sure to enable it since your filter configuration is directing messages to RXFIFO0.
If you want to use interrupts, enable the FDCAN interrupt lines under the "NVIC Settings" tab. 
Ensure that the clock configuration provides the necessary clock to the FDCAN peripheral.
Ensure that MX_FDCAN1_Init(); is called during initialization to set up the FDCAN peripheral.

If you have specific requirements or if you are using additional functionality, you may need to adjust the CubeMX configuration or the initialization code accordingly.
Otherwise, it might be worth checking out these .Ioc configurations for FDCAN projects FDCAN 

 

LCE
Principal

At least for H7 FDCAN: Maybe the "global rejection filter" is not turned on?

Check if you find the function call to 

/* Configure global filter to reject all non-matching frames */
HAL_FDCAN_ConfigGlobalFilter(phCan, FDCAN_REJECT, FDCAN_REJECT, FDCAN_REJECT_REMOTE, FDCAN_REJECT_REMOTE);

somewhere in your source.

It must be called for each CAN peripheral.