Skip to main content
GRoss.5
Associate II
Nov 24, 2020 10:26 PM UTC
Solved

Calling HAL_FDCAN_AddMessageToTxBuffer to Tx on FDCAN always end up in the following error condition: See CANFD_Error.png. Main.c has all FDCAN initialization and use.

This topic has been closed for replies.
TOlli
TOlliBest answer
Senior
Nov 25, 2020 6:14 AM UTC

Hi,

It looks to me that you are not assigning any space for any kind of tx queue or buffer:

row ~378:

  hfdcan1.Init.TxEventsNbr = 0;

  hfdcan1.Init.TxBuffersNbr = 0;

  hfdcan1.Init.TxFifoQueueElmtsNbr = 0;

  hfdcan1.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION;

You need to allocate how many elements are reserved for example for the queue. Otherwise there is no reservation in the RAM and no place for the function call to place the data in.

Same thing goes for rx fifo buffers.

Best regards

3 replies

TOlli
TOlliBest answer
Senior
Nov 25, 2020 6:14 AM UTC

Hi,

It looks to me that you are not assigning any space for any kind of tx queue or buffer:

row ~378:

  hfdcan1.Init.TxEventsNbr = 0;

  hfdcan1.Init.TxBuffersNbr = 0;

  hfdcan1.Init.TxFifoQueueElmtsNbr = 0;

  hfdcan1.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION;

You need to allocate how many elements are reserved for example for the queue. Otherwise there is no reservation in the RAM and no place for the function call to place the data in.

Same thing goes for rx fifo buffers.

Best regards

TOlli
Senior
Nov 27, 2020 6:30 AM UTC

If the above was good enough answer to help you solve the issue, please select it as the answer to help others in the future.

Kaveh
Associate III
Nov 30, 2020 4:29 PM UTC

As suggested by "TOlli" it is a RAM assignment issue. I added "CAN1.Init.TxBuffersNbr = 2;" to my CAN_Init function and worked just fine after that.

Here is the complete CAN Init function function.

void CAN1_Init(void)
{
	CAN1.Instance = FDCAN1;
	CAN1.Init.FrameFormat = FDCAN_FRAME_CLASSIC;
	CAN1.Init.Mode = FDCAN_MODE_EXTERNAL_LOOPBACK;		// EXTERNAL Means FDCAN treats its own transmitted messages as received messages
	CAN1.Init.AutoRetransmission = ENABLE;
	CAN1.Init.NominalPrescaler = 3;		// Setting values for 500k bps
	CAN1.Init.NominalSyncJumpWidth = 1;
	CAN1.Init.NominalTimeSeg1 = 2;
	CAN1.Init.NominalTimeSeg2 = 2;
	CAN1.Init.TxBuffersNbr = 2;
 
	if (HAL_FDCAN_Init(&CAN1) != HAL_OK)
	 {
	 Error_Handler();
	 }
 
}