From e2807058ffc73bd0fc2f4ce9f29e5a56f3e5a18e Mon Sep 17 00:00:00 2001 From: everdrone Date: Thu, 23 Oct 2025 12:49:47 +0200 Subject: fix stm32h723 example --- examples/stm32h723/src/bin/spdifrx.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'examples') diff --git a/examples/stm32h723/src/bin/spdifrx.rs b/examples/stm32h723/src/bin/spdifrx.rs index cdbd69b89..5c29602c6 100644 --- a/examples/stm32h723/src/bin/spdifrx.rs +++ b/examples/stm32h723/src/bin/spdifrx.rs @@ -167,7 +167,7 @@ fn new_sai_transmitter<'d>( sai_config.slot_count = hal::sai::word::U4(CHANNEL_COUNT as u8); sai_config.slot_enable = 0xFFFF; // All slots sai_config.data_size = sai::DataSize::Data32; - sai_config.frame_length = (CHANNEL_COUNT * 32) as u8; + sai_config.frame_length = (CHANNEL_COUNT * 32) as u16; sai_config.master_clock_divider = None; let (sub_block_tx, _) = hal::sai::split_subblocks(sai); -- cgit From 3949a8601f293856df326ccc21252cb5f1518c5c Mon Sep 17 00:00:00 2001 From: Maarten de Vries Date: Thu, 30 Oct 2025 11:52:53 +0100 Subject: embassy-nrf: add gpiote::InputChannel::wait_for_high/low() Also catch GPIOTE events directly when wait() is called, even before polling the future. --- examples/nrf52840/src/bin/gpiote_channel.rs | 8 ++++---- examples/nrf5340/src/bin/gpiote_channel.rs | 8 ++++---- examples/nrf54l15/src/bin/gpiote_channel.rs | 8 ++++---- 3 files changed, 12 insertions(+), 12 deletions(-) (limited to 'examples') diff --git a/examples/nrf52840/src/bin/gpiote_channel.rs b/examples/nrf52840/src/bin/gpiote_channel.rs index c7ddc1d8d..e358779b2 100644 --- a/examples/nrf52840/src/bin/gpiote_channel.rs +++ b/examples/nrf52840/src/bin/gpiote_channel.rs @@ -12,10 +12,10 @@ async fn main(_spawner: Spawner) { let p = embassy_nrf::init(Default::default()); info!("Starting!"); - let ch1 = InputChannel::new(p.GPIOTE_CH0, p.P0_11, Pull::Up, InputChannelPolarity::HiToLo); - let ch2 = InputChannel::new(p.GPIOTE_CH1, p.P0_12, Pull::Up, InputChannelPolarity::LoToHi); - let ch3 = InputChannel::new(p.GPIOTE_CH2, p.P0_24, Pull::Up, InputChannelPolarity::Toggle); - let ch4 = InputChannel::new(p.GPIOTE_CH3, p.P0_25, Pull::Up, InputChannelPolarity::Toggle); + let mut ch1 = InputChannel::new(p.GPIOTE_CH0, p.P0_11, Pull::Up, InputChannelPolarity::HiToLo); + let mut ch2 = InputChannel::new(p.GPIOTE_CH1, p.P0_12, Pull::Up, InputChannelPolarity::LoToHi); + let mut ch3 = InputChannel::new(p.GPIOTE_CH2, p.P0_24, Pull::Up, InputChannelPolarity::Toggle); + let mut ch4 = InputChannel::new(p.GPIOTE_CH3, p.P0_25, Pull::Up, InputChannelPolarity::Toggle); let button1 = async { loop { diff --git a/examples/nrf5340/src/bin/gpiote_channel.rs b/examples/nrf5340/src/bin/gpiote_channel.rs index a085310ce..41ee732c3 100644 --- a/examples/nrf5340/src/bin/gpiote_channel.rs +++ b/examples/nrf5340/src/bin/gpiote_channel.rs @@ -12,10 +12,10 @@ async fn main(_spawner: Spawner) { let p = embassy_nrf::init(Default::default()); info!("Starting!"); - let ch1 = InputChannel::new(p.GPIOTE_CH0, p.P0_23, Pull::Up, InputChannelPolarity::HiToLo); - let ch2 = InputChannel::new(p.GPIOTE_CH1, p.P0_24, Pull::Up, InputChannelPolarity::LoToHi); - let ch3 = InputChannel::new(p.GPIOTE_CH2, p.P0_08, Pull::Up, InputChannelPolarity::Toggle); - let ch4 = InputChannel::new(p.GPIOTE_CH3, p.P0_09, Pull::Up, InputChannelPolarity::Toggle); + let mut ch1 = InputChannel::new(p.GPIOTE_CH0, p.P0_23, Pull::Up, InputChannelPolarity::HiToLo); + let mut ch2 = InputChannel::new(p.GPIOTE_CH1, p.P0_24, Pull::Up, InputChannelPolarity::LoToHi); + let mut ch3 = InputChannel::new(p.GPIOTE_CH2, p.P0_08, Pull::Up, InputChannelPolarity::Toggle); + let mut ch4 = InputChannel::new(p.GPIOTE_CH3, p.P0_09, Pull::Up, InputChannelPolarity::Toggle); let button1 = async { loop { diff --git a/examples/nrf54l15/src/bin/gpiote_channel.rs b/examples/nrf54l15/src/bin/gpiote_channel.rs index 6333250ba..cac8823f8 100644 --- a/examples/nrf54l15/src/bin/gpiote_channel.rs +++ b/examples/nrf54l15/src/bin/gpiote_channel.rs @@ -12,10 +12,10 @@ async fn main(_spawner: Spawner) { let p = embassy_nrf::init(Default::default()); info!("Starting!"); - let ch1 = InputChannel::new(p.GPIOTE20_CH0, p.P1_13, Pull::Up, InputChannelPolarity::HiToLo); - let ch2 = InputChannel::new(p.GPIOTE20_CH1, p.P1_09, Pull::Up, InputChannelPolarity::LoToHi); - let ch3 = InputChannel::new(p.GPIOTE20_CH2, p.P1_08, Pull::Up, InputChannelPolarity::Toggle); - let ch4 = InputChannel::new(p.GPIOTE30_CH0, p.P0_04, Pull::Up, InputChannelPolarity::Toggle); + let mut ch1 = InputChannel::new(p.GPIOTE20_CH0, p.P1_13, Pull::Up, InputChannelPolarity::HiToLo); + let mut ch2 = InputChannel::new(p.GPIOTE20_CH1, p.P1_09, Pull::Up, InputChannelPolarity::LoToHi); + let mut ch3 = InputChannel::new(p.GPIOTE20_CH2, p.P1_08, Pull::Up, InputChannelPolarity::Toggle); + let mut ch4 = InputChannel::new(p.GPIOTE30_CH0, p.P0_04, Pull::Up, InputChannelPolarity::Toggle); let button1 = async { loop { -- cgit From 4fb60b5991c4c98427ef23e6c011210341ba09e1 Mon Sep 17 00:00:00 2001 From: xoviat Date: Thu, 13 Nov 2025 17:41:20 -0600 Subject: fix async adc for h5 and others closes #4882. --- examples/stm32h5/src/bin/adc_dma.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'examples') diff --git a/examples/stm32h5/src/bin/adc_dma.rs b/examples/stm32h5/src/bin/adc_dma.rs index fb9fcbc5c..2138257f7 100644 --- a/examples/stm32h5/src/bin/adc_dma.rs +++ b/examples/stm32h5/src/bin/adc_dma.rs @@ -6,7 +6,7 @@ use embassy_executor::Spawner; use embassy_stm32::adc::{self, Adc, AdcChannel, RxDma, SampleTime}; use embassy_stm32::peripherals::{ADC1, ADC2, GPDMA1_CH0, GPDMA1_CH1, PA0, PA1, PA2, PA3}; use embassy_stm32::{Config, Peri}; -use embassy_time::Instant; +use embassy_time::{Duration, Instant, Ticker}; use {defmt_rtt as _, panic_probe as _}; #[embassy_executor::main] @@ -76,6 +76,9 @@ async fn adc_task<'a, T: adc::Instance>( let mut pin1 = pin1.degrade_adc(); let mut pin2 = pin2.degrade_adc(); + info!("adc init"); + + let mut ticker = Ticker::every(Duration::from_millis(500)); let mut tic = Instant::now(); let mut buffer = [0u16; 512]; loop { @@ -84,11 +87,13 @@ async fn adc_task<'a, T: adc::Instance>( adc.read( dma.reborrow(), [(&mut pin1, SampleTime::CYCLES2_5), (&mut pin2, SampleTime::CYCLES2_5)].into_iter(), - &mut buffer, + &mut buffer[0..2], ) .await; let toc = Instant::now(); info!("\n adc1: {} dt = {}", buffer[0..16], (toc - tic).as_micros()); tic = toc; + + ticker.next().await; } } -- cgit From 9b5fc685a11bc4d5254dffde37beeaba721d1f2a Mon Sep 17 00:00:00 2001 From: Ulf Lilleengen Date: Fri, 14 Nov 2025 12:53:10 +0100 Subject: fix: use correct nrf54l15 flash size Both SVD and documentation agrees on 1524kB --- examples/nrf54l15/memory.x | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'examples') diff --git a/examples/nrf54l15/memory.x b/examples/nrf54l15/memory.x index 1064c8a5c..332200828 100644 --- a/examples/nrf54l15/memory.x +++ b/examples/nrf54l15/memory.x @@ -1,5 +1,5 @@ MEMORY { - FLASH : ORIGIN = 0x00000000, LENGTH = 1536K + FLASH : ORIGIN = 0x00000000, LENGTH = 1524K RAM : ORIGIN = 0x20000000, LENGTH = 256K } -- cgit From a01e37fbc2800e87eb3b45f1e61f717e48c74127 Mon Sep 17 00:00:00 2001 From: 1-rafael-1 Date: Sat, 15 Nov 2025 20:49:07 +0100 Subject: Switch WiFi example to non-TLS httpbin request --- examples/rp/src/bin/wifi_webrequest.rs | 90 ++++++++++++++++++++++------------ 1 file changed, 59 insertions(+), 31 deletions(-) (limited to 'examples') diff --git a/examples/rp/src/bin/wifi_webrequest.rs b/examples/rp/src/bin/wifi_webrequest.rs index b618d2b38..ce85f4b9a 100644 --- a/examples/rp/src/bin/wifi_webrequest.rs +++ b/examples/rp/src/bin/wifi_webrequest.rs @@ -1,9 +1,8 @@ //! This example uses the RP Pico W board Wifi chip (cyw43). -//! Connects to Wifi network and makes a web request to get the current time. +//! Connects to Wifi network and makes a web request to httpbin.org. #![no_std] #![no_main] -#![allow(async_fn_in_trait)] use core::str::from_utf8; @@ -20,11 +19,14 @@ use embassy_rp::gpio::{Level, Output}; use embassy_rp::peripherals::{DMA_CH0, PIO0}; use embassy_rp::pio::{InterruptHandler, Pio}; use embassy_time::{Duration, Timer}; -use reqwless::client::{HttpClient, TlsConfig, TlsVerify}; +use reqwless::client::HttpClient; +// Uncomment these for TLS requests: +// use reqwless::client::{HttpClient, TlsConfig, TlsVerify}; use reqwless::request::Method; use serde::Deserialize; +use serde_json_core::from_slice; use static_cell::StaticCell; -use {defmt_rtt as _, panic_probe as _, serde_json_core}; +use {defmt_rtt as _, panic_probe as _}; bind_interrupts!(struct Irqs { PIO0_IRQ_0 => InterruptHandler; @@ -119,64 +121,90 @@ async fn main(spawner: Spawner) { // And now we can use it! loop { - let mut rx_buffer = [0; 8192]; - let mut tls_read_buffer = [0; 16640]; - let mut tls_write_buffer = [0; 16640]; + let mut rx_buffer = [0; 4096]; + // Uncomment these for TLS requests: + // let mut tls_read_buffer = [0; 16640]; + // let mut tls_write_buffer = [0; 16640]; - let client_state = TcpClientState::<1, 1024, 1024>::new(); + let client_state = TcpClientState::<1, 4096, 4096>::new(); let tcp_client = TcpClient::new(stack, &client_state); let dns_client = DnsSocket::new(stack); - let tls_config = TlsConfig::new(seed, &mut tls_read_buffer, &mut tls_write_buffer, TlsVerify::None); + // Uncomment these for TLS requests: + // let tls_config = TlsConfig::new(seed, &mut tls_read_buffer, &mut tls_write_buffer, TlsVerify::None); - let mut http_client = HttpClient::new_with_tls(&tcp_client, &dns_client, tls_config); - let url = "https://worldtimeapi.org/api/timezone/Europe/Berlin"; - // for non-TLS requests, use this instead: - // let mut http_client = HttpClient::new(&tcp_client, &dns_client); - // let url = "http://worldtimeapi.org/api/timezone/Europe/Berlin"; + // Using non-TLS HTTP for this example + let mut http_client = HttpClient::new(&tcp_client, &dns_client); + let url = "http://httpbin.org/json"; + // For TLS requests, use this instead: + // let mut http_client = HttpClient::new_with_tls(&tcp_client, &dns_client, tls_config); + // let url = "https://httpbin.org/json"; info!("connecting to {}", &url); - let mut request = match http_client.request(Method::GET, &url).await { + let mut request = match http_client.request(Method::GET, url).await { Ok(req) => req, Err(e) => { error!("Failed to make HTTP request: {:?}", e); - return; // handle the error + Timer::after(Duration::from_secs(5)).await; + continue; } }; let response = match request.send(&mut rx_buffer).await { Ok(resp) => resp, - Err(_e) => { - error!("Failed to send HTTP request"); - return; // handle the error; + Err(e) => { + error!("Failed to send HTTP request: {:?}", e); + Timer::after(Duration::from_secs(5)).await; + continue; } }; - let body = match from_utf8(response.body().read_to_end().await.unwrap()) { + info!("Response status: {}", response.status.0); + + let body_bytes = match response.body().read_to_end().await { Ok(b) => b, Err(_e) => { error!("Failed to read response body"); - return; // handle the error + Timer::after(Duration::from_secs(5)).await; + continue; + } + }; + + let body = match from_utf8(body_bytes) { + Ok(b) => b, + Err(_e) => { + error!("Failed to parse response body as UTF-8"); + Timer::after(Duration::from_secs(5)).await; + continue; } }; - info!("Response body: {:?}", &body); + info!("Response body length: {} bytes", body.len()); - // parse the response body and update the RTC + // Parse the JSON response from httpbin.org/json + #[derive(Deserialize)] + struct SlideShow<'a> { + author: &'a str, + title: &'a str, + } #[derive(Deserialize)] - struct ApiResponse<'a> { - datetime: &'a str, - // other fields as needed + struct HttpBinResponse<'a> { + #[serde(borrow)] + slideshow: SlideShow<'a>, } let bytes = body.as_bytes(); - match serde_json_core::de::from_slice::(bytes) { + match from_slice::(bytes) { Ok((output, _used)) => { - info!("Datetime: {:?}", output.datetime); + info!("Successfully parsed JSON response!"); + info!("Slideshow title: {:?}", output.slideshow.title); + info!("Slideshow author: {:?}", output.slideshow.author); } - Err(_e) => { - error!("Failed to parse response body"); - return; // handle the error + Err(e) => { + error!("Failed to parse JSON response: {}", Debug2Format(&e)); + // Log preview of response for debugging + let preview = if body.len() > 200 { &body[..200] } else { body }; + info!("Response preview: {:?}", preview); } } -- cgit From 29d4ade2866e6c8d2114b393853354ded1e61db7 Mon Sep 17 00:00:00 2001 From: xoviat Date: Sun, 16 Nov 2025 07:50:49 -0600 Subject: low_power: misc cleanups and allow main macro --- examples/stm32h5/src/bin/stop.rs | 12 ++---------- examples/stm32l5/src/bin/stop.rs | 12 ++---------- examples/stm32wle5/src/bin/adc.rs | 12 ++---------- examples/stm32wle5/src/bin/blinky.rs | 12 ++---------- examples/stm32wle5/src/bin/button_exti.rs | 12 ++---------- examples/stm32wle5/src/bin/i2c.rs | 13 ++----------- 6 files changed, 12 insertions(+), 61 deletions(-) (limited to 'examples') diff --git a/examples/stm32h5/src/bin/stop.rs b/examples/stm32h5/src/bin/stop.rs index caebc9daf..8d5456b80 100644 --- a/examples/stm32h5/src/bin/stop.rs +++ b/examples/stm32h5/src/bin/stop.rs @@ -7,20 +7,12 @@ use defmt::*; use embassy_executor::Spawner; use embassy_stm32::gpio::{AnyPin, Level, Output, Speed}; -use embassy_stm32::low_power::Executor; use embassy_stm32::rcc::{HSIPrescaler, LsConfig}; -use embassy_stm32::{Config, Peri}; +use embassy_stm32::{Config, Peri, low_power}; use embassy_time::Timer; use {defmt_rtt as _, panic_probe as _}; -#[cortex_m_rt::entry] -fn main() -> ! { - Executor::take().run(|spawner| { - spawner.spawn(unwrap!(async_main(spawner))); - }) -} - -#[embassy_executor::task] +#[embassy_executor::main(executor = "low_power::Executor")] async fn async_main(spawner: Spawner) { defmt::info!("Program Start"); diff --git a/examples/stm32l5/src/bin/stop.rs b/examples/stm32l5/src/bin/stop.rs index 3d119f90f..fde804fb7 100644 --- a/examples/stm32l5/src/bin/stop.rs +++ b/examples/stm32l5/src/bin/stop.rs @@ -4,20 +4,12 @@ use defmt::*; use embassy_executor::Spawner; use embassy_stm32::gpio::{AnyPin, Level, Output, Speed}; -use embassy_stm32::low_power::Executor; use embassy_stm32::rcc::LsConfig; -use embassy_stm32::{Config, Peri}; +use embassy_stm32::{Config, Peri, low_power}; use embassy_time::Timer; use {defmt_rtt as _, panic_probe as _}; -#[cortex_m_rt::entry] -fn main() -> ! { - Executor::take().run(|spawner| { - spawner.spawn(unwrap!(async_main(spawner))); - }) -} - -#[embassy_executor::task] +#[embassy_executor::main(executor = "low_power::Executor")] async fn async_main(spawner: Spawner) { let mut config = Config::default(); config.rcc.ls = LsConfig::default_lsi(); diff --git a/examples/stm32wle5/src/bin/adc.rs b/examples/stm32wle5/src/bin/adc.rs index 4e0574d97..ea91fb063 100644 --- a/examples/stm32wle5/src/bin/adc.rs +++ b/examples/stm32wle5/src/bin/adc.rs @@ -6,20 +6,12 @@ use defmt::*; use defmt_rtt as _; use embassy_executor::Spawner; use embassy_stm32::adc::{Adc, SampleTime}; -use embassy_stm32::low_power::Executor; +use embassy_stm32::low_power; use embassy_time::Timer; use panic_probe as _; use static_cell::StaticCell; -#[cortex_m_rt::entry] -fn main() -> ! { - info!("main: Starting!"); - Executor::take().run(|spawner| { - spawner.spawn(unwrap!(async_main(spawner))); - }); -} - -#[embassy_executor::task] +#[embassy_executor::main(executor = "low_power::Executor")] async fn async_main(_spawner: Spawner) { let mut config = embassy_stm32::Config::default(); // enable HSI clock diff --git a/examples/stm32wle5/src/bin/blinky.rs b/examples/stm32wle5/src/bin/blinky.rs index b2745fdaf..9f0c04672 100644 --- a/examples/stm32wle5/src/bin/blinky.rs +++ b/examples/stm32wle5/src/bin/blinky.rs @@ -6,20 +6,12 @@ use defmt::*; use defmt_rtt as _; use embassy_executor::Spawner; use embassy_stm32::gpio::{Level, Output, Speed}; -use embassy_stm32::low_power::Executor; +use embassy_stm32::low_power; use embassy_time::Timer; use panic_probe as _; use static_cell::StaticCell; -#[cortex_m_rt::entry] -fn main() -> ! { - info!("main: Starting!"); - Executor::take().run(|spawner| { - spawner.spawn(unwrap!(async_main(spawner))); - }); -} - -#[embassy_executor::task] +#[embassy_executor::main(executor = "low_power::Executor")] async fn async_main(_spawner: Spawner) { let mut config = embassy_stm32::Config::default(); // enable HSI clock diff --git a/examples/stm32wle5/src/bin/button_exti.rs b/examples/stm32wle5/src/bin/button_exti.rs index db1bff0be..878eca7d0 100644 --- a/examples/stm32wle5/src/bin/button_exti.rs +++ b/examples/stm32wle5/src/bin/button_exti.rs @@ -7,19 +7,11 @@ use defmt_rtt as _; use embassy_executor::Spawner; use embassy_stm32::exti::ExtiInput; use embassy_stm32::gpio::Pull; -use embassy_stm32::low_power::Executor; +use embassy_stm32::low_power; use panic_probe as _; use static_cell::StaticCell; -#[cortex_m_rt::entry] -fn main() -> ! { - info!("main: Starting!"); - Executor::take().run(|spawner| { - spawner.spawn(unwrap!(async_main(spawner))); - }); -} - -#[embassy_executor::task] +#[embassy_executor::main(executor = "low_power::Executor")] async fn async_main(_spawner: Spawner) { let mut config = embassy_stm32::Config::default(); // enable HSI clock diff --git a/examples/stm32wle5/src/bin/i2c.rs b/examples/stm32wle5/src/bin/i2c.rs index c31c673c9..68c17a672 100644 --- a/examples/stm32wle5/src/bin/i2c.rs +++ b/examples/stm32wle5/src/bin/i2c.rs @@ -6,9 +6,8 @@ use defmt::*; use defmt_rtt as _; use embassy_executor::Spawner; use embassy_stm32::i2c::I2c; -use embassy_stm32::low_power::Executor; use embassy_stm32::time::Hertz; -use embassy_stm32::{bind_interrupts, i2c, peripherals}; +use embassy_stm32::{bind_interrupts, i2c, low_power, peripherals}; use embassy_time::{Duration, Timer}; use panic_probe as _; use static_cell::StaticCell; @@ -18,15 +17,7 @@ bind_interrupts!(struct IrqsI2C{ I2C2_ER => i2c::ErrorInterruptHandler; }); -#[cortex_m_rt::entry] -fn main() -> ! { - info!("main: Starting!"); - Executor::take().run(|spawner| { - spawner.spawn(unwrap!(async_main(spawner))); - }); -} - -#[embassy_executor::task] +#[embassy_executor::main(executor = "low_power::Executor")] async fn async_main(_spawner: Spawner) { let mut config = embassy_stm32::Config::default(); // enable HSI clock -- cgit From 6d2d0c3dee41b03a985890db3d666ac5bff5e956 Mon Sep 17 00:00:00 2001 From: xoviat Date: Sun, 16 Nov 2025 18:47:12 -0600 Subject: wpan: restructure mac driver --- examples/stm32wb/src/bin/mac_ffd_net.rs | 115 +++++--------------------------- 1 file changed, 15 insertions(+), 100 deletions(-) (limited to 'examples') diff --git a/examples/stm32wb/src/bin/mac_ffd_net.rs b/examples/stm32wb/src/bin/mac_ffd_net.rs index 5296943a1..9b705dda9 100644 --- a/examples/stm32wb/src/bin/mac_ffd_net.rs +++ b/examples/stm32wb/src/bin/mac_ffd_net.rs @@ -7,9 +7,7 @@ use embassy_stm32::bind_interrupts; use embassy_stm32::ipcc::{Config, ReceiveInterruptHandler, TransmitInterruptHandler}; use embassy_stm32::rcc::WPAN_DEFAULT; use embassy_stm32_wpan::TlMbox; -use embassy_stm32_wpan::mac::commands::{ResetRequest, SetRequest, StartRequest}; -use embassy_stm32_wpan::mac::typedefs::{MacChannel, PanId, PibId}; -use embassy_stm32_wpan::mac::{self, Runner}; +use embassy_stm32_wpan::mac::{Driver, DriverState, Runner}; use embassy_stm32_wpan::sub::mm; use static_cell::StaticCell; use {defmt_rtt as _, panic_probe as _}; @@ -72,106 +70,23 @@ async fn main(spawner: Spawner) { let result = mbox.sys_subsystem.shci_c2_mac_802_15_4_init().await; info!("initialized mac: {}", result); - info!("resetting"); - mbox.mac_subsystem - .send_command(&ResetRequest { - set_default_pib: true, - ..Default::default() - }) - .await - .unwrap(); - defmt::info!("{:#x}", mbox.mac_subsystem.read().await.unwrap()); - - info!("setting extended address"); - let extended_address: u64 = 0xACDE480000000001; - mbox.mac_subsystem - .send_command(&SetRequest { - pib_attribute_ptr: &extended_address as *const _ as *const u8, - pib_attribute: PibId::ExtendedAddress, - }) - .await - .unwrap(); - defmt::info!("{:#x}", mbox.mac_subsystem.read().await.unwrap()); - - info!("setting short address"); - let short_address: u16 = 0x1122; - mbox.mac_subsystem - .send_command(&SetRequest { - pib_attribute_ptr: &short_address as *const _ as *const u8, - pib_attribute: PibId::ShortAddress, - }) - .await - .unwrap(); - defmt::info!("{:#x}", mbox.mac_subsystem.read().await.unwrap()); - - info!("setting association permit"); - let association_permit: bool = true; - mbox.mac_subsystem - .send_command(&SetRequest { - pib_attribute_ptr: &association_permit as *const _ as *const u8, - pib_attribute: PibId::AssociationPermit, - }) - .await - .unwrap(); - defmt::info!("{:#x}", mbox.mac_subsystem.read().await.unwrap()); - - info!("setting TX power"); - let transmit_power: i8 = 2; - mbox.mac_subsystem - .send_command(&SetRequest { - pib_attribute_ptr: &transmit_power as *const _ as *const u8, - pib_attribute: PibId::TransmitPower, - }) - .await - .unwrap(); - defmt::info!("{:#x}", mbox.mac_subsystem.read().await.unwrap()); - - info!("starting FFD device"); - mbox.mac_subsystem - .send_command(&StartRequest { - pan_id: PanId([0x1A, 0xAA]), - channel_number: MacChannel::Channel16, - beacon_order: 0x0F, - superframe_order: 0x0F, - pan_coordinator: true, - battery_life_extension: false, - ..Default::default() - }) - .await - .unwrap(); - defmt::info!("{:#x}", mbox.mac_subsystem.read().await.unwrap()); - - info!("setting RX on when idle"); - let rx_on_while_idle: bool = true; - mbox.mac_subsystem - .send_command(&SetRequest { - pib_attribute_ptr: &rx_on_while_idle as *const _ as *const u8, - pib_attribute: PibId::RxOnWhenIdle, - }) - .await - .unwrap(); - defmt::info!("{:#x}", mbox.mac_subsystem.read().await.unwrap()); - - static TX1: StaticCell<[u8; 127]> = StaticCell::new(); - static TX2: StaticCell<[u8; 127]> = StaticCell::new(); - static TX3: StaticCell<[u8; 127]> = StaticCell::new(); - static TX4: StaticCell<[u8; 127]> = StaticCell::new(); - static TX5: StaticCell<[u8; 127]> = StaticCell::new(); - let tx_queue = [ - TX1.init([0u8; 127]), - TX2.init([0u8; 127]), - TX3.init([0u8; 127]), - TX4.init([0u8; 127]), - TX5.init([0u8; 127]), - ]; - + static DRIVER_STATE: StaticCell = StaticCell::new(); static RUNNER: StaticCell = StaticCell::new(); - let runner = RUNNER.init(Runner::new(mbox.mac_subsystem, tx_queue)); - spawner.spawn(run_mac(runner).unwrap()); + let driver_state = DRIVER_STATE.init(DriverState::new(mbox.mac_subsystem)); + let (driver, runner, mut control) = Driver::new(driver_state); + + spawner.spawn(run_mac(RUNNER.init(runner)).unwrap()); + + control + .init_link( + 0x1122u16.to_be_bytes().try_into().unwrap(), + 0xACDE480000000001u64.to_be_bytes().try_into().unwrap(), + [0x1A, 0xAA], + ) + .await; - let (driver, control) = mac::new(runner).await; + cortex_m::asm::bkpt(); let _ = driver; - let _ = control; } -- cgit From 21dd55b69ed2418f62a86185b52d6c7df9d6292b Mon Sep 17 00:00:00 2001 From: i509VCB Date: Sat, 25 Oct 2025 13:14:06 -0500 Subject: nxp: generate all chip peripherals and impls from metadata --- examples/lpc55s69/src/bin/pwm.rs | 2 +- examples/lpc55s69/src/bin/usart_async.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'examples') diff --git a/examples/lpc55s69/src/bin/pwm.rs b/examples/lpc55s69/src/bin/pwm.rs index 93b898b9d..8a9894b94 100644 --- a/examples/lpc55s69/src/bin/pwm.rs +++ b/examples/lpc55s69/src/bin/pwm.rs @@ -10,7 +10,7 @@ use {defmt_rtt as _, panic_halt as _}; #[embassy_executor::main] async fn main(_spawner: Spawner) { let p = embassy_nxp::init(Default::default()); - let pwm = Pwm::new_output(p.PWM_OUTPUT1, p.PIO0_18, Config::new(1_000_000_000, 2_000_000_000)); + let pwm = Pwm::new_output(p.SCT0_OUT1, p.PIO0_18, Config::new(1_000_000_000, 2_000_000_000)); loop { info!("Counter: {}", pwm.counter()); Timer::after_millis(50).await; diff --git a/examples/lpc55s69/src/bin/usart_async.rs b/examples/lpc55s69/src/bin/usart_async.rs index b06abd477..a9815b920 100644 --- a/examples/lpc55s69/src/bin/usart_async.rs +++ b/examples/lpc55s69/src/bin/usart_async.rs @@ -38,8 +38,8 @@ async fn main(spawner: Spawner) { p.PIO0_27, p.PIO1_24, Irqs, - p.DMA_CH11, - p.DMA_CH10, + p.DMA0_CH11, + p.DMA0_CH10, Config::default(), ); let led = Output::new(p.PIO1_6, Level::Low); -- cgit From 80ceb42eb1c842fcb214a5fbfbb1c39265c6b29b Mon Sep 17 00:00:00 2001 From: xoviat Date: Mon, 17 Nov 2025 08:23:34 -0600 Subject: wpan_ get net example actually working --- examples/stm32wb/src/bin/mac_ffd_net.rs | 90 +++++++++++++++++++++++++++------ 1 file changed, 75 insertions(+), 15 deletions(-) (limited to 'examples') diff --git a/examples/stm32wb/src/bin/mac_ffd_net.rs b/examples/stm32wb/src/bin/mac_ffd_net.rs index 9b705dda9..5d946b35b 100644 --- a/examples/stm32wb/src/bin/mac_ffd_net.rs +++ b/examples/stm32wb/src/bin/mac_ffd_net.rs @@ -1,30 +1,44 @@ #![no_std] #![no_main] +use core::net::Ipv6Addr; + use defmt::*; use embassy_executor::Spawner; +use embassy_net::udp::{PacketMetadata, UdpSocket}; +use embassy_net::{Ipv6Cidr, StackResources, StaticConfigV6}; use embassy_stm32::bind_interrupts; use embassy_stm32::ipcc::{Config, ReceiveInterruptHandler, TransmitInterruptHandler}; +use embassy_stm32::peripherals::RNG; use embassy_stm32::rcc::WPAN_DEFAULT; +use embassy_stm32::rng::InterruptHandler as RngInterruptHandler; use embassy_stm32_wpan::TlMbox; use embassy_stm32_wpan::mac::{Driver, DriverState, Runner}; use embassy_stm32_wpan::sub::mm; +use embassy_time::{Duration, Timer}; +use heapless::Vec; use static_cell::StaticCell; use {defmt_rtt as _, panic_probe as _}; bind_interrupts!(struct Irqs{ IPCC_C1_RX => ReceiveInterruptHandler; IPCC_C1_TX => TransmitInterruptHandler; + RNG => RngInterruptHandler; }); #[embassy_executor::task] -async fn run_mm_queue(memory_manager: mm::MemoryManager) { - memory_manager.run_queue().await; +async fn run_mm_queue(memory_manager: mm::MemoryManager) -> ! { + memory_manager.run_queue().await +} + +#[embassy_executor::task] +async fn run_mac(runner: &'static Runner<'static>) -> ! { + runner.run().await } #[embassy_executor::task] -async fn run_mac(runner: &'static Runner<'static>) { - runner.run().await; +async fn run_net(mut runner: embassy_net::Runner<'static, Driver<'static>>) -> ! { + runner.run().await } #[embassy_executor::main] @@ -72,21 +86,67 @@ async fn main(spawner: Spawner) { static DRIVER_STATE: StaticCell = StaticCell::new(); static RUNNER: StaticCell = StaticCell::new(); + static RESOURCES: StaticCell> = StaticCell::new(); let driver_state = DRIVER_STATE.init(DriverState::new(mbox.mac_subsystem)); - let (driver, runner, mut control) = Driver::new(driver_state); - spawner.spawn(run_mac(RUNNER.init(runner)).unwrap()); + let (driver, mac_runner, mut control) = Driver::new( + driver_state, + 0x1122u16.to_be_bytes().try_into().unwrap(), + 0xACDE480000000001u64.to_be_bytes().try_into().unwrap(), + ); - control - .init_link( - 0x1122u16.to_be_bytes().try_into().unwrap(), - 0xACDE480000000001u64.to_be_bytes().try_into().unwrap(), - [0x1A, 0xAA], - ) - .await; + // TODO: rng does not work for some reason + // Generate random seed. + // let mut rng = Rng::new(p.RNG, Irqs); + let seed = [0; 8]; + // let _ = rng.async_fill_bytes(&mut seed).await; + let seed = u64::from_le_bytes(seed); - cortex_m::asm::bkpt(); + info!("seed generated"); + + // Init network stack + let ipv6_addr = Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0xc00a, 0x2ff); + + let config = embassy_net::Config::ipv6_static(StaticConfigV6 { + address: Ipv6Cidr::new(ipv6_addr, 104), + gateway: None, + dns_servers: Vec::new(), + }); + + let (stack, eth_runner) = embassy_net::new(driver, config, RESOURCES.init(StackResources::new()), seed); + + // wpan runner + spawner.spawn(run_mac(RUNNER.init(mac_runner)).unwrap()); + + // Launch network task + spawner.spawn(unwrap!(run_net(eth_runner))); + + info!("Network task initialized"); - let _ = driver; + control.init_link([0x1A, 0xAA]).await; + + // Ensure DHCP configuration is up before trying connect + stack.wait_config_up().await; + + info!("Network up"); + + // Then we can use it! + let mut rx_meta = [PacketMetadata::EMPTY]; + let mut rx_buffer = [0; 4096]; + let mut tx_meta = [PacketMetadata::EMPTY]; + let mut tx_buffer = [0; 4096]; + + let mut socket = UdpSocket::new(stack, &mut rx_meta, &mut rx_buffer, &mut tx_meta, &mut tx_buffer); + + let remote_endpoint = (Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0xc00a, 0x2fb), 8000); + + let send_buf = [0u8; 20]; + + socket.bind((ipv6_addr, 8000)).unwrap(); + socket.send_to(&send_buf, remote_endpoint).await.unwrap(); + + Timer::after(Duration::from_secs(2)).await; + + cortex_m::asm::bkpt(); } -- cgit