2020-12-06 04:42 PM
Hello,
My code gets stuck in "Activate the corresponding transmission request" when calling "HAL_FDCAN_AddMessageToTxFifoQ"
Here is where it actually gets stuck in stm32h7xx_hal_fdcan.c:
/* Activate the corresponding transmission request */
hfdcan->Instance->TXBAR = ((uint32_t)1 << PutIndex);
CAN Init:
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();
}
}
CAN transmit:
void CAN1_TX(void)
{
FDCAN_TxHeaderTypeDef TX_Header;
uint8_t CAN_Msg_Ptr[5] = {'H', 'E', 'L', 'L', 'R'};
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();
}
}
Solved! Go to Solution.
2020-12-07 06:54 AM
It was an endless loop. Oddly enough I made bellow changes in the CAN init and issue is fixed.
Basically changing the Nominal to Data in all bellow line.
CAN1.Init.DataPrescaler = 3; // Setting values for 500k bps
CAN1.Init.DataSyncJumpWidth = 1;
CAN1.Init.DataTimeSeg1 = 2;
CAN1.Init.DataTimeSeg2 = 2;
2020-12-06 10:18 PM
"gets stuck" is not quite an exact description.
Does it end up in a fault handler, or in an endless loop ?
Try switching to instruction step / assembler view in your debugger, and single-step through the associated instructions.
2020-12-07 06:54 AM
It was an endless loop. Oddly enough I made bellow changes in the CAN init and issue is fixed.
Basically changing the Nominal to Data in all bellow line.
CAN1.Init.DataPrescaler = 3; // Setting values for 500k bps
CAN1.Init.DataSyncJumpWidth = 1;
CAN1.Init.DataTimeSeg1 = 2;
CAN1.Init.DataTimeSeg2 = 2;