7 years ago.

STM32 Nucleo-64 Clock Setting Registers

I ran some floating point benchmarks on STM32 nucleo 48MHz Coretex-M0 and 72MHz Coretex-M4. The M0 consistently gives better results. I started with floating point matrix multiplications then moved to atan() of random numbers. Eventually, I tried several floating point and non-floating point code snippets in the benchmark with the M0 always giving a better result, confirmed by both timer.read_us() and a manually using a stopwatch and a flashing LED. Since the M4 should be higher performance, I started looking at clock frequencies. RCC_CFGR_SWS_PLL is operating in PLL mode. SystemCoreClock displays 72MHz for the M4, and 48MHz for the M0.

My specific boards are STM32F091 and STM32F302. The 302 Cortex-M4 has a FPU, which should shred the Cortex-M0 in any circumstance. However, the 091 Coretex-M0 board continues to give better real-life results.

According to STM32CubeMX, a prescaler (AHB) is downstream from SYSCLK. The scaled output to the core is HCLK.

  • Does SystemCoreClock display SYSCLK or HCLK? Where is this documented?
  • How can I confirm absolutely the HCLK frequency to the core?

These are some general ideas. I don't know which one's apply to mbed online compiler. Should check to be sure you are actually doing float math and your floats are not accidentally being promoted to doubles somewhere. The rules would be specific to the compiler and the settings used. If you use literals instead of float variables, it's possible the compiler makes them doubles. For any math that involves two floats, the compiler could be promoting to double before doing the math. In GCC the warning (-Wdouble-promotion) can be enabled to let you know when a promotion to double happens. I'm not sure what, if anything, has to be done in online compiler to force it to treat everything as floats or how to set compiler warning on promotion to double.

It is possible the online compiler is not setup to use the FPU hardware at all. I don't know if I can give you all the steps. But the flag FPU_PRESENT, has to be set. And you should use the ABI "softfp", but not "soft". I have no idea how this option is set in online compiler.

posted by Graham S. 28 Nov 2017

1 Answer

7 years ago.

Hi,

The SystemCoreClock variable should contain the system clock. But the best thing to do (if you have a scope) is to measure the system clock on the MCO pin (pin PA8 on both boards).

Add this line in your code:

HAL_RCC_MCOConfig(RCC_MCO, RCC_MCOSOURCE_SYSCLK, RCC_MCO_DIV1);

And clock setting is done in the files:

For F091

https://os.mbed.com/users/mbed_official/code/mbed-dev/file/79309dc6340a/targets/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F091RC/device/system_clock.c

AHBCLK = SYSCLK = 48 MHz

For F302

https://os.mbed.com/users/mbed_official/code/mbed-dev/file/79309dc6340a/targets/TARGET_STM/TARGET_STM32F3/TARGET_STM32F302x8/TARGET_NUCLEO_F302R8/system_clock.c

AHBCLK = SYSCLK = 72 MHz