Skip to main content
Associate II
February 6, 2026
Solved

FDCAN on STM32G491RE: Tx message truncated. 8 bytes sent instead of 12 bytes

  • February 6, 2026
  • 6 replies
  • 515 views

I am using STM32G491RE - NUCLEO. connected to the ADM3055e CAN Transceiver 

Currently I am trying to send 12 Bytes of Data from IXXAT Terminal over to FDCAN1 which receives the message fine and then Output the Message on FDCAN2 though a buffer. So My logic is when a message pass the filter it gets called by the Fifo0Callback and push it to a buffer below. This works fine the buffer also get the full 12Bytes of data same FD format and everything checked out.

But when I try to add the message to HAL_FDCAN_AddMessageToTxFifoQ(&hfdcan2, &TxHeader2, TxData2). Where TxData is the dequeued message from the buffer and copys the 12Bytes. The message somehow gets truncated to 8Bytes on output. 

Heck, when I add "if (HAL_FDCAN_GetTxFifoFreeLevel(&hfdcan2) > 0)", It somehow says it is full even when starting the code.

I have been suspecting because I cant set the HAL_FDCAN_ConfigTxBufferElementSize and HAL_FDCAN_ConfigRxBufferElementSize or even the messageRam offset like i could in the STM32H7 series. which may be causing the issue. Any Ideas on what I should do? 

Let me know if you need more information.

@LCE @mƎALLEm 
Thanks in advance! 

