From 5f366957f31d87030182f80dd2d39dc8a8496883 Mon Sep 17 00:00:00 2001 From: James Munns Date: Fri, 12 Dec 2025 20:45:15 +0100 Subject: Add SOSC support --- examples/mcxa/src/bin/clkout.rs | 85 ++++++++++++++++++++++------------------- 1 file changed, 45 insertions(+), 40 deletions(-) (limited to 'examples') diff --git a/examples/mcxa/src/bin/clkout.rs b/examples/mcxa/src/bin/clkout.rs index 1e52912d3..ba7c8185e 100644 --- a/examples/mcxa/src/bin/clkout.rs +++ b/examples/mcxa/src/bin/clkout.rs @@ -4,6 +4,7 @@ use embassy_executor::Spawner; use embassy_mcxa::clkout::{ClockOut, ClockOutSel, Config, Div4}; use embassy_mcxa::clocks::PoweredClock; +use embassy_mcxa::clocks::config::{SoscConfig, SoscMode, SoscRange}; use embassy_mcxa::gpio::{DriveStrength, Level, Output, SlewRate}; use embassy_time::Timer; use {defmt_rtt as _, embassy_mcxa as hal, panic_probe as _}; @@ -11,58 +12,62 @@ use {defmt_rtt as _, embassy_mcxa as hal, panic_probe as _}; /// Demonstrate CLKOUT, using Pin P4.2 #[embassy_executor::main] async fn main(_spawner: Spawner) { - let p = hal::init(hal::config::Config::default()); + let mut cfg = hal::config::Config::default(); + cfg.clock_cfg.sosc = Some(SoscConfig { + mode: SoscMode::CrystalOscillator, + frequency: 8_000_000, + range: SoscRange::Mhz8To16, + power: PoweredClock::NormalEnabledDeepSleepDisabled, + }); + + let p = hal::init(cfg); + let mut pin = p.P4_2; let mut clkout = p.CLKOUT; - loop { - defmt::info!("Set Low..."); - let mut output = Output::new(pin.reborrow(), Level::Low, DriveStrength::Normal, SlewRate::Slow); - Timer::after_millis(500).await; + const K16_CONFIG: Config = Config { + sel: ClockOutSel::Clk16K, + div: Div4::no_div(), + level: PoweredClock::NormalEnabledDeepSleepDisabled, + }; + const M4_CONFIG: Config = Config { + sel: ClockOutSel::Fro12M, + div: const { Div4::from_divisor(3).unwrap() }, + level: PoweredClock::NormalEnabledDeepSleepDisabled, + }; + const K512_CONFIG: Config = Config { + sel: ClockOutSel::ClkIn, + div: const { Div4::from_divisor(16).unwrap() }, + level: PoweredClock::NormalEnabledDeepSleepDisabled, + }; + let configs = [ + ("16K -> /1 = 16K", K16_CONFIG), + ("12M -> /3 = 4M", M4_CONFIG), + ("8M -> /16 = 512K", K512_CONFIG), + ]; + + loop { defmt::info!("Set High..."); - output.set_high(); - Timer::after_millis(400).await; + let mut output = Output::new(pin.reborrow(), Level::High, DriveStrength::Normal, SlewRate::Slow); + Timer::after_millis(250).await; defmt::info!("Set Low..."); output.set_low(); - Timer::after_millis(500).await; + Timer::after_millis(750).await; - defmt::info!("16k..."); - // Run Clock Out with the 16K clock - let _clock_out = ClockOut::new( - clkout.reborrow(), - pin.reborrow(), - Config { - sel: ClockOutSel::Clk16K, - div: Div4::no_div(), - level: PoweredClock::NormalEnabledDeepSleepDisabled, - }, - ) - .unwrap(); + for (name, conf) in configs.iter() { + defmt::info!("Running {=str}", name); - Timer::after_millis(3000).await; - - defmt::info!("Set Low..."); - drop(_clock_out); + let _clock_out = ClockOut::new(clkout.reborrow(), pin.reborrow(), *conf).unwrap(); - let _output = Output::new(pin.reborrow(), Level::Low, DriveStrength::Normal, SlewRate::Slow); - Timer::after_millis(500).await; + Timer::after_millis(3000).await; - // Run Clock Out with the 12M clock, divided by 3 - defmt::info!("4M..."); - let _clock_out = ClockOut::new( - clkout.reborrow(), - pin.reborrow(), - Config { - sel: ClockOutSel::Fro12M, - div: const { Div4::from_divisor(3).unwrap() }, - level: PoweredClock::NormalEnabledDeepSleepDisabled, - }, - ) - .unwrap(); + defmt::info!("Set Low..."); + drop(_clock_out); - // Let it run for 3 seconds... - Timer::after_millis(3000).await; + let _output = Output::new(pin.reborrow(), Level::Low, DriveStrength::Normal, SlewRate::Slow); + Timer::after_millis(500).await; + } } } -- cgit From d6c65cd0e4b651b1b07e1583562dfccfd5db22b1 Mon Sep 17 00:00:00 2001 From: James Munns Date: Mon, 15 Dec 2025 14:33:47 +0100 Subject: Update example to not explicitly configure range --- examples/mcxa/src/bin/clkout.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'examples') diff --git a/examples/mcxa/src/bin/clkout.rs b/examples/mcxa/src/bin/clkout.rs index ba7c8185e..e6e6a2d3d 100644 --- a/examples/mcxa/src/bin/clkout.rs +++ b/examples/mcxa/src/bin/clkout.rs @@ -4,7 +4,7 @@ use embassy_executor::Spawner; use embassy_mcxa::clkout::{ClockOut, ClockOutSel, Config, Div4}; use embassy_mcxa::clocks::PoweredClock; -use embassy_mcxa::clocks::config::{SoscConfig, SoscMode, SoscRange}; +use embassy_mcxa::clocks::config::{SoscConfig, SoscMode}; use embassy_mcxa::gpio::{DriveStrength, Level, Output, SlewRate}; use embassy_time::Timer; use {defmt_rtt as _, embassy_mcxa as hal, panic_probe as _}; @@ -16,7 +16,6 @@ async fn main(_spawner: Spawner) { cfg.clock_cfg.sosc = Some(SoscConfig { mode: SoscMode::CrystalOscillator, frequency: 8_000_000, - range: SoscRange::Mhz8To16, power: PoweredClock::NormalEnabledDeepSleepDisabled, }); -- cgit From 14d847e1b26ec35b91af50c573af32551437456c Mon Sep 17 00:00:00 2001 From: Lucas Kent Date: Wed, 17 Dec 2025 17:41:53 +1100 Subject: Fix rp webusb example on windows --- examples/rp/src/bin/usb_webusb.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'examples') diff --git a/examples/rp/src/bin/usb_webusb.rs b/examples/rp/src/bin/usb_webusb.rs index 5cecb92f0..edc9a0c52 100644 --- a/examples/rp/src/bin/usb_webusb.rs +++ b/examples/rp/src/bin/usb_webusb.rs @@ -26,6 +26,7 @@ use embassy_rp::usb::{Driver as UsbDriver, InterruptHandler}; use embassy_usb::class::web_usb::{Config as WebUsbConfig, State, Url, WebUsb}; use embassy_usb::driver::{Driver, Endpoint, EndpointIn, EndpointOut}; use embassy_usb::msos::{self, windows_version}; +use embassy_usb::types::InterfaceNumber; use embassy_usb::{Builder, Config}; use {defmt_rtt as _, panic_probe as _}; @@ -56,7 +57,7 @@ async fn main(_spawner: Spawner) { let mut config_descriptor = [0; 256]; let mut bos_descriptor = [0; 256]; let mut control_buf = [0; 64]; - let mut msos_descriptor = [0; 256]; + let mut msos_descriptor = [0; 512]; let webusb_config = WebUsbConfig { max_packet_size: 64, @@ -83,6 +84,14 @@ async fn main(_spawner: Spawner) { // In principle you might want to call msos_feature() just on a specific function, // if your device also has other functions that still use standard class drivers. builder.msos_descriptor(windows_version::WIN8_1, 0); + builder.msos_writer().configuration(0); + builder.msos_writer().function(InterfaceNumber(0)); + builder.msos_feature(msos::CompatibleIdFeatureDescriptor::new("WINUSB", "")); + builder.msos_feature(msos::RegistryPropertyFeatureDescriptor::new( + "DeviceInterfaceGUIDs", + msos::PropertyData::RegMultiSz(DEVICE_INTERFACE_GUIDS), + )); + builder.msos_writer().function(InterfaceNumber(1)); builder.msos_feature(msos::CompatibleIdFeatureDescriptor::new("WINUSB", "")); builder.msos_feature(msos::RegistryPropertyFeatureDescriptor::new( "DeviceInterfaceGUIDs", -- cgit From d113772136548e2bb50cecf1749f73bef72a0fe9 Mon Sep 17 00:00:00 2001 From: xoviat Date: Thu, 18 Dec 2025 07:00:59 -0600 Subject: stm32: cleanup low-power features --- examples/stm32wb/Cargo.toml | 4 ++-- examples/stm32wb/src/bin/blinky.rs | 2 +- examples/stm32wb/src/bin/button_exti.rs | 2 +- examples/stm32wb/src/bin/eddystone_beacon.rs | 2 +- examples/stm32wb/src/bin/gatt_server.rs | 2 +- examples/stm32wb/src/bin/mac_ffd.rs | 2 +- examples/stm32wb/src/bin/mac_ffd_net.rs | 2 +- examples/stm32wb/src/bin/mac_rfd.rs | 2 +- examples/stm32wb/src/bin/tl_mbox.rs | 2 +- examples/stm32wb/src/bin/tl_mbox_ble.rs | 2 +- examples/stm32wb/src/bin/tl_mbox_mac.rs | 2 +- 11 files changed, 12 insertions(+), 12 deletions(-) (limited to 'examples') diff --git a/examples/stm32wb/Cargo.toml b/examples/stm32wb/Cargo.toml index 83f7cb56b..496500f75 100644 --- a/examples/stm32wb/Cargo.toml +++ b/examples/stm32wb/Cargo.toml @@ -7,10 +7,10 @@ publish = false [dependencies] # Change stm32wb55rg to your chip name in both dependencies, if necessary. -embassy-stm32 = { version = "0.4.0", path = "../../embassy-stm32", features = [ "defmt", "stm32wb55rg", "time-driver-any", "memory-x", "exti", "low-power"] } +embassy-stm32 = { version = "0.4.0", path = "../../embassy-stm32", features = [ "defmt", "stm32wb55rg", "time-driver-any", "memory-x", "exti", "low-power-pender"] } embassy-stm32-wpan = { version = "0.1.0", path = "../../embassy-stm32-wpan", features = ["defmt", "stm32wb55rg"] } embassy-sync = { version = "0.7.2", path = "../../embassy-sync", features = ["defmt"] } -embassy-executor = { version = "0.9.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "defmt"] } +embassy-executor = { version = "0.9.0", path = "../../embassy-executor", features = ["defmt"] } embassy-time = { version = "0.5.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } embassy-net = { version = "0.7.1", path = "../../embassy-net", features = ["defmt", "udp", "proto-ipv6", "medium-ieee802154", ], optional = true } diff --git a/examples/stm32wb/src/bin/blinky.rs b/examples/stm32wb/src/bin/blinky.rs index f37e8b1d8..e2737fcd5 100644 --- a/examples/stm32wb/src/bin/blinky.rs +++ b/examples/stm32wb/src/bin/blinky.rs @@ -7,7 +7,7 @@ use embassy_stm32::gpio::{Level, Output, Speed}; use embassy_time::Timer; use {defmt_rtt as _, panic_probe as _}; -#[embassy_executor::main] +#[embassy_executor::main(executor = "embassy_stm32::Executor", entry = "cortex_m_rt::entry")] async fn main(_spawner: Spawner) { let p = embassy_stm32::init(Default::default()); info!("Hello World!"); diff --git a/examples/stm32wb/src/bin/button_exti.rs b/examples/stm32wb/src/bin/button_exti.rs index 3c58eb556..37a207519 100644 --- a/examples/stm32wb/src/bin/button_exti.rs +++ b/examples/stm32wb/src/bin/button_exti.rs @@ -13,7 +13,7 @@ bind_interrupts!( EXTI4 => exti::InterruptHandler; }); -#[embassy_executor::main] +#[embassy_executor::main(executor = "embassy_stm32::Executor", entry = "cortex_m_rt::entry")] async fn main(_spawner: Spawner) { let p = embassy_stm32::init(Default::default()); info!("Hello World!"); diff --git a/examples/stm32wb/src/bin/eddystone_beacon.rs b/examples/stm32wb/src/bin/eddystone_beacon.rs index 413b1ac8f..a679e6fb1 100644 --- a/examples/stm32wb/src/bin/eddystone_beacon.rs +++ b/examples/stm32wb/src/bin/eddystone_beacon.rs @@ -26,7 +26,7 @@ bind_interrupts!(struct Irqs{ const BLE_GAP_DEVICE_NAME_LENGTH: u8 = 7; -#[embassy_executor::main] +#[embassy_executor::main(executor = "embassy_stm32::Executor", entry = "cortex_m_rt::entry")] async fn main(_spawner: Spawner) { /* How to make this work: diff --git a/examples/stm32wb/src/bin/gatt_server.rs b/examples/stm32wb/src/bin/gatt_server.rs index 3484f1844..10c7fd0ba 100644 --- a/examples/stm32wb/src/bin/gatt_server.rs +++ b/examples/stm32wb/src/bin/gatt_server.rs @@ -38,7 +38,7 @@ bind_interrupts!(struct Irqs{ const BLE_GAP_DEVICE_NAME_LENGTH: u8 = 7; -#[embassy_executor::main] +#[embassy_executor::main(executor = "embassy_stm32::Executor", entry = "cortex_m_rt::entry")] async fn main(spawner: Spawner) { /* How to make this work: diff --git a/examples/stm32wb/src/bin/mac_ffd.rs b/examples/stm32wb/src/bin/mac_ffd.rs index 4bab6ea9f..cd15968d2 100644 --- a/examples/stm32wb/src/bin/mac_ffd.rs +++ b/examples/stm32wb/src/bin/mac_ffd.rs @@ -23,7 +23,7 @@ async fn run_mm_queue(mut memory_manager: mm::MemoryManager<'static>) { memory_manager.run_queue().await; } -#[embassy_executor::main] +#[embassy_executor::main(executor = "embassy_stm32::Executor", entry = "cortex_m_rt::entry")] async fn main(spawner: Spawner) { /* How to make this work: diff --git a/examples/stm32wb/src/bin/mac_ffd_net.rs b/examples/stm32wb/src/bin/mac_ffd_net.rs index b4789e3ee..244b35243 100644 --- a/examples/stm32wb/src/bin/mac_ffd_net.rs +++ b/examples/stm32wb/src/bin/mac_ffd_net.rs @@ -41,7 +41,7 @@ async fn run_net(mut runner: embassy_net::Runner<'static, Driver<'static>>) -> ! runner.run().await } -#[embassy_executor::main] +#[embassy_executor::main(executor = "embassy_stm32::Executor", entry = "cortex_m_rt::entry")] async fn main(spawner: Spawner) { /* How to make this work: diff --git a/examples/stm32wb/src/bin/mac_rfd.rs b/examples/stm32wb/src/bin/mac_rfd.rs index dae3c5200..f3e65c66b 100644 --- a/examples/stm32wb/src/bin/mac_rfd.rs +++ b/examples/stm32wb/src/bin/mac_rfd.rs @@ -25,7 +25,7 @@ async fn run_mm_queue(mut memory_manager: mm::MemoryManager<'static>) { memory_manager.run_queue().await; } -#[embassy_executor::main] +#[embassy_executor::main(executor = "embassy_stm32::Executor", entry = "cortex_m_rt::entry")] async fn main(spawner: Spawner) { /* How to make this work: diff --git a/examples/stm32wb/src/bin/tl_mbox.rs b/examples/stm32wb/src/bin/tl_mbox.rs index 0902e28e8..adb6eff7b 100644 --- a/examples/stm32wb/src/bin/tl_mbox.rs +++ b/examples/stm32wb/src/bin/tl_mbox.rs @@ -15,7 +15,7 @@ bind_interrupts!(struct Irqs{ IPCC_C1_TX => TransmitInterruptHandler; }); -#[embassy_executor::main] +#[embassy_executor::main(executor = "embassy_stm32::Executor", entry = "cortex_m_rt::entry")] async fn main(_spawner: Spawner) { /* How to make this work: diff --git a/examples/stm32wb/src/bin/tl_mbox_ble.rs b/examples/stm32wb/src/bin/tl_mbox_ble.rs index 763dc32cd..376b808de 100644 --- a/examples/stm32wb/src/bin/tl_mbox_ble.rs +++ b/examples/stm32wb/src/bin/tl_mbox_ble.rs @@ -20,7 +20,7 @@ async fn run_mm_queue(mut memory_manager: mm::MemoryManager<'static>) { memory_manager.run_queue().await; } -#[embassy_executor::main] +#[embassy_executor::main(executor = "embassy_stm32::Executor", entry = "cortex_m_rt::entry")] async fn main(spawner: Spawner) { /* How to make this work: diff --git a/examples/stm32wb/src/bin/tl_mbox_mac.rs b/examples/stm32wb/src/bin/tl_mbox_mac.rs index 235a48241..697e061c1 100644 --- a/examples/stm32wb/src/bin/tl_mbox_mac.rs +++ b/examples/stm32wb/src/bin/tl_mbox_mac.rs @@ -20,7 +20,7 @@ async fn run_mm_queue(mut memory_manager: mm::MemoryManager<'static>) { memory_manager.run_queue().await; } -#[embassy_executor::main] +#[embassy_executor::main(executor = "embassy_stm32::Executor", entry = "cortex_m_rt::entry")] async fn main(spawner: Spawner) { /* How to make this work: -- cgit