diff options
| author | Dario Nieuwenhuis <[email protected]> | 2021-01-01 22:41:59 +0100 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2021-01-01 22:46:32 +0100 |
| commit | 20d3dc87f95f844e747a7e93036ce9ddac369081 (patch) | |
| tree | 3842a1f3a343de0af8195a1a2a2cf0da17cb7c37 /examples | |
| parent | 4783222f675c1316d0e1a0fda92591f7aca63456 (diff) | |
Rename examples -> embassy-nrf-examples
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/.cargo/config | 27 | ||||
| -rw-r--r-- | examples/Cargo.toml | 32 | ||||
| -rw-r--r-- | examples/build.rs | 31 | ||||
| -rw-r--r-- | examples/memory.x | 7 | ||||
| -rw-r--r-- | examples/src/bin/buffered_uart.rs | 84 | ||||
| -rw-r--r-- | examples/src/bin/executor_fairness_test.rs | 74 | ||||
| -rw-r--r-- | examples/src/bin/gpiote.rs | 83 | ||||
| -rw-r--r-- | examples/src/bin/gpiote_port.rs | 62 | ||||
| -rw-r--r-- | examples/src/bin/multiprio.rs | 176 | ||||
| -rw-r--r-- | examples/src/bin/qspi.rs | 134 | ||||
| -rw-r--r-- | examples/src/bin/rtc_async.rs | 65 | ||||
| -rw-r--r-- | examples/src/bin/rtc_raw.rs | 63 | ||||
| -rw-r--r-- | examples/src/bin/uart.rs | 107 | ||||
| -rw-r--r-- | examples/src/example_common.rs | 18 |
14 files changed, 0 insertions, 963 deletions
diff --git a/examples/.cargo/config b/examples/.cargo/config deleted file mode 100644 index 3f319ae55..000000000 --- a/examples/.cargo/config +++ /dev/null | |||
| @@ -1,27 +0,0 @@ | |||
| 1 | [target.'cfg(all(target_arch = "arm", target_os = "none"))'] | ||
| 2 | runner = "probe-run --chip nRF52840_xxAA --defmt" | ||
| 3 | |||
| 4 | rustflags = [ | ||
| 5 | # LLD (shipped with the Rust toolchain) is used as the default linker | ||
| 6 | "-C", "link-arg=--nmagic", | ||
| 7 | "-C", "link-arg=-Tlink.x", | ||
| 8 | "-C", "link-arg=-Tdefmt.x", | ||
| 9 | |||
| 10 | # if you run into problems with LLD switch to the GNU linker by commenting out | ||
| 11 | # this line | ||
| 12 | # "-C", "linker=arm-none-eabi-ld", | ||
| 13 | |||
| 14 | # if you need to link to pre-compiled C libraries provided by a C toolchain | ||
| 15 | # use GCC as the linker by commenting out both lines above and then | ||
| 16 | # uncommenting the three lines below | ||
| 17 | # "-C", "linker=arm-none-eabi-gcc", | ||
| 18 | # "-C", "link-arg=-Wl,-Tlink.x", | ||
| 19 | # "-C", "link-arg=-nostartfiles", | ||
| 20 | ] | ||
| 21 | |||
| 22 | [build] | ||
| 23 | # Pick ONE of these compilation targets | ||
| 24 | # target = "thumbv6m-none-eabi" # Cortex-M0 and Cortex-M0+ | ||
| 25 | # target = "thumbv7m-none-eabi" # Cortex-M3 | ||
| 26 | # target = "thumbv7em-none-eabi" # Cortex-M4 and Cortex-M7 (no FPU) | ||
| 27 | target = "thumbv7em-none-eabihf" # Cortex-M4F and Cortex-M7F (with FPU) | ||
diff --git a/examples/Cargo.toml b/examples/Cargo.toml deleted file mode 100644 index c845c1bfb..000000000 --- a/examples/Cargo.toml +++ /dev/null | |||
| @@ -1,32 +0,0 @@ | |||
| 1 | [package] | ||
| 2 | authors = ["Dario Nieuwenhuis <[email protected]>"] | ||
| 3 | edition = "2018" | ||
| 4 | name = "embassy-examples" | ||
| 5 | version = "0.1.0" | ||
| 6 | |||
| 7 | [features] | ||
| 8 | default = [ | ||
| 9 | "defmt-default", | ||
| 10 | ] | ||
| 11 | defmt-default = [] | ||
| 12 | defmt-trace = [] | ||
| 13 | defmt-debug = [] | ||
| 14 | defmt-info = [] | ||
| 15 | defmt-warn = [] | ||
| 16 | defmt-error = [] | ||
| 17 | |||
| 18 | |||
| 19 | [dependencies] | ||
| 20 | embassy = { version = "0.1.0", path = "../embassy", features = ["defmt", "defmt-trace"] } | ||
| 21 | embassy-nrf = { version = "0.1.0", path = "../embassy-nrf", features = ["defmt", "defmt-trace", "52840"] } | ||
| 22 | |||
| 23 | defmt = "0.1.3" | ||
| 24 | defmt-rtt = "0.1.0" | ||
| 25 | |||
| 26 | cortex-m = { version = "0.6.3" } | ||
| 27 | cortex-m-rt = "0.6.13" | ||
| 28 | embedded-hal = { version = "0.2.4" } | ||
| 29 | panic-probe = "0.1.0" | ||
| 30 | nrf52840-hal = { version = "0.12.0" } | ||
| 31 | futures = { version = "0.3.8", default-features = false, features = ["async-await"] } | ||
| 32 | cortex-m-rtic = { git = "https://github.com/rtic-rs/cortex-m-rtic", branch = "master"} | ||
diff --git a/examples/build.rs b/examples/build.rs deleted file mode 100644 index d534cc3df..000000000 --- a/examples/build.rs +++ /dev/null | |||
| @@ -1,31 +0,0 @@ | |||
| 1 | //! This build script copies the `memory.x` file from the crate root into | ||
| 2 | //! a directory where the linker can always find it at build time. | ||
| 3 | //! For many projects this is optional, as the linker always searches the | ||
| 4 | //! project root directory -- wherever `Cargo.toml` is. However, if you | ||
| 5 | //! are using a workspace or have a more complicated build setup, this | ||
| 6 | //! build script becomes required. Additionally, by requesting that | ||
| 7 | //! Cargo re-run the build script whenever `memory.x` is changed, | ||
| 8 | //! updating `memory.x` ensures a rebuild of the application with the | ||
| 9 | //! new memory settings. | ||
| 10 | |||
| 11 | use std::env; | ||
| 12 | use std::fs::File; | ||
| 13 | use std::io::Write; | ||
| 14 | use std::path::PathBuf; | ||
| 15 | |||
| 16 | fn main() { | ||
| 17 | // Put `memory.x` in our output directory and ensure it's | ||
| 18 | // on the linker search path. | ||
| 19 | let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap()); | ||
| 20 | File::create(out.join("memory.x")) | ||
| 21 | .unwrap() | ||
| 22 | .write_all(include_bytes!("memory.x")) | ||
| 23 | .unwrap(); | ||
| 24 | println!("cargo:rustc-link-search={}", out.display()); | ||
| 25 | |||
| 26 | // By default, Cargo will re-run a build script whenever | ||
| 27 | // any file in the project changes. By specifying `memory.x` | ||
| 28 | // here, we ensure the build script is only re-run when | ||
| 29 | // `memory.x` is changed. | ||
| 30 | println!("cargo:rerun-if-changed=memory.x"); | ||
| 31 | } | ||
diff --git a/examples/memory.x b/examples/memory.x deleted file mode 100644 index 9b04edec0..000000000 --- a/examples/memory.x +++ /dev/null | |||
| @@ -1,7 +0,0 @@ | |||
| 1 | MEMORY | ||
| 2 | { | ||
| 3 | /* NOTE 1 K = 1 KiBi = 1024 bytes */ | ||
| 4 | /* These values correspond to the NRF52840 with Softdevices S140 7.0.1 */ | ||
| 5 | FLASH : ORIGIN = 0x00000000, LENGTH = 1024K | ||
| 6 | RAM : ORIGIN = 0x20000000, LENGTH = 256K | ||
| 7 | } | ||
diff --git a/examples/src/bin/buffered_uart.rs b/examples/src/bin/buffered_uart.rs deleted file mode 100644 index 6e15fbcfa..000000000 --- a/examples/src/bin/buffered_uart.rs +++ /dev/null | |||
| @@ -1,84 +0,0 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | #![feature(type_alias_impl_trait)] | ||
| 4 | |||
| 5 | #[path = "../example_common.rs"] | ||
| 6 | mod example_common; | ||
| 7 | use example_common::*; | ||
| 8 | |||
| 9 | use cortex_m_rt::entry; | ||
| 10 | use defmt::panic; | ||
| 11 | use futures::pin_mut; | ||
| 12 | use nrf52840_hal::gpio; | ||
| 13 | |||
| 14 | use embassy::executor::{task, Executor}; | ||
| 15 | use embassy::io::{AsyncBufRead, AsyncBufReadExt, AsyncWrite, AsyncWriteExt}; | ||
| 16 | use embassy::util::Forever; | ||
| 17 | use embassy_nrf::buffered_uarte; | ||
| 18 | use embassy_nrf::interrupt; | ||
| 19 | |||
| 20 | #[task] | ||
| 21 | async fn run() { | ||
| 22 | let p = unwrap!(embassy_nrf::pac::Peripherals::take()); | ||
| 23 | |||
| 24 | let port0 = gpio::p0::Parts::new(p.P0); | ||
| 25 | |||
| 26 | let pins = buffered_uarte::Pins { | ||
| 27 | rxd: port0.p0_08.into_floating_input().degrade(), | ||
| 28 | txd: port0 | ||
| 29 | .p0_06 | ||
| 30 | .into_push_pull_output(gpio::Level::Low) | ||
| 31 | .degrade(), | ||
| 32 | cts: None, | ||
| 33 | rts: None, | ||
| 34 | }; | ||
| 35 | |||
| 36 | let irq = interrupt::take!(UARTE0_UART0); | ||
| 37 | let u = buffered_uarte::BufferedUarte::new( | ||
| 38 | p.UARTE0, | ||
| 39 | irq, | ||
| 40 | pins, | ||
| 41 | buffered_uarte::Parity::EXCLUDED, | ||
| 42 | buffered_uarte::Baudrate::BAUD115200, | ||
| 43 | ); | ||
| 44 | pin_mut!(u); | ||
| 45 | |||
| 46 | info!("uarte initialized!"); | ||
| 47 | |||
| 48 | unwrap!(u.write_all(b"Hello!\r\n").await); | ||
| 49 | info!("wrote hello in uart!"); | ||
| 50 | |||
| 51 | // Simple demo, reading 8-char chunks and echoing them back reversed. | ||
| 52 | loop { | ||
| 53 | info!("reading..."); | ||
| 54 | let mut buf = [0u8; 8]; | ||
| 55 | unwrap!(u.read_exact(&mut buf).await); | ||
| 56 | info!("read done, got {:[u8]}", buf); | ||
| 57 | |||
| 58 | // Reverse buf | ||
| 59 | for i in 0..4 { | ||
| 60 | let tmp = buf[i]; | ||
| 61 | buf[i] = buf[7 - i]; | ||
| 62 | buf[7 - i] = tmp; | ||
| 63 | } | ||
| 64 | |||
| 65 | info!("writing..."); | ||
| 66 | unwrap!(u.write_all(&buf).await); | ||
| 67 | info!("write done"); | ||
| 68 | } | ||
| 69 | } | ||
| 70 | |||
| 71 | static EXECUTOR: Forever<Executor> = Forever::new(); | ||
| 72 | |||
| 73 | #[entry] | ||
| 74 | fn main() -> ! { | ||
| 75 | info!("Hello World!"); | ||
| 76 | |||
| 77 | let executor = EXECUTOR.put(Executor::new(cortex_m::asm::sev)); | ||
| 78 | unwrap!(executor.spawn(run())); | ||
| 79 | |||
| 80 | loop { | ||
| 81 | executor.run(); | ||
| 82 | cortex_m::asm::wfe(); | ||
| 83 | } | ||
| 84 | } | ||
diff --git a/examples/src/bin/executor_fairness_test.rs b/examples/src/bin/executor_fairness_test.rs deleted file mode 100644 index 9b2c1bd26..000000000 --- a/examples/src/bin/executor_fairness_test.rs +++ /dev/null | |||
| @@ -1,74 +0,0 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | #![feature(type_alias_impl_trait)] | ||
| 4 | |||
| 5 | #[path = "../example_common.rs"] | ||
| 6 | mod example_common; | ||
| 7 | use example_common::*; | ||
| 8 | |||
| 9 | use core::task::Poll; | ||
| 10 | use cortex_m_rt::entry; | ||
| 11 | use defmt::panic; | ||
| 12 | use embassy::executor::{task, Executor}; | ||
| 13 | use embassy::time::{Duration, Instant, Timer}; | ||
| 14 | use embassy::util::Forever; | ||
| 15 | use embassy_nrf::pac; | ||
| 16 | use embassy_nrf::{interrupt, rtc}; | ||
| 17 | use nrf52840_hal::clocks; | ||
| 18 | |||
| 19 | #[task] | ||
| 20 | async fn run1() { | ||
| 21 | loop { | ||
| 22 | info!("DING DONG"); | ||
| 23 | Timer::after(Duration::from_ticks(16000)).await; | ||
| 24 | } | ||
| 25 | } | ||
| 26 | |||
| 27 | #[task] | ||
| 28 | async fn run2() { | ||
| 29 | loop { | ||
| 30 | Timer::at(Instant::from_ticks(0)).await; | ||
| 31 | } | ||
| 32 | } | ||
| 33 | |||
| 34 | #[task] | ||
| 35 | async fn run3() { | ||
| 36 | futures::future::poll_fn(|cx| { | ||
| 37 | cx.waker().wake_by_ref(); | ||
| 38 | Poll::<()>::Pending | ||
| 39 | }) | ||
| 40 | .await; | ||
| 41 | } | ||
| 42 | |||
| 43 | static RTC: Forever<rtc::RTC<pac::RTC1>> = Forever::new(); | ||
| 44 | static ALARM: Forever<rtc::Alarm<pac::RTC1>> = Forever::new(); | ||
| 45 | static EXECUTOR: Forever<Executor> = Forever::new(); | ||
| 46 | |||
| 47 | #[entry] | ||
| 48 | fn main() -> ! { | ||
| 49 | info!("Hello World!"); | ||
| 50 | |||
| 51 | let p = unwrap!(embassy_nrf::pac::Peripherals::take()); | ||
| 52 | |||
| 53 | clocks::Clocks::new(p.CLOCK) | ||
| 54 | .enable_ext_hfosc() | ||
| 55 | .set_lfclk_src_external(clocks::LfOscConfiguration::NoExternalNoBypass) | ||
| 56 | .start_lfclk(); | ||
| 57 | |||
| 58 | let rtc = RTC.put(rtc::RTC::new(p.RTC1, interrupt::take!(RTC1))); | ||
| 59 | rtc.start(); | ||
| 60 | |||
| 61 | unsafe { embassy::time::set_clock(rtc) }; | ||
| 62 | |||
| 63 | let alarm = ALARM.put(rtc.alarm0()); | ||
| 64 | let executor = EXECUTOR.put(Executor::new_with_alarm(alarm, cortex_m::asm::sev)); | ||
| 65 | |||
| 66 | unwrap!(executor.spawn(run1())); | ||
| 67 | unwrap!(executor.spawn(run2())); | ||
| 68 | unwrap!(executor.spawn(run3())); | ||
| 69 | |||
| 70 | loop { | ||
| 71 | executor.run(); | ||
| 72 | cortex_m::asm::wfe(); | ||
| 73 | } | ||
| 74 | } | ||
diff --git a/examples/src/bin/gpiote.rs b/examples/src/bin/gpiote.rs deleted file mode 100644 index afa1b85d5..000000000 --- a/examples/src/bin/gpiote.rs +++ /dev/null | |||
| @@ -1,83 +0,0 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | #![feature(type_alias_impl_trait)] | ||
| 4 | |||
| 5 | #[path = "../example_common.rs"] | ||
| 6 | mod example_common; | ||
| 7 | use example_common::*; | ||
| 8 | |||
| 9 | use cortex_m_rt::entry; | ||
| 10 | use defmt::panic; | ||
| 11 | use nrf52840_hal::gpio; | ||
| 12 | |||
| 13 | use embassy::executor::{task, Executor}; | ||
| 14 | use embassy::util::Forever; | ||
| 15 | use embassy_nrf::gpiote; | ||
| 16 | use embassy_nrf::interrupt; | ||
| 17 | |||
| 18 | #[task] | ||
| 19 | async fn run() { | ||
| 20 | let p = unwrap!(embassy_nrf::pac::Peripherals::take()); | ||
| 21 | let port0 = gpio::p0::Parts::new(p.P0); | ||
| 22 | |||
| 23 | let g = gpiote::Gpiote::new(p.GPIOTE, interrupt::take!(GPIOTE)); | ||
| 24 | |||
| 25 | info!("Starting!"); | ||
| 26 | |||
| 27 | let pin1 = port0.p0_11.into_pullup_input().degrade(); | ||
| 28 | let button1 = async { | ||
| 29 | let ch = unwrap!(g.new_input_channel(pin1, gpiote::InputChannelPolarity::HiToLo)); | ||
| 30 | |||
| 31 | loop { | ||
| 32 | ch.wait().await; | ||
| 33 | info!("Button 1 pressed") | ||
| 34 | } | ||
| 35 | }; | ||
| 36 | |||
| 37 | let pin2 = port0.p0_12.into_pullup_input().degrade(); | ||
| 38 | let button2 = async { | ||
| 39 | let ch = unwrap!(g.new_input_channel(pin2, gpiote::InputChannelPolarity::LoToHi)); | ||
| 40 | |||
| 41 | loop { | ||
| 42 | ch.wait().await; | ||
| 43 | info!("Button 2 released") | ||
| 44 | } | ||
| 45 | }; | ||
| 46 | |||
| 47 | let pin3 = port0.p0_24.into_pullup_input().degrade(); | ||
| 48 | let button3 = async { | ||
| 49 | let ch = unwrap!(g.new_input_channel(pin3, gpiote::InputChannelPolarity::Toggle)); | ||
| 50 | |||
| 51 | loop { | ||
| 52 | ch.wait().await; | ||
| 53 | info!("Button 3 toggled") | ||
| 54 | } | ||
| 55 | }; | ||
| 56 | |||
| 57 | let pin4 = port0.p0_25.into_pullup_input().degrade(); | ||
| 58 | let button4 = async { | ||
| 59 | let ch = unwrap!(g.new_input_channel(pin4, gpiote::InputChannelPolarity::Toggle)); | ||
| 60 | |||
| 61 | loop { | ||
| 62 | ch.wait().await; | ||
| 63 | info!("Button 4 toggled") | ||
| 64 | } | ||
| 65 | }; | ||
| 66 | |||
| 67 | futures::join!(button1, button2, button3, button4); | ||
| 68 | } | ||
| 69 | |||
| 70 | static EXECUTOR: Forever<Executor> = Forever::new(); | ||
| 71 | |||
| 72 | #[entry] | ||
| 73 | fn main() -> ! { | ||
| 74 | info!("Hello World!"); | ||
| 75 | |||
| 76 | let executor = EXECUTOR.put(Executor::new(cortex_m::asm::sev)); | ||
| 77 | unwrap!(executor.spawn(run())); | ||
| 78 | |||
| 79 | loop { | ||
| 80 | executor.run(); | ||
| 81 | cortex_m::asm::wfe(); | ||
| 82 | } | ||
| 83 | } | ||
diff --git a/examples/src/bin/gpiote_port.rs b/examples/src/bin/gpiote_port.rs deleted file mode 100644 index f5aa81322..000000000 --- a/examples/src/bin/gpiote_port.rs +++ /dev/null | |||
| @@ -1,62 +0,0 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | #![feature(type_alias_impl_trait)] | ||
| 4 | |||
| 5 | #[path = "../example_common.rs"] | ||
| 6 | mod example_common; | ||
| 7 | use example_common::*; | ||
| 8 | |||
| 9 | use core::mem; | ||
| 10 | use cortex_m_rt::entry; | ||
| 11 | use defmt::panic; | ||
| 12 | use nrf52840_hal::gpio; | ||
| 13 | |||
| 14 | use embassy::executor::{task, Executor}; | ||
| 15 | use embassy::util::Forever; | ||
| 16 | use embassy_nrf::gpiote::{Gpiote, PortInputPolarity}; | ||
| 17 | use embassy_nrf::interrupt; | ||
| 18 | |||
| 19 | async fn button(g: &Gpiote, n: usize, pin: gpio::Pin<gpio::Input<gpio::PullUp>>) { | ||
| 20 | loop { | ||
| 21 | g.wait_port_input(&pin, PortInputPolarity::Low).await; | ||
| 22 | info!("Button {:?} pressed!", n); | ||
| 23 | g.wait_port_input(&pin, PortInputPolarity::High).await; | ||
| 24 | info!("Button {:?} released!", n); | ||
| 25 | } | ||
| 26 | } | ||
| 27 | |||
| 28 | #[task] | ||
| 29 | async fn run() { | ||
| 30 | let p = unwrap!(embassy_nrf::pac::Peripherals::take()); | ||
| 31 | let port0 = gpio::p0::Parts::new(p.P0); | ||
| 32 | |||
| 33 | let g = Gpiote::new(p.GPIOTE, interrupt::take!(GPIOTE)); | ||
| 34 | info!( | ||
| 35 | "sizeof Signal<()> = {:usize}", | ||
| 36 | mem::size_of::<embassy::util::Signal<()>>() | ||
| 37 | ); | ||
| 38 | info!("sizeof gpiote = {:usize}", mem::size_of::<Gpiote>()); | ||
| 39 | |||
| 40 | info!("Starting!"); | ||
| 41 | |||
| 42 | let button1 = button(&g, 1, port0.p0_11.into_pullup_input().degrade()); | ||
| 43 | let button2 = button(&g, 2, port0.p0_12.into_pullup_input().degrade()); | ||
| 44 | let button3 = button(&g, 3, port0.p0_24.into_pullup_input().degrade()); | ||
| 45 | let button4 = button(&g, 4, port0.p0_25.into_pullup_input().degrade()); | ||
| 46 | futures::join!(button1, button2, button3, button4); | ||
| 47 | } | ||
| 48 | |||
| 49 | static EXECUTOR: Forever<Executor> = Forever::new(); | ||
| 50 | |||
| 51 | #[entry] | ||
| 52 | fn main() -> ! { | ||
| 53 | info!("Hello World!"); | ||
| 54 | |||
| 55 | let executor = EXECUTOR.put(Executor::new(cortex_m::asm::sev)); | ||
| 56 | unwrap!(executor.spawn(run())); | ||
| 57 | |||
| 58 | loop { | ||
| 59 | executor.run(); | ||
| 60 | cortex_m::asm::wfe(); | ||
| 61 | } | ||
| 62 | } | ||
diff --git a/examples/src/bin/multiprio.rs b/examples/src/bin/multiprio.rs deleted file mode 100644 index c821e3dba..000000000 --- a/examples/src/bin/multiprio.rs +++ /dev/null | |||
| @@ -1,176 +0,0 @@ | |||
| 1 | //! This example showcases how to create multiple Executor instances to run tasks at | ||
| 2 | //! different priority levels. | ||
| 3 | //! | ||
| 4 | //! Low priority executor runs in thread mode (not interrupt), and uses `sev` for signaling | ||
| 5 | //! there's work in the queue, and `wfe` for waiting for work. | ||
| 6 | //! | ||
| 7 | //! Medium and high priority executors run in two interrupts with different priorities. | ||
| 8 | //! Signaling work is done by pending the interrupt. No "waiting" needs to be done explicitly, since | ||
| 9 | //! when there's work the interrupt will trigger and run the executor. | ||
| 10 | //! | ||
| 11 | //! Sample output below. Note that high priority ticks can interrupt everything else, and | ||
| 12 | //! medium priority computations can interrupt low priority computations, making them to appear | ||
| 13 | //! to take significantly longer time. | ||
| 14 | //! | ||
| 15 | //! ```not_rust | ||
| 16 | //! [med] Starting long computation | ||
| 17 | //! [med] done in 992 ms | ||
| 18 | //! [high] tick! | ||
| 19 | //! [low] Starting long computation | ||
| 20 | //! [med] Starting long computation | ||
| 21 | //! [high] tick! | ||
| 22 | //! [high] tick! | ||
| 23 | //! [med] done in 993 ms | ||
| 24 | //! [med] Starting long computation | ||
| 25 | //! [high] tick! | ||
| 26 | //! [high] tick! | ||
| 27 | //! [med] done in 993 ms | ||
| 28 | //! [low] done in 3972 ms | ||
| 29 | //! [med] Starting long computation | ||
| 30 | //! [high] tick! | ||
| 31 | //! [high] tick! | ||
| 32 | //! [med] done in 993 ms | ||
| 33 | //! ``` | ||
| 34 | //! | ||
| 35 | //! For comparison, try changing the code so all 3 tasks get spawned on the low priority executor. | ||
| 36 | //! You will get an output like the following. Note that no computation is ever interrupted. | ||
| 37 | //! | ||
| 38 | //! ```not_rust | ||
| 39 | //! [high] tick! | ||
| 40 | //! [med] Starting long computation | ||
| 41 | //! [med] done in 496 ms | ||
| 42 | //! [low] Starting long computation | ||
| 43 | //! [low] done in 992 ms | ||
| 44 | //! [med] Starting long computation | ||
| 45 | //! [med] done in 496 ms | ||
| 46 | //! [high] tick! | ||
| 47 | //! [low] Starting long computation | ||
| 48 | //! [low] done in 992 ms | ||
| 49 | //! [high] tick! | ||
| 50 | //! [med] Starting long computation | ||
| 51 | //! [med] done in 496 ms | ||
| 52 | //! [high] tick! | ||
| 53 | //! ``` | ||
| 54 | //! | ||
| 55 | |||
| 56 | #![no_std] | ||
| 57 | #![no_main] | ||
| 58 | #![feature(type_alias_impl_trait)] | ||
| 59 | |||
| 60 | #[path = "../example_common.rs"] | ||
| 61 | mod example_common; | ||
| 62 | use example_common::*; | ||
| 63 | |||
| 64 | use cortex_m::peripheral::NVIC; | ||
| 65 | use cortex_m_rt::entry; | ||
| 66 | use defmt::panic; | ||
| 67 | use nrf52840_hal::clocks; | ||
| 68 | |||
| 69 | use embassy::executor::{task, Executor}; | ||
| 70 | use embassy::time::{Duration, Instant, Timer}; | ||
| 71 | use embassy::util::Forever; | ||
| 72 | use embassy_nrf::{interrupt, pac, rtc}; | ||
| 73 | |||
| 74 | #[task] | ||
| 75 | async fn run_high() { | ||
| 76 | loop { | ||
| 77 | info!(" [high] tick!"); | ||
| 78 | Timer::after(Duration::from_ticks(27374)).await; | ||
| 79 | } | ||
| 80 | } | ||
| 81 | |||
| 82 | #[task] | ||
| 83 | async fn run_med() { | ||
| 84 | loop { | ||
| 85 | let start = Instant::now(); | ||
| 86 | info!(" [med] Starting long computation"); | ||
| 87 | |||
| 88 | // Spin-wait to simulate a long CPU computation | ||
| 89 | cortex_m::asm::delay(32_000_000); // ~1 second | ||
| 90 | |||
| 91 | let end = Instant::now(); | ||
| 92 | let ms = end.duration_since(start).as_ticks() / 33; | ||
| 93 | info!(" [med] done in {:u64} ms", ms); | ||
| 94 | |||
| 95 | Timer::after(Duration::from_ticks(23421)).await; | ||
| 96 | } | ||
| 97 | } | ||
| 98 | |||
| 99 | #[task] | ||
| 100 | async fn run_low() { | ||
| 101 | loop { | ||
| 102 | let start = Instant::now(); | ||
| 103 | info!("[low] Starting long computation"); | ||
| 104 | |||
| 105 | // Spin-wait to simulate a long CPU computation | ||
| 106 | cortex_m::asm::delay(64_000_000); // ~2 seconds | ||
| 107 | |||
| 108 | let end = Instant::now(); | ||
| 109 | let ms = end.duration_since(start).as_ticks() / 33; | ||
| 110 | info!("[low] done in {:u64} ms", ms); | ||
| 111 | |||
| 112 | Timer::after(Duration::from_ticks(32983)).await; | ||
| 113 | } | ||
| 114 | } | ||
| 115 | |||
| 116 | static RTC: Forever<rtc::RTC<pac::RTC1>> = Forever::new(); | ||
| 117 | static ALARM_LOW: Forever<rtc::Alarm<pac::RTC1>> = Forever::new(); | ||
| 118 | static EXECUTOR_LOW: Forever<Executor> = Forever::new(); | ||
| 119 | static ALARM_MED: Forever<rtc::Alarm<pac::RTC1>> = Forever::new(); | ||
| 120 | static EXECUTOR_MED: Forever<Executor> = Forever::new(); | ||
| 121 | static ALARM_HIGH: Forever<rtc::Alarm<pac::RTC1>> = Forever::new(); | ||
| 122 | static EXECUTOR_HIGH: Forever<Executor> = Forever::new(); | ||
| 123 | |||
| 124 | #[entry] | ||
| 125 | fn main() -> ! { | ||
| 126 | info!("Hello World!"); | ||
| 127 | |||
| 128 | let p = unwrap!(embassy_nrf::pac::Peripherals::take()); | ||
| 129 | |||
| 130 | clocks::Clocks::new(p.CLOCK) | ||
| 131 | .enable_ext_hfosc() | ||
| 132 | .set_lfclk_src_external(clocks::LfOscConfiguration::NoExternalNoBypass) | ||
| 133 | .start_lfclk(); | ||
| 134 | |||
| 135 | let rtc = RTC.put(rtc::RTC::new(p.RTC1, interrupt::take!(RTC1))); | ||
| 136 | rtc.start(); | ||
| 137 | unsafe { embassy::time::set_clock(rtc) }; | ||
| 138 | |||
| 139 | let alarm_low = ALARM_LOW.put(rtc.alarm0()); | ||
| 140 | let executor_low = EXECUTOR_LOW.put(Executor::new_with_alarm(alarm_low, cortex_m::asm::sev)); | ||
| 141 | let alarm_med = ALARM_MED.put(rtc.alarm1()); | ||
| 142 | let executor_med = EXECUTOR_MED.put(Executor::new_with_alarm(alarm_med, || { | ||
| 143 | NVIC::pend(interrupt::SWI0_EGU0) | ||
| 144 | })); | ||
| 145 | let alarm_high = ALARM_HIGH.put(rtc.alarm2()); | ||
| 146 | let executor_high = EXECUTOR_HIGH.put(Executor::new_with_alarm(alarm_high, || { | ||
| 147 | NVIC::pend(interrupt::SWI1_EGU1) | ||
| 148 | })); | ||
| 149 | |||
| 150 | unsafe { | ||
| 151 | let mut nvic: NVIC = core::mem::transmute(()); | ||
| 152 | nvic.set_priority(interrupt::SWI0_EGU0, 7 << 5); | ||
| 153 | nvic.set_priority(interrupt::SWI1_EGU1, 6 << 5); | ||
| 154 | NVIC::unmask(interrupt::SWI0_EGU0); | ||
| 155 | NVIC::unmask(interrupt::SWI1_EGU1); | ||
| 156 | } | ||
| 157 | |||
| 158 | unwrap!(executor_low.spawn(run_low())); | ||
| 159 | unwrap!(executor_med.spawn(run_med())); | ||
| 160 | unwrap!(executor_high.spawn(run_high())); | ||
| 161 | |||
| 162 | loop { | ||
| 163 | executor_low.run(); | ||
| 164 | cortex_m::asm::wfe(); | ||
| 165 | } | ||
| 166 | } | ||
| 167 | |||
| 168 | #[interrupt] | ||
| 169 | unsafe fn SWI0_EGU0() { | ||
| 170 | EXECUTOR_MED.steal().run() | ||
| 171 | } | ||
| 172 | |||
| 173 | #[interrupt] | ||
| 174 | unsafe fn SWI1_EGU1() { | ||
| 175 | EXECUTOR_HIGH.steal().run() | ||
| 176 | } | ||
diff --git a/examples/src/bin/qspi.rs b/examples/src/bin/qspi.rs deleted file mode 100644 index a7d47f79c..000000000 --- a/examples/src/bin/qspi.rs +++ /dev/null | |||
| @@ -1,134 +0,0 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | #![feature(type_alias_impl_trait)] | ||
| 4 | |||
| 5 | #[path = "../example_common.rs"] | ||
| 6 | mod example_common; | ||
| 7 | use example_common::*; | ||
| 8 | |||
| 9 | use cortex_m_rt::entry; | ||
| 10 | use defmt::{assert_eq, panic, *}; | ||
| 11 | use nrf52840_hal::gpio; | ||
| 12 | |||
| 13 | use embassy::executor::{task, Executor}; | ||
| 14 | use embassy::flash::Flash; | ||
| 15 | use embassy::util::Forever; | ||
| 16 | use embassy_nrf::{interrupt, qspi}; | ||
| 17 | |||
| 18 | const PAGE_SIZE: usize = 4096; | ||
| 19 | |||
| 20 | // Workaround for alignment requirements. | ||
| 21 | // Nicer API will probably come in the future. | ||
| 22 | #[repr(C, align(4))] | ||
| 23 | struct AlignedBuf([u8; 4096]); | ||
| 24 | |||
| 25 | #[task] | ||
| 26 | async fn run() { | ||
| 27 | let p = unwrap!(embassy_nrf::pac::Peripherals::take()); | ||
| 28 | |||
| 29 | let port0 = gpio::p0::Parts::new(p.P0); | ||
| 30 | |||
| 31 | let pins = qspi::Pins { | ||
| 32 | csn: port0 | ||
| 33 | .p0_17 | ||
| 34 | .into_push_pull_output(gpio::Level::High) | ||
| 35 | .degrade(), | ||
| 36 | sck: port0 | ||
| 37 | .p0_19 | ||
| 38 | .into_push_pull_output(gpio::Level::High) | ||
| 39 | .degrade(), | ||
| 40 | io0: port0 | ||
| 41 | .p0_20 | ||
| 42 | .into_push_pull_output(gpio::Level::High) | ||
| 43 | .degrade(), | ||
| 44 | io1: port0 | ||
| 45 | .p0_21 | ||
| 46 | .into_push_pull_output(gpio::Level::High) | ||
| 47 | .degrade(), | ||
| 48 | io2: Some( | ||
| 49 | port0 | ||
| 50 | .p0_22 | ||
| 51 | .into_push_pull_output(gpio::Level::High) | ||
| 52 | .degrade(), | ||
| 53 | ), | ||
| 54 | io3: Some( | ||
| 55 | port0 | ||
| 56 | .p0_23 | ||
| 57 | .into_push_pull_output(gpio::Level::High) | ||
| 58 | .degrade(), | ||
| 59 | ), | ||
| 60 | }; | ||
| 61 | |||
| 62 | let config = qspi::Config { | ||
| 63 | pins, | ||
| 64 | read_opcode: qspi::ReadOpcode::READ4IO, | ||
| 65 | write_opcode: qspi::WriteOpcode::PP4IO, | ||
| 66 | xip_offset: 0, | ||
| 67 | write_page_size: qspi::WritePageSize::_256BYTES, | ||
| 68 | deep_power_down: None, | ||
| 69 | }; | ||
| 70 | |||
| 71 | let irq = interrupt::take!(QSPI); | ||
| 72 | let mut q = qspi::Qspi::new(p.QSPI, irq, config); | ||
| 73 | |||
| 74 | let mut id = [1; 3]; | ||
| 75 | q.custom_instruction(0x9F, &[], &mut id).await.unwrap(); | ||
| 76 | info!("id: {:[u8]}", id); | ||
| 77 | |||
| 78 | // Read status register | ||
| 79 | let mut status = [0; 1]; | ||
| 80 | q.custom_instruction(0x05, &[], &mut status).await.unwrap(); | ||
| 81 | |||
| 82 | info!("status: {:?}", status[0]); | ||
| 83 | |||
| 84 | if status[0] & 0x40 == 0 { | ||
| 85 | status[0] |= 0x40; | ||
| 86 | |||
| 87 | q.custom_instruction(0x01, &status, &mut []).await.unwrap(); | ||
| 88 | |||
| 89 | info!("enabled quad in status"); | ||
| 90 | } | ||
| 91 | |||
| 92 | let mut buf = AlignedBuf([0u8; PAGE_SIZE]); | ||
| 93 | |||
| 94 | let pattern = |a: u32| (a ^ (a >> 8) ^ (a >> 16) ^ (a >> 24)) as u8; | ||
| 95 | |||
| 96 | for i in 0..8 { | ||
| 97 | info!("page {:?}: erasing... ", i); | ||
| 98 | q.erase(i * PAGE_SIZE).await.unwrap(); | ||
| 99 | |||
| 100 | for j in 0..PAGE_SIZE { | ||
| 101 | buf.0[j] = pattern((j + i * PAGE_SIZE) as u32); | ||
| 102 | } | ||
| 103 | |||
| 104 | info!("programming..."); | ||
| 105 | q.write(i * PAGE_SIZE, &buf.0).await.unwrap(); | ||
| 106 | } | ||
| 107 | |||
| 108 | for i in 0..8 { | ||
| 109 | info!("page {:?}: reading... ", i); | ||
| 110 | q.read(i * PAGE_SIZE, &mut buf.0).await.unwrap(); | ||
| 111 | |||
| 112 | info!("verifying..."); | ||
| 113 | for j in 0..PAGE_SIZE { | ||
| 114 | assert_eq!(buf.0[j], pattern((j + i * PAGE_SIZE) as u32)); | ||
| 115 | } | ||
| 116 | } | ||
| 117 | |||
| 118 | info!("done!") | ||
| 119 | } | ||
| 120 | |||
| 121 | static EXECUTOR: Forever<Executor> = Forever::new(); | ||
| 122 | |||
| 123 | #[entry] | ||
| 124 | fn main() -> ! { | ||
| 125 | info!("Hello World!"); | ||
| 126 | |||
| 127 | let executor = EXECUTOR.put(Executor::new(cortex_m::asm::sev)); | ||
| 128 | unwrap!(executor.spawn(run())); | ||
| 129 | |||
| 130 | loop { | ||
| 131 | executor.run(); | ||
| 132 | cortex_m::asm::wfe(); | ||
| 133 | } | ||
| 134 | } | ||
diff --git a/examples/src/bin/rtc_async.rs b/examples/src/bin/rtc_async.rs deleted file mode 100644 index dcdeb7049..000000000 --- a/examples/src/bin/rtc_async.rs +++ /dev/null | |||
| @@ -1,65 +0,0 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | #![feature(type_alias_impl_trait)] | ||
| 4 | |||
| 5 | #[path = "../example_common.rs"] | ||
| 6 | mod example_common; | ||
| 7 | use example_common::*; | ||
| 8 | |||
| 9 | use core::mem::MaybeUninit; | ||
| 10 | use cortex_m_rt::entry; | ||
| 11 | use defmt::panic; | ||
| 12 | use embassy::executor::{task, Executor}; | ||
| 13 | use embassy::time::{Clock, Duration, Timer}; | ||
| 14 | use embassy::util::Forever; | ||
| 15 | use embassy_nrf::pac; | ||
| 16 | use embassy_nrf::{interrupt, rtc}; | ||
| 17 | use nrf52840_hal::clocks; | ||
| 18 | |||
| 19 | #[task] | ||
| 20 | async fn run1() { | ||
| 21 | loop { | ||
| 22 | info!("BIG INFREQUENT TICK"); | ||
| 23 | Timer::after(Duration::from_ticks(64000)).await; | ||
| 24 | } | ||
| 25 | } | ||
| 26 | |||
| 27 | #[task] | ||
| 28 | async fn run2() { | ||
| 29 | loop { | ||
| 30 | info!("tick"); | ||
| 31 | Timer::after(Duration::from_ticks(13000)).await; | ||
| 32 | } | ||
| 33 | } | ||
| 34 | |||
| 35 | static RTC: Forever<rtc::RTC<pac::RTC1>> = Forever::new(); | ||
| 36 | static ALARM: Forever<rtc::Alarm<pac::RTC1>> = Forever::new(); | ||
| 37 | static EXECUTOR: Forever<Executor> = Forever::new(); | ||
| 38 | |||
| 39 | #[entry] | ||
| 40 | fn main() -> ! { | ||
| 41 | info!("Hello World!"); | ||
| 42 | |||
| 43 | let p = unwrap!(embassy_nrf::pac::Peripherals::take()); | ||
| 44 | |||
| 45 | clocks::Clocks::new(p.CLOCK) | ||
| 46 | .enable_ext_hfosc() | ||
| 47 | .set_lfclk_src_external(clocks::LfOscConfiguration::NoExternalNoBypass) | ||
| 48 | .start_lfclk(); | ||
| 49 | |||
| 50 | let rtc = RTC.put(rtc::RTC::new(p.RTC1, interrupt::take!(RTC1))); | ||
| 51 | rtc.start(); | ||
| 52 | |||
| 53 | unsafe { embassy::time::set_clock(rtc) }; | ||
| 54 | |||
| 55 | let alarm = ALARM.put(rtc.alarm0()); | ||
| 56 | let executor = EXECUTOR.put(Executor::new_with_alarm(alarm, cortex_m::asm::sev)); | ||
| 57 | |||
| 58 | unwrap!(executor.spawn(run1())); | ||
| 59 | unwrap!(executor.spawn(run2())); | ||
| 60 | |||
| 61 | loop { | ||
| 62 | executor.run(); | ||
| 63 | cortex_m::asm::wfe(); | ||
| 64 | } | ||
| 65 | } | ||
diff --git a/examples/src/bin/rtc_raw.rs b/examples/src/bin/rtc_raw.rs deleted file mode 100644 index 438585460..000000000 --- a/examples/src/bin/rtc_raw.rs +++ /dev/null | |||
| @@ -1,63 +0,0 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | #![feature(type_alias_impl_trait)] | ||
| 4 | |||
| 5 | #[path = "../example_common.rs"] | ||
| 6 | mod example_common; | ||
| 7 | use example_common::*; | ||
| 8 | |||
| 9 | use core::mem::MaybeUninit; | ||
| 10 | use cortex_m_rt::entry; | ||
| 11 | use defmt::panic; | ||
| 12 | use embassy::time::{Alarm, Clock}; | ||
| 13 | use embassy_nrf::{interrupt, rtc}; | ||
| 14 | use nrf52840_hal::clocks; | ||
| 15 | |||
| 16 | static mut RTC: MaybeUninit<rtc::RTC<embassy_nrf::pac::RTC1>> = MaybeUninit::uninit(); | ||
| 17 | |||
| 18 | #[entry] | ||
| 19 | fn main() -> ! { | ||
| 20 | info!("Hello World!"); | ||
| 21 | |||
| 22 | let p = unwrap!(embassy_nrf::pac::Peripherals::take()); | ||
| 23 | |||
| 24 | clocks::Clocks::new(p.CLOCK) | ||
| 25 | .enable_ext_hfosc() | ||
| 26 | .set_lfclk_src_external(clocks::LfOscConfiguration::NoExternalNoBypass) | ||
| 27 | .start_lfclk(); | ||
| 28 | |||
| 29 | let irq = interrupt::take!(RTC1); | ||
| 30 | |||
| 31 | let rtc: &'static _ = unsafe { | ||
| 32 | let ptr = RTC.as_mut_ptr(); | ||
| 33 | ptr.write(rtc::RTC::new(p.RTC1, irq)); | ||
| 34 | &*ptr | ||
| 35 | }; | ||
| 36 | |||
| 37 | let alarm = rtc.alarm0(); | ||
| 38 | |||
| 39 | rtc.start(); | ||
| 40 | |||
| 41 | alarm.set_callback(|| info!("ALARM TRIGGERED")); | ||
| 42 | alarm.set(53719); | ||
| 43 | |||
| 44 | info!("initialized!"); | ||
| 45 | |||
| 46 | let mut val = 0; | ||
| 47 | let mut printval = 0; | ||
| 48 | loop { | ||
| 49 | let val2 = rtc.now(); | ||
| 50 | if val2 < val { | ||
| 51 | info!( | ||
| 52 | "timer ran backwards! {:u32} -> {:u32}", | ||
| 53 | val as u32, val2 as u32 | ||
| 54 | ); | ||
| 55 | } | ||
| 56 | val = val2; | ||
| 57 | |||
| 58 | if val > printval + 32768 { | ||
| 59 | info!("tick {:u32}", val as u32); | ||
| 60 | printval = val; | ||
| 61 | } | ||
| 62 | } | ||
| 63 | } | ||
diff --git a/examples/src/bin/uart.rs b/examples/src/bin/uart.rs deleted file mode 100644 index 107936686..000000000 --- a/examples/src/bin/uart.rs +++ /dev/null | |||
| @@ -1,107 +0,0 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | #![feature(type_alias_impl_trait)] | ||
| 4 | |||
| 5 | #[path = "../example_common.rs"] | ||
| 6 | mod example_common; | ||
| 7 | use example_common::*; | ||
| 8 | |||
| 9 | use cortex_m_rt::entry; | ||
| 10 | use defmt::panic; | ||
| 11 | use embassy::executor::{task, Executor}; | ||
| 12 | use embassy::time::{Duration, Timer}; | ||
| 13 | use embassy::util::Forever; | ||
| 14 | use embassy_nrf::{interrupt, pac, rtc, uarte}; | ||
| 15 | use futures::future::{select, Either}; | ||
| 16 | use nrf52840_hal::clocks; | ||
| 17 | use nrf52840_hal::gpio; | ||
| 18 | |||
| 19 | #[task] | ||
| 20 | async fn run(mut uart: uarte::Uarte<pac::UARTE0>) { | ||
| 21 | info!("uarte initialized!"); | ||
| 22 | |||
| 23 | // Message must be in SRAM | ||
| 24 | let mut buf = [0; 8]; | ||
| 25 | buf.copy_from_slice(b"Hello!\r\n"); | ||
| 26 | |||
| 27 | uart.send(&buf).await; | ||
| 28 | info!("wrote hello in uart!"); | ||
| 29 | |||
| 30 | info!("reading..."); | ||
| 31 | loop { | ||
| 32 | let received = match select( | ||
| 33 | uart.receive(&mut buf), | ||
| 34 | Timer::after(Duration::from_millis(10)), | ||
| 35 | ) | ||
| 36 | .await | ||
| 37 | { | ||
| 38 | Either::Left((buf, _)) => buf, | ||
| 39 | Either::Right((_, read)) => { | ||
| 40 | let (buf, n) = read.stop().await; | ||
| 41 | &buf[..n] | ||
| 42 | } | ||
| 43 | }; | ||
| 44 | |||
| 45 | if received.len() > 0 { | ||
| 46 | info!("read done, got {:[u8]}", received); | ||
| 47 | |||
| 48 | // Echo back received data | ||
| 49 | uart.send(received).await; | ||
| 50 | } | ||
| 51 | } | ||
| 52 | } | ||
| 53 | |||
| 54 | static RTC: Forever<rtc::RTC<pac::RTC1>> = Forever::new(); | ||
| 55 | static ALARM: Forever<rtc::Alarm<pac::RTC1>> = Forever::new(); | ||
| 56 | static EXECUTOR: Forever<Executor> = Forever::new(); | ||
| 57 | |||
| 58 | #[entry] | ||
| 59 | fn main() -> ! { | ||
| 60 | info!("Hello World!"); | ||
| 61 | |||
| 62 | let p = unwrap!(embassy_nrf::pac::Peripherals::take()); | ||
| 63 | |||
| 64 | clocks::Clocks::new(p.CLOCK) | ||
| 65 | .enable_ext_hfosc() | ||
| 66 | .set_lfclk_src_external(clocks::LfOscConfiguration::NoExternalNoBypass) | ||
| 67 | .start_lfclk(); | ||
| 68 | |||
| 69 | let rtc = RTC.put(rtc::RTC::new(p.RTC1, interrupt::take!(RTC1))); | ||
| 70 | rtc.start(); | ||
| 71 | |||
| 72 | unsafe { embassy::time::set_clock(rtc) }; | ||
| 73 | |||
| 74 | let alarm = ALARM.put(rtc.alarm0()); | ||
| 75 | let executor = EXECUTOR.put(Executor::new_with_alarm(alarm, cortex_m::asm::sev)); | ||
| 76 | |||
| 77 | // Init UART | ||
| 78 | let port0 = gpio::p0::Parts::new(p.P0); | ||
| 79 | |||
| 80 | let pins = uarte::Pins { | ||
| 81 | rxd: port0.p0_08.into_floating_input().degrade(), | ||
| 82 | txd: port0 | ||
| 83 | .p0_06 | ||
| 84 | .into_push_pull_output(gpio::Level::Low) | ||
| 85 | .degrade(), | ||
| 86 | cts: None, | ||
| 87 | rts: None, | ||
| 88 | }; | ||
| 89 | |||
| 90 | // NOTE(unsafe): Safe becasue we do not use `mem::forget` anywhere. | ||
| 91 | let uart = unsafe { | ||
| 92 | uarte::Uarte::new( | ||
| 93 | p.UARTE0, | ||
| 94 | interrupt::take!(UARTE0_UART0), | ||
| 95 | pins, | ||
| 96 | uarte::Parity::EXCLUDED, | ||
| 97 | uarte::Baudrate::BAUD115200, | ||
| 98 | ) | ||
| 99 | }; | ||
| 100 | |||
| 101 | unwrap!(executor.spawn(run(uart))); | ||
| 102 | |||
| 103 | loop { | ||
| 104 | executor.run(); | ||
| 105 | cortex_m::asm::wfe(); | ||
| 106 | } | ||
| 107 | } | ||
diff --git a/examples/src/example_common.rs b/examples/src/example_common.rs deleted file mode 100644 index 60bb02082..000000000 --- a/examples/src/example_common.rs +++ /dev/null | |||
| @@ -1,18 +0,0 @@ | |||
| 1 | #![macro_use] | ||
| 2 | |||
| 3 | use defmt_rtt as _; // global logger | ||
| 4 | use nrf52840_hal as _; | ||
| 5 | use panic_probe as _; | ||
| 6 | |||
| 7 | pub use defmt::*; | ||
| 8 | |||
| 9 | use core::sync::atomic::{AtomicUsize, Ordering}; | ||
| 10 | |||
| 11 | #[defmt::timestamp] | ||
| 12 | fn timestamp() -> u64 { | ||
| 13 | static COUNT: AtomicUsize = AtomicUsize::new(0); | ||
| 14 | // NOTE(no-CAS) `timestamps` runs with interrupts disabled | ||
| 15 | let n = COUNT.load(Ordering::Relaxed); | ||
| 16 | COUNT.store(n + 1, Ordering::Relaxed); | ||
| 17 | n as u64 | ||
| 18 | } | ||
