Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ members = [
"app/demo-stm32f4-discovery",
"app/demo-stm32g0-nucleo",
"app/demo-stm32h7-nucleo",
"app/demo-pi-pico",
"app/gemini-bu",
"app/gemini-bu-rot",
"app/gimlet",
Expand Down Expand Up @@ -93,6 +94,9 @@ members = [
"drv/lpc55-rng",
"drv/lpc55-swd",

"drv/rp2040-sys-api",
"drv/rp2040-sys",

"drv/user-leds",
"drv/user-leds-api",
"drv/ice40-spi-program",
Expand Down
12 changes: 12 additions & 0 deletions app/demo-pi-pico/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
**/*.rs.bk
.#*
.gdb_history
target/

# editor files
.vscode/*
!.vscode/*.md
!.vscode/*.svd
!.vscode/launch.json
!.vscode/tasks.json
!.vscode/extensions.json
31 changes: 31 additions & 0 deletions app/demo-pi-pico/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
[package]
edition = "2018"
readme = "README.md"
name = "demo-pi-pico"
version = "0.1.0"

[features]
semihosting = ["panic-semihosting", "klog-semihosting"]
klog-semihosting = ["kern/klog-semihosting"]

[dependencies]
cortex-m = { version = "0.7", features = ["inline-asm"] }
cortex-m-rt = "0.6.12"
panic-halt = { version = "0.2.0", optional = true }
panic-semihosting = { version = "0.5.3", optional = true }
cfg-if = "0.1.10"
rp2040-pac = {version = "0.3", features = ["rt"]}
rp2040-boot2 = "0.2"

[dependencies.kern]
path = "../../sys/kern"
default-features = false

[build-dependencies]
build-util = {path = "../../build/util"}

# this lets you use `cargo fix`!
[[bin]]
name = "demo-pi-pico"
test = false
bench = false
52 changes: 52 additions & 0 deletions app/demo-pi-pico/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Rasperry Pi Pico demo application

This will blink an LED, and not a whole lot else, on a Raspberry Pi Pico board
(based on the RP2040).

Currently, our tools don't know how to flash this board. So, to use this, you'll
have to jump through some hoops.

You will need:

- [uf2l](https://github.com/cbiffle/uf2l) - you can install it, or run it from
the build directory, but the instructions below will just refer to it as
`uf2l`.
- [rp2040-rustboot](https://github.com/cbiffle/rp2040-rustboot) - run the
`build-all.sh` to produce ELF binaries. The instructions below will refer to
its location as `$RUSTBOOT`.

To build and prepare the image:

```
cargo xtask dist app/demo-pi-pico/app.toml
uf2l pack -e 4096 \
$RUSTBOOT/elf/rustboot-w25q080 \
target/demo-pi-pico/dist/combined.elf \
hubris-pico.uf2
```

Then, hold BOOTSEL while plugging in your Pi Pico. It should show up as a USB
drive. Copy the `hubris-pico.uf2` file onto it. It should reboot and begin
blinking a light at 1 Hz.

## Debugging

General RP2040 support in OpenOCD hasn't been upstreamed, but amusingly there
_is_ upstream support for the [pico-debug] same-chip debugger. This will run on
core 1 while Hubris runs on core 0.

To use this:

1. Flash Hubris as described above.
2. Ensure that you've got a fairly recent OpenOCD git build.
3. Download the GIMMECACHE version of the debug image.
4. Hold BOOTSEL and reboot your RP2040 board into the bootloader.
5. Copy the GIMMECACHE UF2 image onto the board. It should reboot. It does not
appear to correctly start the Flash image by default, but that's easy to fix:
6. From this directory, run: `openocd -f openocd-pico-debug.cfg -c init -c reset
-c exit`

The clock configuration under pico-debug is slightly different from the reset
configuration; there is code in `src/main.rs` to adjust for this. It is a hack.

[pico-debug]: https://github.com/majbthrd/pico-debug
89 changes: 89 additions & 0 deletions app/demo-pi-pico/app.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
name = "demo-pi-pico"
target = "thumbv6m-none-eabi"
chip = "../../chips/rp2040.toml"
board = "pi-pico"
stacksize = 944

[kernel]
path = "."
name = "demo-pi-pico"
requires = {flash = 12000, ram = 1696}
features = ["panic-halt"]
stacksize = 640

[supervisor]
notification = 1

[outputs.flash]
address = 0x10000100 # just past the bootloader
size = 0x1fff00 # 2MiB - 256 bytes
read = true
execute = true

[outputs.ram]
address = 0x20000000
size = 270336
read = true
write = true
execute = false # let's assume XN until proven otherwise

[tasks.jefe]
path = "../../task/jefe"
name = "task-jefe"
priority = 0
requires = {flash = 4096, ram = 512}
start = true
features = ["log-null"]
stacksize = 352

[tasks.sys]
path = "../../drv/rp2040-sys"
name = "drv-rp2040-sys"
priority = 1
requires = {flash = 1024, ram = 256}
uses = ["resets", "sio"]
start = true
stacksize = 256

[tasks.user_leds]
path = "../../drv/user-leds"
name = "drv-user-leds"
features = ["rp2040"]
priority = 2
requires = {flash = 1024, ram = 256}
start = true
task-slots = ["sys"]
stacksize = 256

[tasks.pong]
path = "../../task/pong"
name = "task-pong"
priority = 3
requires = {flash = 1024, ram = 256}
start = true
task-slots = ["user_leds"]
stacksize = 256

[tasks.ping]
path = "../../task/ping"
name = "task-ping"
priority = 4
requires = {flash = 4096, ram = 512}
stacksize = 256
start = true
task-slots = [{peer = "pong"}]

[tasks.hiffy]
path = "../../task/hiffy"
name = "task-hiffy"
priority = 3
requires = {flash = 8192, ram = 8192 }
start = true

[tasks.idle]
path = "../../task/idle"
name = "task-idle"
priority = 5
requires = {flash = 128, ram = 64}
stacksize = 64
start = true
7 changes: 7 additions & 0 deletions app/demo-pi-pico/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

fn main() {
build_util::expose_target_board();
}
6 changes: 6 additions & 0 deletions app/demo-pi-pico/openocd-pico-debug.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
source [find interface/cmsis-dap.cfg]
source [find target/rp2040-core0.cfg]

transport select swd

adapter_khz 500
57 changes: 57 additions & 0 deletions app/demo-pi-pico/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

#![no_std]
#![no_main]

#[cfg(not(any(
feature = "panic-itm",
feature = "panic-semihosting",
feature = "panic-halt"
)))]
compile_error!("Must have one of panic-{itm,semihosting,halt} enabled");

// Panic behavior controlled by Cargo features:
#[cfg(feature = "panic-halt")]
extern crate panic_halt;
#[cfg(feature = "panic-itm")]
extern crate panic_itm; // breakpoint on `rust_begin_unwind` to catch panics
#[cfg(feature = "panic-semihosting")]
extern crate panic_semihosting; // requires a debugger

// We have to do this if we don't otherwise use it to ensure its vector table
// gets linked in.
use rp2040_pac as _;

#[link_section = ".boot_loader"]
#[used]
pub static BOOT_LOADER: [u8; 256] = rp2040_boot2::BOOT_LOADER_W25Q080;

use cortex_m_rt::entry;

#[entry]
fn main() -> ! {
let p = unsafe { rp2040_pac::Peripherals::steal() };

p.RESETS.reset.modify(|_, w| w.io_bank0().clear_bit());
while !p.RESETS.reset_done.read().io_bank0().bit() {}

p.SIO.gpio_oe_set.write(|w| unsafe { w.bits(1 << 25) });
p.SIO.gpio_out_set.write(|w| unsafe { w.bits(1 << 25) });

p.IO_BANK0.gpio[25].gpio_ctrl.write(|w| w.funcsel().sio());

let cycles_per_ms = if p.CLOCKS.clk_sys_ctrl.read().src().is_clk_ref() {
// This is the reset state, so we'll assume we launched directly from
// flash running on the ROSC.
6_000 // ish
} else {
// This is _not_ the reset state, so we'll assume that the pico-debug
// resident debugger has reconfigured things to run off the 48 MHz USB
// clock.
48_000
};

unsafe { kern::startup::start_kernel(cycles_per_ms) }
}
8 changes: 4 additions & 4 deletions build/xtask/src/dist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -639,10 +639,10 @@ Did you mean to run `cargo xtask dist`?"
// any external configuration files, serialize it, and add it to the
// archive.
//
let mut config = crate::flash::config(&toml.board.as_str())?;
config.flatten()?;

archive.text(img_dir.join("flash.ron"), ron::to_string(&config)?)?;
if let Some(mut config) = crate::flash::config(&toml.board.as_str())? {
config.flatten()?;
archive.text(img_dir.join("flash.ron"), ron::to_string(&config)?)?;
}

archive.finish()?;

Expand Down
Loading