Project 5: Context-Switching Mini-Kernel (Raspberry Pi Pico)
A cooperative multi-tasking kernel in assembly that can switch between multiple “tasks,” each with its own stack, giving you a foundation for understanding how RTOSes work.
Quick Reference
| Attribute | Value |
|---|---|
| Primary Language | See main guide |
| Alternative Languages | N/A |
| Difficulty | Level 5: Master |
| Time Estimate | 2-4 weeks |
| Knowledge Area | Operating Systems / Embedded |
| Tooling | Raspberry Pi Pico |
| Prerequisites | Projects 1-2 completed, understanding of stacks and function calls |
What You Will Build
A cooperative multi-tasking kernel in assembly that can switch between multiple “tasks,” each with its own stack, giving you a foundation for understanding how RTOSes work.
Why It Matters
This project builds core skills that appear repeatedly in real-world systems and tooling.
Core Challenges
- Understanding which registers must be saved/restored (caller-saved vs callee-saved)
- Implementing stack switching between tasks
- Using PendSV exception for safe context switches
- Setting up SysTick for preemptive scheduling (advanced)
- Managing task control blocks (TCBs) in assembly
Key Concepts
- Context Switching Mechanics: “Operating Systems: Three Easy Pieces” Ch. 6-7 - Arpaci-Dusseau
- Cortex-M Exception Model: “The Art of ARM Assembly, Volume 1” Ch. 14 - Randall Hyde
- AAPCS Register Usage: “Modern Arm Assembly Language Programming” Ch. 2 - Daniel Kusswurm
- PendSV for Context Switch: ARM Cortex-M Baremetal Assembly Programming - Engineers in Pyjama
Real-World Outcome
[BOOT] Mini-Kernel v1.0 starting...
[INIT] Task 1: LED Blinker (500ms) - Stack @ 0x20003000
[INIT] Task 2: UART Logger (1000ms) - Stack @ 0x20003800
[INIT] Task 3: Counter (250ms) - Stack @ 0x20004000
[SCHED] Starting cooperative scheduler...
[T1] Blink! LED ON
[T3] Counter: 0
[T3] Counter: 1
[T2] Logger tick: 1
[T1] Blink! LED OFF
[T3] Counter: 2
[T3] Counter: 3
[T2] Logger tick: 2
[T1] Blink! LED ON
...
Implementation Guide
- Reproduce the simplest happy-path scenario.
- Build the smallest working version of the core feature.
- Add input validation and error handling.
- Add instrumentation/logging to confirm behavior.
- Refactor into clean modules with tests.
Milestones
- Milestone 1: Minimal working program that runs end-to-end.
- Milestone 2: Correct outputs for typical inputs.
- Milestone 3: Robust handling of edge cases.
- Milestone 4: Clean structure and documented usage.
Validation Checklist
- Output matches the real-world outcome example
- Handles invalid inputs safely
- Provides clear errors and exit codes
- Repeatable results across runs
References
- Main guide:
ARM_ASSEMBLY_LEARNING_PROJECTS.md - “Operating Systems: Three Easy Pieces” by Arpaci-Dusseau