2024-07-11 06:53 AM - last edited on 2024-07-16 03:23 AM by SofLit
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:
BR.
Łukasz
Solved! Go to Solution.
2024-09-20 08:36 AM - edited 2024-09-25 02:24 AM
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).
2024-07-12 05:19 AM
Nobody?
2024-07-16 03:08 AM
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();
}
2024-07-16 04:05 AM
Hello,
Before using Normal mode, start by using Loopback mode to validate your filters config. If you face an issue share your project.
2024-07-16 11:42 PM
// 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.
2024-07-16 11:43 PM
Ok, i'll try and report.
2024-09-20 08:36 AM - edited 2024-09-25 02:24 AM
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).