cancel
Showing results for 
Search instead for 
Did you mean: 

STM32H745I-DISCO – CAN TXFIFO Buffer Full Issue

Sumithra
Associate

Hi everyone,

I am working on Classic CAN communication using the STM32H745I-Discovery board with FDCAN2.
My target CAN configuration is 500 Kbps nominal baud rate with a 16 MHz clock.

Below is my initialization code:

static void MX_FDCAN2_Init(void)
{
hfdcan2.Instance = FDCAN2;
hfdcan2.Init.FrameFormat = FDCAN_FRAME_CLASSIC;
hfdcan2.Init.Mode = FDCAN_MODE_NORMAL;
hfdcan2.Init.AutoRetransmission = ENABLE;
hfdcan2.Init.TransmitPause = DISABLE;
hfdcan2.Init.ProtocolException = ENABLE;

// Timing config: 500 Kbps @ 16 MHz
hfdcan2.Init.NominalPrescaler = 1;
hfdcan2.Init.NominalSyncJumpWidth = 1;
hfdcan2.Init.NominalTimeSeg1 = 23;
hfdcan2.Init.NominalTimeSeg2 = 8;

hfdcan2.Init.DataPrescaler = 1;
hfdcan2.Init.DataSyncJumpWidth = 1;
hfdcan2.Init.DataTimeSeg1 = 1;
hfdcan2.Init.DataTimeSeg2 = 1;

hfdcan2.Init.MessageRAMOffset = 0;
hfdcan2.Init.StdFiltersNbr = 1;
hfdcan2.Init.ExtFiltersNbr = 0;
hfdcan2.Init.RxFifo0ElmtsNbr = 1;
hfdcan2.Init.RxFifo0ElmtSize = FDCAN_DATA_BYTES_8;
hfdcan2.Init.TxFifoQueueElmtsNbr = 1;
hfdcan2.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION;
hfdcan2.Init.TxElmtSize = FDCAN_DATA_BYTES_8;

if (HAL_FDCAN_Init(&hfdcan2) != HAL_OK) Error_Handler();

// Configure filter (accept all standard IDs)
FDCAN_FilterTypeDef filter;
filter.IdType = FDCAN_STANDARD_ID;
filter.FilterIndex = 0;
filter.FilterType = FDCAN_FILTER_MASK;
filter.FilterConfig = FDCAN_FILTER_TO_RXFIFO0;
filter.FilterID1 = 0x000;
filter.FilterID2 = 0x7FF;
HAL_FDCAN_ConfigFilter(&hfdcan2, &filter);

HAL_FDCAN_Start(&hfdcan2);

// Tx header
txHeader.Identifier = 0x123;
txHeader.IdType = FDCAN_STANDARD_ID;
txHeader.TxFrameType = FDCAN_DATA_FRAME;
txHeader.DataLength = FDCAN_DLC_BYTES_8;
txHeader.BitRateSwitch = FDCAN_BRS_OFF;
txHeader.FDFormat = FDCAN_CLASSIC_CAN;
txHeader.TxEventFifoControl = FDCAN_NO_TX_EVENTS;
txHeader.MessageMarker = 0;
}
And the send function:
HAL_StatusTypeDef CAN_Send(uint8_t* data)
{
if (HAL_FDCAN_AddMessageToTxFifoQ(&hfdcan2, &txHeader, data) == HAL_OK)
{   

           return HAL_OK;
}
else
{
         return HAL_ERROR;
}
}

Issue:

The first few CAN frames transmit successfully.

After that, the TXFIFO becomes full and no further frames are sent.

Sometimes it transmits several messages before stopping, sometimes only one or two.

 

What I tried so far:

  1. Increased TxFifoQueueElmtsNbr (tried more than 1).

  2. Verified hardware connections and ensured 120Ω termination resistor is present.

  3. Tested the receiver side (looped with another working board), and confirmed reception is fine there.

  4. Tried with both AutoRetransmission enabled/disabled.

  5. Verified the 500 Kbps baud rate configuration with 16 MHz clock.

Still, the issue persists.

Any guidance or working examples would be very helpful.

Thanks!

 

1 REPLY 1
Karl Yamashita
Principal

Are you queuing your CAN messages? Because if you send a bunch of messages and the Tx buffer is full, then you lose those messages. By using a queue, you can send those messages once the Tx buffer is available.

 

Also, use the </> to post code so that it's formatted and readable.

If a reply has proven helpful, click on Accept as Solution so that it'll show at top of the post.