0
\$\begingroup\$

I have a PCB where I use an 8 MHz quartz resonator as this MCU's external system clock source.

In STM32CubeIDE the setting is as follows:

enter image description here

The program runs fine in MCU, but I cannot be sure if HSE is really used instead of HSI. Here is the clock config:

enter image description here

As you can see, both HSE and HSI are active. I supposed to be using HSE, but I remember once I tried to set like this in a development board which has no external oscillator and MCU still worked using its HSI.

My worry is that, imagine the crystal is not working, then the MCU will switch HSI without telling me and I will never know. I want to be sure that the system is using the external crystal.

Now the problematic part is that I forgot to add test pins and MCO output is unused and is not routed to any PCB header. Meaning that I'm NOT able to probe the MCU pins.

Is there a way/trick I can try without probing pins physically programmatically that ensures that MCU is using HSE but not HSI? I think it's impossible to disable HSI(?) but can there be any way I can try?

\$\endgroup\$
4
  • 1
    \$\begingroup\$ I did now, thanks for reminding. \$\endgroup\$
    – cm64
    Commented Jul 18 at 16:41
  • 1
    \$\begingroup\$ If you short the crystal and it stops then it's using the crystal. \$\endgroup\$ Commented Jul 18 at 16:47
  • \$\begingroup\$ Should that be done before powered? I thought about interfering with it but didnt want to cause some ESD or some other issue so far. \$\endgroup\$
    – cm64
    Commented Jul 18 at 16:54
  • \$\begingroup\$ Yes, tack a wire-wrap wire on there before it's powered, usual ESD precautions for handling an open PCB. \$\endgroup\$ Commented Jul 18 at 17:27

2 Answers 2

1
\$\begingroup\$

The clocks/pll are configured/selected and can be monitored by the Clock Configuration register and the Clock Control register

enter image description here

enter image description here

Bit 15, 16 in RCC_CFGR register will indicate as well as bit 16,17 in RCC_CR register.

I don't use HAL so I can't help with a function that reads registers.

\$\endgroup\$
3
  • \$\begingroup\$ I tried: volatile uint32_t rcc_cr = RCC->CR; // Extract bit 16 (HSEON) and bit 17 (HSERDY) hseon = (rcc_cr >> 16) & 0x1; // Bit 16 hserdy = (rcc_cr >> 17) & 0x1; // Bit 17 and both bits are 1 \$\endgroup\$
    – cm64
    Commented Jul 18 at 17:55
  • \$\begingroup\$ But Im not sure if those registers only show the settings I made or really the HSE is used as system clock(?) \$\endgroup\$
    – cm64
    Commented Jul 18 at 17:56
  • \$\begingroup\$ If you read about bit 17 on page 140 it tells you that if it is hi the HSE is ready. CFGR->PLLSRC is what is the current source. CR->PLLRDY indicates if the pll is ready for use. So these three indicators are what you need. \$\endgroup\$
    – user319836
    Commented Jul 18 at 18:37
0
\$\begingroup\$

There are several ways.

The best would be to select HSE as MCO output to verify the output is 8 MHz.

And then probe the crystal with a second scope probe to see that the two waveforms are a match, i.e. same constant phase offset and freqency.

But those cannot be done without probing.

The generated MCU startup code will usually hang in a loop if you try to start HSE because it does not become ready and oscillate.

Also if you set the parameters for the PLL to expect 8 MHz clock from HSE, please note that you cannot select the 8 MHz HSI as PLL clock source, the PLL can only get prescaled 4 MHz from PLL.

So if you e.g. set 8MHz HSE as PLL source and set the PLL dividers and multipliers so that it makes a 72 MHz clock from 8 MHz, and blink a LED at 1 Hz, the CPU will run at 72 MHz and blink the LED at 1 MHz, or, if accidentally the 4 MHz from HSI is selected as PLL source, the CPU will run at half speed of 36 MHz and the LED will blink at half speed of 2 Hz.

So as the CPU cannot run at 72 MHz unless the PLL input is from HSE, 8 MHz multiplied by 9. With HSI, the maximum achievable clock is only 64 MHz, 4 MHz multiplied by 16x, but if the multiplier is set to 9, with HSI that is 36 MHz.

The code can also enable the Clock Security System and you get an interrupt that HSE failed to work if it was in use.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.