cancel
Showing results for 
Search instead for 
Did you mean: 

Are there any solution about the CAN buffer overwriting?

otcagon
Associate II

I am currently working for the interface controller and it interface the two different CAN speed.

But sometimes the received CAN buffer looks is overwriting with new messages under high CAN messaged load conditions.

These are FDCAN1 and FDCAN2 setting with interrupt enabled.

void MX_FDCAN1_Init(void)

{

 hfdcan1.Instance = FDCAN1;

 hfdcan1.Init.FrameFormat = FDCAN_FRAME_CLASSIC;

 hfdcan1.Init.Mode = FDCAN_MODE_NORMAL;

 hfdcan1.Init.AutoRetransmission = ENABLE;

 hfdcan1.Init.TransmitPause = DISABLE;

 hfdcan1.Init.ProtocolException = DISABLE;

 hfdcan1.Init.NominalPrescaler = 4;

 hfdcan1.Init.NominalSyncJumpWidth = 8;

 hfdcan1.Init.NominalTimeSeg1 = 31;

 hfdcan1.Init.NominalTimeSeg2 = 8;

 hfdcan1.Init.DataPrescaler = 4;

 hfdcan1.Init.DataSyncJumpWidth = 8;

 hfdcan1.Init.DataTimeSeg1 = 31;

 hfdcan1.Init.DataTimeSeg2 = 8;

 hfdcan1.Init.MessageRAMOffset = 0;

 hfdcan1.Init.StdFiltersNbr = 1;

 hfdcan1.Init.ExtFiltersNbr = 1;

 hfdcan1.Init.RxFifo0ElmtsNbr = 2;

 hfdcan1.Init.RxFifo0ElmtSize = FDCAN_DATA_BYTES_8;

 hfdcan1.Init.RxFifo1ElmtsNbr = 1;

 hfdcan1.Init.RxFifo1ElmtSize = FDCAN_DATA_BYTES_8;

 hfdcan1.Init.RxBuffersNbr = 0;

 hfdcan1.Init.RxBufferSize = FDCAN_DATA_BYTES_8;

 hfdcan1.Init.TxEventsNbr = 0;

 hfdcan1.Init.TxBuffersNbr = 0;

 hfdcan1.Init.TxFifoQueueElmtsNbr = 32;

 hfdcan1.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION;

 hfdcan1.Init.TxElmtSize = FDCAN_DATA_BYTES_8;

 if (HAL_FDCAN_Init(&hfdcan1) != HAL_OK)

 {

  Error_Handler();

 }

}

/* FDCAN2 init function */

void MX_FDCAN2_Init(void)

{

 hfdcan2.Instance = FDCAN2;

 hfdcan2.Init.FrameFormat = FDCAN_FRAME_CLASSIC;

 hfdcan2.Init.Mode = FDCAN_MODE_NORMAL;

 hfdcan2.Init.AutoRetransmission = ENABLE;

 hfdcan2.Init.TransmitPause = DISABLE;

 hfdcan2.Init.ProtocolException = DISABLE;

 hfdcan2.Init.NominalPrescaler = 8;

 hfdcan2.Init.NominalSyncJumpWidth = 8;

 hfdcan2.Init.NominalTimeSeg1 = 31;

 hfdcan2.Init.NominalTimeSeg2 = 8;

 hfdcan2.Init.DataPrescaler = 8;

 hfdcan2.Init.DataSyncJumpWidth = 8;

 hfdcan2.Init.DataTimeSeg1 = 31;

 hfdcan2.Init.DataTimeSeg2 = 8;

 hfdcan2.Init.MessageRAMOffset = 0;

 hfdcan2.Init.StdFiltersNbr = 1;

 hfdcan2.Init.ExtFiltersNbr = 1;

 hfdcan2.Init.RxFifo0ElmtsNbr = 2;

 hfdcan2.Init.RxFifo0ElmtSize = FDCAN_DATA_BYTES_8;

 hfdcan2.Init.RxFifo1ElmtsNbr = 2;

 hfdcan2.Init.RxFifo1ElmtSize = FDCAN_DATA_BYTES_8;

 hfdcan2.Init.RxBuffersNbr = 0;

 hfdcan2.Init.RxBufferSize = FDCAN_DATA_BYTES_8;

 hfdcan2.Init.TxEventsNbr = 0;

 hfdcan2.Init.TxBuffersNbr = 0;

 hfdcan2.Init.TxFifoQueueElmtsNbr = 32;

 hfdcan2.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION;

 hfdcan2.Init.TxElmtSize = FDCAN_DATA_BYTES_8;

 if (HAL_FDCAN_Init(&hfdcan2) != HAL_OK)

 {

  Error_Handler();

 }

}

void HAL_FDCAN_RxFifo0Callback(FDCAN_HandleTypeDef *hfdcan, uint32_t RxFifo0ITs)

{

// Receive from DX12 ECU

if (hfdcan->Instance == FDCAN1)

{

if((RxFifo0ITs & FDCAN_IT_RX_FIFO0_NEW_MESSAGE) != 0)

{

/* Retrieve Rx messages from RX FIFO0 */

if (HAL_FDCAN_GetRxMessage(&hfdcan1, FDCAN_RX_FIFO0, &FDCAN_Rx, CAN1_buf_rx) != HAL_OK)

{

Error_Handler();

}

else

{

// 1. CCVS (Cruise Control Vehicle Speed)

if(FDCAN_Rx.Identifier == C1R_CCVS)

{

Rx_MSG_FDCAN1_CCVS();

FDCAN2_Send_Msg(C1R_CCVS, CAN1_buf_rx, FDCAN_DLC_BYTES_8);

}

......

void HAL_FDCAN_RxFifo1Callback(FDCAN_HandleTypeDef *hfdcan, uint32_t RxFifo1ITs)

{

 /* Prevent unused argument(s) compilation warning */

// Receive from DX12 ECU

if (hfdcan->Instance == FDCAN1)

{

if((RxFifo1ITs & FDCAN_IT_RX_FIFO1_NEW_MESSAGE) != 0)

{

/* Retrieve Rx messages from RX FIFO0 */

if (HAL_FDCAN_GetRxMessage(&hfdcan1, FDCAN_RX_FIFO1, &FDCAN_Rx, CAN1_buf_rx) != HAL_OK)

{

Error_Handler();

}

else

{

// 1. CCVS (Cruise Control Vehicle Speed)

if(FDCAN_Rx.Identifier == C1R_CCVS)

{

Rx_MSG_FDCAN1_CCVS();

FDCAN2_Send_Msg(C1R_CCVS, CAN1_buf_rx, FDCAN_DLC_BYTES_8);

}

....

Please help me to solve the current issue.

If I send the one message step by step then no problem.

Thank you

1 REPLY 1
korifey
Associate

Hi,

This should help:

End of function

MX_FDCAN2_Init()
  hfdcan2.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION;
  hfdcan2.Init.TxElmtSize = FDCAN_DATA_BYTES_8;
  hfdcan2.Init.MessageRAMOffset = (((hfdcan1.msgRam.EndAddress - SRAMCAN_BASE) / 4U) + 1U);
  if (HAL_FDCAN_Init(&hfdcan2) != HAL_OK)
  {
    Error_Handler();
  }

 

Have fun with 2 can instances.