All paths

Build a tiny kernel

Your own preemptive kernel on the Uno: task control blocks and hand-built stacks, a context switch in inline assembly, a Timer1 tick, preemption, sleep and semaphores, syscalls, and stack canaries under three tasks at once.

Arduino Uno R3Free7 lessons7 h4 chapters3,800 XPEmbedded engineering · Expert+400 XP

0 of 7 done

What you will build

3 projects, built step by step

7 lessons in 4 chapters, about 7 hours on a simulated Arduino Uno R3. Free, in your browser, every step checked by the simulator.

Chapter 1 project

Context switch in assembly

The heart of every kernel: push all 32 registers and SREG, store SP in the TCB, pick the next task, load its SP, pop and return. Three tasks share the Uno by handing the processor on themselves.

Open it in the simulator
Chapter 2 project

Preemption

Make the tick switch tasks: a naked Timer1 interrupt saves the interrupted task, counts the tick and restores the next one. Tasks that never yield still share, on the logic analyzer, a slice at a time.

Open it in the simulator
Chapter 3 project

Syscalls

One numbered doorway into the kernel: yield, sleep, ticks, write and exit through a table of functions. A task that returns is ended by SYS_EXIT, and the idle loop measures the load.

Open it in the simulator
The map

Chapter by chapter

Each lesson opens when the one before it is done, and each chapter ends in a project.

Chapter 1

Tasks and switching

What a task is, and how the processor moves from one to another.

  1. Open400 XP

    Tasks and stacks

    What a task really is: a function, a stack of its own and a task control block. Build two by hand, read the fake frame on each stack, and launch one by loading its stack pointer and returning into it.

    0 of 7 steps

  2. ProjectLocked800 XP

    Context switch in assembly

    The heart of every kernel: push all 32 registers and SREG, store SP in the TCB, pick the next task, load its SP, pop and return. Three tasks share the Uno by handing the processor on themselves.

    0 of 7 steps

4 questions, graded as you go.
Chapter 2

Time and preemption

A tick of the kernel’s own, and a scheduler that takes the processor back.

  1. Locked350 XP

    A timer tick

    A clock of the kernel’s own: Timer1 in CTC mode interrupts at 100 Hz, leaving Timer0 to millis(). The register math, an atomic read of a two byte counter, and tasks that wait in ticks.

    0 of 6 steps

  2. ProjectLocked700 XP

    Preemption

    Make the tick switch tasks: a naked Timer1 interrupt saves the interrupted task, counts the tick and restores the next one. Tasks that never yield still share, on the logic analyzer, a slice at a time.

    0 of 6 steps

4 questions, graded as you go.
Chapter 3

Waiting and asking

Tasks that block on semaphores, and one doorway into the kernel.

  1. Locked350 XP

    Semaphores

    Waiting without spinning: tasks that sleep, tasks that block, and a counting semaphore that hands a unit straight to the next task in line. Three rovers share a charging dock with two bays.

    0 of 6 steps

  2. ProjectLocked800 XP

    Syscalls

    One numbered doorway into the kernel: yield, sleep, ticks, write and exit through a table of functions. A task that returns is ended by SYS_EXIT, and the idle loop measures the load.

    0 of 7 steps

4 questions, graded as you go.
Chapter 4

Boss project

Three tasks on one Uno, on the kernel you built.

  1. Locked400 XP

    Boss: three tasks on one Uno

    Your whole kernel at work: a beacon, a sensor and a reporter on a 100 Hz preemptive tick, with sleep, a semaphore between sensor and reporter, painted stacks and canaries. Then overflow a stack and watch the kernel catch it.

    0 of 7 steps

3 questions, graded as you go.
Syllabus

Every lesson in the course

All 7 lessons, in order, each with what it covers. Any of them opens in the editor right away.

Chapter 1

Tasks and switching

  1. Tasks and stacksWhat a task really is: a function, a stack of its own and a task control block. Build two by hand, read the fake frame on each stack, and launch one by loading its stack pointer and returning into it.
  2. Context switch in assemblyThe heart of every kernel: push all 32 registers and SREG, store SP in the TCB, pick the next task, load its SP, pop and return. Three tasks share the Uno by handing the processor on themselves.
Chapter 2

Time and preemption

  1. A timer tickA clock of the kernel’s own: Timer1 in CTC mode interrupts at 100 Hz, leaving Timer0 to millis(). The register math, an atomic read of a two byte counter, and tasks that wait in ticks.
  2. PreemptionMake the tick switch tasks: a naked Timer1 interrupt saves the interrupted task, counts the tick and restores the next one. Tasks that never yield still share, on the logic analyzer, a slice at a time.
Chapter 3

Waiting and asking

  1. SemaphoresWaiting without spinning: tasks that sleep, tasks that block, and a counting semaphore that hands a unit straight to the next task in line. Three rovers share a charging dock with two bays.
  2. SyscallsOne numbered doorway into the kernel: yield, sleep, ticks, write and exit through a table of functions. A task that returns is ended by SYS_EXIT, and the idle loop measures the load.
Chapter 4

Boss project

  1. Boss: three tasks on one UnoYour whole kernel at work: a beacon, a sensor and a reporter on a 100 Hz preemptive tick, with sleep, a semaphore between sensor and reporter, painted stacks and canaries. Then overflow a stack and watch the kernel catch it.
Keep going

The next course on your track

Build a tiny kernel is part of the maker track, a ladder of courses from zero to expert.

Next course

Build a voice recorder

A memo pen on an Uno: a microphone on A0, double buffers, an EEPROM that keeps up, real WAV files on microSD, PWM playback and debounced buttons.

Open the next course
Track

Maker track

Follow the starter kit you already own, then build a claw machine, a balance bot, a handheld console or an LED cube, each a short course checked by the simulator.

See every course on the track
Kits

Build it on your bench too

Every lesson runs in the simulator with nothing to buy. When you want the real thing, these kits have the parts.

Have a kit already?

Find your kit

Pick the starter kit you own and run every lesson in its manual with the same parts on the same pins.

See every kit
Questions

About Build a tiny kernel

Is Build a tiny kernel free?

Yes. All 7 lessons of Build a tiny kernel are free and run in your browser, with nothing to install and no parts to buy before you start.

Do I need a real Arduino Uno R3?

No. Every lesson runs on a simulated Arduino Uno R3 with its parts on the canvas, and the simulator checks each step as you go. When you want to build it for real, the same wiring and code work on a real board.

How long does Build a tiny kernel take?

About 7 hours: 7 lessons in 4 chapters, each one a few short steps. Your progress is kept, so you can stop after any lesson and pick up where you left off.

What will I build?

Each chapter ends in a project that puts it together: Context switch in assembly, Preemption and Syscalls.

Where do I start?

With "Tasks and stacks", and each lesson builds on the one before it. New to circuits? Electronics basics is the course that starts from zero.