← Back to the chapter · Previous detail · Next detail →
Technical detail · Microcontroller Programming: Setup and GPIO
Board runtimes and bounded tasks
A real-time operating system (RTOS) schedules small tasks so time-sensitive work can run alongside other jobs. It does not make a long blocking task safe by itself: priorities and waits still affect when a task runs. Programmable I/O (PIO) is a separate hardware engine that handles timed pin signals. Direct memory access (DMA) moves data between a peripheral and memory without the CPU copying each item. Both can free loop time, but their setup and completion still need tests.
Arduino-style firmware looks simple because setup() and loop() hide runtime startup, timers, serial buffers, board package details, and sometimes an RTOS task. Blocking code can still starve sensor reads, watchdog resets, communication retries, or actuator safety checks.
An over-the-air (OTA) update sends new firmware to a device over a network instead of a cable. Non-blocking firmware treats the loop as a small cooperative scheduler. Each task decides whether it is time to run, does bounded work, records evidence, and gives control back. That pattern scales better when the prototype later adds networking, storage, OTA updates, or power management. It also makes failures easier to localize because a missed sample, repeated reset, or stale network send can be tied to the task that monopolized the loop.
A software development kit (SDK) is a set of tools and code supplied for building software on a platform. Its drivers and services can affect when the sketch runs. The hidden machinery differs by board. On a classic AVR Arduino, the sketch often runs close to the foreground loop model. On ESP32 Arduino, loop() runs inside a FreeRTOS task while Wi-Fi, Bluetooth, timers, and system services use other tasks and interrupts. On RP2040, dual-core behavior and PIO peripherals can move timing-sensitive work outside the normal loop. On nRF52 or STM32 boards, vendor SDK layers, timer peripherals, DMA, and low-power modes can change which code runs while the main loop appears idle.