From 4c98cda167ab8b704ff087be7af99a8db5915d31 Mon Sep 17 00:00:00 2001 From: korbin Date: Sun, 27 Jul 2025 06:47:25 -0600 Subject: add missing PartialEq and Eq trait derives to embassy-net config structs --- embassy-net/src/lib.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/embassy-net/src/lib.rs b/embassy-net/src/lib.rs index 2b1888170..0bc6ffe6c 100644 --- a/embassy-net/src/lib.rs +++ b/embassy-net/src/lib.rs @@ -171,7 +171,7 @@ impl Default for DhcpConfig { } /// Network stack configuration. -#[derive(Debug, Clone, Default)] +#[derive(Debug, Clone, Default, PartialEq, Eq)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] #[non_exhaustive] pub struct Config { @@ -223,7 +223,7 @@ impl Config { /// Network stack IPv4 configuration. #[cfg(feature = "proto-ipv4")] -#[derive(Debug, Clone, Default)] +#[derive(Debug, Clone, Default, PartialEq, Eq)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] pub enum ConfigV4 { /// Do not configure IPv4. @@ -238,7 +238,7 @@ pub enum ConfigV4 { /// Network stack IPv6 configuration. #[cfg(feature = "proto-ipv6")] -#[derive(Debug, Clone, Default)] +#[derive(Debug, Clone, Default, PartialEq, Eq)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] pub enum ConfigV6 { /// Do not configure IPv6. -- cgit From 1b3674b30ac2b7deb8e19b132d5ba15351cb8ebd Mon Sep 17 00:00:00 2001 From: Gerzain Mata Date: Sun, 27 Jul 2025 09:35:13 -0700 Subject: Added changes based on PR review --- embassy-stm32/build.rs | 2 +- embassy-stm32/src/rcc/wba.rs | 27 ++++----------------------- embassy-stm32/src/usb/otg.rs | 2 +- examples/stm32wba/src/bin/pwm.rs | 3 +-- 4 files changed, 7 insertions(+), 27 deletions(-) diff --git a/embassy-stm32/build.rs b/embassy-stm32/build.rs index 73860c64a..a4ed86bdf 100644 --- a/embassy-stm32/build.rs +++ b/embassy-stm32/build.rs @@ -1599,7 +1599,7 @@ fn main() { for e in rcc_registers.ir.enums { fn is_rcc_name(e: &str) -> bool { match e { - "Pllp" | "Pllq" | "Pllr" | "Pllm" | "Plln" | "Prediv1" | "Prediv2" => true, + "Pllp" | "Pllq" | "Pllr" | "Pllm" | "Plln" | "Prediv1" | "Prediv2" | "Hpre5" => true, "Timpre" | "Pllrclkpre" => false, e if e.ends_with("pre") || e.ends_with("pres") || e.ends_with("div") || e.ends_with("mul") => true, _ => false, diff --git a/embassy-stm32/src/rcc/wba.rs b/embassy-stm32/src/rcc/wba.rs index 0025d2a51..5f9d4d30a 100644 --- a/embassy-stm32/src/rcc/wba.rs +++ b/embassy-stm32/src/rcc/wba.rs @@ -1,6 +1,5 @@ pub use crate::pac::pwr::vals::Vos as VoltageScale; use crate::pac::rcc::regs::Cfgr1; -use core::ops::Div; pub use crate::pac::rcc::vals::{ Hpre as AHBPrescaler, Hsepre as HsePrescaler, Ppre as APBPrescaler, Sw as Sysclk, Pllsrc as PllSource, Plldiv as PllDiv, Pllm as PllPreDiv, Plln as PllMul, Hpre5 as AHB5Prescaler, Hdiv5, @@ -21,23 +20,6 @@ pub const HSI_FREQ: Hertz = Hertz(16_000_000); // HSE speed pub const HSE_FREQ: Hertz = Hertz(32_000_000); -// Allow dividing a Hertz value by an AHB5 prescaler directly -impl Div for Hertz { - type Output = Hertz; - fn div(self, rhs: AHB5Prescaler) -> Hertz { - // Map the prescaler enum to its integer divisor - let divisor = match rhs { - AHB5Prescaler::DIV1 => 1, - AHB5Prescaler::DIV2 => 2, - AHB5Prescaler::DIV3 => 3, - AHB5Prescaler::DIV4 => 4, - AHB5Prescaler::DIV6 => 6, - _ => unreachable!("Invalid AHB5 prescaler: {:?}", rhs), - }; - Hertz(self.0 / divisor) - } -} - #[derive(Clone, Copy, Eq, PartialEq)] pub struct Hse { pub prescaler: HsePrescaler, @@ -95,8 +77,7 @@ pub struct Config { pub apb7_pre: APBPrescaler, // low speed LSI/LSE/RTC - pub lsi: super::LsConfig, - // pub lsi2: super::LsConfig, + pub ls: super::LsConfig, pub voltage_scale: VoltageScale, @@ -116,7 +97,7 @@ impl Config { apb1_pre: APBPrescaler::DIV1, apb2_pre: APBPrescaler::DIV1, apb7_pre: APBPrescaler::DIV1, - lsi: crate::rcc::LsConfig::new(), + ls: crate::rcc::LsConfig::new(), // lsi2: crate::rcc::LsConfig::new(), voltage_scale: VoltageScale::RANGE2, mux: super::mux::ClockMux::default(), @@ -151,7 +132,7 @@ pub(crate) unsafe fn init(config: Config) { crate::pac::PWR.vosr().write(|w| w.set_vos(config.voltage_scale)); while !crate::pac::PWR.vosr().read().vosrdy() {} - let rtc = config.lsi.init(); + let rtc = config.ls.init(); let hsi = config.hsi.then(|| { hsi_enable(); @@ -276,7 +257,7 @@ pub(crate) unsafe fn init(config: Config) { w.set_clksel(usb_refck_sel); }); - let lsi = config.lsi.lsi.then_some(LSI_FREQ); + let lsi = config.ls.lsi.then_some(LSI_FREQ); config.mux.init(); diff --git a/embassy-stm32/src/usb/otg.rs b/embassy-stm32/src/usb/otg.rs index b074cfa1b..81e6bff4c 100644 --- a/embassy-stm32/src/usb/otg.rs +++ b/embassy-stm32/src/usb/otg.rs @@ -336,7 +336,7 @@ impl<'d, T: Instance> Bus<'d, T> { critical_section::with(|_| { crate::pac::RCC.ahb2enr().modify(|w| { w.set_usb_otg_hsen(true); - w.set_otghsphyen(true); + w.set_usb_otg_hs_phyen(true); }); }); } diff --git a/examples/stm32wba/src/bin/pwm.rs b/examples/stm32wba/src/bin/pwm.rs index 54d223d34..611d7c097 100644 --- a/examples/stm32wba/src/bin/pwm.rs +++ b/examples/stm32wba/src/bin/pwm.rs @@ -5,7 +5,7 @@ use defmt::*; use defmt_rtt as _; // global logger use embassy_executor::Spawner; use embassy_stm32::gpio::OutputType; -use embassy_stm32::rcc::{mux, AHB5Prescaler, AHBPrescaler, APBPrescaler, Sysclk, VoltageScale}; +use embassy_stm32::rcc::{AHB5Prescaler, AHBPrescaler, APBPrescaler, Sysclk, VoltageScale}; use embassy_stm32::rcc::{PllDiv, PllMul, PllPreDiv, PllSource}; use embassy_stm32::time::khz; use embassy_stm32::timer::simple_pwm::{PwmPin, SimplePwm}; @@ -39,7 +39,6 @@ async fn main(_spawner: Spawner) { // voltage scale for max performance config.rcc.voltage_scale = VoltageScale::RANGE1; // route PLL1_P into the USB‐OTG‐HS block - config.rcc.mux.otghssel = mux::Otghssel::PLL1_P; config.rcc.sys = Sysclk::PLL1_R; let p = embassy_stm32::init(config); -- cgit From 982117f5b0650734aece226d93343a30ac3a0b65 Mon Sep 17 00:00:00 2001 From: Gerzain Mata Date: Sun, 27 Jul 2025 09:42:17 -0700 Subject: Cargo fmt --- embassy-stm32/src/rcc/wba.rs | 33 +++++++++++++++++---------------- examples/stm32wba/src/bin/pwm.rs | 5 +++-- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/embassy-stm32/src/rcc/wba.rs b/embassy-stm32/src/rcc/wba.rs index 5f9d4d30a..56ba7b58b 100644 --- a/embassy-stm32/src/rcc/wba.rs +++ b/embassy-stm32/src/rcc/wba.rs @@ -1,20 +1,18 @@ pub use crate::pac::pwr::vals::Vos as VoltageScale; use crate::pac::rcc::regs::Cfgr1; +#[cfg(all(peri_usb_otg_hs))] +pub use crate::pac::rcc::vals::Otghssel; +use crate::pac::rcc::vals::Pllrge; pub use crate::pac::rcc::vals::{ - Hpre as AHBPrescaler, Hsepre as HsePrescaler, Ppre as APBPrescaler, Sw as Sysclk, Pllsrc as PllSource, - Plldiv as PllDiv, Pllm as PllPreDiv, Plln as PllMul, Hpre5 as AHB5Prescaler, Hdiv5, + Hdiv5, Hpre as AHBPrescaler, Hpre5 as AHB5Prescaler, Hsepre as HsePrescaler, Plldiv as PllDiv, Pllm as PllPreDiv, + Plln as PllMul, Pllsrc as PllSource, Ppre as APBPrescaler, Sw as Sysclk, }; -use crate::pac::rcc::vals::Pllrge; +#[cfg(all(peri_usb_otg_hs))] +pub use crate::pac::{syscfg::vals::Usbrefcksel, SYSCFG}; use crate::pac::{FLASH, RCC}; use crate::rcc::LSI_FREQ; use crate::time::Hertz; -#[cfg(all(peri_usb_otg_hs))] -pub use crate::pac::rcc::vals::Otghssel; - -#[cfg(all(peri_usb_otg_hs))] -pub use crate::pac::{syscfg::vals::Usbrefcksel, SYSCFG}; - /// HSI speed pub const HSI_FREQ: Hertz = Hertz(16_000_000); // HSE speed @@ -150,7 +148,7 @@ pub(crate) unsafe fn init(config: Config) { HSE_FREQ }); - let pll_input = PllInput {hse, hsi }; + let pll_input = PllInput { hse, hsi }; let pll1 = init_pll(config.pll1, &pll_input, config.voltage_scale); @@ -231,7 +229,6 @@ pub(crate) unsafe fn init(config: Config) { let hclk5 = sys_clk / config.ahb5_pre; - #[cfg(all(stm32wba, peri_usb_otg_hs))] let usb_refck = match config.mux.otghssel { Otghssel::HSE => hse, @@ -341,7 +338,7 @@ fn init_pll(config: Option, input: &PllInput, voltage_range: VoltageScale) // let vco_freq = ref_freq * pll.mul; // Calculate VCO frequency including fractional part: FVCO = Fref_ck × (N + FRAC/2^13) let numerator = (ref_freq.0 as u64) * (((pll.mul as u64) + 1 << 13) + pll.frac.unwrap_or(0) as u64); - let vco_hz = (numerator >> 13) as u32; + let vco_hz = (numerator >> 13) as u32; let vco_freq = Hertz(vco_hz); assert!(vco_freq >= vco_min && vco_freq <= vco_max); @@ -362,7 +359,9 @@ fn init_pll(config: Option, input: &PllInput, voltage_range: VoltageScale) w.set_pllq(pll.divq.unwrap_or(PllDiv::DIV1)); w.set_pllr(pll.divr.unwrap_or(PllDiv::DIV1)); }); - RCC.pll1fracr().write(|w| {w.set_pllfracn(pll.frac.unwrap_or(0));}); + RCC.pll1fracr().write(|w| { + w.set_pllfracn(pll.frac.unwrap_or(0)); + }); let input_range = match ref_freq.0 { ..=8_000_000 => Pllrge::FREQ_4TO8MHZ, @@ -381,10 +380,12 @@ fn init_pll(config: Option, input: &PllInput, voltage_range: VoltageScale) }; } - RCC.pll1cfgr().write(|w| {write_fields!(w);}); + RCC.pll1cfgr().write(|w| { + write_fields!(w); + }); // Enable PLL pll_enable(true); - PllOutput{ p, q, r } -} \ No newline at end of file + PllOutput { p, q, r } +} diff --git a/examples/stm32wba/src/bin/pwm.rs b/examples/stm32wba/src/bin/pwm.rs index 611d7c097..2c696834a 100644 --- a/examples/stm32wba/src/bin/pwm.rs +++ b/examples/stm32wba/src/bin/pwm.rs @@ -5,8 +5,9 @@ use defmt::*; use defmt_rtt as _; // global logger use embassy_executor::Spawner; use embassy_stm32::gpio::OutputType; -use embassy_stm32::rcc::{AHB5Prescaler, AHBPrescaler, APBPrescaler, Sysclk, VoltageScale}; -use embassy_stm32::rcc::{PllDiv, PllMul, PllPreDiv, PllSource}; +use embassy_stm32::rcc::{ + AHB5Prescaler, AHBPrescaler, APBPrescaler, PllDiv, PllMul, PllPreDiv, PllSource, Sysclk, VoltageScale, +}; use embassy_stm32::time::khz; use embassy_stm32::timer::simple_pwm::{PwmPin, SimplePwm}; use embassy_stm32::Config; -- cgit From 21566666b852e38641ef8ccb3d2b988dfd5a34c5 Mon Sep 17 00:00:00 2001 From: Oscar Aurin Date: Sun, 13 Jul 2025 23:41:17 +0200 Subject: examples: fix RP2040 link establishing logic --- examples/rp/src/bin/wifi_tcp_server.rs | 27 +++++++++++---------------- examples/rp/src/bin/wifi_webrequest.rs | 33 ++++++++++----------------------- 2 files changed, 21 insertions(+), 39 deletions(-) diff --git a/examples/rp/src/bin/wifi_tcp_server.rs b/examples/rp/src/bin/wifi_tcp_server.rs index fbc957e0e..ed1a03fcf 100644 --- a/examples/rp/src/bin/wifi_tcp_server.rs +++ b/examples/rp/src/bin/wifi_tcp_server.rs @@ -18,7 +18,7 @@ use embassy_rp::clocks::RoscRng; 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 embassy_time::Duration; use embedded_io_async::Write; use static_cell::StaticCell; use {defmt_rtt as _, panic_probe as _}; @@ -97,26 +97,21 @@ async fn main(spawner: Spawner) { unwrap!(spawner.spawn(net_task(runner))); - loop { - match control - .join(WIFI_NETWORK, JoinOptions::new(WIFI_PASSWORD.as_bytes())) - .await - { - Ok(_) => break, - Err(err) => { - info!("join failed with status={}", err.status); - } - } + while let Err(err) = control + .join(WIFI_NETWORK, JoinOptions::new(WIFI_PASSWORD.as_bytes())) + .await + { + info!("join failed with status={}", err.status); } - // Wait for DHCP, not necessary when using static IP + info!("waiting for link..."); + stack.wait_link_up().await; + info!("waiting for DHCP..."); - while !stack.is_config_up() { - Timer::after_millis(100).await; - } - info!("DHCP is now up!"); + stack.wait_config_up().await; // And now we can use it! + info!("Stack is up!"); let mut rx_buffer = [0; 4096]; let mut tx_buffer = [0; 4096]; diff --git a/examples/rp/src/bin/wifi_webrequest.rs b/examples/rp/src/bin/wifi_webrequest.rs index 1efd1cd28..a75253bb0 100644 --- a/examples/rp/src/bin/wifi_webrequest.rs +++ b/examples/rp/src/bin/wifi_webrequest.rs @@ -100,33 +100,20 @@ async fn main(spawner: Spawner) { unwrap!(spawner.spawn(net_task(runner))); - loop { - match control - .join(WIFI_NETWORK, JoinOptions::new(WIFI_PASSWORD.as_bytes())) - .await - { - Ok(_) => break, - Err(err) => { - info!("join failed with status={}", err.status); - } - } - } - - // Wait for DHCP, not necessary when using static IP - info!("waiting for DHCP..."); - while !stack.is_config_up() { - Timer::after_millis(100).await; + while let Err(err) = control + .join(WIFI_NETWORK, JoinOptions::new(WIFI_PASSWORD.as_bytes())) + .await + { + info!("join failed with status={}", err.status); } - info!("DHCP is now up!"); - info!("waiting for link up..."); - while !stack.is_link_up() { - Timer::after_millis(500).await; - } - info!("Link is up!"); + info!("waiting for link..."); + stack.wait_link_up().await; - info!("waiting for stack to be up..."); + info!("waiting for DHCP..."); stack.wait_config_up().await; + + // And now we can use it! info!("Stack is up!"); // And now we can use it! -- cgit From 05f1c75f8b01e36e641dca35b6d6f763b6babde5 Mon Sep 17 00:00:00 2001 From: Gerzain Mata Date: Sun, 27 Jul 2025 14:24:36 -0700 Subject: Fixed timer config on STM32WBA pwm example --- examples/stm32wba/src/bin/pwm.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/stm32wba/src/bin/pwm.rs b/examples/stm32wba/src/bin/pwm.rs index 2c696834a..de690fda0 100644 --- a/examples/stm32wba/src/bin/pwm.rs +++ b/examples/stm32wba/src/bin/pwm.rs @@ -44,8 +44,8 @@ async fn main(_spawner: Spawner) { let p = embassy_stm32::init(config); - let ch1_pin = PwmPin::new(p.PA2, OutputType::PushPull); - let mut pwm = SimplePwm::new(p.TIM3, Some(ch1_pin), None, None, None, khz(10), Default::default()); + let ch1_pin = PwmPin::new(p.PB8, OutputType::PushPull); + let mut pwm = SimplePwm::new(p.TIM1, Some(ch1_pin), None, None, None, khz(10), Default::default()); let mut ch1 = pwm.ch1(); ch1.enable(); -- cgit From c708cefe03363135c466a3c0e8543a95973bce7a Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Sun, 27 Jul 2025 23:38:23 +0200 Subject: Add cooldown to doc, book jobs. --- .github/ci/book.sh | 2 ++ .github/ci/doc.sh | 1 + 2 files changed, 3 insertions(+) diff --git a/.github/ci/book.sh b/.github/ci/book.sh index c91d10d16..dada4b348 100755 --- a/.github/ci/book.sh +++ b/.github/ci/book.sh @@ -2,6 +2,7 @@ ## on push branch=main ## priority -100 ## dedup dequeue +## cooldown 15m set -euxo pipefail @@ -17,3 +18,4 @@ kubectl exec $POD -- mkdir -p /usr/share/nginx/html kubectl cp book.tar $POD:/usr/share/nginx/html/ kubectl exec $POD -- find /usr/share/nginx/html kubectl exec $POD -- tar -C /usr/share/nginx/html -xvf /usr/share/nginx/html/book.tar +3 diff --git a/.github/ci/doc.sh b/.github/ci/doc.sh index 26971afdc..ac96008d8 100755 --- a/.github/ci/doc.sh +++ b/.github/ci/doc.sh @@ -2,6 +2,7 @@ ## on push branch=main ## priority -100 ## dedup dequeue +## cooldown 15m set -euxo pipefail -- cgit