2025-03-21 7:06 PM - edited 2025-03-21 7:41 PM
Hi,
For a reason that I cannot explain, the STM32U575ZI (on the nucleo board) is sending a CAN bus message with infinite repeats and 100% bus utilisation, but I have repeated transmission turned off (DAR bit set to 1) and I have confirmed this using the debugger. It continues to send this message at full rate even if I pause the device in the debugger.
My code is configured to send a packet with a changing ID from 0 to 4, but the repeated message always has the same ID (0x1, the first message that was queued), indicating that the message is stuck in the TX FIFO. FDCAN_TXBRP is always 0x1. Interrupts for the FDCAN peripheral are not enabled.
I have the following code as my main loop:
if (HAL_FDCAN_Start(&hfdcan1) != HAL_OK)
{
Error_Handler();
}
FDCAN_TxHeaderTypeDef header;
header.Identifier = 0;
while (1)
{
const uint8_t tx_data[] = {0x01, 0x23, 0x45};
while (HAL_FDCAN_GetTxFifoFreeLevel(&hfdcan1) != 3) {
HAL_Delay(1);
}
header.Identifier = (header.Identifier+1) % 5;
header.IdType = FDCAN_EXTENDED_ID;
header.TxFrameType = FDCAN_DATA_FRAME;
header.DataLength = FDCAN_DLC_BYTES_3;
header.ErrorStateIndicator = FDCAN_ESI_ACTIVE;
header.BitRateSwitch = FDCAN_BRS_OFF;
header.FDFormat = FDCAN_CLASSIC_CAN;
header.TxEventFifoControl = FDCAN_NO_TX_EVENTS;
header.MessageMarker = 0x00;
if (HAL_FDCAN_AddMessageToTxFifoQ(&hfdcan1, &header, tx_data) != HAL_OK)
{
Error_Handler();
}
HAL_Delay(100);
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
}
Everything else is configured through CubeIDE and the IOC file.
I have PD0/PD1 connected to a MCP2542FD transceiver. The CAN side of the bus is wired directly to a PEAK-USB FD Pro (wires about 10cm), and both ends have a 120 ohm between the CAN_H/CAN_L pair. I am using the viewer software that comes with the adapter, but I have also confirmed this behaviour on an oscilloscope. The PEAK-USB adapter is indeed ACKing all of the packets according to the oscilloscope and is not reporting any bus errors.
Some other things I have tried:
- Disconnecting and reconnecting the CAN_TX or CAN_RX pins causes the transmissions to stop (as expected). When reconnected the transmissions do not begin again until the device is reset.
- Running the code without the debugger connected shows the same behaviour
- The TX FIFO free level is permanently fixed at 2 (out of 3, which would be empty)
- Very occasionally (perhaps 1 in 50 times) everything works fine and I do get the messages with the different addresses at the expected interval. But if I attach the debugger and then do a soft reset through the debugger, the problem returns.
- If I put the PEAK adapter in listen-only mode, the problem goes away (but obviously there are no ACKs then).
Here is a screenshot of the ACK working (top is CAN_RX at STM32, bottom is CAN_TX):
And when the PEAK adapter is in listen only mode:
Could you please help me understand why this is happening? I have attached the full project to this post.