cancel
Showing results for 
Search instead for 
Did you mean: 

STM32G431 CANFD with internal clock

kavinkumar
Associate III

Hi, I made an STM32G4 and TCAN1044VDRQ1 setup and tried to use the FDCAN, but I couldn't get it to work. There is no response from the transceiver. I tried all the bit timings and used calculators to compute the values. I used a USB-to-CAN FD analyzer and sent a message, but there is no response in the HAL_FDCAN_RxFifo0Callback interrupt.

It is not getting triggered when a message comes in. I don’t know what to do. I’ve spent too much time on this. Any help would be appreciated. Thank you. I don’t know what other details I need to share, if you think you need something, please let me know and I’ll send a reply.

void CAN_Init(uint8_t can_id) {
    hfdcan1.Instance = FDCAN1;
    hfdcan1.Init.ClockDivider = FDCAN_CLOCK_DIV1;
    hfdcan1.Init.FrameFormat = FDCAN_FRAME_FD_NO_BRS;
    hfdcan1.Init.Mode = FDCAN_MODE_NORMAL;
    hfdcan1.Init.AutoRetransmission = ENABLE;
    hfdcan1.Init.TransmitPause = DISABLE;
    hfdcan1.Init.ProtocolException = DISABLE;

    hfdcan1.Init.NominalPrescaler = 1;
    hfdcan1.Init.NominalSyncJumpWidth = 3;
    hfdcan1.Init.NominalTimeSeg1 = 8;
    hfdcan1.Init.NominalTimeSeg2 = 3;
    hfdcan1.Init.DataPrescaler = 1;
    hfdcan1.Init.DataSyncJumpWidth = 3;
    hfdcan1.Init.DataTimeSeg1 = 8;
    hfdcan1.Init.DataTimeSeg2 = 3;

    hfdcan1.Init.StdFiltersNbr = 1;
    hfdcan1.Init.ExtFiltersNbr = 0;
    hfdcan1.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION;

    if (HAL_FDCAN_Init(&hfdcan1) != HAL_OK) Error_Handler();

    sFilterConfig.IdType = FDCAN_STANDARD_ID;
    sFilterConfig.FilterIndex = 0;
    sFilterConfig.FilterType = FDCAN_FILTER_MASK;
    sFilterConfig.FilterConfig = FDCAN_FILTER_TO_RXFIFO0;
    sFilterConfig.FilterID1 = can_id;
    sFilterConfig.FilterID2 = 0x7FF;
    if (HAL_FDCAN_ConfigFilter(&hfdcan1, &sFilterConfig) != HAL_OK) Error_Handler();

    if (HAL_FDCAN_ConfigGlobalFilter(&hfdcan1, FDCAN_REJECT, FDCAN_REJECT, FDCAN_REJECT_REMOTE, FDCAN_REJECT_REMOTE) != HAL_OK) Error_Handler();

    if (HAL_FDCAN_Start(&hfdcan1) != HAL_OK) Error_Handler();
}
22 REPLIES 22
mƎALLEm
ST Employee

Hello,

Please no internal clock with CAN communication in Normal mode (HSI, CSI etc ..): CAN2.0/CANFD. That's not recommanded at all. You can use the internal clock only in Loopback mode.

Please use HSE with an external accurate clock source example a crystal (100ppm is sufficient).

Please refer to these articles:

STM32 FDCAN running at 8 Mb/s on NUCLEO boards

How to use STLINK-V3 MCO output on Nucleo boards as a precise clock source for STM32

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.

Still i tried in Loopback mode. that didn't work either.

For Normal mode use the provided example in the github: https://github.com/stm32-hotspot/CKB-STM32-FDCAN-8Mbs / Article: STM32 FDCAN running at 8 Mb/s on NUCLEO boards

Especially for G4: https://github.com/stm32-hotspot/CKB-STM32-FDCAN-8Mbs/tree/main/NUCLEO-G474

For Loopback mode: https://github.com/STMicroelectronics/STM32CubeG4/tree/master/Projects/STM32G474E-EVAL/Examples/FDCAN/FDCAN_Loopback

 

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.
Karl Yamashita
Principal

upload your IOC file.

I was told that if a devices starts to smoke, put the smoke back in. I guess I never got all the smoke because the device never worked afterwards.
Don't worry, I won't byte.
TimerCallback tutorial! | UART and DMA Idle tutorial!

If you find my solution useful, please click the Accept as Solution so others see the solution.
kavinkumar
Associate III

@Karl Yamashita  Thank you for replying. I have attached my IOC below. The only thing my working on is CANFD so only that is configured in the IOC I'm using the default PA11 and PA12 pins

will it work if i use the same bit timings for my transceiver too ?

Hello,

1- What is the mode you plan to use: Classic or FD?

2- Target bitrate? if FDCAN provide both Nominal and data phase bitrates

3- Better to attach your complete project. If not possible in public send it in private.

Please answer the three questions above.

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

1- I'm going to use CANFD

2- FDCAN (I'm not sure of the bitrate but i think 1Mbs is sufficient for my needs ) - i just need communication 

3-  I'll share my GitHub repo That would be better if somebody needs it they can use it.
STM32G431CANFD 

Also i saw your post on FDCAN bit time configuration but it doesn't tell how to get the values of 

NominalSyncJumpWidth and DataSyncJumpWidth

@kavinkumar wrote:

2- FDCAN (I'm not sure of the bitrate but i think 1Mbs is sufficient for my needs ) - i just need communication 

 

Not sure? how? you need to know and decide what bitrates you need to use for both Nominal and Data phases.

For FDCAN bit time please use Kvaser CANFD bit time tool.

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.