From f8afc3c8828c334baaa399f73764ba45a3f69799 Mon Sep 17 00:00:00 2001 From: Dominik Boehi Date: Sun, 8 Jan 2023 15:36:35 +0100 Subject: [PATCH 1/4] Add samples for nrf5340 --- examples/nrf5340/.cargo/config.toml | 9 +++ examples/nrf5340/Cargo.toml | 64 ++++++++++++++++++ examples/nrf5340/build.rs | 35 ++++++++++ examples/nrf5340/memory.x | 7 ++ examples/nrf5340/src/bin/awaitable_timer.rs | 26 ++++++++ examples/nrf5340/src/bin/blinky.rs | 21 ++++++ examples/nrf5340/src/bin/buffered_uart.rs | 57 ++++++++++++++++ examples/nrf5340/src/bin/channel.rs | 43 ++++++++++++ .../src/bin/channel_sender_receiver.rs | 50 ++++++++++++++ examples/nrf5340/src/bin/gpiote_channel.rs | 66 +++++++++++++++++++ examples/nrf5340/src/bin/gpiote_port.rs | 34 ++++++++++ examples/nrf5340/src/bin/uart.rs | 35 ++++++++++ examples/nrf5340/src/bin/uart_idle.rs | 35 ++++++++++ examples/nrf5340/src/bin/uart_split.rs | 60 +++++++++++++++++ 14 files changed, 542 insertions(+) create mode 100644 examples/nrf5340/.cargo/config.toml create mode 100644 examples/nrf5340/Cargo.toml create mode 100644 examples/nrf5340/build.rs create mode 100644 examples/nrf5340/memory.x create mode 100644 examples/nrf5340/src/bin/awaitable_timer.rs create mode 100644 examples/nrf5340/src/bin/blinky.rs create mode 100644 examples/nrf5340/src/bin/buffered_uart.rs create mode 100644 examples/nrf5340/src/bin/channel.rs create mode 100644 examples/nrf5340/src/bin/channel_sender_receiver.rs create mode 100644 examples/nrf5340/src/bin/gpiote_channel.rs create mode 100644 examples/nrf5340/src/bin/gpiote_port.rs create mode 100644 examples/nrf5340/src/bin/uart.rs create mode 100644 examples/nrf5340/src/bin/uart_idle.rs create mode 100644 examples/nrf5340/src/bin/uart_split.rs diff --git a/examples/nrf5340/.cargo/config.toml b/examples/nrf5340/.cargo/config.toml new file mode 100644 index 00000000..ff0879c8 --- /dev/null +++ b/examples/nrf5340/.cargo/config.toml @@ -0,0 +1,9 @@ +[target.'cfg(all(target_arch = "arm", target_os = "none"))'] +# replace nRF5340_xxAA with your chip as listed in `probe-run --list-chips` +runner = "probe-run --chip nRF5340_xxAA" + +[build] +target = "thumbv8m.main-none-eabihf" + +[env] +DEFMT_LOG = "trace" diff --git a/examples/nrf5340/Cargo.toml b/examples/nrf5340/Cargo.toml new file mode 100644 index 00000000..03485711 --- /dev/null +++ b/examples/nrf5340/Cargo.toml @@ -0,0 +1,64 @@ +[package] +edition = "2021" +name = "embassy-nrf-examples" +version = "0.1.0" +license = "MIT OR Apache-2.0" + +[features] +default = ["nightly"] +nightly = [ + "embassy-executor/nightly", + "embassy-nrf/nightly", + "embassy-net/nightly", + "embassy-nrf/unstable-traits", + "embassy-usb", + "embedded-io/async", + "embassy-net", +] + +[dependencies] +embassy-futures = { version = "0.1.0", path = "../../embassy-futures" } +embassy-sync = { version = "0.1.0", path = "../../embassy-sync", features = [ + "defmt", +] } +embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = [ + "defmt", + "integrated-timers", +] } +embassy-time = { version = "0.1.0", path = "../../embassy-time", features = [ + "defmt", + "defmt-timestamp-uptime", +] } +embassy-nrf = { version = "0.1.0", path = "../../embassy-nrf", features = [ + "defmt", + "nrf5340-app-s", + "time-driver-rtc1", + "gpiote", + "unstable-pac", +] } +embassy-net = { version = "0.1.0", path = "../../embassy-net", features = [ + "defmt", + "tcp", + "dhcpv4", + "medium-ethernet", +], optional = true } +embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = [ + "defmt", +], optional = true } +embedded-io = "0.4.0" + + +defmt = "0.3" +defmt-rtt = "0.4" + +static_cell = "1.0" +cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] } +cortex-m-rt = "0.7.0" +panic-probe = { version = "0.3", features = ["print-defmt"] } +futures = { version = "0.3.17", default-features = false, features = [ + "async-await", +] } +rand = { version = "0.8.4", default-features = false } +embedded-storage = "0.3.0" +usbd-hid = "0.6.0" +serde = { version = "1.0.136", default-features = false } diff --git a/examples/nrf5340/build.rs b/examples/nrf5340/build.rs new file mode 100644 index 00000000..30691aa9 --- /dev/null +++ b/examples/nrf5340/build.rs @@ -0,0 +1,35 @@ +//! This build script copies the `memory.x` file from the crate root into +//! a directory where the linker can always find it at build time. +//! For many projects this is optional, as the linker always searches the +//! project root directory -- wherever `Cargo.toml` is. However, if you +//! are using a workspace or have a more complicated build setup, this +//! build script becomes required. Additionally, by requesting that +//! Cargo re-run the build script whenever `memory.x` is changed, +//! updating `memory.x` ensures a rebuild of the application with the +//! new memory settings. + +use std::env; +use std::fs::File; +use std::io::Write; +use std::path::PathBuf; + +fn main() { + // Put `memory.x` in our output directory and ensure it's + // on the linker search path. + let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap()); + File::create(out.join("memory.x")) + .unwrap() + .write_all(include_bytes!("memory.x")) + .unwrap(); + println!("cargo:rustc-link-search={}", out.display()); + + // By default, Cargo will re-run a build script whenever + // any file in the project changes. By specifying `memory.x` + // here, we ensure the build script is only re-run when + // `memory.x` is changed. + println!("cargo:rerun-if-changed=memory.x"); + + println!("cargo:rustc-link-arg-bins=--nmagic"); + println!("cargo:rustc-link-arg-bins=-Tlink.x"); + println!("cargo:rustc-link-arg-bins=-Tdefmt.x"); +} diff --git a/examples/nrf5340/memory.x b/examples/nrf5340/memory.x new file mode 100644 index 00000000..a122dc24 --- /dev/null +++ b/examples/nrf5340/memory.x @@ -0,0 +1,7 @@ +MEMORY +{ + /* NOTE 1 K = 1 KiBi = 1024 bytes */ + /* These values correspond to the NRF5340 */ + FLASH : ORIGIN = 0x00000000, LENGTH = 1024K + RAM : ORIGIN = 0x20000000, LENGTH = 256K +} diff --git a/examples/nrf5340/src/bin/awaitable_timer.rs b/examples/nrf5340/src/bin/awaitable_timer.rs new file mode 100644 index 00000000..b32af236 --- /dev/null +++ b/examples/nrf5340/src/bin/awaitable_timer.rs @@ -0,0 +1,26 @@ +#![no_std] +#![no_main] +#![feature(type_alias_impl_trait)] + +use defmt::info; +use embassy_executor::Spawner; +use embassy_nrf::interrupt; +use embassy_nrf::timer::Timer; +use {defmt_rtt as _, panic_probe as _}; + +#[embassy_executor::main] +async fn main(_spawner: Spawner) { + let p = embassy_nrf::init(Default::default()); + let mut t = Timer::new_awaitable(p.TIMER0, interrupt::take!(TIMER0)); + // default frequency is 1MHz, so this triggers every second + t.cc(0).write(1_000_000); + // clear the timer value on cc[0] compare match + t.cc(0).short_compare_clear(); + t.start(); + + loop { + // wait for compare match + t.cc(0).wait().await; + info!("hardware timer tick"); + } +} diff --git a/examples/nrf5340/src/bin/blinky.rs b/examples/nrf5340/src/bin/blinky.rs new file mode 100644 index 00000000..3422cedf --- /dev/null +++ b/examples/nrf5340/src/bin/blinky.rs @@ -0,0 +1,21 @@ +#![no_std] +#![no_main] +#![feature(type_alias_impl_trait)] + +use embassy_executor::Spawner; +use embassy_nrf::gpio::{Level, Output, OutputDrive}; +use embassy_time::{Duration, Timer}; +use {defmt_rtt as _, panic_probe as _}; + +#[embassy_executor::main] +async fn main(_spawner: Spawner) { + let p = embassy_nrf::init(Default::default()); + let mut led = Output::new(p.P0_28, Level::Low, OutputDrive::Standard); + + loop { + led.set_high(); + Timer::after(Duration::from_millis(300)).await; + led.set_low(); + Timer::after(Duration::from_millis(300)).await; + } +} diff --git a/examples/nrf5340/src/bin/buffered_uart.rs b/examples/nrf5340/src/bin/buffered_uart.rs new file mode 100644 index 00000000..25a0ca23 --- /dev/null +++ b/examples/nrf5340/src/bin/buffered_uart.rs @@ -0,0 +1,57 @@ +#![no_std] +#![no_main] +#![feature(type_alias_impl_trait)] + +use defmt::*; +use embassy_executor::Spawner; +use embassy_nrf::buffered_uarte::{BufferedUarte, State}; +use embassy_nrf::{interrupt, uarte}; +use embedded_io::asynch::{BufRead, Write}; +use futures::pin_mut; +use {defmt_rtt as _, panic_probe as _}; + +#[embassy_executor::main] +async fn main(_spawner: Spawner) { + let p = embassy_nrf::init(Default::default()); + let mut config = uarte::Config::default(); + config.parity = uarte::Parity::EXCLUDED; + config.baudrate = uarte::Baudrate::BAUD115200; + + let mut tx_buffer = [0u8; 4096]; + let mut rx_buffer = [0u8; 4096]; + + let irq = interrupt::take!(SERIAL0); + let mut state = State::new(); + // Please note - important to have hardware flow control (https://github.com/embassy-rs/embassy/issues/536) + let u = BufferedUarte::new( + &mut state, + p.UARTETWISPI0, + p.TIMER0, + p.PPI_CH0, + p.PPI_CH1, + irq, + p.P0_08, + p.P0_06, + p.P0_07, + p.P0_05, + config, + &mut rx_buffer, + &mut tx_buffer, + ); + pin_mut!(u); + + info!("uarte initialized!"); + + unwrap!(u.write_all(b"Hello!\r\n").await); + info!("wrote hello in uart!"); + + loop { + info!("reading..."); + let buf = unwrap!(u.fill_buf().await); + info!("read done, got {}", buf); + + // Read bytes have to be explicitly consumed, otherwise fill_buf() will return them again + let n = buf.len(); + u.consume(n); + } +} diff --git a/examples/nrf5340/src/bin/channel.rs b/examples/nrf5340/src/bin/channel.rs new file mode 100644 index 00000000..425d4305 --- /dev/null +++ b/examples/nrf5340/src/bin/channel.rs @@ -0,0 +1,43 @@ +#![no_std] +#![no_main] +#![feature(type_alias_impl_trait)] + +use defmt::unwrap; +use embassy_executor::Spawner; +use embassy_nrf::gpio::{Level, Output, OutputDrive}; +use embassy_sync::blocking_mutex::raw::ThreadModeRawMutex; +use embassy_sync::channel::Channel; +use embassy_time::{Duration, Timer}; +use {defmt_rtt as _, panic_probe as _}; + +enum LedState { + On, + Off, +} + +static CHANNEL: Channel = Channel::new(); + +#[embassy_executor::task] +async fn my_task() { + loop { + CHANNEL.send(LedState::On).await; + Timer::after(Duration::from_secs(1)).await; + CHANNEL.send(LedState::Off).await; + Timer::after(Duration::from_secs(1)).await; + } +} + +#[embassy_executor::main] +async fn main(spawner: Spawner) { + let p = embassy_nrf::init(Default::default()); + let mut led = Output::new(p.P0_28, Level::Low, OutputDrive::Standard); + + unwrap!(spawner.spawn(my_task())); + + loop { + match CHANNEL.recv().await { + LedState::On => led.set_high(), + LedState::Off => led.set_low(), + } + } +} diff --git a/examples/nrf5340/src/bin/channel_sender_receiver.rs b/examples/nrf5340/src/bin/channel_sender_receiver.rs new file mode 100644 index 00000000..9628c052 --- /dev/null +++ b/examples/nrf5340/src/bin/channel_sender_receiver.rs @@ -0,0 +1,50 @@ +#![no_std] +#![no_main] +#![feature(type_alias_impl_trait)] + +use defmt::unwrap; +use embassy_executor::Spawner; +use embassy_nrf::gpio::{AnyPin, Level, Output, OutputDrive, Pin}; +use embassy_sync::blocking_mutex::raw::NoopRawMutex; +use embassy_sync::channel::{Channel, Receiver, Sender}; +use embassy_time::{Duration, Timer}; +use static_cell::StaticCell; +use {defmt_rtt as _, panic_probe as _}; + +enum LedState { + On, + Off, +} + +static CHANNEL: StaticCell> = StaticCell::new(); + +#[embassy_executor::task] +async fn send_task(sender: Sender<'static, NoopRawMutex, LedState, 1>) { + loop { + sender.send(LedState::On).await; + Timer::after(Duration::from_secs(1)).await; + sender.send(LedState::Off).await; + Timer::after(Duration::from_secs(1)).await; + } +} + +#[embassy_executor::task] +async fn recv_task(led: AnyPin, receiver: Receiver<'static, NoopRawMutex, LedState, 1>) { + let mut led = Output::new(led, Level::Low, OutputDrive::Standard); + + loop { + match receiver.recv().await { + LedState::On => led.set_high(), + LedState::Off => led.set_low(), + } + } +} + +#[embassy_executor::main] +async fn main(spawner: Spawner) { + let p = embassy_nrf::init(Default::default()); + let channel = CHANNEL.init(Channel::new()); + + unwrap!(spawner.spawn(send_task(channel.sender()))); + unwrap!(spawner.spawn(recv_task(p.P0_28.degrade(), channel.receiver()))); +} diff --git a/examples/nrf5340/src/bin/gpiote_channel.rs b/examples/nrf5340/src/bin/gpiote_channel.rs new file mode 100644 index 00000000..ceab1194 --- /dev/null +++ b/examples/nrf5340/src/bin/gpiote_channel.rs @@ -0,0 +1,66 @@ +#![no_std] +#![no_main] +#![feature(type_alias_impl_trait)] + +use defmt::info; +use embassy_executor::Spawner; +use embassy_nrf::gpio::{Input, Pull}; +use embassy_nrf::gpiote::{InputChannel, InputChannelPolarity}; +use {defmt_rtt as _, panic_probe as _}; + +#[embassy_executor::main] +async fn main(_spawner: Spawner) { + let p = embassy_nrf::init(Default::default()); + info!("Starting!"); + + let ch1 = InputChannel::new( + p.GPIOTE_CH0, + Input::new(p.P0_23, Pull::Up), + InputChannelPolarity::HiToLo, + ); + let ch2 = InputChannel::new( + p.GPIOTE_CH1, + Input::new(p.P0_24, Pull::Up), + InputChannelPolarity::LoToHi, + ); + let ch3 = InputChannel::new( + p.GPIOTE_CH2, + Input::new(p.P0_08, Pull::Up), + InputChannelPolarity::Toggle, + ); + let ch4 = InputChannel::new( + p.GPIOTE_CH3, + Input::new(p.P0_09, Pull::Up), + InputChannelPolarity::Toggle, + ); + + let button1 = async { + loop { + ch1.wait().await; + info!("Button 1 pressed") + } + }; + + let button2 = async { + loop { + ch2.wait().await; + info!("Button 2 released") + } + }; + + let button3 = async { + loop { + ch3.wait().await; + info!("Button 3 toggled") + } + }; + + let button4 = async { + loop { + ch4.wait().await; + info!("Button 4 toggled") + } + }; + + futures::join!(button1, button2, button3, button4); +} diff --git a/examples/nrf5340/src/bin/gpiote_port.rs b/examples/nrf5340/src/bin/gpiote_port.rs new file mode 100644 index 00000000..0cc911ad --- /dev/null +++ b/examples/nrf5340/src/bin/gpiote_port.rs @@ -0,0 +1,34 @@ +#![no_std] +#![no_main] +#![feature(type_alias_impl_trait)] + +use defmt::{info, unwrap}; +use embassy_executor::Spawner; +use embassy_nrf::gpio::{AnyPin, Input, Pin as _, Pull}; +use {defmt_rtt as _, panic_probe as _}; + +#[embassy_executor::task(pool_size = 4)] +async fn button_task(n: usize, mut pin: Input<'static, AnyPin>) { + loop { + pin.wait_for_low().await; + info!("Button {:?} pressed!", n); + pin.wait_for_high().await; + info!("Button {:?} released!", n); + } +} + +#[embassy_executor::main] +async fn main(spawner: Spawner) { + let p = embassy_nrf::init(Default::default()); + info!("Starting!"); + + let btn1 = Input::new(p.P0_23.degrade(), Pull::Up); + let btn2 = Input::new(p.P0_24.degrade(), Pull::Up); + let btn3 = Input::new(p.P0_08.degrade(), Pull::Up); + let btn4 = Input::new(p.P0_09.degrade(), Pull::Up); + + unwrap!(spawner.spawn(button_task(1, btn1))); + unwrap!(spawner.spawn(button_task(2, btn2))); + unwrap!(spawner.spawn(button_task(3, btn3))); + unwrap!(spawner.spawn(button_task(4, btn4))); +} diff --git a/examples/nrf5340/src/bin/uart.rs b/examples/nrf5340/src/bin/uart.rs new file mode 100644 index 00000000..1db45057 --- /dev/null +++ b/examples/nrf5340/src/bin/uart.rs @@ -0,0 +1,35 @@ +#![no_std] +#![no_main] +#![feature(type_alias_impl_trait)] + +use defmt::*; +use embassy_executor::Spawner; +use embassy_nrf::{interrupt, uarte}; +use {defmt_rtt as _, panic_probe as _}; + +#[embassy_executor::main] +async fn main(_spawner: Spawner) { + let p = embassy_nrf::init(Default::default()); + let mut config = uarte::Config::default(); + config.parity = uarte::Parity::EXCLUDED; + config.baudrate = uarte::Baudrate::BAUD115200; + + let irq = interrupt::take!(SERIAL0); + let mut uart = uarte::Uarte::new(p.UARTETWISPI0, irq, p.P0_08, p.P0_06, config); + + info!("uarte initialized!"); + + // Message must be in SRAM + let mut buf = [0; 8]; + buf.copy_from_slice(b"Hello!\r\n"); + + unwrap!(uart.write(&buf).await); + info!("wrote hello in uart!"); + + loop { + info!("reading..."); + unwrap!(uart.read(&mut buf).await); + info!("writing..."); + unwrap!(uart.write(&buf).await); + } +} diff --git a/examples/nrf5340/src/bin/uart_idle.rs b/examples/nrf5340/src/bin/uart_idle.rs new file mode 100644 index 00000000..327fc4b2 --- /dev/null +++ b/examples/nrf5340/src/bin/uart_idle.rs @@ -0,0 +1,35 @@ +#![no_std] +#![no_main] +#![feature(type_alias_impl_trait)] + +use defmt::*; +use embassy_executor::Spawner; +use embassy_nrf::{interrupt, uarte}; +use {defmt_rtt as _, panic_probe as _}; + +#[embassy_executor::main] +async fn main(_spawner: Spawner) { + let p = embassy_nrf::init(Default::default()); + let mut config = uarte::Config::default(); + config.parity = uarte::Parity::EXCLUDED; + config.baudrate = uarte::Baudrate::BAUD115200; + + let irq = interrupt::take!(SERIAL0); + let uart = uarte::Uarte::new(p.UARTETWISPI0, irq, p.P0_08, p.P0_06, config); + let (mut tx, mut rx) = uart.split_with_idle(p.TIMER0, p.PPI_CH0, p.PPI_CH1); + + info!("uarte initialized!"); + + // Message must be in SRAM + let mut buf = [0; 8]; + buf.copy_from_slice(b"Hello!\r\n"); + + unwrap!(tx.write(&buf).await); + info!("wrote hello in uart!"); + + loop { + info!("reading..."); + let n = unwrap!(rx.read_until_idle(&mut buf).await); + info!("got {} bytes", n); + } +} diff --git a/examples/nrf5340/src/bin/uart_split.rs b/examples/nrf5340/src/bin/uart_split.rs new file mode 100644 index 00000000..1bff382f --- /dev/null +++ b/examples/nrf5340/src/bin/uart_split.rs @@ -0,0 +1,60 @@ +#![no_std] +#![no_main] +#![feature(type_alias_impl_trait)] + +use defmt::*; +use embassy_executor::Spawner; +use embassy_nrf::peripherals::UARTETWISPI0; +use embassy_nrf::uarte::UarteRx; +use embassy_nrf::{interrupt, uarte}; +use embassy_sync::blocking_mutex::raw::ThreadModeRawMutex; +use embassy_sync::channel::Channel; +use {defmt_rtt as _, panic_probe as _}; + +static CHANNEL: Channel = Channel::new(); + +#[embassy_executor::main] +async fn main(spawner: Spawner) { + let p = embassy_nrf::init(Default::default()); + let mut config = uarte::Config::default(); + config.parity = uarte::Parity::EXCLUDED; + config.baudrate = uarte::Baudrate::BAUD115200; + + let irq = interrupt::take!(SERIAL0); + let uart = uarte::Uarte::new(p.UARTETWISPI0, irq, p.P0_08, p.P0_06, config); + let (mut tx, rx) = uart.split(); + + info!("uarte initialized!"); + + // Spawn a task responsible purely for reading + + unwrap!(spawner.spawn(reader(rx))); + + // Message must be in SRAM + { + let mut buf = [0; 23]; + buf.copy_from_slice(b"Type 8 chars to echo!\r\n"); + + unwrap!(tx.write(&buf).await); + info!("wrote hello in uart!"); + } + + // Continue reading in this main task and write + // back out the buffer we receive from the read + // task. + loop { + let buf = CHANNEL.recv().await; + info!("writing..."); + unwrap!(tx.write(&buf).await); + } +} + +#[embassy_executor::task] +async fn reader(mut rx: UarteRx<'static, UARTETWISPI0>) { + let mut buf = [0; 8]; + loop { + info!("reading..."); + unwrap!(rx.read(&mut buf).await); + CHANNEL.send(buf).await; + } +} From 401185b1d95a2519ee94e5d5654cc9325fe85eec Mon Sep 17 00:00:00 2001 From: Dominik Boehi Date: Sun, 8 Jan 2023 16:25:51 +0100 Subject: [PATCH 2/4] Change UART pins for nRF5340 DK --- examples/nrf5340/src/bin/uart.rs | 2 +- examples/nrf5340/src/bin/uart_split.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/nrf5340/src/bin/uart.rs b/examples/nrf5340/src/bin/uart.rs index 1db45057..0f2b7b1e 100644 --- a/examples/nrf5340/src/bin/uart.rs +++ b/examples/nrf5340/src/bin/uart.rs @@ -15,7 +15,7 @@ async fn main(_spawner: Spawner) { config.baudrate = uarte::Baudrate::BAUD115200; let irq = interrupt::take!(SERIAL0); - let mut uart = uarte::Uarte::new(p.UARTETWISPI0, irq, p.P0_08, p.P0_06, config); + let mut uart = uarte::Uarte::new(p.UARTETWISPI0, irq, p.P1_00, p.P1_01, config); info!("uarte initialized!"); diff --git a/examples/nrf5340/src/bin/uart_split.rs b/examples/nrf5340/src/bin/uart_split.rs index 1bff382f..0bbbfeaa 100644 --- a/examples/nrf5340/src/bin/uart_split.rs +++ b/examples/nrf5340/src/bin/uart_split.rs @@ -21,7 +21,7 @@ async fn main(spawner: Spawner) { config.baudrate = uarte::Baudrate::BAUD115200; let irq = interrupt::take!(SERIAL0); - let uart = uarte::Uarte::new(p.UARTETWISPI0, irq, p.P0_08, p.P0_06, config); + let uart = uarte::Uarte::new(p.UARTETWISPI0, irq, p.P1_00, p.P1_01, config); let (mut tx, rx) = uart.split(); info!("uarte initialized!"); From 0a27b6cedb52453123190671f294bbd34918e09a Mon Sep 17 00:00:00 2001 From: Dominik Boehi Date: Mon, 9 Jan 2023 22:29:58 +0100 Subject: [PATCH 3/4] Rename examples/nrf to examples/nrf52840 --- README.md | 7 ++++--- ci.sh | 3 ++- ci_stable.sh | 2 +- docs/modules/ROOT/pages/getting_started.adoc | 2 +- examples/{nrf => nrf52840}/.cargo/config.toml | 0 examples/{nrf => nrf52840}/Cargo.toml | 0 examples/{nrf => nrf52840}/build.rs | 0 examples/{nrf => nrf52840}/memory.x | 0 examples/{nrf => nrf52840}/src/bin/awaitable_timer.rs | 0 examples/{nrf => nrf52840}/src/bin/blinky.rs | 0 examples/{nrf => nrf52840}/src/bin/buffered_uart.rs | 0 examples/{nrf => nrf52840}/src/bin/channel.rs | 0 .../{nrf => nrf52840}/src/bin/channel_sender_receiver.rs | 0 .../{nrf => nrf52840}/src/bin/executor_fairness_test.rs | 0 examples/{nrf => nrf52840}/src/bin/gpiote_channel.rs | 0 examples/{nrf => nrf52840}/src/bin/gpiote_port.rs | 0 examples/{nrf => nrf52840}/src/bin/i2s_effect.rs | 0 examples/{nrf => nrf52840}/src/bin/i2s_monitor.rs | 0 examples/{nrf => nrf52840}/src/bin/i2s_waveform.rs | 0 examples/{nrf => nrf52840}/src/bin/lora_p2p_report.rs | 0 examples/{nrf => nrf52840}/src/bin/lora_p2p_sense.rs | 0 .../{nrf => nrf52840}/src/bin/manually_create_executor.rs | 0 examples/{nrf => nrf52840}/src/bin/multiprio.rs | 0 examples/{nrf => nrf52840}/src/bin/mutex.rs | 0 examples/{nrf => nrf52840}/src/bin/nvmc.rs | 0 examples/{nrf => nrf52840}/src/bin/pdm.rs | 0 examples/{nrf => nrf52840}/src/bin/ppi.rs | 0 examples/{nrf => nrf52840}/src/bin/pubsub.rs | 0 examples/{nrf => nrf52840}/src/bin/pwm.rs | 0 examples/{nrf => nrf52840}/src/bin/pwm_double_sequence.rs | 0 examples/{nrf => nrf52840}/src/bin/pwm_sequence.rs | 0 examples/{nrf => nrf52840}/src/bin/pwm_sequence_ppi.rs | 0 examples/{nrf => nrf52840}/src/bin/pwm_sequence_ws2812b.rs | 0 examples/{nrf => nrf52840}/src/bin/pwm_servo.rs | 0 examples/{nrf => nrf52840}/src/bin/qdec.rs | 0 examples/{nrf => nrf52840}/src/bin/qspi.rs | 0 examples/{nrf => nrf52840}/src/bin/qspi_lowpower.rs | 0 examples/{nrf => nrf52840}/src/bin/raw_spawn.rs | 0 examples/{nrf => nrf52840}/src/bin/rng.rs | 0 examples/{nrf => nrf52840}/src/bin/saadc.rs | 0 examples/{nrf => nrf52840}/src/bin/saadc_continuous.rs | 0 examples/{nrf => nrf52840}/src/bin/self_spawn.rs | 0 .../src/bin/self_spawn_current_executor.rs | 0 examples/{nrf => nrf52840}/src/bin/spim.rs | 0 examples/{nrf => nrf52840}/src/bin/spis.rs | 0 examples/{nrf => nrf52840}/src/bin/temp.rs | 0 examples/{nrf => nrf52840}/src/bin/timer.rs | 0 examples/{nrf => nrf52840}/src/bin/twim.rs | 0 examples/{nrf => nrf52840}/src/bin/twim_lowpower.rs | 0 examples/{nrf => nrf52840}/src/bin/twis.rs | 0 examples/{nrf => nrf52840}/src/bin/uart.rs | 0 examples/{nrf => nrf52840}/src/bin/uart_idle.rs | 0 examples/{nrf => nrf52840}/src/bin/uart_split.rs | 0 examples/{nrf => nrf52840}/src/bin/usb_ethernet.rs | 0 examples/{nrf => nrf52840}/src/bin/usb_hid_keyboard.rs | 0 examples/{nrf => nrf52840}/src/bin/usb_hid_mouse.rs | 0 examples/{nrf => nrf52840}/src/bin/usb_serial.rs | 0 examples/{nrf => nrf52840}/src/bin/usb_serial_multitask.rs | 0 examples/{nrf => nrf52840}/src/bin/wdt.rs | 0 59 files changed, 8 insertions(+), 6 deletions(-) rename examples/{nrf => nrf52840}/.cargo/config.toml (100%) rename examples/{nrf => nrf52840}/Cargo.toml (100%) rename examples/{nrf => nrf52840}/build.rs (100%) rename examples/{nrf => nrf52840}/memory.x (100%) rename examples/{nrf => nrf52840}/src/bin/awaitable_timer.rs (100%) rename examples/{nrf => nrf52840}/src/bin/blinky.rs (100%) rename examples/{nrf => nrf52840}/src/bin/buffered_uart.rs (100%) rename examples/{nrf => nrf52840}/src/bin/channel.rs (100%) rename examples/{nrf => nrf52840}/src/bin/channel_sender_receiver.rs (100%) rename examples/{nrf => nrf52840}/src/bin/executor_fairness_test.rs (100%) rename examples/{nrf => nrf52840}/src/bin/gpiote_channel.rs (100%) rename examples/{nrf => nrf52840}/src/bin/gpiote_port.rs (100%) rename examples/{nrf => nrf52840}/src/bin/i2s_effect.rs (100%) rename examples/{nrf => nrf52840}/src/bin/i2s_monitor.rs (100%) rename examples/{nrf => nrf52840}/src/bin/i2s_waveform.rs (100%) rename examples/{nrf => nrf52840}/src/bin/lora_p2p_report.rs (100%) rename examples/{nrf => nrf52840}/src/bin/lora_p2p_sense.rs (100%) rename examples/{nrf => nrf52840}/src/bin/manually_create_executor.rs (100%) rename examples/{nrf => nrf52840}/src/bin/multiprio.rs (100%) rename examples/{nrf => nrf52840}/src/bin/mutex.rs (100%) rename examples/{nrf => nrf52840}/src/bin/nvmc.rs (100%) rename examples/{nrf => nrf52840}/src/bin/pdm.rs (100%) rename examples/{nrf => nrf52840}/src/bin/ppi.rs (100%) rename examples/{nrf => nrf52840}/src/bin/pubsub.rs (100%) rename examples/{nrf => nrf52840}/src/bin/pwm.rs (100%) rename examples/{nrf => nrf52840}/src/bin/pwm_double_sequence.rs (100%) rename examples/{nrf => nrf52840}/src/bin/pwm_sequence.rs (100%) rename examples/{nrf => nrf52840}/src/bin/pwm_sequence_ppi.rs (100%) rename examples/{nrf => nrf52840}/src/bin/pwm_sequence_ws2812b.rs (100%) rename examples/{nrf => nrf52840}/src/bin/pwm_servo.rs (100%) rename examples/{nrf => nrf52840}/src/bin/qdec.rs (100%) rename examples/{nrf => nrf52840}/src/bin/qspi.rs (100%) rename examples/{nrf => nrf52840}/src/bin/qspi_lowpower.rs (100%) rename examples/{nrf => nrf52840}/src/bin/raw_spawn.rs (100%) rename examples/{nrf => nrf52840}/src/bin/rng.rs (100%) rename examples/{nrf => nrf52840}/src/bin/saadc.rs (100%) rename examples/{nrf => nrf52840}/src/bin/saadc_continuous.rs (100%) rename examples/{nrf => nrf52840}/src/bin/self_spawn.rs (100%) rename examples/{nrf => nrf52840}/src/bin/self_spawn_current_executor.rs (100%) rename examples/{nrf => nrf52840}/src/bin/spim.rs (100%) rename examples/{nrf => nrf52840}/src/bin/spis.rs (100%) rename examples/{nrf => nrf52840}/src/bin/temp.rs (100%) rename examples/{nrf => nrf52840}/src/bin/timer.rs (100%) rename examples/{nrf => nrf52840}/src/bin/twim.rs (100%) rename examples/{nrf => nrf52840}/src/bin/twim_lowpower.rs (100%) rename examples/{nrf => nrf52840}/src/bin/twis.rs (100%) rename examples/{nrf => nrf52840}/src/bin/uart.rs (100%) rename examples/{nrf => nrf52840}/src/bin/uart_idle.rs (100%) rename examples/{nrf => nrf52840}/src/bin/uart_split.rs (100%) rename examples/{nrf => nrf52840}/src/bin/usb_ethernet.rs (100%) rename examples/{nrf => nrf52840}/src/bin/usb_hid_keyboard.rs (100%) rename examples/{nrf => nrf52840}/src/bin/usb_hid_mouse.rs (100%) rename examples/{nrf => nrf52840}/src/bin/usb_serial.rs (100%) rename examples/{nrf => nrf52840}/src/bin/usb_serial_multitask.rs (100%) rename examples/{nrf => nrf52840}/src/bin/wdt.rs (100%) diff --git a/README.md b/README.md index eaa91012..938f2f4a 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ Rust's async/await allows No more messing with hardware timers. embassy_time provides Instant, Duration and Timer types that are globally available and never overflow. - **Real-time ready** - -Tasks on the same async executor run cooperatively, but you can create multiple executors with different priorities, so that higher priority tasks preempt lower priority ones. See the example. +Tasks on the same async executor run cooperatively, but you can create multiple executors with different priorities, so that higher priority tasks preempt lower priority ones. See the example. - **Low-power ready** - Easily build devices with years of battery life. The async executor automatically puts the core to sleep when there's no work to do. Tasks are woken by interrupts, there is no busy-loop polling while waiting. @@ -87,7 +87,8 @@ async fn main(spawner: Spawner) { Examples are found in the `examples/` folder seperated by the chip manufacturer they are designed to run on. For example: -* `examples/nrf` run on the `nrf52840-dk` board (PCA10056) but should be easily adaptable to other nRF52 chips and boards. +* `examples/nrf52840` run on the `nrf52840-dk` board (PCA10056) but should be easily adaptable to other nRF52 chips and boards. +* `examples/nrf5340` run on the `nrf5340-dk` board (PCA10095). * `examples/stm32xx` for the various STM32 families. * `examples/rp` are for the RP2040 chip. * `examples/std` are designed to run locally on your PC. @@ -110,7 +111,7 @@ cargo install probe-run - Change directory to the sample's base directory. For example: ```bash -cd examples/nrf +cd examples/nrf52840 ``` - Run the example diff --git a/ci.sh b/ci.sh index f59f3f46..30e664a2 100755 --- a/ci.sh +++ b/ci.sh @@ -89,7 +89,8 @@ cargo batch \ --- build --release --manifest-path docs/modules/ROOT/examples/layer-by-layer/blinky-hal/Cargo.toml --target thumbv7em-none-eabi \ --- build --release --manifest-path docs/modules/ROOT/examples/layer-by-layer/blinky-irq/Cargo.toml --target thumbv7em-none-eabi \ --- build --release --manifest-path docs/modules/ROOT/examples/layer-by-layer/blinky-async/Cargo.toml --target thumbv7em-none-eabi \ - --- build --release --manifest-path examples/nrf/Cargo.toml --target thumbv7em-none-eabi --out-dir out/examples/nrf \ + --- build --release --manifest-path examples/nrf52840/Cargo.toml --target thumbv7em-none-eabi --out-dir out/examples/nrf52840 \ + --- build --release --manifest-path examples/nrf5340/Cargo.toml --target thumbv8m.main-none-eabihf --out-dir out/examples/nrf5340 \ --- build --release --manifest-path examples/rp/Cargo.toml --target thumbv6m-none-eabi --out-dir out/examples/rp \ --- build --release --manifest-path examples/stm32f0/Cargo.toml --target thumbv6m-none-eabi --out-dir out/examples/stm32f0 \ --- build --release --manifest-path examples/stm32f1/Cargo.toml --target thumbv7m-none-eabi --out-dir out/examples/stm32f1 \ diff --git a/ci_stable.sh b/ci_stable.sh index a1d507d7..60ddb659 100755 --- a/ci_stable.sh +++ b/ci_stable.sh @@ -65,5 +65,5 @@ cargo batch \ --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7m-none-eabi --features stm32l151cb-a,defmt,exti,time-driver-any,unstable-traits \ --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7m-none-eabi --features stm32f217zg,defmt,exti,time-driver-any \ --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7m-none-eabi --features stm32f217zg,defmt,exti,time-driver-any,unstable-traits \ - --- build --release --manifest-path examples/nrf/Cargo.toml --target thumbv7em-none-eabi --no-default-features --out-dir out/examples/nrf --bin raw_spawn \ + --- build --release --manifest-path examples/nrf52840/Cargo.toml --target thumbv7em-none-eabi --no-default-features --out-dir out/examples/nrf52840 --bin raw_spawn \ --- build --release --manifest-path examples/stm32l0/Cargo.toml --target thumbv6m-none-eabi --no-default-features --out-dir out/examples/stm32l0 --bin raw_spawn \ diff --git a/docs/modules/ROOT/pages/getting_started.adoc b/docs/modules/ROOT/pages/getting_started.adoc index f3492a3d..9015d784 100644 --- a/docs/modules/ROOT/pages/getting_started.adoc +++ b/docs/modules/ROOT/pages/getting_started.adoc @@ -45,7 +45,7 @@ You can run an example by opening a terminal and entering the following commands [source, bash] ---- -cd examples/nrf +cd examples/nrf52840 cargo run --bin blinky --release ---- diff --git a/examples/nrf/.cargo/config.toml b/examples/nrf52840/.cargo/config.toml similarity index 100% rename from examples/nrf/.cargo/config.toml rename to examples/nrf52840/.cargo/config.toml diff --git a/examples/nrf/Cargo.toml b/examples/nrf52840/Cargo.toml similarity index 100% rename from examples/nrf/Cargo.toml rename to examples/nrf52840/Cargo.toml diff --git a/examples/nrf/build.rs b/examples/nrf52840/build.rs similarity index 100% rename from examples/nrf/build.rs rename to examples/nrf52840/build.rs diff --git a/examples/nrf/memory.x b/examples/nrf52840/memory.x similarity index 100% rename from examples/nrf/memory.x rename to examples/nrf52840/memory.x diff --git a/examples/nrf/src/bin/awaitable_timer.rs b/examples/nrf52840/src/bin/awaitable_timer.rs similarity index 100% rename from examples/nrf/src/bin/awaitable_timer.rs rename to examples/nrf52840/src/bin/awaitable_timer.rs diff --git a/examples/nrf/src/bin/blinky.rs b/examples/nrf52840/src/bin/blinky.rs similarity index 100% rename from examples/nrf/src/bin/blinky.rs rename to examples/nrf52840/src/bin/blinky.rs diff --git a/examples/nrf/src/bin/buffered_uart.rs b/examples/nrf52840/src/bin/buffered_uart.rs similarity index 100% rename from examples/nrf/src/bin/buffered_uart.rs rename to examples/nrf52840/src/bin/buffered_uart.rs diff --git a/examples/nrf/src/bin/channel.rs b/examples/nrf52840/src/bin/channel.rs similarity index 100% rename from examples/nrf/src/bin/channel.rs rename to examples/nrf52840/src/bin/channel.rs diff --git a/examples/nrf/src/bin/channel_sender_receiver.rs b/examples/nrf52840/src/bin/channel_sender_receiver.rs similarity index 100% rename from examples/nrf/src/bin/channel_sender_receiver.rs rename to examples/nrf52840/src/bin/channel_sender_receiver.rs diff --git a/examples/nrf/src/bin/executor_fairness_test.rs b/examples/nrf52840/src/bin/executor_fairness_test.rs similarity index 100% rename from examples/nrf/src/bin/executor_fairness_test.rs rename to examples/nrf52840/src/bin/executor_fairness_test.rs diff --git a/examples/nrf/src/bin/gpiote_channel.rs b/examples/nrf52840/src/bin/gpiote_channel.rs similarity index 100% rename from examples/nrf/src/bin/gpiote_channel.rs rename to examples/nrf52840/src/bin/gpiote_channel.rs diff --git a/examples/nrf/src/bin/gpiote_port.rs b/examples/nrf52840/src/bin/gpiote_port.rs similarity index 100% rename from examples/nrf/src/bin/gpiote_port.rs rename to examples/nrf52840/src/bin/gpiote_port.rs diff --git a/examples/nrf/src/bin/i2s_effect.rs b/examples/nrf52840/src/bin/i2s_effect.rs similarity index 100% rename from examples/nrf/src/bin/i2s_effect.rs rename to examples/nrf52840/src/bin/i2s_effect.rs diff --git a/examples/nrf/src/bin/i2s_monitor.rs b/examples/nrf52840/src/bin/i2s_monitor.rs similarity index 100% rename from examples/nrf/src/bin/i2s_monitor.rs rename to examples/nrf52840/src/bin/i2s_monitor.rs diff --git a/examples/nrf/src/bin/i2s_waveform.rs b/examples/nrf52840/src/bin/i2s_waveform.rs similarity index 100% rename from examples/nrf/src/bin/i2s_waveform.rs rename to examples/nrf52840/src/bin/i2s_waveform.rs diff --git a/examples/nrf/src/bin/lora_p2p_report.rs b/examples/nrf52840/src/bin/lora_p2p_report.rs similarity index 100% rename from examples/nrf/src/bin/lora_p2p_report.rs rename to examples/nrf52840/src/bin/lora_p2p_report.rs diff --git a/examples/nrf/src/bin/lora_p2p_sense.rs b/examples/nrf52840/src/bin/lora_p2p_sense.rs similarity index 100% rename from examples/nrf/src/bin/lora_p2p_sense.rs rename to examples/nrf52840/src/bin/lora_p2p_sense.rs diff --git a/examples/nrf/src/bin/manually_create_executor.rs b/examples/nrf52840/src/bin/manually_create_executor.rs similarity index 100% rename from examples/nrf/src/bin/manually_create_executor.rs rename to examples/nrf52840/src/bin/manually_create_executor.rs diff --git a/examples/nrf/src/bin/multiprio.rs b/examples/nrf52840/src/bin/multiprio.rs similarity index 100% rename from examples/nrf/src/bin/multiprio.rs rename to examples/nrf52840/src/bin/multiprio.rs diff --git a/examples/nrf/src/bin/mutex.rs b/examples/nrf52840/src/bin/mutex.rs similarity index 100% rename from examples/nrf/src/bin/mutex.rs rename to examples/nrf52840/src/bin/mutex.rs diff --git a/examples/nrf/src/bin/nvmc.rs b/examples/nrf52840/src/bin/nvmc.rs similarity index 100% rename from examples/nrf/src/bin/nvmc.rs rename to examples/nrf52840/src/bin/nvmc.rs diff --git a/examples/nrf/src/bin/pdm.rs b/examples/nrf52840/src/bin/pdm.rs similarity index 100% rename from examples/nrf/src/bin/pdm.rs rename to examples/nrf52840/src/bin/pdm.rs diff --git a/examples/nrf/src/bin/ppi.rs b/examples/nrf52840/src/bin/ppi.rs similarity index 100% rename from examples/nrf/src/bin/ppi.rs rename to examples/nrf52840/src/bin/ppi.rs diff --git a/examples/nrf/src/bin/pubsub.rs b/examples/nrf52840/src/bin/pubsub.rs similarity index 100% rename from examples/nrf/src/bin/pubsub.rs rename to examples/nrf52840/src/bin/pubsub.rs diff --git a/examples/nrf/src/bin/pwm.rs b/examples/nrf52840/src/bin/pwm.rs similarity index 100% rename from examples/nrf/src/bin/pwm.rs rename to examples/nrf52840/src/bin/pwm.rs diff --git a/examples/nrf/src/bin/pwm_double_sequence.rs b/examples/nrf52840/src/bin/pwm_double_sequence.rs similarity index 100% rename from examples/nrf/src/bin/pwm_double_sequence.rs rename to examples/nrf52840/src/bin/pwm_double_sequence.rs diff --git a/examples/nrf/src/bin/pwm_sequence.rs b/examples/nrf52840/src/bin/pwm_sequence.rs similarity index 100% rename from examples/nrf/src/bin/pwm_sequence.rs rename to examples/nrf52840/src/bin/pwm_sequence.rs diff --git a/examples/nrf/src/bin/pwm_sequence_ppi.rs b/examples/nrf52840/src/bin/pwm_sequence_ppi.rs similarity index 100% rename from examples/nrf/src/bin/pwm_sequence_ppi.rs rename to examples/nrf52840/src/bin/pwm_sequence_ppi.rs diff --git a/examples/nrf/src/bin/pwm_sequence_ws2812b.rs b/examples/nrf52840/src/bin/pwm_sequence_ws2812b.rs similarity index 100% rename from examples/nrf/src/bin/pwm_sequence_ws2812b.rs rename to examples/nrf52840/src/bin/pwm_sequence_ws2812b.rs diff --git a/examples/nrf/src/bin/pwm_servo.rs b/examples/nrf52840/src/bin/pwm_servo.rs similarity index 100% rename from examples/nrf/src/bin/pwm_servo.rs rename to examples/nrf52840/src/bin/pwm_servo.rs diff --git a/examples/nrf/src/bin/qdec.rs b/examples/nrf52840/src/bin/qdec.rs similarity index 100% rename from examples/nrf/src/bin/qdec.rs rename to examples/nrf52840/src/bin/qdec.rs diff --git a/examples/nrf/src/bin/qspi.rs b/examples/nrf52840/src/bin/qspi.rs similarity index 100% rename from examples/nrf/src/bin/qspi.rs rename to examples/nrf52840/src/bin/qspi.rs diff --git a/examples/nrf/src/bin/qspi_lowpower.rs b/examples/nrf52840/src/bin/qspi_lowpower.rs similarity index 100% rename from examples/nrf/src/bin/qspi_lowpower.rs rename to examples/nrf52840/src/bin/qspi_lowpower.rs diff --git a/examples/nrf/src/bin/raw_spawn.rs b/examples/nrf52840/src/bin/raw_spawn.rs similarity index 100% rename from examples/nrf/src/bin/raw_spawn.rs rename to examples/nrf52840/src/bin/raw_spawn.rs diff --git a/examples/nrf/src/bin/rng.rs b/examples/nrf52840/src/bin/rng.rs similarity index 100% rename from examples/nrf/src/bin/rng.rs rename to examples/nrf52840/src/bin/rng.rs diff --git a/examples/nrf/src/bin/saadc.rs b/examples/nrf52840/src/bin/saadc.rs similarity index 100% rename from examples/nrf/src/bin/saadc.rs rename to examples/nrf52840/src/bin/saadc.rs diff --git a/examples/nrf/src/bin/saadc_continuous.rs b/examples/nrf52840/src/bin/saadc_continuous.rs similarity index 100% rename from examples/nrf/src/bin/saadc_continuous.rs rename to examples/nrf52840/src/bin/saadc_continuous.rs diff --git a/examples/nrf/src/bin/self_spawn.rs b/examples/nrf52840/src/bin/self_spawn.rs similarity index 100% rename from examples/nrf/src/bin/self_spawn.rs rename to examples/nrf52840/src/bin/self_spawn.rs diff --git a/examples/nrf/src/bin/self_spawn_current_executor.rs b/examples/nrf52840/src/bin/self_spawn_current_executor.rs similarity index 100% rename from examples/nrf/src/bin/self_spawn_current_executor.rs rename to examples/nrf52840/src/bin/self_spawn_current_executor.rs diff --git a/examples/nrf/src/bin/spim.rs b/examples/nrf52840/src/bin/spim.rs similarity index 100% rename from examples/nrf/src/bin/spim.rs rename to examples/nrf52840/src/bin/spim.rs diff --git a/examples/nrf/src/bin/spis.rs b/examples/nrf52840/src/bin/spis.rs similarity index 100% rename from examples/nrf/src/bin/spis.rs rename to examples/nrf52840/src/bin/spis.rs diff --git a/examples/nrf/src/bin/temp.rs b/examples/nrf52840/src/bin/temp.rs similarity index 100% rename from examples/nrf/src/bin/temp.rs rename to examples/nrf52840/src/bin/temp.rs diff --git a/examples/nrf/src/bin/timer.rs b/examples/nrf52840/src/bin/timer.rs similarity index 100% rename from examples/nrf/src/bin/timer.rs rename to examples/nrf52840/src/bin/timer.rs diff --git a/examples/nrf/src/bin/twim.rs b/examples/nrf52840/src/bin/twim.rs similarity index 100% rename from examples/nrf/src/bin/twim.rs rename to examples/nrf52840/src/bin/twim.rs diff --git a/examples/nrf/src/bin/twim_lowpower.rs b/examples/nrf52840/src/bin/twim_lowpower.rs similarity index 100% rename from examples/nrf/src/bin/twim_lowpower.rs rename to examples/nrf52840/src/bin/twim_lowpower.rs diff --git a/examples/nrf/src/bin/twis.rs b/examples/nrf52840/src/bin/twis.rs similarity index 100% rename from examples/nrf/src/bin/twis.rs rename to examples/nrf52840/src/bin/twis.rs diff --git a/examples/nrf/src/bin/uart.rs b/examples/nrf52840/src/bin/uart.rs similarity index 100% rename from examples/nrf/src/bin/uart.rs rename to examples/nrf52840/src/bin/uart.rs diff --git a/examples/nrf/src/bin/uart_idle.rs b/examples/nrf52840/src/bin/uart_idle.rs similarity index 100% rename from examples/nrf/src/bin/uart_idle.rs rename to examples/nrf52840/src/bin/uart_idle.rs diff --git a/examples/nrf/src/bin/uart_split.rs b/examples/nrf52840/src/bin/uart_split.rs similarity index 100% rename from examples/nrf/src/bin/uart_split.rs rename to examples/nrf52840/src/bin/uart_split.rs diff --git a/examples/nrf/src/bin/usb_ethernet.rs b/examples/nrf52840/src/bin/usb_ethernet.rs similarity index 100% rename from examples/nrf/src/bin/usb_ethernet.rs rename to examples/nrf52840/src/bin/usb_ethernet.rs diff --git a/examples/nrf/src/bin/usb_hid_keyboard.rs b/examples/nrf52840/src/bin/usb_hid_keyboard.rs similarity index 100% rename from examples/nrf/src/bin/usb_hid_keyboard.rs rename to examples/nrf52840/src/bin/usb_hid_keyboard.rs diff --git a/examples/nrf/src/bin/usb_hid_mouse.rs b/examples/nrf52840/src/bin/usb_hid_mouse.rs similarity index 100% rename from examples/nrf/src/bin/usb_hid_mouse.rs rename to examples/nrf52840/src/bin/usb_hid_mouse.rs diff --git a/examples/nrf/src/bin/usb_serial.rs b/examples/nrf52840/src/bin/usb_serial.rs similarity index 100% rename from examples/nrf/src/bin/usb_serial.rs rename to examples/nrf52840/src/bin/usb_serial.rs diff --git a/examples/nrf/src/bin/usb_serial_multitask.rs b/examples/nrf52840/src/bin/usb_serial_multitask.rs similarity index 100% rename from examples/nrf/src/bin/usb_serial_multitask.rs rename to examples/nrf52840/src/bin/usb_serial_multitask.rs diff --git a/examples/nrf/src/bin/wdt.rs b/examples/nrf52840/src/bin/wdt.rs similarity index 100% rename from examples/nrf/src/bin/wdt.rs rename to examples/nrf52840/src/bin/wdt.rs From 2baebabf4dd2abecfd08ca078ecf59060d5ad585 Mon Sep 17 00:00:00 2001 From: Dominik Boehi Date: Mon, 9 Jan 2023 22:57:40 +0100 Subject: [PATCH 4/4] Reduce amount of samples for nrf5340 --- .vscode/settings.json | 3 +- examples/nrf5340/src/bin/awaitable_timer.rs | 26 -------- examples/nrf5340/src/bin/buffered_uart.rs | 57 ------------------ examples/nrf5340/src/bin/channel.rs | 43 ------------- .../src/bin/channel_sender_receiver.rs | 50 ---------------- examples/nrf5340/src/bin/gpiote_port.rs | 34 ----------- examples/nrf5340/src/bin/uart_idle.rs | 35 ----------- examples/nrf5340/src/bin/uart_split.rs | 60 ------------------- 8 files changed, 2 insertions(+), 306 deletions(-) delete mode 100644 examples/nrf5340/src/bin/awaitable_timer.rs delete mode 100644 examples/nrf5340/src/bin/buffered_uart.rs delete mode 100644 examples/nrf5340/src/bin/channel.rs delete mode 100644 examples/nrf5340/src/bin/channel_sender_receiver.rs delete mode 100644 examples/nrf5340/src/bin/gpiote_port.rs delete mode 100644 examples/nrf5340/src/bin/uart_idle.rs delete mode 100644 examples/nrf5340/src/bin/uart_split.rs diff --git a/.vscode/settings.json b/.vscode/settings.json index 086f435d..402ed241 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -13,7 +13,8 @@ // Declare for the target you wish to develop // "embassy-executor/Cargo.toml", // "embassy-sync/Cargo.toml", - "examples/nrf/Cargo.toml", + "examples/nrf52840/Cargo.toml", + //"examples/nrf5340/Cargo.toml", // "examples/nrf-rtos-trace/Cargo.toml", // "examples/rp/Cargo.toml", // "examples/std/Cargo.toml", diff --git a/examples/nrf5340/src/bin/awaitable_timer.rs b/examples/nrf5340/src/bin/awaitable_timer.rs deleted file mode 100644 index b32af236..00000000 --- a/examples/nrf5340/src/bin/awaitable_timer.rs +++ /dev/null @@ -1,26 +0,0 @@ -#![no_std] -#![no_main] -#![feature(type_alias_impl_trait)] - -use defmt::info; -use embassy_executor::Spawner; -use embassy_nrf::interrupt; -use embassy_nrf::timer::Timer; -use {defmt_rtt as _, panic_probe as _}; - -#[embassy_executor::main] -async fn main(_spawner: Spawner) { - let p = embassy_nrf::init(Default::default()); - let mut t = Timer::new_awaitable(p.TIMER0, interrupt::take!(TIMER0)); - // default frequency is 1MHz, so this triggers every second - t.cc(0).write(1_000_000); - // clear the timer value on cc[0] compare match - t.cc(0).short_compare_clear(); - t.start(); - - loop { - // wait for compare match - t.cc(0).wait().await; - info!("hardware timer tick"); - } -} diff --git a/examples/nrf5340/src/bin/buffered_uart.rs b/examples/nrf5340/src/bin/buffered_uart.rs deleted file mode 100644 index 25a0ca23..00000000 --- a/examples/nrf5340/src/bin/buffered_uart.rs +++ /dev/null @@ -1,57 +0,0 @@ -#![no_std] -#![no_main] -#![feature(type_alias_impl_trait)] - -use defmt::*; -use embassy_executor::Spawner; -use embassy_nrf::buffered_uarte::{BufferedUarte, State}; -use embassy_nrf::{interrupt, uarte}; -use embedded_io::asynch::{BufRead, Write}; -use futures::pin_mut; -use {defmt_rtt as _, panic_probe as _}; - -#[embassy_executor::main] -async fn main(_spawner: Spawner) { - let p = embassy_nrf::init(Default::default()); - let mut config = uarte::Config::default(); - config.parity = uarte::Parity::EXCLUDED; - config.baudrate = uarte::Baudrate::BAUD115200; - - let mut tx_buffer = [0u8; 4096]; - let mut rx_buffer = [0u8; 4096]; - - let irq = interrupt::take!(SERIAL0); - let mut state = State::new(); - // Please note - important to have hardware flow control (https://github.com/embassy-rs/embassy/issues/536) - let u = BufferedUarte::new( - &mut state, - p.UARTETWISPI0, - p.TIMER0, - p.PPI_CH0, - p.PPI_CH1, - irq, - p.P0_08, - p.P0_06, - p.P0_07, - p.P0_05, - config, - &mut rx_buffer, - &mut tx_buffer, - ); - pin_mut!(u); - - info!("uarte initialized!"); - - unwrap!(u.write_all(b"Hello!\r\n").await); - info!("wrote hello in uart!"); - - loop { - info!("reading..."); - let buf = unwrap!(u.fill_buf().await); - info!("read done, got {}", buf); - - // Read bytes have to be explicitly consumed, otherwise fill_buf() will return them again - let n = buf.len(); - u.consume(n); - } -} diff --git a/examples/nrf5340/src/bin/channel.rs b/examples/nrf5340/src/bin/channel.rs deleted file mode 100644 index 425d4305..00000000 --- a/examples/nrf5340/src/bin/channel.rs +++ /dev/null @@ -1,43 +0,0 @@ -#![no_std] -#![no_main] -#![feature(type_alias_impl_trait)] - -use defmt::unwrap; -use embassy_executor::Spawner; -use embassy_nrf::gpio::{Level, Output, OutputDrive}; -use embassy_sync::blocking_mutex::raw::ThreadModeRawMutex; -use embassy_sync::channel::Channel; -use embassy_time::{Duration, Timer}; -use {defmt_rtt as _, panic_probe as _}; - -enum LedState { - On, - Off, -} - -static CHANNEL: Channel = Channel::new(); - -#[embassy_executor::task] -async fn my_task() { - loop { - CHANNEL.send(LedState::On).await; - Timer::after(Duration::from_secs(1)).await; - CHANNEL.send(LedState::Off).await; - Timer::after(Duration::from_secs(1)).await; - } -} - -#[embassy_executor::main] -async fn main(spawner: Spawner) { - let p = embassy_nrf::init(Default::default()); - let mut led = Output::new(p.P0_28, Level::Low, OutputDrive::Standard); - - unwrap!(spawner.spawn(my_task())); - - loop { - match CHANNEL.recv().await { - LedState::On => led.set_high(), - LedState::Off => led.set_low(), - } - } -} diff --git a/examples/nrf5340/src/bin/channel_sender_receiver.rs b/examples/nrf5340/src/bin/channel_sender_receiver.rs deleted file mode 100644 index 9628c052..00000000 --- a/examples/nrf5340/src/bin/channel_sender_receiver.rs +++ /dev/null @@ -1,50 +0,0 @@ -#![no_std] -#![no_main] -#![feature(type_alias_impl_trait)] - -use defmt::unwrap; -use embassy_executor::Spawner; -use embassy_nrf::gpio::{AnyPin, Level, Output, OutputDrive, Pin}; -use embassy_sync::blocking_mutex::raw::NoopRawMutex; -use embassy_sync::channel::{Channel, Receiver, Sender}; -use embassy_time::{Duration, Timer}; -use static_cell::StaticCell; -use {defmt_rtt as _, panic_probe as _}; - -enum LedState { - On, - Off, -} - -static CHANNEL: StaticCell> = StaticCell::new(); - -#[embassy_executor::task] -async fn send_task(sender: Sender<'static, NoopRawMutex, LedState, 1>) { - loop { - sender.send(LedState::On).await; - Timer::after(Duration::from_secs(1)).await; - sender.send(LedState::Off).await; - Timer::after(Duration::from_secs(1)).await; - } -} - -#[embassy_executor::task] -async fn recv_task(led: AnyPin, receiver: Receiver<'static, NoopRawMutex, LedState, 1>) { - let mut led = Output::new(led, Level::Low, OutputDrive::Standard); - - loop { - match receiver.recv().await { - LedState::On => led.set_high(), - LedState::Off => led.set_low(), - } - } -} - -#[embassy_executor::main] -async fn main(spawner: Spawner) { - let p = embassy_nrf::init(Default::default()); - let channel = CHANNEL.init(Channel::new()); - - unwrap!(spawner.spawn(send_task(channel.sender()))); - unwrap!(spawner.spawn(recv_task(p.P0_28.degrade(), channel.receiver()))); -} diff --git a/examples/nrf5340/src/bin/gpiote_port.rs b/examples/nrf5340/src/bin/gpiote_port.rs deleted file mode 100644 index 0cc911ad..00000000 --- a/examples/nrf5340/src/bin/gpiote_port.rs +++ /dev/null @@ -1,34 +0,0 @@ -#![no_std] -#![no_main] -#![feature(type_alias_impl_trait)] - -use defmt::{info, unwrap}; -use embassy_executor::Spawner; -use embassy_nrf::gpio::{AnyPin, Input, Pin as _, Pull}; -use {defmt_rtt as _, panic_probe as _}; - -#[embassy_executor::task(pool_size = 4)] -async fn button_task(n: usize, mut pin: Input<'static, AnyPin>) { - loop { - pin.wait_for_low().await; - info!("Button {:?} pressed!", n); - pin.wait_for_high().await; - info!("Button {:?} released!", n); - } -} - -#[embassy_executor::main] -async fn main(spawner: Spawner) { - let p = embassy_nrf::init(Default::default()); - info!("Starting!"); - - let btn1 = Input::new(p.P0_23.degrade(), Pull::Up); - let btn2 = Input::new(p.P0_24.degrade(), Pull::Up); - let btn3 = Input::new(p.P0_08.degrade(), Pull::Up); - let btn4 = Input::new(p.P0_09.degrade(), Pull::Up); - - unwrap!(spawner.spawn(button_task(1, btn1))); - unwrap!(spawner.spawn(button_task(2, btn2))); - unwrap!(spawner.spawn(button_task(3, btn3))); - unwrap!(spawner.spawn(button_task(4, btn4))); -} diff --git a/examples/nrf5340/src/bin/uart_idle.rs b/examples/nrf5340/src/bin/uart_idle.rs deleted file mode 100644 index 327fc4b2..00000000 --- a/examples/nrf5340/src/bin/uart_idle.rs +++ /dev/null @@ -1,35 +0,0 @@ -#![no_std] -#![no_main] -#![feature(type_alias_impl_trait)] - -use defmt::*; -use embassy_executor::Spawner; -use embassy_nrf::{interrupt, uarte}; -use {defmt_rtt as _, panic_probe as _}; - -#[embassy_executor::main] -async fn main(_spawner: Spawner) { - let p = embassy_nrf::init(Default::default()); - let mut config = uarte::Config::default(); - config.parity = uarte::Parity::EXCLUDED; - config.baudrate = uarte::Baudrate::BAUD115200; - - let irq = interrupt::take!(SERIAL0); - let uart = uarte::Uarte::new(p.UARTETWISPI0, irq, p.P0_08, p.P0_06, config); - let (mut tx, mut rx) = uart.split_with_idle(p.TIMER0, p.PPI_CH0, p.PPI_CH1); - - info!("uarte initialized!"); - - // Message must be in SRAM - let mut buf = [0; 8]; - buf.copy_from_slice(b"Hello!\r\n"); - - unwrap!(tx.write(&buf).await); - info!("wrote hello in uart!"); - - loop { - info!("reading..."); - let n = unwrap!(rx.read_until_idle(&mut buf).await); - info!("got {} bytes", n); - } -} diff --git a/examples/nrf5340/src/bin/uart_split.rs b/examples/nrf5340/src/bin/uart_split.rs deleted file mode 100644 index 0bbbfeaa..00000000 --- a/examples/nrf5340/src/bin/uart_split.rs +++ /dev/null @@ -1,60 +0,0 @@ -#![no_std] -#![no_main] -#![feature(type_alias_impl_trait)] - -use defmt::*; -use embassy_executor::Spawner; -use embassy_nrf::peripherals::UARTETWISPI0; -use embassy_nrf::uarte::UarteRx; -use embassy_nrf::{interrupt, uarte}; -use embassy_sync::blocking_mutex::raw::ThreadModeRawMutex; -use embassy_sync::channel::Channel; -use {defmt_rtt as _, panic_probe as _}; - -static CHANNEL: Channel = Channel::new(); - -#[embassy_executor::main] -async fn main(spawner: Spawner) { - let p = embassy_nrf::init(Default::default()); - let mut config = uarte::Config::default(); - config.parity = uarte::Parity::EXCLUDED; - config.baudrate = uarte::Baudrate::BAUD115200; - - let irq = interrupt::take!(SERIAL0); - let uart = uarte::Uarte::new(p.UARTETWISPI0, irq, p.P1_00, p.P1_01, config); - let (mut tx, rx) = uart.split(); - - info!("uarte initialized!"); - - // Spawn a task responsible purely for reading - - unwrap!(spawner.spawn(reader(rx))); - - // Message must be in SRAM - { - let mut buf = [0; 23]; - buf.copy_from_slice(b"Type 8 chars to echo!\r\n"); - - unwrap!(tx.write(&buf).await); - info!("wrote hello in uart!"); - } - - // Continue reading in this main task and write - // back out the buffer we receive from the read - // task. - loop { - let buf = CHANNEL.recv().await; - info!("writing..."); - unwrap!(tx.write(&buf).await); - } -} - -#[embassy_executor::task] -async fn reader(mut rx: UarteRx<'static, UARTETWISPI0>) { - let mut buf = [0; 8]; - loop { - info!("reading..."); - unwrap!(rx.read(&mut buf).await); - CHANNEL.send(buf).await; - } -}