Skip to main content
Visitor II
August 23, 2024
Solved

STM32F4 microcontroller: instructions cycle number

  • August 23, 2024
  • 2 replies
  • 1479 views

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! 

    This topic has been closed for replies.
    Best answer by Andrew Neil

    basically the same question here:

    https://community.st.com/t5/stm32-mcus-products/instruction-timings-not-matching-arm-cortex-m4-manual/m-p/708765

    just substitute F3 for F4

    2 replies

    Technical Moderator
    August 23, 2024

    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.

    Super User
    August 23, 2024