Low Power & Optimization
Sleep instead of spinning, keep data in flash, and write C the compiler can optimise for small, fast code.
Battery-powered devices spend most of their life asleep, and cheap microcontrollers have little flash and modest clock speeds. Both reward the same habits: do work only when an event requires it, and let the compiler help.
Code-size and speed habits
for (;;) { if (flag) work(); } // spins at full power for (;;) { if (flag) work(); __WFI(); }
Without sleep the CPU burns its full current while waiting for an event that comes only every few milliseconds.
What does WFI do?
Wait For Interrupt: halts the CPU core clock until an interrupt (or debug event) occurs, cutting power while idle.
Which linker flags remove unused functions from the image?
Compile with -ffunction-sections -fdata-sections and link with -Wl,--gc-sections.