Bare-metal examples logo

Bare-metal examples

Free

Progressive bare-metal programming tutorials for Raspberry Pi

FreeFree tier
Type
Open Source

About Bare-metal examples

A collection of bare-metal examples for the Raspberry Pi (including Pi, Pi b+, and Pi 2) that guide users from simple LED blinking to advanced topics like exception handling and timer interrupts. Each example is numbered and builds upon previous ones, especially the UART setup. The repository includes both assembly and C/C++ examples, with automatic detection of the Raspberry Pi model after the fourth example. Users can build the examples using a cross-compiler (typically arm-none-eabi-gcc) and copy the resulting .img file to an SD card to boot. The project also mentions raspbootin for uploading images over serial without removing the SD card.

Key Features

Numbered examples from simple to complex
Supports Raspberry Pi, Pi b+, and Pi 2 models
Automatic model detection from example 004 onward
Examples in both Assembly and C/C++ (C++ in later examples)
Builds bootable .img files from cross-compilation
Includes UART output, echo, printf, exception handling, timer sleep, and more
Optional raspbootin for serial upload without SD card removal

Pros & Cons

Pros
  • Well-structured progressive difficulty; each example builds on previous ones
  • Covers multiple Raspberry Pi models with auto-detection
  • Open source and free to use, modify, and distribute
  • Includes both assembly and C/C++ examples for different learning preferences
  • Active repository with 32 stars and 7 forks (community interest)
Cons
  • Requires setup of an arm cross-compiler toolchain (arm-none-eabi-)
  • Only officially supports Raspberry Pi, Pi b+, and Pi 2 (not Pi 3/4/Zero directly without modification)
  • No pre-built binaries or releases; users must build from source
  • Limited documentation beyond README; examples are code-heavy with minimal explanatory comments

Best For

Learning bare-metal (no operating system) programming on Raspberry PiUnderstanding low-level hardware interaction (GPIO, UART, interrupts, timers)Educational resource for embedded systems courses or self-studyPrototyping custom kernel or firmware for Raspberry Pi

FAQ

What is the purpose of this repository?
It provides a series of bare-metal examples for the Raspberry Pi (Pi, Pi b+, Pi 2) ranging from simple LED control to advanced topics like exception handling and timer interrupts. Each example is numbered and builds upon previous ones, allowing users to progressively learn low-level programming without an operating system.
How do I build the examples?
Each example can be built by running 'make' inside its directory, using a cross compiler prefixed with 'arm-none-eabi-' (e.g., arm-none-eabi-gcc) that must be in your PATH. You can also run make from the top directory to build all examples at once.
How do I run the examples on my Raspberry Pi?
After building, the project creates a bootable *.img file. Copy that file to your SD card and boot your Raspberry Pi. For the first few examples, you need to choose the correct flavor for your Pi model; later examples auto-detect the model.
Do I need a cross-compiler?
Yes, the examples require an ARM cross-compiler (typically arm-none-eabi-gcc) to build. You can specify a different compiler by exporting the CROSS, CC, or CXX variables.
Can I test without removing the SD card each time?
Yes, the author recommends using 'raspbootin', which allows you to upload the image over a serial connection without taking out the SD card.