CPU Clock Frequency Measurement

From SEGGER Wiki
Jump to: navigation, search

The J-Link DLL supports the CPU clock frequency measurement of connected target devices.

This i.e. is mandatory for CMSIS compatible flash loader which require the clock frequency being passed to the Init function:

int Init (unsigned long adr, unsigned long clk, unsigned long fnc);

Core Support

The generic clock frequency measurement is based on counting loop passes over a specified time. In detail the process consists of multiple steps:

  • Preserve RAM and register content
  • Load counting loop code into RAM
  • Set PC and run code
  • Halt target after a specified runtime
  • Read counted value
  • Restore RAM and register content
  • Calculate CPU clock frequency

However, this requires knowledge of the instruction-to-clock ratio of each individual device.

Some cores provide additional core modules and allow hardware-sided clock counting for precise measurements. One example is the cycle counter (CYCCNT) of the Data Watchpoint and Trace Unit (DWT) integrated in ARM Cortex-M cores. If such unit is available, the DLL will make use of it.

This table gives an overview about the supported CPU cores and the implemented measurement methods:

Core Methods Supported
ARM11 NO.png
ARM79 Loop counter YES.png
BT5511 NO.png
Coldfire BDM3 Loop counter YES.png
PIC32 NO.png
PowerPC NO.png
ARM Cortex-A/R (ARMv7-A) Loop counter + DWT CYCCNT (opt.) YES.png
ARM Cortex-A/R (ARMv8-A) NO.png
ARM Cortex-M Loop counter + DWT CYCCNT YES.png
RISC-V NO.png
Renesas RX Loop counter YES.png

Requirements

For successful CPU clock frequency measurements, some requirements have to be fulfilled:

  • The clock frequency measurement must be supported by the DLL
  • There must be not watchdog running while clock frequency measurement
  • If the core has a DWT CYCCNT, it must be kept enabled at any time

A deviation of described reqiurements can cause unknown behavior and failing of flash programming.