cancel
Showing results for 
Search instead for 
Did you mean: 

STM32U5 FDCAN permanently retransmitting with retransmission disabled

jeremyh
Associate II

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).

- I have run the same code as above on a NUCLEO-H743ZI by copy+pasting it in. The only real difference I think is the configuration of the buffers and the use of the MCO clock source. On this MCU, everything worked fine and as expected.

 

Here is a screenshot of the ACK working (top is CAN_RX at STM32, bottom is CAN_TX):

RigolDS1.png

 

And when the PEAK adapter is in listen only mode:

RigolDS2.png

 

Could you please help me understand why this is happening? I have attached the full project to this post.

 

1 REPLY 1
jeremyh
Associate II

Interestingly, the IOC clock configuration showed no errors, but I noticed that my SYSCLK was fairly low compared to the FDCAN1 clock (48MHz vs 128MHz). I adjusted this so that they were both equal (128MHz) and now the problem seems to have disappeared.

I can't find any mention of this in the reference manual, datasheet or in the errata sheet. Perhaps one of these needs to be updated to include this (or the clock constraints in the CubeMX package need to be fixed).