Skip to main content
Visitor II
April 4, 2024
Solved

FDCAN transmitting wrong data and crashing peripheral

  • April 4, 2024
  • 1 reply
  • 1087 views

Hey, I am trying to send 20 messages over FDCAN using the G0B1RE Nucleo board. The problem is that only a few messages arrive (~12 most of the time), the messages have wrong data and sometimes it crashes the FDCAN-Module. When it crashes the HAL_FDCAN_RxFifo0Callback is not being called anymore, no more messages are being sent and no error code is generated yet all HAL FDCAN functions return HAL_OK.

 

I am sending the first message via HAL_FDCAN_AddMessageToTxFifoQ in my main loop and every following message in the HAL_FDCAN_TxBufferCompleteCallback

/*SENDING THE MESSAGES*/

FDCAN_TxHeaderTypeDef header;
header.Identifier = 0;
header.IdType = FDCAN_STANDARD_ID;
header.TxFrameType = FDCAN_DATA_FRAME;
header.ErrorStateIndicator = FDCAN_ESI_PASSIVE;
header.BitRateSwitch = FDCAN_BRS_OFF;
header.FDFormat = FDCAN_CLASSIC_CAN;
header.TxEventFifoControl = FDCAN_NO_TX_EVENTS;
header.MessageMarker = 0;
header.DataLength = FDCAN_DLC_BYTES_8;

uint8_t buf[32] = {0};
memset(buf, 0x31, sizeof(buf));
memset(buf + 16, 0x55, 8);
for(uint8_t i = 0; i < 20; i++)
{
	header.Identifier = i;
	send_msg(phfdcan, header, buf + 16);
}

/* INIT */

hfdcan1.Instance = FDCAN1;
 hfdcan1.Init.ClockDivider = FDCAN_CLOCK_DIV6;
 hfdcan1.Init.FrameFormat = FDCAN_FRAME_CLASSIC;
 hfdcan1.Init.Mode = FDCAN_MODE_NORMAL;
 hfdcan1.Init.AutoRetransmission = DISABLE;
 hfdcan1.Init.TransmitPause = DISABLE;
 hfdcan1.Init.ProtocolException = DISABLE;
 hfdcan1.Init.NominalPrescaler = 1;
 hfdcan1.Init.NominalSyncJumpWidth = 16;
 hfdcan1.Init.NominalTimeSeg1 = 5;
 hfdcan1.Init.NominalTimeSeg2 = 2;
 hfdcan1.Init.DataPrescaler = 1;
 hfdcan1.Init.DataSyncJumpWidth = 16;
 hfdcan1.Init.DataTimeSeg1 = 1;
 hfdcan1.Init.DataTimeSeg2 = 1;
 hfdcan1.Init.StdFiltersNbr = 1;
 hfdcan1.Init.ExtFiltersNbr = 0;
 hfdcan1.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION;

 

    This topic has been closed for replies.
    Best answer by SvenBordihn

    I didnt want to include the whole send_msg implementation because it boils down to taking a message out of a buffer, checking HAL_FDCAN_GetTxFifoFreeLevel and transmitting it with HAL_FDCAN_AddMessageToTxFifoQ.

     

    The problem was caused by the cheap USB-CAN Analyzer and not the st board. I verified this by using an Oscilloscope with a CAN decode feature

    1 reply

    Technical Moderator
    April 4, 2024

    Hello,

    You need to debug the issue. Do you face Hardfaut exception?

    what about send_msg() implementation?

    send_msg(phfdcan, header, buf + 16);

     Since you're using  G0B1RE Nucleo board, are you using a CAN transceiver + another node connected to the bus? If not this is not a normal operation of CAN in Normal mode. Use Loopback mode instead.

    SvenBordihnAuthorAnswer
    Visitor II
    April 5, 2024

    I didnt want to include the whole send_msg implementation because it boils down to taking a message out of a buffer, checking HAL_FDCAN_GetTxFifoFreeLevel and transmitting it with HAL_FDCAN_AddMessageToTxFifoQ.

     

    The problem was caused by the cheap USB-CAN Analyzer and not the st board. I verified this by using an Oscilloscope with a CAN decode feature