Skip to content

Commit 1d611c8

Browse files
authored
Merge pull request #4 from Neotron-Compute/feature/add-defmt-and-rtt
Feature/add defmt and rtt
2 parents 99fe438 + c1a42ec commit 1d611c8

5 files changed

Lines changed: 86 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: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
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 using defmt
6+
* Report git version over defmt
7+
* Describe how to flash/debug with a second Raspberry Pi Pico
68

79
## 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))
810

Cargo.toml

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,32 @@ 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+
# Fetches the BIOS version from git
31+
git-version = "0.3"
32+
33+
[features]
34+
default = [
35+
"defmt-default",
36+
]
37+
defmt-default = []
38+
# Enables trace logs
39+
defmt-trace = []
40+
# Enables debug logs
41+
defmt-debug = []
42+
# Enables info logs
43+
defmt-info = []
44+
# Enables warn logs
45+
defmt-warn = []
46+
# Enables error logs
47+
defmt-error = []
2648

2749
[[bin]]
2850
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: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,13 @@
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::*;
45+
use git_version::git_version;
4346
use hal::clocks::Clock;
44-
use panic_halt as _;
47+
use panic_probe as _;
4548
use pico;
4649
use pico::hal;
4750
use pico::hal::pac;
@@ -60,6 +63,9 @@ use pico::hal::pac;
6063
#[used]
6164
pub static BOOT2: [u8; 256] = rp2040_boot2::BOOT_LOADER;
6265

66+
/// BIOS version
67+
const GIT_VERSION: &str = git_version!();
68+
6369
// -----------------------------------------------------------------------------
6470
// Types
6571
// -----------------------------------------------------------------------------
@@ -74,6 +80,8 @@ pub static BOOT2: [u8; 256] = rp2040_boot2::BOOT_LOADER;
7480
/// `.bss` and `.data` sections have been initialised.
7581
#[entry]
7682
fn main() -> ! {
83+
info!("Neotron BIOS {} starting...", GIT_VERSION);
84+
7785
// Grab the singleton containing all the RP2040 peripherals
7886
let mut pac = pac::Peripherals::take().unwrap();
7987
// Grab the singleton containing all the generic Cortex-M peripherals
@@ -95,6 +103,8 @@ fn main() -> ! {
95103
.ok()
96104
.unwrap();
97105

106+
info!("Clocks OK");
107+
98108
// Create an object we can use to busy-wait for specified numbers of
99109
// milliseconds. For this to work, it needs to know our clock speed.
100110
let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().integer());
@@ -112,11 +122,14 @@ fn main() -> ! {
112122
&mut pac.RESETS,
113123
);
114124

125+
info!("Pins OK");
126+
115127
// Grab the LED pin
116128
let mut led_pin = pins.led.into_push_pull_output();
117129

118130
// Do some blinky so we can see it work.
119131
loop {
132+
debug!("Loop...");
120133
led_pin.set_high().unwrap();
121134
delay.delay_ms(500);
122135
led_pin.set_low().unwrap();

0 commit comments

Comments
 (0)