STM32F4 System Clock Testing – MCOx
Keywords: Embedded systems, ARM, STM32F4, Clock, Microcontroller Clock Output
Code Link: Source Code Github Keil- Bare-Metal
Code Link: Source Code Github Keil- HAL Libraries
In previous tutorials we discussed what are different clock source available on STM32 and how each of them can be selected programmatically. Although we set clock selection bits in respective registers as per STM32F4 Reference Manual [1] yet there was (may be) still a teeny tiny doubt:
- Is the clock really selected?
- Does the system really switched to selected clock source?
- What actual clock frequency does the system receiving as apposed to expected clock!
In short – how can the configured clock be verified? ð
Well the good news is there is a way around to verify system clock. The Microntroller Clock Ouput (MCOx) feature of STM32 allows to reroute one of six system clocks i.e. HSI, HSE, LSE, SYSCLK, PLL, and PLLI2S to specific GPIOs Pins for verification purpose or providing clock to external devices in case if required.
The STM32 onchip clock and power control unit i.e. RCC provides the facility to route various system clock sources to specific GPIOs Output Pins (MCO1-PA8, MCO2-PC9) as a part of alternate function. This output clock routed from system clock sources can be measured externally via a logic analyzer etc.
In this tutorial we will discuss how clock from various clock sources can be routed to GPIO pins for test purpose. The board we are using is STM32F4-Discovery. If we look at STM32F407 Clock tree [1], we will see that there are two pins i.e. MCO1 and MCO2 to which various clock source are connected via a multiplexer and prescalers. Figure-1.

The MCO1 and MCO2 are the pins which can be used to verify various System clock sources. According to datasheet [2]:

For demonstration purpose we will verify the default connected clock source i.e. the internal 16MHZ HSI Oscillator on MCO1 (PA8).
Following are the steps…
Steps:
1. As we are using MCO1 pin which is multiplexed with GPIOA Pin#8 (PA.8) so the first step is to configure PA.8 to be used for Clock output and not as General Purpose GPIO. The configuration includes enabling clock to GPIOA and programming PA.8 for Alternate function AF0. We have a separate tutorial for GPIO configuration as an Alternate Function. The tutorial can be accessed via the following link.
PA.8 is configured as Alternate Function – 0 via the following code snippet.
/* MCO1 --> PA8 */ /* Enable clock to GPIOA */ RCC->AHB1ENR |= 1U; /********************* PA.8 Configuration *********************/ /* PA8 will be used for clock output (MCO1) and not as GPIO so configure it for alternate funciton */ GPIOA->MODER &= ~(1U << 16); GPIOA->MODER |= (1U << 17); /* Push Pull -> clock inlcludes both states */ GPIOA->OTYPER &= ~(1U << 8); /* high speed */ GPIOA->OSPEEDR |= (2U << 16); /* connect to alternate function AF0 (System Function)*/ GPIOA->AFR[1] &= ~(0xFU);
2. As shown in Figure-2, four different clock sources can be output on MCO1. For demonstration purpose we will select the internal RC Oscillator HSI. The clock sources for both MCO1 and MCO2 can be selected via RCC Clock Configuration Register (RCC_CFGR) – Figure-3.