void HAL_FDCAN_RxFifo0Callback(FDCAN_HandleTypeDef *hfdcan, uint32_t RxFifo0ITs)
{
	if((RxFifo0ITs & FDCAN_IT_RX_FIFO0_NEW_MESSAGE) != RESET)
	{
		if (hfdcan->Instance == FDCAN2)
		{
...
		}
		else if (hfdcan->Instance == FDCAN1)
		{
			if (HAL_FDCAN_GetRxMessage(hfdcan, FDCAN_RX_FIFO0, &RxHeader1, RxData1) == HAL_OK)
			{
				uint8_t len = Can_DlcToBytes(RxHeader1.DataLength);
				if (!CanRxBuffer_EnqueueFromISR1(RxHeader1.Identifier, RxData1, len)) {
					FDCAN1_LED_State = LED_FIFO0_ERROR;
				} else {
					FDCAN1_LED_State = LED_STORE_BUFFER;
				}
			}
			else {
				FDCAN1_LED_State = LED_FIFO0_ERROR;
			}
		}

 

Best answer by Qin1

Ok I found the issue....It's ridiculous simple mistake but it solved my issue.

I realised that when configuring TxHeader FDFormat my mistake was:
TxHeader1.FDFormat = FDCAN_FRAME_FD_BRS;

however it should be 
TxHeader2.FDFormat = FDCAN_FD_CAN;

But anyways that solved my issue.

6 replies

mƎALLEm
Technical Moderator
February 6, 2026

Hello,

"But when I try to add the message to HAL_FDCAN_AddMessageToTxFifoQ(&hfdcan2, &TxHeader2, TxData2). Where TxData is the dequeued message from the buffer and copys the 12Bytes. The message somehow gets truncated to 8Bytes on output. "

I didn't understand the relation between the statement above and the FIFO callback.

Please be concise in the description. Does the issue is on Rx or on Tx?

Check the TxHeader. Is it set to DLC 12 or DLC 8?:

TxHeader.DataLength = FDCAN_DLC_BYTES_12;

 

"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."
Qin1Author
Associate II
February 6, 2026

Sorry.

The issue is on my Tx

I have configured my Tx as follows

TxHeader2.Identifier = 0x321;
TxHeader2.BitRateSwitch = FDCAN_BRS_ON;
TxHeader2.FDFormat = FDCAN_FRAME_FD_BRS;
 TxHeader2.IdType = FDCAN_EXTENDED_ID;
 TxHeader2.TxFrameType = FDCAN_DATA_FRAME;
 TxHeader2.DataLength = FDCAN_DLC_BYTES_12;
 TxHeader2.ErrorStateIndicator = FDCAN_ESI_PASSIVE;
 TxHeader2.TxEventFifoControl = FDCAN_NO_TX_EVENTS;
 TxHeader2.MessageMarker = 0;
mƎALLEm
Technical Moderator
February 6, 2026

Please clarify this point:

How did you check the Tx buffer was truncated? 

"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."
Qin1Author
Associate II
February 6, 2026

I will reword my issue

I am defining a 12-byte payload and setting TxHeader.DataLength = FDCAN_DLC_BYTES_12. In debug mode, I can verify that the header value is correctly set to 0x00090000 (DLC 9). However, my IXXAT analyzer shows the message arriving with DLC 8 and only the first 8 bytes of data.

Even when sending internally from FDCAN2 to FDCAN1, the RxData array only updates the first 8 bytes, while the remaining 4 bytes remain zeroed, despite the RxHeader reporting a DLC of 12.

Also another issue I am facing is when I add this. It say FifoFreeLevel is == 0

if (HAL_FDCAN_GetTxFifoFreeLevel(&hfdcan2) > 0)
			{
//				TxHeader2.DataLength = msg.Length;
				//TODO: remove TxData1 -> msg.Data
				memcpy(&TxData2, msg.Data, sizeof(msg.Data));
				if (HAL_FDCAN_AddMessageToTxFifoQ(&hfdcan2, &TxHeader2, TxData2) == HAL_OK) {
					FDCAN1_LED_State = LED_Tx_SUCCESS;
					printf("Bridge: Forwarded ID 0x%lx to FDCAN2\n\r", msg.Identifier);
				} else {
					FDCAN1_LED_State = LED_TRANSMISSION_ERROR;
					printf("Transmission Error!\n\r");
				}
			}
			else
			{
				FDCAN1_LED_State = LED_FIFO0_ERROR;
				printf("FDCAN2: Hardware FIFO Full - stalling bridge\n\r");
			}



mƎALLEm
Technical Moderator
February 6, 2026

Please share your project. What you are sharing doesn't tell anything about the issue.

"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."
Qin1Author
Associate II
February 6, 2026

I have attached a ZIP file of it below.

mƎALLEm
Technical Moderator
February 6, 2026

What that printf is showing here for the DLC?: DLC 12?

					printf("FDCAN1 RxHeader: DLC=%lu (bytes=%u) FDFormat=%lu last Byte=%u\r\n",
							TxHeader2.DataLength,
							Can_DlcToBytes(TxHeader2.DataLength),
							TxHeader2.FDFormat,
							TxData2[11]);

And what Can_BytesToDlc() returns here?

TxHeader2.DataLength = Can_BytesToDlc(currentPacketSize);

Try to force TxHeader2.DataLength with:

FDCAN_DLC_BYTES_12

 

"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."
Qin1Author
Associate II
February 6, 2026

DLC = 9
Bytes = 12

Qin1_0-1770375126945.png

 

Qin1Author
Associate II
February 6, 2026

I did that and still the same result

Qin1_0-1770375336253.png

 

mƎALLEm
Technical Moderator
February 6, 2026

I don't have the device to test and debug. I think at this stage better to create a simple project where you simply send 12 bytes to your analyzer and test. 

You can also try the Loopback mode.

"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."
Qin1Author
Associate II
February 6, 2026

Alright I'll do that and let you know how it goes. Thank you for the help @mƎALLEm 

On a side note may I ask how the RAM allocation and Tx / Rx BufferElementSize can be configured on G4 Series. As in cubeMX it doesnt give me the option to like the H7 series. Or is that done automatically by the core? 

mƎALLEm
Technical Moderator
February 6, 2026

Better to separate questions here. Please create another thread for that question.

"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."
Qin1AuthorBest answer
Associate II
February 6, 2026

Ok I found the issue....It's ridiculous simple mistake but it solved my issue.

I realised that when configuring TxHeader FDFormat my mistake was:
TxHeader1.FDFormat = FDCAN_FRAME_FD_BRS;

however it should be 
TxHeader2.FDFormat = FDCAN_FD_CAN;

But anyways that solved my issue.

LCE
Principal II
February 6, 2026

I just had a look at the G4 FDCAN, and the memory is really heavily limited (basically only 3 TX buffers!) compared to the H723..H735 that I know.

I would have suspected that there is your problem, but nice that you found it.

Better check your CAN memory handling anyway.

And in case of doubt, like FIFO level, always check the registers directly.