Skip to content

Commit 49d1234

Browse files
committed
boards: add initial code for Raspberry Pi Pico 2
This commit adds the code for the RP2350 MCU and the RP2350 board that uses that MCU. At the moment, the board supports the following: - UART Console; - Timers; - GPIO with interrupts. It also changes `tock_kernel_layout.ld` because of an apparent bug with arm-none-eabi-objcopy.
1 parent 0fe56e0 commit 49d1234

28 files changed

Lines changed: 6205 additions & 15 deletions

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66
members = [
77
"arch/cortex-m",
88
"arch/cortex-v7m",
9+
"arch/cortex-v8m",
910
"arch/cortex-m0",
1011
"arch/cortex-m0p",
1112
"arch/cortex-m3",
13+
"arch/cortex-m33",
1214
"arch/cortex-m4",
1315
"arch/cortex-m7",
1416
"arch/riscv",
@@ -41,6 +43,7 @@ members = [
4143
"boards/particle_boron",
4244
"boards/pico_explorer_base",
4345
"boards/raspberry_pi_pico",
46+
"boards/raspberry_pi_pico_2",
4447
"boards/apollo3/redboard_artemis_atp",
4548
"boards/apollo3/redboard_artemis_nano",
4649
"boards/apollo3/lora_things_plus",
@@ -92,6 +95,7 @@ members = [
9295
"chips/qemu_rv32_virt_chip",
9396
"chips/psoc62xa",
9497
"chips/rp2040",
98+
"chips/rp2350",
9599
"chips/sam4l",
96100
"chips/segger",
97101
"chips/sifive",

arch/cortex-m/src/mpu.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -156,15 +156,6 @@ impl<const NUM_REGIONS: usize, const MIN_REGION_SIZE: usize> MPU<NUM_REGIONS, MI
156156
}
157157
}
158158

159-
// Function for boards that have TrustZone.
160-
pub const unsafe fn new_ns() -> Self {
161-
Self {
162-
registers: MPU_NS_BASE_ADDRESS,
163-
config_count: Cell::new(NonZeroUsize::MIN),
164-
hardware_is_configured_for: OptionalCell::empty(),
165-
}
166-
}
167-
168159
// Function useful for boards where the bootloader sets up some
169160
// MPU configuration that conflicts with Tock's configuration:
170161
pub unsafe fn clear_mpu(&self) {

arch/cortex-m33/src/lib.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,20 @@
44

55
//! Shared implementations for ARM Cortex-M33 MCUs.
66
7-
#![crate_name = "cortexm33"]
8-
#![crate_type = "rlib"]
97
#![no_std]
108

119
use core::fmt::Write;
1210

1311
pub mod mpu {
14-
pub type MPU = cortexm::mpu::MPU<16, 32>; // Cortex-M7 MPU has 16 regions
12+
use kernel::utilities::StaticRef;
13+
pub type MPU = cortexm::mpu::MPU<16, 32>;
14+
15+
const MPU_BASE_ADDRESS: StaticRef<cortexm::mpu::MpuRegisters> =
16+
unsafe { StaticRef::new(0xE002ED90 as *const cortexm::mpu::MpuRegisters) };
17+
18+
pub unsafe fn new() -> MPU {
19+
MPU::new(MPU_BASE_ADDRESS)
20+
}
1521
}
1622

1723
pub use cortexm::initialize_ram_jump_to_main;

arch/cortex-v8m/src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55
//! Generic support for all Cortex-M platforms.
66
7-
#![crate_name = "cortexv8m"]
8-
#![crate_type = "rlib"]
97
#![no_std]
108

119
// These constants are defined in the linker script.

boards/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ but the approximate definitions:
9797
| [Digilent Arty A-7 100T](arty_e21/README.md) | RISC-V RV32IMAC | SiFive E21 | openocd | tockloader | No |
9898
| [MSP432 Evaluation kit MSP432P401R](msp_exp432p401r/README.md) | ARM Cortex-M4 | MSP432P401R | openocd | custom | No |
9999
| [CY8CPROTO-062-4343W](cy8cproto_62_4343_w/README.md) | ARM Cortex-M0+ | PSoC62 | openocd | custom | No |
100+
| [Raspberry Pi Pico 2](raspberry_pi_pico_2/README.md) | ARM Cortex-M33 | RP2350 | openocd | openocd | No |
100101

101102

102103
### Other
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Licensed under the Apache License, Version 2.0 or the MIT License.
2+
# SPDX-License-Identifier: Apache-2.0 OR MIT
3+
# Copyright Tock Contributors 2024.
4+
5+
include = [
6+
"../../cargo/tock_flags.toml",
7+
"../../cargo/unstable_flags.toml",
8+
]
9+
10+
[build]
11+
target = "thumbv8m.main-none-eabi"
12+
13+
[unstable]
14+
config-include = true
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Licensed under the Apache License, Version 2.0 or the MIT License.
2+
# SPDX-License-Identifier: Apache-2.0 OR MIT
3+
# Copyright OxidOS Automotive 2025.
4+
5+
[package]
6+
name = "raspberry_pi_pico_2"
7+
version.workspace = true
8+
authors.workspace = true
9+
build = "../build.rs"
10+
edition.workspace = true
11+
12+
[dependencies]
13+
cortexm33 = { path = "../../arch/cortex-m33" }
14+
kernel = { path = "../../kernel" }
15+
rp2350 = { path = "../../chips/rp2350" }
16+
components = { path = "../components" }
17+
enum_primitive = { path = "../../libraries/enum_primitive" }
18+
19+
capsules-core = { path = "../../capsules/core" }
20+
capsules-extra = { path = "../../capsules/extra" }
21+
capsules-system = { path = "../../capsules/system" }
22+
23+
[build-dependencies]
24+
tock_build_scripts = { path = "../build_scripts" }
25+
26+
[lints]
27+
workspace = true
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Licensed under the Apache License, Version 2.0 or the MIT License.
2+
# SPDX-License-Identifier: Apache-2.0 OR MIT
3+
# Copyright OxidOS Automotive 2025.
4+
5+
# Makefile for building the tock kernel for the Raspberry Pi Pico 2 board.
6+
7+
include ../Makefile.common
8+
9+
OPENOCD=openocd
10+
OPENOCD_INTERFACE=picoprobe
11+
OPENOCD_OPTIONS=-f openocd-$(OPENOCD_INTERFACE).cfg
12+
13+
BOOTSEL_FOLDER?=/run/media/$(USER)/RP2350
14+
15+
KERNEL=$(TOCK_ROOT_DIRECTORY)target/$(TARGET)/release/$(PLATFORM).elf
16+
KERNEL_WITH_APP=$(TOCK_ROOT_DIRECTORY)/target/$(TARGET)/release/$(PLATFORM)-app.elf
17+
18+
19+
# Default target for installing the kernel.
20+
.PHONY: install
21+
install: flash
22+
23+
.PHONY: flash-openocd
24+
flash-openocd: $(TOCK_ROOT_DIRECTORY)target/$(TARGET)/release/$(PLATFORM).elf
25+
$(OPENOCD) $(OPENOCD_OPTIONS) -c "adapter speed 5000" -c "program $<; verify_image $<; reset; shutdown;"
26+
27+
.PHONY: flash
28+
flash: $(KERNEL)
29+
picotool uf2 convert $< $(TOCK_ROOT_DIRECTORY)target/$(TARGET)/release/$(PLATFORM).uf2
30+
@if [ -d $(BOOTSEL_FOLDER) ]; then cp $(TOCK_ROOT_DIRECTORY)target/$(TARGET)/release/$(PLATFORM).uf2 "$(BOOTSEL_FOLDER)"; else echo; echo Please edit the BOOTSEL_FOLDER variable to point to you Raspberry Pi Pico 2 Flash Drive Folder; echo You can download and flash $(TOCK_ROOT_DIRECTORY)target/$(TARGET)/release/$(PLATFORM).uf2; fi
31+
32+
.PHONY: program
33+
program: $(KERNEL)
34+
ifeq ($(APP),)
35+
$(error Please define the APP variable with the TBF file to flash an application)
36+
endif
37+
arm-none-eabi-objcopy --set-section-flags .apps=LOAD,ALLOC $(KERNEL) $(KERNEL_WITH_APP)
38+
arm-none-eabi-objcopy --update-section .apps=$(APP) $(KERNEL_WITH_APP)
39+
picotool uf2 convert $(KERNEL_WITH_APP) $(TOCK_ROOT_DIRECTORY)target/$(TARGET)/release/$(PLATFORM)-app.uf2
40+
@if [ -d $(BOOTSEL_FOLDER) ]; then cp $(TOCK_ROOT_DIRECTORY)target/$(TARGET)/release/$(PLATFORM)-app.uf2 "$(BOOTSEL_FOLDER)"; else echo; echo Please edit the BOOTSEL_FOLDER variable to point to you Raspberry Pi Pico 2 Flash Drive Folder; echo You can download and flash $(TOCK_ROOT_DIRECTORY)target/$(TARGET)/release/$(PLATFORM)-app.uf2; fi
Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
Raspberry Pi Pico 2 - RP2350
2+
============================
3+
4+
<img src="https://www.raspberrypi.com/documentation/microcontrollers/images/pico-2.png?hash=c4b2ccf2504c98fdd111405dd95346b5" width="80%">
5+
6+
The [Raspberry Pi Pico 2](https://www.raspberrypi.com/products/raspberry-pi-pico-2/) is a
7+
board developed by the Raspberry Pi Foundation and is based on the RP2350 chip.
8+
9+
## Getting Started
10+
11+
First, follow the [Tock Getting Started guide](../../doc/Getting_Started.md)
12+
13+
## Installing picotool
14+
15+
The RP2350 uses UF2 files for flashing. Tock compiles to an ELF file.
16+
The `picotool` utility is needed to transform the Tock ELF file into an UF2 file.
17+
18+
To install `picotool`, check the instructions from their GitHub [page](https://github.com/raspberrypi/picotool).
19+
20+
21+
## Flashing the kernel
22+
23+
The Raspberry Pi Pico 2 RP2350 Connect can be programmed using its bootloader, which requires an UF2 file.
24+
25+
### Enter BOOTSEL mode
26+
27+
To flash the Pico RP2350, it needs to be put into BOOTSEL mode. This will mount
28+
a flash drive that allows one to copy a UF2 file. To enter BOOTSEL mode, press the BOOTSEL button and hold it while you connect the other end of the micro USB cable to your computer.
29+
30+
Then `cd` into `boards/raspberry_pi_pico_2` directory and run:
31+
32+
```bash
33+
$ make flash
34+
35+
(or)
36+
37+
$ make flash-debug
38+
```
39+
40+
> Note: The Makefile provides the BOOTSEL_FOLDER variable that points towards the mount point of
41+
> the Pico 2 RP2350 flash drive. By default, this is located in `/media/$(USER)/RP2350`. This might
42+
> be different on several systems, make sure to adjust it.
43+
44+
## Flashing app
45+
46+
Enter BOOTSEL mode.
47+
48+
Apps are built out-of-tree. Once an app is built, you can add the path to it in the Makefile (APP variable), then run:
49+
```bash
50+
$ APP="<path to app's tbf file>" make flash-app
51+
```
52+
53+
## Debugging
54+
55+
The Raspberry Pi Pico can also be programmed via an SWD connection, which requires the Pico to be connected to a regular Raspberry Pi device that exposes the necessary pins OR using another Raspberry Pi Pico set up in “Picoprobe” mode. The kernel is transferred to the Raspberry Pi Pico using a [custom version of OpenOCD](https://github.com/raspberrypi/openocd).
56+
57+
### Flashing Setup
58+
59+
#### From a regular Raspberry Pi (option 1)
60+
61+
To install OpenOCD on the Raspberry Pi run the following commands on the Pi:
62+
```bash
63+
$ sudo apt update
64+
$ sudo apt install automake autoconf build-essential texinfo libtool libftdi-dev libusb-1.0-0-dev git
65+
$ git clone https://github.com/raspberrypi/openocd.git --recursive --branch sdk-2.0.0 --depth=1
66+
$ cd openocd
67+
$ ./bootstrap
68+
$ ./configure --enable-ftdi --enable-sysfsgpio --enable-bcm2835gpio
69+
$ make -j4
70+
$ sudo make install
71+
```
72+
73+
Enable SSH on the Raspberry Pi by following the [instructions on the Raspberry Pi website](https://www.raspberrypi.org/documentation/remote-access/ssh/).
74+
75+
Next, connect the SWD pins of the Pico 2 (the tree lower wires) to GND, GPIO 24, and GPIO 25 of the Raspberry Pi. You can follow the schematic in the [official documentation](https://datasheets.raspberrypi.org/pico/getting-started-with-pico.pdf#%5B%7B%22num%22%3A22%2C%22gen%22%3A0%7D%2C%7B%22name%22%3A%22XYZ%22%7D%2C115%2C431.757%2Cnull%5D) and connect the blue, black, and purple wires.
76+
77+
Also connect the other three wires as shown in the schematic, which will connect the Pico UART to the Raspberry Pi. This will enable the serial communication between the two devices.
78+
79+
#### From a Linux Host using a Picoprobe (option 2)
80+
81+
To install OpenOCD on Debian/Ubuntu run the following commands:
82+
```bash
83+
$ sudo apt update
84+
$ sudo apt install automake autoconf build-essential texinfo libtool libftdi-dev libusb-1.0-0-dev git
85+
$ git clone https://github.com/raspberrypi/openocd.git --recursive --branch sdk-2.0.0 --depth=1
86+
$ cd openocd
87+
$ ./bootstrap
88+
$ ./configure --enable-picoprobe
89+
$ make -j4
90+
$ sudo make install
91+
```
92+
93+
Download the Picoprobe UF2 file onto the USB mass storage device presented by the Pico that is going to act as Picoprobe device after plugging it into some USB port: https://datasheets.raspberrypi.com/soft/picoprobe.uf2 (the device should automatically restart after the file has been written).
94+
95+
Next, connect the SWD pins of the Pico 2 target (the tree lower wires, left-to-right) to GP2, GND, and GP3 of the Pico that will act as Picoprobe. You can follow the schematic in the [official documentation](https://datasheets.raspberrypi.com/pico/getting-started-with-pico.pdf#%5B%7B%22num%22%3A64%2C%22gen%22%3A0%7D%2C%7B%22name%22%3A%22XYZ%22%7D%2C115%2C696.992%2Cnull%5D) and connect the blue, black, and purple wires.
96+
97+
Also connect the other four wires as shown in the schematic, which will connect the Pico UART and power to the Picoprobe. This will enable the serial communication between the two devices.
98+
99+
### Flashing the tock kernel
100+
101+
#### Building and Deploying from the same System
102+
`cd` into `boards/raspberry_pi_pico` directory and run:
103+
104+
```bash
105+
$ make flash OPENOCD_INTERFACE=[swd|picoprobe]
106+
```
107+
108+
The *OPENOCD_INTERFACE* parameter selects which mode to flash the target Pico device in: `swd` flashes directly via SWD over GPIO (default, needs to be run a regular Raspberry Pi), `picoprobe` flashes indirectly via another Raspberry Pi Pico device.
109+
110+
You can also open a serial console on to view debug messages:
111+
```bash
112+
$ sudo apt install picocom
113+
$ picocom /dev/ttyACM0 -b 115200 -l
114+
```
115+
116+
#### Building on a Desktop/Laptop then Flashing via regular Raspberry Pi
117+
118+
`cd` into `boards/raspberry_pi_pico_2` directory and run:
119+
120+
```bash
121+
$ make
122+
123+
(or)
124+
125+
$ make debug
126+
```
127+
128+
Connect via ssh to the Raspberry Pi and forward port 3333. Then start OpenOCD on the Pi.
129+
```bash
130+
$ ssh pi@<pi_IP> -L 3333:localhost:3333
131+
132+
(wait to connect)
133+
134+
$ openocd -f interface/raspberrypi-swd.cfg -f target/rp2350.cfg
135+
```
136+
You can also open a serial console on the Raspberry Pi for debug messages.
137+
```bash
138+
$ sudo apt install minicom
139+
$ minicom -b 115200 -o -D /dev/serial0
140+
```
141+
142+
On the local computer use gdb-multiarch on Linux or arm-none-eabi-gdb on MacOS to deploy tock.
143+
```bash
144+
$ arm-none-eabi-gdb tock/target/thumbv8m.main-none-eabi/release/raspberry_pi_pico_2.elf
145+
(gdb) target remote :3333
146+
(gdb) load
147+
(gdb) continue
148+
```
149+
## Flashing app
150+
151+
Apps are built out-of-tree. Once an app is built, you can add the path to it in the Makefile (APP variable), then run:
152+
```bash
153+
$ make program
154+
```
155+
156+
This will generate a new ELF file that can be deployed on the Raspberry Pi Pico 2 via gdb and OpenOCD as described in the [section above](#flash-the-tock-kernel).
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/* Licensed under the Apache License, Version 2.0 or the MIT License. */
2+
/* SPDX-License-Identifier: Apache-2.0 OR MIT */
3+
/* Copyright OxidOS Automotive 2025. */
4+
5+
MEMORY
6+
{
7+
/* uncomment this to boot from RAM */
8+
/* reset (rx) : ORIGIN = 0x20000000, LENGTH = 16K
9+
rom (rx) : ORIGIN = 0x20000100, LENGTH = 256K
10+
prog (rx) : ORIGIN = 0x20040000, LENGTH = 1K
11+
ram (rwx) : ORIGIN = 0x20004000, LENGTH = 240K */
12+
13+
/* boot from Flash */
14+
bootloader (rx) : ORIGIN = 0x10000000, LENGTH = 1024
15+
rom (rx) : ORIGIN = 0x10000400, LENGTH = 255K
16+
prog (rx) : ORIGIN = 0x10040000, LENGTH = 256K
17+
ram (rwx) : ORIGIN = 0x20000000, LENGTH = 264K
18+
}
19+
20+
PAGE_SIZE = 4K;
21+
22+
ENTRY(jump_to_bootloader)
23+
24+
SECTIONS {
25+
.bootloader : ALIGN(4)
26+
{
27+
KEEP (*(.metadata_block));
28+
KEEP (*(.flash_bootloader));
29+
. = ALIGN (256);
30+
} > bootloader
31+
32+
/*
33+
* This padding has been added because arm-none-eabi-objcopy
34+
* wrongly aligns the .stack section.
35+
*/
36+
.padding (NOLOAD) : {
37+
BYTE(0xFF)
38+
} > ram
39+
}
40+
41+
INCLUDE tock_kernel_layout.ld

0 commit comments

Comments
 (0)