Skip to content

Commit 655eb70

Browse files
committed
Use probe-run-rp and defmt.
1 parent 99fe438 commit 655eb70

5 files changed

Lines changed: 79 additions & 5 deletions

File tree

.cargo/config.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
[target.thumbv6m-none-eabi]
2-
runner = "elf2uf2-rs -d"
2+
# runner = "elf2uf2-rs -d"
3+
runner = "probe-run-rp --chip RP2040"
34

45
rustflags = [
56
# This is needed if your flash or ram addresses are not aligned to 0x10000 in memory.x
@@ -8,6 +9,9 @@ rustflags = [
89

910
# LLD (shipped with the Rust toolchain) is used as the default linker
1011
"-C", "link-arg=-Tlink.x",
12+
13+
# Support defmt formatted logging
14+
"-C", "link-arg=-Tdefmt.x",
1115
]
1216

1317
[build]

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
## Unreleased Changes ([Source](https://github.com/neotron-compute/neotron-pico-bios/tree/master) | [Changes](https://github.com/neotron-compute/neotron-pico-bios/compare/v0.1.0...master))
44

5-
* None
5+
* Add RTT debugging
6+
* Describe how to flash/debug with a second Raspberry Pi Pico
67

78
## v0.1.0 ([Source](https://github.com/neotron-compute/neotron-pico-bios/tree/v0.1.0) | [Release](https://github.com/neotron-compute/neotron-pico-bios/release/tag/v0.1.0))
89

Cargo.toml

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,30 @@ neotron-common-bios = { git = "https://github.com/Neotron-Compute/Neotron-Common
1919
embedded-time = "0.12"
2020
# For the RP2040 bootloader
2121
rp2040-boot2 = "0.1"
22-
# For panic handling (todo remove this)
23-
panic-halt = "0.2"
2422
# For hardware abstraction traits
2523
embedded-hal ="0.2"
24+
# Gives us formatted PC-side logging
25+
defmt = "0.2"
26+
# Sends defmt logs to the SWD debugger
27+
defmt-rtt = "0.2"
28+
# Send panics to the debugger
29+
panic-probe = "0.2"
30+
31+
[features]
32+
default = [
33+
"defmt-default",
34+
]
35+
defmt-default = []
36+
# Enables trace logs
37+
defmt-trace = []
38+
# Enables debug logs
39+
defmt-debug = []
40+
# Enables info logs
41+
defmt-info = []
42+
# Enables warn logs
43+
defmt-warn = []
44+
# Enables error logs
45+
defmt-error = []
2646

2747
[[bin]]
2848
name = "neotron-pico-bios"

README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,46 @@ Currently the BIOS only uses a single core, and starts the OS on the same core.
3535
Later versions may move some functionality onto the second core (e.g. screen
3636
updates) for performance reasons.
3737

38+
## Programming
39+
40+
The Neotron BIOS uses the [defmt](https://crates.io/crates/defmt) crate to provide structured logging over the SWD interface. The easiest way to flash and debug your Neotron Pico BIOS is with a second Raspberry Pi Pico.
41+
42+
1. Connect your *Debugger* Pico to the *Neotron* Pico:
43+
* connect Pin 3 on the *Debugger* Pico to GND on the *Neotron* Pico
44+
* connect Pin 4 on the *Debugger* Pico to SWCLK on the *Neotron* Pico
45+
* connect Pin 5 on the *Debugger* Pico to SWDIO on the *Neotron* Pico
46+
* connect USB on the *Debugger* Pico to your PC
47+
48+
2. Flash your *Debugger* Pico with https://github.com/majbthrd/DapperMime firmware (e.g. by copying the UF2 file to the USB Mass Storage device)
49+
50+
3. On your PC, install *probe-rs-rp* from the RP2040-specific [probe-run](https://github.com/knurling-rs/probe-run) fork at https://github.com/rp-rs/probe-run.
51+
52+
```console
53+
user@host ~ $ cargo install probe-rs-rp
54+
```
55+
56+
4. Power on your Neotron Pico.
57+
58+
5. Build and load the Neotron BIOS, and view the debug output stream, with `cargo run`:
59+
60+
```console
61+
user@host ~/neotron-pico-bios $ cargo run --release
62+
Compiling neotron-pico-bios v0.1.0 (/home/jonathan/Documents/neotron/neotron-pico-bios)
63+
Finished release [optimized + debuginfo] target(s) in 0.76s
64+
Running `probe-run-rp --chip RP2040 target/thumbv6m-none-eabi/release/neotron-pico-bios`
65+
(HOST) INFO flashing program (7.30 KiB)
66+
(HOST) INFO success!
67+
────────────────────────────────────────────────────────────────────────────────
68+
INFO Neotron BIOS starting...
69+
└─ neotron_pico_bios::__cortex_m_rt_main @ src/main.rs:79
70+
INFO Clocks OK
71+
└─ neotron_pico_bios::__cortex_m_rt_main @ src/main.rs:102
72+
INFO Pins OK
73+
└─ neotron_pico_bios::__cortex_m_rt_main @ src/main.rs:121
74+
DEBUG Loop...
75+
└─ neotron_pico_bios::__cortex_m_rt_main @ src/main.rs:128
76+
```
77+
3878
## Changelog
3979

4080
See [CHANGELOG.md](./CHANGELOG.md)

src/main.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,12 @@
3838
// -----------------------------------------------------------------------------
3939

4040
use cortex_m_rt::entry;
41+
use defmt::*;
42+
use defmt_rtt as _;
4143
use embedded_hal::digital::v2::OutputPin;
4244
use embedded_time::rate::*;
4345
use hal::clocks::Clock;
44-
use panic_halt as _;
46+
use panic_probe as _;
4547
use pico;
4648
use pico::hal;
4749
use pico::hal::pac;
@@ -74,6 +76,8 @@ pub static BOOT2: [u8; 256] = rp2040_boot2::BOOT_LOADER;
7476
/// `.bss` and `.data` sections have been initialised.
7577
#[entry]
7678
fn main() -> ! {
79+
info!("Neotron BIOS starting...");
80+
7781
// Grab the singleton containing all the RP2040 peripherals
7882
let mut pac = pac::Peripherals::take().unwrap();
7983
// Grab the singleton containing all the generic Cortex-M peripherals
@@ -95,6 +99,8 @@ fn main() -> ! {
9599
.ok()
96100
.unwrap();
97101

102+
info!("Clocks OK");
103+
98104
// Create an object we can use to busy-wait for specified numbers of
99105
// milliseconds. For this to work, it needs to know our clock speed.
100106
let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().integer());
@@ -112,11 +118,14 @@ fn main() -> ! {
112118
&mut pac.RESETS,
113119
);
114120

121+
info!("Pins OK");
122+
115123
// Grab the LED pin
116124
let mut led_pin = pins.led.into_push_pull_output();
117125

118126
// Do some blinky so we can see it work.
119127
loop {
128+
debug!("Loop...");
120129
led_pin.set_high().unwrap();
121130
delay.delay_ms(500);
122131
led_pin.set_low().unwrap();

0 commit comments

Comments
 (0)