Skip to main content
Visitor II
December 17, 2025
Solved

Setup CANFD in CAN2.0 on Riverdi 12.1 display (STM32H7)

  • December 17, 2025
  • 1 reply
  • 620 views

I'm trying to receive some data over CAN (using Kvaser CanKing 500 kbit/s) and display it on a Riverdi 12.1" display. In fdcan.c, I have:

void MX_FDCAN1_Init(void)
{

 /* USER CODE BEGIN FDCAN1_Init 0 */
	FDCAN_FilterTypeDef sFilterConfig; // the required filter ID can be found in the struct
 /* USER CODE END FDCAN1_Init 0 */

 /* USER CODE BEGIN FDCAN1_Init 1 */

 /* USER CODE END FDCAN1_Init 1 */
	hfdcan1.Instance = FDCAN1;
	 hfdcan1.Init.FrameFormat = FDCAN_FRAME_CLASSIC;
	 hfdcan1.Init.Mode = FDCAN_MODE_NORMAL; // FDCAN_MODE_INTERNAL_LOOPBACK; // FDCAN_MODE_NORMAL;
	 hfdcan1.Init.AutoRetransmission = DISABLE;
	 hfdcan1.Init.TransmitPause = DISABLE;
	 hfdcan1.Init.ProtocolException = DISABLE;
	 hfdcan1.Init.NominalPrescaler = 1;
	 hfdcan1.Init.NominalSyncJumpWidth = 32;
	 hfdcan1.Init.NominalTimeSeg1 = 127;
	 hfdcan1.Init.NominalTimeSeg2 = 32;
	 hfdcan1.Init.DataPrescaler = 1;
	 hfdcan1.Init.DataSyncJumpWidth = 10;
	 hfdcan1.Init.DataTimeSeg1 = 29;
	 hfdcan1.Init.DataTimeSeg2 = 10;
	 hfdcan1.Init.MessageRAMOffset = 0;
	 hfdcan1.Init.StdFiltersNbr = 1;
	 hfdcan1.Init.ExtFiltersNbr = 0;
	 hfdcan1.Init.RxFifo0ElmtsNbr = 32;
	 hfdcan1.Init.RxFifo0ElmtSize = FDCAN_DATA_BYTES_64;
	 hfdcan1.Init.RxFifo1ElmtsNbr = 0;
	 hfdcan1.Init.RxFifo1ElmtSize = FDCAN_DATA_BYTES_8;
	 hfdcan1.Init.RxBuffersNbr = 1;
	 hfdcan1.Init.RxBufferSize = FDCAN_DATA_BYTES_8;
	 hfdcan1.Init.TxEventsNbr = 0;
	 hfdcan1.Init.TxBuffersNbr = 1;
	 hfdcan1.Init.TxFifoQueueElmtsNbr = 1;
	 hfdcan1.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION;
	 hfdcan1.Init.TxElmtSize = FDCAN_DATA_BYTES_8;
	 if (HAL_FDCAN_Init(&hfdcan1) != HAL_OK)
	 {
		Error_Handler();
	 }
	 HAL_GPIO_TogglePin(USR_LED_1_GPIO_Port, USR_LED_1_Pin);
	 /* USER CODE BEGIN FDCAN1_Init 2 */
	 FDCAN_FilterTypeDef sFilter = {0};

	 // Route standard ID 0x123 to FIFO0
	 sFilter.IdType = FDCAN_STANDARD_ID;
	 sFilter.FilterIndex = 0;
	 sFilter.FilterType = FDCAN_FILTER_MASK;
	 sFilter.FilterConfig = FDCAN_FILTER_TO_RXFIFO0;
	 sFilter.FilterID1 = 0x111; // ID
	 sFilter.FilterID2 = 0x000; // mask: all bits must match

	 if (HAL_FDCAN_ConfigFilter(&hfdcan1, &sFilter) != HAL_OK)
	 {
		Error_Handler();
	 }
	 HAL_FDCAN_ConfigGlobalFilter(
	 &hfdcan1,
	 FDCAN_ACCEPT_IN_RX_FIFO0, // Non-matching standard IDs
	 FDCAN_ACCEPT_IN_RX_FIFO0, // Non-matching extended IDs
	 FDCAN_REJECT_REMOTE, // Standard remote
	 FDCAN_REJECT_REMOTE // Extended remote
	 );
	 if (HAL_FDCAN_Start(&hfdcan1) != HAL_OK)
	 {
		Error_Handler();
	 }
	 HAL_FDCAN_ActivateNotification(&hfdcan1, FDCAN_IT_RX_FIFO0_NEW_MESSAGE, 0);
	 FDCAN_TxHeaderTypeDef txh = {0};
	 uint8_t txd[8] = {0};

	 txh.Identifier = 0x123;
	 txh.IdType = FDCAN_STANDARD_ID;
	 txh.TxFrameType = FDCAN_DATA_FRAME;
	 txh.DataLength = FDCAN_DLC_BYTES_8;
	 txh.ErrorStateIndicator = FDCAN_ESI_ACTIVE;
	 txh.BitRateSwitch = FDCAN_BRS_OFF;
	 txh.FDFormat = FDCAN_CLASSIC_CAN;
	 txh.TxEventFifoControl = FDCAN_NO_TX_EVENTS;
	 txh.MessageMarker = 0;

	 uint32_t value = 424242; // whatever you want to see
	 txd[0] = (uint8_t)(value);
	 txd[1] = (uint8_t)(value >> 8);
	 txd[2] = (uint8_t)(value >> 16);
	 txd[3] = (uint8_t)(value >> 24);
	 //rest bytes can be 0

	 HAL_FDCAN_ActivateNotification(&hfdcan1,
	 FDCAN_IT_TX_COMPLETE | FDCAN_IT_BUS_OFF | FDCAN_IT_ERROR_PASSIVE | FDCAN_IT_ERROR_WARNING,
	 0);

	 if (HAL_FDCAN_AddMessageToTxFifoQ(&hfdcan1, &txh, txd) != HAL_OK)
	 {
		Error_Handler();
	 }
 /* USER CODE END FDCAN1_Init 2 */

}

 

If I use FDCAN_INTERNAL_LOOPBACK, I can see "424242" as expected on the display. But in FDCAN_MODE_NORMAL, I cannot send anything. On CanKing, I simply see an error frame received from the display. Is there any documentation or sample code I can refer to, to make this work? IF needed, I can share the Git repo for the project.

Also, is it possible to debug the code from the CubeIDE?

Best answer by mƎALLEm

Hello,

You didn't show the clock configuration.

Did you select HSE with an external crystal as clock source for FDCAN? You need to use HSE with an external crystal. 

Check also the wiring.

 

1 reply

mƎALLEm
mƎALLEmBest answer
Technical Moderator
December 19, 2025

Hello,

You didn't show the clock configuration.

Did you select HSE with an external crystal as clock source for FDCAN? You need to use HSE with an external crystal. 

Check also the wiring.

 

"To give better visibility on the answered topics, please click on ""Accept as Solution"" on the reply which solved your issue or answered your question."