Skip to main content
Associate II
January 28, 2026
Question

The issue of clock configuration for STM32F446RCT6

  • January 28, 2026
  • 6 replies
  • 734 views

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

 

6 replies

乒乓_itAuthor
Associate II
January 28, 2026

Threads murged for the same question.

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 freque

void SystemClock_Config (void)

 RCC_OscInitTypeDef RCC_OscInitStruct = {0};
 RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};

 */
 HAL_RCC_PWR CLK_ENABLE ();
 HAL_PWR_VOLTAGESCALING_CONFIG (PWR_REGULATOR_VOLTAGE_SCALE1);

 */
 RCC_OscInitStruct. OscillatorType = RCC_OSCILLATORTYPE_HSE;
 RCC_OscInitStruct. HSEState = RCC_HSE ON;
 RCC_OscInitStruct. PLL. PLLState = RCC_PLL_ON;
 RCC_OscInitStruct. PLL. PLLSource = RCC_PLLSOURCE_HSE;
 RCC_OscInitStruct. PLL. PLLM = 4;
 RCC_OscInitStruct. PLL. PLLN = 180;
 RCC_OscInitStruct. PLL. PLLP = RCC_PLLP_DIV2;
 RCC_OscInitStruct. PLL. PLLQ = 2;
 RCC_OscInitStruct. PLL. PLLR = 2;
 if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL OK)
 {
 Error Handler () ;
 }

 RCC_ClkInitStruct. ClockType = RCC CLOCKTYPE HCLK | RCC CLOCKTYPE SYSCLK
 RCC_CLOCKTYPE PCLK1 | RCC CLOCKTYPE PCLK2;
 RCC_ClkInitStruct. SYSCLKSource = RCC SYSCLKSOURCE PLLCLK;
 RCC_ClkInitStruct . AHBCLKDivider = RCC SYSCLK DIV1;
 RCC_ClkInitStruct. APB1CLKDivider = RCC HCLK DIV4;
 RCC_ClkInitStruct. APB2CLKDivider = RCC HCLK DIV2;
 
 if (HAL PWREx EnableOverDrive () != HAL OK)
 {
 Error Handler () ;
 }

 if (HAL RCC_ClockConfig (&RCC_ClkInitStruct, FLASH_LATENCY_5) != HAL OK)
 {
 Error Handler();
 }

Edited to apply source code formatting - please see How to insert source code for future reference.

TDK
Super User
January 28, 2026

Please edit your post to have a proper title and post your question within the message.

Please indicate the full part number of the chip you are using.

How to write your question to maximize your chance... - STMicroelectronics Community

"If you feel a post has answered your question, please click ""Accept as Solution""."
mƎALLEm
Technical Moderator
January 28, 2026

Hello @乒乓_it and welcome to the ST community,

What crystal value you've attached to HSE? you should not exceed 8MHz in that configuration.

"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."
乒乓_itAuthor
Associate II
January 28, 2026

The external clock I configured is 8 MHz.

Associate II
January 28, 2026

Is the crystal really 8 MHz?

The MCU might get in trouble when you configure 8 MHz but the reality is e.g. 16 MHz...

mƎALLEm
Technical Moderator
January 28, 2026

@mfgkw wrote:

Is the crystal really 8 MHz?

The MCU might get in trouble when you configure 8 MHz but the reality is e.g. 16 MHz...


This is what I'm suspecting.

"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."
乒乓_itAuthor
Associate II
January 29, 2026

_0-1769647418184.png

The external crystal oscillator is indeed 8 MHz.

Associate II
January 29, 2026

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?

乒乓_itAuthor
Associate II
January 29, 2026

_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.

TDK
Super User
January 29, 2026

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""."
乒乓_itAuthor
Associate II
February 10, 2026

 

_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

mƎALLEm
Technical Moderator
February 10, 2026

Hello @乒乓_it ,

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."
Associate III
February 11, 2026

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.