cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with clock configuration of STM32F401VCT6 MCU - works fine on 42MHz clock, but crashes when set to 84 MHz

MKola
Associate II

I'm programming a custom board built around the STM32F401 MCU and I'm having a hard time configuring the system clock.

I'm using a 8MHz external crystal and I'm trying to set up the PLL to get the maximum frequency given by the datasheet, i.e. 84MHz. I've double checked the values with the cubeMX Clock Configuration tab (i'm not using it to generate code though) and the reference manual, the resulting setup being like this:

pll_m = 8,
 
pll_n = 336,
 
pll_p = 4,
 
pll_q = 7.

the formula for SYSCLK frequency value is

SYSCLK_freq = HSE_freq/pll_m*pll_n/pll_p

which gives us

8MHz/8*336/4 = 84MHz

which is a maximal frequency the MCU can run on. There are some additional constrains on the clocks' values, but they are all satisfied with this setup.

The problem is, it doesn't work. The software crashes even before the main() function - the clock setup function is called from the initialization code in reset handler, and the mcu crashes shortly after setting the sysclk source to PLL.

Interestingly, everything works fine if I set the pll_m value to 16 instead of 8 - the MCU then runs on 42MHz.

The thing is, it shouldn't - the smallest input clock frequency tolerated by the PLL is 1MHz, but it's easy to see that in this case it's HSE_freq/pll_m = 8MHz/16 = 500KHz.

I've checked the HSE frequency with a scope and it indeed equals 8MHz, also checked the frequency of the working setup - indeed it is 42MHz.

The high clock frequency is not that critical and my application can run just fine on 42MHz, however I'm just curious and a little surprised as to why this happens.

I'm using the StdPeriph library to set up the clock and it takes care of setting the flash wait states to 2WS, which is appropriate value for 84MHz clock running at 3.3V, so it's not the flash issue I think.

Any ideas about what could I be doing wrong would be greatly appreciated

15 REPLIES 15

Should be working examples in the SPL. Even if you took the the 168MHz examples and moved P from 2 to 4

STM32F401 discovery firmware package

https://www.st.com/en/embedded-software/stsw-stm32136.html

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

That's exactly the thing I did, the initialization code is straight out of the SPL (in file system_stm32f4xx.c), I just changed the PLL values to match the value of HSE (SPL assumed 25MHz crystal)

I just created an empty project in CubeMX and the code crashed in the HAL_RCC_ClockConfig() function (after configuring the PLL as the system clock source)

I feel very dumb now - of course I forgot connecting the capacitor to the VCAP2 pin - will try soldering directly to the MCU pin and check if it fixes anything

well, of course it works now - turns out it was a hardware issue after all. Thanks everyone for helping!

Why, this is how we learn, from errors. Ours or others'. That's why I am here, to see as many others' errors as possible, in the hope that then my errors seem less pathetic... ;)

Thanks for coming back with the solution.

JW