0
0
Cnc-programmingConceptBeginner · 3 min read

Sleep Mode in ARM Cortex-M: What It Is and How It Works

In ARM Cortex-M processors, sleep mode is a low-power state where the CPU stops executing instructions but can quickly resume when needed. It reduces power consumption by halting the processor clock while keeping the system ready to wake up on interrupts or events.
⚙️

How It Works

Sleep mode in ARM Cortex-M works by pausing the processor's core activity to save power, similar to how a person might close their eyes and rest but stay alert to sounds. When the processor enters sleep mode, the CPU clock is stopped, which means it does not execute any instructions, but the system's memory and peripherals can remain active.

The processor wakes up instantly when an interrupt or event occurs, like a phone ringing waking someone from a light nap. This mechanism allows devices to save battery life while still responding quickly to important signals.

💻

Example

This example shows how to put an ARM Cortex-M processor into sleep mode using the WFI (Wait For Interrupt) instruction, which tells the CPU to sleep until an interrupt wakes it.

c
#include "core_cm4.h"  // CMSIS header for Cortex-M4

void enter_sleep_mode(void) {
    __WFI();  // Wait For Interrupt: enter sleep mode
}

int main(void) {
    while (1) {
        // Do some work here

        // Enter sleep mode to save power
        enter_sleep_mode();

        // CPU wakes up here after interrupt
    }
    return 0;
}
Output
No direct output; CPU enters low-power sleep mode until an interrupt occurs.
🎯

When to Use

Sleep mode is useful in battery-powered or energy-sensitive devices like wearables, sensors, and IoT gadgets. When the device is idle or waiting for an event, sleep mode helps extend battery life by reducing power use.

For example, a temperature sensor might sleep most of the time and wake only to take readings or send data. This approach balances responsiveness with energy efficiency.

Key Points

  • Sleep mode stops the CPU clock to save power.
  • The processor wakes instantly on interrupts or events.
  • Memory and peripherals can stay active during sleep.
  • Use WFI instruction to enter sleep mode.
  • Ideal for low-power, event-driven applications.

Key Takeaways

Sleep mode reduces power by stopping the CPU clock while keeping the system ready to wake.
The CPU wakes immediately on interrupts, ensuring quick response.
Use the WFI instruction to enter sleep mode in ARM Cortex-M processors.
Sleep mode is essential for extending battery life in embedded and IoT devices.
Memory and peripherals can remain active during sleep to maintain system state.