cancel
Showing results for 
Search instead for 
Did you mean: 

CAN BUS "Check that the selected buffer has an allocated area into the RAM"

Kaveh
Associate III

Hello,

I am trying to set up the CAN protocol and receiving "Check that the selected buffer has an allocated area into the RAM" when using HAL_FDCAN_AddMessageToTxBuffer.

This is where the error is thrown, inside stm32h7xx_hal_fdcan.c

/* Check that the selected buffer has an allocated area into the RAM */
    if (POSITION_VAL(BufferIndex) >= ((hfdcan->Instance->TXBC & FDCAN_TXBC_NDTB) >> FDCAN_TXBC_NDTB_Pos))
    {
      /* Update error code */
      hfdcan->ErrorCode |= HAL_FDCAN_ERROR_PARAM;
 
      return HAL_ERROR;
    }

Here is CAN Initialization

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 = 64;
	CAN1.Init.TxEventsNbr = 32;
	CAN1.Init.TxFifoQueueElmtsNbr = 32;
	CAN1.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION;
	CAN1.Init.TxElmtSize = FDCAN_DATA_BYTES_16;
	CAN1.Init.MessageRAMOffset = 0;
	CAN1.Init.RxBuffersNbr = 64;
	CAN1.Init.RxFifo0ElmtsNbr = 64;
	CAN1.Init.RxFifo0ElmtSize = FDCAN_DATA_BYTES_16;
 
	if (HAL_FDCAN_Init(&CAN1) != HAL_OK)
	  {
	    Error_Handler();
	  }
 
}

And Transmit function:

void CAN1_TX(void)
{
	FDCAN_TxHeaderTypeDef TX_Header;
 
	uint8_t CAN_Msg_Ptr[5] = {'H', 'E', 'L', 'L', 'O'};
 
	TX_Header.DataLength = 1;
	TX_Header.Identifier = 0x7DF;
	TX_Header.IdType = FDCAN_STANDARD_ID;
	TX_Header.TxFrameType = FDCAN_DATA_FRAME;
	TX_Header.ErrorStateIndicator = FDCAN_ESI_ACTIVE;
	TX_Header.BitRateSwitch = FDCAN_BRS_OFF;
	TX_Header.FDFormat = FDCAN_CLASSIC_CAN;
	TX_Header.TxEventFifoControl = FDCAN_STORE_TX_EVENTS;
	TX_Header.MessageMarker = 0x00;
 
	if (HAL_FDCAN_AddMessageToTxBuffer(&CAN1, &TX_Header, CAN_Msg_Ptr, FDCAN_TX_BUFFER0) != HAL_OK)
	  {
	    Error_Handler();
 
	  }
 
}

1 ACCEPTED SOLUTION

Accepted Solutions
Kaveh
Associate III

There was a mistake in setting the CAN initialization values.

I had set "CAN1.Init.TxBuffersNbr" to 64 while max value is 32.

View solution in original post

1 REPLY 1
Kaveh
Associate III

There was a mistake in setting the CAN initialization values.

I had set "CAN1.Init.TxBuffersNbr" to 64 while max value is 32.