cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F446xx - measuring system clock on MC01

PPopo
Senior

Hello everyone,

I have a development board with the MCU specified in the title. I have used Keil to create a project and flash my board.

According to what I understood from the documentation I read and by looking at the startup code:

  • MCU is by default using a 16Mhz internall RC oscillator
  • one can measure the frequency of the RC oscillator by sampling the MC01 pin of the microcontroller. PA8(MC01) must be configured as alternate function mode 0

I have done(hopefully :D) the above in the code then I connected the oscilloscope in this manner:

  • the probe's head on PA8 pin(MCO1 pin of the microcontroller)
  • the probe's ground on some 'GND' connection from the board

When I power up the oscilloscope I was expecting to see a 16Mhz frequency wave on the display. However I see some unstable frequency in the range of 200Hz-300Hz.

Here is the code that I wrote:

#include "stm32f446xx.h"
#include<stdint.h>
#include "Board_Buttons.h"
#include "Board_LED.h"
 
int main(void)
{
 RCC->AHB1ENR |= (1 << 0);    // enable GPIOA clock
 GPIOA->MODER |= (1 << 17);   // pa8 set as ALTERNATE FUNCTION MODE (MCO1 - HSI)
 GPIOA->MODER &= ~(1 << 16);
 //GPIOA->AFR[0] &= ~0xFF;         // the alternate function is selected via GPIOx_AFR registers
 //GPIOA->AFR[1] &= ~0xFF;	  // By default the PA8 pin's alternate function is CO01
 return 0;
}

 I have configured the pin as alternate function pin. Then I have not touched the AFR registers since their reset value is 0x0 which means PA8 will have alternate function 0 which means it can be used to measure HSI frequency.

Please help me understand why am I not getting the required frequency on the wave from my oscilloscope. I guess the code is correct and I'm doing something wrong in the way I have connected the probe of my oscilloscope. Also I want to mention this is the first time I'm using an oscilloscope so if you want me to give further details about how I connected or what options I have selected for the oscilloscope please tell me :D

Thank you for reading my long post! :D

8 REPLIES 8

You never return from main() in mcu. Instead, you remain in an endless loop, while(1); or such.

> this is the first time I'm using an oscilloscope

So you maybe did not chose the proper timebase. Turn the timebase knob so that you have some 100ns/div.

You should see now some 16MHz waveform, maybe a distorted sine. At this point you may need to change the pin's drive in GPIOA_OSPEED to one of the higher settings.

Use a 1:10 probe.

JW

PPopo
Senior

I have put an endless while loop in the code like you said. I have then sampled the pin with the probe and i get same result(a waveform with modifying frequency. I have uploaded a video showing this). I selected 'dc coupling' on the scope because i was expecting to see the waveform as a pwm output woth 16 mhz frequency. Instead when i select dc coupling i get a sognal which is around 3.24v in amplitude. About your suggestion to increase the zooming i have tried that as well but my scope does not seem to let me go further than 10 mv per div.

PPopo
Senior

Now after reading some stuff about oscilloscopes I have one more question:

  • I guess the output from that pin should be like a pwm signal with a frequency of 16Mhz. So on my oscilloscope I should select 'DC coupling' and not 'AC coupling right'?
  • Is that the correct way of setting the oscilloscope probe for what I want to do? The probe head on the MCO1 pin and the ground on a GND pin of the board?

I have attached a photo with the channel 0 when 'Dc coupling' is selected and also all the settings are shown there on the right:

0690X000008BYtLQAW.jpg

DC coupling is OK, but even with AC you should've seen something else than just noise. You should adjust the timebase to ca 100ns but again, even with 200us as you have it now you should see something.

So the MCO1 is not working, or the mcu is not running at all.

Try to write a simple program which sets a pin as GPIO Output and toggles it in a loop.

JW

The mcu is working I have tested already. I guess if everything else was correctly done that I have done something wrong when configuring it. I will look at the documentation and try again. Thanks ;)

S.Ma
Principal

Connect in DC coupling the probe and find a ground point.

Use the scope autosetup to see if you get something (best for beginners)

Then MCO is a peripheral which has registers to be programmed.

Read the reference manual to find out these registers.

Also the very first step is to enable clocks on the MCU peripheral registers so you can actually program it.

Look at the HAL code for hints.

One more thing, read erratum Delay after an RCC peripheral clock enabling.

Check whether the registers are set as you think they are, reading them back, in debugger perhaps. This is such a simple "program" that you could do without programming at all, just by writing into registers in the debugger - at least for the testing.

JW

PPopo
Senior

Hello,

After investigating the datasheet I have noticed that it said the following:

  • two microcontroller pins are available on which one can output a clock signal: MCO1 and MC02.
  • MCO1(PA8) can output the following clock sources: HSI, LSE, HSE and PLL
  • MCO2(PC9) can output the following clock sources: HSE, PLL, System clock(SYSCLK), PLLi2S clock

I was trying to sample the MCO1 pin because I have assumed the MCU uses internal RC oscillator(HSI) as default set to 16Mhz because that's what I heard from someone else.

But after seiing that info above in the datasheet I have decided to sample MCO2 instead since it outputed the System clock which must be active all the time(since it is the clock that drives the MCU and it can come from either source). So I sampled PC9 instead and found out on my oscilloscope that the frequency was indeed 16Mhz.

So my conclusion is that the MCU was by default configured to use some other clock source and not HSI as I expected. Now for my next exercise I will try to modify the clock source and observe the result :D. Can't wait to play with my scope and do that.

Also one more question about the scope: I have observed the output on the MCO2 pin as a sinusoid with a frequency of 16Mhz. That is the output from the MCU Sys Clock. That's nice that I confirmed the freuquency at which the MCU runs but I was expecting to see it as a PWM output and not as a sinusoid. Why is the output from the clock not displayed as a pwm signal on the scope?

Thanks for reading and thank you all for your answers!