cancel
Showing results for 
Search instead for 
Did you mean: 

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.

GRoss.5
Associate II

0693W000005CXo8QAG.png

1 ACCEPTED SOLUTION

Accepted Solutions
TOlli
Senior

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

View solution in original post

3 REPLIES 3
TOlli
Senior

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

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

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