Clock Monitor Frequency Meter

Browse source code on GitHub

Overview

This sample uses the clock monitor API in CLOCK_MONITOR_MODE_MEASURE mode, which performs one measurement per clock_monitor_start(). It shows the idiomatic wait pattern: the callback gives a semaphore, main() waits on it with its own timeout, and the result is read back with clock_monitor_get_rate().

The API has no blocking wait, so the timeout belongs to the application; on timeout the sample calls clock_monitor_stop() to abort the measurement. The happy path needs no stop, as the device disarms itself before the callback runs. The measurement window is set using CONFIG_SAMPLE_WINDOW_NS.

Requirements

Building and Running

west build -b frdm_mcxe31b samples/drivers/clock_monitor/measure_freq
west flash

On a board using the FREQME peripheral, add the shared overlay:

west build -b frdm_mcxn236 samples/drivers/clock_monitor/measure_freq -- -DEXTRA_DTC_OVERLAY_FILE="../clock_monitor.overlay"
west flash

Sample Output

[00:00:00.000,000] <inf> sample: cmu-fm@2bc020 configured in MEASURE mode, window = 1000000 ns
[00:00:00.001,000] <inf> sample: Measured frequency = 48000000 Hz

If the monitored clock stops producing edges, the driver reports the loss instead:

[00:00:00.001,000] <wrn> sample: monitored clock lost (FMTO-class event)

See also

Clock Monitor