cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F051 - Question regarding external / internal oscillator

jai
Associate
Posted on February 22, 2016 at 12:27

Hi,

I have bread boarded STM32F051 and it's working. The clock is configured for external

8Mhz Crystal. Its working checked with scope. When i remove the crystal it seems to still work from internal oscillator. I would like switchover to be disabled. how can i do it.

using std peripheral lib.

Thanks,

Jai.

6 REPLIES 6
Posted on February 22, 2016 at 14:39

The processor always starts off the internal clock, you get to enable the external one and the PLL within the code under SystemInit(), where you get to choose what happens.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
re.wolff9
Senior
Posted on February 23, 2016 at 09:29

It works the other way around. The CPU starts in ''internal clock'' mode, and then in software enables the external crystal, waits for it to start running, and then switches to the external clock. 

Many ST-provided startup files will however have a section: ''handle clock error here''  that is empty. That empty section is executed when the external clock fails to start. 

From a software-point-of-view, I don't like editing those files: They are delivered to me, and whomever made them may have an update later on which I'll have to merge with my changes if I edit the file. 

I would add a check near the beginning of your application code: if (! external_clock_is_running () ) stop ();

pkumar1883
Associate II
Posted on February 23, 2016 at 12:43

dear kumar.jai.001,

First try to enable HSE if it fails then  disable  HSI by following piece of code-

RCC_HSICmd(DISABLE); 

/*Please

 mark helpfull

 if this post helps you or solves your problem.*/

/* If you need any personal support for your work please contact at 

embeddeddesign.help@gmail.com*/

Posted on February 23, 2016 at 21:19

From a software-point-of-view, I don't like editing those files: They are delivered to me, and whomever made them may have an update later on which I'll have to merge with my changes if I edit the file.

The system_stm32fxxx.c are supposed to be board/implementation specific, in your project directory, you are supposed to ''own'' them.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
re.wolff9
Senior
Posted on February 23, 2016 at 22:48

I understand that ST wants me to ''own'' them. So, next week, ST notices a bug in the old, or maybe NEW version of the STM32F072 that I use. Turns out there is a software fix, which is easy to implement in the startup file. ST distributes new startup files, but now, on a certain percentage of boards, my application doesn't work, while demo-apps from ST do work. After a lot of debugging..... I have to merge my changes into the changed version from ST. 

Whatever the scenario, ST tries to make me own that file, while in fact THEY wrote it and could possibly deliver an updated version in the future. 

That stuff is badly designed. e.g. the ''setup_clocks'' function in there could easily return ''FAILED'' when it fails to set the clocks as expected. Then my ''handle failed clock setup'' can be in /my/ main function where it belongs. 

I get to ignore the error like many people apparently do without knowing. See for example the person who started this thread.

Posted on February 24, 2016 at 02:03

Ok, but I don't think the code should be considered golden, it is a minimal template with the expectation that someone using it actually understands it and refines it.

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