cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F4 microcontroller: instructions cycle number

hedy_nelson
Associate II

I'm working with an STM32F4 microcontroller, a ChipWhisperer, and the SimpleSerial library, trying to track the execution of instructions. During this process, I noticed that the number of CPU cycles I measured doesn't match what I expected based on the ARM Cortex-M4 instruction timings. Specifically, I used a base code, added instructions incrementally, and measured the number of cycles each time. Here are my results:

Instruction | Cycles


ldrh r3, [r1] | 110

sub r2, #85 | 113

mul r6, r7 | 115

and r1, r9 | 117

strh r5, [r2] | 119

These cycle counts are for all the instructions combined. It seems that the sub instruction takes two cycles because it's pipelined with other instructions.

What confuses me is the and instruction. My measurements show that the and instruction takes two cycles, but the ARM Cortex-M4 manual states that it should only take one cycle.

Am I missing something? Or is there something in the STM32F4 that isn’t mentioned in the ARM Cortex-M4 manual that could be affecting the cycle counts?

The attachment contains the base code with all the instructions between lines 60 and 265. The above instructions are between lines 130 and 135.

Thanks in advance! 

2 REPLIES 2
SofLit
ST Employee

Hello,

Are you executing from Flash? or RAM? you need to consider also the Flash wait states. Disabled the interrupts? 

See also https://community.st.com/t5/stm32-mcus-products/how-do-i-calculate-how-many-clock-cycles-are-needed-to-run-block/td-p/134579 on how to measure the cycles number.

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.
Andrew Neil
Evangelist III