cancel
Showing results for 
Search instead for 
Did you mean: 

STM32H743 CAN BUS

gfghg.1
Associate

I am using stm32h743zi with my custom board. I configured fd can 1 as classic can as in cubemx example. I configured the baudrate as 125 kbit/s.

But after sending couple of packets, it stops sending due to fifo full error. How can i clear the fifo?

My clock speed is 400 mhz. FDCAN kernel clock is 36 mhz.

This is the rest of the configuration :

 hfdcan1.Instance = FDCAN1;

 hfdcan1.Init.FrameFormat = FDCAN_FRAME_CLASSIC;

 hfdcan1.Init.Mode = FDCAN_MODE_NORMAL;

 hfdcan1.Init.AutoRetransmission = DISABLE;

 hfdcan1.Init.TransmitPause = DISABLE;

 hfdcan1.Init.ProtocolException = ENABLE;

 hfdcan1.Init.NominalPrescaler = 16;

 hfdcan1.Init.NominalSyncJumpWidth = 1;

 hfdcan1.Init.NominalTimeSeg1 = 12;

 hfdcan1.Init.NominalTimeSeg2 = 5;

 hfdcan1.Init.DataPrescaler = 16;

 hfdcan1.Init.DataSyncJumpWidth = 1;

 hfdcan1.Init.DataTimeSeg1 = 12;

 hfdcan1.Init.DataTimeSeg2 = 5;

 hfdcan1.Init.MessageRAMOffset = 0;

 hfdcan1.Init.StdFiltersNbr = 1;

 hfdcan1.Init.ExtFiltersNbr = 0;

 hfdcan1.Init.RxFifo0ElmtsNbr = 1;

 hfdcan1.Init.RxFifo0ElmtSize = FDCAN_DATA_BYTES_8;

 hfdcan1.Init.RxFifo1ElmtsNbr = 0;

 hfdcan1.Init.RxFifo1ElmtSize = FDCAN_DATA_BYTES_8;

 hfdcan1.Init.RxBuffersNbr = 0;

 hfdcan1.Init.RxBufferSize = FDCAN_DATA_BYTES_8;

 hfdcan1.Init.TxEventsNbr = 0;

 hfdcan1.Init.TxBuffersNbr = 0;

 hfdcan1.Init.TxFifoQueueElmtsNbr = 32;

 hfdcan1.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION;

 hfdcan1.Init.TxElmtSize = FDCAN_DATA_BYTES_8;

 FDCAN_TxHeaderTypeDef TxHeader;

 uint8_t TxData[8] = { 0, 1, 2, 3, 4, 5, 6, 7 };

 TxHeader.Identifier = 0x321;

 TxHeader.IdType = FDCAN_STANDARD_ID;

 TxHeader.TxFrameType = FDCAN_DATA_FRAME;

 TxHeader.DataLength = FDCAN_DLC_BYTES_8;

 TxHeader.ErrorStateIndicator = FDCAN_ESI_ACTIVE;

 TxHeader.BitRateSwitch = FDCAN_BRS_OFF;

 TxHeader.FDFormat = FDCAN_CLASSIC_CAN;

 TxHeader.TxEventFifoControl = FDCAN_NO_TX_EVENTS;

 TxHeader.MessageMarker = 0;

 if (HAL_FDCAN_Start(&hfdcan1) != HAL_OK)

 Error_Handler();

 while (1)

 {

 uint32_t rr = HAL_FDCAN_GetTxFifoFreeLevel(&hfdcan1);

 if(rr != 0)

 {

 HAL_StatusTypeDef tt = HAL_FDCAN_AddMessageToTxFifoQ(&hfdcan1, &TxHeader, TxData);

 if (tt != HAL_OK)

 {

 printf("bb");

 }

 }

 else

 {

 printf("aa");

 }

 HAL_Delay(100);

  /* USER CODE END WHILE */

  /* USER CODE BEGIN 3 */

 }

What could be the problem?

1 REPLY 1
T J
Lead

i think you issue may be the Fifo Level you are checking, does it return the number of bytes free or number of fifos free ?

anyhow the simple fix is to increase your delay to 1000 and during that time you could report to the console the Fifo Level.

then this line

if (rr !=0)

could be reviewed.