An MCU answers a button in 0.17 µs, milliseconds after power-on. A Linux board adds drivers, a network and files, but it boots for seconds and its answers have a tail. In this toy at 80% load, stock Linux misses a 1 ms deadline 14 times in 10,000 cycles. With PREEMPT_RT, the worst answer takes 38 µs.
Pick a platform, then raise the background load and watch the slowest answers. Then we build, piece by piece, the cross-compiler, the boot chain, the image, the device tree, a driver, a service and the real-time kernel.
You need Lesson 1's MCU and interrupts, C and a Linux terminal. We build the rest from zero.
Lesson 5 of the Embedded Systems series. Before: Lesson 4, Hardware Interfacing. Next: Lesson 6, Real-Time Systems. The hands-on track is Firmware from Zero.
Illustrative toy, simulated with a fixed seed. Each wake-up adds an interrupt entry, a context switch of 6 to 14 µs, and sometimes the rest of a section the scheduler cannot interrupt. Stock: 1% of those sections run 0.2 to 2.5 ms, and at 80% load 77% of wake-ups still finish within 20 µs. PREEMPT_RT: at most 20 µs. The MCU's 12-cycle entry at 72 MHz is Arm's figure for the Cortex-M3. Boot stages as in Chapter 2.
Chapter 0
Count the memory a camera needs, then weigh what Linux gives against what it costs
Lesson 1's stop button ran on an STM32F103 with 20 KB of RAM. Now the product grows. It must stream a 720p camera over Wi-Fi, keep logs on an SD card and serve a settings page. Each of those is a large program that someone already wrote, for Linux.
Start with memory. How many bytes do the camera's frames need? Call the frame's width w and its height h, in pixels. Call the bytes per pixel b, and the number of frames held at once n. The memory is M:
M equals w times h times b times n.
Multiply the width w by the height h to count the pixels. Multiply by b to get the bytes of one frame. Multiply by n for every frame you hold.
With w = 1,280, h = 720, b = 2 and n = 3: M = 5,529,600 bytes, 5.53 MB. The STM32F103C8 has 20,480 bytes of SRAM, so the frames need 270 times its whole memory.
That moves you to a microprocessor (MPU) board with external DRAM (Lesson 1, Chapter 1), and to an operating system. Embedded Linux is the same kernel that runs on a laptop, configured for one board: only its drivers, compiled for its CPU, with a small set of programs.
Each bar is the RAM a platform has, on a log scale. The teal line is what your features need. Turn features on and watch which platforms still fit.
Illustrative sizes. The 20 KB is the STM32F103C8's SRAM (datasheet); 512 KB stands for a larger MCU with an RTOS; 2 GB stands for an MPU board. Feature memory is a round guess, except the camera, which is the equation above, and the screen: 1,024 × 600 pixels × 2 bytes × 2 buffers.
Linux gives you a network stack, file systems, USB and thousands of drivers. It costs three things. The board boots for seconds, not milliseconds. A kernel sits between your code and every pin. And the time to answer an event has a long tail, which matters when a deadline is hard. Many products use both: Linux for the camera and the network, and a small MCU beside it for the hard stop.
Symptom: the motor loop on the Linux board jerks when someone opens the settings page.
Measure: log the loop's period for an hour and look at the worst value, not the mean.
Fix: move the hard loop to a helper MCU, or use PREEMPT_RT and a real-time priority (Chapter 8).
Chapter 1
Cross-compile for the board's CPU, and read the two errors a wrong binary gives
You write and build code on your laptop, the host. It runs on the board, the target. The host is usually x86-64 and the target is ARM. Each CPU runs only its own instruction set, so a program built for the laptop cannot run on the board.
A cross-compiler runs on the host and makes code for the target. Its name is a prefix that states the target: arm-linux-gnueabihf-gcc builds for 32-bit ARM, Linux, the GNU EABI with hardware floating point. aarch64-linux-gnu-gcc builds for 64-bit ARM. The target's headers and libraries live in a sysroot, a folder on the host that copies the board's /usr/include and /usr/lib. The flag --sysroot points the compiler at it.
Build a program, then pick a board to run it on. The kernel checks the CPU number in the header first, then looks for the loader the program names.
The e_machine numbers are the kernel's elf-em.h; the loader paths are glibc's and musl's standard names. The musl board stands for a Buildroot image built with musl. The 32-bit program on a 64-bit board assumes the kernel's 32-bit support (CONFIG_COMPAT) is on. Sizes are illustrative.
The board's kernel makes two checks before your program runs. First it reads the ELF header, the first bytes of the file. Its field e_machine, at byte 18, names the CPU: 62 for x86-64, 40 for 32-bit ARM, 183 (0xB7) for 64-bit ARM. A wrong number gives Exec format error.
Second, a dynamically linked program names an interpreter: the loader that maps its shared libraries. glibc on 64-bit ARM uses /lib/ld-linux-aarch64.so.1; musl uses /lib/ld-musl-aarch64.so.1. If the named file is missing on the board, the shell says not found about a file you can see. A static build carries its libraries inside and needs no loader. The cost is size: hundreds of kilobytes instead of a few.
bash aarch64-linux-gnu-gcc --sysroot=/opt/sysroot -O2 -o hello hello.c readelf -h hello | grep Machine # Machine: AArch64 readelf -l hello | grep interpreter # /lib/ld-linux-aarch64.so.1 scp hello root@board:/root/ && ssh root@board ./hello
Symptom: ./app: not found, although ls shows the file.
Measure: run readelf -l app | grep interpreter on the host, then look for that path on the board.
Fix: build against the board's own sysroot and C library, or link static.
Chapter 2
Follow the board from power-on to your program, and find where the seconds go
At power-on the DRAM does not work yet: the chip must set up its controller first. So the boot runs in stages. Each stage runs from the memory it has, and prepares the memory for the next stage.
bootdelay seconds for a key (2 by default), then runs bootcmd: copy the kernel and the device tree into DRAM, and jump.bootargs, starts its drivers and mounts the root file system that root= names.How long does a stage take to copy an image? Call the image's size S, in megabytes, and the storage's read speed B, in megabytes per second. The time is t:
t equals S over B.
Divide the size S by the speed B. A faster disk or a smaller image cuts t.
With made-up speeds: 8 MB from an SD card at 20 MB/s takes 0.4 s. Over TFTP at 10 MB/s it takes 0.8 s. From eMMC at 100 MB/s it takes 0.08 s.
Warm bars are code that runs; the blue bar copies the kernel; the yellow bar only waits. Change one choice at a time and watch which bar shrinks.
Illustrative times. ROM 0.1 s, SPL 0.3 s and U-Boot 0.6 s are round guesses; kernel start 1.6 s with every driver or 0.9 s trimmed; systemd 2.5 s or BusyBox 0.4 s to your program. The 2 s delay is U-Boot's default CONFIG_BOOTDELAY.
Copying is rarely the big cost. In the default toy, the boot delay, the kernel's driver start-up and systemd take 6.1 of the 7.5 s. Set bootdelay to 0, trim the kernel to the board's drivers and use BusyBox init, and the boot takes 2.34 s.
While you develop, boot over the network. U-Boot loads the kernel by TFTP, and the kernel mounts its root file system from the host by NFS. Rebuild on the host and the board runs the new code on the next boot, with no SD card to swap.
Symptom: the console stops after Starting kernel ..., or ends in VFS: Unable to mount root fs.
Measure: read the last console line. It names the stage that stopped.
Fix: for the root file system, check root= in bootargs against the real partition, and check that the kernel image holds the disk's driver (Chapter 3).
Chapter 3
Set each kernel option to built-in, module or off, and find the choice that stops the boot
The kernel has thousands of options, kept in a file called .config. Each driver can be y, built into the kernel image; m, a module, a .ko file on the root file system that loads later; or n, not built. Start from the board's defconfig, then change it with make menuconfig.
The board's root file system is ext4 on an SD card. Set each option, then read the image size and the boot result. Try the SD driver as a module.
Illustrative sizes: core 3.0 MB, networking 1.1, Wi-Fi 0.6, graphics 1.2, sound 0.5, USB 0.4, ext4 0.35, SD/MMC 0.2. Wi-Fi depends on networking, so this toy builds networking in whenever Wi-Fi is on. The panic line is the kernel's real message.
The trap is the root file system. The kernel loads modules from /lib/modules, which lives on the root file system. So the drivers that mount it, here the SD host and ext4, cannot be modules on that same disk. Build them in, or add an initramfs: a small file system that the bootloader loads into RAM with the kernel. It holds those modules and mounts the real root.
In the toy, the core plus the SD host and ext4 make a 3.55 MB image that boots. Set everything else to m and the image stays at 3.55 MB: the other drivers wait on the disk until a device needs them.
The root file system also needs programs: init, a shell, the C library and your app. Two tools build the whole image from source. Buildroot is a set of Makefiles: one make menuconfig picks a cross toolchain, a root file system, a kernel and a bootloader, and make writes them to output/images. The Yocto Project builds with BitBake from layers of recipes. It takes longer to learn and its first build is long, but its layers keep the chip vendor's support, your product and your updates apart.
| Tool | Engine | Default init | Good for |
|---|---|---|---|
| Buildroot | Makefiles and Kconfig | BusyBox init | a small fixed image; a full rebuild after a config change |
| Yocto Project | BitBake, layers of recipes | set by the distribution | products with many variants, package feeds, an SDK; sstate caching speeds rebuilds |
Symptom: Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(0,0).
Measure: grep .config for the disk's host driver and its file system. "=m" with no initramfs is the cause.
Fix: set both to y, or build an initramfs that carries them.
Chapter 4
Match a node to a driver by its compatible string, and translate the address the node gives
On a PC, the firmware tells Linux what hardware exists. On most ARM boards nothing does, so you describe the board in a device tree: a text file (.dts) compiled into a blob (.dtb) that U-Boot hands to the kernel. Each node says what a device is, where its registers are and what it connects to.
dts status_led: led { compatible = "mycompany,my-led"; /* which driver */ gpios = <&gpio 17 GPIO_ACTIVE_HIGH>; /* which pin */ status = "okay"; };
The compatible string names the device as "manufacturer,model". A driver lists the strings it handles in its of_match_table. When a node's string matches, the kernel calls the driver's probe() with that node. So one driver binary serves every board, and only the .dtb changes. The kernel skips a node with status = "disabled".
The reg property gives an address on the node's own bus. Its parent's ranges property maps a window of bus addresses onto CPU addresses. Call the address in reg a. Call the window's start on the bus c, and its start on the CPU side p. The CPU address is A:
Big A equals small a minus c plus p.
reg, on the bus: 0x7e200000 for the GPIO block.ranges entry.Subtract c from a to get the offset inside the window. Add p to place that offset in the CPU's map. The offset must be smaller than the window's length.
The kernel's bcm2711.dtsi (Raspberry Pi 4) maps bus 0x7e000000 to CPU 0xfe000000. So A = 0x7e200000 − 0x7e000000 + 0xfe000000 = 0xfe200000. The bcm2837.dtsi (Pi 3) maps it to 0x3f000000, so the same node lands at 0x3f200000.
The driver on the right never changes. Change the board, the LED's pin or the node itself, and watch probe() and the address.
The ranges and the GPIO block at bus address 0x7e200000 come from the kernel's bcm2711.dtsi, bcm2837.dtsi and bcm283x.dtsi; GPSET0 sits 0x1c into that block. "mycompany,my-led" is a made-up driver.
Symptom: the module loads, but there is no probe message and no device.
Measure: look for the node under /proc/device-tree. Compare its compatible string, byte for byte, with the driver's table, and read its status.
Fix: correct the string, or set status = "okay". A driver that waits for a clock or regulator is a different fault: Device Tree and the Device Model covers deferred probe.
reg says 0x7e200000. Its parent maps bus 0x7e000000 to CPU 0x3f000000. What address does the driver map?Chapter 5
Load code into the kernel, then follow one write from echo to the LED
Your app runs in user space: its own memory, walled off by the CPU's memory management unit. If it reads a bad pointer, the kernel kills only that process, with a segmentation fault. The kernel runs in kernel space and can touch everything. A bad pointer there is an oops, and it can stop the whole board.
A kernel module is code you load into the running kernel with insmod and remove with rmmod. It has an init function and an exit function. It logs with printk to a ring buffer that dmesg prints. The kernel has no C library: no printf, no malloc.
To reach hardware from user space, a driver appears as a file. A character device, such as /dev/myled, is a stream of bytes. The driver fills a struct file_operations with its open, read, write and release functions. The kernel calls them when a program opens, reads or writes the file.
Press Trace to send echo 1 > /dev/myled down the layers. Then make the driver read the user's pointer directly, and hand it a bad pointer.
Simplified path; real calls go through more layers. The register address is the Pi 4's GPSET0 (Chapter 4). Major 240 stands for a number that alloc_chrdev_region could pick.
The kernel finds the driver by a device number with two parts. The major number picks the driver; the minor number picks one of the devices it runs. Call them M and m. Inside the kernel they pack into one number, dev:
dev equals big M times two to the twenty, plus small m.
dev_t, made by MKDEV.MINORBITS in kdev_t.h).Shift the major M left by 20 bits, which is the same as multiplying by 220. Put the minor m in the low 20 bits. MAJOR() and MINOR() undo it.
Major 240, minor 0: dev = 240 × 1,048,576 + 0 = 251,658,240, or 0x0F000000. User space prints the same pair as 240, 0 in ls -l /dev/myled.
Never read a user pointer directly in a driver. copy_from_user() copies the bytes, and returns an error that the driver turns into -EFAULT if the pointer is bad. The program then gets a failed write(). A direct read of the same pointer is an oops.
c static ssize_t myled_write(struct file *f, const char __user *buf, size_t len, loff_t *off) { char c; if (len < 1) return -EINVAL; if (copy_from_user(&c, buf, 1)) return -EFAULT; /* never *buf */ gpiod_set_value(led_gpio, c == '1'); return len; }
Symptom: a write to /dev/myled freezes the board, or dmesg shows "Unable to handle kernel paging request".
Measure: the oops names the function and the offset, for example myled_write+0x1c.
Fix: copy with copy_from_user() and check what it returns.
write(). The driver uses copy_from_user(). What happens?Chapter 6
Let probe() take its pins from the device tree, then show a sensor's reading as a sysfs file
Chapter 5's driver needs to know its pin. A platform driver gets it from the device tree. In probe(), devm_gpiod_get() asks for the GPIO named in the node. Every devm_ function frees its resource when the device goes away, so the driver has no cleanup code to forget.
c static int my_led_probe(struct platform_device *pdev) { struct gpio_desc *g = devm_gpiod_get(&pdev->dev, NULL, GPIOD_OUT_LOW); if (IS_ERR(g)) return PTR_ERR(g); /* the pin comes from the node */ platform_set_drvdata(pdev, g); return 0; } static void my_led_remove(struct platform_device *pdev) /* void since Linux 6.11 */ { gpiod_set_value(platform_get_drvdata(pdev), 0); }
Many drivers publish values through sysfs: files under /sys, one value each, as text. A temperature driver registers with the hwmon subsystem, which creates temp1_input: the temperature in millidegrees Celsius. A program reads it with cat and never touches I²C.
Take a TI TMP102 sensor at I²C address 0x48. Its temperature register holds a signed 12-bit number in its top 12 bits, in steps of 0.0625 °C. Read the 16-bit register as a signed number and call it s. The temperature is T:
T equals s over sixteen, times zero point zero six two five degrees.
Read the two bytes, most significant first, as a signed number s. Divide by 16 to get the count of steps. Multiply by 0.0625 to get T. hwmon wants millidegrees, so multiply by 1,000.
At 25 °C the register reads 0x1900 = 6,400. 6,400 / 16 = 400 steps, and 400 × 0.0625 = 25.0 °C: temp1_input shows 25000. At −25 °C it reads 0xE700, which is −6,400 as signed: −25.0 °C.
Drag the true temperature (pink). Purple is what the sensor stores and what the driver computes. Take it below zero with each version of the driver.
TMP102 in its default 12-bit mode, rounded to the nearest step. The mainline tmp102 driver uses the chip's 13-bit extended mode instead, so it divides by 128; the sign rule is the same.
The trap is the sign. If the driver shifts the unsigned value, 0xE700 becomes 3,696 steps: 231.0 °C. The old version of this lesson had exactly that bug. The kernel's own tmp102 driver reads the register into an s16 first.
Symptom: a sensor in a freezer reports 231 °C.
Measure: cool it below 0 °C and print the raw register next to the result.
Fix: treat the register as an s16 before you shift, or use sign_extend32().
Chapter 7
Let systemd start, watch and restart your program, and compute the worst downtime
The board boots with nobody logged in, yet your program must run, and run again if it dies. systemd, process 1 on most distributions, starts services from unit files. Old Unix daemons forked and detached themselves; under systemd, write a plain loop that stays in the foreground. systemd handles the start order, the logs in its journal, and restarts.
ini # /etc/systemd/system/tempmon.service [Unit] Description=Temperature monitor [Service] Type=notify # started when the program sends READY=1 ExecStart=/usr/bin/tempmon Restart=always RestartSec=5 WatchdogSec=30 [Install] WantedBy=multi-user.target
Restart=always restarts the service whenever it exits, cleanly or not; on-failure skips clean exits. A crash is easy to see. A hang is not: the process is alive but does nothing. So WatchdogSec=30 asks the program to send WATCHDOG=1 with sd_notify(). If 30 s pass without one, systemd kills the service and restarts it. systemd's manual advises a ping every half interval, here 15 s.
How long can the service be down? Call the time systemd takes to notice the failure Tdet, the restart delay Trs and the program's start-up time Tst. The downtime is Tdown:
T-down equals T-det plus T-r-s plus T-s-t.
WatchdogSec for a hang.RestartSec, 100 ms by default.Add the three waits in order. A hang just after a ping waits almost the whole watchdog interval, so the worst T-det for a hang is WatchdogSec.
With the unit above and a made-up 1 s start: a crash gives 0 + 5 + 1 = 6 s. A hang gives at most 30 + 5 + 1 = 36 s.
The warm lane is the service running; yellow ticks are watchdog pings. A crash comes at 20 s and a hang at 60 s. Change the settings and read the downtime.
Illustrative program: it starts in 1 s and pings every half interval. A watchdog of off means no WatchdogSec line. With NotifyAccess unset, systemd accepts notifications only from the main process (systemd.service manual).
Symptom: the service restarts every 30 s, although it works.
Measure: journalctl -u tempmon shows a watchdog timeout. The pings come from a helper process, and systemd ignores them.
Fix: send the pings from the main process, or set NotifyAccess=all.
Chapter 8
Add up what can delay a wake-up, then see what PREEMPT_RT takes away
A 1 kHz control loop must wake every millisecond. The time from when it should run to when it runs is its latency. The mean hardly matters: one late cycle can trip a motor. The Real-Time Mental Model covers deadlines, tails and scheduling. Here we look at what the kernel adds.
In the worst case, three delays add up. Call the time from the interrupt to its handler tirq. Call the longest stretch of kernel code the scheduler cannot interrupt tnp, for "not preemptible". Call the wake-up and context switch tsw. The worst latency is Lmax:
L-max equals t-irq plus t-n-p plus t-s-w.
Take the worst value of each delay and add them. The wake-up can land at the start of the longest section, so it waits for all of t-n-p.
With the toy's values: stock kernel, 3 + 2,500 + 14 = 2,517 µs, two and a half deadlines. PREEMPT_RT, 7 + 20 + 14 = 41 µs.
The middle term is the problem. On a stock kernel, one slow driver that holds a spinlock sets t-np for every task. PREEMPT_RT turns most spinlocks into sleeping locks with priority inheritance, runs interrupt handlers as threads, and breaks up long sections. A high-priority task can then preempt almost all kernel code. Mainline Linux 6.12 (November 2024) merged it for x86, arm64 and RISC-V. It costs some throughput.
The top bar is the bound from the equation. Below, the toy runs the 1 kHz loop for the chosen time. Run longer, and watch the worst wake-up climb toward the bound.
The same illustrative toy as the hero, with a fixed seed. Real numbers depend on the board, the drivers and the load: measure yours with cyclictest.
In the toy at full load, stock Linux misses 72 of 60,000 cycles in one minute, and 3,755 in an hour. PREEMPT_RT misses none; its worst is 40.8 µs. The kernel is half the job. Run the loop as SCHED_FIFO with a priority above the load, call mlockall() so it never waits for a page fault, and measure with cyclictest for hours.
Symptom: stalls of about 2 ms, a few times a minute, only under load.
Measure: run cyclictest -m -p 90 for hours beside the real load. Check uname -v for PREEMPT_RT and chrt -p for the loop's policy.
Fix: an RT kernel, a SCHED_FIFO priority, mlockall(), and a CPU kept free of other work.
Chapter 9
Boot a board with six planted faults, and name each fault from the line where the console stops
A new board must boot from its SD card, run the temperature service and the LED driver, and hold a 1 kHz loop under load. We planted six faults, one from each chapter. Boot it, read the last line of the console, fix that fault, and boot again.
Each lit button is a planted fault. Press Boot and read where the log stops. Then press the fault it names to fix it, and boot again.
Illustrative board and log, shortened. The panic and error lines follow the real kernel and systemd messages; 179 is the block major of SD and eMMC devices. The loop numbers come from the Chapter 8 toy at full load for one minute.
| Fault | Where the log stops | Chapter |
|---|---|---|
| root=/dev/mmcblk0p3 | VFS: Cannot open root device; panic on unknown-block(179,3) | 2 |
| SD driver as a module | panic on unknown-block(0,0): no disk at all | 3 |
| tempmon built for x86-64 | Failed to execute /usr/bin/tempmon: Exec format error | 1 |
| "mycompany,my-lde" | no probe; open /dev/myled: No such file or directory | 4 |
| Pings from a helper | Watchdog timeout, then a restart every 30 s | 7 |
| Stock kernel | 72 missed deadlines in 60 s, worst 2.40 ms | 8 |
The log tells you the order. A fault in an early stage hides every later one, so fix from the top. The last fault prints no error at all: the board boots and runs, and only a long latency test finds it.
Chapter 10
Keep the numbers, the bug table and the next steps in one place
An embedded Linux board is a stack of contracts. The binary must match the CPU and the loader. Each boot stage must find the next one and the memory for it.
The kernel must have the root disk's drivers built in. The device tree must name what the driver matches. The driver must copy across the user boundary and get the sign right. A service needs a watchdog to recover from a hang, and a hard loop needs a bounded worst case.
| Quantity | Rule | Example |
|---|---|---|
| Frame memory | w × h × b × n | 720p, 3 frames: 5.53 MB |
| Image copy | S / B | 8 MB at 20 MB/s: 0.4 s |
| Boot time | sum of the stages | 7.5 s, trimmed 2.34 s |
| Bus to CPU address | a − c + p | 0x7e200000 to 0xfe200000 |
| Device number | M × 220 + m | 240:0 is 251,658,240 |
| TMP102 reading | (s / 16) × 0.0625 °C | 0xE700: −25.0 °C |
| Downtime | Tdet + Trs + Tst | hang: 30 + 5 + 1 = 36 s |
| Worst latency | tirq + tnp + tsw | 2,517 µs; RT 41 µs |
| Bug | Symptom | What names it |
|---|---|---|
| Wrong CPU | Exec format error | readelf -h: Machine |
| Wrong C library | "not found" for a file that exists | readelf -l: interpreter |
| Wrong root= | panic, unknown-block(179,N) | bootargs against the partition table |
| Root driver as module | panic, unknown-block(0,0) | =m in .config, no initramfs |
| Compatible typo | no probe, no device | /proc/device-tree against of_match_table |
| Direct user pointer | oops on a bad write | the oops: function and offset |
| Unsigned sensor value | 231 °C in a freezer | raw register below 0 °C |
| Ignored pings | restart every WatchdogSec | journal: watchdog timeout |
| Long kernel section | rare ms stalls under load | hours of cyclictest |
python def frame_bytes(w, h, b, n): return w * h * b * n def copy_time(size_mb, mb_per_s): return size_mb / mb_per_s def dt_translate(a, child_base, parent_base, length): off = a - child_base assert 0 <= off < length, "address outside the window" return parent_base + off def mkdev(major, minor): return (major << 20) | minor def tmp102_c(reg): s = reg - 65536 if reg >= 32768 else reg # read as signed 16-bit return (s / 16) * 0.0625 def downtime(detect, restart_sec, start): return detect + restart_sec + start def worst_latency(t_irq, t_np, t_sw): return t_irq + t_np + t_sw
We ran each function. frame_bytes(1280, 720, 2, 3) gives 5,529,600. copy_time(8, 20) gives 0.4. hex(dt_translate(0x7e200000, 0x7e000000, 0xfe000000, 0x1800000)) gives 0xfe200000. mkdev(240, 0) gives 251,658,240. tmp102_c(0xE700) gives −25.0. downtime(30, 5, 1) gives 36. worst_latency(3, 2500, 14) gives 2,517.
Where it sits. Lesson 1 met the MCU and its interrupts; Lesson 4 wired its buses. This lesson puts a kernel between your code and those buses. Next come deadlines and scheduling in depth: Real-Time Systems and RTOS.
Now teach it: press Present or Teach and explain why each boot stage exists, and why one slow driver sets a stock kernel's worst latency. Then go back to the three platforms and predict where each one's slowest answer lands before you raise the load.