bare metal experiment with pi zero

71cc5c7 SD WIP

3 months ago

803c555 Add SD setup with EMMC

3 months ago
This project documents an ongoing experiments conducted to run Raspberry
 Pi-Zero baremetal, focusing on BCM2865 SoC peripherals and ARMv6 assembly. The
 experiments are intentionally Pi-Zero  specific to remove generic logics and
 codes for other Raspberries.  Ultimately an operating system will be
 handcrafted at the very end.

Hardware overview:
    - Raspbery Pi-Zero (W is optional for early stages) with header pins
    - Micro SD card (and a reader)
    - UART to USB bridge
    - SSD1306 (or any I2C display with datasheet that you understand)
    - Arduino (or any I2C slave capable MCU that you know how to use)*
    - Breadboard, some resistors and capacitors, a TRRS audio jack breakout,
       some wires.  (For low pass filter in pwm audio experiment, can be
    - A passive playback device (e.g. cheap headset), tiny chance that it might
       be damaged.  Avoid using your high end audio gear.

* optional

To start, a cross compiler targeting `arm-none-eabi` is required.  OSDev wiki
 has provided a very nice guide:


The bootcode.bin and start.elf is required:


Format the card with FAT32 and copy the files into it.  The files will instruct
 the pi to load kernel.img and execute it.  Each experiments will output a bin
 file which can be renamed into kernel.img and works.

Discussions are welcomed.

Experiments (in order of simplicity):
    1. blinker
    2. uart
    3. oled (i2c)
    4. pwm (audio)

Recommended Reading Order
    1. blinker
    2. uart
    3. bootloader
    4. oled
    5. hal *s
    6. pwm

*s - Software Topic

Global notes:
    - The BCM peripherals address space is 0x20XXXXXX instead of 0x7EXXXXXX in
       ARM window. (see

List of community resources that has been of great help throughout the process:
    - https://github.com/dwelch67/raspberrypi
    - https://elinux.org/RPi_BCM2835_GPIOs

Useful datasheets and documentations:
    - BCM2835 ARM Peripherals
    - ARM Architecture Reference Manual
    - ARM1176JZF-S Technical Reference Manual
    - binutils Documentation, and the AArch64-specific parts