summaryrefslogtreecommitdiff
path: root/examples/src/bin/flash.rs
diff options
context:
space:
mode:
authorDario Nieuwenhuis <dirbaio@dirbaio.net>2020-09-14 17:47:43 +0200
committerDario Nieuwenhuis <dirbaio@dirbaio.net>2020-09-14 17:47:43 +0200
commit1d840cf4b190397f5944ed1fb7e9007e5a2d82dc (patch)
tree5e259e4ee5234c6a9b5a8e382ef19b943c867fcf /examples/src/bin/flash.rs
parentcb6771aceb53281797e578256a661ecbb1286f87 (diff)
downloadnrf-softdevice-1d840cf4b190397f5944ed1fb7e9007e5a2d82dc.zip
example -> examples
Diffstat (limited to 'examples/src/bin/flash.rs')
-rw-r--r--examples/src/bin/flash.rs47
1 files changed, 47 insertions, 0 deletions
diff --git a/examples/src/bin/flash.rs b/examples/src/bin/flash.rs
new file mode 100644
index 0000000..e4570c2
--- /dev/null
+++ b/examples/src/bin/flash.rs
@@ -0,0 +1,47 @@
+#![no_std]
+#![no_main]
+#![feature(type_alias_impl_trait)]
+
+#[path = "../example_common.rs"]
+mod example_common;
+use example_common::*;
+
+use async_flash::Flash as _;
+use cortex_m_rt::entry;
+use nrf_softdevice::{Flash, Softdevice};
+
+#[static_executor::task]
+async fn softdevice_task(sd: &'static Softdevice) {
+ sd.run().await;
+}
+
+#[static_executor::task]
+async fn flash_task(sd: &'static Softdevice) {
+ let mut f = Flash::take(sd);
+
+ info!("starting erase");
+ match f.erase(0x80000).await {
+ Ok(()) => info!("erased!"),
+ Err(e) => depanic!("erase failed: {:?}", e),
+ }
+
+ info!("starting write");
+ match f.write(0x80000, &[1, 2, 3, 4]).await {
+ Ok(()) => info!("write done!"),
+ Err(e) => depanic!("write failed: {:?}", e),
+ }
+}
+
+#[entry]
+fn main() -> ! {
+ info!("Hello World!");
+
+ let sd = Softdevice::enable(&Default::default());
+
+ unsafe {
+ softdevice_task.spawn(sd).dewrap();
+ flash_task.spawn(sd).dewrap();
+
+ static_executor::run();
+ }
+}