cancel
Showing results for 
Search instead for 
Did you mean: 

FDCAN in normal mode is not working

TArre.1
Associate III

Hi!

I am using the stm32mp157C-DK2 board to communicate via FDCAN and my idea is to use it as normal mode to send and receive CAN messages. For this I have created a program in stm32cubeide and I enable FDCAN1 with the following parameters (125Kb/s):

 hfdcan1.Instance = FDCAN1;

 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 = 8;

 hfdcan1.Init.NominalSyncJumpWidth = 3;

 hfdcan1.Init.NominalTimeSeg1 = 20;

 hfdcan1.Init.NominalTimeSeg2 = 3;

 hfdcan1.Init.DataPrescaler = 16;

 hfdcan1.Init.DataSyncJumpWidth = 6;

 hfdcan1.Init.DataTimeSeg1 = 5;

 hfdcan1.Init.DataTimeSeg2 = 6;

 hfdcan1.Init.MessageRAMOffset = 0;

 hfdcan1.Init.StdFiltersNbr = 1;

 hfdcan1.Init.ExtFiltersNbr = 0;

 hfdcan1.Init.RxFifo0ElmtsNbr = 1;

 hfdcan1.Init.RxFifo0ElmtSize = FDCAN_DATA_BYTES_8;

 hfdcan1.Init.RxFifo1ElmtsNbr = 0;

 hfdcan1.Init.RxFifo1ElmtSize = FDCAN_DATA_BYTES_8;

 hfdcan1.Init.RxBuffersNbr = 0;

 hfdcan1.Init.RxBufferSize = FDCAN_DATA_BYTES_8;

 hfdcan1.Init.TxEventsNbr = 0;

 hfdcan1.Init.TxBuffersNbr = 0;

 hfdcan1.Init.TxFifoQueueElmtsNbr = 5;

 hfdcan1.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION;

 hfdcan1.Init.TxElmtSize = FDCAN_DATA_BYTES_8;

 if (HAL_FDCAN_Init(&hfdcan1) != HAL_OK)

 {

  Error_Handler();

 }

I have also changed FDCAN1 pins to be able to connect to the board (FDCAN_RX --> PA11 and FDCAN_TX --> PA12). Finally, I have created the program to send message via CAN:

 while (1)

 {

 sprintf ((char *)TxData1, "CAN1: %d", indx++);

 if (HAL_FDCAN_AddMessageToTxFifoQ(&hfdcan1, &TxHeader1, TxData1)!= HAL_OK)

 {

 Error_Handler();

 }

 HAL_Delay (1000);

 }

But when I run this program, i can´tsend messages and always get the same error:

HAL_FDCAN_ERROR_FIFO_FULL;

It seems that the FDCAN is not sending messages.

Can somebody help me?

Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
PatrickF
ST Employee

Hi,

I don't know much about FDCAN, but I assume that if external loopback is ok then it mean the clocks are ok.

Maybe you have an electrical issue on your FDCAN transceiver (e.g. wrong signal levels at TX or RX) which might block the transmit.

Or maybe just because you are trying to transmit without any device able to receive (i.e no ACK), so TX will become full.

This is just my though, sorry not able to help you more.

Regards.

In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question.

View solution in original post

7 REPLIES 7
PatrickF
ST Employee

Hi @TArre.1​ 

I'm not knowledgeable for FDCAN, but did you have all the required clocks present to the IP ?

0693W00000WKDXzQAP.png 

0693W00000WKDYnQAP.png 

Regards,

In order to give better visibility on the answered topics, please click on 'Select as Best' on the reply which solved your issue or answered your question. See also 'Best Answers'

In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question.

Hi @PatrickF​ , thank you for your reply!

I see that i have to enable the clock. In my case, I have connected the FDCAN1 to HSE as you can see in the image:

0693W00000WKDjRQAX.pngIn the main program, I think I have enable this with the PeriphCommonClock_Config program:

void PeriphCommonClock_Config(void)

{

 RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};

 PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_CKPER;

 PeriphClkInit.CkperClockSelection = RCC_CKPERCLKSOURCE_HSE;

 if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)

 {

  Error_Handler();

 }

}

Is something missing in my program or do I have to change something?

Thanks!

PatrickF
ST Employee

Hi,

I assume you are in Development Boot mode, so HSE is not automatically started. Don't know if CubeMX generate the code for that (as in production mode, root clocks are managed by TF-A/uBoot/Linux).

Note that on DK2 board, the HSE should be started in 'digital bypass' mode.

I think you already checked that the FDCANEN bit in RCC is set.

Regards.

In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question.

Hi @PatrickF​ 

I am in engineering boot mode. I've tried in external loopback mode and everything is ok, but when I run this program in normal mode, I can't send messages and always get the same error:

HAL_FDCAN_ERROR_FIFO_FULL.

Now, I have tried to do with another source clock (HSI) but the result is the same.

How can I know if the clock is running?

Thanks!

PatrickF
ST Employee

Hi,

I don't know much about FDCAN, but I assume that if external loopback is ok then it mean the clocks are ok.

Maybe you have an electrical issue on your FDCAN transceiver (e.g. wrong signal levels at TX or RX) which might block the transmit.

Or maybe just because you are trying to transmit without any device able to receive (i.e no ACK), so TX will become full.

This is just my though, sorry not able to help you more.

Regards.

In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question.

Hi @PatrickF​ 

Thanks for your advice, I'll try to test it with other devices to see if it works for me ;)

ngoctoan150699
Associate III

hi, Have you fixed that error yet?