cancel
Showing results for 
Search instead for 
Did you mean: 

The issue of clock configuration for STM32F446RCT6

乒乓
Associate II

Why is it that when I set the clock frequency of the STM32 to a high frequency (180 MHz), the code will crash, but when I set it to a low frequency (72 MHz), the code can run normally?

_0-1769582293868.png

_1-1769582326658.png

 

18 REPLIES 18

_0-1769647418184.png

The external crystal oscillator is indeed 8 MHz.

I was not in doubt about the osc value on paper, but its real value.

Anyway, what's the use of resistor R20?

9aec12f7f36e7dd3d607ab9327d374de.jpg

The external clock is indeed 8 MHz. R20 is NC and no resistor is connected to it. When I tried the clock frequency at 80 MHz, the system would frequently enter the void HardFault Handler (void).

 

mfgkw
Senior III

Ok, then it should be 8 MHz.

Your clock intitialization looks like 100% autogenerated by CubeMX for 180 MHz.

Can you determine, when it runs into the error handler?

TDK
Super User

R18 should not be there.

Crystal appears to have 20 pF load capacitance so load capacitors should be about 2 * (20 pF - 5 pF) = 30 pF.

Guidelines for oscillator design on STM8AF/AL/S and STM32 MCUs/MPUs - Application note

 

What does the hard fault analyzer say is the reason for the hard fault?

 

Likely there is nothing wrong with the clock settings if they were generated by CubeMX. Try these settings on a known good board such as an ST Nucleo if you have one.

If you feel a post has answered your question, please click "Accept as Solution".

_2-1769669783012.png

 

_3-1769669782957.png

 

 

When I was conducting a single-step debugging, I reached the line: if (HAL RCC ClockConfig (&RCC ClkInitStruct, FLASH LATENCY 5)! =HAL OK) At this point, he directly entered the "void HardFault Handler (void)" section.

The clock configurations were all generated by CubeMX. I didn't make any changes and I'm not sure what the reason is.

乒乓
Associate II

 

_2-1770714773521.png_3-1770714796763.png

 

As shown in the above figure, this is the clock I configured with CubeMAX. The external clock is 8 MHz and the main frequency is 180 MHz. Then the code generated by CubeMAX is as follows: 

_4-1770714841537.png

_5-1770714866056.png

phenomenon:
        The clock is configured correctly and there is no reason for the code to crash in the "HardFault_Handler" function. However, when the configuration is set to a lower frequency, the code can run normally.
 cause:   
       The "bus wait" for Flash read operation is not effective.Although you have set FLASH_LATENCY_5 in your code, there might be the following issues at high frequencies: __HAL_FLASH_SET_LATENCY() is executed too late (for example, after PLL configuration but the Flash has  already been accessed at high frequency);The Flash voltage calibration of the chip has not been completed, resulting in the "actual non-effectiveness" of the 5 wait cycles configuration.
 The solution is as follows:
      Move the Flash wait cycle configuration to be performed before the PLL configuration (modify SystemClock_Config()).

_6-1770714899154.png

 

_8-1770714941312.png

Hello @乒乓 ,

I have a doubt regarding the measured frequency value with the oscilloscope here. 8.32MHz with a crystal of +/-10PPM!

mALLEm_3-1770741979788.png

Your oscillo screanshot:

 

mALLEm_1-1770741839689.png

So Could you please do two tests:

1- Measure the clock on one of the MCO outputs:

Example:

mALLEm_4-1770742101109.png

Do you get 8MHz?

2- Run your code with HSI at the same system clock frequency with the same flash latency. Do you get the same issue: getting a hard fault?

mALLEm_5-1770742199868.png

 

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.

Yes for me this 8.32MHz was immediately suspected. But if it really simply enought use without OC at 168MHz. By the way I did overclock NUCLEOF446 up to 240MHz it was work without any problem.