cancel
Showing results for 
Search instead for 
Did you mean: 

STM32G474RE FDCAN not transmitting

DWils.1
Associate

I had FDCAN working on the G4 MCU before doing the firmware update from 1.0.1 to 1.1.0. Since the firmware update and upgrade from STM32CubeIDE 1.0.0 to 1.2.0, the FDCAN controller seems to not transmit any messages, even though the HAL_FDCAN_AddMessageToTxFifoQ succesfully copies the message to the RAM and sets the transmit flag for the first 2 messages. Further messages fail due to Fifo full error. I looked into the FDCAN classic networking example for the STM32G474E-EVAL.

This is my code:

int main(void)
{
  HAL_Init();
 
  SystemClock_Config();
 
  MX_GPIO_Init();
  MX_FDCAN1_Init();
 
  FDCAN_config();
 
  /* Infinite loop */
  while (1)
  {
	if(HAL_FDCAN_AddMessageToTxFifoQ(&hfdcan1, &TxHeader, TxData) != HAL_OK)
	{
		Error_Handler();
	}
	HAL_Delay(1000);
  }
}
static void MX_FDCAN1_Init(void)
{
  hfdcan1.Instance = FDCAN1;
  hfdcan1.Init.ClockDivider = FDCAN_CLOCK_DIV1;
  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 = 20;
  hfdcan1.Init.NominalSyncJumpWidth = 1;
  hfdcan1.Init.NominalTimeSeg1 = 14;
  hfdcan1.Init.NominalTimeSeg2 = 2;
  hfdcan1.Init.DataPrescaler = 1;
  hfdcan1.Init.DataSyncJumpWidth = 1;
  hfdcan1.Init.DataTimeSeg1 = 1;
  hfdcan1.Init.DataTimeSeg2 = 1;
  hfdcan1.Init.StdFiltersNbr = 1;
  hfdcan1.Init.ExtFiltersNbr = 0;
  hfdcan1.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION;
  if (HAL_FDCAN_Init(&hfdcan1) != HAL_OK)
  {
    Error_Handler();
  }
}
void FDCAN_config(void)
{
	FDCAN_FilterTypeDef sFilterConfig;
 
	sFilterConfig.IdType = FDCAN_STANDARD_ID;
	sFilterConfig.FilterIndex = 0;
	sFilterConfig.FilterType = FDCAN_FILTER_MASK;
	sFilterConfig.FilterConfig = FDCAN_FILTER_TO_RXFIFO0;
	sFilterConfig.FilterID1 = 0x000;
	sFilterConfig.FilterID2 = 0x7FF;
 
	if(HAL_FDCAN_ConfigFilter(&hfdcan1, &sFilterConfig) != HAL_OK)
	{
		Error_Handler();
	}
 
	if(HAL_FDCAN_ConfigGlobalFilter(&hfdcan1, FDCAN_REJECT, FDCAN_REJECT, FDCAN_FILTER_REMOTE, FDCAN_FILTER_REMOTE) != HAL_OK)
	{
		Error_Handler();
	}
 
	if(HAL_FDCAN_Start(&hfdcan1) != HAL_OK)
	{
		Error_Handler();
	}
 
	if(HAL_FDCAN_ActivateNotification(&hfdcan1, FDCAN_IT_RX_FIFO0_NEW_MESSAGE, 0) != HAL_OK)
	{
		Error_Handler();
	}
 
	TxHeader.Identifier = 0x123;
	TxHeader.IdType = FDCAN_STANDARD_ID;
	TxHeader.TxFrameType = FDCAN_DATA_FRAME;
	TxHeader.DataLength = FDCAN_DLC_BYTES_8;
	TxHeader.ErrorStateIndicator = FDCAN_ESI_ACTIVE;
	TxHeader.BitRateSwitch = FDCAN_BRS_OFF;
	TxHeader.FDFormat = FDCAN_CLASSIC_CAN;
	TxHeader.TxEventFifoControl = FDCAN_NO_TX_EVENTS;
	TxHeader.MessageMarker = 0;
}

Am I missing something or does anyone know how to fix the problem?

6 REPLIES 6
Bodri
Associate

I have the same problem with my custom STM32G474VEH board. I realised that the transmission works in external loop-back mode, but not in normal mode. You can also prevent the TX Fifo full error by disabling auto retransmit. Is there any solution/work-around?

SReyn.1
Associate

I can confirm this happens on my custom STM32G474CEU board, too.

Bodri is right, this appears to be an issue with AutoRetransmission. CAN communicates between two boards fine with it off, but when I turn it on, nothing happens.

e-zeki
Associate III

if your code works with internal loopback mode, check your tranceiver connections and end resistors. It'll work. I had the same sort of error on STM32G431RB NUCLEO, it turned out the wiring between two boards had some faults. I'm no expert but your code looks pretty normal to me.

Hi,

I have the same problem (CAN frames are not transmitted) with the STM3232G431RB NUCLEO.

I configured FDCAN_MODE_NORMAL, but nothing is sent on the pin. I still checked the wiring - everything seems good. I also checked the logical state with a oscilloscope, but the pin is not toggling. Any idea what the problem is.

P.S.: I copied the implementation from DWils.1, but I still have the problem...

Thanks

DWils.1
Associate

It turned out to be a transceiver problem. The code worked fine in internal loopback mode. For me it looked like i had a bad transceiver and after using another one it worked.

Thanks for the help!

So sorry to reply this late.

Did you checked your ESR register for any possible error occurance? and again, did you test your code on LOOPBACK mode?