Skip to main content
GRoss.5
Associate II
November 24, 2020
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.

  • November 24, 2020
  • 3 replies
  • 3665 views
This topic has been closed for replies.
Best answer by TOlli

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
November 25, 2020

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
November 27, 2020

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
November 30, 2020

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();
	 }
 
}