Skip to content

wisonye/embedded-tutorial-with-rp2040

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

75 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

All-in-one Embedded Tutorial With Raspberrypi RP2040 MCU

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.

The major purposes of this tutorial:

  1. 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.
  2. The real-world demo to show how to use C, Zig and ARM assembly in embedded programming.
  3. How to mix Zig and C in low-level hardware development.

RP2040 MCU and Raspberry Pi Pico W board datasheet

All demos in this tutorial use the Raspberry Pi Pico W microcontroller, you can download the related resources from here:

Major datasheets

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.

Pin and PCB related

Pico/Pico W C/C++ SDK related

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.

Folder structure

.
├── 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

Tutorial chapters

1. Glossary of terms

  1. Basic concepts

    2.1 What is MCU, SOC and SBC

    2.2 Well-known MCU families

    2.3 MCU memory (very important)

    2.4 Memory layout (very important)

  2. Install tooling

    3.1. Install ARM GNU Toolchain

    3.2. Setup PICO C/C++ SDK

    3.3. Setup PICO Examples when you needed

  3. Write your first program and run on Pico W

    4.1 How does your program tell MCU what to do

    4.2 Bitwise operations to control RP2040 register

    4.3 Blinking led by the RP2040 register

  4. 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 UART

    5.3 Solve the losing printf content after stdio_init_all(); call

    5.4 How cmake build your pico program

    5.5 How you main function gets called

  5. SPI (Serial Peripheral Interface)

    6.1 How SPI works

    6.2 SPI demo

  6. Interrupt

    7.1 How Interrupt works

    7.2 How to write ARM startup file and linker script from scratch

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published