liveBook · Manning

Cycle-accurate timing

As explained in Embedded Software with Rust

Cycle-accurate timing is timing behavior that matches the precise processor-cycle execution of the real hardware.

Cycle-accurate timing measures firmware execution against processor cycles, helping determine whether code is fast enough. On Cortex-M3 and later, the DWT cycle counter provides this measurement; SysTick is a fallback on cores without DWT. Semihosting halts the core and distorts timing measurements, while emulators do not guarantee cycle-accurate timing. section 6.0 section 6.7 section 2.7.1

Choose the measurement path to match the target:

  • Use the DWT’s 32-bit CYCCNT counter on Cortex-M3 and later. section 6.7
  • Use SysTick’s 24-bit down-counter where DWT is absent; reserve timing-sensitive tests for physical hardware when emulator timing matters. section 6.7 section 2.7.1

How Embedded Software with Rust covers it

How deep it goes
Identifies DWT’s 32-bit CYCCNT and SysTick’s 24-bit fallback, and warns that semihosting distorts measurements.
Examples
Uses DWT CYCCNT on Cortex-M3 and later, or SysTick where DWT is absent.
What you can do after
Apply it by measuring firmware cycles with DWT CYCCNT or the SysTick fallback, avoiding semihosting during measurement.
How it connects
Connects profiling with DWT, SysTick, and semihosting.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Embedded Software with Rust. The section links point to the parts of the book it draws on.