diff --git a/beginner/apps/Cargo.toml b/beginner/apps/Cargo.toml index 589ef2c..633f9b2 100644 --- a/beginner/apps/Cargo.toml +++ b/beginner/apps/Cargo.toml @@ -6,13 +6,13 @@ name = "apps" version = "0.0.0" [dependencies] -cortex-m = "0.6.4" -cortex-m-rt = "0.6.13" +cortex-m = "0.7.3" +cortex-m-rt = "0.7.1" dk = { path = "../../boards/dk", features = ["beginner"] } -heapless = "0.5.5" -panic-probe = { version = "0.2.0", features = ["print-defmt"] } -defmt = "0.2.1" -defmt-rtt = "0.2.0" +heapless = "0.7.9" +panic-probe = { version = "0.3.0", features = ["print-defmt"] } +defmt = "0.3.0" +defmt-rtt = "0.3.1" # optimize code in both profiles [profile.dev] diff --git a/beginner/apps/src/bin/panic.rs b/beginner/apps/src/bin/panic.rs index b3c139d..272f2b6 100644 --- a/beginner/apps/src/bin/panic.rs +++ b/beginner/apps/src/bin/panic.rs @@ -3,8 +3,7 @@ use cortex_m::asm; use cortex_m_rt::entry; -// this imports `beginner/apps/lib.rs` to retrieve our global logger + panicking-behavior -use apps as _; +// use apps as _; // this defines the panicking behaviour #[entry] @@ -36,3 +35,8 @@ fn bar() { fn index() -> usize { 3 } + +#[panic_handler] +fn panic(info: &core::panic::PanicInfo) -> ! { + defmt::panic!("lalal {}", info); +} \ No newline at end of file diff --git a/boards/dk/Cargo.toml b/boards/dk/Cargo.toml index b946e92..989c418 100644 --- a/boards/dk/Cargo.toml +++ b/boards/dk/Cargo.toml @@ -6,13 +6,13 @@ name = "dk" version = "0.0.0" [dependencies] -cortex-m = "0.6.4" -cortex-m-rt = "0.6.13" -embedded-hal = "0.2.3" -hal = { package = "nrf52840-hal", version = "0.12.1" } -defmt = "0.2.1" -defmt-rtt = "0.2.0" -panic-probe = { version = "0.2.0", features = ["print-defmt" ] } +cortex-m = "0.7.3" +cortex-m-rt = "0.7.1" +embedded-hal = "0.2.6" +hal = { package = "nrf52840-hal", version = "0.14.0" } +panic-probe = { version = "0.3.0", features = ["print-defmt"] } +defmt = "0.3.0" +defmt-rtt = "0.3.1" [features] beginner = [] diff --git a/embedded-workshop-book/src/installation.md b/embedded-workshop-book/src/installation.md index 0a96e37..9546fdc 100644 --- a/embedded-workshop-book/src/installation.md +++ b/embedded-workshop-book/src/installation.md @@ -147,11 +147,11 @@ Install the [`flip-link`](https://crates.io/crates/flip-link) and [`probe-run`]( $ cargo install probe-run (..) -Installed package `probe-run v0.1.8` (..) +Installed package `probe-run v0.3.1` (..) $ cargo install flip-link (..) -Installed package `flip-link v0.1.2` (..) +Installed package `flip-link v0.1.5` (..) $ cargo install nrfdfu (..) diff --git a/embedded-workshop-book/src/panicking.md b/embedded-workshop-book/src/panicking.md index 0093782..451ad16 100644 --- a/embedded-workshop-book/src/panicking.md +++ b/embedded-workshop-book/src/panicking.md @@ -5,31 +5,45 @@ This program attempts to index an array beyond its length and this results in a panic. ``` console -ERROR:panic_log -- panicked at 'index out of bounds: the len is 3 but the index is 3', src/bin/panic.rs:29:13 +──────────────────────────────────────────────────────────────────────────────── +ERROR panicked at 'index out of bounds: the len is 3 but the index is 3', src/bin/panic.rs:32:13 +──────────────────────────────────────────────────────────────────────────────── stack backtrace: - 0: 0x000022f0 - __bkpt - 1: 0x00002010 - rust_begin_unwind - 2: 0x00000338 - core::panicking::panic_fmt - 3: 0x00000216 - core::panicking::panic_bounds_check - 4: 0x0000016a - panic::bar - 5: 0x00000158 - panic::foo - 6: 0x00000192 - panic::__cortex_m_rt_main - 7: 0x00000178 - main - 8: 0x0000199e - Reset + 0: HardFaultTrampoline + + 1: lib::inline::__udf + at ./asm/inline.rs:172:5 + 2: __udf + at ./asm/lib.rs:49:17 + 3: cortex_m::asm::udf + at /Users/name/.cargo/registry/src/github.com-1ecc6299db9ec823/cortex-m-0.7.3/src/asm.rs:43:5 + 4: rust_begin_unwind + at /Users/name/.cargo/registry/src/github.com-1ecc6299db9ec823/panic-probe-0.3.0/src/lib.rs:72:9 + 5: core::panicking::panic_fmt + at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c/library/core/src/panicking.rs:100:14 + 6: core::panicking::panic_bounds_check + at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c/library/core/src/panicking.rs:76:5 + 7: panic::bar + at src/bin/panic.rs:32:13 + 8: panic::foo + at src/bin/panic.rs:25:5 + 9: panic::__cortex_m_rt_main + at src/bin/panic.rs:15:5 + 10: main + at src/bin/panic.rs:11:1 + 11: Reset +(HOST) ERROR the program panicked ``` In `no_std` programs the behavior of panic is defined using the `#[panic_handler]` attribute. In the example, the *panic handler* is defined in the `panic_log` crate but we can also implement it manually: -✅ Comment out the `panic_log` import and add the following function to the example: +✅ Comment out the `panic_probe` import and add the following function to the example: ``` rust #[panic_handler] fn panic(info: &core::panic::PanicInfo) -> ! { - log::error!("{}", info); - loop { - asm::bkpt() - } + defmt::panic!("{}", info); } ``` -Now run the program again. Try changing the format string of the `error!` macro. +Now run the program again. Try changing the format string of the `panic!` macro. diff --git a/embedded-workshop-book/src/radio-setup.md b/embedded-workshop-book/src/radio-setup.md index 9ddf2b4..dabddd0 100644 --- a/embedded-workshop-book/src/radio-setup.md +++ b/embedded-workshop-book/src/radio-setup.md @@ -7,7 +7,7 @@ ``` console $ cargo xtask serial-term deviceid=588c06af0877c8f2 channel=20 TxPower=+8dBm app=loopback.hex -received 5 bytes (LQI=49) +received 5 bytes (CRC=Ok(0xdad9), LQI=53) ``` The program broadcasts a radio packet that contains the 5-byte string `Hello` over channel 20 (which has a center frequency of 2450 MHz). The `loopback` program running on the Dongle is listening to all packets sent over channel 20; every time it receives a new packet it reports its length and the Link Quality Indicator (LQI) metric of the transmission over the USB/serial interface. As the name implies the LQI metric indicates how good the connection between the sender and the receiver is. diff --git a/embedded-workshop-book/src/running-from-vsc.md b/embedded-workshop-book/src/running-from-vsc.md index b3a44ef..be59374 100644 --- a/embedded-workshop-book/src/running-from-vsc.md +++ b/embedded-workshop-book/src/running-from-vsc.md @@ -13,21 +13,13 @@ Expected output: ``` console $ cargo run --bin hello - Running `probe-run --chip nRF52840_xxAA target/thumbv7em-none-eabihf/debug/hello` - (HOST) INFO flashing program (30.09 KiB) - (HOST) INFO success! + Running `probe-run --chip nRF52840_xxAA target/thumbv7em-none-eabihf/debug/hello` +(HOST) INFO flashing program (4 pages / 16.00 KiB) +(HOST) INFO success! ──────────────────────────────────────────────────────────────────────────────── INFO:hello -- Hello, world! -stack backtrace: - 0: __bkpt - 1: hello::__cortex_m_rt_main - at src/bin/hello.rs:15 - 2: main - at src/bin/hello.rs:8 - 3: ResetTrampoline - at $REGISTRY/cortex-m-rt-0.6.13/src/lib.rs:547 - 4: Reset - at $REGISTRY/cortex-m-rt-0.6.13/src/lib.rs:550 +──────────────────────────────────────────────────────────────────────────────── +(HOST) INFO device halted without error ``` `cargo run` will compile the application and then invoke the `probe-run` tool with its argument set to the path of the output ELF file. @@ -36,7 +28,7 @@ The `probe-run` tool will - flash (load) the program on the microcontroller - reset the microcontroller to make it execute the new program - collect logs from the microcontroller and print them to the console -- print a backtrace of the program and exit when the devices reaches a breakpoint (`asm::bkpt()`) +- print a backtrace of the program if the halt was due to an error. Should you need to configure the `probe-run` invocation to e.g. flash a different microcontroller you can do that in the `.cargo/config.toml` file.