Do you pine for the nice days of 8-bit microcontrollers, when men were men and wrote their own device drivers?
This repository is a comprehensive guide to programming the Raspberry Pi Pico board based on the RP2040 microcontroller, without relying on the Pico-SDK, operating system or additional software layers. Here, you'll find examples to better understand the RP2040 boot process, how to writing a linker script to load the code to Flash memory or to RAM, configuring peripherals like GPIOs, clocks, PLLs, interrupts, and more.
By exploring baremetal programming, you'll gain a deep understanding of the RP2040's inner workings and unleash its full potential. Whether you're a beginner or an experienced developer, this project provides the knowledge and resources needed to excel in baremetal programming.
Key Features:
- Clear examples: The project includes a variety of examples with detailed explanations with little complexity.
- In-depth explanations: Understand the underlying concepts and mechanisms of baremetal programming.
- Step-by-step tutorials: Practical, hands-on learning experience from setup to running code on the Raspberry Pi Pico.
Please note that in all the examples provided in this project, the code is intentionally written in an explicit manner, prioritizing clarity over optimization. While advanced programmers may find more efficient ways to implement the same functions with fewer lines of code, my goal here is to ensure that beginners can easily follow along without getting lost in abstract or complex code snippets. The emphasis is on understanding the concepts and principles behind each step, rather than on achieving the most optimized code.
I hope you find this GitHub project inspiring as you embark on your journey into the world of baremetal programming with the RP2040 microcontroller.
Enjoy exploring and building amazing things!
To get started with this GitHub project, you will need to follow a few prerequisites. Here are the steps required to begin using the project effectively:
-
Biuld machine: This project has been developed and verified on a Linux machine. It is recommended to use a PC with Ubuntu or a Raspberry Pi with Raspbian. The Raspberry Pi Foundation provides strong support for Linux, making it ideal for code development related to the Raspberry Pi Pico.
-
Install Tools and SDK: Follow the instructions provided in the official Raspberry Pi Pico C/C++ SDK documentation to install the necessary build tools (gcc for ARM, CMake, etc.) and the Pico-SDK. The SDK contains essential files and utilities that will be required. Make sure to have these installed on your system before proceeding.
-
RP2040 Based Board: You will need an RP2040 based board to work with this project. The examples and code have been tested on an original Raspberry Pi Pico board. While it is possible to use a different board, please note that you may need to make adaptations to the code. For instance, the on-board LED may be connected to a different GPIO, or the board may use a different external flash memory.
By following these prerequisites, you will set up your development environment and have the necessary tools and hardware to dive into the GitHub project successfully.
-
By using Microsoft Visual Studio Code with the Remote SSH extension on your Destop PC, you can work remotely on the source code and flash the Pico on the Raspberry Pi (via SSH). I incluided a json file to be able to build the examples by presing ctrl+shift+b.
-
The UF2 converter provided in the pico-sdk follows a strict memory map. As I'm not using the linkler script provided in the SDK, in some cases my .elf file did not fulfill the converter memory rules. For that reason I searched for an open source alternative and found the ELF-to-UF2 converter from Microsoft. By using the --wait option, the converter waits the RPI-RP2 drive to be mounted to copy the generated UF2 file there. Very convenient.
-
Serial port:
- When working with serial port with RPI4, use "sudo raspi-config" -> 3 Interfaces Options -> I6 Serial port to disable shell messages on the serial port and to enable it.
- if still there is unwanted data on the RPI4 serial port, then disable the following services: "sudo systemctl disable serial-getty@serial0.service"
-
To generate the CMSIS Header file out of the rp2040.svd provided in the pico sdk:
- SVDconv tool: https://github.com/Open-CMSIS-Pack/devtools
- svd file: ~/pico/pico-sdk/src/rp2040/hardware_regs/rp2040.svd
- commnad: ./SVDConv rp2040.svd --generate=header --fields=struct --fields=macro --fields=enum --debug-headerfile
- I had to add manually the peripheral declaration for the XOR, CLR and SET atomic access.
-
Debugging with J-Link:
-
Raspberry Pi
-
ARM
-
UF2
- Covenrter
-
BMP280 Digital Pressure Sensor