summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrian Cully <bjc@kublai.com>2019-08-11 22:12:51 -0400
committerBrian Cully <bjc@kublai.com>2019-08-13 15:33:14 -0400
commit9cf9bb05f460a830384c211fa3ed94580de755df (patch)
treead05246b6955007975ab0d7c6c633c46a300e472
parent48b18d01e3fa887b884fe6aac26b39e321eab56b (diff)
downloadbleusb-9cf9bb05f460a830384c211fa3ed94580de755df.tar.gz
bleusb-9cf9bb05f460a830384c211fa3ed94580de755df.zip
WIP: sample code and runner for mdk board.
-rw-r--r--ble/.cargo/config6
-rw-r--r--ble/.gdbinit13
-rw-r--r--ble/Cargo.lock31
-rw-r--r--ble/Cargo.toml10
-rw-r--r--ble/openocd.cfg2
-rw-r--r--ble/src/main.rs40
6 files changed, 97 insertions, 5 deletions
diff --git a/ble/.cargo/config b/ble/.cargo/config
new file mode 100644
index 0000000..c4ce5ef
--- /dev/null
+++ b/ble/.cargo/config
@@ -0,0 +1,6 @@
+[build]
+target = "thumbv7em-none-eabihf"
+
+[target.thumbv7em-none-eabihf]
+rustflags = ["-C", "link-arg=-Tlink.x"]
+runner = "gdb-multiarch"
diff --git a/ble/.gdbinit b/ble/.gdbinit
new file mode 100644
index 0000000..a32f910
--- /dev/null
+++ b/ble/.gdbinit
@@ -0,0 +1,13 @@
+# print demangled symbols by default
+set print asm-demangle on
+
+# OpenOCD
+#set remote hardware-breakpoint-limit 6
+#set remote hardware-watchpoint-limit 4
+#target extended-remote :3333
+target remote :3333
+#monitor flash breakpoints 1
+#monitor semihosting enable
+#monitor semihosting IOClient 3
+monitor reset
+load
diff --git a/ble/Cargo.lock b/ble/Cargo.lock
index 1ae5de2..42cc690 100644
--- a/ble/Cargo.lock
+++ b/ble/Cargo.lock
@@ -39,7 +39,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
name = "ble"
version = "0.1.0"
dependencies = [
+ "cortex-m 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "cortex-m-rt 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)",
+ "nb 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"nrf52840-hal 0.8.1",
+ "nrf52840-mdk-bsp 0.1.0",
+ "panic-semihosting 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
"rubble 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
"rubble-nrf52 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
]
@@ -85,6 +90,14 @@ dependencies = [
]
[[package]]
+name = "cortex-m-semihosting"
+version = "0.3.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "cortex-m 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
name = "embedded-hal"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -143,6 +156,13 @@ dependencies = [
]
[[package]]
+name = "nrf52840-mdk-bsp"
+version = "0.1.0"
+dependencies = [
+ "nrf52840-hal 0.8.1",
+]
+
+[[package]]
name = "nrf52840-pac"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -154,6 +174,15 @@ dependencies = [
]
[[package]]
+name = "panic-semihosting"
+version = "0.5.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "cortex-m 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "cortex-m-semihosting 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
name = "proc-macro2"
version = "0.4.30"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -295,11 +324,13 @@ dependencies = [
"checksum cortex-m 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f3c18719fdc57db65668bfc977db9a0fa1a41d718c5d9cd4f652c9d4b0e0956a"
"checksum cortex-m-rt 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)" = "17805910e3ecf029bdbfcc42b7384d9e3d9e5626153fa810002c1ef9839338ac"
"checksum cortex-m-rt-macros 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "d7ae692573e0acccb1579fef1abf5a5bf1d2f3f0149a22b16870ec9309aee25f"
+"checksum cortex-m-semihosting 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "165f3f86f4d1031351a6c9dc8d5a3f8fae2050f9dd6ef925e3d675c232cc0e46"
"checksum embedded-hal 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ee4908a155094da7723c2d60d617b820061e3b4efcc3d9e293d206a5a76c170b"
"checksum fpa 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f074479d683e5a8fd0bf1251d0a5d91b0d9178b867b44962191ed0eaaf8d4009"
"checksum generic-array 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)" = "c68f0274ae0e023facc3c97b2e00f076be70e254bc851d972503b328db79b2ec"
"checksum nb 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b1411551beb3c11dedfb0a90a0fa256b47d28b9ec2cdff34c25a2fa59e45dbdc"
"checksum nrf52840-pac 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e375b19eec5ae6c75387ea2fff3d5a6f989d65a0af350fcfe854f31243bfdfe2"
+"checksum panic-semihosting 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "97cfb37c1d3b5f0cc18bf14485018cccd13bdd24f7b5bfd456c1d8760afef824"
"checksum proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)" = "cf3d2011ab5c909338f7887f4fc896d35932e29146c12c8d01da6b22a80ba759"
"checksum quote 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)" = "6ce23b6b870e8f94f81fb0a363d65d86675884b34a09043c81e5562f11c1f8e1"
"checksum r0 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e2a38df5b15c8d5c7e8654189744d8e396bddc18ad48041a500ce52d6948941f"
diff --git a/ble/Cargo.toml b/ble/Cargo.toml
index be54397..ad7b888 100644
--- a/ble/Cargo.toml
+++ b/ble/Cargo.toml
@@ -4,15 +4,19 @@ version = "0.1.0"
authors = ["Brian Cully <bjc@kublai.com>"]
edition = "2018"
-# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
-
[dependencies]
+nrf52840-mdk-bsp = { path = "../../nrf52-hal/boards/nrf52840-mdk" }
nrf52840-hal = "0.8"
rubble = "0.0"
rubble-nrf52 = "0.0"
+cortex-m = "~0.6"
+cortex-m-rt = "~0.6"
+panic-semihosting = "~0.5"
+nb = "~0.1"
[features]
-default = ["rubble-nrf52/52840"]
+default = ["rt", "rubble-nrf52/52840"]
+rt = ["nrf52840-hal/rt"]
[patch.crates-io]
nrf52840-hal = { path = "../../nrf52-hal/nrf52840-hal" }
diff --git a/ble/openocd.cfg b/ble/openocd.cfg
new file mode 100644
index 0000000..1aa6f38
--- /dev/null
+++ b/ble/openocd.cfg
@@ -0,0 +1,2 @@
+source [find interface/cmsis-dap.cfg]
+source [find target/nrf52.cfg]
diff --git a/ble/src/main.rs b/ble/src/main.rs
index e7a11a9..8b8c513 100644
--- a/ble/src/main.rs
+++ b/ble/src/main.rs
@@ -1,3 +1,39 @@
-fn main() {
- println!("Hello, world!");
+//! BLE interface.
+#![no_std]
+#![no_main]
+
+use core::fmt::Write;
+use cortex_m_rt::entry;
+use nb::block;
+
+#[allow(unused_imports)]
+extern crate panic_semihosting;
+
+use nrf52840_mdk_bsp::{
+ hal::{
+ prelude::*,
+ timer::{self, Timer},
+ },
+ Board,
+};
+
+#[entry]
+fn main() -> ! {
+ let mut nrf52 = Board::take().unwrap();
+
+ let mut timer = Timer::new(nrf52.TIMER0);
+
+ write!(nrf52.cdc, "Bootstrap complete.").ok();
+ loop {
+ write!(nrf52.cdc, ".").ok();
+ delay(&mut timer, 1_000_000); // 1s
+ }
+}
+
+fn delay<T>(timer: &mut Timer<T>, cycles: u32)
+where
+ T: timer::Instance,
+{
+ timer.start(cycles);
+ let _ = block!(timer.wait());
}