diff options
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/mimxrt6/Cargo.toml | 2 | ||||
| -rw-r--r-- | examples/mimxrt6/src/bin/dma.rs | 26 | ||||
| -rw-r--r-- | examples/mimxrt6/src/bin/spi-async.rs | 35 | ||||
| -rw-r--r-- | examples/mimxrt6/src/bin/spi.rs | 51 | ||||
| -rw-r--r-- | examples/nrf54l15/src/bin/rramc.rs (renamed from examples/nrf54l15/src/bin/nvmc.rs) | 0 | ||||
| -rw-r--r-- | examples/nrf54l15/src/bin/rramc_buffered.rs | 59 | ||||
| -rw-r--r-- | examples/std/src/bin/net_ppp.rs | 9 | ||||
| -rw-r--r-- | examples/std/src/bin/tick_cancel.rs | 47 |
8 files changed, 225 insertions, 4 deletions
diff --git a/examples/mimxrt6/Cargo.toml b/examples/mimxrt6/Cargo.toml index dc09e97e7..ada112833 100644 --- a/examples/mimxrt6/Cargo.toml +++ b/examples/mimxrt6/Cargo.toml | |||
| @@ -21,6 +21,8 @@ embedded-hal-async = "1.0.0" | |||
| 21 | 21 | ||
| 22 | mimxrt600-fcb = "0.2.2" | 22 | mimxrt600-fcb = "0.2.2" |
| 23 | panic-probe = { version = "1.0.0", features = ["print-defmt"] } | 23 | panic-probe = { version = "1.0.0", features = ["print-defmt"] } |
| 24 | embedded-hal-bus = "0.3.0" | ||
| 25 | is31fl3743b-driver = { version = "0.1.1", features = ["is_blocking"] } | ||
| 24 | 26 | ||
| 25 | # cargo build/run | 27 | # cargo build/run |
| 26 | [profile.dev] | 28 | [profile.dev] |
diff --git a/examples/mimxrt6/src/bin/dma.rs b/examples/mimxrt6/src/bin/dma.rs new file mode 100644 index 000000000..b490efc6b --- /dev/null +++ b/examples/mimxrt6/src/bin/dma.rs | |||
| @@ -0,0 +1,26 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | |||
| 4 | extern crate embassy_imxrt_examples; | ||
| 5 | |||
| 6 | use defmt::info; | ||
| 7 | use embassy_executor::Spawner; | ||
| 8 | use embassy_imxrt::dma::copy; | ||
| 9 | use {defmt_rtt as _, panic_probe as _}; | ||
| 10 | |||
| 11 | const BUFLEN: usize = 1024; | ||
| 12 | |||
| 13 | #[embassy_executor::main] | ||
| 14 | async fn main(_spawner: Spawner) { | ||
| 15 | let p = embassy_imxrt::init(Default::default()); | ||
| 16 | |||
| 17 | info!("Test memory-to-memory DMA transfers"); | ||
| 18 | |||
| 19 | let src = [0x55u8; BUFLEN]; | ||
| 20 | let mut dst = [0u8; BUFLEN]; | ||
| 21 | |||
| 22 | unsafe { copy(p.DMA0_CH0, &src, &mut dst) }.await; | ||
| 23 | assert!(dst == src); | ||
| 24 | |||
| 25 | info!("DMA copy succeeded"); | ||
| 26 | } | ||
diff --git a/examples/mimxrt6/src/bin/spi-async.rs b/examples/mimxrt6/src/bin/spi-async.rs new file mode 100644 index 000000000..aa56f7c42 --- /dev/null +++ b/examples/mimxrt6/src/bin/spi-async.rs | |||
| @@ -0,0 +1,35 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | |||
| 4 | use defmt::info; | ||
| 5 | use embassy_executor::Spawner; | ||
| 6 | use embassy_imxrt::bind_interrupts; | ||
| 7 | use embassy_imxrt::flexcomm::spi::{InterruptHandler, Spi}; | ||
| 8 | use embassy_imxrt::peripherals::FLEXCOMM5; | ||
| 9 | use {defmt_rtt as _, embassy_imxrt_examples as _, panic_probe as _}; | ||
| 10 | |||
| 11 | bind_interrupts!(struct Irqs { | ||
| 12 | FLEXCOMM5 => InterruptHandler<FLEXCOMM5>; | ||
| 13 | }); | ||
| 14 | |||
| 15 | const BUFLEN: usize = 1024; | ||
| 16 | |||
| 17 | #[embassy_executor::main] | ||
| 18 | async fn main(_spawner: Spawner) { | ||
| 19 | let p = embassy_imxrt::init(Default::default()); | ||
| 20 | |||
| 21 | info!("Initializing SPI"); | ||
| 22 | |||
| 23 | let mut spi = Spi::new_async(p.FLEXCOMM5, p.PIO1_3, p.PIO1_5, p.PIO1_4, Irqs, Default::default()); | ||
| 24 | |||
| 25 | let mut rxbuf = [0x55; BUFLEN]; | ||
| 26 | let txbuf = [0xaa; BUFLEN]; | ||
| 27 | |||
| 28 | for _ in 0..10 { | ||
| 29 | spi.async_transfer(&mut rxbuf, &txbuf).await.unwrap(); | ||
| 30 | assert!(rxbuf.iter().all(|b| *b == 0xaa)); | ||
| 31 | rxbuf.fill(0x55); | ||
| 32 | } | ||
| 33 | |||
| 34 | info!("SPI transfers succeeded"); | ||
| 35 | } | ||
diff --git a/examples/mimxrt6/src/bin/spi.rs b/examples/mimxrt6/src/bin/spi.rs new file mode 100644 index 000000000..4854432e8 --- /dev/null +++ b/examples/mimxrt6/src/bin/spi.rs | |||
| @@ -0,0 +1,51 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | |||
| 4 | use defmt::info; | ||
| 5 | use embassy_executor::Spawner; | ||
| 6 | use embassy_imxrt::flexcomm::spi::Spi; | ||
| 7 | use embassy_imxrt::gpio; | ||
| 8 | use embassy_time::{Delay, Timer}; | ||
| 9 | use embedded_hal_bus::spi::ExclusiveDevice; | ||
| 10 | use is31fl3743b_driver::{CSy, Is31fl3743b, SWx}; | ||
| 11 | use {defmt_rtt as _, embassy_imxrt_examples as _, panic_probe as _}; | ||
| 12 | |||
| 13 | #[embassy_executor::main] | ||
| 14 | async fn main(_spawner: Spawner) { | ||
| 15 | let p = embassy_imxrt::init(Default::default()); | ||
| 16 | |||
| 17 | info!("Initializing SPI"); | ||
| 18 | |||
| 19 | let cs = gpio::Output::new( | ||
| 20 | p.PIO1_6, | ||
| 21 | gpio::Level::Low, | ||
| 22 | gpio::DriveMode::PushPull, | ||
| 23 | gpio::DriveStrength::Normal, | ||
| 24 | gpio::SlewRate::Standard, | ||
| 25 | ); | ||
| 26 | |||
| 27 | let spi = Spi::new_blocking(p.FLEXCOMM5, p.PIO1_3, p.PIO1_5, p.PIO1_4, Default::default()); | ||
| 28 | let delay = Delay; | ||
| 29 | |||
| 30 | // One SPI device only on the SPI bus | ||
| 31 | let spi_dev = ExclusiveDevice::new(spi, cs, delay).unwrap(); | ||
| 32 | |||
| 33 | // Instantiate IS31FL3743B device | ||
| 34 | let mut driver = Is31fl3743b::new(spi_dev).unwrap(); | ||
| 35 | |||
| 36 | // Enable phase delay to help reduce power noise | ||
| 37 | let _ = driver.enable_phase_delay(); | ||
| 38 | // Set global current, check method documentation for more info | ||
| 39 | let _ = driver.set_global_current(90); | ||
| 40 | |||
| 41 | let _ = driver.set_led_peak_current_bulk(SWx::SW1, CSy::CS1, &[100; 11 * 18]); | ||
| 42 | |||
| 43 | // Driver is fully set up, we can now start turning on LEDs! | ||
| 44 | // Create a white breathing effect | ||
| 45 | loop { | ||
| 46 | for brightness in (0..=255_u8).chain((0..=255).rev()) { | ||
| 47 | let _ = driver.set_led_brightness_bulk(SWx::SW1, CSy::CS1, &[brightness; 11 * 18]); | ||
| 48 | Timer::after_micros(1).await; | ||
| 49 | } | ||
| 50 | } | ||
| 51 | } | ||
diff --git a/examples/nrf54l15/src/bin/nvmc.rs b/examples/nrf54l15/src/bin/rramc.rs index f990604cd..f990604cd 100644 --- a/examples/nrf54l15/src/bin/nvmc.rs +++ b/examples/nrf54l15/src/bin/rramc.rs | |||
diff --git a/examples/nrf54l15/src/bin/rramc_buffered.rs b/examples/nrf54l15/src/bin/rramc_buffered.rs new file mode 100644 index 000000000..06c9585ed --- /dev/null +++ b/examples/nrf54l15/src/bin/rramc_buffered.rs | |||
| @@ -0,0 +1,59 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | |||
| 4 | use defmt::{info, unwrap}; | ||
| 5 | use embassy_executor::Spawner; | ||
| 6 | use embassy_nrf::rramc::{Buffered, PAGE_SIZE, Rramc}; | ||
| 7 | use embedded_storage::nor_flash::{NorFlash, ReadNorFlash}; | ||
| 8 | use {defmt_rtt as _, panic_probe as _}; | ||
| 9 | |||
| 10 | #[embassy_executor::main] | ||
| 11 | async fn main(_spawner: Spawner) { | ||
| 12 | let p = embassy_nrf::init(Default::default()); | ||
| 13 | info!("Hello RRAMC NVMC!"); | ||
| 14 | |||
| 15 | // Buffer 8 word lines | ||
| 16 | let mut f: Rramc<'_, Buffered<128>> = Rramc::new_buffered(p.RRAMC); | ||
| 17 | |||
| 18 | const ADDR: u32 = 0x80000; | ||
| 19 | let mut buf = [0u8; 4]; | ||
| 20 | |||
| 21 | info!("Reading..."); | ||
| 22 | unwrap!(f.read(ADDR, &mut buf)); | ||
| 23 | info!("Read: {=[u8]:x}", buf); | ||
| 24 | |||
| 25 | info!("Erasing..."); | ||
| 26 | unwrap!(f.erase(ADDR, ADDR + PAGE_SIZE as u32)); | ||
| 27 | |||
| 28 | info!("Reading..."); | ||
| 29 | unwrap!(f.read(ADDR, &mut buf)); | ||
| 30 | info!("Read: {=[u8]:x}", buf); | ||
| 31 | |||
| 32 | info!("Writing..."); | ||
| 33 | // 16 B (128-bit) write minimum | ||
| 34 | let out: [u8; 256] = [ | ||
| 35 | 0xaa, 0xaa, 0xaa, 0xaa, 0xbb, 0xbb, 0xbb, 0xbb, 0xcc, 0xcc, 0xcc, 0xcc, 0xdd, 0xdd, 0xdd, 0xdd, 0xaa, 0xaa, | ||
| 36 | 0xaa, 0xaa, 0xbb, 0xbb, 0xbb, 0xbb, 0xcc, 0xcc, 0xcc, 0xcc, 0xdd, 0xdd, 0xdd, 0xdd, 0xaa, 0xaa, 0xaa, 0xaa, | ||
| 37 | 0xbb, 0xbb, 0xbb, 0xbb, 0xcc, 0xcc, 0xcc, 0xcc, 0xdd, 0xdd, 0xdd, 0xdd, 0xaa, 0xaa, 0xaa, 0xaa, 0xbb, 0xbb, | ||
| 38 | 0xbb, 0xbb, 0xcc, 0xcc, 0xcc, 0xcc, 0xdd, 0xdd, 0xdd, 0xdd, 0xaa, 0xaa, 0xaa, 0xaa, 0xbb, 0xbb, 0xbb, 0xbb, | ||
| 39 | 0xcc, 0xcc, 0xcc, 0xcc, 0xdd, 0xdd, 0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cc, 0xdd, 0xdd, 0xdd, 0xdd, 0xaa, 0xaa, 0xaa, 0xaa, 0xbb, 0xbb, 0xbb, 0xbb, 0xcc, 0xcc, 0xcc, 0xcc, | ||
| 49 | 0xdd, 0xdd, 0xdd, 0xdd, | ||
| 50 | ]; | ||
| 51 | unwrap!(f.write(ADDR, &out)); | ||
| 52 | |||
| 53 | info!("Reading..."); | ||
| 54 | // Can read arbitrary sizes | ||
| 55 | for addr in (ADDR..ADDR + 256).step_by(4) { | ||
| 56 | unwrap!(f.read(addr, &mut buf)); | ||
| 57 | info!("Read: {=[u8]:x}", buf); | ||
| 58 | } | ||
| 59 | } | ||
diff --git a/examples/std/src/bin/net_ppp.rs b/examples/std/src/bin/net_ppp.rs index 82272c798..685dbf3d3 100644 --- a/examples/std/src/bin/net_ppp.rs +++ b/examples/std/src/bin/net_ppp.rs | |||
| @@ -52,7 +52,7 @@ async fn ppp_task(stack: Stack<'static>, mut runner: Runner<'static>, port: Seri | |||
| 52 | password: b"mypass", | 52 | password: b"mypass", |
| 53 | }; | 53 | }; |
| 54 | 54 | ||
| 55 | runner | 55 | let r = runner |
| 56 | .run(port, config, |ipv4| { | 56 | .run(port, config, |ipv4| { |
| 57 | let Some(addr) = ipv4.address else { | 57 | let Some(addr) = ipv4.address else { |
| 58 | warn!("PPP did not provide an IP address."); | 58 | warn!("PPP did not provide an IP address."); |
| @@ -69,9 +69,10 @@ async fn ppp_task(stack: Stack<'static>, mut runner: Runner<'static>, port: Seri | |||
| 69 | }); | 69 | }); |
| 70 | stack.set_config_v4(config); | 70 | stack.set_config_v4(config); |
| 71 | }) | 71 | }) |
| 72 | .await | 72 | .await; |
| 73 | .unwrap(); | 73 | match r { |
| 74 | unreachable!() | 74 | Err(e) => panic!("{:?}", e), |
| 75 | } | ||
| 75 | } | 76 | } |
| 76 | 77 | ||
| 77 | #[embassy_executor::task] | 78 | #[embassy_executor::task] |
diff --git a/examples/std/src/bin/tick_cancel.rs b/examples/std/src/bin/tick_cancel.rs new file mode 100644 index 000000000..54e44790f --- /dev/null +++ b/examples/std/src/bin/tick_cancel.rs | |||
| @@ -0,0 +1,47 @@ | |||
| 1 | use std::sync::atomic::{AtomicBool, Ordering}; | ||
| 2 | use std::thread; | ||
| 3 | use std::time::Duration; | ||
| 4 | |||
| 5 | use embassy_executor::Executor; | ||
| 6 | use embassy_time::Timer; | ||
| 7 | use log::*; | ||
| 8 | use static_cell::StaticCell; | ||
| 9 | |||
| 10 | #[embassy_executor::task] | ||
| 11 | async fn run() { | ||
| 12 | loop { | ||
| 13 | info!("tick"); | ||
| 14 | Timer::after_secs(1).await; | ||
| 15 | } | ||
| 16 | } | ||
| 17 | |||
| 18 | static DONE: StaticCell<AtomicBool> = StaticCell::new(); | ||
| 19 | static EXECUTOR: StaticCell<Executor> = StaticCell::new(); | ||
| 20 | |||
| 21 | fn main() { | ||
| 22 | env_logger::builder() | ||
| 23 | .filter_level(log::LevelFilter::Debug) | ||
| 24 | .format_timestamp_nanos() | ||
| 25 | .init(); | ||
| 26 | |||
| 27 | let done = DONE.init(AtomicBool::new(false)); | ||
| 28 | let done_cb = || done.load(Ordering::Relaxed); | ||
| 29 | |||
| 30 | let server_thread = thread::spawn(move || { | ||
| 31 | let executor = EXECUTOR.init(Executor::new()); | ||
| 32 | executor.run_until( | ||
| 33 | |spawner| { | ||
| 34 | spawner.spawn(run().unwrap()); | ||
| 35 | }, | ||
| 36 | done_cb, | ||
| 37 | ); | ||
| 38 | info!("Executor finished"); | ||
| 39 | }); | ||
| 40 | |||
| 41 | thread::sleep(Duration::from_secs(5)); | ||
| 42 | |||
| 43 | info!("Cancelling executor"); | ||
| 44 | done.store(true, Ordering::Relaxed); | ||
| 45 | |||
| 46 | server_thread.join().unwrap(); | ||
| 47 | } | ||
