-
Notifications
You must be signed in to change notification settings - Fork 202
Debugging
ATSAM parts have a SWD debug interface, which can be controlled through a number of programs on the host PC.
This is the preferred pure rust ecosystem method for debugging. It requires no external gdb server, nor C or Python tooling like openocd.
probe-run attemps to bring the hosted cargo run print line debugging experience to embedded. It also has advanced logging features to vastly reduce format size under the defmt project which is not covered here.
probe-run
needs to be set as your runner
in the .cargo/config
along with the id of your chip. Also debug symbols need to be enabled for any profile you're building for. In your application you'll want to use a probe-run
compatible panic crate like panic-probe
and an rtt debug logging crate like rtt-target
. Also don't forget to init your rtt machinery.
probe-run
will then be called after a successful build to flash the code directly to the target via debugger and will then wait to receive any rtt prints from your target. Finally if a panic occurs or you ever call cortex_m::asm::bkpt()
probe-run
will detect, print a stack trace, and exit. You can exit probe-run
on the host side with ctrl-c.
$ cargo install probe-run
Then simply use your ide's run or play button, or run:
$ cargo run --release --example adc --features=unproven
Finished release [optimized + debuginfo] target(s) in 1.10s
Running `probe-run --chip ATSAMD11C14A target/thumbv6m-none-eabi/release/examples/adc`
(HOST) INFO flashing program (35.17 KiB)
(HOST) INFO success!
────────────────────────────────────────────────────────────────────────────────
4129
4074
4177
^Cstack backtrace:
0: <atsamd_hal::common::delay::Delay as embedded_hal::blocking::delay::DelayUs<u32>>::delay_us
at /home/atsamd/hal/src/common/delay.rs:72
1: <atsamd_hal::common::delay::Delay as embedded_hal::blocking::delay::DelayMs<u32>>::delay_ms
at /home/atsamd/hal/src/common/delay.rs:35
2: <atsamd_hal::common::delay::Delay as embedded_hal::blocking::delay::DelayMs<u16>>::delay_ms
at /home/atsamd/hal/src/common/delay.rs:41
3: neopixel_adc_battery::__cortex_m_rt_main
at examples/neopixel_adc_battery.rs:50
4: main
at examples/neopixel_adc_battery.rs:23
5: ResetTrampoline
at /home/.cargo/registry/src/github.com-1ecc6299db9ec823/cortex-m-rt-0.6.13/src/lib.rs:547
6: Reset
at /home/.cargo/registry/src/github.com-1ecc6299db9ec823/cortex-m-rt-0.6.13/src/lib.rs:550
If you have a board with a SWD debug header, such as the [Metro M0][metro_m0], or if you attached the header yourself, you can use your JLink together with gdb. @wez prefers using the JLinkGDBServer, but you can also use OpenOCD.
In one window, run JLinkGDBServer -if SWD -device ATSAMD21G18
, then in another, run these commands from the root of this repo so that you pick up its .gdbinit
file:
$ cargo build --manifest-path metro_m0/Cargo.toml --example blinky_basic
$ arm-none-eabi-gdb metro_m0/target/thumbv6m-none-eabi/debug/examples/blinky_basic
If you prefer or otherwise need to use OpenOCD, then you'd run it in place of the JLinkGDBServer and then modify the .gdbinit
file to comment out the JLink section and uncomment the OpenOCD section.