cancel
Showing results for 
Search instead for 
Did you mean: 

FDCAN Filter problem in Classic Mode STM32U575I

Ankit_0611
Associate

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 

  1. FDCAN Init with  HAL_FDCAN_Init
  2. Configuring FDCAN Filter with HAL_FDCAN_ConfigFilter
  3. Configuring global filter to reject remote and not matching message frames using HAL_FDCAN_ConfigGlobalFilter
  4. Starting FDCAN by HAL_FDCAN_Start

This case is working fine and filtering all the unwanted CAN messages.

Case 2 :

Init sequence as mentioned below

  1. FDCAN Init with  HAL_FDCAN_Init
  2. Configuring FDCAN Filter with HAL_FDCAN_ConfigFilter
  3. Configuring global filter to reject remote and not matching message frames using HAL_FDCAN_ConfigGlobalFilter
  4. Starting FDCAN by HAL_FDCAN_Start
  5. Re-Configured the Filter with new ID and new Mask with HAL_FDCAN_ConfigFilter
  6. Re-Configuring global filter to reject remote and not matching message frames using HAL_FDCAN_ConfigGlobalFilter

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.

  • Init FDCAN
/* 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();
}
  • FDCAN MSP init
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 FDCAN Filter in MASK mode before starting FDCAN
/* 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 FDCAN Global Filter
/* 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();
}
  • Start FDCAN
if(HAL_FDCAN_Start(&FDCANHandle) != HAL_OK)
{
    /* Start Error */
    Error_Handler();
}
  •  Re-Configure FDCAN with new filter and mask as an when required in running application code
/* 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.

0 REPLIES 0