Skip to main content
Explorer
July 15, 2025
Question

STM32G431 CANFD with internal clock

  • July 15, 2025
  • 4 replies
  • 1135 views

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();
}
    This topic has been closed for replies.

    4 replies

    Technical Moderator
    July 15, 2025

    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

    Explorer
    July 15, 2025

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

    Graduate II
    July 15, 2025

    upload your IOC file.

    Explorer
    July 16, 2025

    @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

    Technical Moderator
    July 16, 2025

    Hello,

    Attached an example in Loopback mode using HSI, Nominal: 500kb/s, Data: 1Mb/s.

    Please test it

     

    Explorer
    July 16, 2025

    Thank you for your time. I will test this code and let you know. i saw your code to know it is working i just need to see the if the data from TxData is copied to the RxData in the debug console right?

    Technical Moderator
    July 16, 2025

    I didn't test with the debug console. BufferCmp8b() was used for data comparison Rx vs Tx.

    Put two break points:

    1- One at Error_Handler() (line 194 ) -> comparison failed -> communication failed

    2- One at while(1) (line 200) -> comparison succeeded -> communication succeeded

    PS: the attached project is based on this example: https://github.com/STMicroelectronics/STM32CubeG4/tree/master/Projects/STM32G474E-EVAL1/Examples/FDCAN/FDCAN_Loopback