Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates #1

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 3 additions & 1 deletion .cargo/config
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# vim:ft=toml:
[target.thumbv7em-none-eabihf]
runner = 'arm-none-eabi-gdb'
#runner = 'arm-none-eabi-gdb'
runner = "probe-run --chip nRF52840_xxAA"

rustflags = [
"-C", "link-arg=-Tlink.x",
]
Expand Down
14 changes: 14 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"editor.formatOnSave": true,
"rust-analyzer.cargo.allFeatures": false,
"rust-analyzer.checkOnSave.allFeatures": false,
"rust-analyzer.cargo.target": "thumbv7em-none-eabihf",
"rust-analyzer.checkOnSave.allTargets": false,
"rust-analyzer.cargo.loadOutDirsFromCheck": true,
"rust-analyzer.procMacro.enable": true,
"files.watcherExclude": {
"**/.git/objects/**": true,
"**/.git/subtree-cache/**": true,
"**/target/**": true,
}
}
12 changes: 9 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,22 @@ version = "0.0.1"
edition = "2018"

[dependencies]
nrf52840-hal = { path = "../nrf52-hal/nrf52840-hal" }
nrf52840-hal = "0.12.0"

[dev-dependencies]
cortex-m-rt = "0.6"
cortex-m-rt = "0.6.13"
panic-halt = "0.2"
rtt-target = { version = "0.3.0", features = ["cortex-m"] }
panic-probe = "0.1.0"

# for cargo flash
[package.metadata]
chip = "nRF52840_xxAA"

[features]
rt = ["nrf52840-hal/rt"]
default = ["rt"]
#usb = ["nrf52840-hal/usb"]
default = ["rt"]

[profile.dev]
incremental = false
Expand Down
55 changes: 53 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,62 @@

https://github.com/makerdiary/nrf52840-mdk

## OpenOCD
## flashing with cargo flash

This is the recommended way to go for flashing

* Install the dependencies for[cargo-flash](https://crates.io/crates/cargo-flash)
* Install probe-run `cargo install cargo-flash`

Then simply `cargo flash --release --example blinky`

## debugging with probe-run

This is the recommended way to go for debugging

* Install the dependencies for[probe-run](https://crates.io/crates/probe-run) (same as for cargo-flash if you already have that)
* Install probe-run `cargo install probe-run`
* On linux you need udev rules saved to somewhere like /etc/udev/rules.d/50-cmsis-dap.rules

```
# 0d28:0204 DAPLink
SUBSYSTEM=="usb", ATTR{idVendor}=="0d28", ATTR{idProduct}=="0204", MODE:="666"
```

Then or reload your udev rules with something like `sudo udevadm control -R`

Then simply `cargo run --example debug`

```bash
Finished dev [unoptimized + debuginfo] target(s) in 0.18s
Running `probe-run --chip nRF52840_xxAA target/thumbv7em-none-eabihf/debug/examples/debug`
(HOST) INFO flashing program
(HOST) INFO success!
────────────────────────────────────────────────────────────────────────────────
this is what debugging looks like
stack backtrace:
0: 0x00001fd2 - HardFaultTrampoline
<exception entry>
1: 0x0000149c - __udf
2: 0x00001b2c - cortex_m::asm::udf
3: 0x00001bc4 - rust_begin_unwind
4: 0x0000154a - core::panicking::panic_fmt
5: 0x000014e2 - core::panicking::panic
6: 0x000002d8 - debug::__cortex_m_rt_main
7: 0x0000019a - main
8: 0x00001fbc - ResetTrampoline
9: 0x00000156 - Reset
```

## Debugging with OpenOCD

I was unable to get this working with the openocd that ships with
ubuntu 18.04, but was able to hook up SWD to my JLink. This thread
is someone else having similar issues:

https://devzone.nordicsemi.com/b/blog/posts/debugging-on-nrf52840-with-gdb-from-cli-on-linux

## JLink
## Debugging with JLink

I hooked up my JLink using one of these breakouts:
https://www.adafruit.com/product/2743
Expand All @@ -24,6 +71,10 @@ https://www.adafruit.com/product/2743
| TDO | SWO |
| GND | GND x 3 |

* Uncomment the `arm-none-eabi-gdb` runner in .cargo/config
* Start your gdbserver
* use `cargo run`

## License

Licensed under either of
Expand Down
24 changes: 12 additions & 12 deletions examples/blinky.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use cortex_m_rt::entry;
use nrf52840_mdk::hal::gpio::{p0, p1, Level};
use nrf52840_mdk::hal::prelude::*;
use nrf52840_mdk::hal::timer::Timer;
use nrf52840_mdk::nrf52840_pac::Peripherals;
use nrf52840_mdk::pac::Peripherals;
use nrf52840_mdk::Pins;

#[entry]
Expand All @@ -19,24 +19,24 @@ fn main() -> ! {
let mut blue_led = pins.blue_led.into_push_pull_output(Level::Low);
let mut green_led = pins.green_led.into_push_pull_output(Level::Low);

green_led.set_high();
red_led.set_high();
blue_led.set_high();
let _ = green_led.set_high();
let _ = red_led.set_high();
let _ = blue_led.set_high();

let mut timer = Timer::new(p.TIMER0);

// Alternately flash the red, green and blue leds
loop {
green_led.set_high();
red_led.set_low();
blue_led.set_high();
let _ = green_led.set_high();
let _ = red_led.set_low();
let _ = blue_led.set_high();
timer.delay(250_000); // 250ms
red_led.set_high();
blue_led.set_low();
let _ = red_led.set_high();
let _ = blue_led.set_low();
timer.delay(1_000_000); // 1s
green_led.set_low();
blue_led.set_high();
red_led.set_high();
let _ = green_led.set_low();
let _ = blue_led.set_high();
let _ = red_led.set_high();
timer.delay(250_000); // 250ms
}
}
21 changes: 21 additions & 0 deletions examples/debug.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#![no_main]
#![no_std]

use cortex_m_rt::entry;
use panic_probe as _;

use nrf52840_mdk::hal::prelude::*;
use rtt_target::{rprintln, rtt_init_print};

#[entry]
fn main() -> ! {
// allocate the rtt machinery for printing
// rtt_init_print!(); //non blocking but 1024 buffer and lose data if full
rtt_init_print!(BlockIfFull, 128); //NOTE! will block if not hooked up to debugger

rprintln!("this is what debugging looks like");

loop {
panic!("This is what a panic looks like")
}
}
8 changes: 4 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#![no_std]

pub extern crate nrf52840_hal as hal;
use hal::gpio::{p0, p1, Floating, Input};
pub use hal::nrf52840_pac;
use hal::gpio::{p0, p1, Disconnected};
pub use hal::pac;

macro_rules! define_pins {
($(#[$topattr:meta])* struct $Type:ident,
Expand All @@ -15,8 +15,8 @@ macro_rules! define_pins {

$(#[$topattr])*
pub struct $Type {
$($(#[$attr])* pub $name: p0:: $pin_type <Input<Floating>>,)+
$($(#[$attr1])* pub $name1: p1:: $pin_type1 <Input<Floating>>,)+
$($(#[$attr])* pub $name: p0:: $pin_type <Disconnected>,)+
$($(#[$attr1])* pub $name1: p1:: $pin_type1 <Disconnected>,)+
}

impl $Type {
Expand Down