2021-09-16 12:34 AM
Hi All,
I'm working with a STM32F303x8, when using the HSI as the clock I've found the timers drift too much between cold and hot running (which is fair), I'm seeing about a 0.3% drift which is an issue for this application.
I now have an 8MHz External crystal as the main clock and that appears to be working except I get a 'HardFault' after a few seconds of running. Switch back to the HSI and it's fine.
When the exception happens most of the time I am seeing the 'UNDEFINSTR' flag set (the processor has attempted to execute an undefined instruction) which makes no sense at all. If there was a bad instruction why would it happily execute off the Internal Clock and not hit this. So I'm not believing that as being the actual fault or my determination of that is wrong.
If I check the RCC status (SWS: System clock switch status) it says it is running off the HSE and HSERDY = 1.
The thing is when this exception happens the Timers are still generating an output signal, so the clock must still be functional. In fact I know it is the External Crystal still being used because my pulse outputs are dead accurate (unlike when running off the HSI).
Has anybody else run across anything like this before?
Thanks.
2021-09-17 01:17 AM
As an FYI the tip offered by Tesla DeLorean helped, my scope measured (on the MCO pin) 7.99968 MHz when running off the HSE, and 7.975 MHz when running off the HSI, so that explains the issues I was seeing with the timer drift.
But I think my problem was maybe the External Crystal signal was not ideal and was causing the System Clock to be unstable when HSE was being used for SysClk.
Instead I now have the PLL clocked from the external crystal and the PLL becomes the SysClk. This has resulted in stable operation and the MCO pin (when the PLL is being switched to that output) is a rock solid 7.99968 MHz as well.
Then where ONadr.1 said to use the MCO pin from the ST-LINK STM32 on the Nucleo board I think I will ditch my external crystal and use that instead.
Thanks everyone for the replies.