2023-11-07 03:37 AM
Hi,
I am working using FDCAN as Classic CAN 2.0B, in STM32U575-EV kit.
I am facing issue with FDCAN filtering with Classic Mask mode. There is two cases of filter configuration explained below, in first case it is working as expected but in second case FDCAN Filter stop working.
Case 1 :
Init sequence as mentioned
This case is working fine and filtering all the unwanted CAN messages.
Case 2 :
Init sequence as mentioned below
This case is not working and it stops receiving message from the valid ID too.
Below is code shows the configuration of FDCAN
FDCAN Clock is enabled at 80Mhz, source is PLL1Q. Bus speed is 500 KBPS.
/* Initialize FDCAN1 */
FDCANHandle.Instance = FDCAN1;
FDCANHandle.Init.ClockDivider = FDCAN_CLOCK_DIV1;
FDCANHandle.Init.FrameFormat = FDCAN_FRAME_CLASSIC;
FDCANHandle.Init.AutoRetransmission = ENABLE;
FDCANHandle.Init.TransmitPause = DISABLE;
FDCANHandle.Init.ProtocolException = ENABLE;
FDCANHandle.Init.NominalPrescaler = 10;
FDCANHandle.Init.NominalSyncJumpWidth = 1;
FDCANHandle.Init.NominalTimeSeg1 = 13;
FDCANHandle.Init.NominalTimeSeg2 = 2;
FDCANHandle.Init.DataPrescaler = 1;
FDCANHandle.Init.DataSyncJumpWidth = 1;
FDCANHandle.Init.DataTimeSeg1 = 1;
FDCANHandle.Init.DataTimeSeg2 = 1;
FDCANHandle.Init.StdFiltersNbr = 0;
FDCANHandle.Init.ExtFiltersNbr = 1;
FDCANHandle.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION;
if (HAL_FDCAN_Init(&FDCANHandle) != HAL_OK)
{
Error_Handler();
}
void HAL_FDCAN_MspInit(FDCAN_HandleTypeDef* canHandle)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
if(canHandle->Instance==FDCAN1)
{
/* USER CODE BEGIN FDCAN1_MspInit 0 */
/* USER CODE END FDCAN1_MspInit 0 */
/** Initializes the peripherals clock
*/
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_FDCAN1;
PeriphClkInit.Fdcan1ClockSelection = RCC_FDCAN1CLKSOURCE_PLL1;
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
{
Error_Handler();
}
/* Peripheral clock enable */
__HAL_RCC_FDCAN1_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();
/**FDCAN1 GPIO Configuration
PB9 ------> FDCAN1_TX
PB8 ------> FDCAN1_RX
*/
GPIO_InitStruct.Pin = GPIO_PIN_9|GPIO_PIN_8;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF9_FDCAN1;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
/* FDCAN1 interrupt Init */
HAL_NVIC_SetPriority(FDCAN1_IT0_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(FDCAN1_IT0_IRQn);
/* USER CODE BEGIN FDCAN1_MspInit 1 */
if ( ! __HAL_RCC_FDCAN1_IS_CLK_ENABLED() )
{
LOG_T("%s RCC_FDCAN1_IS_CLK_ENABLED NOT enabled ",__FUNCTION__);
}
/* USER CODE END FDCAN1_MspInit 1 */
}
}
/* Configure extended ID reception filter to Rx FIFO 0 */
FDCANfilterConfig.IdType = FDCAN_EXTENDED_ID;
FDCANfilterConfig.FilterIndex = 0;
FDCANfilterConfig.FilterType = FDCAN_FILTER_MASK;
FDCANfilterConfig.FilterConfig = FDCAN_FILTER_TO_RXFIFO0;
FDCANfilterConfig.FilterID1 = 0x00000000;
FDCANfilterConfig.FilterID2 = 0x00000000;
if (HAL_FDCAN_ConfigFilter(&FDCANHandle, &FDCANfilterConfig) != HAL_OK)
{
Error_Handler();
}
/* Configure global filter:
Reject all remote frames with STD and EXT ID
Reject non matching frames with STD ID and EXT ID */
if(HAL_FDCAN_ConfigGlobalFilter(&FDCANHandle, FDCAN_REJECT, FDCAN_REJECT, FDCAN_REJECT, FDCAN_REJECT) != HAL_OK)
{
Error_Handler();
}
if(HAL_FDCAN_Start(&FDCANHandle) != HAL_OK)
{
/* Start Error */
Error_Handler();
}
/* Configure extended ID reception filter to Rx FIFO 0 */
FDCANfilterConfig.IdType = FDCAN_EXTENDED_ID;
FDCANfilterConfig.FilterIndex = 0;
FDCANfilterConfig.FilterType = FDCAN_FILTER_MASK;
FDCANfilterConfig.FilterConfig = FDCAN_FILTER_TO_RXFIFO0;
FDCANfilterConfig.FilterID1 = 0x1f81fe10; // This could be change as per message IDs
FDCANfilterConfig.FilterID2 = 0x1f87ffff; // This could be change as per message IDs
if (HAL_FDCAN_ConfigFilter(&FDCANHandle, &FDCANfilterConfig) != HAL_OK)
{
Error_Handler();
}
Could anyone please help why I FDCAN stop working, when we reconfigure the FDCAN filter after starting of the FDCAN ?
Thank you
Best Regards,
Ankit G.