cancel
Showing results for 
Search instead for 
Did you mean: 

Wrong STM32 clock at startup

MarcoM
Associate II
Posted on March 31, 2014 at 15:44

Hello, I have a problem similar to the one discussed in the post named ''STM32F103RB - Different Clock Speed Between Reset?''

https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=https%3a%2f%2fmy%2est%2ecom%2fpublic%2fSTe2ecommunities%2fmcu%2fLists%2fcortex_mx_stm32%2fSTM32F103RB%20-%20Different%20Clock%20Speed%20Between%20Reset&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E...

My board have an STM32F103VET7 and there is an 8MHz xtal for the HSE oscillator.

When I flash a program, the clock speed is correct: all timings are ok (baud retes, ecc) and a GPIO pulse made from the SysTick timer set to 1ms give exactly a pulse of 1ms.

When I power down and up the board, the clock speed is completely wrong: the 1ms pulse becames about 12ms, and so on.

I observe that when I have fresly programmed the board the clock is ALWAYS correct, and on all the following power on the clock is ALWAYS wrong.

The software is developed on the CooCox IDE. I am using the standard ST startup. All things works correctly, except for this big clock problem.

I have a customer with a gun pointing to my head... please I need a good idea to solve the issue.

Thank you very much.

#rcc #smt32f103-clock-startup
3 REPLIES 3
Andrew Neil
Evangelist
Posted on March 31, 2014 at 15:48

Are you sure that the oscillator is actually starting correctly with your external crystal...?

Posted on March 31, 2014 at 17:38

As I recall CooCox breaks the CMSIS standard, and you need to call SystemInit() from main() to select clocks.

Have the board output diagnostic information about what clock sources are enabled and selected. Output internal clocks via MCO (PA8). Dump internal registers from RCC until you understand the differences in the operational modes you are observing.

Try testing things with a different tool chain.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
jpeacock2399
Associate II
Posted on March 31, 2014 at 21:31

From the description it sounds like you are referring to HCLK and SYSCLK not being at the expected frequency.  First, at what point do you enable the HSE, set the PLL multiplier and switch from HSI to HSE or PLLCLK oscillator?  After a reset the STM32 runs off the HSI oscillator, not HSE.  Have you checked the RCC registers to see what oscillators ar running and which one is selected for system clock?

You might be more precise in the problem description...is it a clock or an oscillator that isn't coming up right?  Oscillators are time base sources, clocks are consumers.  Your problem description seems to imply that you incorrectly expect the STM32 to start with the HSE enabled and selected as oscillator source for the system clock.  You might want to go over the RCC section of the reference manual to better understand clock sequencing on startup.

  Jack Peacock