2024-08-22 07:01 PM - last edited on 2024-08-23 01:52 AM by SofLit
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!
2024-08-23 01:51 AM - edited 2024-08-23 01:54 AM
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.
2024-08-23 02:25 AM
basically the same question here:
just substitute F3 for F4