Embedded Rust Experiments: Is My STM32 MCU Running Fast?

Embedded Rust Experiments: Is My STM32 MCU Running Fast?

We need to change GPIO MODE to output, and CNF pin to select this alternate function (GPIOx_CRH, reference manual, 7.2.2):

To clean things up a bit, we can move MCO configuration into another function:

Here we go, our system clock is at 8MHz:

Now that we can measure it, let’s continue working on enabling external oscillator (HSE). We have a chip running system clock at the maximum speed:

However, the final result leaves a lot to be desired: the peripheral initialization code is in Rust (MCO), while rcc initialization is in C (HSE-PLL-SYSCLK). To achieve target PLL speed of 24MHz, we can PREDIV 8MHz by 2 and then multiply 4MHz output by 6:

Then, we can set PLL as system clock input (reference manual, 6.3.2):

Let’s not forget to set MCO back to SYSCLK:

Here we go:

This was a great learning experience!

Source: nercury.github.io