2025-09-11 7:39 AM - last edited on 2025-09-16 3:03 AM by mƎALLEm
ST moderator edited the title to give more visibility on the issue/subject
Hello,
I have a board with an STM32C092KCU6 where the main clock is using the HSI48 internal oscillator but I also have an 8MHz crystal for the HSE oscillator to use for FDCAN for higher precision. When the HSE is clocking just the FDCAN module the CAN does not work.
I can get the CAN to work by using HSI48 as the FDCAN clock source. I can also get the CAN to work if I use HSE as the main clock (but it is too slow) or if I enable the clock output MCO2 with HSE as its source or also if I enable the RTC module and set HSE as its source.
So it seems that the HSE oscillator will only work if it is being used on FDCAN + one other place.
Osc for core
|
CAN clk
|
RTC clk
|
MCO2
|
CAN working?
|
HSI48
|
HSE
|
-
|
-
|
No
|
HSE
|
HSE
|
-
|
-
|
Yes
|
HSI48
|
INT
|
-
|
-
|
Yes |
HSI48
|
HSE
|
HSE
|
-
|
Yes |
HSI48
|
HSE
|
-
|
HSE
|
Yes |
HSI48
|
HSE
|
-
|
HSI48
|
No
|
I first thought this was a gain margin or a drive problem but I calculated that Gm is 7.57 for the crystal I have used. Also, my colleague has tried this on a C092 Nucleo board and says he can see the same thing.
Any clues as to what the problem might be would be appreciated.
Many thanks.
Solved! Go to Solution.
2025-09-17 7:30 AM - edited 2025-09-17 9:11 AM
Hello,
After doing the difference between both code sources, I noticed the following line was different:
Working:
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI|RCC_OSCILLATORTYPE_HSE;
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
Not working:
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
So it seems like CubeMx does generate the code related to HSE only if we enable something related to HSE example enabling MCO2 to output HSE or setting the system clock to HSE but it doesn't generate the code related to the HSE when only HSE was selected as source clock for the FDCAN.
I'm escalating this behavior to CubeMx team for analysis and for eventual fix.
So from your side, in RCC configuration, replace:
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
by:
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI|RCC_OSCILLATORTYPE_HSE;
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
and it will work. For sure you need to replace these lines each time you generate the code.
Internal ticket number for follow-up: 217709 not accessible by the ST community members.
This post will be moved to CubeMx forum board as it seems to be a CubeMx issue.
2025-09-11 7:50 AM - edited 2025-09-11 7:53 AM
Hello @Neiliow ,
First, with CAN/CAN-FD it's not recommended to use any of the internal clock source HSI/HSI48 etc .. You should use an external precise clock source with HSE: crystal or crystal oscillator.
Second, please refer to this article as you could be in the same situation as what is described in this article: FAQ: Fixing STM32 FDCAN communication disruptions - APB bus, kernel, and time quanta clocks
The FDCAN requires that the CAN time quanta clock is always below the APB clock:
fdcan_tq_ck < fdcan_pclk
2025-09-11 8:52 AM
Hello mƎALLEm,
Thank you for your reply and for the link to that article. I need to read it in more detail, however -
1. I was just using HSI48 clock to test the CAN. In my design I want to use HSE as the FDCAN clock and that is what is not working.
2. I think my clock configuration shown below meets the requirements since my APB clock is 48MHz and the FDCAN clock is 8MHz.
Kind regards,
Neil
2025-09-11 9:14 AM - edited 2025-09-11 9:30 AM
First, start by using one of the loopback modes. Do you face the same issue with that config? this is important to know from which way to go..
Second, what is the sample point set and what is the mode used: classical/CAN-FD? what are the BS1, BS2 values?
Third, you didn't tell what do you mean by "is not working"! wrong frames? communication doesn't start at all? other?
2025-09-12 12:52 AM
Hi,
Thanks for your suggetions.
The FDCAN is configured as -
which are the same settings for Tq, Tseg1, Tseg2, etc as we have used in other designs, although they are based on F042 / F072 devices. This is the first design where I have used the C092.
I am testing it by trying to periodically transmit a message out to the CAN bus. By 'not working' I mean the message is not being sent. If I then change the clock settings to either use the HSI48 clock (and change the prescaler to 6 to keep Tq=125ns) or if I enable MCO2 sourced from from HSE or if I enable the RTC and use HSE as its clock source then the message is sent. This is reliable and works every time.
I have ordered some different crystals to see if that could be the problem but one of my colleagues has a C092 Nucleo board and he says he can see the same thing happening so I'm not sure that is the cause.
2025-09-12 12:59 AM
Hello,
As I said previously, please try with External Loopback mode and see what happens on Tx. Unfortunately, I don't have STM32C092 chip to test.
2025-09-12 1:15 AM
OK, I tried it in external loopack mode and basically the same -
CAN clock from HSE : nothing on CANTx / CANRx
CAN clock from HSI : continuous CAN data packets on CANTx / CANRx
CAN clock from HSE + MCO2 from HSE : continuous CAN data packets on CANTx / CANRx
2025-09-12 2:32 AM - edited 2025-09-12 2:35 AM
Hello,
Thank you for the feedback. Is that possible to attach two minimal projects in loopback mode (working/not working) that reproduces the behavior? Hopefully I can find a NUCLEO-C092RC to test it.
2025-09-12 4:43 AM
No problem. I have attached the project (as it is for our target hardware). To toggle between working / not working Enable / Disable the "Master Clock Output 2" in the RCC configuration, using HSE as the MCO2 clock source.
We are not currently using the MCO2 pin (PB2) so it isn't a problem to use it for this test.
It should send a CAN message every 200ms.
Hope that gives you something you can work with.
2025-09-12 5:05 AM
Sorry something I didn't catch in your issue. When you say:
"To toggle between working / not working Enable / Disable the "Master Clock Output 2" in the RCC configuration, using HSE as the MCO2 clock source."
Do you mean the issue is related to the enable/disable of the Master Clock Output 2?
So if you enable MCO2 it's working, otherwise not?