~ekangmonyet/bare-pizero

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
       optional)*
    - 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:

    https://wiki.osdev.org/GCC_Cross-Compiler

The bootcode.bin and start.elf is required:

    https://github.com/raspberrypi/firmware/tree/master/boot

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
       https://github.com/dwelch67/raspberrypi/tree/master/boards/pizero/blinker01)


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
        https://www.raspberrypi.org/documentation/hardware/raspberrypi/bcm2835/BCM2835-ARM-Peripherals.pdf
      (IMPORTANT ERRATA!!)
        https://elinux.org/BCM2835_datasheet_errata
    - ARM Architecture Reference Manual
        https://static.docs.arm.com/ddi0100/i/DDI%2001001.pdf
    - ARM1176JZF-S Technical Reference Manual
        https://static.docs.arm.com/ddi0301/h/DDI0301H_arm1176jzfs_r0p7_trm.pdf
    - binutils Documentation, and the AArch64-specific parts
        https://sourceware.org/binutils/docs-2.26/as/AArch64_002dDependent.html#AArch64_002dDependent