For MCO1, bit#21,22 are used to select clock source.
00: HSI clock selected
01: LSE oscillator selected
10: HSE oscillator clock selected
11: PLL clock selected
As we want HSI output on MCO1 so bit#21,22 are both set to 0
/******************** MCO1 Settings ********************/ /* 00: HSI clock selected [WE WILL SELECT THIS ON] 01: LSE oscillator selected 10: HSE oscillator clock selected 11: PLL clock selected */ RCC->CFGR &= ~(3U << 21);
3. This step is kind of optional. If both output clock frequency comes under the range of:
- Bus frequency on which GPIOx is interfaced (Max Bus Speed)
- Measuring Instrument
If both of these conditions are satisfied then you may skip this step. Otherwise in either case, you need to scale down the frequency internally by a factor so that it can be measured accurately. The actual frequency will be the measured frequency multiplied by the scaled factor. The scale factor can be set via bit#24-26 (for MCO1) and bit#27-29 (for MCO2) in RCC Clock Configuration Register (RCC_CFGR) – Figure-3.
0xx: no division
100: division by 2
101: division by 3
110: division by 4
111: division by 5
In our case, as we want the clock output to be HSI (16MHz), so lets scale it down by a factor of 4. Now the clock frequency on MCO1 pin should be ~4Mhz (16/4).
/* Prescale by factor of 4 --> 4Mhz output on MCO1 (in range of low quality analyzer) */ RCC->CFGR &= ~(1U << 24); RCC->CFGR |= (3U << 25); /* Now HSI clock is connected to MCO1 MCO1 pin will now provide clock of ~4Mhz. */
For complete code refer to the link given at the start of this tutorial.
References:
[1] – Reference manual-RM0090
Hi this is somewhat of off topic but I was wondering if blogs use WYSIWYG editors or if you have
to manually code with HTML. I’m starting a blog soon but have no
coding knowledge so I wanted to get guidance from someone with experience.
Any help would be enormously appreciated! 0mniartist asmr
Hello to every body, it’s my first visit of this blog; this weblog consists of
remarkable and in fact fine stuff in favor of visitors.
asmr 0mniartist
Have you ever thought about adding a little bit more
than just your articles? I mean, what you say is important
and everything. But imagine if you added some great visuals
or videos to give your posts more, “pop”! Your content is excellent
but with pics and clips, this website could certainly
be one of the best in its field. Very good blog! 0mniartist asmr
Pretty! This has been an extremely wonderful article.
Thanks for supplying this information. asmr 0mniartist
Have you ever considered publishing an ebook or guest authoring on other websites?
I have a blog centered on the same information you discuss and
would love to have you share some stories/information. I know my
visitors would enjoy your work. If you’re even remotely interested,
feel free to shoot me an e-mail. asmr 0mniartist
I used to be suggested this website through my cousin. I’m no longer positive whether this publish is written by way
of him as nobody else realize such specific about my trouble.
You are wonderful! Thank you!
Hey there! This post could not be written any better!
Reading through this post reminds me of my old room mate!
He always kept talking about this. I will forward this
post to him. Pretty sure he will have a good read.
Many thanks for sharing!
Fantastic goods from you, man. I have understand your stuff previous to
and you’re just extremely great. I really like what you have acquired here, certainly like what
you are saying and the way in which you say it.
You make it enjoyable and you still take care of to keep it smart.
I cant wait to read much more from you. This is actually a wonderful web site.
whoah this weblog is fantastic i really like reading your articles.
Stay up the good work! You already know, lots of persons are
searching round for this info, you can aid them greatly.
What’s up Dear, are you genuinely visiting this
website regularly, if so after that you will definitely obtain good know-how.
Whats up are using WordPress for your site platform?
I’m new to the blog world but I’m trying to get started and create my own. Do you require any coding knowledge to make your own blog?
Any help would be greatly appreciated!
Wow, fantastic blog layout! How long have you been blogging for?
you make blogging look easy. The overall look of your web site is great, as well
as the content!
It’s going to be finish of mine day, except before end
I am reading this wonderful paragraph to improve my know-how.
Hello, i think that i saw you visited my site thus i came to âreturn the favorâ.I am attempting to find
things to improve my site!I suppose its ok to use a few of your
ideas!!
scoliosis
I think this is among the most vital information for me.
And i am glad reading your article. But should remark on few general things, The web site style is wonderful, the articles is really excellent : D.
Good job, cheers scoliosis
scoliosis
Hi! I know this is kinda off topic however ,
I’d figured I’d ask. Would you be interested in trading links or maybe guest writing a blog
post or vice-versa? My blog covers a lot of the same subjects as yours and I believe
we could greatly benefit from each other. If you are
interested feel free to shoot me an email. I look forward to hearing from you!
Wonderful blog by the way! scoliosis
dating sites
We’re a group of volunteers and opening a new scheme in our community.
Your website provided us with valuable information to work
on. You have done an impressive activity and our entire group will probably be
grateful to you. free dating sites https://785days.tumblr.com/
free dating sites
Thank you for another fantastic article. The place else may anyone get that
type of info in such a perfect manner of writing?
I’ve a presentation next week, and I am on the look for such information. dating sites
Thank you a lot for sharing this with all people you actually understand what
you are talking about! Bookmarked. Kindly additionally consult with my website =).
We could have a link alternate arrangement among us
What’s up to every one, since I am truly eager of reading this web site’s post
to be updated on a regular basis. It includes pleasant
information.
naturally like your web-site but you have to check the spelling on several of your posts.
Many of them are rife with spelling issues and I
find it very bothersome to inform the reality however I’ll surely come back again.
I got this web site from my pal who told me regarding this
web site and now this time I am visiting this web page and reading very
informative content here.
When I initially left a comment I seem to have clicked the -Notify me when new comments are added- checkbox and from now on whenever a comment is added I
get 4 emails with the exact same comment.
Is there a means you are able to remove me from that service?
Kudos!
It’s an amazing paragraph in support of all the web users; they will obtain benefit from it
I am sure.
Hi there, I want to subscribe for this webpage to obtain most recent updates, thus where can i do it please help out.
Ilona Andrews Hidden Legacy Characters Grammar In Use Martin Hewings
Also visit my homepage best books; chwenny.getenjoyment.net,
Hey there would you mind stating which blog platform you’re using?
I’m looking to start my own blog soon but I’m having a hard time selecting between BlogEngine/Wordpress/B2evolution and Drupal.
The reason I ask is because your layout seems different then most blogs
and I’m looking for something completely unique. P.S
Apologies for being off-topic but I had to ask!
I constantly spent my half an hour to read this website’s content daily along with a mug of
coffee.
Caramba, que show hein! NÃĢo ÃĐ nas qualquer lugar que se
acha tema Bom de como o esse. Agradeço de Teu website, acabei de incluir Seu website nos
meus favoritos. ð
wonderful points altogether, you just received a new reader.
What could you suggest about your put up that you made some days in the past?
Any certain?
Hi there, I enjoy reading all of your article post.
I wanted to write a little comment to support you.
Esse artigo ÃĐ fantÃĄstico ! Eu achei esse artigo por acaso e vim te
dizer que curti todos os posts . Vou te adicionar e te desejo muito sucesso!
Oi . VocÊs oferecem consultoria ? gostaria de aprender mais sobre este tema mas
esse ainda ÃĐ um mundo completamente novo para mim. como posso
contactÃĄ-los ?
Hello, i think that i saw you visited my site thus i came to âreturn the favorâ.I’m attempting to find things to enhance my site!I
suppose its ok to use a few of your ideas!!
Hello, I enjoy reading all of your article. I wanted to write a little comment to support you.
Hello, I think your website might be having browser compatibility issues.
When I look at your blog in Opera, it looks fine but when opening in Internet Explorer,
it has some overlapping. I just wanted to give you a quick heads up!
Other then that, wonderful blog!
Hi exceptional blog! Does running a blog similar to this require a massive amount work?
I have no understanding of programming however I had been hoping to
start my own blog soon. Anyway, if you have any recommendations or tips for
new blog owners please share. I understand this is off topic but I simply had to ask.
Cheers!
Remarkable! Its truly amazing article, I have got much clear idea regarding from this paragraph.
Greate article. Keep posting such kind of information on your site.
Im really impressed by your blog.
Hey there, You’ve done an incredible job. I will definitely digg it and in my
view recommend to my friends. I’m sure they will be benefited from this web site.
It’s actáĨallŅ a cool and useful pŅece of information. I аm glad that you jut snared this
useful innfo with us. Ð lease keep us informed likoe this.
Thanks for sharing.
Hi, I do think this is a great site. I stumbledupon it ð I’m going to come back yet again since i have
saved as a favorite it. Money and freedom is the greatest way to change,
may you be rich and continue to guide other
people.
I do accept as true with all the concepts you have introduced in your post.
They’re very convincing and can definitely work.
Still, the posts are too quick for novices. May you please extend them a bit from subsequent
time? Thanks for the post.
Good day! Do you use Twitter? I’d like to follow you if that would be ok.
I’m absolutely enjoying your blog and look forward to new posts.
Excellent post. I was checking continuously this blog and I’m inspired!
Very useful info specially the final part ð I take care
of such info much. I used to be looking for this particular info for a very long time.
Thank you and good luck.
Yes! Ïinally Ņomeone writers abâēut daftar pkv Ņoker.
What’s up everyone, it’s my first pay a visit at
this website, and piece of writing is really fruitful in support of me, keep up posting these content.
I am not sure where you’re getting your info, but good topic.
I needs to spend some time learning more or understanding more.
Thanks for wonderful information I was looking for this
information for my mission.
Wow, wonderful blog layout! How long have you been blogging for?
you make blogging look easy. The overall look of your website is wonderful, as well as the content!
Thanks to my father who informed me concerning this website, this web site is
actually awesome.
you are really a just right webmaster. The site loading velocity is amazing.
It kind of feels that you are doing any unique trick. Furthermore,
The contents are masterpiece. you’ve done a
great activity on this subject!
It’s not my first time to visit this website, i am visiting this
web page dailly and obtain nice information from here daily.
Hi there! Someone in my Facebook group shared this website with us so I came to check it out.
I’m definitely loving the information. I’m book-marking and will be tweeting
this to my followers! Exceptional blog and wonderful design.
Really when someone doesn’t understand after that its up to other users that
they will assist, so here it takes place.
Hi! I know this is kinda off topic but I was wondering which blog platform
are you using for this website? I’m getting sick and tired of
Wordpress because I’ve had problems with hackers and I’m looking at options for another platform.
I would be fantastic if you could point me in the direction of a good platform.
I have been browsing on-line more than 3 hours
these days, yet I by no means discovered any interesting article
like yours. It is beautiful price enough for me. In my opinion, if all webmasters and bloggers made just right content material as you did, the web
might be much more helpful than ever before.
An interesting discussion is worth comment. I do think
that you should publish more on this subject,
it might not be a taboo subject but usually
people do not speak about these subjects. To the next!
All the best!!
You really make it seem so easy with your presentation but I find this topic to
be actually something which I think I would never understand.
It seems too complex and extremely broad for me.
I’m looking forward for your next post, I’ll try to
get the hang of it!
Great line up. We will be linking to this great article on our site. Keep up the good writing.
Superb post but I was wondering if you could write a litte more on this topic?
I’d be very thankful if you could elaborate a little bit more.
Thank you!
I think that what you composed made a lot of sense.
However, what about this? suppose you added a little information? I am not saying your
information isn’t solid, however suppose you added a title that makes people want more?
I mean STM32F4 System Clock Testing – MCOx – EcoderLenz is a little plain. You might
peek at Yahoo’s front page and note how they write
news headlines to grab viewers to click.
You might add a related video or a pic or two to get people excited about everything’ve written.
In my opinion, it might bring your blog a little bit more interesting.
Thanks for the marvelous posting! I really enjoyed reading it, you might be a great author.I will make sure to bookmark your blog and will often come back someday.
I want to encourage you to continue your great job, have a nice weekend!
It’s really a cool and useful piece of info. I am satisfied that you shared this useful
information with us. Please stay us informed like this. Thanks
for sharing.
Appreciate the recommendation. Let me try it out.
Hi there mates, its enormous post on the topic of tutoringand completely explained,
keep it up all the time.
Heya just wanted to give you a quick heads up and let you know a few of the images aren’t loading properly.
I’m not sure why but I think its a linking issue.
I’ve tried it in two different browsers and both show the same outcome.
Hello are using WordPress for your blog platform? I’m new to the blog world
but I’m trying to get started and set up my own. Do you need any coding knowledge to make your own blog?
Any help would be really appreciated!
Excellent way of telling, and fastidious post to get data regarding my
presentation focus, which i am going to present in school.
Appreciate the recommendation. Will try it out.
Wow, awesome blog structure! How lengthy have you ever been running a blog for?
you make running a blog glance easy. The full glance of your web site is excellent, as well as
the content material!
I think the admin of this website is truly working hard in support of his site,
for the reason that here every material is quality based material.
Does your site have a contact page? I’m having problems locating it but, I’d like to
shoot you an e-mail. I’ve got some creative ideas for your blog you might be
interested in hearing. Either way, great blog
and I look forward to seeing it grow over time.
Excellent weblog here! Additionally your web site a lot up very fast!
What web host are you the usage of? Can I get your associate link for your host?
I wish my website loaded up as fast as yours lol
I was able to find good advice from your articles.
Do you mind if I quote a couple of your posts as long as I provide credit and
sources back to your website? My blog is in the very same niche as yours and my visitors would genuinely benefit from
a lot of the information you provide here. Please let
me know if this okay with you. Regards! quest bars http://bit.ly/3jZgEA2 quest bars
I’m really impressed with your writing skills and
also with the layout on your blog. Is this a paid theme or
did you customize it yourself? Either way keep up the nice quality
writing, it is rare to see a great blog like this one these
days. asmr https://app.gumroad.com/asmr2021/p/best-asmr-online asmr
I have been browsing online more than 4 hours today, yet I never found any interesting article like yours.
It is pretty worth enough for me. In my view,
if all website owners and bloggers made good content as you did, the web will be much more useful than ever
before. scoliosis surgery https://0401mm.tumblr.com/ scoliosis
surgery
Heya i am for the first time here. I came across this
board and I find It really helpful & it helped me out much.
I am hoping to give one thing again and help others like you helped me.
cheap flights http://1704milesapart.tumblr.com/ cheap flights
Good replies in return of this difficulty with firm arguments and explaining the whole thing about
that. scoliosis surgery https://coub.com/stories/962966-scoliosis-surgery scoliosis surgery
This is really interesting, You’re a very skilled blogger.
I have joined your feed and look forward to seeking more of
your wonderful post. Also, I’ve shared your site in my social networks!
ps4 games https://bitly.com/3nkdKIi ps4 games
Howdy! Would you mind if I share your blog with my twitter group?
There’s a lot of folks that I think would really appreciate your content.
Please let me know. Many thanks quest bars https://www.iherb.com/search?kw=quest%20bars quest bars
Thanks for some other informative site. Where else may just I am getting that type of information written in such an ideal method? I’ve a project that I’m just now operating on, and I’ve been on the look out for such info.
This is a topic that’s close to my heart… Best wishes!
Exactly where are your contact details though? part time jobs
hired in 30 minutes https://parttimejobshiredin30minutes.wildapricot.org/
These loans are created available to those people,
who are in employment for at least previous six months and pull a monthly salary.
The debtors must repay the loan from next
salary cheque.
Feel free to surf to my webpage Installment Loans USA
hello there and thank you for your information â I have definitely picked up anything new from
right here. I did however expertise a few technical points
using this site, as I experienced to reload the site lots of times previous to I could get it to load properly.
I had been wondering if your web hosting is OK?
Not that I am complaining, but sluggish loading instances times will sometimes affect your placement in google and can damage your quality score if ads and marketing with Adwords.
Well I am adding this RSS to my e-mail and could look out for much more of your respective fascinating content.
Make sure you update this again soon.
Heya great blog! Does running a blog such as this
take a lot of work? I have virtually no understanding of programming however I was
hoping to start my own blog in the near future. Anyhow, if you have
any suggestions or techniques for new blog owners please share.
I know this is off subject however I simply
wanted to ask. Thank you!
āđāļāļāļĢāđ āļĄāļāļāļĨ āļŠāļģāļŦāļĢāļąāļ Pg āļāļąāļāđāļŠāļĩāđāļĒāļāđāļāļ āļŠāļĨāđāļāļāđāļāļāļāđāļēāļĒāļĄāļēāļāļĒāļīāđāļāļāļ§āđāļēāđāļāļīāļĄāļāđāđāļĨāļĒāđāļāđāļāļāļĩāđāđāļĢāļĩāļĒāļāļĢāđāļāļāļāļāļāļĄāļāļļāļĐāļĒāđāļĨāđāļāļŦāļĨāļēāļĄ āđāļāļ·āđāļāļāļāđāļāļāļāļāļāļēāļ§āđāļāļĒāļāļąāđāļāļāļĢāļ°āļāļąāļāđāļāļāļēāļĢāļĨāļļāđāļāđāļāļ āđāļŠāļ§āļāđāļāļāļĨāļēāļ pg slot āđāļāļ·āđāļāļāļĨāļāļĩāđāļĄāļĩāļāļĨāļāļĩāļāđāļāđāļāļāļāļ°āļāļē
āļāļāļĨāļāļāđāļĨāđāļāļŠāļĨāđāļāļāļāļĢāļĩ āļŠāļēāļĄāļēāļĢāļāļāļ·āđāļāļāļĢāļĩāļŠāļāļīāļāļāļļāļāđāļāļĄ BETFLIX āļŠāļēāļĄāļēāļĢāļāļāļ·āđāļāļāļĢāļĩāļŠāļāļīāļ āđāļāđāļāļēāļ 100āļāļēāļ āļĢāļąāļāđāļāļāļąāļŠāļāļĩāļ 200 āļāļēāļ āļĄāļĩāđāļāļĄāđāļŦāđāļāļļāļāđāļĨāļ·āļāļāđāļĨāđāļāļāļ§āđāļēāļāļĩāđāļāļļāļāļāļīāļ āļĢāļąāļāļĢāļāļāđāļĄāđāļĄāļĩāđāļāļ·āđāļ āļĨāļļāđāļāļĢāļąāļāđāļāļāļąāļŠāļāļēāļ 15 āļĢāļąāļ 100 āđāļĨāļ°āđāļāļĢāđāļĄāļāļąāđāļāļāļāļĢāļąāļāđāļāļ āđāļĨāļ°āđāļāļĢāđāļāđāļāđāļāļāđāļ āļāļĩāļāđāļāļĩāļĒāļ āđāļĨāđāļāđāļāļĄāļāļĢāļĩāđāļĄāđāļĄāļĩāļŠāļ°āļāļļāļ āļĨāļ·āđāļāđāļŦāļĨ āđāļŠāļāļĩāļĒāļĢāđāļĢāđāļ§āđāļĢāļāļĢāļąāļāđāļāļāļąāļŠāļāļĢāļĩ