In this tutorial, we will cover all the pieces of knowledge we need to know for using C, Zig and ARM assembly
to do embedded programming.
Although we’re targeting the RP2040 MCU
, in fact, we still need an MCU board that has the RP2040
to run all demo codes. That’s why we pick the Raspberrypi Pico-W
as our target board to run all the demos.
- Learn the fundamental concepts and knowledge for embedded programming from scratch, what we’ve learned is NOT limited to Raspberry Pi RP2040 MCU, actually, it benefits all MCUs as well.
- The real-world demo to show how to use
C, Zig and ARM assembly
in embedded programming. - How to mix
Zig
andC
in low-level hardware development.
All demos in this tutorial use the Raspberry Pi Pico W microcontroller, you can download the related resources from here:
The following data sheets are the major knowledge sources that we will learn from, as we need to know the fundamental concepts and terms about MCU programming, that’s the best resource.
- Hardware design with RP2040 (Just in case you want to build your own PCB with minimal design to work with
RP2040
MCU) - Pico Pinout Diagram
- Pico W datasheet
In the first demo, we will learn how to use MCU registers to control MCU, as that’s fundamental to how the MCU works. But usually, you should choose to use the existing C/C++ SDK (to call APIs) to deal with RP2040 to get a faster development cycle.
- Pico W C/C++ SDK
- Getting started with Pico (how to debug pico)
- Pico W WIFI and Bluetooth
.
├── README.org # This file
│
├── c-demos # C demos
│ ├── cmake-build-process.org # Explain how cmake builds your pico program
│ │
│ ├── blinking-led-register # Particular demo project
│ │ ├── build.sh # Project scope build script
│ │ ├── CMakeLists.txt # Project scope CMake configuration file
│ │ ├── configure.sh # Project scope configure script to init CMake
│ │ ├── flash_xxx.sh # Flash your program to Pico hardware via USB-C
│ │ ├── minicom.sh # Minicom script
│ │ ├── pico_sdk_import.cmake # `pico-sdk CMake` configuration (copied from PICO_SDK)
│ │ ├── README.org # Project scope README
│ │ └── src # source code files inside
│ └── ... # Another C demos projects
│
├── zig-demos # Zig demos
│ ├── README.org # Zig demo scope README
│ ├── CMakeLists.txt # ZIg demo Top level CMake configuration
│ ├── build.zig # Zig build script
│ ├── flash_xxx.sh # Flash your program to Pico hardware via USB-C
│ ├── minicom.sh # Minicom script
│ ├── extra_include
│ │ ├── lwipopts.h # pico WIFI/TCP/IP support
│ │ └── pico
│ │ └── version.h # Copied from CMake auto generated version header
│ └── src
│ ├── xxx.cmake # Demo CMake configuration
│ ├── xxx.zig # Demo zig entry file
│ └── utils # Shared utils
│ ├── bit_utils.zig # Particular util source file
│ ├── driver # Pico hardware drivers
│ └── register # Pico register implementation
│
└── tutorial # Tutorials folder
├── 1-glossary-of-terms.org # Tutorail chapter files
├── 2-basic-concepts.org # Tutorail chapter files
└── ... # Tutorail chapter files
- Basic concepts
- Install tooling
- Write your first program and run on
Pico W
4.1 How does your program tell MCU what to do
- The important things you need to know about the C/C++ SDK
5.1 Why SDK enables all peripherals by default
5.2 How the
printf
actually print to USB and UART5.3 Solve the losing
printf
content afterstdio_init_all();
call - SPI (Serial Peripheral Interface)
6.1 How SPI works
6.2 SPI demo
- Interrupt
7.2 How to write ARM startup file and linker script from scratch