STM32U545 Execution Speed Slower Than Expected
Software Environment:
- Windows platform
- Configured using STM32CubeMX
- Compiled with STM32CubeIDE
Hardware Platform:
- NUCLEO-U545RE-Q
- MCU: STM32U545 (Cortex-M33, ARMv8-M)
Test Objective:
We initially noticed slow SPI performance (CS low to CS high) and decided to test the MCU performance by measuring the simplest instruction set to toggle a GPIO pin. We further simplified the HAL_GPIO_WritePin( ) to only write to the registers back to back as shown below:

And the Assembly equivalent:

Issue Description:
Since there are only 3 assembly instructions for each SET / REST in the above code, we expected the execution time to be about 6 instruction cycles. However, when we measure the actual toggle time, we actually measure about 10 instruction cycles for the resulting pulse period. For example with the SYSCLK & AHB2 CLK running @ 16 MHz, we see a period of 680 nS which represents about 11 instruction cycles. (We are assuming that each assembly instruction takes 1 instruction cycle to execute.)

Details of test:
- Clock Configuration:
- HCLK: 16 MHz
- AHB2 / GPIO Clock: 16 MHz
- Test Method:
After initializing the system, we toggle a GPIO pin in code and measure the switching speed. - For this test the GPIO speed was set to SLOW , FAST and VERY FAST. The output waveform did not change appreciably. Also, the GPIO clk was enabled using the default init call of __HAL_RCC_GPIOA_CLK_ENABLE();
- For this test, no other peripheral or interrupts have been enabled.
Questions:
- Is there a better method to test the MCU’s performance than toggling GPIO pin?
- Is there an explanation for why the GPIO toggling takes so much longer to execute?
- Are there any additional configurations (other than default config that was used for this example) needed to achieve optimal MCU speed?
Any insights or suggestions would be greatly appreciated!
