From 78f709a3621a50b434206a6200ae18ce7f5a0194 Mon Sep 17 00:00:00 2001 From: Carlos Barrales Ruiz Date: Sat, 9 Dec 2023 14:14:34 +0100 Subject: [PATCH 001/124] * Add GP TIM9 and TIM11 to be used as time_driver --- embassy-stm32/Cargo.toml | 4 ++++ embassy-stm32/build.rs | 8 +++++++- embassy-stm32/src/time_driver.rs | 21 ++++++++++++++++++++- 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/embassy-stm32/Cargo.toml b/embassy-stm32/Cargo.toml index f8c4313e5..074538d3b 100644 --- a/embassy-stm32/Cargo.toml +++ b/embassy-stm32/Cargo.toml @@ -120,6 +120,10 @@ time-driver-tim3 = ["_time-driver"] time-driver-tim4 = ["_time-driver"] ## Use TIM5 as time driver time-driver-tim5 = ["_time-driver"] +## Use TIM9 as time driver +time-driver-tim9 = ["_time-driver"] +## Use TIM11 as time driver +time-driver-tim11 = ["_time-driver"] ## Use TIM12 as time driver time-driver-tim12 = ["_time-driver"] ## Use TIM15 as time driver diff --git a/embassy-stm32/build.rs b/embassy-stm32/build.rs index 0eef43ac4..bb60d244f 100644 --- a/embassy-stm32/build.rs +++ b/embassy-stm32/build.rs @@ -187,6 +187,8 @@ fn main() { Some("tim3") => "TIM3", Some("tim4") => "TIM4", Some("tim5") => "TIM5", + Some("tim9") => "TIM9", + Some("tim11") => "TIM11", Some("tim12") => "TIM12", Some("tim15") => "TIM15", Some("any") => { @@ -198,12 +200,16 @@ fn main() { "TIM4" } else if singletons.contains(&"TIM5".to_string()) { "TIM5" + } else if singletons.contains(&"TIM9".to_string()) { + "TIM9" + } else if singletons.contains(&"TIM11".to_string()) { + "TIM11" } else if singletons.contains(&"TIM12".to_string()) { "TIM12" } else if singletons.contains(&"TIM15".to_string()) { "TIM15" } else { - panic!("time-driver-any requested, but the chip doesn't have TIM2, TIM3, TIM4, TIM5, TIM12 or TIM15.") + panic!("time-driver-any requested, but the chip doesn't have TIM2, TIM3, TIM4, TIM5, TIM9, TIM11, TIM12 or TIM15.") } } _ => panic!("unknown time_driver {:?}", time_driver), diff --git a/embassy-stm32/src/time_driver.rs b/embassy-stm32/src/time_driver.rs index e2a4cc4da..ea9c22d87 100644 --- a/embassy-stm32/src/time_driver.rs +++ b/embassy-stm32/src/time_driver.rs @@ -43,7 +43,10 @@ type T = peripherals::TIM3; type T = peripherals::TIM4; #[cfg(time_driver_tim5)] type T = peripherals::TIM5; - +#[cfg(time_driver_tim9)] +type T = peripherals::TIM9; +#[cfg(time_driver_tim11)] +type T = peripherals::TIM11; #[cfg(time_driver_tim12)] type T = peripherals::TIM12; #[cfg(time_driver_tim15)] @@ -82,6 +85,22 @@ foreach_interrupt! { DRIVER.on_interrupt() } }; + (TIM9, timer, $block:ident, UP, $irq:ident) => { + #[cfg(time_driver_tim9)] + #[cfg(feature = "rt")] + #[interrupt] + fn $irq() { + DRIVER.on_interrupt() + } + }; + (TIM11, timer, $block:ident, UP, $irq:ident) => { + #[cfg(time_driver_tim11)] + #[cfg(feature = "rt")] + #[interrupt] + fn $irq() { + DRIVER.on_interrupt() + } + }; (TIM12, timer, $block:ident, UP, $irq:ident) => { #[cfg(time_driver_tim12)] #[cfg(feature = "rt")] From dfba51d3f2a4d6866f6d6de98fde9a620cda20b7 Mon Sep 17 00:00:00 2001 From: lights0123 Date: Sun, 10 Dec 2023 18:39:45 -0500 Subject: [PATCH 002/124] stm32: usart pin inversion --- embassy-stm32/src/usart/mod.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/embassy-stm32/src/usart/mod.rs b/embassy-stm32/src/usart/mod.rs index d5828a492..dfa1f3a6a 100644 --- a/embassy-stm32/src/usart/mod.rs +++ b/embassy-stm32/src/usart/mod.rs @@ -132,6 +132,14 @@ pub struct Config { /// Set this to true to swap the RX and TX pins. #[cfg(any(usart_v3, usart_v4))] pub swap_rx_tx: bool, + + /// Set this to true to invert TX pin signal values (VDD =0/mark, Gnd = 1/idle). + #[cfg(any(usart_v3, usart_v4))] + pub invert_tx: bool, + + /// Set this to true to invert RX pin signal values (VDD =0/mark, Gnd = 1/idle). + #[cfg(any(usart_v3, usart_v4))] + pub invert_rx: bool, } impl Default for Config { @@ -147,6 +155,10 @@ impl Default for Config { assume_noise_free: false, #[cfg(any(usart_v3, usart_v4))] swap_rx_tx: false, + #[cfg(any(usart_v3, usart_v4))] + invert_tx: false, + #[cfg(any(usart_v3, usart_v4))] + invert_rx: false, } } } @@ -972,7 +984,11 @@ fn configure( }); #[cfg(any(usart_v3, usart_v4))] - w.set_swap(config.swap_rx_tx); + { + w.set_txinv(config.invert_tx); + w.set_rxinv(config.invert_rx); + w.set_swap(config.swap_rx_tx); + } }); #[cfg(not(usart_v1))] From 13af76af88a82f6c0f453b66520f0ff83df09c2d Mon Sep 17 00:00:00 2001 From: Corey Schuhen Date: Mon, 11 Dec 2023 21:08:58 +1000 Subject: [PATCH 003/124] Add example for using CAN with STM32F103 (BluePill) with a real CAN --- examples/stm32f1/src/bin/can.rs | 79 +++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 examples/stm32f1/src/bin/can.rs diff --git a/examples/stm32f1/src/bin/can.rs b/examples/stm32f1/src/bin/can.rs new file mode 100644 index 000000000..abe60b350 --- /dev/null +++ b/examples/stm32f1/src/bin/can.rs @@ -0,0 +1,79 @@ +#![no_std] +#![no_main] +#![feature(type_alias_impl_trait)] + +use defmt::*; +use embassy_executor::Spawner; +use embassy_stm32::bind_interrupts; +use embassy_stm32::can::bxcan::filter::Mask32; +use embassy_stm32::can::bxcan::{Fifo, Frame, StandardId, Id}; +use embassy_stm32::can::{Can, Rx0InterruptHandler, Rx1InterruptHandler, SceInterruptHandler, TxInterruptHandler}; +use embassy_stm32::Config; + +use embassy_stm32::peripherals::CAN; +use {defmt_rtt as _, panic_probe as _}; + +bind_interrupts!(struct Irqs { + USB_LP_CAN1_RX0 => Rx0InterruptHandler; + CAN1_RX1 => Rx1InterruptHandler; + CAN1_SCE => SceInterruptHandler; + USB_HP_CAN1_TX => TxInterruptHandler; +}); + +// This example is configured to work with real CAN transceivers on B8/B9. +// See other examples for loopback. + + +#[embassy_executor::main] +async fn main(_spawner: Spawner) { + + let p = embassy_stm32::init(Config::default()); + + // Set alternate pin mapping to B8/B9 + embassy_stm32::pac::AFIO.mapr().modify(|w| w.set_can1_remap(2)); + + let mut can = Can::new(p.CAN, p.PB8, p.PB9, Irqs); + + + can.as_mut() + .modify_filters() + .enable_bank(0, Fifo::Fifo0, Mask32::accept_all()); + + can.as_mut() + .modify_config() + .set_loopback(false) + .set_silent(false) + .leave_disabled(); + + + can.set_bitrate(250_000); + + can.enable().await; + + + let mut i: u8 = 0; + loop { + let tx_frame = Frame::new_data(unwrap!(StandardId::new(i as _)), [i]); + can.write(&tx_frame).await; + + match can.read().await { + Ok(env) => { + + match env.frame.id() { + Id::Extended(id) => { + defmt::println!("Extended Frame id={:x}", id.as_raw()); + }, + Id::Standard(id) => { + defmt::println!("Standard Frame id={:x}", id.as_raw()); + }, + } + + }, + Err(err) => { + defmt::println!("Error {}", err); + + } + } + i += 1; + } +} From b34c8e3eb1f3adab3e28c3b0b8ae3ab4c339c33b Mon Sep 17 00:00:00 2001 From: Corey Schuhen Date: Mon, 11 Dec 2023 21:25:05 +1000 Subject: [PATCH 004/124] Update formatting. --- examples/stm32f1/src/bin/can.rs | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/examples/stm32f1/src/bin/can.rs b/examples/stm32f1/src/bin/can.rs index abe60b350..625a3843c 100644 --- a/examples/stm32f1/src/bin/can.rs +++ b/examples/stm32f1/src/bin/can.rs @@ -4,13 +4,12 @@ use defmt::*; use embassy_executor::Spawner; -use embassy_stm32::bind_interrupts; use embassy_stm32::can::bxcan::filter::Mask32; -use embassy_stm32::can::bxcan::{Fifo, Frame, StandardId, Id}; +use embassy_stm32::can::bxcan::{Fifo, Frame, Id, StandardId}; use embassy_stm32::can::{Can, Rx0InterruptHandler, Rx1InterruptHandler, SceInterruptHandler, TxInterruptHandler}; -use embassy_stm32::Config; use embassy_stm32::peripherals::CAN; +use embassy_stm32::{bind_interrupts, Config}; use {defmt_rtt as _, panic_probe as _}; bind_interrupts!(struct Irqs { @@ -23,10 +22,8 @@ bind_interrupts!(struct Irqs { // This example is configured to work with real CAN transceivers on B8/B9. // See other examples for loopback. - #[embassy_executor::main] async fn main(_spawner: Spawner) { - let p = embassy_stm32::init(Config::default()); // Set alternate pin mapping to B8/B9 @@ -34,7 +31,6 @@ async fn main(_spawner: Spawner) { let mut can = Can::new(p.CAN, p.PB8, p.PB9, Irqs); - can.as_mut() .modify_filters() .enable_bank(0, Fifo::Fifo0, Mask32::accept_all()); @@ -44,34 +40,27 @@ async fn main(_spawner: Spawner) { .set_loopback(false) .set_silent(false) .leave_disabled(); - can.set_bitrate(250_000); can.enable().await; - let mut i: u8 = 0; loop { let tx_frame = Frame::new_data(unwrap!(StandardId::new(i as _)), [i]); can.write(&tx_frame).await; match can.read().await { - Ok(env) => { - - match env.frame.id() { - Id::Extended(id) => { - defmt::println!("Extended Frame id={:x}", id.as_raw()); - }, - Id::Standard(id) => { - defmt::println!("Standard Frame id={:x}", id.as_raw()); - }, + Ok(env) => match env.frame.id() { + Id::Extended(id) => { + defmt::println!("Extended Frame id={:x}", id.as_raw()); + } + Id::Standard(id) => { + defmt::println!("Standard Frame id={:x}", id.as_raw()); } - }, Err(err) => { defmt::println!("Error {}", err); - } } i += 1; From 3626deecaab1ed5b2f2c97ef49f6dbf058ad068a Mon Sep 17 00:00:00 2001 From: Corey Schuhen Date: Mon, 11 Dec 2023 21:26:23 +1000 Subject: [PATCH 005/124] More formatting. --- examples/stm32f1/src/bin/can.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/examples/stm32f1/src/bin/can.rs b/examples/stm32f1/src/bin/can.rs index 625a3843c..a5ce819d4 100644 --- a/examples/stm32f1/src/bin/can.rs +++ b/examples/stm32f1/src/bin/can.rs @@ -7,7 +7,6 @@ use embassy_executor::Spawner; use embassy_stm32::can::bxcan::filter::Mask32; use embassy_stm32::can::bxcan::{Fifo, Frame, Id, StandardId}; use embassy_stm32::can::{Can, Rx0InterruptHandler, Rx1InterruptHandler, SceInterruptHandler, TxInterruptHandler}; - use embassy_stm32::peripherals::CAN; use embassy_stm32::{bind_interrupts, Config}; use {defmt_rtt as _, panic_probe as _}; @@ -54,7 +53,7 @@ async fn main(_spawner: Spawner) { Ok(env) => match env.frame.id() { Id::Extended(id) => { defmt::println!("Extended Frame id={:x}", id.as_raw()); - } + } Id::Standard(id) => { defmt::println!("Standard Frame id={:x}", id.as_raw()); } From 6782fb1efa1bd4c5372220bb38539ea1e7ef6ffa Mon Sep 17 00:00:00 2001 From: Priit Laes Date: Wed, 13 Dec 2023 11:41:46 +0200 Subject: [PATCH 006/124] embassy-boot: Add explanation to dfu vs active size assertion --- embassy-boot/boot/src/boot_loader.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/embassy-boot/boot/src/boot_loader.rs b/embassy-boot/boot/src/boot_loader.rs index a8c19197b..1663f4f2c 100644 --- a/embassy-boot/boot/src/boot_loader.rs +++ b/embassy-boot/boot/src/boot_loader.rs @@ -224,6 +224,7 @@ impl BootLoader( ) { assert_eq!(active.capacity() as u32 % page_size, 0); assert_eq!(dfu.capacity() as u32 % page_size, 0); + // DFU partition has to be bigger than ACTIVE partition to handle swap algorithm assert!(dfu.capacity() as u32 - active.capacity() as u32 >= page_size); assert!(2 + 2 * (active.capacity() as u32 / page_size) <= state.capacity() as u32 / STATE::WRITE_SIZE as u32); } From d596a1091d25e89533d08a1f96678f1c1182dc40 Mon Sep 17 00:00:00 2001 From: djstrickland <96876452+dstric-aqueduct@users.noreply.github.com> Date: Wed, 13 Dec 2023 10:17:07 -0500 Subject: [PATCH 007/124] add `susependable` field to `embassy_usb::builder::Config` - allow for optional override of `Suspend` event for a UsbDevice --- embassy-usb/src/builder.rs | 10 ++++++++++ embassy-usb/src/lib.rs | 8 +++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/embassy-usb/src/builder.rs b/embassy-usb/src/builder.rs index c4705d041..ebc1283e6 100644 --- a/embassy-usb/src/builder.rs +++ b/embassy-usb/src/builder.rs @@ -94,6 +94,15 @@ pub struct Config<'a> { /// Default: 100mA /// Max: 500mA pub max_power: u16, + + /// Allow the bus to be suspended. + /// + /// If set to `true`, the bus will put itself in the suspended state + /// when it receives a `driver::Event::Suspend` bus event. If you wish + /// to override this behavior, set this field to `false`. + /// + /// Default: `true` + pub suspendable: bool, } impl<'a> Config<'a> { @@ -114,6 +123,7 @@ impl<'a> Config<'a> { supports_remote_wakeup: false, composite_with_iads: false, max_power: 100, + suspendable: true, } } } diff --git a/embassy-usb/src/lib.rs b/embassy-usb/src/lib.rs index 241e33a78..ff3295871 100644 --- a/embassy-usb/src/lib.rs +++ b/embassy-usb/src/lib.rs @@ -471,9 +471,11 @@ impl<'d, D: Driver<'d>> Inner<'d, D> { } Event::Suspend => { trace!("usb: suspend"); - self.suspended = true; - for h in &mut self.handlers { - h.suspended(true); + if self.config.suspendable { + self.suspended = true; + for h in &mut self.handlers { + h.suspended(true); + } } } Event::PowerDetected => { From 876faa5685de66ce422bc9196f2442195cdff63b Mon Sep 17 00:00:00 2001 From: Ulf Lilleengen Date: Wed, 13 Dec 2023 19:00:26 +0100 Subject: [PATCH 008/124] docs: more docs in embassy-boot crate documentation --- docs/modules/ROOT/pages/bootloader.adoc | 4 +++- embassy-boot/boot/README.md | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/docs/modules/ROOT/pages/bootloader.adoc b/docs/modules/ROOT/pages/bootloader.adoc index b7215e52a..3b0cdb182 100644 --- a/docs/modules/ROOT/pages/bootloader.adoc +++ b/docs/modules/ROOT/pages/bootloader.adoc @@ -45,6 +45,8 @@ The BOOTLOADER_STATE partition must be big enough to store one word per page in The bootloader has a platform-agnostic part, which implements the power fail safe swapping algorithm given the boundaries set by the partitions. The platform-specific part is a minimal shim that provides additional functionality such as watchdogs or supporting the nRF52 softdevice. +NOTE: The linker scripts for the application and bootloader look similar, but the FLASH region must point to the BOOTLOADER partition for the bootloader, and the ACTIVE partition for the application. + === FirmwareUpdater The `FirmwareUpdater` is an object for conveniently flashing firmware to the DFU partition and subsequently marking it as being ready for swapping with the active partition on the next reset. Its principle methods are `write_firmware`, which is called once per the size of the flash "write block" (typically 4KiB), and `mark_updated`, which is the final call. @@ -91,4 +93,4 @@ cp $FIRMWARE_DIR/myfirmware $FIRMWARE_DIR/myfirmware+signed tail -n1 $SECRETS_DIR/message.txt.sig | base64 -d -i - | dd ibs=10 skip=1 >> $FIRMWARE_DIR/myfirmware+signed ---- -Remember, guard the `$SECRETS_DIR/key.sec` key as compromising it means that another party can sign your firmware. \ No newline at end of file +Remember, guard the `$SECRETS_DIR/key.sec` key as compromising it means that another party can sign your firmware. diff --git a/embassy-boot/boot/README.md b/embassy-boot/boot/README.md index 07755bc6c..3fc81f24b 100644 --- a/embassy-boot/boot/README.md +++ b/embassy-boot/boot/README.md @@ -8,6 +8,24 @@ The bootloader can be used either as a library or be flashed directly with the d By design, the bootloader does not provide any network capabilities. Networking capabilities for fetching new firmware can be provided by the user application, using the bootloader as a library for updating the firmware, or by using the bootloader as a library and adding this capability yourself. +## Overview + +The bootloader divides the storage into 4 main partitions, configurable when creating the bootloader instance or via linker scripts: + +* BOOTLOADER - Where the bootloader is placed. The bootloader itself consumes about 8kB of flash, but if you need to debug it and have space available, increasing this to 24kB will allow you to run the bootloader with probe-rs. +* ACTIVE - Where the main application is placed. The bootloader will attempt to load the application at the start of this partition. The minimum size required for this partition is the size of your application. +* DFU - Where the application-to-be-swapped is placed. This partition is written to by the application. This partition must be at least 1 page bigger than the ACTIVE partition. +* BOOTLOADER STATE - Where the bootloader stores the current state describing if the active and dfu partitions need to be swapped. + +For any partition, the following preconditions are required: + +* Partitions must be aligned on the page size. +* Partitions must be a multiple of the page size. + +The linker scripts for the application and bootloader look similar, but the FLASH region must point to the BOOTLOADER partition for the bootloader, and the ACTIVE partition for the application. + +For more details on the bootloader, see [the documentation](https://embassy.dev/book/dev/bootloader.html). + ## Hardware support The bootloader supports different hardware in separate crates: @@ -16,6 +34,7 @@ The bootloader supports different hardware in separate crates: * `embassy-boot-rp` - for the RP2040 microcontrollers. * `embassy-boot-stm32` - for the STM32 microcontrollers. + ## Minimum supported Rust version (MSRV) `embassy-boot` is guaranteed to compile on the latest stable Rust version at the time of release. It might compile with older versions but that may change in any new patch release. From 976a7ae22aa222213861c12d515115aac87bd2e0 Mon Sep 17 00:00:00 2001 From: Kaitlyn Kenwell Date: Wed, 13 Dec 2023 14:40:49 -0500 Subject: [PATCH 009/124] Add embassy-usb-dfu --- embassy-boot/boot/src/boot_loader.rs | 4 +- .../boot/src/firmware_updater/asynch.rs | 13 +- .../boot/src/firmware_updater/blocking.rs | 17 +- embassy-boot/boot/src/lib.rs | 3 + embassy-boot/stm32/src/lib.rs | 9 +- embassy-usb-dfu/Cargo.toml | 31 +++ embassy-usb-dfu/src/application.rs | 114 ++++++++++ embassy-usb-dfu/src/bootloader.rs | 196 ++++++++++++++++++ embassy-usb-dfu/src/consts.rs | 96 +++++++++ embassy-usb-dfu/src/lib.rs | 16 ++ 10 files changed, 492 insertions(+), 7 deletions(-) create mode 100644 embassy-usb-dfu/Cargo.toml create mode 100644 embassy-usb-dfu/src/application.rs create mode 100644 embassy-usb-dfu/src/bootloader.rs create mode 100644 embassy-usb-dfu/src/consts.rs create mode 100644 embassy-usb-dfu/src/lib.rs diff --git a/embassy-boot/boot/src/boot_loader.rs b/embassy-boot/boot/src/boot_loader.rs index a8c19197b..c0deca22b 100644 --- a/embassy-boot/boot/src/boot_loader.rs +++ b/embassy-boot/boot/src/boot_loader.rs @@ -5,7 +5,7 @@ use embassy_sync::blocking_mutex::raw::NoopRawMutex; use embassy_sync::blocking_mutex::Mutex; use embedded_storage::nor_flash::{NorFlash, NorFlashError, NorFlashErrorKind}; -use crate::{State, BOOT_MAGIC, STATE_ERASE_VALUE, SWAP_MAGIC}; +use crate::{State, BOOT_MAGIC, STATE_ERASE_VALUE, SWAP_MAGIC, DFU_DETACH_MAGIC}; /// Errors returned by bootloader #[derive(PartialEq, Eq, Debug)] @@ -384,6 +384,8 @@ impl BootLoader FirmwareUpdater<'d, DFU, STATE> { self.state.mark_updated().await } + /// Mark to trigger USB DFU on next boot. + pub async fn mark_dfu(&mut self) -> Result<(), FirmwareUpdaterError> { + self.state.verify_booted().await?; + self.state.mark_dfu().await + } + /// Mark firmware boot successful and stop rollback on reset. pub async fn mark_booted(&mut self) -> Result<(), FirmwareUpdaterError> { self.state.mark_booted().await @@ -247,6 +253,11 @@ impl<'d, STATE: NorFlash> FirmwareState<'d, STATE> { self.set_magic(SWAP_MAGIC).await } + /// Mark to trigger USB DFU on next boot. + pub async fn mark_dfu(&mut self) -> Result<(), FirmwareUpdaterError> { + self.set_magic(DFU_DETACH_MAGIC).await + } + /// Mark firmware boot successful and stop rollback on reset. pub async fn mark_booted(&mut self) -> Result<(), FirmwareUpdaterError> { self.set_magic(BOOT_MAGIC).await diff --git a/embassy-boot/boot/src/firmware_updater/blocking.rs b/embassy-boot/boot/src/firmware_updater/blocking.rs index 76e4264a0..b2a633d1e 100644 --- a/embassy-boot/boot/src/firmware_updater/blocking.rs +++ b/embassy-boot/boot/src/firmware_updater/blocking.rs @@ -6,7 +6,7 @@ use embassy_sync::blocking_mutex::raw::NoopRawMutex; use embedded_storage::nor_flash::NorFlash; use super::FirmwareUpdaterConfig; -use crate::{FirmwareUpdaterError, State, BOOT_MAGIC, STATE_ERASE_VALUE, SWAP_MAGIC}; +use crate::{FirmwareUpdaterError, State, BOOT_MAGIC, STATE_ERASE_VALUE, SWAP_MAGIC, DFU_DETACH_MAGIC}; /// Blocking FirmwareUpdater is an application API for interacting with the BootLoader without the ability to /// 'mess up' the internal bootloader state @@ -168,6 +168,12 @@ impl<'d, DFU: NorFlash, STATE: NorFlash> BlockingFirmwareUpdater<'d, DFU, STATE> self.state.mark_updated() } + /// Mark to trigger USB DFU device on next boot. + pub fn mark_dfu(&mut self) -> Result<(), FirmwareUpdaterError> { + self.state.verify_booted()?; + self.state.mark_dfu() + } + /// Mark firmware boot successful and stop rollback on reset. pub fn mark_booted(&mut self) -> Result<(), FirmwareUpdaterError> { self.state.mark_booted() @@ -226,7 +232,7 @@ impl<'d, STATE: NorFlash> BlockingFirmwareState<'d, STATE> { // Make sure we are running a booted firmware to avoid reverting to a bad state. fn verify_booted(&mut self) -> Result<(), FirmwareUpdaterError> { - if self.get_state()? == State::Boot { + if self.get_state()? == State::Boot || self.get_state()? == State::DfuDetach { Ok(()) } else { Err(FirmwareUpdaterError::BadState) @@ -243,6 +249,8 @@ impl<'d, STATE: NorFlash> BlockingFirmwareState<'d, STATE> { if !self.aligned.iter().any(|&b| b != SWAP_MAGIC) { Ok(State::Swap) + } else if !self.aligned.iter().any(|&b| b != DFU_DETACH_MAGIC) { + Ok(State::DfuDetach) } else { Ok(State::Boot) } @@ -253,6 +261,11 @@ impl<'d, STATE: NorFlash> BlockingFirmwareState<'d, STATE> { self.set_magic(SWAP_MAGIC) } + /// Mark to trigger USB DFU on next boot. + pub fn mark_dfu(&mut self) -> Result<(), FirmwareUpdaterError> { + self.set_magic(DFU_DETACH_MAGIC) + } + /// Mark firmware boot successful and stop rollback on reset. pub fn mark_booted(&mut self) -> Result<(), FirmwareUpdaterError> { self.set_magic(BOOT_MAGIC) diff --git a/embassy-boot/boot/src/lib.rs b/embassy-boot/boot/src/lib.rs index 9e70a4dca..451992945 100644 --- a/embassy-boot/boot/src/lib.rs +++ b/embassy-boot/boot/src/lib.rs @@ -23,6 +23,7 @@ pub use firmware_updater::{ pub(crate) const BOOT_MAGIC: u8 = 0xD0; pub(crate) const SWAP_MAGIC: u8 = 0xF0; +pub(crate) const DFU_DETACH_MAGIC: u8 = 0xE0; /// The state of the bootloader after running prepare. #[derive(PartialEq, Eq, Debug)] @@ -32,6 +33,8 @@ pub enum State { Boot, /// Bootloader has swapped the active partition with the dfu partition and will attempt boot. Swap, + /// Application has received a DFU_DETACH request over USB, and is rebooting into the bootloader to apply a DFU. + DfuDetach, } /// Buffer aligned to 32 byte boundary, largest known alignment requirement for embassy-boot. diff --git a/embassy-boot/stm32/src/lib.rs b/embassy-boot/stm32/src/lib.rs index c418cb262..4b4091ac9 100644 --- a/embassy-boot/stm32/src/lib.rs +++ b/embassy-boot/stm32/src/lib.rs @@ -10,7 +10,10 @@ pub use embassy_boot::{ use embedded_storage::nor_flash::NorFlash; /// A bootloader for STM32 devices. -pub struct BootLoader; +pub struct BootLoader { + /// The reported state of the bootloader after preparing for boot + pub state: State, +} impl BootLoader { /// Inspect the bootloader state and perform actions required before booting, such as swapping firmware @@ -19,8 +22,8 @@ impl BootLoader { ) -> Self { let mut aligned_buf = AlignedBuffer([0; BUFFER_SIZE]); let mut boot = embassy_boot::BootLoader::new(config); - boot.prepare_boot(aligned_buf.as_mut()).expect("Boot prepare error"); - Self + let state = boot.prepare_boot(aligned_buf.as_mut()).expect("Boot prepare error"); + Self { state } } /// Boots the application. diff --git a/embassy-usb-dfu/Cargo.toml b/embassy-usb-dfu/Cargo.toml new file mode 100644 index 000000000..62398afbc --- /dev/null +++ b/embassy-usb-dfu/Cargo.toml @@ -0,0 +1,31 @@ +[package] +edition = "2021" +name = "embassy-usb-dfu" +version = "0.1.0" +description = "An implementation of the USB DFU 1.1 protocol, using embassy-boot" +license = "MIT OR Apache-2.0" +repository = "https://github.com/embassy-rs/embassy" +categories = [ + "embedded", + "no-std", + "asynchronous" +] + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +bitflags = "2.4.1" +cortex-m = { version = "0.7.7", features = ["inline-asm"] } +defmt = { version = "0.3.5", optional = true } +embassy-boot = { version = "0.1.1", path = "../embassy-boot/boot" } +embassy-embedded-hal = { version = "0.1.0", path = "../embassy-embedded-hal" } +embassy-futures = { version = "0.1.1", path = "../embassy-futures" } +embassy-sync = { version = "0.5.0", path = "../embassy-sync" } +embassy-time = { version = "0.2.0", path = "../embassy-time" } +embassy-usb = { version = "0.1.0", path = "../embassy-usb", default-features = false } +embedded-storage = { version = "0.3.1" } + +[features] +bootloader = [] +application = [] +defmt = ["dep:defmt"] diff --git a/embassy-usb-dfu/src/application.rs b/embassy-usb-dfu/src/application.rs new file mode 100644 index 000000000..5a52a9fed --- /dev/null +++ b/embassy-usb-dfu/src/application.rs @@ -0,0 +1,114 @@ + +use embassy_boot::BlockingFirmwareUpdater; +use embassy_time::{Instant, Duration}; +use embassy_usb::{Handler, control::{RequestType, Recipient, OutResponse, InResponse}, Builder, driver::Driver}; +use embedded_storage::nor_flash::NorFlash; + +use crate::consts::{DfuAttributes, Request, Status, State, USB_CLASS_APPN_SPEC, APPN_SPEC_SUBCLASS_DFU, DESC_DFU_FUNCTIONAL, DFU_PROTOCOL_RT}; + +/// Internal state for the DFU class +pub struct Control<'d, DFU: NorFlash, STATE: NorFlash> { + updater: BlockingFirmwareUpdater<'d, DFU, STATE>, + attrs: DfuAttributes, + state: State, + timeout: Option, + detach_start: Option, +} + +impl<'d, DFU: NorFlash, STATE: NorFlash> Control<'d, DFU, STATE> { + pub fn new(updater: BlockingFirmwareUpdater<'d, DFU, STATE>, attrs: DfuAttributes) -> Self { + Control { updater, attrs, state: State::AppIdle, detach_start: None, timeout: None } + } +} + +impl<'d, DFU: NorFlash, STATE: NorFlash> Handler for Control<'d, DFU, STATE> { + fn reset(&mut self) { + if let Some(start) = self.detach_start { + let delta = Instant::now() - start; + let timeout = self.timeout.unwrap(); + #[cfg(feature = "defmt")] + defmt::info!("Received RESET with delta = {}, timeout = {}", delta.as_millis(), timeout.as_millis()); + if delta < timeout { + self.updater.mark_dfu().expect("Failed to mark DFU mode in bootloader"); + cortex_m::asm::dsb(); + cortex_m::peripheral::SCB::sys_reset(); + } + } + } + + fn control_out(&mut self, req: embassy_usb::control::Request, _: &[u8]) -> Option { + if (req.request_type, req.recipient) != (RequestType::Class, Recipient::Interface) { + return None; + } + + #[cfg(feature = "defmt")] + defmt::info!("Received request {}", req); + + match Request::try_from(req.request) { + Ok(Request::Detach) => { + #[cfg(feature = "defmt")] + defmt::info!("Received DETACH, awaiting USB reset"); + self.detach_start = Some(Instant::now()); + self.timeout = Some(Duration::from_millis(req.value as u64)); + self.state = State::AppDetach; + Some(OutResponse::Accepted) + } + _ => { + None + } + } + } + + fn control_in<'a>(&'a mut self, req: embassy_usb::control::Request, buf: &'a mut [u8]) -> Option> { + if (req.request_type, req.recipient) != (RequestType::Class, Recipient::Interface) { + return None; + } + + #[cfg(feature = "defmt")] + defmt::info!("Received request {}", req); + + match Request::try_from(req.request) { + Ok(Request::GetStatus) => { + buf[0..6].copy_from_slice(&[Status::Ok as u8, 0x32, 0x00, 0x00, self.state as u8, 0x00]); + Some(InResponse::Accepted(buf)) + } + _ => None + } + } +} + +/// An implementation of the USB DFU 1.1 runtime protocol +/// +/// This function will add a DFU interface descriptor to the provided Builder, and register the provided Control as a handler for the USB device. The USB builder can be used as normal once this is complete. +/// The handler is responsive to DFU GetStatus and Detach commands. +/// +/// Once a detach command, followed by a USB reset is received by the host, a magic number will be written into the bootloader state partition to indicate that +/// it should expose a DFU device, and a software reset will be issued. +/// +/// To apply USB DFU updates, the bootloader must be capable of recognizing the DFU magic and exposing a device to handle the full DFU transaction with the host. +pub fn usb_dfu<'d, D: Driver<'d>, DFU: NorFlash, STATE: NorFlash>(builder: &mut Builder<'d, D>, handler: &'d mut Control<'d, DFU, STATE>, timeout: Duration) { + #[cfg(feature = "defmt")] + defmt::info!("Application USB DFU initializing"); + let mut func = builder.function(0x00, 0x00, 0x00); + let mut iface = func.interface(); + let mut alt = iface.alt_setting( + USB_CLASS_APPN_SPEC, + APPN_SPEC_SUBCLASS_DFU, + DFU_PROTOCOL_RT, + None, + ); + let timeout = timeout.as_millis() as u16; + alt.descriptor( + DESC_DFU_FUNCTIONAL, + &[ + handler.attrs.bits(), + (timeout & 0xff) as u8, + ((timeout >> 8) & 0xff) as u8, + 0x40, 0x00, // 64B control buffer size for application side + 0x10, 0x01, // DFU 1.1 + ], + ); + + drop(func); + builder.handler(handler); +} \ No newline at end of file diff --git a/embassy-usb-dfu/src/bootloader.rs b/embassy-usb-dfu/src/bootloader.rs new file mode 100644 index 000000000..7bcb0b258 --- /dev/null +++ b/embassy-usb-dfu/src/bootloader.rs @@ -0,0 +1,196 @@ +use embassy_boot::BlockingFirmwareUpdater; +use embassy_usb::{ + control::{InResponse, OutResponse, Recipient, RequestType}, + driver::Driver, + Builder, Handler, +}; +use embedded_storage::nor_flash::{NorFlashErrorKind, NorFlash}; + +use crate::consts::{DfuAttributes, Request, State, Status, USB_CLASS_APPN_SPEC, APPN_SPEC_SUBCLASS_DFU, DFU_PROTOCOL_DFU, DESC_DFU_FUNCTIONAL}; + +/// Internal state for USB DFU +pub struct Control<'d, DFU: NorFlash, STATE: NorFlash, const BLOCK_SIZE: usize> { + updater: BlockingFirmwareUpdater<'d, DFU, STATE>, + attrs: DfuAttributes, + state: State, + status: Status, + offset: usize, +} + +impl<'d, DFU: NorFlash, STATE: NorFlash, const BLOCK_SIZE: usize> Control<'d, DFU, STATE, BLOCK_SIZE> { + pub fn new(updater: BlockingFirmwareUpdater<'d, DFU, STATE>, attrs: DfuAttributes) -> Self { + Self { + updater, + attrs, + state: State::DfuIdle, + status: Status::Ok, + offset: 0, + } + } + + fn reset_state(&mut self) { + self.offset = 0; + self.state = State::DfuIdle; + self.status = Status::Ok; + } +} + +impl<'d, DFU: NorFlash, STATE: NorFlash, const BLOCK_SIZE: usize> Handler for Control<'d, DFU, STATE, BLOCK_SIZE> { + fn control_out( + &mut self, + req: embassy_usb::control::Request, + data: &[u8], + ) -> Option { + if (req.request_type, req.recipient) != (RequestType::Class, Recipient::Interface) { + return None; + } + match Request::try_from(req.request) { + Ok(Request::Abort) => { + self.reset_state(); + Some(OutResponse::Accepted) + } + Ok(Request::Dnload) if self.attrs.contains(DfuAttributes::CAN_DOWNLOAD) => { + if req.value == 0 { + self.state = State::Download; + self.offset = 0; + } + + let mut buf = [0; BLOCK_SIZE]; + buf[..data.len()].copy_from_slice(data); + + if req.length == 0 { + match self.updater.mark_updated() { + Ok(_) => { + self.status = Status::Ok; + self.state = State::ManifestSync; + } + Err(e) => { + self.state = State::Error; + match e { + embassy_boot::FirmwareUpdaterError::Flash(e) => match e { + NorFlashErrorKind::NotAligned => self.status = Status::ErrWrite, + NorFlashErrorKind::OutOfBounds => { + self.status = Status::ErrAddress + } + _ => self.status = Status::ErrUnknown, + }, + embassy_boot::FirmwareUpdaterError::Signature(_) => { + self.status = Status::ErrVerify + } + embassy_boot::FirmwareUpdaterError::BadState => { + self.status = Status::ErrUnknown + } + } + } + } + } else { + if self.state != State::Download { + // Unexpected DNLOAD while chip is waiting for a GETSTATUS + self.status = Status::ErrUnknown; + self.state = State::Error; + return Some(OutResponse::Rejected); + } + match self.updater.write_firmware(self.offset, &buf[..]) { + Ok(_) => { + self.status = Status::Ok; + self.state = State::DlSync; + self.offset += data.len(); + } + Err(e) => { + self.state = State::Error; + match e { + embassy_boot::FirmwareUpdaterError::Flash(e) => match e { + NorFlashErrorKind::NotAligned => self.status = Status::ErrWrite, + NorFlashErrorKind::OutOfBounds => { + self.status = Status::ErrAddress + } + _ => self.status = Status::ErrUnknown, + }, + embassy_boot::FirmwareUpdaterError::Signature(_) => { + self.status = Status::ErrVerify + } + embassy_boot::FirmwareUpdaterError::BadState => { + self.status = Status::ErrUnknown + } + } + } + } + } + + Some(OutResponse::Accepted) + } + Ok(Request::Detach) => Some(OutResponse::Accepted), // Device is already in DFU mode + Ok(Request::ClrStatus) => { + self.reset_state(); + Some(OutResponse::Accepted) + } + _ => None, + } + } + + fn control_in<'a>( + &'a mut self, + req: embassy_usb::control::Request, + buf: &'a mut [u8], + ) -> Option> { + if (req.request_type, req.recipient) != (RequestType::Class, Recipient::Interface) { + return None; + } + match Request::try_from(req.request) { + Ok(Request::GetStatus) => { + //TODO: Configurable poll timeout, ability to add string for Vendor error + buf[0..6].copy_from_slice(&[self.status as u8, 0x32, 0x00, 0x00, self.state as u8, 0x00]); + match self.state { + State::DlSync => self.state = State::Download, + State::ManifestSync => cortex_m::peripheral::SCB::sys_reset(), + _ => {} + } + + Some(InResponse::Accepted(&buf[0..6])) + } + Ok(Request::GetState) => { + buf[0] = self.state as u8; + Some(InResponse::Accepted(&buf[0..1])) + } + Ok(Request::Upload) if self.attrs.contains(DfuAttributes::CAN_UPLOAD) => { + //TODO: FirmwareUpdater does not provide a way of reading the active partition, can't upload. + Some(InResponse::Rejected) + } + _ => None, + } + } +} + +/// An implementation of the USB DFU 1.1 protocol +/// +/// This function will add a DFU interface descriptor to the provided Builder, and register the provided Control as a handler for the USB device +/// The handler is responsive to DFU GetState, GetStatus, Abort, and ClrStatus commands, as well as Download if configured by the user. +/// +/// Once the host has initiated a DFU download operation, the chunks sent by the host will be written to the DFU partition. +/// Once the final sync in the manifestation phase has been received, the handler will trigger a system reset to swap the new firmware. +pub fn usb_dfu<'d, D: Driver<'d>, DFU: NorFlash, STATE: NorFlash, const BLOCK_SIZE: usize>( + builder: &mut Builder<'d, D>, + handler: &'d mut Control<'d, DFU, STATE, BLOCK_SIZE>, +) { + let mut func = builder.function(0x00, 0x00, 0x00); + let mut iface = func.interface(); + let mut alt = iface.alt_setting( + USB_CLASS_APPN_SPEC, + APPN_SPEC_SUBCLASS_DFU, + DFU_PROTOCOL_DFU, + None, + ); + alt.descriptor( + DESC_DFU_FUNCTIONAL, + &[ + handler.attrs.bits(), + 0xc4, 0x09, // 2500ms timeout, doesn't affect operation as DETACH not necessary in bootloader code + (BLOCK_SIZE & 0xff) as u8, + ((BLOCK_SIZE & 0xff00) >> 8) as u8, + 0x10, 0x01, // DFU 1.1 + ], + ); + + drop(func); + builder.handler(handler); +} diff --git a/embassy-usb-dfu/src/consts.rs b/embassy-usb-dfu/src/consts.rs new file mode 100644 index 000000000..b083af9de --- /dev/null +++ b/embassy-usb-dfu/src/consts.rs @@ -0,0 +1,96 @@ + +pub(crate) const USB_CLASS_APPN_SPEC: u8 = 0xFE; +pub(crate) const APPN_SPEC_SUBCLASS_DFU: u8 = 0x01; +#[allow(unused)] +pub(crate) const DFU_PROTOCOL_DFU: u8 = 0x02; +#[allow(unused)] +pub(crate) const DFU_PROTOCOL_RT: u8 = 0x01; +pub(crate) const DESC_DFU_FUNCTIONAL: u8 = 0x21; + +#[cfg(feature = "defmt")] +defmt::bitflags! { + pub struct DfuAttributes: u8 { + const WILL_DETACH = 0b0000_1000; + const MANIFESTATION_TOLERANT = 0b0000_0100; + const CAN_UPLOAD = 0b0000_0010; + const CAN_DOWNLOAD = 0b0000_0001; + } +} + +#[cfg(not(feature = "defmt"))] +bitflags::bitflags! { + pub struct DfuAttributes: u8 { + const WILL_DETACH = 0b0000_1000; + const MANIFESTATION_TOLERANT = 0b0000_0100; + const CAN_UPLOAD = 0b0000_0010; + const CAN_DOWNLOAD = 0b0000_0001; + } +} + +#[derive(Copy, Clone, PartialEq, Eq)] +#[repr(u8)] +#[allow(unused)] +pub enum State { + AppIdle = 0, + AppDetach = 1, + DfuIdle = 2, + DlSync = 3, + DlBusy = 4, + Download = 5, + ManifestSync = 6, + Manifest = 7, + ManifestWaitReset = 8, + UploadIdle = 9, + Error = 10, +} + +#[derive(Copy, Clone, PartialEq, Eq)] +#[repr(u8)] +#[allow(unused)] +pub enum Status { + Ok = 0x00, + ErrTarget = 0x01, + ErrFile = 0x02, + ErrWrite = 0x03, + ErrErase = 0x04, + ErrCheckErased = 0x05, + ErrProg = 0x06, + ErrVerify = 0x07, + ErrAddress = 0x08, + ErrNotDone = 0x09, + ErrFirmware = 0x0A, + ErrVendor = 0x0B, + ErrUsbr = 0x0C, + ErrPor = 0x0D, + ErrUnknown = 0x0E, + ErrStalledPkt = 0x0F, +} + +#[derive(Copy, Clone, PartialEq, Eq)] +#[repr(u8)] +pub enum Request { + Detach = 0, + Dnload = 1, + Upload = 2, + GetStatus = 3, + ClrStatus = 4, + GetState = 5, + Abort = 6, +} + +impl TryFrom for Request { + type Error = (); + + fn try_from(value: u8) -> Result { + match value { + 0 => Ok(Request::Detach), + 1 => Ok(Request::Dnload), + 2 => Ok(Request::Upload), + 3 => Ok(Request::GetStatus), + 4 => Ok(Request::ClrStatus), + 5 => Ok(Request::GetState), + 6 => Ok(Request::Abort), + _ => Err(()), + } + } +} diff --git a/embassy-usb-dfu/src/lib.rs b/embassy-usb-dfu/src/lib.rs new file mode 100644 index 000000000..dcdb11b2a --- /dev/null +++ b/embassy-usb-dfu/src/lib.rs @@ -0,0 +1,16 @@ +#![no_std] + +pub mod consts; + +#[cfg(feature = "bootloader")] +mod bootloader; +#[cfg(feature = "bootloader")] +pub use self::bootloader::*; + +#[cfg(feature = "application")] +mod application; +#[cfg(feature = "application")] +pub use self::application::*; + +#[cfg(any(all(feature = "bootloader", feature = "application"), not(any(feature = "bootloader", feature = "application"))))] +compile_error!("usb-dfu must be compiled with exactly one of `bootloader`, or `application` features"); From 6bf70e14fb14882ce6adf0d47179b7408bdcb184 Mon Sep 17 00:00:00 2001 From: djstrickland <96876452+dstric-aqueduct@users.noreply.github.com> Date: Wed, 13 Dec 2023 14:50:13 -0500 Subject: [PATCH 010/124] Update usb.rs - add check of `dev_resume_from_host` interrupt register to catch wake event --- embassy-rp/src/usb.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/embassy-rp/src/usb.rs b/embassy-rp/src/usb.rs index 4ab881f6e..4a74ee6f7 100644 --- a/embassy-rp/src/usb.rs +++ b/embassy-rp/src/usb.rs @@ -363,7 +363,7 @@ impl<'d, T: Instance> driver::Bus for Bus<'d, T> { let siestatus = regs.sie_status().read(); let intrstatus = regs.intr().read(); - if siestatus.resume() { + if siestatus.resume() || intrstatus.dev_resume_from_host() { regs.sie_status().write(|w| w.set_resume(true)); return Poll::Ready(Event::Resume); } From c2942f2727739d8972ad211721b1bb1804fb7b4a Mon Sep 17 00:00:00 2001 From: Kaitlyn Kenwell Date: Wed, 13 Dec 2023 14:53:49 -0500 Subject: [PATCH 011/124] fmt --- embassy-usb-dfu/src/application.rs | 75 +++++++++++++++++++----------- embassy-usb-dfu/src/bootloader.rs | 56 +++++++++------------- embassy-usb-dfu/src/consts.rs | 1 - embassy-usb-dfu/src/lib.rs | 5 +- 4 files changed, 73 insertions(+), 64 deletions(-) diff --git a/embassy-usb-dfu/src/application.rs b/embassy-usb-dfu/src/application.rs index 5a52a9fed..2e7bda121 100644 --- a/embassy-usb-dfu/src/application.rs +++ b/embassy-usb-dfu/src/application.rs @@ -1,10 +1,14 @@ - use embassy_boot::BlockingFirmwareUpdater; -use embassy_time::{Instant, Duration}; -use embassy_usb::{Handler, control::{RequestType, Recipient, OutResponse, InResponse}, Builder, driver::Driver}; +use embassy_time::{Duration, Instant}; +use embassy_usb::control::{InResponse, OutResponse, Recipient, RequestType}; +use embassy_usb::driver::Driver; +use embassy_usb::{Builder, Handler}; use embedded_storage::nor_flash::NorFlash; -use crate::consts::{DfuAttributes, Request, Status, State, USB_CLASS_APPN_SPEC, APPN_SPEC_SUBCLASS_DFU, DESC_DFU_FUNCTIONAL, DFU_PROTOCOL_RT}; +use crate::consts::{ + DfuAttributes, Request, State, Status, APPN_SPEC_SUBCLASS_DFU, DESC_DFU_FUNCTIONAL, DFU_PROTOCOL_RT, + USB_CLASS_APPN_SPEC, +}; /// Internal state for the DFU class pub struct Control<'d, DFU: NorFlash, STATE: NorFlash> { @@ -17,7 +21,13 @@ pub struct Control<'d, DFU: NorFlash, STATE: NorFlash> { impl<'d, DFU: NorFlash, STATE: NorFlash> Control<'d, DFU, STATE> { pub fn new(updater: BlockingFirmwareUpdater<'d, DFU, STATE>, attrs: DfuAttributes) -> Self { - Control { updater, attrs, state: State::AppIdle, detach_start: None, timeout: None } + Control { + updater, + attrs, + state: State::AppIdle, + detach_start: None, + timeout: None, + } } } @@ -27,7 +37,11 @@ impl<'d, DFU: NorFlash, STATE: NorFlash> Handler for Control<'d, DFU, STATE> { let delta = Instant::now() - start; let timeout = self.timeout.unwrap(); #[cfg(feature = "defmt")] - defmt::info!("Received RESET with delta = {}, timeout = {}", delta.as_millis(), timeout.as_millis()); + defmt::info!( + "Received RESET with delta = {}, timeout = {}", + delta.as_millis(), + timeout.as_millis() + ); if delta < timeout { self.updater.mark_dfu().expect("Failed to mark DFU mode in bootloader"); cortex_m::asm::dsb(); @@ -36,7 +50,11 @@ impl<'d, DFU: NorFlash, STATE: NorFlash> Handler for Control<'d, DFU, STATE> { } } - fn control_out(&mut self, req: embassy_usb::control::Request, _: &[u8]) -> Option { + fn control_out( + &mut self, + req: embassy_usb::control::Request, + _: &[u8], + ) -> Option { if (req.request_type, req.recipient) != (RequestType::Class, Recipient::Interface) { return None; } @@ -53,13 +71,15 @@ impl<'d, DFU: NorFlash, STATE: NorFlash> Handler for Control<'d, DFU, STATE> { self.state = State::AppDetach; Some(OutResponse::Accepted) } - _ => { - None - } + _ => None, } } - fn control_in<'a>(&'a mut self, req: embassy_usb::control::Request, buf: &'a mut [u8]) -> Option> { + fn control_in<'a>( + &'a mut self, + req: embassy_usb::control::Request, + buf: &'a mut [u8], + ) -> Option> { if (req.request_type, req.recipient) != (RequestType::Class, Recipient::Interface) { return None; } @@ -72,31 +92,30 @@ impl<'d, DFU: NorFlash, STATE: NorFlash> Handler for Control<'d, DFU, STATE> { buf[0..6].copy_from_slice(&[Status::Ok as u8, 0x32, 0x00, 0x00, self.state as u8, 0x00]); Some(InResponse::Accepted(buf)) } - _ => None + _ => None, } } } /// An implementation of the USB DFU 1.1 runtime protocol -/// +/// /// This function will add a DFU interface descriptor to the provided Builder, and register the provided Control as a handler for the USB device. The USB builder can be used as normal once this is complete. -/// The handler is responsive to DFU GetStatus and Detach commands. -/// +/// The handler is responsive to DFU GetStatus and Detach commands. +/// /// Once a detach command, followed by a USB reset is received by the host, a magic number will be written into the bootloader state partition to indicate that /// it should expose a DFU device, and a software reset will be issued. -/// +/// /// To apply USB DFU updates, the bootloader must be capable of recognizing the DFU magic and exposing a device to handle the full DFU transaction with the host. -pub fn usb_dfu<'d, D: Driver<'d>, DFU: NorFlash, STATE: NorFlash>(builder: &mut Builder<'d, D>, handler: &'d mut Control<'d, DFU, STATE>, timeout: Duration) { +pub fn usb_dfu<'d, D: Driver<'d>, DFU: NorFlash, STATE: NorFlash>( + builder: &mut Builder<'d, D>, + handler: &'d mut Control<'d, DFU, STATE>, + timeout: Duration, +) { #[cfg(feature = "defmt")] defmt::info!("Application USB DFU initializing"); let mut func = builder.function(0x00, 0x00, 0x00); let mut iface = func.interface(); - let mut alt = iface.alt_setting( - USB_CLASS_APPN_SPEC, - APPN_SPEC_SUBCLASS_DFU, - DFU_PROTOCOL_RT, - None, - ); + let mut alt = iface.alt_setting(USB_CLASS_APPN_SPEC, APPN_SPEC_SUBCLASS_DFU, DFU_PROTOCOL_RT, None); let timeout = timeout.as_millis() as u16; alt.descriptor( DESC_DFU_FUNCTIONAL, @@ -104,11 +123,13 @@ pub fn usb_dfu<'d, D: Driver<'d>, DFU: NorFlash, STATE: NorFlash>(builder: &mut handler.attrs.bits(), (timeout & 0xff) as u8, ((timeout >> 8) & 0xff) as u8, - 0x40, 0x00, // 64B control buffer size for application side - 0x10, 0x01, // DFU 1.1 + 0x40, + 0x00, // 64B control buffer size for application side + 0x10, + 0x01, // DFU 1.1 ], ); drop(func); - builder.handler(handler); -} \ No newline at end of file + builder.handler(handler); +} diff --git a/embassy-usb-dfu/src/bootloader.rs b/embassy-usb-dfu/src/bootloader.rs index 7bcb0b258..215058932 100644 --- a/embassy-usb-dfu/src/bootloader.rs +++ b/embassy-usb-dfu/src/bootloader.rs @@ -1,12 +1,13 @@ use embassy_boot::BlockingFirmwareUpdater; -use embassy_usb::{ - control::{InResponse, OutResponse, Recipient, RequestType}, - driver::Driver, - Builder, Handler, -}; -use embedded_storage::nor_flash::{NorFlashErrorKind, NorFlash}; +use embassy_usb::control::{InResponse, OutResponse, Recipient, RequestType}; +use embassy_usb::driver::Driver; +use embassy_usb::{Builder, Handler}; +use embedded_storage::nor_flash::{NorFlash, NorFlashErrorKind}; -use crate::consts::{DfuAttributes, Request, State, Status, USB_CLASS_APPN_SPEC, APPN_SPEC_SUBCLASS_DFU, DFU_PROTOCOL_DFU, DESC_DFU_FUNCTIONAL}; +use crate::consts::{ + DfuAttributes, Request, State, Status, APPN_SPEC_SUBCLASS_DFU, DESC_DFU_FUNCTIONAL, DFU_PROTOCOL_DFU, + USB_CLASS_APPN_SPEC, +}; /// Internal state for USB DFU pub struct Control<'d, DFU: NorFlash, STATE: NorFlash, const BLOCK_SIZE: usize> { @@ -69,17 +70,11 @@ impl<'d, DFU: NorFlash, STATE: NorFlash, const BLOCK_SIZE: usize> Handler for Co match e { embassy_boot::FirmwareUpdaterError::Flash(e) => match e { NorFlashErrorKind::NotAligned => self.status = Status::ErrWrite, - NorFlashErrorKind::OutOfBounds => { - self.status = Status::ErrAddress - } + NorFlashErrorKind::OutOfBounds => self.status = Status::ErrAddress, _ => self.status = Status::ErrUnknown, }, - embassy_boot::FirmwareUpdaterError::Signature(_) => { - self.status = Status::ErrVerify - } - embassy_boot::FirmwareUpdaterError::BadState => { - self.status = Status::ErrUnknown - } + embassy_boot::FirmwareUpdaterError::Signature(_) => self.status = Status::ErrVerify, + embassy_boot::FirmwareUpdaterError::BadState => self.status = Status::ErrUnknown, } } } @@ -101,17 +96,11 @@ impl<'d, DFU: NorFlash, STATE: NorFlash, const BLOCK_SIZE: usize> Handler for Co match e { embassy_boot::FirmwareUpdaterError::Flash(e) => match e { NorFlashErrorKind::NotAligned => self.status = Status::ErrWrite, - NorFlashErrorKind::OutOfBounds => { - self.status = Status::ErrAddress - } + NorFlashErrorKind::OutOfBounds => self.status = Status::ErrAddress, _ => self.status = Status::ErrUnknown, }, - embassy_boot::FirmwareUpdaterError::Signature(_) => { - self.status = Status::ErrVerify - } - embassy_boot::FirmwareUpdaterError::BadState => { - self.status = Status::ErrUnknown - } + embassy_boot::FirmwareUpdaterError::Signature(_) => self.status = Status::ErrVerify, + embassy_boot::FirmwareUpdaterError::BadState => self.status = Status::ErrUnknown, } } } @@ -162,10 +151,10 @@ impl<'d, DFU: NorFlash, STATE: NorFlash, const BLOCK_SIZE: usize> Handler for Co } /// An implementation of the USB DFU 1.1 protocol -/// +/// /// This function will add a DFU interface descriptor to the provided Builder, and register the provided Control as a handler for the USB device /// The handler is responsive to DFU GetState, GetStatus, Abort, and ClrStatus commands, as well as Download if configured by the user. -/// +/// /// Once the host has initiated a DFU download operation, the chunks sent by the host will be written to the DFU partition. /// Once the final sync in the manifestation phase has been received, the handler will trigger a system reset to swap the new firmware. pub fn usb_dfu<'d, D: Driver<'d>, DFU: NorFlash, STATE: NorFlash, const BLOCK_SIZE: usize>( @@ -174,20 +163,17 @@ pub fn usb_dfu<'d, D: Driver<'d>, DFU: NorFlash, STATE: NorFlash, const BLOCK_SI ) { let mut func = builder.function(0x00, 0x00, 0x00); let mut iface = func.interface(); - let mut alt = iface.alt_setting( - USB_CLASS_APPN_SPEC, - APPN_SPEC_SUBCLASS_DFU, - DFU_PROTOCOL_DFU, - None, - ); + let mut alt = iface.alt_setting(USB_CLASS_APPN_SPEC, APPN_SPEC_SUBCLASS_DFU, DFU_PROTOCOL_DFU, None); alt.descriptor( DESC_DFU_FUNCTIONAL, &[ handler.attrs.bits(), - 0xc4, 0x09, // 2500ms timeout, doesn't affect operation as DETACH not necessary in bootloader code + 0xc4, + 0x09, // 2500ms timeout, doesn't affect operation as DETACH not necessary in bootloader code (BLOCK_SIZE & 0xff) as u8, ((BLOCK_SIZE & 0xff00) >> 8) as u8, - 0x10, 0x01, // DFU 1.1 + 0x10, + 0x01, // DFU 1.1 ], ); diff --git a/embassy-usb-dfu/src/consts.rs b/embassy-usb-dfu/src/consts.rs index b083af9de..b359a107e 100644 --- a/embassy-usb-dfu/src/consts.rs +++ b/embassy-usb-dfu/src/consts.rs @@ -1,4 +1,3 @@ - pub(crate) const USB_CLASS_APPN_SPEC: u8 = 0xFE; pub(crate) const APPN_SPEC_SUBCLASS_DFU: u8 = 0x01; #[allow(unused)] diff --git a/embassy-usb-dfu/src/lib.rs b/embassy-usb-dfu/src/lib.rs index dcdb11b2a..81ef041f8 100644 --- a/embassy-usb-dfu/src/lib.rs +++ b/embassy-usb-dfu/src/lib.rs @@ -12,5 +12,8 @@ mod application; #[cfg(feature = "application")] pub use self::application::*; -#[cfg(any(all(feature = "bootloader", feature = "application"), not(any(feature = "bootloader", feature = "application"))))] +#[cfg(any( + all(feature = "bootloader", feature = "application"), + not(any(feature = "bootloader", feature = "application")) +))] compile_error!("usb-dfu must be compiled with exactly one of `bootloader`, or `application` features"); From 702d2a1a193985c9b8da6fc5e532ac55b5485464 Mon Sep 17 00:00:00 2001 From: Kaitlyn Kenwell Date: Wed, 13 Dec 2023 16:08:20 -0500 Subject: [PATCH 012/124] Formatting fixes, add example using stm32wb55 --- .../boot/src/firmware_updater/asynch.rs | 2 +- .../boot/src/firmware_updater/blocking.rs | 2 +- examples/boot-usb-dfu/.cargo/config.toml | 9 ++ .../application/stm32wb/.cargo/config.toml | 9 ++ .../application/stm32wb/Cargo.toml | 32 +++++++ .../application/stm32wb/README.md | 29 ++++++ .../boot-usb-dfu/application/stm32wb/build.rs | 37 ++++++++ .../boot-usb-dfu/application/stm32wb/memory.x | 15 +++ .../application/stm32wb/src/main.rs | 64 +++++++++++++ .../bootloader/stm32wb/Cargo.toml | 63 ++++++++++++ .../boot-usb-dfu/bootloader/stm32wb/README.md | 11 +++ .../boot-usb-dfu/bootloader/stm32wb/build.rs | 27 ++++++ .../boot-usb-dfu/bootloader/stm32wb/memory.x | 18 ++++ .../bootloader/stm32wb/src/main.rs | 95 +++++++++++++++++++ 14 files changed, 411 insertions(+), 2 deletions(-) create mode 100644 examples/boot-usb-dfu/.cargo/config.toml create mode 100644 examples/boot-usb-dfu/application/stm32wb/.cargo/config.toml create mode 100644 examples/boot-usb-dfu/application/stm32wb/Cargo.toml create mode 100644 examples/boot-usb-dfu/application/stm32wb/README.md create mode 100644 examples/boot-usb-dfu/application/stm32wb/build.rs create mode 100644 examples/boot-usb-dfu/application/stm32wb/memory.x create mode 100644 examples/boot-usb-dfu/application/stm32wb/src/main.rs create mode 100644 examples/boot-usb-dfu/bootloader/stm32wb/Cargo.toml create mode 100644 examples/boot-usb-dfu/bootloader/stm32wb/README.md create mode 100644 examples/boot-usb-dfu/bootloader/stm32wb/build.rs create mode 100644 examples/boot-usb-dfu/bootloader/stm32wb/memory.x create mode 100644 examples/boot-usb-dfu/bootloader/stm32wb/src/main.rs diff --git a/embassy-boot/boot/src/firmware_updater/asynch.rs b/embassy-boot/boot/src/firmware_updater/asynch.rs index 0a3cbc136..82e99965b 100644 --- a/embassy-boot/boot/src/firmware_updater/asynch.rs +++ b/embassy-boot/boot/src/firmware_updater/asynch.rs @@ -6,7 +6,7 @@ use embassy_sync::blocking_mutex::raw::NoopRawMutex; use embedded_storage_async::nor_flash::NorFlash; use super::FirmwareUpdaterConfig; -use crate::{FirmwareUpdaterError, State, BOOT_MAGIC, STATE_ERASE_VALUE, SWAP_MAGIC, DFU_DETACH_MAGIC}; +use crate::{FirmwareUpdaterError, State, BOOT_MAGIC, DFU_DETACH_MAGIC, STATE_ERASE_VALUE, SWAP_MAGIC}; /// FirmwareUpdater is an application API for interacting with the BootLoader without the ability to /// 'mess up' the internal bootloader state diff --git a/embassy-boot/boot/src/firmware_updater/blocking.rs b/embassy-boot/boot/src/firmware_updater/blocking.rs index b2a633d1e..ae4179ba3 100644 --- a/embassy-boot/boot/src/firmware_updater/blocking.rs +++ b/embassy-boot/boot/src/firmware_updater/blocking.rs @@ -6,7 +6,7 @@ use embassy_sync::blocking_mutex::raw::NoopRawMutex; use embedded_storage::nor_flash::NorFlash; use super::FirmwareUpdaterConfig; -use crate::{FirmwareUpdaterError, State, BOOT_MAGIC, STATE_ERASE_VALUE, SWAP_MAGIC, DFU_DETACH_MAGIC}; +use crate::{FirmwareUpdaterError, State, BOOT_MAGIC, DFU_DETACH_MAGIC, STATE_ERASE_VALUE, SWAP_MAGIC}; /// Blocking FirmwareUpdater is an application API for interacting with the BootLoader without the ability to /// 'mess up' the internal bootloader state diff --git a/examples/boot-usb-dfu/.cargo/config.toml b/examples/boot-usb-dfu/.cargo/config.toml new file mode 100644 index 000000000..de3a814f7 --- /dev/null +++ b/examples/boot-usb-dfu/.cargo/config.toml @@ -0,0 +1,9 @@ +[unstable] +build-std = ["core"] +build-std-features = ["panic_immediate_abort"] + +[build] +target = "thumbv7em-none-eabi" + +[env] +DEFMT_LOG = "trace" diff --git a/examples/boot-usb-dfu/application/stm32wb/.cargo/config.toml b/examples/boot-usb-dfu/application/stm32wb/.cargo/config.toml new file mode 100644 index 000000000..4f8094ff2 --- /dev/null +++ b/examples/boot-usb-dfu/application/stm32wb/.cargo/config.toml @@ -0,0 +1,9 @@ +[target.'cfg(all(target_arch = "arm", target_os = "none"))'] +# replace your chip as listed in `probe-rs chip list` +runner = "probe-rs run --chip STM32WLE5JCIx" + +[build] +target = "thumbv7em-none-eabihf" + +[env] +DEFMT_LOG = "trace" diff --git a/examples/boot-usb-dfu/application/stm32wb/Cargo.toml b/examples/boot-usb-dfu/application/stm32wb/Cargo.toml new file mode 100644 index 000000000..0a41c0648 --- /dev/null +++ b/examples/boot-usb-dfu/application/stm32wb/Cargo.toml @@ -0,0 +1,32 @@ +[package] +edition = "2021" +name = "embassy-boot-stm32wl-examples" +version = "0.1.0" +license = "MIT OR Apache-2.0" + +[dependencies] +embassy-sync = { version = "0.5.0", path = "../../../../embassy-sync" } +embassy-executor = { version = "0.4.0", path = "../../../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "nightly", "integrated-timers"] } +embassy-time = { version = "0.2", path = "../../../../embassy-time", features = [ "tick-hz-32_768"] } +embassy-stm32 = { version = "0.1.0", path = "../../../../embassy-stm32", features = ["stm32wb55rg", "time-driver-any", "exti"] } +embassy-boot-stm32 = { version = "0.1.0", path = "../../../../embassy-boot/stm32", features = [] } +embassy-embedded-hal = { version = "0.1.0", path = "../../../../embassy-embedded-hal" } +embassy-usb = { version = "0.1.0", path = "../../../../embassy-usb" } +embassy-usb-dfu = { version = "0.1.0", path = "../../../../embassy-usb-dfu", features = ["application"] } + +defmt = { version = "0.3", optional = true } +defmt-rtt = { version = "0.4", optional = true } +panic-reset = { version = "0.1.1" } +embedded-hal = { version = "0.2.6" } + +cortex-m = { version = "0.7.6", features = ["inline-asm", "critical-section-single-core"] } +cortex-m-rt = "0.7.0" + +[features] +defmt = [ + "dep:defmt", + "embassy-stm32/defmt", + "embassy-boot-stm32/defmt", + "embassy-sync/defmt", +] +skip-include = [] diff --git a/examples/boot-usb-dfu/application/stm32wb/README.md b/examples/boot-usb-dfu/application/stm32wb/README.md new file mode 100644 index 000000000..c8dce0387 --- /dev/null +++ b/examples/boot-usb-dfu/application/stm32wb/README.md @@ -0,0 +1,29 @@ +# Examples using bootloader + +Example for STM32WL demonstrating the bootloader. The example consists of application binaries, 'a' +which allows you to press a button to start the DFU process, and 'b' which is the updated +application. + + +## Prerequisites + +* `cargo-binutils` +* `cargo-flash` +* `embassy-boot-stm32` + +## Usage + +``` +# Flash bootloader +cargo flash --manifest-path ../../bootloader/stm32/Cargo.toml --release --features embassy-stm32/stm32wl55jc-cm4 --chip STM32WLE5JCIx +# Build 'b' +cargo build --release --bin b +# Generate binary for 'b' +cargo objcopy --release --bin b -- -O binary b.bin +``` + +# Flash `a` (which includes b.bin) + +``` +cargo flash --release --bin a --chip STM32WLE5JCIx +``` diff --git a/examples/boot-usb-dfu/application/stm32wb/build.rs b/examples/boot-usb-dfu/application/stm32wb/build.rs new file mode 100644 index 000000000..e1da69328 --- /dev/null +++ b/examples/boot-usb-dfu/application/stm32wb/build.rs @@ -0,0 +1,37 @@ +//! 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"); + if env::var("CARGO_FEATURE_DEFMT").is_ok() { + println!("cargo:rustc-link-arg-bins=-Tdefmt.x"); + } +} diff --git a/examples/boot-usb-dfu/application/stm32wb/memory.x b/examples/boot-usb-dfu/application/stm32wb/memory.x new file mode 100644 index 000000000..f51875766 --- /dev/null +++ b/examples/boot-usb-dfu/application/stm32wb/memory.x @@ -0,0 +1,15 @@ +MEMORY +{ + /* NOTE 1 K = 1 KiBi = 1024 bytes */ + BOOTLOADER : ORIGIN = 0x08000000, LENGTH = 24K + BOOTLOADER_STATE : ORIGIN = 0x08006000, LENGTH = 4K + FLASH : ORIGIN = 0x08008000, LENGTH = 32K + DFU : ORIGIN = 0x08010000, LENGTH = 36K + RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 32K +} + +__bootloader_state_start = ORIGIN(BOOTLOADER_STATE) - ORIGIN(BOOTLOADER); +__bootloader_state_end = ORIGIN(BOOTLOADER_STATE) + LENGTH(BOOTLOADER_STATE) - ORIGIN(BOOTLOADER); + +__bootloader_dfu_start = ORIGIN(DFU) - ORIGIN(BOOTLOADER); +__bootloader_dfu_end = ORIGIN(DFU) + LENGTH(DFU) - ORIGIN(BOOTLOADER); diff --git a/examples/boot-usb-dfu/application/stm32wb/src/main.rs b/examples/boot-usb-dfu/application/stm32wb/src/main.rs new file mode 100644 index 000000000..f03003ffe --- /dev/null +++ b/examples/boot-usb-dfu/application/stm32wb/src/main.rs @@ -0,0 +1,64 @@ +#![no_std] +#![no_main] +#![feature(type_alias_impl_trait)] + +use core::cell::RefCell; + +#[cfg(feature = "defmt-rtt")] +use defmt_rtt::*; +use embassy_boot_stm32::{AlignedBuffer, BlockingFirmwareUpdater, FirmwareUpdaterConfig}; +use embassy_executor::Spawner; +use embassy_stm32::flash::{Flash, WRITE_SIZE}; +use embassy_stm32::rcc::WPAN_DEFAULT; +use embassy_stm32::usb::{self, Driver}; +use embassy_stm32::{bind_interrupts, peripherals}; +use embassy_sync::blocking_mutex::Mutex; +use embassy_time::Duration; +use embassy_usb::Builder; +use embassy_usb_dfu::consts::DfuAttributes; +use embassy_usb_dfu::{usb_dfu, Control}; +use panic_reset as _; + +bind_interrupts!(struct Irqs { + USB_LP => usb::InterruptHandler; +}); + +#[embassy_executor::main] +async fn main(_spawner: Spawner) { + let mut config = embassy_stm32::Config::default(); + config.rcc = WPAN_DEFAULT; + let p = embassy_stm32::init(config); + let flash = Flash::new_blocking(p.FLASH); + let flash = Mutex::new(RefCell::new(flash)); + + let config = FirmwareUpdaterConfig::from_linkerfile_blocking(&flash); + let mut magic = AlignedBuffer([0; WRITE_SIZE]); + let mut updater = BlockingFirmwareUpdater::new(config, &mut magic.0); + updater.mark_booted().expect("Failed to mark booted"); + + let driver = Driver::new(p.USB, Irqs, p.PA12, p.PA11); + let mut config = embassy_usb::Config::new(0xc0de, 0xcafe); + config.manufacturer = Some("Embassy"); + config.product = Some("USB-DFU Runtime example"); + config.serial_number = Some("1235678"); + + let mut device_descriptor = [0; 256]; + let mut config_descriptor = [0; 256]; + let mut bos_descriptor = [0; 256]; + let mut control_buf = [0; 64]; + let mut state = Control::new(updater, DfuAttributes::CAN_DOWNLOAD); + let mut builder = Builder::new( + driver, + config, + &mut device_descriptor, + &mut config_descriptor, + &mut bos_descriptor, + &mut [], + &mut control_buf, + ); + + usb_dfu::<_, _, _>(&mut builder, &mut state, Duration::from_millis(2500)); + + let mut dev = builder.build(); + dev.run().await +} diff --git a/examples/boot-usb-dfu/bootloader/stm32wb/Cargo.toml b/examples/boot-usb-dfu/bootloader/stm32wb/Cargo.toml new file mode 100644 index 000000000..774a8223d --- /dev/null +++ b/examples/boot-usb-dfu/bootloader/stm32wb/Cargo.toml @@ -0,0 +1,63 @@ +[package] +edition = "2021" +name = "stm32-bootloader-example" +version = "0.1.0" +description = "Example bootloader for STM32 chips" +license = "MIT OR Apache-2.0" + +[dependencies] +defmt = { version = "0.3", optional = true } +defmt-rtt = { version = "0.4", optional = true } + +embassy-stm32 = { path = "../../../../embassy-stm32", features = ["stm32wb55rg"] } +embassy-boot-stm32 = { path = "../../../../embassy-boot/stm32" } +cortex-m = { version = "0.7.6", features = ["inline-asm", "critical-section-single-core"] } +embassy-sync = { version = "0.5.0", path = "../../../../embassy-sync" } +cortex-m-rt = { version = "0.7" } +embedded-storage = "0.3.1" +embedded-storage-async = "0.4.0" +cfg-if = "1.0.0" +embassy-usb-dfu = { version = "0.1.0", path = "../../../../embassy-usb-dfu", features = ["bootloader"] } +embassy-usb = { version = "0.1.0", path = "../../../../embassy-usb", default-features = false } +embassy-futures = { version = "0.1.1", path = "../../../../embassy-futures" } + +[features] +defmt = [ + "dep:defmt", + "embassy-boot-stm32/defmt", + "embassy-stm32/defmt", + "embassy-usb/defmt", + "embassy-usb-dfu/defmt" +] +debug = ["defmt-rtt", "defmt"] + +[profile.dev] +debug = 2 +debug-assertions = true +incremental = false +opt-level = 'z' +overflow-checks = true + +[profile.release] +codegen-units = 1 +debug = 2 +debug-assertions = false +incremental = false +lto = 'fat' +opt-level = 'z' +overflow-checks = false + +# do not optimize proc-macro crates = faster builds from scratch +[profile.dev.build-override] +codegen-units = 8 +debug = false +debug-assertions = false +opt-level = 0 +overflow-checks = false + +[profile.release.build-override] +codegen-units = 8 +debug = false +debug-assertions = false +opt-level = 0 +overflow-checks = false diff --git a/examples/boot-usb-dfu/bootloader/stm32wb/README.md b/examples/boot-usb-dfu/bootloader/stm32wb/README.md new file mode 100644 index 000000000..a82b730b9 --- /dev/null +++ b/examples/boot-usb-dfu/bootloader/stm32wb/README.md @@ -0,0 +1,11 @@ +# Bootloader for STM32 + +The bootloader uses `embassy-boot` to interact with the flash. + +# Usage + +Flash the bootloader + +``` +cargo flash --features embassy-stm32/stm32wl55jc-cm4 --release --chip STM32WLE5JCIx +``` diff --git a/examples/boot-usb-dfu/bootloader/stm32wb/build.rs b/examples/boot-usb-dfu/bootloader/stm32wb/build.rs new file mode 100644 index 000000000..fd605991f --- /dev/null +++ b/examples/boot-usb-dfu/bootloader/stm32wb/build.rs @@ -0,0 +1,27 @@ +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"); + if env::var("CARGO_FEATURE_DEFMT").is_ok() { + println!("cargo:rustc-link-arg-bins=-Tdefmt.x"); + } +} diff --git a/examples/boot-usb-dfu/bootloader/stm32wb/memory.x b/examples/boot-usb-dfu/bootloader/stm32wb/memory.x new file mode 100644 index 000000000..b6f185ef7 --- /dev/null +++ b/examples/boot-usb-dfu/bootloader/stm32wb/memory.x @@ -0,0 +1,18 @@ +MEMORY +{ + /* NOTE 1 K = 1 KiBi = 1024 bytes */ + FLASH : ORIGIN = 0x08000000, LENGTH = 24K + BOOTLOADER_STATE : ORIGIN = 0x08006000, LENGTH = 4K + ACTIVE : ORIGIN = 0x08008000, LENGTH = 32K + DFU : ORIGIN = 0x08010000, LENGTH = 36K + RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 16K +} + +__bootloader_state_start = ORIGIN(BOOTLOADER_STATE) - ORIGIN(FLASH); +__bootloader_state_end = ORIGIN(BOOTLOADER_STATE) + LENGTH(BOOTLOADER_STATE) - ORIGIN(FLASH); + +__bootloader_active_start = ORIGIN(ACTIVE) - ORIGIN(FLASH); +__bootloader_active_end = ORIGIN(ACTIVE) + LENGTH(ACTIVE) - ORIGIN(FLASH); + +__bootloader_dfu_start = ORIGIN(DFU) - ORIGIN(FLASH); +__bootloader_dfu_end = ORIGIN(DFU) + LENGTH(DFU) - ORIGIN(FLASH); diff --git a/examples/boot-usb-dfu/bootloader/stm32wb/src/main.rs b/examples/boot-usb-dfu/bootloader/stm32wb/src/main.rs new file mode 100644 index 000000000..00a535d35 --- /dev/null +++ b/examples/boot-usb-dfu/bootloader/stm32wb/src/main.rs @@ -0,0 +1,95 @@ +#![no_std] +#![no_main] + +use core::cell::RefCell; + +use cortex_m_rt::{entry, exception}; +#[cfg(feature = "defmt")] +use defmt_rtt as _; +use embassy_boot_stm32::*; +use embassy_stm32::flash::{Flash, BANK1_REGION, WRITE_SIZE}; +use embassy_stm32::rcc::WPAN_DEFAULT; +use embassy_stm32::usb::Driver; +use embassy_stm32::{bind_interrupts, peripherals, usb}; +use embassy_sync::blocking_mutex::Mutex; +use embassy_usb::Builder; +use embassy_usb_dfu::consts::DfuAttributes; +use embassy_usb_dfu::{usb_dfu, Control}; + +bind_interrupts!(struct Irqs { + USB_LP => usb::InterruptHandler; +}); + +#[entry] +fn main() -> ! { + let mut config = embassy_stm32::Config::default(); + config.rcc = WPAN_DEFAULT; + let p = embassy_stm32::init(config); + + // Uncomment this if you are debugging the bootloader with debugger/RTT attached, + // as it prevents a hard fault when accessing flash 'too early' after boot. + /* + for i in 0..10000000 { + cortex_m::asm::nop(); + } + */ + + let layout = Flash::new_blocking(p.FLASH).into_blocking_regions(); + let flash = Mutex::new(RefCell::new(layout.bank1_region)); + + let config = BootLoaderConfig::from_linkerfile_blocking(&flash); + let active_offset = config.active.offset(); + let bl = BootLoader::prepare::<_, _, _, 2048>(config); + if bl.state == State::DfuDetach { + let driver = Driver::new(p.USB, Irqs, p.PA12, p.PA11); + let mut config = embassy_usb::Config::new(0xc0de, 0xcafe); + config.manufacturer = Some("Embassy"); + config.product = Some("USB-DFU Bootloader example"); + config.serial_number = Some("1235678"); + + let fw_config = FirmwareUpdaterConfig::from_linkerfile_blocking(&flash); + let mut buffer = AlignedBuffer([0; WRITE_SIZE]); + let updater = BlockingFirmwareUpdater::new(fw_config, &mut buffer.0[..]); + + let mut device_descriptor = [0; 256]; + let mut config_descriptor = [0; 256]; + let mut bos_descriptor = [0; 256]; + let mut control_buf = [0; 4096]; + let mut state = Control::new(updater, DfuAttributes::CAN_DOWNLOAD); + let mut builder = Builder::new( + driver, + config, + &mut device_descriptor, + &mut config_descriptor, + &mut bos_descriptor, + &mut [], + &mut control_buf, + ); + + usb_dfu::<_, _, _, 4096>(&mut builder, &mut state); + + let mut dev = builder.build(); + embassy_futures::block_on(dev.run()); + } + + unsafe { bl.load(BANK1_REGION.base + active_offset) } +} + +#[no_mangle] +#[cfg_attr(target_os = "none", link_section = ".HardFault.user")] +unsafe extern "C" fn HardFault() { + cortex_m::peripheral::SCB::sys_reset(); +} + +#[exception] +unsafe fn DefaultHandler(_: i16) -> ! { + const SCB_ICSR: *const u32 = 0xE000_ED04 as *const u32; + let irqn = core::ptr::read_volatile(SCB_ICSR) as u8 as i16 - 16; + + panic!("DefaultHandler #{:?}", irqn); +} + +#[panic_handler] +fn panic(_info: &core::panic::PanicInfo) -> ! { + cortex_m::asm::udf(); +} From b60b3f4eb8f22ecda1c30d63213010f1b6b47686 Mon Sep 17 00:00:00 2001 From: Kaitlyn Kenwell Date: Wed, 13 Dec 2023 16:19:59 -0500 Subject: [PATCH 013/124] Last fmt hopefully --- embassy-boot/boot/src/boot_loader.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/embassy-boot/boot/src/boot_loader.rs b/embassy-boot/boot/src/boot_loader.rs index 340962a7a..b3970d867 100644 --- a/embassy-boot/boot/src/boot_loader.rs +++ b/embassy-boot/boot/src/boot_loader.rs @@ -5,7 +5,7 @@ use embassy_sync::blocking_mutex::raw::NoopRawMutex; use embassy_sync::blocking_mutex::Mutex; use embedded_storage::nor_flash::{NorFlash, NorFlashError, NorFlashErrorKind}; -use crate::{State, BOOT_MAGIC, STATE_ERASE_VALUE, SWAP_MAGIC, DFU_DETACH_MAGIC}; +use crate::{State, BOOT_MAGIC, DFU_DETACH_MAGIC, STATE_ERASE_VALUE, SWAP_MAGIC}; /// Errors returned by bootloader #[derive(PartialEq, Eq, Debug)] From b17f16f0af635f4268543dcfe4cee1ec48b216a1 Mon Sep 17 00:00:00 2001 From: Priit Laes Date: Thu, 14 Dec 2023 09:11:30 +0200 Subject: [PATCH 014/124] embassy-boot: Fix formatting for tables Tables describing the a-b flashing were all garbled up in the cargo doc output, so fix up the syntax. --- embassy-boot/boot/src/boot_loader.rs | 36 +++++++++------------------- 1 file changed, 11 insertions(+), 25 deletions(-) diff --git a/embassy-boot/boot/src/boot_loader.rs b/embassy-boot/boot/src/boot_loader.rs index 1663f4f2c..65b12dc5f 100644 --- a/embassy-boot/boot/src/boot_loader.rs +++ b/embassy-boot/boot/src/boot_loader.rs @@ -135,51 +135,44 @@ impl BootLoader BootLoader Result { // Ensure we have enough progress pages to store copy progress From 879c0ad9890e80f2e7c19c715347b86b61eb432a Mon Sep 17 00:00:00 2001 From: eZio Pan Date: Thu, 14 Dec 2023 21:33:35 +0800 Subject: [PATCH 015/124] after stm32-metapac update, TIM CR1 ARPE enum to bool --- embassy-stm32/Cargo.toml | 4 ++-- embassy-stm32/src/timer/mod.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/embassy-stm32/Cargo.toml b/embassy-stm32/Cargo.toml index 074538d3b..f54d5608f 100644 --- a/embassy-stm32/Cargo.toml +++ b/embassy-stm32/Cargo.toml @@ -58,7 +58,7 @@ rand_core = "0.6.3" sdio-host = "0.5.0" embedded-sdmmc = { git = "https://github.com/embassy-rs/embedded-sdmmc-rs", rev = "a4f293d3a6f72158385f79c98634cb8a14d0d2fc", optional = true } critical-section = "1.1" -stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-8f5fcae8c289c1ad481cc3a2bb37db023a61599c" } +stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-91cee0d1fdcb4e447b65a09756b506f4af91b7e2" } vcell = "0.1.3" bxcan = "0.7.0" nb = "1.0.0" @@ -76,7 +76,7 @@ critical-section = { version = "1.1", features = ["std"] } [build-dependencies] proc-macro2 = "1.0.36" quote = "1.0.15" -stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-8f5fcae8c289c1ad481cc3a2bb37db023a61599c", default-features = false, features = ["metadata"]} +stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-91cee0d1fdcb4e447b65a09756b506f4af91b7e2", default-features = false, features = ["metadata"]} [features] diff --git a/embassy-stm32/src/timer/mod.rs b/embassy-stm32/src/timer/mod.rs index 2313a5b94..9f93c6425 100644 --- a/embassy-stm32/src/timer/mod.rs +++ b/embassy-stm32/src/timer/mod.rs @@ -77,7 +77,7 @@ pub(crate) mod sealed { Self::regs().dier().write(|r| r.set_uie(enable)); } - fn set_autoreload_preload(&mut self, enable: vals::Arpe) { + fn set_autoreload_preload(&mut self, enable: bool) { Self::regs().cr1().modify(|r| r.set_arpe(enable)); } From e27e00f6280683293f427d0731aa69ca32dbbe60 Mon Sep 17 00:00:00 2001 From: Kaitlyn Kenwell Date: Thu, 14 Dec 2023 09:36:22 -0500 Subject: [PATCH 016/124] Address reviews --- .../boot/src/firmware_updater/asynch.rs | 10 + .../boot/src/firmware_updater/blocking.rs | 10 + embassy-boot/boot/src/lib.rs | 2 +- embassy-usb-dfu/src/application.rs | 36 ++- embassy-usb-dfu/src/bootloader.rs | 8 +- embassy-usb-dfu/src/fmt.rs | 258 ++++++++++++++++++ embassy-usb-dfu/src/lib.rs | 1 + examples/boot-usb-dfu/.cargo/config.toml | 9 - .../stm32wb-dfu}/.cargo/config.toml | 0 .../application/stm32wb-dfu}/Cargo.toml | 1 + .../application/stm32wb-dfu}/README.md | 0 .../application/stm32wb-dfu}/build.rs | 0 .../application/stm32wb-dfu}/memory.x | 0 .../application/stm32wb-dfu}/src/main.rs | 0 .../bootloader/stm32wb-dfu}/Cargo.toml | 0 .../bootloader/stm32wb-dfu}/README.md | 0 .../bootloader/stm32wb-dfu}/build.rs | 0 .../bootloader/stm32wb-dfu}/memory.x | 0 .../bootloader/stm32wb-dfu}/src/main.rs | 13 +- 19 files changed, 307 insertions(+), 41 deletions(-) create mode 100644 embassy-usb-dfu/src/fmt.rs delete mode 100644 examples/boot-usb-dfu/.cargo/config.toml rename examples/{boot-usb-dfu/application/stm32wb => boot/application/stm32wb-dfu}/.cargo/config.toml (100%) rename examples/{boot-usb-dfu/application/stm32wb => boot/application/stm32wb-dfu}/Cargo.toml (98%) rename examples/{boot-usb-dfu/application/stm32wb => boot/application/stm32wb-dfu}/README.md (100%) rename examples/{boot-usb-dfu/application/stm32wb => boot/application/stm32wb-dfu}/build.rs (100%) rename examples/{boot-usb-dfu/application/stm32wb => boot/application/stm32wb-dfu}/memory.x (100%) rename examples/{boot-usb-dfu/application/stm32wb => boot/application/stm32wb-dfu}/src/main.rs (100%) rename examples/{boot-usb-dfu/bootloader/stm32wb => boot/bootloader/stm32wb-dfu}/Cargo.toml (100%) rename examples/{boot-usb-dfu/bootloader/stm32wb => boot/bootloader/stm32wb-dfu}/README.md (100%) rename examples/{boot-usb-dfu/bootloader/stm32wb => boot/bootloader/stm32wb-dfu}/build.rs (100%) rename examples/{boot-usb-dfu/bootloader/stm32wb => boot/bootloader/stm32wb-dfu}/memory.x (100%) rename examples/{boot-usb-dfu/bootloader/stm32wb => boot/bootloader/stm32wb-dfu}/src/main.rs (91%) diff --git a/embassy-boot/boot/src/firmware_updater/asynch.rs b/embassy-boot/boot/src/firmware_updater/asynch.rs index 82e99965b..d8d85c3d2 100644 --- a/embassy-boot/boot/src/firmware_updater/asynch.rs +++ b/embassy-boot/boot/src/firmware_updater/asynch.rs @@ -213,6 +213,16 @@ pub struct FirmwareState<'d, STATE> { } impl<'d, STATE: NorFlash> FirmwareState<'d, STATE> { + /// Create a firmware state instance from a FirmwareUpdaterConfig with a buffer for magic content and state partition. + /// + /// # Safety + /// + /// The `aligned` buffer must have a size of STATE::WRITE_SIZE, and follow the alignment rules for the flash being read from + /// and written to. + pub fn from_config(config: FirmwareUpdaterConfig, aligned: &'d mut [u8]) -> Self { + Self::new(config.state, aligned) + } + /// Create a firmware state instance with a buffer for magic content and state partition. /// /// # Safety diff --git a/embassy-boot/boot/src/firmware_updater/blocking.rs b/embassy-boot/boot/src/firmware_updater/blocking.rs index ae4179ba3..4f56f152d 100644 --- a/embassy-boot/boot/src/firmware_updater/blocking.rs +++ b/embassy-boot/boot/src/firmware_updater/blocking.rs @@ -219,6 +219,16 @@ pub struct BlockingFirmwareState<'d, STATE> { } impl<'d, STATE: NorFlash> BlockingFirmwareState<'d, STATE> { + /// Creates a firmware state instance from a FirmwareUpdaterConfig, with a buffer for magic content and state partition. + /// + /// # Safety + /// + /// The `aligned` buffer must have a size of STATE::WRITE_SIZE, and follow the alignment rules for the flash being read from + /// and written to. + pub fn from_config(config: FirmwareUpdaterConfig, aligned: &'d mut [u8]) -> Self { + Self::new(config.state, aligned) + } + /// Create a firmware state instance with a buffer for magic content and state partition. /// /// # Safety diff --git a/embassy-boot/boot/src/lib.rs b/embassy-boot/boot/src/lib.rs index 451992945..15b69f69d 100644 --- a/embassy-boot/boot/src/lib.rs +++ b/embassy-boot/boot/src/lib.rs @@ -33,7 +33,7 @@ pub enum State { Boot, /// Bootloader has swapped the active partition with the dfu partition and will attempt boot. Swap, - /// Application has received a DFU_DETACH request over USB, and is rebooting into the bootloader to apply a DFU. + /// Application has received a request to reboot into DFU mode to apply an update. DfuDetach, } diff --git a/embassy-usb-dfu/src/application.rs b/embassy-usb-dfu/src/application.rs index 2e7bda121..0b7b53af8 100644 --- a/embassy-usb-dfu/src/application.rs +++ b/embassy-usb-dfu/src/application.rs @@ -1,4 +1,4 @@ -use embassy_boot::BlockingFirmwareUpdater; +use embassy_boot::BlockingFirmwareState; use embassy_time::{Duration, Instant}; use embassy_usb::control::{InResponse, OutResponse, Recipient, RequestType}; use embassy_usb::driver::Driver; @@ -11,18 +11,18 @@ use crate::consts::{ }; /// Internal state for the DFU class -pub struct Control<'d, DFU: NorFlash, STATE: NorFlash> { - updater: BlockingFirmwareUpdater<'d, DFU, STATE>, +pub struct Control<'d, STATE: NorFlash> { + firmware_state: BlockingFirmwareState<'d, STATE>, attrs: DfuAttributes, state: State, timeout: Option, detach_start: Option, } -impl<'d, DFU: NorFlash, STATE: NorFlash> Control<'d, DFU, STATE> { - pub fn new(updater: BlockingFirmwareUpdater<'d, DFU, STATE>, attrs: DfuAttributes) -> Self { +impl<'d, STATE: NorFlash> Control<'d, STATE> { + pub fn new(firmware_state: BlockingFirmwareState<'d, STATE>, attrs: DfuAttributes) -> Self { Control { - updater, + firmware_state, attrs, state: State::AppIdle, detach_start: None, @@ -31,19 +31,20 @@ impl<'d, DFU: NorFlash, STATE: NorFlash> Control<'d, DFU, STATE> { } } -impl<'d, DFU: NorFlash, STATE: NorFlash> Handler for Control<'d, DFU, STATE> { +impl<'d, STATE: NorFlash> Handler for Control<'d, STATE> { fn reset(&mut self) { if let Some(start) = self.detach_start { let delta = Instant::now() - start; let timeout = self.timeout.unwrap(); - #[cfg(feature = "defmt")] - defmt::info!( + trace!( "Received RESET with delta = {}, timeout = {}", delta.as_millis(), timeout.as_millis() ); if delta < timeout { - self.updater.mark_dfu().expect("Failed to mark DFU mode in bootloader"); + self.firmware_state + .mark_dfu() + .expect("Failed to mark DFU mode in bootloader"); cortex_m::asm::dsb(); cortex_m::peripheral::SCB::sys_reset(); } @@ -59,13 +60,11 @@ impl<'d, DFU: NorFlash, STATE: NorFlash> Handler for Control<'d, DFU, STATE> { return None; } - #[cfg(feature = "defmt")] - defmt::info!("Received request {}", req); + trace!("Received request {}", req); match Request::try_from(req.request) { Ok(Request::Detach) => { - #[cfg(feature = "defmt")] - defmt::info!("Received DETACH, awaiting USB reset"); + trace!("Received DETACH, awaiting USB reset"); self.detach_start = Some(Instant::now()); self.timeout = Some(Duration::from_millis(req.value as u64)); self.state = State::AppDetach; @@ -84,8 +83,7 @@ impl<'d, DFU: NorFlash, STATE: NorFlash> Handler for Control<'d, DFU, STATE> { return None; } - #[cfg(feature = "defmt")] - defmt::info!("Received request {}", req); + trace!("Received request {}", req); match Request::try_from(req.request) { Ok(Request::GetStatus) => { @@ -106,13 +104,11 @@ impl<'d, DFU: NorFlash, STATE: NorFlash> Handler for Control<'d, DFU, STATE> { /// it should expose a DFU device, and a software reset will be issued. /// /// To apply USB DFU updates, the bootloader must be capable of recognizing the DFU magic and exposing a device to handle the full DFU transaction with the host. -pub fn usb_dfu<'d, D: Driver<'d>, DFU: NorFlash, STATE: NorFlash>( +pub fn usb_dfu<'d, D: Driver<'d>, STATE: NorFlash>( builder: &mut Builder<'d, D>, - handler: &'d mut Control<'d, DFU, STATE>, + handler: &'d mut Control<'d, STATE>, timeout: Duration, ) { - #[cfg(feature = "defmt")] - defmt::info!("Application USB DFU initializing"); let mut func = builder.function(0x00, 0x00, 0x00); let mut iface = func.interface(); let mut alt = iface.alt_setting(USB_CLASS_APPN_SPEC, APPN_SPEC_SUBCLASS_DFU, DFU_PROTOCOL_RT, None); diff --git a/embassy-usb-dfu/src/bootloader.rs b/embassy-usb-dfu/src/bootloader.rs index 215058932..99384d961 100644 --- a/embassy-usb-dfu/src/bootloader.rs +++ b/embassy-usb-dfu/src/bootloader.rs @@ -1,4 +1,4 @@ -use embassy_boot::BlockingFirmwareUpdater; +use embassy_boot::{AlignedBuffer, BlockingFirmwareUpdater}; use embassy_usb::control::{InResponse, OutResponse, Recipient, RequestType}; use embassy_usb::driver::Driver; use embassy_usb::{Builder, Handler}; @@ -56,8 +56,8 @@ impl<'d, DFU: NorFlash, STATE: NorFlash, const BLOCK_SIZE: usize> Handler for Co self.offset = 0; } - let mut buf = [0; BLOCK_SIZE]; - buf[..data.len()].copy_from_slice(data); + let mut buf = AlignedBuffer([0; BLOCK_SIZE]); + buf.as_mut()[..data.len()].copy_from_slice(data); if req.length == 0 { match self.updater.mark_updated() { @@ -85,7 +85,7 @@ impl<'d, DFU: NorFlash, STATE: NorFlash, const BLOCK_SIZE: usize> Handler for Co self.state = State::Error; return Some(OutResponse::Rejected); } - match self.updater.write_firmware(self.offset, &buf[..]) { + match self.updater.write_firmware(self.offset, buf.as_ref()) { Ok(_) => { self.status = Status::Ok; self.state = State::DlSync; diff --git a/embassy-usb-dfu/src/fmt.rs b/embassy-usb-dfu/src/fmt.rs new file mode 100644 index 000000000..78e583c1c --- /dev/null +++ b/embassy-usb-dfu/src/fmt.rs @@ -0,0 +1,258 @@ +#![macro_use] +#![allow(unused_macros)] + +use core::fmt::{Debug, Display, LowerHex}; + +#[cfg(all(feature = "defmt", feature = "log"))] +compile_error!("You may not enable both `defmt` and `log` features."); + +macro_rules! assert { + ($($x:tt)*) => { + { + #[cfg(not(feature = "defmt"))] + ::core::assert!($($x)*); + #[cfg(feature = "defmt")] + ::defmt::assert!($($x)*); + } + }; +} + +macro_rules! assert_eq { + ($($x:tt)*) => { + { + #[cfg(not(feature = "defmt"))] + ::core::assert_eq!($($x)*); + #[cfg(feature = "defmt")] + ::defmt::assert_eq!($($x)*); + } + }; +} + +macro_rules! assert_ne { + ($($x:tt)*) => { + { + #[cfg(not(feature = "defmt"))] + ::core::assert_ne!($($x)*); + #[cfg(feature = "defmt")] + ::defmt::assert_ne!($($x)*); + } + }; +} + +macro_rules! debug_assert { + ($($x:tt)*) => { + { + #[cfg(not(feature = "defmt"))] + ::core::debug_assert!($($x)*); + #[cfg(feature = "defmt")] + ::defmt::debug_assert!($($x)*); + } + }; +} + +macro_rules! debug_assert_eq { + ($($x:tt)*) => { + { + #[cfg(not(feature = "defmt"))] + ::core::debug_assert_eq!($($x)*); + #[cfg(feature = "defmt")] + ::defmt::debug_assert_eq!($($x)*); + } + }; +} + +macro_rules! debug_assert_ne { + ($($x:tt)*) => { + { + #[cfg(not(feature = "defmt"))] + ::core::debug_assert_ne!($($x)*); + #[cfg(feature = "defmt")] + ::defmt::debug_assert_ne!($($x)*); + } + }; +} + +macro_rules! todo { + ($($x:tt)*) => { + { + #[cfg(not(feature = "defmt"))] + ::core::todo!($($x)*); + #[cfg(feature = "defmt")] + ::defmt::todo!($($x)*); + } + }; +} + +#[cfg(not(feature = "defmt"))] +macro_rules! unreachable { + ($($x:tt)*) => { + ::core::unreachable!($($x)*) + }; +} + +#[cfg(feature = "defmt")] +macro_rules! unreachable { + ($($x:tt)*) => { + ::defmt::unreachable!($($x)*) + }; +} + +macro_rules! panic { + ($($x:tt)*) => { + { + #[cfg(not(feature = "defmt"))] + ::core::panic!($($x)*); + #[cfg(feature = "defmt")] + ::defmt::panic!($($x)*); + } + }; +} + +macro_rules! trace { + ($s:literal $(, $x:expr)* $(,)?) => { + { + #[cfg(feature = "log")] + ::log::trace!($s $(, $x)*); + #[cfg(feature = "defmt")] + ::defmt::trace!($s $(, $x)*); + #[cfg(not(any(feature = "log", feature="defmt")))] + let _ = ($( & $x ),*); + } + }; +} + +macro_rules! debug { + ($s:literal $(, $x:expr)* $(,)?) => { + { + #[cfg(feature = "log")] + ::log::debug!($s $(, $x)*); + #[cfg(feature = "defmt")] + ::defmt::debug!($s $(, $x)*); + #[cfg(not(any(feature = "log", feature="defmt")))] + let _ = ($( & $x ),*); + } + }; +} + +macro_rules! info { + ($s:literal $(, $x:expr)* $(,)?) => { + { + #[cfg(feature = "log")] + ::log::info!($s $(, $x)*); + #[cfg(feature = "defmt")] + ::defmt::info!($s $(, $x)*); + #[cfg(not(any(feature = "log", feature="defmt")))] + let _ = ($( & $x ),*); + } + }; +} + +macro_rules! warn { + ($s:literal $(, $x:expr)* $(,)?) => { + { + #[cfg(feature = "log")] + ::log::warn!($s $(, $x)*); + #[cfg(feature = "defmt")] + ::defmt::warn!($s $(, $x)*); + #[cfg(not(any(feature = "log", feature="defmt")))] + let _ = ($( & $x ),*); + } + }; +} + +macro_rules! error { + ($s:literal $(, $x:expr)* $(,)?) => { + { + #[cfg(feature = "log")] + ::log::error!($s $(, $x)*); + #[cfg(feature = "defmt")] + ::defmt::error!($s $(, $x)*); + #[cfg(not(any(feature = "log", feature="defmt")))] + let _ = ($( & $x ),*); + } + }; +} + +#[cfg(feature = "defmt")] +macro_rules! unwrap { + ($($x:tt)*) => { + ::defmt::unwrap!($($x)*) + }; +} + +#[cfg(not(feature = "defmt"))] +macro_rules! unwrap { + ($arg:expr) => { + match $crate::fmt::Try::into_result($arg) { + ::core::result::Result::Ok(t) => t, + ::core::result::Result::Err(e) => { + ::core::panic!("unwrap of `{}` failed: {:?}", ::core::stringify!($arg), e); + } + } + }; + ($arg:expr, $($msg:expr),+ $(,)? ) => { + match $crate::fmt::Try::into_result($arg) { + ::core::result::Result::Ok(t) => t, + ::core::result::Result::Err(e) => { + ::core::panic!("unwrap of `{}` failed: {}: {:?}", ::core::stringify!($arg), ::core::format_args!($($msg,)*), e); + } + } + } +} + +#[derive(Debug, Copy, Clone, Eq, PartialEq)] +pub struct NoneError; + +pub trait Try { + type Ok; + type Error; + fn into_result(self) -> Result; +} + +impl Try for Option { + type Ok = T; + type Error = NoneError; + + #[inline] + fn into_result(self) -> Result { + self.ok_or(NoneError) + } +} + +impl Try for Result { + type Ok = T; + type Error = E; + + #[inline] + fn into_result(self) -> Self { + self + } +} + +#[allow(unused)] +pub(crate) struct Bytes<'a>(pub &'a [u8]); + +impl<'a> Debug for Bytes<'a> { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + write!(f, "{:#02x?}", self.0) + } +} + +impl<'a> Display for Bytes<'a> { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + write!(f, "{:#02x?}", self.0) + } +} + +impl<'a> LowerHex for Bytes<'a> { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + write!(f, "{:#02x?}", self.0) + } +} + +#[cfg(feature = "defmt")] +impl<'a> defmt::Format for Bytes<'a> { + fn format(&self, fmt: defmt::Formatter) { + defmt::write!(fmt, "{:02x}", self.0) + } +} diff --git a/embassy-usb-dfu/src/lib.rs b/embassy-usb-dfu/src/lib.rs index 81ef041f8..ae0fbbd4c 100644 --- a/embassy-usb-dfu/src/lib.rs +++ b/embassy-usb-dfu/src/lib.rs @@ -1,4 +1,5 @@ #![no_std] +mod fmt; pub mod consts; diff --git a/examples/boot-usb-dfu/.cargo/config.toml b/examples/boot-usb-dfu/.cargo/config.toml deleted file mode 100644 index de3a814f7..000000000 --- a/examples/boot-usb-dfu/.cargo/config.toml +++ /dev/null @@ -1,9 +0,0 @@ -[unstable] -build-std = ["core"] -build-std-features = ["panic_immediate_abort"] - -[build] -target = "thumbv7em-none-eabi" - -[env] -DEFMT_LOG = "trace" diff --git a/examples/boot-usb-dfu/application/stm32wb/.cargo/config.toml b/examples/boot/application/stm32wb-dfu/.cargo/config.toml similarity index 100% rename from examples/boot-usb-dfu/application/stm32wb/.cargo/config.toml rename to examples/boot/application/stm32wb-dfu/.cargo/config.toml diff --git a/examples/boot-usb-dfu/application/stm32wb/Cargo.toml b/examples/boot/application/stm32wb-dfu/Cargo.toml similarity index 98% rename from examples/boot-usb-dfu/application/stm32wb/Cargo.toml rename to examples/boot/application/stm32wb-dfu/Cargo.toml index 0a41c0648..e67224ce6 100644 --- a/examples/boot-usb-dfu/application/stm32wb/Cargo.toml +++ b/examples/boot/application/stm32wb-dfu/Cargo.toml @@ -25,6 +25,7 @@ cortex-m-rt = "0.7.0" [features] defmt = [ "dep:defmt", + "dep:defmt-rtt", "embassy-stm32/defmt", "embassy-boot-stm32/defmt", "embassy-sync/defmt", diff --git a/examples/boot-usb-dfu/application/stm32wb/README.md b/examples/boot/application/stm32wb-dfu/README.md similarity index 100% rename from examples/boot-usb-dfu/application/stm32wb/README.md rename to examples/boot/application/stm32wb-dfu/README.md diff --git a/examples/boot-usb-dfu/application/stm32wb/build.rs b/examples/boot/application/stm32wb-dfu/build.rs similarity index 100% rename from examples/boot-usb-dfu/application/stm32wb/build.rs rename to examples/boot/application/stm32wb-dfu/build.rs diff --git a/examples/boot-usb-dfu/application/stm32wb/memory.x b/examples/boot/application/stm32wb-dfu/memory.x similarity index 100% rename from examples/boot-usb-dfu/application/stm32wb/memory.x rename to examples/boot/application/stm32wb-dfu/memory.x diff --git a/examples/boot-usb-dfu/application/stm32wb/src/main.rs b/examples/boot/application/stm32wb-dfu/src/main.rs similarity index 100% rename from examples/boot-usb-dfu/application/stm32wb/src/main.rs rename to examples/boot/application/stm32wb-dfu/src/main.rs diff --git a/examples/boot-usb-dfu/bootloader/stm32wb/Cargo.toml b/examples/boot/bootloader/stm32wb-dfu/Cargo.toml similarity index 100% rename from examples/boot-usb-dfu/bootloader/stm32wb/Cargo.toml rename to examples/boot/bootloader/stm32wb-dfu/Cargo.toml diff --git a/examples/boot-usb-dfu/bootloader/stm32wb/README.md b/examples/boot/bootloader/stm32wb-dfu/README.md similarity index 100% rename from examples/boot-usb-dfu/bootloader/stm32wb/README.md rename to examples/boot/bootloader/stm32wb-dfu/README.md diff --git a/examples/boot-usb-dfu/bootloader/stm32wb/build.rs b/examples/boot/bootloader/stm32wb-dfu/build.rs similarity index 100% rename from examples/boot-usb-dfu/bootloader/stm32wb/build.rs rename to examples/boot/bootloader/stm32wb-dfu/build.rs diff --git a/examples/boot-usb-dfu/bootloader/stm32wb/memory.x b/examples/boot/bootloader/stm32wb-dfu/memory.x similarity index 100% rename from examples/boot-usb-dfu/bootloader/stm32wb/memory.x rename to examples/boot/bootloader/stm32wb-dfu/memory.x diff --git a/examples/boot-usb-dfu/bootloader/stm32wb/src/main.rs b/examples/boot/bootloader/stm32wb-dfu/src/main.rs similarity index 91% rename from examples/boot-usb-dfu/bootloader/stm32wb/src/main.rs rename to examples/boot/bootloader/stm32wb-dfu/src/main.rs index 00a535d35..a2b884770 100644 --- a/examples/boot-usb-dfu/bootloader/stm32wb/src/main.rs +++ b/examples/boot/bootloader/stm32wb-dfu/src/main.rs @@ -26,13 +26,12 @@ fn main() -> ! { config.rcc = WPAN_DEFAULT; let p = embassy_stm32::init(config); - // Uncomment this if you are debugging the bootloader with debugger/RTT attached, - // as it prevents a hard fault when accessing flash 'too early' after boot. - /* - for i in 0..10000000 { - cortex_m::asm::nop(); - } - */ + // Prevent a hard fault when accessing flash 'too early' after boot. + #[cfg(feature = "defmt")] + for _ in 0..10000000 { + cortex_m::asm::nop(); + } + let layout = Flash::new_blocking(p.FLASH).into_blocking_regions(); let flash = Mutex::new(RefCell::new(layout.bank1_region)); From c1438fe87bf363b018231bd36e188c72679eb202 Mon Sep 17 00:00:00 2001 From: Kaitlyn Kenwell Date: Thu, 14 Dec 2023 09:38:02 -0500 Subject: [PATCH 017/124] fmt --- embassy-boot/boot/src/firmware_updater/blocking.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/embassy-boot/boot/src/firmware_updater/blocking.rs b/embassy-boot/boot/src/firmware_updater/blocking.rs index 4f56f152d..c4c142169 100644 --- a/embassy-boot/boot/src/firmware_updater/blocking.rs +++ b/embassy-boot/boot/src/firmware_updater/blocking.rs @@ -220,9 +220,9 @@ pub struct BlockingFirmwareState<'d, STATE> { impl<'d, STATE: NorFlash> BlockingFirmwareState<'d, STATE> { /// Creates a firmware state instance from a FirmwareUpdaterConfig, with a buffer for magic content and state partition. - /// + /// /// # Safety - /// + /// /// The `aligned` buffer must have a size of STATE::WRITE_SIZE, and follow the alignment rules for the flash being read from /// and written to. pub fn from_config(config: FirmwareUpdaterConfig, aligned: &'d mut [u8]) -> Self { From 9cc5d8ac892d4efbb629ab3bafdf341edd50ca7e Mon Sep 17 00:00:00 2001 From: Kaitlyn Kenwell Date: Thu, 14 Dec 2023 09:38:49 -0500 Subject: [PATCH 018/124] fmt --- examples/boot/bootloader/stm32wb-dfu/src/main.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/boot/bootloader/stm32wb-dfu/src/main.rs b/examples/boot/bootloader/stm32wb-dfu/src/main.rs index a2b884770..db7039e8c 100644 --- a/examples/boot/bootloader/stm32wb-dfu/src/main.rs +++ b/examples/boot/bootloader/stm32wb-dfu/src/main.rs @@ -31,7 +31,6 @@ fn main() -> ! { for _ in 0..10000000 { cortex_m::asm::nop(); } - let layout = Flash::new_blocking(p.FLASH).into_blocking_regions(); let flash = Mutex::new(RefCell::new(layout.bank1_region)); From ef692c514101d6c91059c13af52cdd70dc5cd6e0 Mon Sep 17 00:00:00 2001 From: Kaitlyn Kenwell Date: Thu, 14 Dec 2023 10:06:36 -0500 Subject: [PATCH 019/124] SCB::sys_reset has a DSB internally, no need to replicate --- embassy-usb-dfu/src/application.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/embassy-usb-dfu/src/application.rs b/embassy-usb-dfu/src/application.rs index 0b7b53af8..5ff8f90f8 100644 --- a/embassy-usb-dfu/src/application.rs +++ b/embassy-usb-dfu/src/application.rs @@ -45,7 +45,6 @@ impl<'d, STATE: NorFlash> Handler for Control<'d, STATE> { self.firmware_state .mark_dfu() .expect("Failed to mark DFU mode in bootloader"); - cortex_m::asm::dsb(); cortex_m::peripheral::SCB::sys_reset(); } } From d81395fab3c4e336650b0481790ecdab7d7aa13f Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Thu, 14 Dec 2023 16:01:51 +0100 Subject: [PATCH 020/124] Update embedded-hal to 1.0.0-rc.3 --- cyw43/Cargo.toml | 2 +- .../layer-by-layer/blinky-hal/src/main.rs | 2 +- embassy-embedded-hal/Cargo.toml | 4 +- embassy-net-adin1110/Cargo.toml | 8 +- embassy-net-enc28j60/Cargo.toml | 4 +- embassy-net-esp-hosted/Cargo.toml | 4 +- embassy-net-wiznet/Cargo.toml | 4 +- embassy-nrf/Cargo.toml | 5 +- embassy-nrf/src/gpio.rs | 67 +++++++----- embassy-nrf/src/gpiote.rs | 10 +- embassy-rp/Cargo.toml | 6 +- embassy-rp/src/gpio.rs | 101 ++++++++++-------- embassy-stm32/Cargo.toml | 6 +- embassy-stm32/src/exti.rs | 14 +-- embassy-stm32/src/gpio.rs | 94 ++++++++-------- embassy-time/CHANGELOG.md | 4 +- embassy-time/Cargo.toml | 4 +- examples/nrf52840/Cargo.toml | 6 +- examples/rp/Cargo.toml | 6 +- examples/rp/src/bin/button.rs | 2 +- examples/stm32c0/src/bin/button.rs | 2 +- examples/stm32f3/src/bin/button.rs | 2 +- examples/stm32f4/src/bin/button.rs | 2 +- examples/stm32f7/src/bin/button.rs | 2 +- examples/stm32g0/src/bin/button.rs | 2 +- examples/stm32g4/src/bin/button.rs | 2 +- examples/stm32h5/Cargo.toml | 4 +- examples/stm32h7/Cargo.toml | 4 +- examples/stm32l0/src/bin/button.rs | 2 +- examples/stm32l4/Cargo.toml | 6 +- examples/stm32l4/src/bin/button.rs | 2 +- .../src/bin/spe_adin1110_http_server.rs | 8 +- .../stm32l4/src/bin/spi_blocking_async.rs | 2 +- examples/stm32l4/src/bin/spi_dma.rs | 2 +- examples/stm32wl/src/bin/button.rs | 2 +- tests/nrf/Cargo.toml | 4 +- tests/rp/Cargo.toml | 6 +- tests/rp/src/bin/gpio.rs | 10 +- tests/rp/src/bin/pwm.rs | 8 +- tests/stm32/Cargo.toml | 4 +- tests/stm32/src/bin/gpio.rs | 12 +-- 41 files changed, 238 insertions(+), 203 deletions(-) diff --git a/cyw43/Cargo.toml b/cyw43/Cargo.toml index 293c00982..72faad805 100644 --- a/cyw43/Cargo.toml +++ b/cyw43/Cargo.toml @@ -23,7 +23,7 @@ cortex-m = "0.7.6" cortex-m-rt = "0.7.0" futures = { version = "0.3.17", default-features = false, features = ["async-await", "cfg-target-has-atomic", "unstable"] } -embedded-hal-1 = { package = "embedded-hal", version = "1.0.0-rc.2" } +embedded-hal-1 = { package = "embedded-hal", version = "1.0.0-rc.3" } num_enum = { version = "0.5.7", default-features = false } [package.metadata.embassy_docs] diff --git a/docs/modules/ROOT/examples/layer-by-layer/blinky-hal/src/main.rs b/docs/modules/ROOT/examples/layer-by-layer/blinky-hal/src/main.rs index d0c9f4907..54b87662e 100644 --- a/docs/modules/ROOT/examples/layer-by-layer/blinky-hal/src/main.rs +++ b/docs/modules/ROOT/examples/layer-by-layer/blinky-hal/src/main.rs @@ -9,7 +9,7 @@ use {defmt_rtt as _, panic_probe as _}; fn main() -> ! { let p = embassy_stm32::init(Default::default()); let mut led = Output::new(p.PB14, Level::High, Speed::VeryHigh); - let button = Input::new(p.PC13, Pull::Up); + let mut button = Input::new(p.PC13, Pull::Up); loop { if button.is_low() { diff --git a/embassy-embedded-hal/Cargo.toml b/embassy-embedded-hal/Cargo.toml index 2a0b25479..f292f952d 100644 --- a/embassy-embedded-hal/Cargo.toml +++ b/embassy-embedded-hal/Cargo.toml @@ -23,8 +23,8 @@ embassy-time = { version = "0.2", path = "../embassy-time", optional = true } embedded-hal-02 = { package = "embedded-hal", version = "0.2.6", features = [ "unproven", ] } -embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-rc.2" } -embedded-hal-async = { version = "=1.0.0-rc.2" } +embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-rc.3" } +embedded-hal-async = { version = "=1.0.0-rc.3" } embedded-storage = "0.3.1" embedded-storage-async = { version = "0.4.1" } nb = "1.0.0" diff --git a/embassy-net-adin1110/Cargo.toml b/embassy-net-adin1110/Cargo.toml index d95b2628c..adcdfe80f 100644 --- a/embassy-net-adin1110/Cargo.toml +++ b/embassy-net-adin1110/Cargo.toml @@ -13,16 +13,16 @@ edition = "2021" heapless = "0.8" defmt = { version = "0.3", optional = true } log = { version = "0.4", default-features = false, optional = true } -embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-rc.2" } -embedded-hal-async = { version = "=1.0.0-rc.2" } -embedded-hal-bus = { version = "=0.1.0-rc.2", features = ["async"] } +embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-rc.3" } +embedded-hal-async = { version = "=1.0.0-rc.3" } +embedded-hal-bus = { version = "=0.1.0-rc.3", features = ["async"] } embassy-net-driver-channel = { version = "0.2.0", path = "../embassy-net-driver-channel" } embassy-time = { version = "0.2", path = "../embassy-time" } embassy-futures = { version = "0.1.0", path = "../embassy-futures" } bitfield = "0.14.0" [dev-dependencies] -embedded-hal-mock = { git = "https://github.com/Dirbaio/embedded-hal-mock", rev = "c5c4dca18e043e6386aee02173f61a65fea3981e", features = ["embedded-hal-async", "eh1"] } +embedded-hal-mock = { git = "https://github.com/Dirbaio/embedded-hal-mock", rev = "b5a2274759a8c484f4fae71a22f8a083fdd9d5da", features = ["embedded-hal-async", "eh1"] } crc = "3.0.1" env_logger = "0.10" critical-section = { version = "1.1.2", features = ["std"] } diff --git a/embassy-net-enc28j60/Cargo.toml b/embassy-net-enc28j60/Cargo.toml index 72e1d4e5c..8cd723c4c 100644 --- a/embassy-net-enc28j60/Cargo.toml +++ b/embassy-net-enc28j60/Cargo.toml @@ -8,8 +8,8 @@ license = "MIT OR Apache-2.0" edition = "2021" [dependencies] -embedded-hal = { version = "1.0.0-rc.2" } -embedded-hal-async = { version = "=1.0.0-rc.2" } +embedded-hal = { version = "1.0.0-rc.3" } +embedded-hal-async = { version = "=1.0.0-rc.3" } embassy-net-driver = { version = "0.2.0", path = "../embassy-net-driver" } embassy-time = { version = "0.2", path = "../embassy-time" } embassy-futures = { version = "0.1.0", path = "../embassy-futures" } diff --git a/embassy-net-esp-hosted/Cargo.toml b/embassy-net-esp-hosted/Cargo.toml index eb44a6544..70b1bbe2a 100644 --- a/embassy-net-esp-hosted/Cargo.toml +++ b/embassy-net-esp-hosted/Cargo.toml @@ -12,8 +12,8 @@ embassy-sync = { version = "0.5.0", path = "../embassy-sync"} embassy-futures = { version = "0.1.0", path = "../embassy-futures"} embassy-net-driver-channel = { version = "0.2.0", path = "../embassy-net-driver-channel"} -embedded-hal = { version = "1.0.0-rc.2" } -embedded-hal-async = { version = "=1.0.0-rc.2" } +embedded-hal = { version = "1.0.0-rc.3" } +embedded-hal-async = { version = "=1.0.0-rc.3" } noproto = { git="https://github.com/embassy-rs/noproto", rev = "f5e6d1f325b6ad4e344f60452b09576e24671f62", default-features = false, features = ["derive"] } #noproto = { version = "0.1", path = "/home/dirbaio/noproto", default-features = false, features = ["derive"] } diff --git a/embassy-net-wiznet/Cargo.toml b/embassy-net-wiznet/Cargo.toml index 9c103ebb1..a1f0b0c51 100644 --- a/embassy-net-wiznet/Cargo.toml +++ b/embassy-net-wiznet/Cargo.toml @@ -8,8 +8,8 @@ license = "MIT OR Apache-2.0" edition = "2021" [dependencies] -embedded-hal = { version = "1.0.0-rc.2" } -embedded-hal-async = { version = "=1.0.0-rc.2" } +embedded-hal = { version = "1.0.0-rc.3" } +embedded-hal-async = { version = "=1.0.0-rc.3" } embassy-net-driver-channel = { version = "0.2.0", path = "../embassy-net-driver-channel" } embassy-time = { version = "0.2", path = "../embassy-time" } embassy-futures = { version = "0.1.0", path = "../embassy-futures" } diff --git a/embassy-nrf/Cargo.toml b/embassy-nrf/Cargo.toml index a7f3cb35d..6d7440519 100644 --- a/embassy-nrf/Cargo.toml +++ b/embassy-nrf/Cargo.toml @@ -94,8 +94,8 @@ embassy-embedded-hal = {version = "0.1.0", path = "../embassy-embedded-hal" } embassy-usb-driver = {version = "0.1.0", path = "../embassy-usb-driver" } embedded-hal-02 = { package = "embedded-hal", version = "0.2.6", features = ["unproven"] } -embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-rc.2" } -embedded-hal-async = { version = "=1.0.0-rc.2" } +embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-rc.3" } +embedded-hal-async = { version = "=1.0.0-rc.3" } embedded-io = { version = "0.6.0" } embedded-io-async = { version = "0.6.1" } @@ -120,4 +120,3 @@ nrf52840-pac = { version = "0.12.0", optional = true } nrf5340-app-pac = { version = "0.12.0", optional = true } nrf5340-net-pac = { version = "0.12.0", optional = true } nrf9160-pac = { version = "0.12.0", optional = true } - diff --git a/embassy-nrf/src/gpio.rs b/embassy-nrf/src/gpio.rs index cf6225282..85977a804 100644 --- a/embassy-nrf/src/gpio.rs +++ b/embassy-nrf/src/gpio.rs @@ -52,19 +52,19 @@ impl<'d, T: Pin> Input<'d, T> { /// Test if current pin level is high. #[inline] - pub fn is_high(&self) -> bool { + pub fn is_high(&mut self) -> bool { self.pin.is_high() } /// Test if current pin level is low. #[inline] - pub fn is_low(&self) -> bool { + pub fn is_low(&mut self) -> bool { self.pin.is_low() } /// Returns current pin level #[inline] - pub fn get_level(&self) -> Level { + pub fn get_level(&mut self) -> Level { self.pin.get_level() } } @@ -160,19 +160,19 @@ impl<'d, T: Pin> Output<'d, T> { /// Is the output pin set as high? #[inline] - pub fn is_set_high(&self) -> bool { + pub fn is_set_high(&mut self) -> bool { self.pin.is_set_high() } /// Is the output pin set as low? #[inline] - pub fn is_set_low(&self) -> bool { + pub fn is_set_low(&mut self) -> bool { self.pin.is_set_low() } /// What level output is set to #[inline] - pub fn get_output_level(&self) -> Level { + pub fn get_output_level(&mut self) -> Level { self.pin.get_output_level() } } @@ -277,19 +277,24 @@ impl<'d, T: Pin> Flex<'d, T> { /// Test if current pin level is high. #[inline] - pub fn is_high(&self) -> bool { + pub fn is_high(&mut self) -> bool { !self.is_low() } /// Test if current pin level is low. #[inline] - pub fn is_low(&self) -> bool { + pub fn is_low(&mut self) -> bool { + self.ref_is_low() + } + + #[inline] + pub(crate) fn ref_is_low(&self) -> bool { self.pin.block().in_.read().bits() & (1 << self.pin.pin()) == 0 } /// Returns current pin level #[inline] - pub fn get_level(&self) -> Level { + pub fn get_level(&mut self) -> Level { self.is_high().into() } @@ -316,19 +321,25 @@ impl<'d, T: Pin> Flex<'d, T> { /// Is the output pin set as high? #[inline] - pub fn is_set_high(&self) -> bool { + pub fn is_set_high(&mut self) -> bool { !self.is_set_low() } /// Is the output pin set as low? #[inline] - pub fn is_set_low(&self) -> bool { + pub fn is_set_low(&mut self) -> bool { + self.ref_is_set_low() + } + + /// Is the output pin set as low? + #[inline] + pub(crate) fn ref_is_set_low(&self) -> bool { self.pin.block().out.read().bits() & (1 << self.pin.pin()) == 0 } /// What level output is set to #[inline] - pub fn get_output_level(&self) -> Level { + pub fn get_output_level(&mut self) -> Level { self.is_set_high().into() } } @@ -498,11 +509,11 @@ mod eh02 { type Error = Infallible; fn is_high(&self) -> Result { - Ok(self.is_high()) + Ok(!self.pin.ref_is_low()) } fn is_low(&self) -> Result { - Ok(self.is_low()) + Ok(self.pin.ref_is_low()) } } @@ -520,11 +531,11 @@ mod eh02 { impl<'d, T: Pin> embedded_hal_02::digital::v2::StatefulOutputPin for Output<'d, T> { fn is_set_high(&self) -> Result { - Ok(self.is_set_high()) + Ok(!self.pin.ref_is_set_low()) } fn is_set_low(&self) -> Result { - Ok(self.is_set_low()) + Ok(self.pin.ref_is_set_low()) } } @@ -535,11 +546,11 @@ mod eh02 { type Error = Infallible; fn is_high(&self) -> Result { - Ok(self.is_high()) + Ok(!self.ref_is_low()) } fn is_low(&self) -> Result { - Ok(self.is_low()) + Ok(self.ref_is_low()) } } @@ -557,11 +568,11 @@ mod eh02 { impl<'d, T: Pin> embedded_hal_02::digital::v2::StatefulOutputPin for Flex<'d, T> { fn is_set_high(&self) -> Result { - Ok(self.is_set_high()) + Ok(!self.ref_is_set_low()) } fn is_set_low(&self) -> Result { - Ok(self.is_set_low()) + Ok(self.ref_is_set_low()) } } } @@ -571,11 +582,11 @@ impl<'d, T: Pin> embedded_hal_1::digital::ErrorType for Input<'d, T> { } impl<'d, T: Pin> embedded_hal_1::digital::InputPin for Input<'d, T> { - fn is_high(&self) -> Result { + fn is_high(&mut self) -> Result { Ok(self.is_high()) } - fn is_low(&self) -> Result { + fn is_low(&mut self) -> Result { Ok(self.is_low()) } } @@ -595,11 +606,11 @@ impl<'d, T: Pin> embedded_hal_1::digital::OutputPin for Output<'d, T> { } impl<'d, T: Pin> embedded_hal_1::digital::StatefulOutputPin for Output<'d, T> { - fn is_set_high(&self) -> Result { + fn is_set_high(&mut self) -> Result { Ok(self.is_set_high()) } - fn is_set_low(&self) -> Result { + fn is_set_low(&mut self) -> Result { Ok(self.is_set_low()) } } @@ -612,11 +623,11 @@ impl<'d, T: Pin> embedded_hal_1::digital::ErrorType for Flex<'d, T> { /// /// If the pin is not in input mode the result is unspecified. impl<'d, T: Pin> embedded_hal_1::digital::InputPin for Flex<'d, T> { - fn is_high(&self) -> Result { + fn is_high(&mut self) -> Result { Ok(self.is_high()) } - fn is_low(&self) -> Result { + fn is_low(&mut self) -> Result { Ok(self.is_low()) } } @@ -632,11 +643,11 @@ impl<'d, T: Pin> embedded_hal_1::digital::OutputPin for Flex<'d, T> { } impl<'d, T: Pin> embedded_hal_1::digital::StatefulOutputPin for Flex<'d, T> { - fn is_set_high(&self) -> Result { + fn is_set_high(&mut self) -> Result { Ok(self.is_set_high()) } - fn is_set_low(&self) -> Result { + fn is_set_low(&mut self) -> Result { Ok(self.is_set_low()) } } diff --git a/embassy-nrf/src/gpiote.rs b/embassy-nrf/src/gpiote.rs index fd629ea76..07196abf7 100644 --- a/embassy-nrf/src/gpiote.rs +++ b/embassy-nrf/src/gpiote.rs @@ -243,7 +243,7 @@ impl<'d, C: Channel, T: GpioPin> Drop for OutputChannel<'d, C, T> { impl<'d, C: Channel, T: GpioPin> OutputChannel<'d, C, T> { /// Create a new GPIOTE output channel driver. - pub fn new(ch: impl Peripheral

+ 'd, pin: Output<'d, T>, polarity: OutputChannelPolarity) -> Self { + pub fn new(ch: impl Peripheral

+ 'd, mut pin: Output<'d, T>, polarity: OutputChannelPolarity) -> Self { into_ref!(ch); let g = regs(); let num = ch.number(); @@ -481,11 +481,11 @@ mod eh02 { type Error = Infallible; fn is_high(&self) -> Result { - Ok(self.pin.is_high()) + Ok(!self.pin.pin.ref_is_low()) } fn is_low(&self) -> Result { - Ok(self.pin.is_low()) + Ok(self.pin.pin.ref_is_low()) } } } @@ -495,11 +495,11 @@ impl<'d, C: Channel, T: GpioPin> embedded_hal_1::digital::ErrorType for InputCha } impl<'d, C: Channel, T: GpioPin> embedded_hal_1::digital::InputPin for InputChannel<'d, C, T> { - fn is_high(&self) -> Result { + fn is_high(&mut self) -> Result { Ok(self.pin.is_high()) } - fn is_low(&self) -> Result { + fn is_low(&mut self) -> Result { Ok(self.pin.is_low()) } } diff --git a/embassy-rp/Cargo.toml b/embassy-rp/Cargo.toml index dfdd1fee9..c557940b1 100644 --- a/embassy-rp/Cargo.toml +++ b/embassy-rp/Cargo.toml @@ -78,9 +78,9 @@ fixed = "1.23.1" rp-pac = { version = "6" } embedded-hal-02 = { package = "embedded-hal", version = "0.2.6", features = ["unproven"] } -embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-rc.2" } -embedded-hal-async = { version = "=1.0.0-rc.2" } -embedded-hal-nb = { version = "=1.0.0-rc.2" } +embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-rc.3" } +embedded-hal-async = { version = "=1.0.0-rc.3" } +embedded-hal-nb = { version = "=1.0.0-rc.3" } pio-proc = {version= "0.2" } pio = {version= "0.2.1" } diff --git a/embassy-rp/src/gpio.rs b/embassy-rp/src/gpio.rs index 9034f3f36..23273e627 100644 --- a/embassy-rp/src/gpio.rs +++ b/embassy-rp/src/gpio.rs @@ -105,18 +105,18 @@ impl<'d, T: Pin> Input<'d, T> { } #[inline] - pub fn is_high(&self) -> bool { + pub fn is_high(&mut self) -> bool { self.pin.is_high() } #[inline] - pub fn is_low(&self) -> bool { + pub fn is_low(&mut self) -> bool { self.pin.is_low() } /// Returns current pin level #[inline] - pub fn get_level(&self) -> Level { + pub fn get_level(&mut self) -> Level { self.pin.get_level() } @@ -357,19 +357,19 @@ impl<'d, T: Pin> Output<'d, T> { /// Is the output pin set as high? #[inline] - pub fn is_set_high(&self) -> bool { + pub fn is_set_high(&mut self) -> bool { self.pin.is_set_high() } /// Is the output pin set as low? #[inline] - pub fn is_set_low(&self) -> bool { + pub fn is_set_low(&mut self) -> bool { self.pin.is_set_low() } /// What level output is set to #[inline] - pub fn get_output_level(&self) -> Level { + pub fn get_output_level(&mut self) -> Level { self.pin.get_output_level() } @@ -434,19 +434,19 @@ impl<'d, T: Pin> OutputOpenDrain<'d, T> { /// Is the output level high? #[inline] - pub fn is_set_high(&self) -> bool { + pub fn is_set_high(&mut self) -> bool { !self.is_set_low() } /// Is the output level low? #[inline] - pub fn is_set_low(&self) -> bool { + pub fn is_set_low(&mut self) -> bool { self.pin.is_set_as_output() } /// What level output is set to #[inline] - pub fn get_output_level(&self) -> Level { + pub fn get_output_level(&mut self) -> Level { self.is_set_high().into() } @@ -457,18 +457,18 @@ impl<'d, T: Pin> OutputOpenDrain<'d, T> { } #[inline] - pub fn is_high(&self) -> bool { + pub fn is_high(&mut self) -> bool { self.pin.is_high() } #[inline] - pub fn is_low(&self) -> bool { + pub fn is_low(&mut self) -> bool { self.pin.is_low() } /// Returns current pin level #[inline] - pub fn get_level(&self) -> Level { + pub fn get_level(&mut self) -> Level { self.is_high().into() } @@ -590,7 +590,12 @@ impl<'d, T: Pin> Flex<'d, T> { } #[inline] - fn is_set_as_output(&self) -> bool { + pub fn is_set_as_output(&mut self) -> bool { + self.ref_is_set_as_output() + } + + #[inline] + pub(crate) fn ref_is_set_as_output(&self) -> bool { (self.pin.sio_oe().value().read() & self.bit()) != 0 } @@ -600,18 +605,23 @@ impl<'d, T: Pin> Flex<'d, T> { } #[inline] - pub fn is_high(&self) -> bool { + pub fn is_high(&mut self) -> bool { !self.is_low() } #[inline] - pub fn is_low(&self) -> bool { + pub fn is_low(&mut self) -> bool { + self.ref_is_low() + } + + #[inline] + pub(crate) fn ref_is_low(&self) -> bool { self.pin.sio_in().read() & self.bit() == 0 } /// Returns current pin level #[inline] - pub fn get_level(&self) -> Level { + pub fn get_level(&mut self) -> Level { self.is_high().into() } @@ -638,19 +648,24 @@ impl<'d, T: Pin> Flex<'d, T> { /// Is the output level high? #[inline] - pub fn is_set_high(&self) -> bool { + pub fn is_set_high(&mut self) -> bool { !self.is_set_low() } /// Is the output level low? #[inline] - pub fn is_set_low(&self) -> bool { + pub fn is_set_low(&mut self) -> bool { + self.ref_is_set_low() + } + + #[inline] + pub(crate) fn ref_is_set_low(&self) -> bool { (self.pin.sio_out().value().read() & self.bit()) == 0 } /// What level output is set to #[inline] - pub fn get_output_level(&self) -> Level { + pub fn get_output_level(&mut self) -> Level { self.is_set_high().into() } @@ -912,11 +927,11 @@ mod eh02 { type Error = Infallible; fn is_high(&self) -> Result { - Ok(self.is_high()) + Ok(!self.pin.ref_is_low()) } fn is_low(&self) -> Result { - Ok(self.is_low()) + Ok(self.pin.ref_is_low()) } } @@ -934,11 +949,11 @@ mod eh02 { impl<'d, T: Pin> embedded_hal_02::digital::v2::StatefulOutputPin for Output<'d, T> { fn is_set_high(&self) -> Result { - Ok(self.is_set_high()) + Ok(!self.pin.ref_is_set_low()) } fn is_set_low(&self) -> Result { - Ok(self.is_set_low()) + Ok(self.pin.ref_is_set_low()) } } @@ -954,11 +969,11 @@ mod eh02 { type Error = Infallible; fn is_high(&self) -> Result { - Ok(self.is_high()) + Ok(!self.pin.ref_is_low()) } fn is_low(&self) -> Result { - Ok(self.is_low()) + Ok(self.pin.ref_is_low()) } } @@ -978,11 +993,11 @@ mod eh02 { impl<'d, T: Pin> embedded_hal_02::digital::v2::StatefulOutputPin for OutputOpenDrain<'d, T> { fn is_set_high(&self) -> Result { - Ok(self.is_set_high()) + Ok(!self.pin.ref_is_set_as_output()) } fn is_set_low(&self) -> Result { - Ok(self.is_set_low()) + Ok(self.pin.ref_is_set_as_output()) } } @@ -998,11 +1013,11 @@ mod eh02 { type Error = Infallible; fn is_high(&self) -> Result { - Ok(self.is_high()) + Ok(!self.ref_is_low()) } fn is_low(&self) -> Result { - Ok(self.is_low()) + Ok(self.ref_is_low()) } } @@ -1020,11 +1035,11 @@ mod eh02 { impl<'d, T: Pin> embedded_hal_02::digital::v2::StatefulOutputPin for Flex<'d, T> { fn is_set_high(&self) -> Result { - Ok(self.is_set_high()) + Ok(!self.ref_is_set_low()) } fn is_set_low(&self) -> Result { - Ok(self.is_set_low()) + Ok(self.ref_is_set_low()) } } @@ -1042,11 +1057,11 @@ impl<'d, T: Pin> embedded_hal_1::digital::ErrorType for Input<'d, T> { } impl<'d, T: Pin> embedded_hal_1::digital::InputPin for Input<'d, T> { - fn is_high(&self) -> Result { + fn is_high(&mut self) -> Result { Ok(self.is_high()) } - fn is_low(&self) -> Result { + fn is_low(&mut self) -> Result { Ok(self.is_low()) } } @@ -1066,11 +1081,11 @@ impl<'d, T: Pin> embedded_hal_1::digital::OutputPin for Output<'d, T> { } impl<'d, T: Pin> embedded_hal_1::digital::StatefulOutputPin for Output<'d, T> { - fn is_set_high(&self) -> Result { + fn is_set_high(&mut self) -> Result { Ok(self.is_set_high()) } - fn is_set_low(&self) -> Result { + fn is_set_low(&mut self) -> Result { Ok(self.is_set_low()) } } @@ -1096,11 +1111,11 @@ impl<'d, T: Pin> embedded_hal_1::digital::OutputPin for OutputOpenDrain<'d, T> { } impl<'d, T: Pin> embedded_hal_1::digital::StatefulOutputPin for OutputOpenDrain<'d, T> { - fn is_set_high(&self) -> Result { + fn is_set_high(&mut self) -> Result { Ok(self.is_set_high()) } - fn is_set_low(&self) -> Result { + fn is_set_low(&mut self) -> Result { Ok(self.is_set_low()) } } @@ -1112,11 +1127,11 @@ impl<'d, T: Pin> embedded_hal_1::digital::ToggleableOutputPin for OutputOpenDrai } impl<'d, T: Pin> embedded_hal_1::digital::InputPin for OutputOpenDrain<'d, T> { - fn is_high(&self) -> Result { + fn is_high(&mut self) -> Result { Ok(self.is_high()) } - fn is_low(&self) -> Result { + fn is_low(&mut self) -> Result { Ok(self.is_low()) } } @@ -1126,11 +1141,11 @@ impl<'d, T: Pin> embedded_hal_1::digital::ErrorType for Flex<'d, T> { } impl<'d, T: Pin> embedded_hal_1::digital::InputPin for Flex<'d, T> { - fn is_high(&self) -> Result { + fn is_high(&mut self) -> Result { Ok(self.is_high()) } - fn is_low(&self) -> Result { + fn is_low(&mut self) -> Result { Ok(self.is_low()) } } @@ -1146,11 +1161,11 @@ impl<'d, T: Pin> embedded_hal_1::digital::OutputPin for Flex<'d, T> { } impl<'d, T: Pin> embedded_hal_1::digital::StatefulOutputPin for Flex<'d, T> { - fn is_set_high(&self) -> Result { + fn is_set_high(&mut self) -> Result { Ok(self.is_set_high()) } - fn is_set_low(&self) -> Result { + fn is_set_low(&mut self) -> Result { Ok(self.is_set_low()) } } diff --git a/embassy-stm32/Cargo.toml b/embassy-stm32/Cargo.toml index 074538d3b..3de15debe 100644 --- a/embassy-stm32/Cargo.toml +++ b/embassy-stm32/Cargo.toml @@ -42,9 +42,9 @@ embassy-usb-driver = {version = "0.1.0", path = "../embassy-usb-driver" } embassy-executor = { version = "0.4.0", path = "../embassy-executor", optional = true } embedded-hal-02 = { package = "embedded-hal", version = "0.2.6", features = ["unproven"] } -embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-rc.2" } -embedded-hal-async = { version = "=1.0.0-rc.2" } -embedded-hal-nb = { version = "=1.0.0-rc.2" } +embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-rc.3" } +embedded-hal-async = { version = "=1.0.0-rc.3" } +embedded-hal-nb = { version = "=1.0.0-rc.3" } embedded-storage = "0.3.1" embedded-storage-async = { version = "0.4.1" } diff --git a/embassy-stm32/src/exti.rs b/embassy-stm32/src/exti.rs index dbd24804f..e77ac30fb 100644 --- a/embassy-stm32/src/exti.rs +++ b/embassy-stm32/src/exti.rs @@ -97,15 +97,15 @@ impl<'d, T: GpioPin> ExtiInput<'d, T> { Self { pin } } - pub fn is_high(&self) -> bool { + pub fn is_high(&mut self) -> bool { self.pin.is_high() } - pub fn is_low(&self) -> bool { + pub fn is_low(&mut self) -> bool { self.pin.is_low() } - pub fn get_level(&self) -> Level { + pub fn get_level(&mut self) -> Level { self.pin.get_level() } @@ -142,11 +142,11 @@ impl<'d, T: GpioPin> embedded_hal_02::digital::v2::InputPin for ExtiInput<'d, T> type Error = Infallible; fn is_high(&self) -> Result { - Ok(self.is_high()) + Ok(!self.pin.pin.ref_is_low()) } fn is_low(&self) -> Result { - Ok(self.is_low()) + Ok(self.pin.pin.ref_is_low()) } } @@ -155,11 +155,11 @@ impl<'d, T: GpioPin> embedded_hal_1::digital::ErrorType for ExtiInput<'d, T> { } impl<'d, T: GpioPin> embedded_hal_1::digital::InputPin for ExtiInput<'d, T> { - fn is_high(&self) -> Result { + fn is_high(&mut self) -> Result { Ok(self.is_high()) } - fn is_low(&self) -> Result { + fn is_low(&mut self) -> Result { Ok(self.is_low()) } } diff --git a/embassy-stm32/src/gpio.rs b/embassy-stm32/src/gpio.rs index b863c4ffe..bb3cf2bc4 100644 --- a/embassy-stm32/src/gpio.rs +++ b/embassy-stm32/src/gpio.rs @@ -142,36 +142,46 @@ impl<'d, T: Pin> Flex<'d, T> { } #[inline] - pub fn is_high(&self) -> bool { - !self.is_low() + pub fn is_high(&mut self) -> bool { + !self.ref_is_low() } #[inline] - pub fn is_low(&self) -> bool { + pub fn is_low(&mut self) -> bool { + self.ref_is_low() + } + + #[inline] + pub(crate) fn ref_is_low(&self) -> bool { let state = self.pin.block().idr().read().idr(self.pin.pin() as _); state == vals::Idr::LOW } #[inline] - pub fn get_level(&self) -> Level { + pub fn get_level(&mut self) -> Level { self.is_high().into() } #[inline] - pub fn is_set_high(&self) -> bool { - !self.is_set_low() + pub fn is_set_high(&mut self) -> bool { + !self.ref_is_set_low() } /// Is the output pin set as low? #[inline] - pub fn is_set_low(&self) -> bool { + pub fn is_set_low(&mut self) -> bool { + self.ref_is_set_low() + } + + #[inline] + pub(crate) fn ref_is_set_low(&self) -> bool { let state = self.pin.block().odr().read().odr(self.pin.pin() as _); state == vals::Odr::LOW } /// What level output is set to #[inline] - pub fn get_output_level(&self) -> Level { + pub fn get_output_level(&mut self) -> Level { self.is_set_high().into() } @@ -310,17 +320,17 @@ impl<'d, T: Pin> Input<'d, T> { } #[inline] - pub fn is_high(&self) -> bool { + pub fn is_high(&mut self) -> bool { self.pin.is_high() } #[inline] - pub fn is_low(&self) -> bool { + pub fn is_low(&mut self) -> bool { self.pin.is_low() } #[inline] - pub fn get_level(&self) -> Level { + pub fn get_level(&mut self) -> Level { self.pin.get_level() } } @@ -399,19 +409,19 @@ impl<'d, T: Pin> Output<'d, T> { /// Is the output pin set as high? #[inline] - pub fn is_set_high(&self) -> bool { + pub fn is_set_high(&mut self) -> bool { self.pin.is_set_high() } /// Is the output pin set as low? #[inline] - pub fn is_set_low(&self) -> bool { + pub fn is_set_low(&mut self) -> bool { self.pin.is_set_low() } /// What level output is set to #[inline] - pub fn get_output_level(&self) -> Level { + pub fn get_output_level(&mut self) -> Level { self.pin.get_output_level() } @@ -453,18 +463,18 @@ impl<'d, T: Pin> OutputOpenDrain<'d, T> { } #[inline] - pub fn is_high(&self) -> bool { + pub fn is_high(&mut self) -> bool { !self.pin.is_low() } #[inline] - pub fn is_low(&self) -> bool { + pub fn is_low(&mut self) -> bool { self.pin.is_low() } /// Returns current pin level #[inline] - pub fn get_level(&self) -> Level { + pub fn get_level(&mut self) -> Level { self.pin.get_level() } @@ -488,19 +498,19 @@ impl<'d, T: Pin> OutputOpenDrain<'d, T> { /// Is the output pin set as high? #[inline] - pub fn is_set_high(&self) -> bool { + pub fn is_set_high(&mut self) -> bool { self.pin.is_set_high() } /// Is the output pin set as low? #[inline] - pub fn is_set_low(&self) -> bool { + pub fn is_set_low(&mut self) -> bool { self.pin.is_set_low() } /// What level output is set to #[inline] - pub fn get_output_level(&self) -> Level { + pub fn get_output_level(&mut self) -> Level { self.pin.get_output_level() } @@ -777,12 +787,12 @@ impl<'d, T: Pin> embedded_hal_02::digital::v2::InputPin for Input<'d, T> { #[inline] fn is_high(&self) -> Result { - Ok(self.is_high()) + Ok(!self.pin.ref_is_low()) } #[inline] fn is_low(&self) -> Result { - Ok(self.is_low()) + Ok(self.pin.ref_is_low()) } } @@ -805,13 +815,13 @@ impl<'d, T: Pin> embedded_hal_02::digital::v2::OutputPin for Output<'d, T> { impl<'d, T: Pin> embedded_hal_02::digital::v2::StatefulOutputPin for Output<'d, T> { #[inline] fn is_set_high(&self) -> Result { - Ok(self.is_set_high()) + Ok(!self.pin.ref_is_set_low()) } /// Is the output pin set as low? #[inline] fn is_set_low(&self) -> Result { - Ok(self.is_set_low()) + Ok(self.pin.ref_is_set_low()) } } @@ -843,13 +853,13 @@ impl<'d, T: Pin> embedded_hal_02::digital::v2::OutputPin for OutputOpenDrain<'d, impl<'d, T: Pin> embedded_hal_02::digital::v2::StatefulOutputPin for OutputOpenDrain<'d, T> { #[inline] fn is_set_high(&self) -> Result { - Ok(self.is_set_high()) + Ok(!self.pin.ref_is_set_low()) } /// Is the output pin set as low? #[inline] fn is_set_low(&self) -> Result { - Ok(self.is_set_low()) + Ok(self.pin.ref_is_set_low()) } } @@ -867,12 +877,12 @@ impl<'d, T: Pin> embedded_hal_02::digital::v2::InputPin for Flex<'d, T> { #[inline] fn is_high(&self) -> Result { - Ok(self.is_high()) + Ok(!self.ref_is_low()) } #[inline] fn is_low(&self) -> Result { - Ok(self.is_low()) + Ok(self.ref_is_low()) } } @@ -895,13 +905,13 @@ impl<'d, T: Pin> embedded_hal_02::digital::v2::OutputPin for Flex<'d, T> { impl<'d, T: Pin> embedded_hal_02::digital::v2::StatefulOutputPin for Flex<'d, T> { #[inline] fn is_set_high(&self) -> Result { - Ok(self.is_set_high()) + Ok(!self.ref_is_set_low()) } /// Is the output pin set as low? #[inline] fn is_set_low(&self) -> Result { - Ok(self.is_set_low()) + Ok(self.ref_is_set_low()) } } @@ -920,12 +930,12 @@ impl<'d, T: Pin> embedded_hal_1::digital::ErrorType for Input<'d, T> { impl<'d, T: Pin> embedded_hal_1::digital::InputPin for Input<'d, T> { #[inline] - fn is_high(&self) -> Result { + fn is_high(&mut self) -> Result { Ok(self.is_high()) } #[inline] - fn is_low(&self) -> Result { + fn is_low(&mut self) -> Result { Ok(self.is_low()) } } @@ -948,13 +958,13 @@ impl<'d, T: Pin> embedded_hal_1::digital::OutputPin for Output<'d, T> { impl<'d, T: Pin> embedded_hal_1::digital::StatefulOutputPin for Output<'d, T> { #[inline] - fn is_set_high(&self) -> Result { + fn is_set_high(&mut self) -> Result { Ok(self.is_set_high()) } /// Is the output pin set as low? #[inline] - fn is_set_low(&self) -> Result { + fn is_set_low(&mut self) -> Result { Ok(self.is_set_low()) } } @@ -972,12 +982,12 @@ impl<'d, T: Pin> embedded_hal_1::digital::ErrorType for OutputOpenDrain<'d, T> { impl<'d, T: Pin> embedded_hal_1::digital::InputPin for OutputOpenDrain<'d, T> { #[inline] - fn is_high(&self) -> Result { + fn is_high(&mut self) -> Result { Ok(self.is_high()) } #[inline] - fn is_low(&self) -> Result { + fn is_low(&mut self) -> Result { Ok(self.is_low()) } } @@ -996,13 +1006,13 @@ impl<'d, T: Pin> embedded_hal_1::digital::OutputPin for OutputOpenDrain<'d, T> { impl<'d, T: Pin> embedded_hal_1::digital::StatefulOutputPin for OutputOpenDrain<'d, T> { #[inline] - fn is_set_high(&self) -> Result { + fn is_set_high(&mut self) -> Result { Ok(self.is_set_high()) } /// Is the output pin set as low? #[inline] - fn is_set_low(&self) -> Result { + fn is_set_low(&mut self) -> Result { Ok(self.is_set_low()) } } @@ -1016,12 +1026,12 @@ impl<'d, T: Pin> embedded_hal_1::digital::ToggleableOutputPin for OutputOpenDrai impl<'d, T: Pin> embedded_hal_1::digital::InputPin for Flex<'d, T> { #[inline] - fn is_high(&self) -> Result { + fn is_high(&mut self) -> Result { Ok(self.is_high()) } #[inline] - fn is_low(&self) -> Result { + fn is_low(&mut self) -> Result { Ok(self.is_low()) } } @@ -1051,13 +1061,13 @@ impl<'d, T: Pin> embedded_hal_1::digital::ErrorType for Flex<'d, T> { impl<'d, T: Pin> embedded_hal_1::digital::StatefulOutputPin for Flex<'d, T> { #[inline] - fn is_set_high(&self) -> Result { + fn is_set_high(&mut self) -> Result { Ok(self.is_set_high()) } /// Is the output pin set as low? #[inline] - fn is_set_low(&self) -> Result { + fn is_set_low(&mut self) -> Result { Ok(self.is_set_low()) } } diff --git a/embassy-time/CHANGELOG.md b/embassy-time/CHANGELOG.md index d8c0c7d08..99f6ef7ac 100644 --- a/embassy-time/CHANGELOG.md +++ b/embassy-time/CHANGELOG.md @@ -24,8 +24,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## 0.1.3 - 2023-08-28 -- Update `embedded-hal-async` to `1.0.0-rc.2` -- Update `embedded-hal v1` to `1.0.0-rc.2` +- Update `embedded-hal-async` to `1.0.0-rc.3` +- Update `embedded-hal v1` to `1.0.0-rc.3` ## 0.1.2 - 2023-07-05 diff --git a/embassy-time/Cargo.toml b/embassy-time/Cargo.toml index 94e79382f..6d9b7aa69 100644 --- a/embassy-time/Cargo.toml +++ b/embassy-time/Cargo.toml @@ -235,8 +235,8 @@ defmt = { version = "0.3", optional = true } log = { version = "0.4.14", optional = true } embedded-hal-02 = { package = "embedded-hal", version = "0.2.6" } -embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-rc.2" } -embedded-hal-async = { version = "=1.0.0-rc.2" } +embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-rc.3" } +embedded-hal-async = { version = "=1.0.0-rc.3" } futures-util = { version = "0.3.17", default-features = false } critical-section = "1.1" diff --git a/examples/nrf52840/Cargo.toml b/examples/nrf52840/Cargo.toml index 65cd631f8..1c49c32e1 100644 --- a/examples/nrf52840/Cargo.toml +++ b/examples/nrf52840/Cargo.toml @@ -36,9 +36,9 @@ rand = { version = "0.8.4", default-features = false } embedded-storage = "0.3.1" usbd-hid = "0.6.0" serde = { version = "1.0.136", default-features = false } -embedded-hal = { version = "1.0.0-rc.2" } -embedded-hal-async = { version = "1.0.0-rc.2" } -embedded-hal-bus = { version = "0.1.0-rc.2", features = ["async"] } +embedded-hal = { version = "1.0.0-rc.3" } +embedded-hal-async = { version = "1.0.0-rc.3" } +embedded-hal-bus = { version = "0.1.0-rc.3", features = ["async"] } num-integer = { version = "0.1.45", default-features = false } microfft = "0.5.0" diff --git a/examples/rp/Cargo.toml b/examples/rp/Cargo.toml index 7f637758d..521f17b82 100644 --- a/examples/rp/Cargo.toml +++ b/examples/rp/Cargo.toml @@ -38,9 +38,9 @@ smart-leds = "0.3.0" heapless = "0.8" usbd-hid = "0.6.1" -embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-rc.2" } -embedded-hal-async = "1.0.0-rc.2" -embedded-hal-bus = { version = "0.1.0-rc.2", features = ["async"] } +embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-rc.3" } +embedded-hal-async = "1.0.0-rc.3" +embedded-hal-bus = { version = "0.1.0-rc.3", features = ["async"] } embedded-io-async = { version = "0.6.1", features = ["defmt-03"] } embedded-storage = { version = "0.3" } static_cell = { version = "2", features = ["nightly"]} diff --git a/examples/rp/src/bin/button.rs b/examples/rp/src/bin/button.rs index d7aa89410..a9f34ab5d 100644 --- a/examples/rp/src/bin/button.rs +++ b/examples/rp/src/bin/button.rs @@ -17,7 +17,7 @@ async fn main(_spawner: Spawner) { // Use PIN_28, Pin34 on J0 for RP Pico, as a input. // You need to add your own button. - let button = Input::new(p.PIN_28, Pull::Up); + let mut button = Input::new(p.PIN_28, Pull::Up); loop { if button.is_high() { diff --git a/examples/stm32c0/src/bin/button.rs b/examples/stm32c0/src/bin/button.rs index 72a3f5cbf..40c58013b 100644 --- a/examples/stm32c0/src/bin/button.rs +++ b/examples/stm32c0/src/bin/button.rs @@ -13,7 +13,7 @@ fn main() -> ! { let p = embassy_stm32::init(Default::default()); - let button = Input::new(p.PC13, Pull::Up); + let mut button = Input::new(p.PC13, Pull::Up); loop { if button.is_high() { diff --git a/examples/stm32f3/src/bin/button.rs b/examples/stm32f3/src/bin/button.rs index b55bf3901..2f47d8f80 100644 --- a/examples/stm32f3/src/bin/button.rs +++ b/examples/stm32f3/src/bin/button.rs @@ -13,7 +13,7 @@ fn main() -> ! { let p = embassy_stm32::init(Default::default()); - let button = Input::new(p.PA0, Pull::Down); + let mut button = Input::new(p.PA0, Pull::Down); let mut led1 = Output::new(p.PE9, Level::High, Speed::Low); let mut led2 = Output::new(p.PE15, Level::High, Speed::Low); diff --git a/examples/stm32f4/src/bin/button.rs b/examples/stm32f4/src/bin/button.rs index b13e64531..aa1eed46f 100644 --- a/examples/stm32f4/src/bin/button.rs +++ b/examples/stm32f4/src/bin/button.rs @@ -13,7 +13,7 @@ fn main() -> ! { let p = embassy_stm32::init(Default::default()); - let button = Input::new(p.PC13, Pull::Down); + let mut button = Input::new(p.PC13, Pull::Down); let mut led1 = Output::new(p.PB0, Level::High, Speed::Low); let _led2 = Output::new(p.PB7, Level::High, Speed::Low); let mut led3 = Output::new(p.PB14, Level::High, Speed::Low); diff --git a/examples/stm32f7/src/bin/button.rs b/examples/stm32f7/src/bin/button.rs index b13e64531..aa1eed46f 100644 --- a/examples/stm32f7/src/bin/button.rs +++ b/examples/stm32f7/src/bin/button.rs @@ -13,7 +13,7 @@ fn main() -> ! { let p = embassy_stm32::init(Default::default()); - let button = Input::new(p.PC13, Pull::Down); + let mut button = Input::new(p.PC13, Pull::Down); let mut led1 = Output::new(p.PB0, Level::High, Speed::Low); let _led2 = Output::new(p.PB7, Level::High, Speed::Low); let mut led3 = Output::new(p.PB14, Level::High, Speed::Low); diff --git a/examples/stm32g0/src/bin/button.rs b/examples/stm32g0/src/bin/button.rs index 72a3f5cbf..40c58013b 100644 --- a/examples/stm32g0/src/bin/button.rs +++ b/examples/stm32g0/src/bin/button.rs @@ -13,7 +13,7 @@ fn main() -> ! { let p = embassy_stm32::init(Default::default()); - let button = Input::new(p.PC13, Pull::Up); + let mut button = Input::new(p.PC13, Pull::Up); loop { if button.is_high() { diff --git a/examples/stm32g4/src/bin/button.rs b/examples/stm32g4/src/bin/button.rs index 15abd86d9..127efb08a 100644 --- a/examples/stm32g4/src/bin/button.rs +++ b/examples/stm32g4/src/bin/button.rs @@ -13,7 +13,7 @@ fn main() -> ! { let p = embassy_stm32::init(Default::default()); - let button = Input::new(p.PC13, Pull::Down); + let mut button = Input::new(p.PC13, Pull::Down); loop { if button.is_high() { diff --git a/examples/stm32h5/Cargo.toml b/examples/stm32h5/Cargo.toml index 0ed0ce3c0..f714a3984 100644 --- a/examples/stm32h5/Cargo.toml +++ b/examples/stm32h5/Cargo.toml @@ -19,8 +19,8 @@ defmt-rtt = "0.4" cortex-m = { version = "0.7.6", features = ["inline-asm", "critical-section-single-core"] } cortex-m-rt = "0.7.0" embedded-hal = "0.2.6" -embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-rc.2" } -embedded-hal-async = { version = "=1.0.0-rc.2" } +embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-rc.3" } +embedded-hal-async = { version = "=1.0.0-rc.3" } embedded-io-async = { version = "0.6.1" } embedded-nal-async = { version = "0.7.1" } panic-probe = { version = "0.3", features = ["print-defmt"] } diff --git a/examples/stm32h7/Cargo.toml b/examples/stm32h7/Cargo.toml index baa530cf6..c6aea3e11 100644 --- a/examples/stm32h7/Cargo.toml +++ b/examples/stm32h7/Cargo.toml @@ -19,8 +19,8 @@ defmt-rtt = "0.4" cortex-m = { version = "0.7.6", features = ["inline-asm", "critical-section-single-core"] } cortex-m-rt = "0.7.0" embedded-hal = "0.2.6" -embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-rc.2" } -embedded-hal-async = { version = "=1.0.0-rc.2" } +embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-rc.3" } +embedded-hal-async = { version = "=1.0.0-rc.3" } embedded-nal-async = { version = "0.7.1" } embedded-io-async = { version = "0.6.1" } panic-probe = { version = "0.3", features = ["print-defmt"] } diff --git a/examples/stm32l0/src/bin/button.rs b/examples/stm32l0/src/bin/button.rs index 9d194471e..3e56160e9 100644 --- a/examples/stm32l0/src/bin/button.rs +++ b/examples/stm32l0/src/bin/button.rs @@ -12,7 +12,7 @@ async fn main(_spawner: Spawner) { let p = embassy_stm32::init(Default::default()); info!("Hello World!"); - let button = Input::new(p.PB2, Pull::Up); + let mut button = Input::new(p.PB2, Pull::Up); let mut led1 = Output::new(p.PA5, Level::High, Speed::Low); let mut led2 = Output::new(p.PB5, Level::High, Speed::Low); diff --git a/examples/stm32l4/Cargo.toml b/examples/stm32l4/Cargo.toml index a936d27c3..2861216d4 100644 --- a/examples/stm32l4/Cargo.toml +++ b/examples/stm32l4/Cargo.toml @@ -24,9 +24,9 @@ defmt-rtt = "0.4" cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] } cortex-m-rt = "0.7.0" embedded-hal = "0.2.6" -embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-rc.2" } -embedded-hal-async = { version = "=1.0.0-rc.2" } -embedded-hal-bus = { version = "=0.1.0-rc.2", features = ["async"] } +embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-rc.3" } +embedded-hal-async = { version = "=1.0.0-rc.3" } +embedded-hal-bus = { version = "=0.1.0-rc.3", features = ["async"] } panic-probe = { version = "0.3", features = ["print-defmt"] } futures = { version = "0.3.17", default-features = false, features = ["async-await"] } heapless = { version = "0.8", default-features = false } diff --git a/examples/stm32l4/src/bin/button.rs b/examples/stm32l4/src/bin/button.rs index 73b1962e8..0a102c2d6 100644 --- a/examples/stm32l4/src/bin/button.rs +++ b/examples/stm32l4/src/bin/button.rs @@ -12,7 +12,7 @@ fn main() -> ! { let p = embassy_stm32::init(Default::default()); - let button = Input::new(p.PC13, Pull::Up); + let mut button = Input::new(p.PC13, Pull::Up); loop { if button.is_high() { diff --git a/examples/stm32l4/src/bin/spe_adin1110_http_server.rs b/examples/stm32l4/src/bin/spe_adin1110_http_server.rs index 4826e0bed..8ec810c7f 100644 --- a/examples/stm32l4/src/bin/spe_adin1110_http_server.rs +++ b/examples/stm32l4/src/bin/spe_adin1110_http_server.rs @@ -114,8 +114,8 @@ async fn main(spawner: Spawner) { let led_uc4_blue = Output::new(dp.PG15, Level::High, Speed::Low); // Read the uc_cfg switches - let uc_cfg0 = Input::new(dp.PB2, Pull::None); - let uc_cfg1 = Input::new(dp.PF11, Pull::None); + let mut uc_cfg0 = Input::new(dp.PB2, Pull::None); + let mut uc_cfg1 = Input::new(dp.PF11, Pull::None); let _uc_cfg2 = Input::new(dp.PG6, Pull::None); let _uc_cfg3 = Input::new(dp.PG11, Pull::None); @@ -133,8 +133,8 @@ async fn main(spawner: Spawner) { // Setup IO and SPI for the SPE chip let spe_reset_n = Output::new(dp.PC7, Level::Low, Speed::Low); - let spe_cfg0 = Input::new(dp.PC8, Pull::None); - let spe_cfg1 = Input::new(dp.PC9, Pull::None); + let mut spe_cfg0 = Input::new(dp.PC8, Pull::None); + let mut spe_cfg1 = Input::new(dp.PC9, Pull::None); let _spe_ts_capt = Output::new(dp.PC6, Level::Low, Speed::Low); let spe_int = Input::new(dp.PB11, Pull::None); diff --git a/examples/stm32l4/src/bin/spi_blocking_async.rs b/examples/stm32l4/src/bin/spi_blocking_async.rs index f1b80087c..903ca58df 100644 --- a/examples/stm32l4/src/bin/spi_blocking_async.rs +++ b/examples/stm32l4/src/bin/spi_blocking_async.rs @@ -30,7 +30,7 @@ async fn main(_spawner: Spawner) { let _wake = Output::new(p.PB13, Level::Low, Speed::VeryHigh); let mut reset = Output::new(p.PE8, Level::Low, Speed::VeryHigh); let mut cs = Output::new(p.PE0, Level::High, Speed::VeryHigh); - let ready = Input::new(p.PE1, Pull::Up); + let mut ready = Input::new(p.PE1, Pull::Up); cortex_m::asm::delay(100_000); reset.set_high(); diff --git a/examples/stm32l4/src/bin/spi_dma.rs b/examples/stm32l4/src/bin/spi_dma.rs index ff9b5b43b..58cf2e51e 100644 --- a/examples/stm32l4/src/bin/spi_dma.rs +++ b/examples/stm32l4/src/bin/spi_dma.rs @@ -25,7 +25,7 @@ async fn main(_spawner: Spawner) { let _wake = Output::new(p.PB13, Level::Low, Speed::VeryHigh); let mut reset = Output::new(p.PE8, Level::Low, Speed::VeryHigh); let mut cs = Output::new(p.PE0, Level::High, Speed::VeryHigh); - let ready = Input::new(p.PE1, Pull::Up); + let mut ready = Input::new(p.PE1, Pull::Up); cortex_m::asm::delay(100_000); reset.set_high(); diff --git a/examples/stm32wl/src/bin/button.rs b/examples/stm32wl/src/bin/button.rs index 982a7a112..6c1f5a5ef 100644 --- a/examples/stm32wl/src/bin/button.rs +++ b/examples/stm32wl/src/bin/button.rs @@ -13,7 +13,7 @@ fn main() -> ! { let p = embassy_stm32::init(Default::default()); - let button = Input::new(p.PA0, Pull::Up); + let mut button = Input::new(p.PA0, Pull::Up); let mut led1 = Output::new(p.PB15, Level::High, Speed::Low); let mut led2 = Output::new(p.PB9, Level::High, Speed::Low); diff --git a/tests/nrf/Cargo.toml b/tests/nrf/Cargo.toml index 7b0d59ee2..b6067abcc 100644 --- a/tests/nrf/Cargo.toml +++ b/tests/nrf/Cargo.toml @@ -16,8 +16,8 @@ embedded-io-async = { version = "0.6.1", features = ["defmt-03"] } embassy-net = { version = "0.2.0", path = "../../embassy-net", features = ["defmt", "tcp", "dhcpv4", "medium-ethernet", ] } embassy-net-esp-hosted = { version = "0.1.0", path = "../../embassy-net-esp-hosted", features = ["defmt"] } embassy-net-enc28j60 = { version = "0.1.0", path = "../../embassy-net-enc28j60", features = ["defmt"] } -embedded-hal-async = { version = "1.0.0-rc.2" } -embedded-hal-bus = { version = "0.1.0-rc.2", features = ["async"] } +embedded-hal-async = { version = "1.0.0-rc.3" } +embedded-hal-bus = { version = "0.1.0-rc.3", features = ["async"] } static_cell = { version = "2", features = [ "nightly" ] } perf-client = { path = "../perf-client" } diff --git a/tests/rp/Cargo.toml b/tests/rp/Cargo.toml index 44fb7bed6..028ce43ee 100644 --- a/tests/rp/Cargo.toml +++ b/tests/rp/Cargo.toml @@ -24,9 +24,9 @@ defmt-rtt = "0.4" cortex-m = { version = "0.7.6" } cortex-m-rt = "0.7.0" embedded-hal = "0.2.6" -embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-rc.2" } -embedded-hal-async = { version = "=1.0.0-rc.2" } -embedded-hal-bus = { version = "=0.1.0-rc.2", features = ["async"] } +embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-rc.3" } +embedded-hal-async = { version = "=1.0.0-rc.3" } +embedded-hal-bus = { version = "=0.1.0-rc.3", features = ["async"] } panic-probe = { version = "0.3.0", features = ["print-defmt"] } futures = { version = "0.3.17", default-features = false, features = ["async-await"] } embedded-io-async = { version = "0.6.1" } diff --git a/tests/rp/src/bin/gpio.rs b/tests/rp/src/bin/gpio.rs index e0c309887..a57d5d9e8 100644 --- a/tests/rp/src/bin/gpio.rs +++ b/tests/rp/src/bin/gpio.rs @@ -16,10 +16,10 @@ async fn main(_spawner: Spawner) { // Test initial output { - let b = Input::new(&mut b, Pull::None); + let mut b = Input::new(&mut b, Pull::None); { - let a = Output::new(&mut a, Level::Low); + let mut a = Output::new(&mut a, Level::Low); delay(); assert!(b.is_low()); assert!(!b.is_high()); @@ -64,7 +64,7 @@ async fn main(_spawner: Spawner) { // Test input no pull { - let b = Input::new(&mut b, Pull::None); + let mut b = Input::new(&mut b, Pull::None); // no pull, the status is undefined let mut a = Output::new(&mut a, Level::Low); @@ -77,7 +77,7 @@ async fn main(_spawner: Spawner) { // Test input pulldown { - let b = Input::new(&mut b, Pull::Down); + let mut b = Input::new(&mut b, Pull::Down); delay(); assert!(b.is_low()); @@ -91,7 +91,7 @@ async fn main(_spawner: Spawner) { // Test input pullup { - let b = Input::new(&mut b, Pull::Up); + let mut b = Input::new(&mut b, Pull::Up); delay(); assert!(b.is_high()); diff --git a/tests/rp/src/bin/pwm.rs b/tests/rp/src/bin/pwm.rs index e71d9e610..3fc0bb2a0 100644 --- a/tests/rp/src/bin/pwm.rs +++ b/tests/rp/src/bin/pwm.rs @@ -45,7 +45,7 @@ async fn main(_spawner: Spawner) { // Test output from A { - let pin1 = Input::new(&mut p9, Pull::None); + let mut pin1 = Input::new(&mut p9, Pull::None); let _pwm = Pwm::new_output_a(&mut p.PWM_CH3, &mut p6, cfg.clone()); Timer::after_millis(1).await; assert_eq!(pin1.is_low(), invert_a); @@ -59,7 +59,7 @@ async fn main(_spawner: Spawner) { // Test output from B { - let pin2 = Input::new(&mut p11, Pull::None); + let mut pin2 = Input::new(&mut p11, Pull::None); let _pwm = Pwm::new_output_b(&mut p.PWM_CH3, &mut p7, cfg.clone()); Timer::after_millis(1).await; assert_ne!(pin2.is_low(), invert_a); @@ -73,8 +73,8 @@ async fn main(_spawner: Spawner) { // Test output from A+B { - let pin1 = Input::new(&mut p9, Pull::None); - let pin2 = Input::new(&mut p11, Pull::None); + let mut pin1 = Input::new(&mut p9, Pull::None); + let mut pin2 = Input::new(&mut p11, Pull::None); let _pwm = Pwm::new_output_ab(&mut p.PWM_CH3, &mut p6, &mut p7, cfg.clone()); Timer::after_millis(1).await; assert_eq!(pin1.is_low(), invert_a); diff --git a/tests/stm32/Cargo.toml b/tests/stm32/Cargo.toml index 4f53e84f0..bdec41571 100644 --- a/tests/stm32/Cargo.toml +++ b/tests/stm32/Cargo.toml @@ -63,8 +63,8 @@ defmt-rtt = "0.4" cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] } cortex-m-rt = "0.7.0" embedded-hal = "0.2.6" -embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-rc.2" } -embedded-hal-async = { version = "=1.0.0-rc.2" } +embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-rc.3" } +embedded-hal-async = { version = "=1.0.0-rc.3" } micromath = "2.0.0" panic-probe = { version = "0.3.0", features = ["print-defmt"] } rand_core = { version = "0.6", default-features = false } diff --git a/tests/stm32/src/bin/gpio.rs b/tests/stm32/src/bin/gpio.rs index c4e2fe161..9f1993024 100644 --- a/tests/stm32/src/bin/gpio.rs +++ b/tests/stm32/src/bin/gpio.rs @@ -20,10 +20,10 @@ async fn main(_spawner: Spawner) { // Test initial output { - let b = Input::new(&mut b, Pull::None); + let mut b = Input::new(&mut b, Pull::None); { - let a = Output::new(&mut a, Level::Low, Speed::Low); + let mut a = Output::new(&mut a, Level::Low, Speed::Low); delay(); assert!(b.is_low()); assert!(!b.is_high()); @@ -68,7 +68,7 @@ async fn main(_spawner: Spawner) { // Test input no pull { - let b = Input::new(&mut b, Pull::None); + let mut b = Input::new(&mut b, Pull::None); // no pull, the status is undefined let mut a = Output::new(&mut a, Level::Low, Speed::Low); @@ -81,7 +81,7 @@ async fn main(_spawner: Spawner) { // Test input pulldown { - let b = Input::new(&mut b, Pull::Down); + let mut b = Input::new(&mut b, Pull::Down); delay(); assert!(b.is_low()); @@ -95,7 +95,7 @@ async fn main(_spawner: Spawner) { // Test input pullup { - let b = Input::new(&mut b, Pull::Up); + let mut b = Input::new(&mut b, Pull::Up); delay(); assert!(b.is_high()); @@ -109,7 +109,7 @@ async fn main(_spawner: Spawner) { // Test output open drain { - let b = Input::new(&mut b, Pull::Down); + let mut b = Input::new(&mut b, Pull::Down); // no pull, the status is undefined let mut a = OutputOpenDrain::new(&mut a, Level::Low, Speed::Low, Pull::None); From a34abd849f09187edea48713538403ebf44d6576 Mon Sep 17 00:00:00 2001 From: Kaitlyn Kenwell Date: Thu, 14 Dec 2023 10:30:10 -0500 Subject: [PATCH 021/124] Add examples to ci.sh --- ci.sh | 2 ++ examples/boot/application/stm32wb-dfu/Cargo.toml | 1 - 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/ci.sh b/ci.sh index 8a5e206d2..83c05d1b9 100755 --- a/ci.sh +++ b/ci.sh @@ -173,10 +173,12 @@ cargo batch \ --- build --release --manifest-path examples/boot/application/stm32l1/Cargo.toml --target thumbv7m-none-eabi --features skip-include --out-dir out/examples/boot/stm32l1 \ --- build --release --manifest-path examples/boot/application/stm32l4/Cargo.toml --target thumbv7em-none-eabi --features skip-include --out-dir out/examples/boot/stm32l4 \ --- build --release --manifest-path examples/boot/application/stm32wl/Cargo.toml --target thumbv7em-none-eabihf --features skip-include --out-dir out/examples/boot/stm32wl \ + --- build --release --manifest-path examples/boot/application/stm32wb-dfu/Cargo.toml --target thumbv7em-none-eabihf --out-dir out/examples/boot/stm32wb-dfu \ --- build --release --manifest-path examples/boot/bootloader/nrf/Cargo.toml --target thumbv7em-none-eabi --features embassy-nrf/nrf52840 \ --- build --release --manifest-path examples/boot/bootloader/nrf/Cargo.toml --target thumbv8m.main-none-eabihf --features embassy-nrf/nrf9160-ns \ --- build --release --manifest-path examples/boot/bootloader/rp/Cargo.toml --target thumbv6m-none-eabi \ --- build --release --manifest-path examples/boot/bootloader/stm32/Cargo.toml --target thumbv7em-none-eabi --features embassy-stm32/stm32wl55jc-cm4 \ + --- build --release --manifest-path examples/boot/bootloader/stm32wb-dfu/Cargo.toml --target thumbv7em-none-eabihf \ --- build --release --manifest-path examples/wasm/Cargo.toml --target wasm32-unknown-unknown --out-dir out/examples/wasm \ --- build --release --manifest-path tests/stm32/Cargo.toml --target thumbv7m-none-eabi --features stm32f103c8 --out-dir out/tests/stm32f103c8 \ --- build --release --manifest-path tests/stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32f429zi --out-dir out/tests/stm32f429zi \ diff --git a/examples/boot/application/stm32wb-dfu/Cargo.toml b/examples/boot/application/stm32wb-dfu/Cargo.toml index e67224ce6..57d51de02 100644 --- a/examples/boot/application/stm32wb-dfu/Cargo.toml +++ b/examples/boot/application/stm32wb-dfu/Cargo.toml @@ -30,4 +30,3 @@ defmt = [ "embassy-boot-stm32/defmt", "embassy-sync/defmt", ] -skip-include = [] From e579095a9075c8a3efdb956877b533f47ef1ec42 Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Thu, 14 Dec 2023 16:30:45 +0100 Subject: [PATCH 022/124] ci: fix test job not caching anything. --- .github/ci/build-stable.sh | 2 +- .github/ci/build.sh | 2 +- .github/ci/crlf.sh | 2 +- .github/ci/test.sh | 4 ++++ 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/.github/ci/build-stable.sh b/.github/ci/build-stable.sh index 9160a2be2..e0bd77867 100755 --- a/.github/ci/build-stable.sh +++ b/.github/ci/build-stable.sh @@ -27,4 +27,4 @@ sed -i 's/channel.*/channel = "beta"/g' rust-toolchain.toml # Save lockfiles echo Saving lockfiles... -find . -type f -name Cargo.lock -exec tar -cf /ci/cache/lockfiles.tar '{}' \+ \ No newline at end of file +find . -type f -name Cargo.lock -exec tar -cf /ci/cache/lockfiles.tar '{}' \+ diff --git a/.github/ci/build.sh b/.github/ci/build.sh index e7a6c0d86..77d2b3cab 100755 --- a/.github/ci/build.sh +++ b/.github/ci/build.sh @@ -31,4 +31,4 @@ hashtime save /ci/cache/filetime.json # Save lockfiles echo Saving lockfiles... -find . -type f -name Cargo.lock -exec tar -cf /ci/cache/lockfiles.tar '{}' \+ \ No newline at end of file +find . -type f -name Cargo.lock -exec tar -cf /ci/cache/lockfiles.tar '{}' \+ diff --git a/.github/ci/crlf.sh b/.github/ci/crlf.sh index 457510407..69838ce88 100755 --- a/.github/ci/crlf.sh +++ b/.github/ci/crlf.sh @@ -14,4 +14,4 @@ else echo -e "ERROR: Found ${NR_FILES} files with CRLF endings." echo "$FILES_WITH_CRLF" exit "$NR_FILES" -fi \ No newline at end of file +fi diff --git a/.github/ci/test.sh b/.github/ci/test.sh index 1ee760d31..0ec65d2a1 100755 --- a/.github/ci/test.sh +++ b/.github/ci/test.sh @@ -4,6 +4,10 @@ set -euo pipefail +export RUSTUP_HOME=/ci/cache/rustup +export CARGO_HOME=/ci/cache/cargo +export CARGO_TARGET_DIR=/ci/cache/target + MIRIFLAGS=-Zmiri-ignore-leaks cargo miri test --manifest-path ./embassy-executor/Cargo.toml MIRIFLAGS=-Zmiri-ignore-leaks cargo miri test --manifest-path ./embassy-executor/Cargo.toml --features nightly From 27d054aa6875d977efc5f5c3554c57fd1245bdb9 Mon Sep 17 00:00:00 2001 From: Kaitlyn Kenwell Date: Thu, 14 Dec 2023 10:34:22 -0500 Subject: [PATCH 023/124] Adjust toml files, fix application example --- examples/boot/application/stm32wb-dfu/Cargo.toml | 2 +- examples/boot/application/stm32wb-dfu/src/main.rs | 10 +++++----- examples/boot/bootloader/stm32wb-dfu/Cargo.toml | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/examples/boot/application/stm32wb-dfu/Cargo.toml b/examples/boot/application/stm32wb-dfu/Cargo.toml index 57d51de02..0ed0b75e0 100644 --- a/examples/boot/application/stm32wb-dfu/Cargo.toml +++ b/examples/boot/application/stm32wb-dfu/Cargo.toml @@ -1,6 +1,6 @@ [package] edition = "2021" -name = "embassy-boot-stm32wl-examples" +name = "embassy-boot-stm32wb-dfu-examples" version = "0.1.0" license = "MIT OR Apache-2.0" diff --git a/examples/boot/application/stm32wb-dfu/src/main.rs b/examples/boot/application/stm32wb-dfu/src/main.rs index f03003ffe..cdac903b5 100644 --- a/examples/boot/application/stm32wb-dfu/src/main.rs +++ b/examples/boot/application/stm32wb-dfu/src/main.rs @@ -6,7 +6,7 @@ use core::cell::RefCell; #[cfg(feature = "defmt-rtt")] use defmt_rtt::*; -use embassy_boot_stm32::{AlignedBuffer, BlockingFirmwareUpdater, FirmwareUpdaterConfig}; +use embassy_boot_stm32::{AlignedBuffer, BlockingFirmwareState, FirmwareUpdaterConfig}; use embassy_executor::Spawner; use embassy_stm32::flash::{Flash, WRITE_SIZE}; use embassy_stm32::rcc::WPAN_DEFAULT; @@ -33,8 +33,8 @@ async fn main(_spawner: Spawner) { let config = FirmwareUpdaterConfig::from_linkerfile_blocking(&flash); let mut magic = AlignedBuffer([0; WRITE_SIZE]); - let mut updater = BlockingFirmwareUpdater::new(config, &mut magic.0); - updater.mark_booted().expect("Failed to mark booted"); + let mut firmware_state = BlockingFirmwareState::from_config(config, &mut magic.0); + firmware_state.mark_booted().expect("Failed to mark booted"); let driver = Driver::new(p.USB, Irqs, p.PA12, p.PA11); let mut config = embassy_usb::Config::new(0xc0de, 0xcafe); @@ -46,7 +46,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 state = Control::new(updater, DfuAttributes::CAN_DOWNLOAD); + let mut state = Control::new(firmware_state, DfuAttributes::CAN_DOWNLOAD); let mut builder = Builder::new( driver, config, @@ -57,7 +57,7 @@ async fn main(_spawner: Spawner) { &mut control_buf, ); - usb_dfu::<_, _, _>(&mut builder, &mut state, Duration::from_millis(2500)); + usb_dfu::<_, _>(&mut builder, &mut state, Duration::from_millis(2500)); let mut dev = builder.build(); dev.run().await diff --git a/examples/boot/bootloader/stm32wb-dfu/Cargo.toml b/examples/boot/bootloader/stm32wb-dfu/Cargo.toml index 774a8223d..fde9eb57d 100644 --- a/examples/boot/bootloader/stm32wb-dfu/Cargo.toml +++ b/examples/boot/bootloader/stm32wb-dfu/Cargo.toml @@ -1,8 +1,8 @@ [package] edition = "2021" -name = "stm32-bootloader-example" +name = "stm32wb-dfu-bootloader-example" version = "0.1.0" -description = "Example bootloader for STM32 chips" +description = "Example USB DFUbootloader for the STM32WB series of chips" license = "MIT OR Apache-2.0" [dependencies] From cbc8ccc51e8e747fab51ac377225495cd24eb447 Mon Sep 17 00:00:00 2001 From: Kaitlyn Kenwell Date: Thu, 14 Dec 2023 10:56:16 -0500 Subject: [PATCH 024/124] Adjust stm32wb-dfu example memory maps to fix linker errors --- examples/boot/application/stm32wb-dfu/memory.x | 4 ++-- examples/boot/bootloader/stm32wb-dfu/memory.x | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/boot/application/stm32wb-dfu/memory.x b/examples/boot/application/stm32wb-dfu/memory.x index f51875766..ff1b800d2 100644 --- a/examples/boot/application/stm32wb-dfu/memory.x +++ b/examples/boot/application/stm32wb-dfu/memory.x @@ -3,8 +3,8 @@ MEMORY /* NOTE 1 K = 1 KiBi = 1024 bytes */ BOOTLOADER : ORIGIN = 0x08000000, LENGTH = 24K BOOTLOADER_STATE : ORIGIN = 0x08006000, LENGTH = 4K - FLASH : ORIGIN = 0x08008000, LENGTH = 32K - DFU : ORIGIN = 0x08010000, LENGTH = 36K + FLASH : ORIGIN = 0x08008000, LENGTH = 128K + DFU : ORIGIN = 0x08028000, LENGTH = 132K RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 32K } diff --git a/examples/boot/bootloader/stm32wb-dfu/memory.x b/examples/boot/bootloader/stm32wb-dfu/memory.x index b6f185ef7..858062631 100644 --- a/examples/boot/bootloader/stm32wb-dfu/memory.x +++ b/examples/boot/bootloader/stm32wb-dfu/memory.x @@ -3,8 +3,8 @@ MEMORY /* NOTE 1 K = 1 KiBi = 1024 bytes */ FLASH : ORIGIN = 0x08000000, LENGTH = 24K BOOTLOADER_STATE : ORIGIN = 0x08006000, LENGTH = 4K - ACTIVE : ORIGIN = 0x08008000, LENGTH = 32K - DFU : ORIGIN = 0x08010000, LENGTH = 36K + ACTIVE : ORIGIN = 0x08008000, LENGTH = 128K + DFU : ORIGIN = 0x08028000, LENGTH = 132K RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 16K } From 9f9f6e75bb3ef6d285ebed88a20ab57fb55f3d07 Mon Sep 17 00:00:00 2001 From: Kaitlyn Kenwell Date: Thu, 14 Dec 2023 13:29:26 -0500 Subject: [PATCH 025/124] Abstract chip reset logic, add Reset impls for cortex-m and esp32c3 --- embassy-usb-dfu/Cargo.toml | 5 +-- embassy-usb-dfu/src/application.rs | 17 ++++++---- embassy-usb-dfu/src/bootloader.rs | 19 ++++++++---- embassy-usb-dfu/src/lib.rs | 31 +++++++++++++++++++ .../boot/application/stm32wb-dfu/Cargo.toml | 2 +- .../boot/application/stm32wb-dfu/src/main.rs | 4 +-- .../boot/bootloader/stm32wb-dfu/Cargo.toml | 2 +- .../boot/bootloader/stm32wb-dfu/src/main.rs | 4 +-- 8 files changed, 64 insertions(+), 20 deletions(-) diff --git a/embassy-usb-dfu/Cargo.toml b/embassy-usb-dfu/Cargo.toml index 62398afbc..02146c646 100644 --- a/embassy-usb-dfu/Cargo.toml +++ b/embassy-usb-dfu/Cargo.toml @@ -15,15 +15,16 @@ categories = [ [dependencies] bitflags = "2.4.1" -cortex-m = { version = "0.7.7", features = ["inline-asm"] } +cortex-m = { version = "0.7.7", features = ["inline-asm"], optional = true } defmt = { version = "0.3.5", optional = true } embassy-boot = { version = "0.1.1", path = "../embassy-boot/boot" } -embassy-embedded-hal = { version = "0.1.0", path = "../embassy-embedded-hal" } +# embassy-embedded-hal = { version = "0.1.0", path = "../embassy-embedded-hal" } embassy-futures = { version = "0.1.1", path = "../embassy-futures" } embassy-sync = { version = "0.5.0", path = "../embassy-sync" } embassy-time = { version = "0.2.0", path = "../embassy-time" } embassy-usb = { version = "0.1.0", path = "../embassy-usb", default-features = false } embedded-storage = { version = "0.3.1" } +esp32c3-hal = { version = "0.13.0", optional = true, default-features = false } [features] bootloader = [] diff --git a/embassy-usb-dfu/src/application.rs b/embassy-usb-dfu/src/application.rs index 5ff8f90f8..75689db26 100644 --- a/embassy-usb-dfu/src/application.rs +++ b/embassy-usb-dfu/src/application.rs @@ -1,3 +1,5 @@ +use core::marker::PhantomData; + use embassy_boot::BlockingFirmwareState; use embassy_time::{Duration, Instant}; use embassy_usb::control::{InResponse, OutResponse, Recipient, RequestType}; @@ -9,17 +11,19 @@ use crate::consts::{ DfuAttributes, Request, State, Status, APPN_SPEC_SUBCLASS_DFU, DESC_DFU_FUNCTIONAL, DFU_PROTOCOL_RT, USB_CLASS_APPN_SPEC, }; +use crate::Reset; /// Internal state for the DFU class -pub struct Control<'d, STATE: NorFlash> { +pub struct Control<'d, STATE: NorFlash, RST: Reset> { firmware_state: BlockingFirmwareState<'d, STATE>, attrs: DfuAttributes, state: State, timeout: Option, detach_start: Option, + _rst: PhantomData, } -impl<'d, STATE: NorFlash> Control<'d, STATE> { +impl<'d, STATE: NorFlash, RST: Reset> Control<'d, STATE, RST> { pub fn new(firmware_state: BlockingFirmwareState<'d, STATE>, attrs: DfuAttributes) -> Self { Control { firmware_state, @@ -27,11 +31,12 @@ impl<'d, STATE: NorFlash> Control<'d, STATE> { state: State::AppIdle, detach_start: None, timeout: None, + _rst: PhantomData, } } } -impl<'d, STATE: NorFlash> Handler for Control<'d, STATE> { +impl<'d, STATE: NorFlash, RST: Reset> Handler for Control<'d, STATE, RST> { fn reset(&mut self) { if let Some(start) = self.detach_start { let delta = Instant::now() - start; @@ -45,7 +50,7 @@ impl<'d, STATE: NorFlash> Handler for Control<'d, STATE> { self.firmware_state .mark_dfu() .expect("Failed to mark DFU mode in bootloader"); - cortex_m::peripheral::SCB::sys_reset(); + RST::sys_reset() } } } @@ -103,9 +108,9 @@ impl<'d, STATE: NorFlash> Handler for Control<'d, STATE> { /// it should expose a DFU device, and a software reset will be issued. /// /// To apply USB DFU updates, the bootloader must be capable of recognizing the DFU magic and exposing a device to handle the full DFU transaction with the host. -pub fn usb_dfu<'d, D: Driver<'d>, STATE: NorFlash>( +pub fn usb_dfu<'d, D: Driver<'d>, STATE: NorFlash, RST: Reset>( builder: &mut Builder<'d, D>, - handler: &'d mut Control<'d, STATE>, + handler: &'d mut Control<'d, STATE, RST>, timeout: Duration, ) { let mut func = builder.function(0x00, 0x00, 0x00); diff --git a/embassy-usb-dfu/src/bootloader.rs b/embassy-usb-dfu/src/bootloader.rs index 99384d961..d41e6280d 100644 --- a/embassy-usb-dfu/src/bootloader.rs +++ b/embassy-usb-dfu/src/bootloader.rs @@ -1,3 +1,5 @@ +use core::marker::PhantomData; + use embassy_boot::{AlignedBuffer, BlockingFirmwareUpdater}; use embassy_usb::control::{InResponse, OutResponse, Recipient, RequestType}; use embassy_usb::driver::Driver; @@ -8,17 +10,19 @@ use crate::consts::{ DfuAttributes, Request, State, Status, APPN_SPEC_SUBCLASS_DFU, DESC_DFU_FUNCTIONAL, DFU_PROTOCOL_DFU, USB_CLASS_APPN_SPEC, }; +use crate::Reset; /// Internal state for USB DFU -pub struct Control<'d, DFU: NorFlash, STATE: NorFlash, const BLOCK_SIZE: usize> { +pub struct Control<'d, DFU: NorFlash, STATE: NorFlash, RST: Reset, const BLOCK_SIZE: usize> { updater: BlockingFirmwareUpdater<'d, DFU, STATE>, attrs: DfuAttributes, state: State, status: Status, offset: usize, + _rst: PhantomData, } -impl<'d, DFU: NorFlash, STATE: NorFlash, const BLOCK_SIZE: usize> Control<'d, DFU, STATE, BLOCK_SIZE> { +impl<'d, DFU: NorFlash, STATE: NorFlash, RST: Reset, const BLOCK_SIZE: usize> Control<'d, DFU, STATE, RST, BLOCK_SIZE> { pub fn new(updater: BlockingFirmwareUpdater<'d, DFU, STATE>, attrs: DfuAttributes) -> Self { Self { updater, @@ -26,6 +30,7 @@ impl<'d, DFU: NorFlash, STATE: NorFlash, const BLOCK_SIZE: usize> Control<'d, DF state: State::DfuIdle, status: Status::Ok, offset: 0, + _rst: PhantomData, } } @@ -36,7 +41,9 @@ impl<'d, DFU: NorFlash, STATE: NorFlash, const BLOCK_SIZE: usize> Control<'d, DF } } -impl<'d, DFU: NorFlash, STATE: NorFlash, const BLOCK_SIZE: usize> Handler for Control<'d, DFU, STATE, BLOCK_SIZE> { +impl<'d, DFU: NorFlash, STATE: NorFlash, RST: Reset, const BLOCK_SIZE: usize> Handler + for Control<'d, DFU, STATE, RST, BLOCK_SIZE> +{ fn control_out( &mut self, req: embassy_usb::control::Request, @@ -131,7 +138,7 @@ impl<'d, DFU: NorFlash, STATE: NorFlash, const BLOCK_SIZE: usize> Handler for Co buf[0..6].copy_from_slice(&[self.status as u8, 0x32, 0x00, 0x00, self.state as u8, 0x00]); match self.state { State::DlSync => self.state = State::Download, - State::ManifestSync => cortex_m::peripheral::SCB::sys_reset(), + State::ManifestSync => RST::sys_reset(), _ => {} } @@ -157,9 +164,9 @@ impl<'d, DFU: NorFlash, STATE: NorFlash, const BLOCK_SIZE: usize> Handler for Co /// /// Once the host has initiated a DFU download operation, the chunks sent by the host will be written to the DFU partition. /// Once the final sync in the manifestation phase has been received, the handler will trigger a system reset to swap the new firmware. -pub fn usb_dfu<'d, D: Driver<'d>, DFU: NorFlash, STATE: NorFlash, const BLOCK_SIZE: usize>( +pub fn usb_dfu<'d, D: Driver<'d>, DFU: NorFlash, STATE: NorFlash, RST: Reset, const BLOCK_SIZE: usize>( builder: &mut Builder<'d, D>, - handler: &'d mut Control<'d, DFU, STATE, BLOCK_SIZE>, + handler: &'d mut Control<'d, DFU, STATE, RST, BLOCK_SIZE>, ) { let mut func = builder.function(0x00, 0x00, 0x00); let mut iface = func.interface(); diff --git a/embassy-usb-dfu/src/lib.rs b/embassy-usb-dfu/src/lib.rs index ae0fbbd4c..283905de9 100644 --- a/embassy-usb-dfu/src/lib.rs +++ b/embassy-usb-dfu/src/lib.rs @@ -18,3 +18,34 @@ pub use self::application::*; not(any(feature = "bootloader", feature = "application")) ))] compile_error!("usb-dfu must be compiled with exactly one of `bootloader`, or `application` features"); + +/// Provides a platform-agnostic interface for initiating a system reset. +/// +/// This crate exposes `ResetImmediate` when compiled with cortex-m or esp32c3 support, which immediately issues a +/// reset request without interfacing with any other peripherals. +/// +/// If alternate behaviour is desired, a custom implementation of Reset can be provided as a type argument to the usb_dfu function. +pub trait Reset { + fn sys_reset() -> !; +} + +#[cfg(feature = "esp32c3-hal")] +pub struct ResetImmediate; + +#[cfg(feature = "esp32c3-hal")] +impl Reset for ResetImmediate { + fn sys_reset() -> ! { + esp32c3_hal::reset::software_reset(); + loop {} + } +} + +#[cfg(feature = "cortex-m")] +pub struct ResetImmediate; + +#[cfg(feature = "cortex-m")] +impl Reset for ResetImmediate { + fn sys_reset() -> ! { + cortex_m::peripheral::SCB::sys_reset() + } +} diff --git a/examples/boot/application/stm32wb-dfu/Cargo.toml b/examples/boot/application/stm32wb-dfu/Cargo.toml index 0ed0b75e0..f6beea498 100644 --- a/examples/boot/application/stm32wb-dfu/Cargo.toml +++ b/examples/boot/application/stm32wb-dfu/Cargo.toml @@ -12,7 +12,7 @@ embassy-stm32 = { version = "0.1.0", path = "../../../../embassy-stm32", feature embassy-boot-stm32 = { version = "0.1.0", path = "../../../../embassy-boot/stm32", features = [] } embassy-embedded-hal = { version = "0.1.0", path = "../../../../embassy-embedded-hal" } embassy-usb = { version = "0.1.0", path = "../../../../embassy-usb" } -embassy-usb-dfu = { version = "0.1.0", path = "../../../../embassy-usb-dfu", features = ["application"] } +embassy-usb-dfu = { version = "0.1.0", path = "../../../../embassy-usb-dfu", features = ["application", "cortex-m"] } defmt = { version = "0.3", optional = true } defmt-rtt = { version = "0.4", optional = true } diff --git a/examples/boot/application/stm32wb-dfu/src/main.rs b/examples/boot/application/stm32wb-dfu/src/main.rs index cdac903b5..fbecbf23b 100644 --- a/examples/boot/application/stm32wb-dfu/src/main.rs +++ b/examples/boot/application/stm32wb-dfu/src/main.rs @@ -16,7 +16,7 @@ use embassy_sync::blocking_mutex::Mutex; use embassy_time::Duration; use embassy_usb::Builder; use embassy_usb_dfu::consts::DfuAttributes; -use embassy_usb_dfu::{usb_dfu, Control}; +use embassy_usb_dfu::{usb_dfu, Control, ResetImmediate}; use panic_reset as _; bind_interrupts!(struct Irqs { @@ -57,7 +57,7 @@ async fn main(_spawner: Spawner) { &mut control_buf, ); - usb_dfu::<_, _>(&mut builder, &mut state, Duration::from_millis(2500)); + usb_dfu::<_, _, ResetImmediate>(&mut builder, &mut state, Duration::from_millis(2500)); let mut dev = builder.build(); dev.run().await diff --git a/examples/boot/bootloader/stm32wb-dfu/Cargo.toml b/examples/boot/bootloader/stm32wb-dfu/Cargo.toml index fde9eb57d..e849eb539 100644 --- a/examples/boot/bootloader/stm32wb-dfu/Cargo.toml +++ b/examples/boot/bootloader/stm32wb-dfu/Cargo.toml @@ -17,7 +17,7 @@ cortex-m-rt = { version = "0.7" } embedded-storage = "0.3.1" embedded-storage-async = "0.4.0" cfg-if = "1.0.0" -embassy-usb-dfu = { version = "0.1.0", path = "../../../../embassy-usb-dfu", features = ["bootloader"] } +embassy-usb-dfu = { version = "0.1.0", path = "../../../../embassy-usb-dfu", features = ["bootloader", "cortex-m"] } embassy-usb = { version = "0.1.0", path = "../../../../embassy-usb", default-features = false } embassy-futures = { version = "0.1.1", path = "../../../../embassy-futures" } diff --git a/examples/boot/bootloader/stm32wb-dfu/src/main.rs b/examples/boot/bootloader/stm32wb-dfu/src/main.rs index db7039e8c..a7ab813b6 100644 --- a/examples/boot/bootloader/stm32wb-dfu/src/main.rs +++ b/examples/boot/bootloader/stm32wb-dfu/src/main.rs @@ -14,7 +14,7 @@ use embassy_stm32::{bind_interrupts, peripherals, usb}; use embassy_sync::blocking_mutex::Mutex; use embassy_usb::Builder; use embassy_usb_dfu::consts::DfuAttributes; -use embassy_usb_dfu::{usb_dfu, Control}; +use embassy_usb_dfu::{usb_dfu, Control, ResetImmediate}; bind_interrupts!(struct Irqs { USB_LP => usb::InterruptHandler; @@ -64,7 +64,7 @@ fn main() -> ! { &mut control_buf, ); - usb_dfu::<_, _, _, 4096>(&mut builder, &mut state); + usb_dfu::<_, _, _, ResetImmediate, 4096>(&mut builder, &mut state); let mut dev = builder.build(); embassy_futures::block_on(dev.run()); From 33e8943e5b6e637b82f13c77bd88bb56d55ab515 Mon Sep 17 00:00:00 2001 From: Kaitlyn Kenwell Date: Thu, 14 Dec 2023 14:16:58 -0500 Subject: [PATCH 026/124] Rename bootloader feature to dfu --- embassy-usb-dfu/Cargo.toml | 2 +- embassy-usb-dfu/src/lib.rs | 8 ++++---- examples/boot/bootloader/stm32wb-dfu/Cargo.toml | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/embassy-usb-dfu/Cargo.toml b/embassy-usb-dfu/Cargo.toml index 02146c646..ee110ee87 100644 --- a/embassy-usb-dfu/Cargo.toml +++ b/embassy-usb-dfu/Cargo.toml @@ -27,6 +27,6 @@ embedded-storage = { version = "0.3.1" } esp32c3-hal = { version = "0.13.0", optional = true, default-features = false } [features] -bootloader = [] +dfu = [] application = [] defmt = ["dep:defmt"] diff --git a/embassy-usb-dfu/src/lib.rs b/embassy-usb-dfu/src/lib.rs index 283905de9..389bb33f2 100644 --- a/embassy-usb-dfu/src/lib.rs +++ b/embassy-usb-dfu/src/lib.rs @@ -3,9 +3,9 @@ mod fmt; pub mod consts; -#[cfg(feature = "bootloader")] +#[cfg(feature = "dfu")] mod bootloader; -#[cfg(feature = "bootloader")] +#[cfg(feature = "dfu")] pub use self::bootloader::*; #[cfg(feature = "application")] @@ -14,8 +14,8 @@ mod application; pub use self::application::*; #[cfg(any( - all(feature = "bootloader", feature = "application"), - not(any(feature = "bootloader", feature = "application")) + all(feature = "dfu", feature = "application"), + not(any(feature = "dfu", feature = "application")) ))] compile_error!("usb-dfu must be compiled with exactly one of `bootloader`, or `application` features"); diff --git a/examples/boot/bootloader/stm32wb-dfu/Cargo.toml b/examples/boot/bootloader/stm32wb-dfu/Cargo.toml index e849eb539..ada073970 100644 --- a/examples/boot/bootloader/stm32wb-dfu/Cargo.toml +++ b/examples/boot/bootloader/stm32wb-dfu/Cargo.toml @@ -17,7 +17,7 @@ cortex-m-rt = { version = "0.7" } embedded-storage = "0.3.1" embedded-storage-async = "0.4.0" cfg-if = "1.0.0" -embassy-usb-dfu = { version = "0.1.0", path = "../../../../embassy-usb-dfu", features = ["bootloader", "cortex-m"] } +embassy-usb-dfu = { version = "0.1.0", path = "../../../../embassy-usb-dfu", features = ["dfu", "cortex-m"] } embassy-usb = { version = "0.1.0", path = "../../../../embassy-usb", default-features = false } embassy-futures = { version = "0.1.1", path = "../../../../embassy-futures" } From 98481c20fe44d5f0dea88675d08aa21c0fd8091c Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Thu, 14 Dec 2023 21:11:33 +0100 Subject: [PATCH 027/124] use released embedded-hal-mock. --- embassy-net-adin1110/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/embassy-net-adin1110/Cargo.toml b/embassy-net-adin1110/Cargo.toml index adcdfe80f..b1582ac9b 100644 --- a/embassy-net-adin1110/Cargo.toml +++ b/embassy-net-adin1110/Cargo.toml @@ -22,7 +22,7 @@ embassy-futures = { version = "0.1.0", path = "../embassy-futures" } bitfield = "0.14.0" [dev-dependencies] -embedded-hal-mock = { git = "https://github.com/Dirbaio/embedded-hal-mock", rev = "b5a2274759a8c484f4fae71a22f8a083fdd9d5da", features = ["embedded-hal-async", "eh1"] } +embedded-hal-mock = { version = "0.10.0-rc.4", features = ["embedded-hal-async", "eh1"] } crc = "3.0.1" env_logger = "0.10" critical-section = { version = "1.1.2", features = ["std"] } From a165d73eedfd7e02fe5360e9d844882e0d0df113 Mon Sep 17 00:00:00 2001 From: eZio Pan Date: Fri, 15 Dec 2023 14:10:11 +0800 Subject: [PATCH 028/124] add ws2812 example for stm32f4 with PWM and DMA --- examples/stm32f4/src/bin/ws2812_pwm_dma.rs | 135 +++++++++++++++++++++ 1 file changed, 135 insertions(+) create mode 100644 examples/stm32f4/src/bin/ws2812_pwm_dma.rs diff --git a/examples/stm32f4/src/bin/ws2812_pwm_dma.rs b/examples/stm32f4/src/bin/ws2812_pwm_dma.rs new file mode 100644 index 000000000..79493dced --- /dev/null +++ b/examples/stm32f4/src/bin/ws2812_pwm_dma.rs @@ -0,0 +1,135 @@ +// Configure TIM3 in PWM mode, and start DMA Transfer(s) to send color data into ws2812. +// We assume the DIN pin of ws2812 connect to GPIO PB4, and ws2812 is properly powered. +// +// This demo is a combination of HAL, PAC, and manually invoke `dma::Transfer` +// +// Warning: +// DO NOT stare at ws2812 directy (especially after each MCU Reset), its (max) brightness could easily make your eyes feel burn. + +#![no_std] +#![no_main] +#![feature(type_alias_impl_trait)] + +use embassy_executor::Spawner; + +use embassy_stm32::{ + gpio::OutputType, + pac, + time::khz, + timer::{ + simple_pwm::{PwmPin, SimplePwm}, + Channel, CountingMode, + }, +}; +use embassy_time::Timer; + +use {defmt_rtt as _, panic_probe as _}; + +#[embassy_executor::main] +async fn main(_spawner: Spawner) { + let mut device_config = embassy_stm32::Config::default(); + + // set SYSCLK/HCLK/PCLK2 to 20 MHz, thus each tick is 0.05 us, + // and ws2812 timings are integer multiples of 0.05 us + { + use embassy_stm32::rcc::*; + use embassy_stm32::time::*; + device_config.enable_debug_during_sleep = true; + device_config.rcc.hse = Some(Hse { + freq: mhz(12), + mode: HseMode::Oscillator, + }); + device_config.rcc.sys = Sysclk::PLL1_P; + device_config.rcc.pll_src = PllSource::HSE; + device_config.rcc.pll = Some(Pll { + prediv: PllPreDiv::DIV6, + mul: PllMul::MUL80, + divp: Some(PllPDiv::DIV8), + divq: None, + divr: None, + }); + } + + let mut dp = embassy_stm32::init(device_config); + + let mut ws2812_pwm = SimplePwm::new( + dp.TIM3, + Some(PwmPin::new_ch1(dp.PB4, OutputType::PushPull)), + None, + None, + None, + khz(800), // data rate of ws2812 + CountingMode::EdgeAlignedUp, + ); + + // PAC level hacking, + // enable auto-reload preload, and enable timer-update-event trigger DMA + { + pac::TIM3.cr1().modify(|v| v.set_arpe(true)); + pac::TIM3.dier().modify(|v| v.set_ude(true)); + } + + // construct ws2812 non-return-to-zero (NRZ) code bit by bit + + let max_duty = ws2812_pwm.get_max_duty(); + let n0 = 8 * max_duty / 25; // ws2812 Bit 0 high level timing + let n1 = 2 * n0; // ws2812 Bit 1 high level timing + + let turn_off = [ + n0, n0, n0, n0, n0, n0, n0, n0, // Green + n0, n0, n0, n0, n0, n0, n0, n0, // Red + n0, n0, n0, n0, n0, n0, n0, n0, // Blue + 0, // keep PWM output low after a transfer + ]; + + let dim_white = [ + n0, n0, n0, n0, n0, n0, n1, n0, // Green + n0, n0, n0, n0, n0, n0, n1, n0, // Red + n0, n0, n0, n0, n0, n0, n1, n0, // Blue + 0, // keep PWM output low after a transfer + ]; + + let color_list = [&turn_off, &dim_white]; + + // make sure PWM output keep low on first start + ws2812_pwm.set_duty(Channel::Ch1, 0); + + { + use embassy_stm32::dma::{Burst, FifoThreshold, Transfer, TransferOptions}; + + // configure FIFO and MBURST of DMA, to minimize DMA occupation on AHB/APB + let mut dma_transfer_option = TransferOptions::default(); + dma_transfer_option.fifo_threshold = Some(FifoThreshold::Full); + dma_transfer_option.mburst = Burst::Incr8; + + let mut color_list_index = 0; + + loop { + // start PWM output + ws2812_pwm.enable(Channel::Ch1); + + unsafe { + Transfer::new_write( + // with &mut, we can easily reuse same DMA channel multiple times + &mut dp.DMA1_CH2, + 5, + color_list[color_list_index], + pac::TIM3.ccr(0).as_ptr() as *mut _, + dma_transfer_option, + ) + .await; + // ws2812 need at least 50 us low level input to confirm the input data and change it's state + Timer::after_micros(50).await; + } + + // stop PWM output for saving some energy + ws2812_pwm.disable(Channel::Ch1); + + // wait another half second, so that we can see color change + Timer::after_millis(500).await; + + // flip the index bit so that next round DMA transfer the other color data + color_list_index ^= 1; + } + } +} From 77e372e842c64b95e94fff93a711112514588841 Mon Sep 17 00:00:00 2001 From: eZio Pan Date: Fri, 15 Dec 2023 14:15:45 +0800 Subject: [PATCH 029/124] cargo fmt --- examples/stm32f4/src/bin/ws2812_pwm_dma.rs | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/examples/stm32f4/src/bin/ws2812_pwm_dma.rs b/examples/stm32f4/src/bin/ws2812_pwm_dma.rs index 79493dced..0c3444a47 100644 --- a/examples/stm32f4/src/bin/ws2812_pwm_dma.rs +++ b/examples/stm32f4/src/bin/ws2812_pwm_dma.rs @@ -11,18 +11,12 @@ #![feature(type_alias_impl_trait)] use embassy_executor::Spawner; - -use embassy_stm32::{ - gpio::OutputType, - pac, - time::khz, - timer::{ - simple_pwm::{PwmPin, SimplePwm}, - Channel, CountingMode, - }, -}; +use embassy_stm32::gpio::OutputType; +use embassy_stm32::pac; +use embassy_stm32::time::khz; +use embassy_stm32::timer::simple_pwm::{PwmPin, SimplePwm}; +use embassy_stm32::timer::{Channel, CountingMode}; use embassy_time::Timer; - use {defmt_rtt as _, panic_probe as _}; #[embassy_executor::main] From e5e85ba02bc91a47d80ba89dee27e6ccb20f0ccd Mon Sep 17 00:00:00 2001 From: Oliver Rockstedt Date: Fri, 15 Dec 2023 11:42:58 +0100 Subject: [PATCH 030/124] STM32H7: Allow PLL1 DIVP of 1 for certain series --- embassy-stm32/src/rcc/h.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/embassy-stm32/src/rcc/h.rs b/embassy-stm32/src/rcc/h.rs index 1889eb280..18dff9f29 100644 --- a/embassy-stm32/src/rcc/h.rs +++ b/embassy-stm32/src/rcc/h.rs @@ -70,7 +70,9 @@ pub struct Pll { pub mul: PllMul, /// PLL P division factor. If None, PLL P output is disabled. - /// On PLL1, it must be even (in particular, it cannot be 1.) + /// On PLL1, it must be even for most series (in particular, + /// it cannot be 1 in series other than STM32H723/733, + /// STM32H725/735 and STM32H730.) pub divp: Option, /// PLL Q division factor. If None, PLL Q output is disabled. pub divq: Option, @@ -729,9 +731,12 @@ fn init_pll(num: usize, config: Option, input: &PllInput) -> PllOutput { let p = config.divp.map(|div| { if num == 0 { - // on PLL1, DIVP must be even. + // on PLL1, DIVP must be even for most series. // The enum value is 1 less than the divider, so check it's odd. + #[cfg(not(pwr_h7rm0468))] assert!(div.to_bits() % 2 == 1); + #[cfg(pwr_h7rm0468)] + assert!(div.to_bits() % 2 == 1 || div.to_bits() == 0); } vco_clk / div From a8d0da91dc7b43bb05b200e7f530e58e25f20194 Mon Sep 17 00:00:00 2001 From: Oliver Rockstedt Date: Fri, 15 Dec 2023 12:22:17 +0100 Subject: [PATCH 031/124] STM32H7: adjust frequency limits for series in RM0468 --- embassy-stm32/src/rcc/h.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/embassy-stm32/src/rcc/h.rs b/embassy-stm32/src/rcc/h.rs index 18dff9f29..f28bd0b9d 100644 --- a/embassy-stm32/src/rcc/h.rs +++ b/embassy-stm32/src/rcc/h.rs @@ -478,7 +478,14 @@ pub(crate) unsafe fn init(config: Config) { VoltageScale::Scale2 => (Hertz(160_000_000), Hertz(160_000_000), Hertz(80_000_000)), VoltageScale::Scale3 => (Hertz(88_000_000), Hertz(88_000_000), Hertz(44_000_000)), }; - #[cfg(all(stm32h7, not(pwr_h7rm0455)))] + #[cfg(pwr_h7rm0468)] + let (d1cpre_clk_max, hclk_max, pclk_max) = match config.voltage_scale { + VoltageScale::Scale0 => (Hertz(550_000_000), Hertz(275_000_000), Hertz(137_500_000)), + VoltageScale::Scale1 => (Hertz(400_000_000), Hertz(200_000_000), Hertz(100_000_000)), + VoltageScale::Scale2 => (Hertz(300_000_000), Hertz(150_000_000), Hertz(75_000_000)), + VoltageScale::Scale3 => (Hertz(170_000_000), Hertz(85_000_000), Hertz(42_500_000)), + }; + #[cfg(all(stm32h7, not(any(pwr_h7rm0455, pwr_h7rm0468))))] let (d1cpre_clk_max, hclk_max, pclk_max) = match config.voltage_scale { VoltageScale::Scale0 => (Hertz(480_000_000), Hertz(240_000_000), Hertz(120_000_000)), VoltageScale::Scale1 => (Hertz(400_000_000), Hertz(200_000_000), Hertz(100_000_000)), From c17fee27bb37233df7300bea3c2658f87df9dd6b Mon Sep 17 00:00:00 2001 From: Oliver Rockstedt Date: Fri, 15 Dec 2023 13:53:06 +0100 Subject: [PATCH 032/124] STM32H7: limit max frequency to 520MHz until cpu frequency boost option is implemented --- embassy-stm32/src/rcc/h.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/embassy-stm32/src/rcc/h.rs b/embassy-stm32/src/rcc/h.rs index f28bd0b9d..389b2a871 100644 --- a/embassy-stm32/src/rcc/h.rs +++ b/embassy-stm32/src/rcc/h.rs @@ -480,7 +480,7 @@ pub(crate) unsafe fn init(config: Config) { }; #[cfg(pwr_h7rm0468)] let (d1cpre_clk_max, hclk_max, pclk_max) = match config.voltage_scale { - VoltageScale::Scale0 => (Hertz(550_000_000), Hertz(275_000_000), Hertz(137_500_000)), + VoltageScale::Scale0 => (Hertz(520_000_000), Hertz(275_000_000), Hertz(137_500_000)), VoltageScale::Scale1 => (Hertz(400_000_000), Hertz(200_000_000), Hertz(100_000_000)), VoltageScale::Scale2 => (Hertz(300_000_000), Hertz(150_000_000), Hertz(75_000_000)), VoltageScale::Scale3 => (Hertz(170_000_000), Hertz(85_000_000), Hertz(42_500_000)), From 560e72813292e0ceb32b25daf887bb69b48af771 Mon Sep 17 00:00:00 2001 From: Oliver Rockstedt Date: Fri, 15 Dec 2023 14:14:30 +0100 Subject: [PATCH 033/124] STM32H7: adjust flash latency and programming delay for series in RM0468 --- embassy-stm32/src/rcc/h.rs | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/embassy-stm32/src/rcc/h.rs b/embassy-stm32/src/rcc/h.rs index 389b2a871..15b51a398 100644 --- a/embassy-stm32/src/rcc/h.rs +++ b/embassy-stm32/src/rcc/h.rs @@ -832,7 +832,7 @@ fn flash_setup(clk: Hertz, vos: VoltageScale) { _ => unreachable!(), }; - #[cfg(flash_h7)] + #[cfg(all(flash_h7, not(pwr_h7rm0468)))] let (latency, wrhighfreq) = match (vos, clk.0) { // VOS 0 range VCORE 1.26V - 1.40V (VoltageScale::Scale0, ..=70_000_000) => (0, 0), @@ -861,6 +861,30 @@ fn flash_setup(clk: Hertz, vos: VoltageScale) { _ => unreachable!(), }; + // See RM0468 Rev 3 Table 16. FLASH recommended number of wait + // states and programming delay + #[cfg(all(flash_h7, pwr_h7rm0468))] + let (latency, wrhighfreq) = match (vos, clk.0) { + // VOS 0 range VCORE 1.26V - 1.40V + (VoltageScale::Scale0, ..=70_000_000) => (0, 0), + (VoltageScale::Scale0, ..=140_000_000) => (1, 1), + (VoltageScale::Scale0, ..=210_000_000) => (2, 2), + (VoltageScale::Scale0, ..=275_000_000) => (3, 3), + // VOS 1 range VCORE 1.15V - 1.26V + (VoltageScale::Scale1, ..=67_000_000) => (0, 0), + (VoltageScale::Scale1, ..=133_000_000) => (1, 1), + (VoltageScale::Scale1, ..=200_000_000) => (2, 2), + // VOS 2 range VCORE 1.05V - 1.15V + (VoltageScale::Scale2, ..=50_000_000) => (0, 0), + (VoltageScale::Scale2, ..=100_000_000) => (1, 1), + (VoltageScale::Scale2, ..=150_000_000) => (2, 2), + // VOS 3 range VCORE 0.95V - 1.05V + (VoltageScale::Scale3, ..=35_000_000) => (0, 0), + (VoltageScale::Scale3, ..=70_000_000) => (1, 1), + (VoltageScale::Scale3, ..=85_000_000) => (2, 2), + _ => unreachable!(), + }; + // See RM0455 Rev 10 Table 16. FLASH recommended number of wait // states and programming delay #[cfg(flash_h7ab)] From ea1e1973eb88a3a57e7f4e2ad97d32e5fcd8b8d1 Mon Sep 17 00:00:00 2001 From: eZio Pan Date: Sat, 16 Dec 2023 02:15:56 +0800 Subject: [PATCH 034/124] unify channel assign --- examples/stm32f4/src/bin/ws2812_pwm_dma.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/examples/stm32f4/src/bin/ws2812_pwm_dma.rs b/examples/stm32f4/src/bin/ws2812_pwm_dma.rs index 0c3444a47..52cc665c7 100644 --- a/examples/stm32f4/src/bin/ws2812_pwm_dma.rs +++ b/examples/stm32f4/src/bin/ws2812_pwm_dma.rs @@ -85,8 +85,10 @@ async fn main(_spawner: Spawner) { let color_list = [&turn_off, &dim_white]; + let pwm_channel = Channel::Ch1; + // make sure PWM output keep low on first start - ws2812_pwm.set_duty(Channel::Ch1, 0); + ws2812_pwm.set_duty(pwm_channel, 0); { use embassy_stm32::dma::{Burst, FifoThreshold, Transfer, TransferOptions}; @@ -100,7 +102,7 @@ async fn main(_spawner: Spawner) { loop { // start PWM output - ws2812_pwm.enable(Channel::Ch1); + ws2812_pwm.enable(pwm_channel); unsafe { Transfer::new_write( @@ -108,7 +110,7 @@ async fn main(_spawner: Spawner) { &mut dp.DMA1_CH2, 5, color_list[color_list_index], - pac::TIM3.ccr(0).as_ptr() as *mut _, + pac::TIM3.ccr(pwm_channel.raw()).as_ptr() as *mut _, dma_transfer_option, ) .await; @@ -117,7 +119,7 @@ async fn main(_spawner: Spawner) { } // stop PWM output for saving some energy - ws2812_pwm.disable(Channel::Ch1); + ws2812_pwm.disable(pwm_channel); // wait another half second, so that we can see color change Timer::after_millis(500).await; From 3568e4a5ffb1aebb97dd58975b02a00cd0a116fe Mon Sep 17 00:00:00 2001 From: Piotr Esden-Tempski Date: Fri, 15 Dec 2023 16:47:56 -0800 Subject: [PATCH 035/124] STM32 QSPI: Fix flash selection. --- embassy-stm32/src/qspi/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/embassy-stm32/src/qspi/mod.rs b/embassy-stm32/src/qspi/mod.rs index 4b0e8ecef..1153455c7 100644 --- a/embassy-stm32/src/qspi/mod.rs +++ b/embassy-stm32/src/qspi/mod.rs @@ -119,7 +119,7 @@ impl<'d, T: Instance, Dma> Qspi<'d, T, Dma> { Some(nss.map_into()), dma, config, - FlashSelection::Flash2, + FlashSelection::Flash1, ) } From f6bc96dfbd1ec363a7bed877240a971ff1760200 Mon Sep 17 00:00:00 2001 From: Adam Greig Date: Sat, 16 Dec 2023 03:44:15 +0000 Subject: [PATCH 036/124] STM32: Enable flash support for STM32G4 --- embassy-stm32/src/flash/f0.rs | 2 +- embassy-stm32/src/flash/f3.rs | 2 +- embassy-stm32/src/flash/f4.rs | 2 +- embassy-stm32/src/flash/f7.rs | 2 +- embassy-stm32/src/flash/{g0.rs => g.rs} | 2 +- embassy-stm32/src/flash/h7.rs | 2 +- embassy-stm32/src/flash/l.rs | 2 +- embassy-stm32/src/flash/mod.rs | 6 +++--- 8 files changed, 10 insertions(+), 10 deletions(-) rename embassy-stm32/src/flash/{g0.rs => g.rs} (98%) diff --git a/embassy-stm32/src/flash/f0.rs b/embassy-stm32/src/flash/f0.rs index 1ab8435a0..80d2a8166 100644 --- a/embassy-stm32/src/flash/f0.rs +++ b/embassy-stm32/src/flash/f0.rs @@ -79,7 +79,7 @@ pub(crate) unsafe fn blocking_erase_sector(sector: &FlashSector) -> Result<(), E pub(crate) unsafe fn clear_all_err() { // read and write back the same value. - // This clears all "write 0 to clear" bits. + // This clears all "write 1 to clear" bits. pac::FLASH.sr().modify(|_| {}); } diff --git a/embassy-stm32/src/flash/f3.rs b/embassy-stm32/src/flash/f3.rs index 7e6d7ca26..27d5281a7 100644 --- a/embassy-stm32/src/flash/f3.rs +++ b/embassy-stm32/src/flash/f3.rs @@ -79,7 +79,7 @@ pub(crate) unsafe fn blocking_erase_sector(sector: &FlashSector) -> Result<(), E pub(crate) unsafe fn clear_all_err() { // read and write back the same value. - // This clears all "write 0 to clear" bits. + // This clears all "write 1 to clear" bits. pac::FLASH.sr().modify(|_| {}); } diff --git a/embassy-stm32/src/flash/f4.rs b/embassy-stm32/src/flash/f4.rs index 5d07020ce..f442c5894 100644 --- a/embassy-stm32/src/flash/f4.rs +++ b/embassy-stm32/src/flash/f4.rs @@ -337,7 +337,7 @@ pub(crate) unsafe fn blocking_erase_sector(sector: &FlashSector) -> Result<(), E pub(crate) fn clear_all_err() { // read and write back the same value. - // This clears all "write 0 to clear" bits. + // This clears all "write 1 to clear" bits. pac::FLASH.sr().modify(|_| {}); } diff --git a/embassy-stm32/src/flash/f7.rs b/embassy-stm32/src/flash/f7.rs index b52231ca8..017393e80 100644 --- a/embassy-stm32/src/flash/f7.rs +++ b/embassy-stm32/src/flash/f7.rs @@ -69,7 +69,7 @@ pub(crate) unsafe fn blocking_erase_sector(sector: &FlashSector) -> Result<(), E pub(crate) unsafe fn clear_all_err() { // read and write back the same value. - // This clears all "write 0 to clear" bits. + // This clears all "write 1 to clear" bits. pac::FLASH.sr().modify(|_| {}); } diff --git a/embassy-stm32/src/flash/g0.rs b/embassy-stm32/src/flash/g.rs similarity index 98% rename from embassy-stm32/src/flash/g0.rs rename to embassy-stm32/src/flash/g.rs index 19a388970..08145e9c4 100644 --- a/embassy-stm32/src/flash/g0.rs +++ b/embassy-stm32/src/flash/g.rs @@ -92,6 +92,6 @@ pub(crate) unsafe fn wait_ready_blocking() -> Result<(), Error> { pub(crate) unsafe fn clear_all_err() { // read and write back the same value. - // This clears all "write 0 to clear" bits. + // This clears all "write 1 to clear" bits. pac::FLASH.sr().modify(|_| {}); } diff --git a/embassy-stm32/src/flash/h7.rs b/embassy-stm32/src/flash/h7.rs index b064fd6ea..555f8d155 100644 --- a/embassy-stm32/src/flash/h7.rs +++ b/embassy-stm32/src/flash/h7.rs @@ -113,7 +113,7 @@ pub(crate) unsafe fn clear_all_err() { unsafe fn bank_clear_all_err(bank: pac::flash::Bank) { // read and write back the same value. - // This clears all "write 0 to clear" bits. + // This clears all "write 1 to clear" bits. bank.sr().modify(|_| {}); } diff --git a/embassy-stm32/src/flash/l.rs b/embassy-stm32/src/flash/l.rs index 1db0da923..e0159a3f6 100644 --- a/embassy-stm32/src/flash/l.rs +++ b/embassy-stm32/src/flash/l.rs @@ -120,7 +120,7 @@ pub(crate) unsafe fn blocking_erase_sector(sector: &FlashSector) -> Result<(), E pub(crate) unsafe fn clear_all_err() { // read and write back the same value. - // This clears all "write 0 to clear" bits. + // This clears all "write 1 to clear" bits. pac::FLASH.sr().modify(|_| {}); } diff --git a/embassy-stm32/src/flash/mod.rs b/embassy-stm32/src/flash/mod.rs index fb20dcd38..3e8f2830b 100644 --- a/embassy-stm32/src/flash/mod.rs +++ b/embassy-stm32/src/flash/mod.rs @@ -63,13 +63,13 @@ impl FlashRegion { #[cfg_attr(flash_f3, path = "f3.rs")] #[cfg_attr(flash_f4, path = "f4.rs")] #[cfg_attr(flash_f7, path = "f7.rs")] -#[cfg_attr(flash_g0, path = "g0.rs")] +#[cfg_attr(any(flash_g0, flash_g4), path = "g.rs")] #[cfg_attr(flash_h7, path = "h7.rs")] #[cfg_attr(flash_h7ab, path = "h7.rs")] #[cfg_attr( not(any( - flash_l0, flash_l1, flash_l4, flash_wl, flash_wb, flash_f0, flash_f3, flash_f4, flash_f7, flash_g0, flash_h7, - flash_h7ab + flash_l0, flash_l1, flash_l4, flash_wl, flash_wb, flash_f0, flash_f3, flash_f4, flash_f7, flash_g0, flash_g4, + flash_h7, flash_h7ab )), path = "other.rs" )] From a5379e708cab6e284a00f8b01e9db3d5c2eb400c Mon Sep 17 00:00:00 2001 From: djstrickland <96876452+dstric-aqueduct@users.noreply.github.com> Date: Sat, 16 Dec 2023 08:19:52 -0500 Subject: [PATCH 037/124] remove `suspendable` field from `embassy_usb::builder::Config` --- embassy-usb/src/builder.rs | 10 ---------- embassy-usb/src/lib.rs | 8 +++----- 2 files changed, 3 insertions(+), 15 deletions(-) diff --git a/embassy-usb/src/builder.rs b/embassy-usb/src/builder.rs index ebc1283e6..c4705d041 100644 --- a/embassy-usb/src/builder.rs +++ b/embassy-usb/src/builder.rs @@ -94,15 +94,6 @@ pub struct Config<'a> { /// Default: 100mA /// Max: 500mA pub max_power: u16, - - /// Allow the bus to be suspended. - /// - /// If set to `true`, the bus will put itself in the suspended state - /// when it receives a `driver::Event::Suspend` bus event. If you wish - /// to override this behavior, set this field to `false`. - /// - /// Default: `true` - pub suspendable: bool, } impl<'a> Config<'a> { @@ -123,7 +114,6 @@ impl<'a> Config<'a> { supports_remote_wakeup: false, composite_with_iads: false, max_power: 100, - suspendable: true, } } } diff --git a/embassy-usb/src/lib.rs b/embassy-usb/src/lib.rs index ff3295871..241e33a78 100644 --- a/embassy-usb/src/lib.rs +++ b/embassy-usb/src/lib.rs @@ -471,11 +471,9 @@ impl<'d, D: Driver<'d>> Inner<'d, D> { } Event::Suspend => { trace!("usb: suspend"); - if self.config.suspendable { - self.suspended = true; - for h in &mut self.handlers { - h.suspended(true); - } + self.suspended = true; + for h in &mut self.handlers { + h.suspended(true); } } Event::PowerDetected => { From 0a890cfbe7fc10bc40f2e97bc4fac17630e9864f Mon Sep 17 00:00:00 2001 From: eZio Pan Date: Sun, 17 Dec 2023 23:47:00 +0800 Subject: [PATCH 038/124] stm32f4 ws2812 example with spi ... ... and more doc on TIM&DMA version, also remove useless TIM APRE settings, and use for loop instead of manually flip the index bit, and replace `embassy_time::Timer` with `embassy_time::Ticker`, for more constant time interval. --- examples/stm32f4/src/bin/ws2812_pwm_dma.rs | 74 +++++++++-------- examples/stm32f4/src/bin/ws2812_spi.rs | 95 ++++++++++++++++++++++ 2 files changed, 135 insertions(+), 34 deletions(-) create mode 100644 examples/stm32f4/src/bin/ws2812_spi.rs diff --git a/examples/stm32f4/src/bin/ws2812_pwm_dma.rs b/examples/stm32f4/src/bin/ws2812_pwm_dma.rs index 52cc665c7..dccd639ac 100644 --- a/examples/stm32f4/src/bin/ws2812_pwm_dma.rs +++ b/examples/stm32f4/src/bin/ws2812_pwm_dma.rs @@ -1,7 +1,16 @@ // Configure TIM3 in PWM mode, and start DMA Transfer(s) to send color data into ws2812. // We assume the DIN pin of ws2812 connect to GPIO PB4, and ws2812 is properly powered. // -// This demo is a combination of HAL, PAC, and manually invoke `dma::Transfer` +// The idea is that the data rate of ws2812 is 800 kHz, and it use different duty ratio to represent bit 0 and bit 1. +// Thus we can set TIM overflow at 800 kHz, and let TIM Update Event trigger a DMA transfer, then let DMA change CCR value, +// such that pwm duty ratio meet the bit representation of ws2812. +// +// You may want to modify TIM CCR with Cortex core directly, +// but according to my test, Cortex core will need to run far more than 100 MHz to catch up with TIM. +// Thus we need to use a DMA. +// +// This demo is a combination of HAL, PAC, and manually invoke `dma::Transfer`. +// If you need a simpler way to control ws2812, you may want to take a look at `ws2812_spi.rs` file, which make use of SPI. // // Warning: // DO NOT stare at ws2812 directy (especially after each MCU Reset), its (max) brightness could easily make your eyes feel burn. @@ -16,7 +25,7 @@ use embassy_stm32::pac; use embassy_stm32::time::khz; use embassy_stm32::timer::simple_pwm::{PwmPin, SimplePwm}; use embassy_stm32::timer::{Channel, CountingMode}; -use embassy_time::Timer; +use embassy_time::{Duration, Ticker, Timer}; use {defmt_rtt as _, panic_probe as _}; #[embassy_executor::main] @@ -33,7 +42,6 @@ async fn main(_spawner: Spawner) { freq: mhz(12), mode: HseMode::Oscillator, }); - device_config.rcc.sys = Sysclk::PLL1_P; device_config.rcc.pll_src = PllSource::HSE; device_config.rcc.pll = Some(Pll { prediv: PllPreDiv::DIV6, @@ -42,6 +50,7 @@ async fn main(_spawner: Spawner) { divq: None, divr: None, }); + device_config.rcc.sys = Sysclk::PLL1_P; } let mut dp = embassy_stm32::init(device_config); @@ -56,14 +65,11 @@ async fn main(_spawner: Spawner) { CountingMode::EdgeAlignedUp, ); - // PAC level hacking, - // enable auto-reload preload, and enable timer-update-event trigger DMA - { - pac::TIM3.cr1().modify(|v| v.set_arpe(true)); - pac::TIM3.dier().modify(|v| v.set_ude(true)); - } + // PAC level hacking, enable timer-update-event trigger DMA + pac::TIM3.dier().modify(|v| v.set_ude(true)); // construct ws2812 non-return-to-zero (NRZ) code bit by bit + // ws2812 only need 24 bits for each LED, but we add one bit more to keep PWM output low let max_duty = ws2812_pwm.get_max_duty(); let n0 = 8 * max_duty / 25; // ws2812 Bit 0 high level timing @@ -83,7 +89,7 @@ async fn main(_spawner: Spawner) { 0, // keep PWM output low after a transfer ]; - let color_list = [&turn_off, &dim_white]; + let color_list = &[&turn_off, &dim_white]; let pwm_channel = Channel::Ch1; @@ -98,34 +104,34 @@ async fn main(_spawner: Spawner) { dma_transfer_option.fifo_threshold = Some(FifoThreshold::Full); dma_transfer_option.mburst = Burst::Incr8; - let mut color_list_index = 0; + // flip color at 2 Hz + let mut ticker = Ticker::every(Duration::from_micros(500)); loop { - // start PWM output - ws2812_pwm.enable(pwm_channel); + for &color in color_list { + // start PWM output + ws2812_pwm.enable(pwm_channel); - unsafe { - Transfer::new_write( - // with &mut, we can easily reuse same DMA channel multiple times - &mut dp.DMA1_CH2, - 5, - color_list[color_list_index], - pac::TIM3.ccr(pwm_channel.raw()).as_ptr() as *mut _, - dma_transfer_option, - ) - .await; - // ws2812 need at least 50 us low level input to confirm the input data and change it's state - Timer::after_micros(50).await; + unsafe { + Transfer::new_write( + // with &mut, we can easily reuse same DMA channel multiple times + &mut dp.DMA1_CH2, + 5, + color, + pac::TIM3.ccr(pwm_channel.raw()).as_ptr() as *mut _, + dma_transfer_option, + ) + .await; + // ws2812 need at least 50 us low level input to confirm the input data and change it's state + Timer::after_micros(50).await; + } + + // stop PWM output for saving some energy + ws2812_pwm.disable(pwm_channel); + + // wait until ticker tick + ticker.next().await; } - - // stop PWM output for saving some energy - ws2812_pwm.disable(pwm_channel); - - // wait another half second, so that we can see color change - Timer::after_millis(500).await; - - // flip the index bit so that next round DMA transfer the other color data - color_list_index ^= 1; } } } diff --git a/examples/stm32f4/src/bin/ws2812_spi.rs b/examples/stm32f4/src/bin/ws2812_spi.rs new file mode 100644 index 000000000..e0d28af7f --- /dev/null +++ b/examples/stm32f4/src/bin/ws2812_spi.rs @@ -0,0 +1,95 @@ +// Mimic PWM with SPI, to control ws2812 +// We assume the DIN pin of ws2812 connect to GPIO PB5, and ws2812 is properly powered. +// +// The idea is that the data rate of ws2812 is 800 kHz, and it use different duty ratio to represent bit 0 and bit 1. +// Thus we can adjust SPI to send each *round* of data at 800 kHz, and in each *round*, we can adjust each *bit* to mimic 2 different PWM waveform. +// such that the output waveform meet the bit representation of ws2812. +// +// If you want to save SPI for other purpose, you may want to take a look at `ws2812_tim_dma.rs` file, which make use of TIM and DMA. +// +// Warning: +// DO NOT stare at ws2812 directy (especially after each MCU Reset), its (max) brightness could easily make your eyes feel burn. + +#![no_std] +#![no_main] +#![feature(type_alias_impl_trait)] + +use embassy_stm32::time::khz; +use embassy_stm32::{dma, spi}; +use embassy_time::{Duration, Ticker, Timer}; +use {defmt_rtt as _, panic_probe as _}; + +// we use 16 bit data frame format of SPI, to let timing as accurate as possible. +// thanks to loose tolerance of ws2812 timing, you can also use 8 bit data frame format, thus you need want to adjust the bit representation. +const N0: u16 = 0b1111100000000000u16; // ws2812 Bit 0 high level timing +const N1: u16 = 0b1111111111000000u16; // ws2812 Bit 1 high level timing + +// ws2812 only need 24 bits for each LED, but we add one bit more to keep SPI output low + +static TURN_OFF: [u16; 25] = [ + N0, N0, N0, N0, N0, N0, N0, N0, // Green + N0, N0, N0, N0, N0, N0, N0, N0, // Red + N0, N0, N0, N0, N0, N0, N0, N0, // Blue + 0, // keep SPI output low after last bit +]; + +static DIM_WHITE: [u16; 25] = [ + N0, N0, N0, N0, N0, N0, N1, N0, // Green + N0, N0, N0, N0, N0, N0, N1, N0, // Red + N0, N0, N0, N0, N0, N0, N1, N0, // Blue + 0, // keep SPI output low after last bit +]; + +static COLOR_LIST: &[&[u16]] = &[&TURN_OFF, &DIM_WHITE]; + +#[embassy_executor::main] +async fn main(_spawner: embassy_executor::Spawner) { + let mut device_config = embassy_stm32::Config::default(); + + // Since we use 16 bit SPI, and we need each round 800 kHz, + // thus SPI output speed should be 800 kHz * 16 = 12.8 MHz, and APB clock should be 2 * 12.8 MHz = 25.6 MHz. + // + // As for my setup, with 12 MHz HSE, I got 25.5 MHz SYSCLK, which is slightly slower, but it's ok for ws2812. + { + use embassy_stm32::rcc::{Hse, HseMode, Pll, PllMul, PllPDiv, PllPreDiv, PllSource, Sysclk}; + use embassy_stm32::time::mhz; + device_config.enable_debug_during_sleep = true; + device_config.rcc.hse = Some(Hse { + freq: mhz(12), + mode: HseMode::Oscillator, + }); + device_config.rcc.pll_src = PllSource::HSE; + device_config.rcc.pll = Some(Pll { + prediv: PllPreDiv::DIV6, + mul: PllMul::MUL102, + divp: Some(PllPDiv::DIV8), + divq: None, + divr: None, + }); + device_config.rcc.sys = Sysclk::PLL1_P; + } + + let dp = embassy_stm32::init(device_config); + + // Set SPI output speed. + // It's ok to blindly set frequency to 12800 kHz, the hal crate will take care of the SPI CR1 BR field. + // And in my case, the real bit rate will be 25.5 MHz / 2 = 12_750 kHz + let mut spi_config = spi::Config::default(); + spi_config.frequency = khz(12_800); + + // Since we only output waveform, then the Rx and Sck it is not considered + let mut ws2812_spi = spi::Spi::new_txonly_nosck(dp.SPI1, dp.PB5, dp.DMA2_CH2, dma::NoDma, spi_config); + + // flip color at 2 Hz + let mut ticker = Ticker::every(Duration::from_millis(500)); + + loop { + for &color in COLOR_LIST { + ws2812_spi.write(color).await.unwrap(); + // ws2812 need at least 50 us low level input to confirm the input data and change it's state + Timer::after_micros(50).await; + // wait until ticker tick + ticker.next().await; + } + } +} From 1934c2abc81f0dd981fad625ec2712964d0a1a91 Mon Sep 17 00:00:00 2001 From: eZio Pan Date: Mon, 18 Dec 2023 00:06:32 +0800 Subject: [PATCH 039/124] match up with stm32f429zi feature flag stm32f429 has less DMA channel than stm32f411 --- examples/stm32f4/src/bin/ws2812_spi.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/stm32f4/src/bin/ws2812_spi.rs b/examples/stm32f4/src/bin/ws2812_spi.rs index e0d28af7f..170f0b59b 100644 --- a/examples/stm32f4/src/bin/ws2812_spi.rs +++ b/examples/stm32f4/src/bin/ws2812_spi.rs @@ -78,7 +78,7 @@ async fn main(_spawner: embassy_executor::Spawner) { spi_config.frequency = khz(12_800); // Since we only output waveform, then the Rx and Sck it is not considered - let mut ws2812_spi = spi::Spi::new_txonly_nosck(dp.SPI1, dp.PB5, dp.DMA2_CH2, dma::NoDma, spi_config); + let mut ws2812_spi = spi::Spi::new_txonly_nosck(dp.SPI1, dp.PB5, dp.DMA2_CH3, dma::NoDma, spi_config); // flip color at 2 Hz let mut ticker = Ticker::every(Duration::from_millis(500)); From 05b8818de01866fa988a8f65a395690f02176b34 Mon Sep 17 00:00:00 2001 From: eZio Pan Date: Mon, 18 Dec 2023 01:02:58 +0800 Subject: [PATCH 040/124] typo fix --- examples/stm32f4/src/bin/ws2812_spi.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/examples/stm32f4/src/bin/ws2812_spi.rs b/examples/stm32f4/src/bin/ws2812_spi.rs index 170f0b59b..eca657900 100644 --- a/examples/stm32f4/src/bin/ws2812_spi.rs +++ b/examples/stm32f4/src/bin/ws2812_spi.rs @@ -5,7 +5,7 @@ // Thus we can adjust SPI to send each *round* of data at 800 kHz, and in each *round*, we can adjust each *bit* to mimic 2 different PWM waveform. // such that the output waveform meet the bit representation of ws2812. // -// If you want to save SPI for other purpose, you may want to take a look at `ws2812_tim_dma.rs` file, which make use of TIM and DMA. +// If you want to save SPI for other purpose, you may want to take a look at `ws2812_pwm_dma.rs` file, which make use of TIM and DMA. // // Warning: // DO NOT stare at ws2812 directy (especially after each MCU Reset), its (max) brightness could easily make your eyes feel burn. @@ -20,11 +20,12 @@ use embassy_time::{Duration, Ticker, Timer}; use {defmt_rtt as _, panic_probe as _}; // we use 16 bit data frame format of SPI, to let timing as accurate as possible. -// thanks to loose tolerance of ws2812 timing, you can also use 8 bit data frame format, thus you need want to adjust the bit representation. +// thanks to loose tolerance of ws2812 timing, you can also use 8 bit data frame format, thus you will need to adjust the bit representation. const N0: u16 = 0b1111100000000000u16; // ws2812 Bit 0 high level timing const N1: u16 = 0b1111111111000000u16; // ws2812 Bit 1 high level timing -// ws2812 only need 24 bits for each LED, but we add one bit more to keep SPI output low +// ws2812 only need 24 bits for each LED, +// but we add one bit more to keep SPI output low at the end static TURN_OFF: [u16; 25] = [ N0, N0, N0, N0, N0, N0, N0, N0, // Green @@ -77,7 +78,7 @@ async fn main(_spawner: embassy_executor::Spawner) { let mut spi_config = spi::Config::default(); spi_config.frequency = khz(12_800); - // Since we only output waveform, then the Rx and Sck it is not considered + // Since we only output waveform, then the Rx and Sck and RxDma it is not considered let mut ws2812_spi = spi::Spi::new_txonly_nosck(dp.SPI1, dp.PB5, dp.DMA2_CH3, dma::NoDma, spi_config); // flip color at 2 Hz From b857334f92fc188004567edb93e0d1dfce4c259e Mon Sep 17 00:00:00 2001 From: RobertTDowling Date: Sun, 17 Dec 2023 15:11:03 -0800 Subject: [PATCH 041/124] STM32: Fix race in alarm setting, which impacted scheduling. Detect potential race condition (should be rare) and return false back to caller, allowing them to handle the possibility that either the alarm was never set because it was in the past (old meaning of false), or that in fact the alarm was set and may have fired within the race window (new meaning of false). In either case, the caller needs to make sure the callback got called. --- embassy-stm32/src/time_driver.rs | 19 ++++++++++++++++--- embassy-time/src/driver.rs | 4 ++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/embassy-stm32/src/time_driver.rs b/embassy-stm32/src/time_driver.rs index ea9c22d87..9981800b2 100644 --- a/embassy-stm32/src/time_driver.rs +++ b/embassy-stm32/src/time_driver.rs @@ -474,16 +474,29 @@ impl Driver for RtcDriver { return false; } - let safe_timestamp = timestamp.max(t + 3); - // Write the CCR value regardless of whether we're going to enable it now or not. // This way, when we enable it later, the right value is already set. - r.ccr(n + 1).write(|w| w.set_ccr(safe_timestamp as u16)); + r.ccr(n + 1).write(|w| w.set_ccr(timestamp as u16)); // Enable it if it'll happen soon. Otherwise, `next_period` will enable it. let diff = timestamp - t; r.dier().modify(|w| w.set_ccie(n + 1, diff < 0xc000)); + // Reevaluate if the alarm timestamp is still in the future + let t = self.now(); + if timestamp <= t { + // If alarm timestamp has passed since we set it, we have a race condition and + // the alarm may or may not have fired. + // Disarm the alarm and return `false` to indicate that. + // It is the caller's responsibility to handle this ambiguity. + r.dier().modify(|w| w.set_ccie(n + 1, false)); + + alarm.timestamp.set(u64::MAX); + + return false; + } + + // We're confident the alarm will ring in the future. true }) } diff --git a/embassy-time/src/driver.rs b/embassy-time/src/driver.rs index 5fe7becaf..81ee1b0f5 100644 --- a/embassy-time/src/driver.rs +++ b/embassy-time/src/driver.rs @@ -108,6 +108,10 @@ pub trait Driver: Send + Sync + 'static { /// The `Driver` implementation should guarantee that the alarm callback is never called synchronously from `set_alarm`. /// Rather - if `timestamp` is already in the past - `false` should be returned and alarm should not be set, /// or alternatively, the driver should return `true` and arrange to call the alarm callback as soon as possible, but not synchronously. + /// There is a rare third possibility that the alarm was barely in the future, and by the time it was enabled, it had slipped into the + /// past. This is can be detected by double-checking that the alarm is still in the future after enabling it; if it isn't, `false` + /// should also be returned to indicate that the callback may have been called already by the alarm, but it is not guaranteed, so the + /// caller should also call the callback, just like in the more common `false` case. (Note: This requires idempotency of the callback.) /// /// When callback is called, it is guaranteed that now() will return a value greater or equal than timestamp. /// From 80c9d04bbd83367340a4f3a1e991df825a0b6029 Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Sun, 17 Dec 2023 22:09:14 +0100 Subject: [PATCH 042/124] stm32: add some docs. --- embassy-nrf/src/gpio.rs | 25 ++++---- embassy-stm32/src/adc/mod.rs | 6 ++ embassy-stm32/src/adc/resolution.rs | 7 +++ embassy-stm32/src/adc/v4.rs | 11 ++++ embassy-stm32/src/can/fdcan.rs | 15 +---- embassy-stm32/src/crc/v2v3.rs | 13 ++++ embassy-stm32/src/dac/mod.rs | 21 ++++--- embassy-stm32/src/dac/tsel.rs | 2 + embassy-stm32/src/dcmi.rs | 24 +++++++- embassy-stm32/src/dma/bdma.rs | 62 ++++++++++++++++--- embassy-stm32/src/dma/dma.rs | 79 ++++++++++++++++++++++-- embassy-stm32/src/dma/dmamux.rs | 4 ++ embassy-stm32/src/dma/mod.rs | 7 +++ embassy-stm32/src/dma/word.rs | 10 +++ embassy-stm32/src/eth/generic_smi.rs | 1 + embassy-stm32/src/eth/mod.rs | 25 +++++++- embassy-stm32/src/eth/v2/mod.rs | 3 + embassy-stm32/src/exti.rs | 50 ++++++++++++--- embassy-stm32/src/flash/asynch.rs | 2 +- embassy-stm32/src/flash/common.rs | 33 +++++++++- embassy-stm32/src/flash/f0.rs | 4 +- embassy-stm32/src/flash/f3.rs | 4 +- embassy-stm32/src/flash/f7.rs | 4 +- embassy-stm32/src/flash/g.rs | 4 +- embassy-stm32/src/flash/h7.rs | 4 +- embassy-stm32/src/flash/l.rs | 4 +- embassy-stm32/src/flash/mod.rs | 76 +++++++++++++++++------ embassy-stm32/src/flash/other.rs | 4 +- embassy-stm32/src/gpio.rs | 81 ++++++++++++++++++++++--- embassy-stm32/src/i2c/mod.rs | 14 ++++- embassy-stm32/src/qspi/enums.rs | 41 ++++++++++--- embassy-stm32/src/qspi/mod.rs | 4 +- embassy-stm32/src/sai/mod.rs | 4 +- embassy-stm32/src/traits.rs | 6 ++ embassy-stm32/src/usart/ringbuffered.rs | 2 +- examples/stm32f4/src/bin/flash.rs | 6 +- examples/stm32f4/src/bin/flash_async.rs | 6 +- 37 files changed, 544 insertions(+), 124 deletions(-) diff --git a/embassy-nrf/src/gpio.rs b/embassy-nrf/src/gpio.rs index 85977a804..a47fb8350 100644 --- a/embassy-nrf/src/gpio.rs +++ b/embassy-nrf/src/gpio.rs @@ -50,19 +50,19 @@ impl<'d, T: Pin> Input<'d, T> { Self { pin } } - /// Test if current pin level is high. + /// Get whether the pin input level is high. #[inline] pub fn is_high(&mut self) -> bool { self.pin.is_high() } - /// Test if current pin level is low. + /// Get whether the pin input level is low. #[inline] pub fn is_low(&mut self) -> bool { self.pin.is_low() } - /// Returns current pin level + /// Get the pin input level. #[inline] pub fn get_level(&mut self) -> Level { self.pin.get_level() @@ -158,19 +158,19 @@ impl<'d, T: Pin> Output<'d, T> { self.pin.set_level(level) } - /// Is the output pin set as high? + /// Get whether the output level is set to high. #[inline] pub fn is_set_high(&mut self) -> bool { self.pin.is_set_high() } - /// Is the output pin set as low? + /// Get whether the output level is set to low. #[inline] pub fn is_set_low(&mut self) -> bool { self.pin.is_set_low() } - /// What level output is set to + /// Get the current output level. #[inline] pub fn get_output_level(&mut self) -> Level { self.pin.get_output_level() @@ -275,13 +275,13 @@ impl<'d, T: Pin> Flex<'d, T> { self.pin.conf().reset(); } - /// Test if current pin level is high. + /// Get whether the pin input level is high. #[inline] pub fn is_high(&mut self) -> bool { !self.is_low() } - /// Test if current pin level is low. + /// Get whether the pin input level is low. #[inline] pub fn is_low(&mut self) -> bool { self.ref_is_low() @@ -292,7 +292,7 @@ impl<'d, T: Pin> Flex<'d, T> { self.pin.block().in_.read().bits() & (1 << self.pin.pin()) == 0 } - /// Returns current pin level + /// Get the pin input level. #[inline] pub fn get_level(&mut self) -> Level { self.is_high().into() @@ -319,25 +319,24 @@ impl<'d, T: Pin> Flex<'d, T> { } } - /// Is the output pin set as high? + /// Get whether the output level is set to high. #[inline] pub fn is_set_high(&mut self) -> bool { !self.is_set_low() } - /// Is the output pin set as low? + /// Get whether the output level is set to low. #[inline] pub fn is_set_low(&mut self) -> bool { self.ref_is_set_low() } - /// Is the output pin set as low? #[inline] pub(crate) fn ref_is_set_low(&self) -> bool { self.pin.block().out.read().bits() & (1 << self.pin.pin()) == 0 } - /// What level output is set to + /// Get the current output level. #[inline] pub fn get_output_level(&mut self) -> Level { self.is_set_high().into() diff --git a/embassy-stm32/src/adc/mod.rs b/embassy-stm32/src/adc/mod.rs index dbe53c807..2e470662d 100644 --- a/embassy-stm32/src/adc/mod.rs +++ b/embassy-stm32/src/adc/mod.rs @@ -1,3 +1,4 @@ +//! Analog to Digital (ADC) converter driver. #![macro_use] #[cfg(not(adc_f3_v2))] @@ -24,6 +25,7 @@ pub use sample_time::SampleTime; use crate::peripherals; +/// Analog to Digital driver. pub struct Adc<'d, T: Instance> { #[allow(unused)] adc: crate::PeripheralRef<'d, T>, @@ -75,12 +77,16 @@ pub(crate) mod sealed { } } +/// ADC instance. #[cfg(not(any(adc_f1, adc_v1, adc_v2, adc_v3, adc_v4, adc_f3, adc_f3_v1_1, adc_g0)))] pub trait Instance: sealed::Instance + crate::Peripheral

{} +/// ADC instance. #[cfg(any(adc_f1, adc_v1, adc_v2, adc_v3, adc_v4, adc_f3, adc_f3_v1_1, adc_g0))] pub trait Instance: sealed::Instance + crate::Peripheral

+ crate::rcc::RccPeripheral {} +/// ADC pin. pub trait AdcPin: sealed::AdcPin {} +/// ADC internal channel. pub trait InternalChannel: sealed::InternalChannel {} foreach_adc!( diff --git a/embassy-stm32/src/adc/resolution.rs b/embassy-stm32/src/adc/resolution.rs index 383980b5a..64c25a776 100644 --- a/embassy-stm32/src/adc/resolution.rs +++ b/embassy-stm32/src/adc/resolution.rs @@ -1,3 +1,5 @@ +/// ADC resolution +#[allow(missing_docs)] #[cfg(any(adc_v1, adc_v2, adc_v3, adc_g0, adc_f3, adc_f3_v1_1))] #[derive(Clone, Copy, Debug, Eq, PartialEq)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] @@ -8,6 +10,8 @@ pub enum Resolution { SixBit, } +/// ADC resolution +#[allow(missing_docs)] #[cfg(adc_v4)] #[derive(Clone, Copy, Debug, Eq, PartialEq)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] @@ -49,6 +53,9 @@ impl From for crate::pac::adc::vals::Res { } impl Resolution { + /// Get the maximum reading value for this resolution. + /// + /// This is `2**n - 1`. pub fn to_max_count(&self) -> u32 { match self { #[cfg(adc_v4)] diff --git a/embassy-stm32/src/adc/v4.rs b/embassy-stm32/src/adc/v4.rs index d74617cb3..048e73184 100644 --- a/embassy-stm32/src/adc/v4.rs +++ b/embassy-stm32/src/adc/v4.rs @@ -32,6 +32,7 @@ const TEMP_CHANNEL: u8 = 18; const VBAT_CHANNEL: u8 = 17; // NOTE: Vrefint/Temperature/Vbat are not available on all ADCs, this currently cannot be modeled with stm32-data, so these are available from the software on all ADCs +/// Internal voltage reference channel. pub struct VrefInt; impl InternalChannel for VrefInt {} impl super::sealed::InternalChannel for VrefInt { @@ -40,6 +41,7 @@ impl super::sealed::InternalChannel for VrefInt { } } +/// Internal temperature channel. pub struct Temperature; impl InternalChannel for Temperature {} impl super::sealed::InternalChannel for Temperature { @@ -48,6 +50,7 @@ impl super::sealed::InternalChannel for Temperature { } } +/// Internal battery voltage channel. pub struct Vbat; impl InternalChannel for Vbat {} impl super::sealed::InternalChannel for Vbat { @@ -125,6 +128,7 @@ impl Prescaler { } impl<'d, T: Instance> Adc<'d, T> { + /// Create a new ADC driver. pub fn new(adc: impl Peripheral

+ 'd, delay: &mut impl DelayUs) -> Self { embassy_hal_internal::into_ref!(adc); T::enable_and_reset(); @@ -212,6 +216,7 @@ impl<'d, T: Instance> Adc<'d, T> { }); } + /// Enable reading the voltage reference internal channel. pub fn enable_vrefint(&self) -> VrefInt { T::common_regs().ccr().modify(|reg| { reg.set_vrefen(true); @@ -220,6 +225,7 @@ impl<'d, T: Instance> Adc<'d, T> { VrefInt {} } + /// Enable reading the temperature internal channel. pub fn enable_temperature(&self) -> Temperature { T::common_regs().ccr().modify(|reg| { reg.set_vsenseen(true); @@ -228,6 +234,7 @@ impl<'d, T: Instance> Adc<'d, T> { Temperature {} } + /// Enable reading the vbat internal channel. pub fn enable_vbat(&self) -> Vbat { T::common_regs().ccr().modify(|reg| { reg.set_vbaten(true); @@ -236,10 +243,12 @@ impl<'d, T: Instance> Adc<'d, T> { Vbat {} } + /// Set the ADC sample time. pub fn set_sample_time(&mut self, sample_time: SampleTime) { self.sample_time = sample_time; } + /// Set the ADC resolution. pub fn set_resolution(&mut self, resolution: Resolution) { T::regs().cfgr().modify(|reg| reg.set_res(resolution.into())); } @@ -263,6 +272,7 @@ impl<'d, T: Instance> Adc<'d, T> { T::regs().dr().read().0 as u16 } + /// Read an ADC pin. pub fn read

(&mut self, pin: &mut P) -> u16 where P: AdcPin, @@ -273,6 +283,7 @@ impl<'d, T: Instance> Adc<'d, T> { self.read_channel(pin.channel()) } + /// Read an ADC internal channel. pub fn read_internal(&mut self, channel: &mut impl InternalChannel) -> u16 { self.read_channel(channel.channel()) } diff --git a/embassy-stm32/src/can/fdcan.rs b/embassy-stm32/src/can/fdcan.rs index f77788db3..0cc2559cf 100644 --- a/embassy-stm32/src/can/fdcan.rs +++ b/embassy-stm32/src/can/fdcan.rs @@ -1,6 +1,3 @@ -pub use bxcan; -use embassy_hal_internal::PeripheralRef; - use crate::peripherals; pub(crate) mod sealed { @@ -25,27 +22,19 @@ pub(crate) mod sealed { } pub trait Instance { - const REGISTERS: *mut bxcan::RegisterBlock; - fn regs() -> &'static crate::pac::can::Fdcan; fn state() -> &'static State; } } +/// Interruptable FDCAN instance. pub trait InterruptableInstance {} +/// FDCAN instance. pub trait Instance: sealed::Instance + InterruptableInstance + 'static {} -pub struct BxcanInstance<'a, T>(PeripheralRef<'a, T>); - -unsafe impl<'d, T: Instance> bxcan::Instance for BxcanInstance<'d, T> { - const REGISTERS: *mut bxcan::RegisterBlock = T::REGISTERS; -} - foreach_peripheral!( (can, $inst:ident) => { impl sealed::Instance for peripherals::$inst { - const REGISTERS: *mut bxcan::RegisterBlock = crate::pac::$inst.as_ptr() as *mut _; - fn regs() -> &'static crate::pac::can::Fdcan { &crate::pac::$inst } diff --git a/embassy-stm32/src/crc/v2v3.rs b/embassy-stm32/src/crc/v2v3.rs index b36f6018c..0c4ae55ce 100644 --- a/embassy-stm32/src/crc/v2v3.rs +++ b/embassy-stm32/src/crc/v2v3.rs @@ -6,15 +6,19 @@ use crate::peripherals::CRC; use crate::rcc::sealed::RccPeripheral; use crate::Peripheral; +/// CRC driver. pub struct Crc<'d> { _peripheral: PeripheralRef<'d, CRC>, _config: Config, } +/// CRC configuration errlr pub enum ConfigError { + /// The selected polynomial is invalid. InvalidPolynomial, } +/// CRC configuration pub struct Config { reverse_in: InputReverseConfig, reverse_out: bool, @@ -25,14 +29,20 @@ pub struct Config { crc_poly: u32, } +/// Input reverse configuration. pub enum InputReverseConfig { + /// Don't reverse anything None, + /// Reverse bytes Byte, + /// Reverse 16-bit halfwords. Halfword, + /// Reverse 32-bit words. Word, } impl Config { + /// Create a new CRC config. pub fn new( reverse_in: InputReverseConfig, reverse_out: bool, @@ -57,7 +67,9 @@ impl Config { } } +/// Polynomial size #[cfg(crc_v3)] +#[allow(missing_docs)] pub enum PolySize { Width7, Width8, @@ -81,6 +93,7 @@ impl<'d> Crc<'d> { instance } + /// Reset the CRC engine. pub fn reset(&mut self) { PAC_CRC.cr().modify(|w| w.set_reset(true)); } diff --git a/embassy-stm32/src/dac/mod.rs b/embassy-stm32/src/dac/mod.rs index 500eac4c1..9c670195d 100644 --- a/embassy-stm32/src/dac/mod.rs +++ b/embassy-stm32/src/dac/mod.rs @@ -62,11 +62,11 @@ impl Mode { /// /// 12-bit values outside the permitted range are silently truncated. pub enum Value { - // 8 bit value + /// 8 bit value Bit8(u8), - // 12 bit value stored in a u16, left-aligned + /// 12 bit value stored in a u16, left-aligned Bit12Left(u16), - // 12 bit value stored in a u16, right-aligned + /// 12 bit value stored in a u16, right-aligned Bit12Right(u16), } @@ -76,11 +76,11 @@ pub enum Value { /// /// 12-bit values outside the permitted range are silently truncated. pub enum DualValue { - // 8 bit value + /// 8 bit value Bit8(u8, u8), - // 12 bit value stored in a u16, left-aligned + /// 12 bit value stored in a u16, left-aligned Bit12Left(u16, u16), - // 12 bit value stored in a u16, right-aligned + /// 12 bit value stored in a u16, right-aligned Bit12Right(u16, u16), } @@ -88,11 +88,11 @@ pub enum DualValue { #[cfg_attr(feature = "defmt", derive(defmt::Format))] /// Array variant of [`Value`]. pub enum ValueArray<'a> { - // 8 bit values + /// 8 bit values Bit8(&'a [u8]), - // 12 bit value stored in a u16, left-aligned + /// 12 bit value stored in a u16, left-aligned Bit12Left(&'a [u16]), - // 12 bit values stored in a u16, right-aligned + /// 12 bit values stored in a u16, right-aligned Bit12Right(&'a [u16]), } @@ -106,7 +106,9 @@ pub struct DacChannel<'d, T: Instance, const N: u8, DMA = NoDma> { dma: PeripheralRef<'d, DMA>, } +/// DAC channel 1 type alias. pub type DacCh1<'d, T, DMA = NoDma> = DacChannel<'d, T, 1, DMA>; +/// DAC channel 2 type alias. pub type DacCh2<'d, T, DMA = NoDma> = DacChannel<'d, T, 2, DMA>; impl<'d, T: Instance, const N: u8, DMA> DacChannel<'d, T, N, DMA> { @@ -492,6 +494,7 @@ pub(crate) mod sealed { } } +/// DAC instance. pub trait Instance: sealed::Instance + RccPeripheral + 'static {} dma_trait!(DacDma1, Instance); dma_trait!(DacDma2, Instance); diff --git a/embassy-stm32/src/dac/tsel.rs b/embassy-stm32/src/dac/tsel.rs index f38dd8fd7..22d8d3dfa 100644 --- a/embassy-stm32/src/dac/tsel.rs +++ b/embassy-stm32/src/dac/tsel.rs @@ -1,3 +1,5 @@ +#![allow(missing_docs)] + /// Trigger selection for STM32F0. #[cfg(stm32f0)] #[derive(Debug, Copy, Clone, Eq, PartialEq)] diff --git a/embassy-stm32/src/dcmi.rs b/embassy-stm32/src/dcmi.rs index b12230794..139d8fd1b 100644 --- a/embassy-stm32/src/dcmi.rs +++ b/embassy-stm32/src/dcmi.rs @@ -36,6 +36,7 @@ impl interrupt::typelevel::Handler for InterruptHandl } /// The level on the VSync pin when the data is not valid on the parallel interface. +#[allow(missing_docs)] #[derive(Clone, Copy, PartialEq)] pub enum VSyncDataInvalidLevel { Low, @@ -43,6 +44,7 @@ pub enum VSyncDataInvalidLevel { } /// The level on the VSync pin when the data is not valid on the parallel interface. +#[allow(missing_docs)] #[derive(Clone, Copy, PartialEq)] pub enum HSyncDataInvalidLevel { Low, @@ -50,14 +52,16 @@ pub enum HSyncDataInvalidLevel { } #[derive(Clone, Copy, PartialEq)] +#[allow(missing_docs)] pub enum PixelClockPolarity { RisingEdge, FallingEdge, } -pub struct State { +struct State { waker: AtomicWaker, } + impl State { const fn new() -> State { State { @@ -68,18 +72,25 @@ impl State { static STATE: State = State::new(); +/// DCMI error. #[derive(Debug, Eq, PartialEq, Copy, Clone)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] #[non_exhaustive] pub enum Error { + /// Overrun error: the hardware generated data faster than we could read it. Overrun, + /// Internal peripheral error. PeripheralError, } +/// DCMI configuration. #[non_exhaustive] pub struct Config { + /// VSYNC level. pub vsync_level: VSyncDataInvalidLevel, + /// HSYNC level. pub hsync_level: HSyncDataInvalidLevel, + /// PIXCLK polarity. pub pixclk_polarity: PixelClockPolarity, } @@ -105,6 +116,7 @@ macro_rules! config_pins { }; } +/// DCMI driver. pub struct Dcmi<'d, T: Instance, Dma: FrameDma> { inner: PeripheralRef<'d, T>, dma: PeripheralRef<'d, Dma>, @@ -115,6 +127,7 @@ where T: Instance, Dma: FrameDma, { + /// Create a new DCMI driver with 8 data bits. pub fn new_8bit( peri: impl Peripheral

+ 'd, dma: impl Peripheral

+ 'd, @@ -139,6 +152,7 @@ where Self::new_inner(peri, dma, config, false, 0b00) } + /// Create a new DCMI driver with 10 data bits. pub fn new_10bit( peri: impl Peripheral

+ 'd, dma: impl Peripheral

+ 'd, @@ -165,6 +179,7 @@ where Self::new_inner(peri, dma, config, false, 0b01) } + /// Create a new DCMI driver with 12 data bits. pub fn new_12bit( peri: impl Peripheral

+ 'd, dma: impl Peripheral

+ 'd, @@ -193,6 +208,7 @@ where Self::new_inner(peri, dma, config, false, 0b10) } + /// Create a new DCMI driver with 14 data bits. pub fn new_14bit( peri: impl Peripheral

+ 'd, dma: impl Peripheral

+ 'd, @@ -223,6 +239,7 @@ where Self::new_inner(peri, dma, config, false, 0b11) } + /// Create a new DCMI driver with 8 data bits, with embedded synchronization. pub fn new_es_8bit( peri: impl Peripheral

+ 'd, dma: impl Peripheral

+ 'd, @@ -245,6 +262,7 @@ where Self::new_inner(peri, dma, config, true, 0b00) } + /// Create a new DCMI driver with 10 data bits, with embedded synchronization. pub fn new_es_10bit( peri: impl Peripheral

+ 'd, dma: impl Peripheral

+ 'd, @@ -269,6 +287,7 @@ where Self::new_inner(peri, dma, config, true, 0b01) } + /// Create a new DCMI driver with 12 data bits, with embedded synchronization. pub fn new_es_12bit( peri: impl Peripheral

+ 'd, dma: impl Peripheral

+ 'd, @@ -295,6 +314,7 @@ where Self::new_inner(peri, dma, config, true, 0b10) } + /// Create a new DCMI driver with 14 data bits, with embedded synchronization. pub fn new_es_14bit( peri: impl Peripheral

+ 'd, dma: impl Peripheral

+ 'd, @@ -538,7 +558,9 @@ mod sealed { } } +/// DCMI instance. pub trait Instance: sealed::Instance + 'static { + /// Interrupt for this instance. type Interrupt: interrupt::typelevel::Interrupt; } diff --git a/embassy-stm32/src/dma/bdma.rs b/embassy-stm32/src/dma/bdma.rs index a7422f66b..5102330c0 100644 --- a/embassy-stm32/src/dma/bdma.rs +++ b/embassy-stm32/src/dma/bdma.rs @@ -1,4 +1,4 @@ -#![macro_use] +//! Basic Direct Memory Acccess (BDMA) use core::future::Future; use core::pin::Pin; @@ -17,6 +17,7 @@ use crate::interrupt::Priority; use crate::pac; use crate::pac::bdma::{regs, vals}; +/// BDMA transfer options. #[derive(Debug, Copy, Clone, PartialEq, Eq)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] #[non_exhaustive] @@ -140,13 +141,17 @@ pub(crate) unsafe fn on_irq_inner(dma: pac::bdma::Dma, channel_num: usize, index STATE.ch_wakers[index].wake(); } +/// DMA request type alias. #[cfg(any(bdma_v2, dmamux))] pub type Request = u8; +/// DMA request type alias. #[cfg(not(any(bdma_v2, dmamux)))] pub type Request = (); +/// DMA channel. #[cfg(dmamux)] pub trait Channel: sealed::Channel + Peripheral

+ 'static + super::dmamux::MuxChannel {} +/// DMA channel. #[cfg(not(dmamux))] pub trait Channel: sealed::Channel + Peripheral

+ 'static {} @@ -161,12 +166,14 @@ pub(crate) mod sealed { } } +/// DMA transfer. #[must_use = "futures do nothing unless you `.await` or poll them"] pub struct Transfer<'a, C: Channel> { channel: PeripheralRef<'a, C>, } impl<'a, C: Channel> Transfer<'a, C> { + /// Create a new read DMA transfer (peripheral to memory). pub unsafe fn new_read( channel: impl Peripheral

+ 'a, request: Request, @@ -177,6 +184,7 @@ impl<'a, C: Channel> Transfer<'a, C> { Self::new_read_raw(channel, request, peri_addr, buf, options) } + /// Create a new read DMA transfer (peripheral to memory), using raw pointers. pub unsafe fn new_read_raw( channel: impl Peripheral

+ 'a, request: Request, @@ -202,6 +210,7 @@ impl<'a, C: Channel> Transfer<'a, C> { ) } + /// Create a new write DMA transfer (memory to peripheral). pub unsafe fn new_write( channel: impl Peripheral

+ 'a, request: Request, @@ -212,6 +221,7 @@ impl<'a, C: Channel> Transfer<'a, C> { Self::new_write_raw(channel, request, buf, peri_addr, options) } + /// Create a new write DMA transfer (memory to peripheral), using raw pointers. pub unsafe fn new_write_raw( channel: impl Peripheral

+ 'a, request: Request, @@ -237,6 +247,7 @@ impl<'a, C: Channel> Transfer<'a, C> { ) } + /// Create a new write DMA transfer (memory to peripheral), writing the same value repeatedly. pub unsafe fn new_write_repeated( channel: impl Peripheral

+ 'a, request: Request, @@ -321,6 +332,9 @@ impl<'a, C: Channel> Transfer<'a, C> { }); } + /// Request the transfer to stop. + /// + /// This doesn't immediately stop the transfer, you have to wait until [`is_running`](Self::is_running) returns false. pub fn request_stop(&mut self) { let ch = self.channel.regs().ch(self.channel.num()); @@ -331,6 +345,10 @@ impl<'a, C: Channel> Transfer<'a, C> { }); } + /// Return whether this transfer is still running. + /// + /// If this returns `false`, it can be because either the transfer finished, or + /// it was requested to stop early with [`request_stop`](Self::request_stop). pub fn is_running(&mut self) -> bool { let ch = self.channel.regs().ch(self.channel.num()); let en = ch.cr().read().en(); @@ -339,13 +357,15 @@ impl<'a, C: Channel> Transfer<'a, C> { en && (circular || !tcif) } - /// Gets the total remaining transfers for the channel - /// Note: this will be zero for transfers that completed without cancellation. + /// Get the total remaining transfers for the channel. + /// + /// This will be zero for transfers that completed instead of being canceled with [`request_stop`](Self::request_stop). pub fn get_remaining_transfers(&self) -> u16 { let ch = self.channel.regs().ch(self.channel.num()); ch.ndtr().read().ndt() } + /// Blocking wait until the transfer finishes. pub fn blocking_wait(mut self) { while self.is_running() {} self.request_stop(); @@ -411,6 +431,7 @@ impl<'a, C: Channel> DmaCtrl for DmaCtrlImpl<'a, C> { } } +/// Ringbuffer for reading data using DMA circular mode. pub struct ReadableRingBuffer<'a, C: Channel, W: Word> { cr: regs::Cr, channel: PeripheralRef<'a, C>, @@ -418,7 +439,8 @@ pub struct ReadableRingBuffer<'a, C: Channel, W: Word> { } impl<'a, C: Channel, W: Word> ReadableRingBuffer<'a, C, W> { - pub unsafe fn new_read( + /// Create a new ring buffer. + pub unsafe fn new( channel: impl Peripheral

+ 'a, _request: Request, peri_addr: *mut W, @@ -473,11 +495,15 @@ impl<'a, C: Channel, W: Word> ReadableRingBuffer<'a, C, W> { this } + /// Start the ring buffer operation. + /// + /// You must call this after creating it for it to work. pub fn start(&mut self) { let ch = self.channel.regs().ch(self.channel.num()); ch.cr().write_value(self.cr) } + /// Clear all data in the ring buffer. pub fn clear(&mut self) { self.ringbuf.clear(&mut DmaCtrlImpl(self.channel.reborrow())); } @@ -509,10 +535,11 @@ impl<'a, C: Channel, W: Word> ReadableRingBuffer<'a, C, W> { } /// The capacity of the ringbuffer. - pub const fn cap(&self) -> usize { + pub const fn capacity(&self) -> usize { self.ringbuf.cap() } + /// Set a waker to be woken when at least one byte is received. pub fn set_waker(&mut self, waker: &Waker) { DmaCtrlImpl(self.channel.reborrow()).set_waker(waker); } @@ -526,6 +553,9 @@ impl<'a, C: Channel, W: Word> ReadableRingBuffer<'a, C, W> { }); } + /// Request DMA to stop. + /// + /// This doesn't immediately stop the transfer, you have to wait until [`is_running`](Self::is_running) returns false. pub fn request_stop(&mut self) { let ch = self.channel.regs().ch(self.channel.num()); @@ -539,6 +569,10 @@ impl<'a, C: Channel, W: Word> ReadableRingBuffer<'a, C, W> { }); } + /// Return whether DMA is still running. + /// + /// If this returns `false`, it can be because either the transfer finished, or + /// it was requested to stop early with [`request_stop`](Self::request_stop). pub fn is_running(&mut self) -> bool { let ch = self.channel.regs().ch(self.channel.num()); ch.cr().read().en() @@ -555,6 +589,7 @@ impl<'a, C: Channel, W: Word> Drop for ReadableRingBuffer<'a, C, W> { } } +/// Ringbuffer for writing data using DMA circular mode. pub struct WritableRingBuffer<'a, C: Channel, W: Word> { cr: regs::Cr, channel: PeripheralRef<'a, C>, @@ -562,7 +597,8 @@ pub struct WritableRingBuffer<'a, C: Channel, W: Word> { } impl<'a, C: Channel, W: Word> WritableRingBuffer<'a, C, W> { - pub unsafe fn new_write( + /// Create a new ring buffer. + pub unsafe fn new( channel: impl Peripheral

+ 'a, _request: Request, peri_addr: *mut W, @@ -617,11 +653,15 @@ impl<'a, C: Channel, W: Word> WritableRingBuffer<'a, C, W> { this } + /// Start the ring buffer operation. + /// + /// You must call this after creating it for it to work. pub fn start(&mut self) { let ch = self.channel.regs().ch(self.channel.num()); ch.cr().write_value(self.cr) } + /// Clear all data in the ring buffer. pub fn clear(&mut self) { self.ringbuf.clear(&mut DmaCtrlImpl(self.channel.reborrow())); } @@ -640,10 +680,11 @@ impl<'a, C: Channel, W: Word> WritableRingBuffer<'a, C, W> { } /// The capacity of the ringbuffer. - pub const fn cap(&self) -> usize { + pub const fn capacity(&self) -> usize { self.ringbuf.cap() } + /// Set a waker to be woken when at least one byte is sent. pub fn set_waker(&mut self, waker: &Waker) { DmaCtrlImpl(self.channel.reborrow()).set_waker(waker); } @@ -657,6 +698,9 @@ impl<'a, C: Channel, W: Word> WritableRingBuffer<'a, C, W> { }); } + /// Request DMA to stop. + /// + /// This doesn't immediately stop the transfer, you have to wait until [`is_running`](Self::is_running) returns false. pub fn request_stop(&mut self) { let ch = self.channel.regs().ch(self.channel.num()); @@ -670,6 +714,10 @@ impl<'a, C: Channel, W: Word> WritableRingBuffer<'a, C, W> { }); } + /// Return whether DMA is still running. + /// + /// If this returns `false`, it can be because either the transfer finished, or + /// it was requested to stop early with [`request_stop`](Self::request_stop). pub fn is_running(&mut self) -> bool { let ch = self.channel.regs().ch(self.channel.num()); ch.cr().read().en() diff --git a/embassy-stm32/src/dma/dma.rs b/embassy-stm32/src/dma/dma.rs index cce0407c1..64e492c10 100644 --- a/embassy-stm32/src/dma/dma.rs +++ b/embassy-stm32/src/dma/dma.rs @@ -16,6 +16,7 @@ use crate::interrupt::Priority; use crate::pac::dma::{regs, vals}; use crate::{interrupt, pac}; +/// DMA transfer options. #[derive(Debug, Copy, Clone, PartialEq, Eq)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] #[non_exhaustive] @@ -69,6 +70,7 @@ impl From

for vals::Dir { } } +/// DMA transfer burst setting. #[derive(Debug, Copy, Clone, PartialEq, Eq)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] pub enum Burst { @@ -93,6 +95,7 @@ impl From for vals::Burst { } } +/// DMA flow control setting. #[derive(Debug, Copy, Clone, PartialEq, Eq)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] pub enum FlowControl { @@ -111,6 +114,7 @@ impl From for vals::Pfctrl { } } +/// DMA FIFO threshold. #[derive(Debug, Copy, Clone, PartialEq, Eq)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] pub enum FifoThreshold { @@ -208,13 +212,17 @@ pub(crate) unsafe fn on_irq_inner(dma: pac::dma::Dma, channel_num: usize, index: STATE.ch_wakers[index].wake(); } +/// DMA request type alias. (also known as DMA channel number in some chips) #[cfg(any(dma_v2, dmamux))] pub type Request = u8; +/// DMA request type alias. (also known as DMA channel number in some chips) #[cfg(not(any(dma_v2, dmamux)))] pub type Request = (); +/// DMA channel. #[cfg(dmamux)] pub trait Channel: sealed::Channel + Peripheral

+ 'static + super::dmamux::MuxChannel {} +/// DMA channel. #[cfg(not(dmamux))] pub trait Channel: sealed::Channel + Peripheral

+ 'static {} @@ -229,12 +237,14 @@ pub(crate) mod sealed { } } +/// DMA transfer. #[must_use = "futures do nothing unless you `.await` or poll them"] pub struct Transfer<'a, C: Channel> { channel: PeripheralRef<'a, C>, } impl<'a, C: Channel> Transfer<'a, C> { + /// Create a new read DMA transfer (peripheral to memory). pub unsafe fn new_read( channel: impl Peripheral

+ 'a, request: Request, @@ -245,6 +255,7 @@ impl<'a, C: Channel> Transfer<'a, C> { Self::new_read_raw(channel, request, peri_addr, buf, options) } + /// Create a new read DMA transfer (peripheral to memory), using raw pointers. pub unsafe fn new_read_raw( channel: impl Peripheral

+ 'a, request: Request, @@ -270,6 +281,7 @@ impl<'a, C: Channel> Transfer<'a, C> { ) } + /// Create a new write DMA transfer (memory to peripheral). pub unsafe fn new_write( channel: impl Peripheral

+ 'a, request: Request, @@ -280,6 +292,7 @@ impl<'a, C: Channel> Transfer<'a, C> { Self::new_write_raw(channel, request, buf, peri_addr, options) } + /// Create a new write DMA transfer (memory to peripheral), using raw pointers. pub unsafe fn new_write_raw( channel: impl Peripheral

+ 'a, request: Request, @@ -305,6 +318,7 @@ impl<'a, C: Channel> Transfer<'a, C> { ) } + /// Create a new write DMA transfer (memory to peripheral), writing the same value repeatedly. pub unsafe fn new_write_repeated( channel: impl Peripheral

+ 'a, request: Request, @@ -407,6 +421,9 @@ impl<'a, C: Channel> Transfer<'a, C> { }); } + /// Request the transfer to stop. + /// + /// This doesn't immediately stop the transfer, you have to wait until [`is_running`](Self::is_running) returns false. pub fn request_stop(&mut self) { let ch = self.channel.regs().st(self.channel.num()); @@ -417,6 +434,10 @@ impl<'a, C: Channel> Transfer<'a, C> { }); } + /// Return whether this transfer is still running. + /// + /// If this returns `false`, it can be because either the transfer finished, or + /// it was requested to stop early with [`request_stop`](Self::request_stop). pub fn is_running(&mut self) -> bool { let ch = self.channel.regs().st(self.channel.num()); ch.cr().read().en() @@ -429,6 +450,7 @@ impl<'a, C: Channel> Transfer<'a, C> { ch.ndtr().read().ndt() } + /// Blocking wait until the transfer finishes. pub fn blocking_wait(mut self) { while self.is_running() {} @@ -465,12 +487,14 @@ impl<'a, C: Channel> Future for Transfer<'a, C> { // ================================== +/// Double-buffered DMA transfer. pub struct DoubleBuffered<'a, C: Channel, W: Word> { channel: PeripheralRef<'a, C>, _phantom: PhantomData, } impl<'a, C: Channel, W: Word> DoubleBuffered<'a, C, W> { + /// Create a new read DMA transfer (peripheral to memory). pub unsafe fn new_read( channel: impl Peripheral

+ 'a, _request: Request, @@ -554,25 +578,36 @@ impl<'a, C: Channel, W: Word> DoubleBuffered<'a, C, W> { }); } + /// Set the first buffer address. + /// + /// You may call this while DMA is transferring the other buffer. pub unsafe fn set_buffer0(&mut self, buffer: *mut W) { let ch = self.channel.regs().st(self.channel.num()); ch.m0ar().write_value(buffer as _); } + /// Set the second buffer address. + /// + /// You may call this while DMA is transferring the other buffer. pub unsafe fn set_buffer1(&mut self, buffer: *mut W) { let ch = self.channel.regs().st(self.channel.num()); ch.m1ar().write_value(buffer as _); } + /// Returh whether buffer0 is accessible (i.e. whether DMA is transferring buffer1 now) pub fn is_buffer0_accessible(&mut self) -> bool { let ch = self.channel.regs().st(self.channel.num()); ch.cr().read().ct() == vals::Ct::MEMORY1 } + /// Set a waker to be woken when one of the buffers is being transferred. pub fn set_waker(&mut self, waker: &Waker) { STATE.ch_wakers[self.channel.index()].register(waker); } + /// Request the transfer to stop. + /// + /// This doesn't immediately stop the transfer, you have to wait until [`is_running`](Self::is_running) returns false. pub fn request_stop(&mut self) { let ch = self.channel.regs().st(self.channel.num()); @@ -583,6 +618,10 @@ impl<'a, C: Channel, W: Word> DoubleBuffered<'a, C, W> { }); } + /// Return whether this transfer is still running. + /// + /// If this returns `false`, it can be because either the transfer finished, or + /// it was requested to stop early with [`request_stop`](Self::request_stop). pub fn is_running(&mut self) -> bool { let ch = self.channel.regs().st(self.channel.num()); ch.cr().read().en() @@ -629,6 +668,7 @@ impl<'a, C: Channel> DmaCtrl for DmaCtrlImpl<'a, C> { } } +/// Ringbuffer for receiving data using DMA circular mode. pub struct ReadableRingBuffer<'a, C: Channel, W: Word> { cr: regs::Cr, channel: PeripheralRef<'a, C>, @@ -636,7 +676,8 @@ pub struct ReadableRingBuffer<'a, C: Channel, W: Word> { } impl<'a, C: Channel, W: Word> ReadableRingBuffer<'a, C, W> { - pub unsafe fn new_read( + /// Create a new ring buffer. + pub unsafe fn new( channel: impl Peripheral

+ 'a, _request: Request, peri_addr: *mut W, @@ -706,11 +747,15 @@ impl<'a, C: Channel, W: Word> ReadableRingBuffer<'a, C, W> { this } + /// Start the ring buffer operation. + /// + /// You must call this after creating it for it to work. pub fn start(&mut self) { let ch = self.channel.regs().st(self.channel.num()); ch.cr().write_value(self.cr); } + /// Clear all data in the ring buffer. pub fn clear(&mut self) { self.ringbuf.clear(&mut DmaCtrlImpl(self.channel.reborrow())); } @@ -741,11 +786,12 @@ impl<'a, C: Channel, W: Word> ReadableRingBuffer<'a, C, W> { .await } - // The capacity of the ringbuffer - pub const fn cap(&self) -> usize { + /// The capacity of the ringbuffer + pub const fn capacity(&self) -> usize { self.ringbuf.cap() } + /// Set a waker to be woken when at least one byte is received. pub fn set_waker(&mut self, waker: &Waker) { DmaCtrlImpl(self.channel.reborrow()).set_waker(waker); } @@ -763,6 +809,9 @@ impl<'a, C: Channel, W: Word> ReadableRingBuffer<'a, C, W> { }); } + /// Request DMA to stop. + /// + /// This doesn't immediately stop the transfer, you have to wait until [`is_running`](Self::is_running) returns false. pub fn request_stop(&mut self) { let ch = self.channel.regs().st(self.channel.num()); @@ -774,6 +823,10 @@ impl<'a, C: Channel, W: Word> ReadableRingBuffer<'a, C, W> { }); } + /// Return whether DMA is still running. + /// + /// If this returns `false`, it can be because either the transfer finished, or + /// it was requested to stop early with [`request_stop`](Self::request_stop). pub fn is_running(&mut self) -> bool { let ch = self.channel.regs().st(self.channel.num()); ch.cr().read().en() @@ -790,6 +843,7 @@ impl<'a, C: Channel, W: Word> Drop for ReadableRingBuffer<'a, C, W> { } } +/// Ringbuffer for writing data using DMA circular mode. pub struct WritableRingBuffer<'a, C: Channel, W: Word> { cr: regs::Cr, channel: PeripheralRef<'a, C>, @@ -797,7 +851,8 @@ pub struct WritableRingBuffer<'a, C: Channel, W: Word> { } impl<'a, C: Channel, W: Word> WritableRingBuffer<'a, C, W> { - pub unsafe fn new_write( + /// Create a new ring buffer. + pub unsafe fn new( channel: impl Peripheral

+ 'a, _request: Request, peri_addr: *mut W, @@ -867,11 +922,15 @@ impl<'a, C: Channel, W: Word> WritableRingBuffer<'a, C, W> { this } + /// Start the ring buffer operation. + /// + /// You must call this after creating it for it to work. pub fn start(&mut self) { let ch = self.channel.regs().st(self.channel.num()); ch.cr().write_value(self.cr); } + /// Clear all data in the ring buffer. pub fn clear(&mut self) { self.ringbuf.clear(&mut DmaCtrlImpl(self.channel.reborrow())); } @@ -889,11 +948,12 @@ impl<'a, C: Channel, W: Word> WritableRingBuffer<'a, C, W> { .await } - // The capacity of the ringbuffer - pub const fn cap(&self) -> usize { + /// The capacity of the ringbuffer + pub const fn capacity(&self) -> usize { self.ringbuf.cap() } + /// Set a waker to be woken when at least one byte is received. pub fn set_waker(&mut self, waker: &Waker) { DmaCtrlImpl(self.channel.reborrow()).set_waker(waker); } @@ -911,6 +971,9 @@ impl<'a, C: Channel, W: Word> WritableRingBuffer<'a, C, W> { }); } + /// Request DMA to stop. + /// + /// This doesn't immediately stop the transfer, you have to wait until [`is_running`](Self::is_running) returns false. pub fn request_stop(&mut self) { let ch = self.channel.regs().st(self.channel.num()); @@ -922,6 +985,10 @@ impl<'a, C: Channel, W: Word> WritableRingBuffer<'a, C, W> { }); } + /// Return whether DMA is still running. + /// + /// If this returns `false`, it can be because either the transfer finished, or + /// it was requested to stop early with [`request_stop`](Self::request_stop). pub fn is_running(&mut self) -> bool { let ch = self.channel.regs().st(self.channel.num()); ch.cr().read().en() diff --git a/embassy-stm32/src/dma/dmamux.rs b/embassy-stm32/src/dma/dmamux.rs index 20601dc86..9cd494724 100644 --- a/embassy-stm32/src/dma/dmamux.rs +++ b/embassy-stm32/src/dma/dmamux.rs @@ -22,11 +22,15 @@ pub(crate) mod dmamux_sealed { } } +/// DMAMUX1 instance. pub struct DMAMUX1; +/// DMAMUX2 instance. #[cfg(stm32h7)] pub struct DMAMUX2; +/// DMAMUX channel trait. pub trait MuxChannel: dmamux_sealed::MuxChannel { + /// DMAMUX instance this channel is on. type Mux; } diff --git a/embassy-stm32/src/dma/mod.rs b/embassy-stm32/src/dma/mod.rs index 29fced8fc..fb40a4b5e 100644 --- a/embassy-stm32/src/dma/mod.rs +++ b/embassy-stm32/src/dma/mod.rs @@ -39,6 +39,13 @@ enum Dir { PeripheralToMemory, } +/// "No DMA" placeholder. +/// +/// You may pass this in place of a real DMA channel when creating a driver +/// to indicate it should not use DMA. +/// +/// This often causes async functionality to not be available on the instance, +/// leaving only blocking functionality. pub struct NoDma; impl_peripheral!(NoDma); diff --git a/embassy-stm32/src/dma/word.rs b/embassy-stm32/src/dma/word.rs index aef6e9700..a72c4b7d9 100644 --- a/embassy-stm32/src/dma/word.rs +++ b/embassy-stm32/src/dma/word.rs @@ -1,3 +1,6 @@ +//! DMA word sizes. + +#[allow(missing_docs)] #[derive(Debug, Copy, Clone, PartialEq, Eq)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] pub enum WordSize { @@ -7,6 +10,7 @@ pub enum WordSize { } impl WordSize { + /// Amount of bytes of this word size. pub fn bytes(&self) -> usize { match self { Self::OneByte => 1, @@ -20,8 +24,13 @@ mod sealed { pub trait Word {} } +/// DMA word trait. +/// +/// This is implemented for u8, u16, u32, etc. pub trait Word: sealed::Word + Default + Copy + 'static { + /// Word size fn size() -> WordSize; + /// Amount of bits of this word size. fn bits() -> usize; } @@ -40,6 +49,7 @@ macro_rules! impl_word { ($T:ident, $uX:ident, $bits:literal, $size:ident) => { #[repr(transparent)] #[derive(Copy, Clone, Default)] + #[doc = concat!(stringify!($T), " word size")] pub struct $T(pub $uX); impl_word!(_, $T, $bits, $size); }; diff --git a/embassy-stm32/src/eth/generic_smi.rs b/embassy-stm32/src/eth/generic_smi.rs index 1e1094a1c..9c26e90f1 100644 --- a/embassy-stm32/src/eth/generic_smi.rs +++ b/embassy-stm32/src/eth/generic_smi.rs @@ -102,6 +102,7 @@ unsafe impl PHY for GenericSMI { /// Public functions for the PHY impl GenericSMI { + /// Set the SMI polling interval. #[cfg(feature = "time")] pub fn set_poll_interval(&mut self, poll_interval: Duration) { self.poll_interval = poll_interval diff --git a/embassy-stm32/src/eth/mod.rs b/embassy-stm32/src/eth/mod.rs index 556aadd73..dbf91eedc 100644 --- a/embassy-stm32/src/eth/mod.rs +++ b/embassy-stm32/src/eth/mod.rs @@ -22,6 +22,14 @@ const RX_BUFFER_SIZE: usize = 1536; #[derive(Copy, Clone)] pub(crate) struct Packet([u8; N]); +/// Ethernet packet queue. +/// +/// This struct owns the memory used for reading and writing packets. +/// +/// `TX` is the number of packets in the transmit queue, `RX` in the receive +/// queue. A bigger queue allows the hardware to receive more packets while the +/// CPU is busy doing other things, which may increase performance (especially for RX) +/// at the cost of more RAM usage. pub struct PacketQueue { tx_desc: [TDes; TX], rx_desc: [RDes; RX], @@ -30,6 +38,7 @@ pub struct PacketQueue { } impl PacketQueue { + /// Create a new packet queue. pub const fn new() -> Self { const NEW_TDES: TDes = TDes::new(); const NEW_RDES: RDes = RDes::new(); @@ -41,7 +50,18 @@ impl PacketQueue { } } - // Allow to initialize a Self without requiring it to go on the stack + /// Initialize a packet queue in-place. + /// + /// This can be helpful to avoid accidentally stack-allocating the packet queue in the stack. The + /// Rust compiler can sometimes be a bit dumb when working with large owned values: if you call `new()` + /// and then store the returned PacketQueue in its final place (like a `static`), the compiler might + /// place it temporarily on the stack then move it. Since this struct is quite big, it may result + /// in a stack overflow. + /// + /// With this function, you can create an uninitialized `static` with type `MaybeUninit>` + /// and initialize it in-place, guaranteeing no stack usage. + /// + /// After calling this function, calling `assume_init` on the MaybeUninit is guaranteed safe. pub fn init(this: &mut MaybeUninit) { unsafe { this.as_mut_ptr().write_bytes(0u8, 1); @@ -93,6 +113,7 @@ impl<'d, T: Instance, P: PHY> embassy_net_driver::Driver for Ethernet<'d, T, P> } } +/// `embassy-net` RX token. pub struct RxToken<'a, 'd> { rx: &'a mut RDesRing<'d>, } @@ -110,6 +131,7 @@ impl<'a, 'd> embassy_net_driver::RxToken for RxToken<'a, 'd> { } } +/// `embassy-net` TX token. pub struct TxToken<'a, 'd> { tx: &'a mut TDesRing<'d>, } @@ -159,6 +181,7 @@ pub(crate) mod sealed { } } +/// Ethernet instance. pub trait Instance: sealed::Instance + Send + 'static {} impl sealed::Instance for crate::peripherals::ETH { diff --git a/embassy-stm32/src/eth/v2/mod.rs b/embassy-stm32/src/eth/v2/mod.rs index c77155fea..59745cba0 100644 --- a/embassy-stm32/src/eth/v2/mod.rs +++ b/embassy-stm32/src/eth/v2/mod.rs @@ -34,6 +34,7 @@ impl interrupt::typelevel::Handler for InterruptHandl } } +/// Ethernet driver. pub struct Ethernet<'d, T: Instance, P: PHY> { _peri: PeripheralRef<'d, T>, pub(crate) tx: TDesRing<'d>, @@ -56,6 +57,7 @@ macro_rules! config_pins { } impl<'d, T: Instance, P: PHY> Ethernet<'d, T, P> { + /// Create a new Ethernet driver. pub fn new( queue: &'d mut PacketQueue, peri: impl Peripheral

+ 'd, @@ -237,6 +239,7 @@ impl<'d, T: Instance, P: PHY> Ethernet<'d, T, P> { } } +/// Ethernet SMI driver. pub struct EthernetStationManagement { peri: PhantomData, clock_range: u8, diff --git a/embassy-stm32/src/exti.rs b/embassy-stm32/src/exti.rs index e77ac30fb..371be913e 100644 --- a/embassy-stm32/src/exti.rs +++ b/embassy-stm32/src/exti.rs @@ -39,7 +39,7 @@ fn exticr_regs() -> pac::afio::Afio { pac::AFIO } -pub unsafe fn on_irq() { +unsafe fn on_irq() { #[cfg(feature = "low-power")] crate::low_power::on_wakeup_irq(); @@ -85,7 +85,13 @@ impl Iterator for BitIter { } } -/// EXTI input driver +/// EXTI input driver. +/// +/// This driver augments a GPIO `Input` with EXTI functionality. EXTI is not +/// built into `Input` itself because it needs to take ownership of the corresponding +/// EXTI channel, which is a limited resource. +/// +/// Pins PA5, PB5, PC5... all use EXTI channel 5, so you can't use EXTI on, say, PA5 and PC5 at the same time. pub struct ExtiInput<'d, T: GpioPin> { pin: Input<'d, T>, } @@ -93,23 +99,30 @@ pub struct ExtiInput<'d, T: GpioPin> { impl<'d, T: GpioPin> Unpin for ExtiInput<'d, T> {} impl<'d, T: GpioPin> ExtiInput<'d, T> { + /// Create an EXTI input. pub fn new(pin: Input<'d, T>, _ch: impl Peripheral

+ 'd) -> Self { Self { pin } } + /// Get whether the pin is high. pub fn is_high(&mut self) -> bool { self.pin.is_high() } + /// Get whether the pin is low. pub fn is_low(&mut self) -> bool { self.pin.is_low() } + /// Get the pin level. pub fn get_level(&mut self) -> Level { self.pin.get_level() } - pub async fn wait_for_high<'a>(&'a mut self) { + /// Asynchronously wait until the pin is high. + /// + /// This returns immediately if the pin is already high. + pub async fn wait_for_high(&mut self) { let fut = ExtiInputFuture::new(self.pin.pin.pin.pin(), self.pin.pin.pin.port(), true, false); if self.is_high() { return; @@ -117,7 +130,10 @@ impl<'d, T: GpioPin> ExtiInput<'d, T> { fut.await } - pub async fn wait_for_low<'a>(&'a mut self) { + /// Asynchronously wait until the pin is low. + /// + /// This returns immediately if the pin is already low. + pub async fn wait_for_low(&mut self) { let fut = ExtiInputFuture::new(self.pin.pin.pin.pin(), self.pin.pin.pin.port(), false, true); if self.is_low() { return; @@ -125,15 +141,22 @@ impl<'d, T: GpioPin> ExtiInput<'d, T> { fut.await } - pub async fn wait_for_rising_edge<'a>(&'a mut self) { + /// Asynchronously wait until the pin sees a rising edge. + /// + /// If the pin is already high, it will wait for it to go low then back high. + pub async fn wait_for_rising_edge(&mut self) { ExtiInputFuture::new(self.pin.pin.pin.pin(), self.pin.pin.pin.port(), true, false).await } - pub async fn wait_for_falling_edge<'a>(&'a mut self) { + /// Asynchronously wait until the pin sees a falling edge. + /// + /// If the pin is already low, it will wait for it to go high then back low. + pub async fn wait_for_falling_edge(&mut self) { ExtiInputFuture::new(self.pin.pin.pin.pin(), self.pin.pin.pin.port(), false, true).await } - pub async fn wait_for_any_edge<'a>(&'a mut self) { + /// Asynchronously wait until the pin sees any edge (either rising or falling). + pub async fn wait_for_any_edge(&mut self) { ExtiInputFuture::new(self.pin.pin.pin.pin(), self.pin.pin.pin.port(), true, true).await } } @@ -284,6 +307,7 @@ macro_rules! foreach_exti_irq { macro_rules! impl_irq { ($e:ident) => { + #[allow(non_snake_case)] #[cfg(feature = "rt")] #[interrupt] unsafe fn $e() { @@ -298,8 +322,16 @@ pub(crate) mod sealed { pub trait Channel {} } +/// EXTI channel trait. pub trait Channel: sealed::Channel + Sized { + /// Get the EXTI channel number. fn number(&self) -> usize; + + /// Type-erase (degrade) this channel into an `AnyChannel`. + /// + /// This converts EXTI channel singletons (`EXTI0`, `EXTI1`, ...), which + /// are all different types, into the same type. It is useful for + /// creating arrays of channels, or avoiding generics. fn degrade(self) -> AnyChannel { AnyChannel { number: self.number() as u8, @@ -307,9 +339,13 @@ pub trait Channel: sealed::Channel + Sized { } } +/// Type-erased (degraded) EXTI channel. +/// +/// This represents ownership over any EXTI channel, known at runtime. pub struct AnyChannel { number: u8, } + impl_peripheral!(AnyChannel); impl sealed::Channel for AnyChannel {} impl Channel for AnyChannel { diff --git a/embassy-stm32/src/flash/asynch.rs b/embassy-stm32/src/flash/asynch.rs index eae40c7ec..e3c6d4d67 100644 --- a/embassy-stm32/src/flash/asynch.rs +++ b/embassy-stm32/src/flash/asynch.rs @@ -59,7 +59,7 @@ impl embedded_storage_async::nor_flash::ReadNorFlash for Flash<'_, Async> { const READ_SIZE: usize = super::READ_SIZE; async fn read(&mut self, offset: u32, bytes: &mut [u8]) -> Result<(), Self::Error> { - self.read(offset, bytes) + self.blocking_read(offset, bytes) } fn capacity(&self) -> usize { diff --git a/embassy-stm32/src/flash/common.rs b/embassy-stm32/src/flash/common.rs index 8acad1c7c..f8561edb3 100644 --- a/embassy-stm32/src/flash/common.rs +++ b/embassy-stm32/src/flash/common.rs @@ -12,12 +12,14 @@ use super::{ use crate::peripherals::FLASH; use crate::Peripheral; +/// Internal flash memory driver. pub struct Flash<'d, MODE = Async> { pub(crate) inner: PeripheralRef<'d, FLASH>, pub(crate) _mode: PhantomData, } impl<'d> Flash<'d, Blocking> { + /// Create a new flash driver, usable in blocking mode. pub fn new_blocking(p: impl Peripheral

+ 'd) -> Self { into_ref!(p); @@ -29,15 +31,26 @@ impl<'d> Flash<'d, Blocking> { } impl<'d, MODE> Flash<'d, MODE> { + /// Split this flash driver into one instance per flash memory region. + /// + /// See module-level documentation for details on how memory regions work. pub fn into_blocking_regions(self) -> FlashLayout<'d, Blocking> { assert!(family::is_default_layout()); FlashLayout::new(self.inner) } - pub fn read(&mut self, offset: u32, bytes: &mut [u8]) -> Result<(), Error> { + /// Blocking read. + /// + /// NOTE: `offset` is an offset from the flash start, NOT an absolute address. + /// For example, to read address `0x0800_1234` you have to use offset `0x1234`. + pub fn blocking_read(&mut self, offset: u32, bytes: &mut [u8]) -> Result<(), Error> { blocking_read(FLASH_BASE as u32, FLASH_SIZE as u32, offset, bytes) } + /// Blocking write. + /// + /// NOTE: `offset` is an offset from the flash start, NOT an absolute address. + /// For example, to write address `0x0800_1234` you have to use offset `0x1234`. pub fn blocking_write(&mut self, offset: u32, bytes: &[u8]) -> Result<(), Error> { unsafe { blocking_write( @@ -50,6 +63,10 @@ impl<'d, MODE> Flash<'d, MODE> { } } + /// Blocking erase. + /// + /// NOTE: `from` and `to` are offsets from the flash start, NOT an absolute address. + /// For example, to erase address `0x0801_0000` you have to use offset `0x1_0000`. pub fn blocking_erase(&mut self, from: u32, to: u32) -> Result<(), Error> { unsafe { blocking_erase(FLASH_BASE as u32, from, to, erase_sector_unlocked) } } @@ -206,7 +223,7 @@ impl embedded_storage::nor_flash::ReadNorFlash for Flash<'_, MODE> { const READ_SIZE: usize = READ_SIZE; fn read(&mut self, offset: u32, bytes: &mut [u8]) -> Result<(), Self::Error> { - self.read(offset, bytes) + self.blocking_read(offset, bytes) } fn capacity(&self) -> usize { @@ -230,16 +247,28 @@ impl embedded_storage::nor_flash::NorFlash for Flash<'_, MODE> { foreach_flash_region! { ($type_name:ident, $write_size:literal, $erase_size:literal) => { impl crate::_generated::flash_regions::$type_name<'_, MODE> { + /// Blocking read. + /// + /// NOTE: `offset` is an offset from the flash start, NOT an absolute address. + /// For example, to read address `0x0800_1234` you have to use offset `0x1234`. pub fn blocking_read(&mut self, offset: u32, bytes: &mut [u8]) -> Result<(), Error> { blocking_read(self.0.base, self.0.size, offset, bytes) } } impl crate::_generated::flash_regions::$type_name<'_, Blocking> { + /// Blocking write. + /// + /// NOTE: `offset` is an offset from the flash start, NOT an absolute address. + /// For example, to write address `0x0800_1234` you have to use offset `0x1234`. pub fn blocking_write(&mut self, offset: u32, bytes: &[u8]) -> Result<(), Error> { unsafe { blocking_write(self.0.base, self.0.size, offset, bytes, write_chunk_with_critical_section) } } + /// Blocking erase. + /// + /// NOTE: `from` and `to` are offsets from the flash start, NOT an absolute address. + /// For example, to erase address `0x0801_0000` you have to use offset `0x1_0000`. pub fn blocking_erase(&mut self, from: u32, to: u32) -> Result<(), Error> { unsafe { blocking_erase(self.0.base, from, to, erase_sector_with_critical_section) } } diff --git a/embassy-stm32/src/flash/f0.rs b/embassy-stm32/src/flash/f0.rs index 80d2a8166..c0a8d7022 100644 --- a/embassy-stm32/src/flash/f0.rs +++ b/embassy-stm32/src/flash/f0.rs @@ -6,11 +6,11 @@ use super::{FlashRegion, FlashSector, FLASH_REGIONS, WRITE_SIZE}; use crate::flash::Error; use crate::pac; -pub const fn is_default_layout() -> bool { +pub(crate) const fn is_default_layout() -> bool { true } -pub const fn get_flash_regions() -> &'static [&'static FlashRegion] { +pub(crate) const fn get_flash_regions() -> &'static [&'static FlashRegion] { &FLASH_REGIONS } diff --git a/embassy-stm32/src/flash/f3.rs b/embassy-stm32/src/flash/f3.rs index 27d5281a7..817ccef4d 100644 --- a/embassy-stm32/src/flash/f3.rs +++ b/embassy-stm32/src/flash/f3.rs @@ -6,11 +6,11 @@ use super::{FlashRegion, FlashSector, FLASH_REGIONS, WRITE_SIZE}; use crate::flash::Error; use crate::pac; -pub const fn is_default_layout() -> bool { +pub(crate) const fn is_default_layout() -> bool { true } -pub const fn get_flash_regions() -> &'static [&'static FlashRegion] { +pub(crate) const fn get_flash_regions() -> &'static [&'static FlashRegion] { &FLASH_REGIONS } diff --git a/embassy-stm32/src/flash/f7.rs b/embassy-stm32/src/flash/f7.rs index 017393e80..6b3e66ac6 100644 --- a/embassy-stm32/src/flash/f7.rs +++ b/embassy-stm32/src/flash/f7.rs @@ -6,11 +6,11 @@ use super::{FlashRegion, FlashSector, FLASH_REGIONS, WRITE_SIZE}; use crate::flash::Error; use crate::pac; -pub const fn is_default_layout() -> bool { +pub(crate) const fn is_default_layout() -> bool { true } -pub const fn get_flash_regions() -> &'static [&'static FlashRegion] { +pub(crate) const fn get_flash_regions() -> &'static [&'static FlashRegion] { &FLASH_REGIONS } diff --git a/embassy-stm32/src/flash/g.rs b/embassy-stm32/src/flash/g.rs index 08145e9c4..d97b4a932 100644 --- a/embassy-stm32/src/flash/g.rs +++ b/embassy-stm32/src/flash/g.rs @@ -8,11 +8,11 @@ use super::{FlashRegion, FlashSector, FLASH_REGIONS, WRITE_SIZE}; use crate::flash::Error; use crate::pac; -pub const fn is_default_layout() -> bool { +pub(crate) const fn is_default_layout() -> bool { true } -pub const fn get_flash_regions() -> &'static [&'static FlashRegion] { +pub(crate) const fn get_flash_regions() -> &'static [&'static FlashRegion] { &FLASH_REGIONS } diff --git a/embassy-stm32/src/flash/h7.rs b/embassy-stm32/src/flash/h7.rs index 555f8d155..65d163d29 100644 --- a/embassy-stm32/src/flash/h7.rs +++ b/embassy-stm32/src/flash/h7.rs @@ -6,7 +6,7 @@ use super::{FlashRegion, FlashSector, BANK1_REGION, FLASH_REGIONS, WRITE_SIZE}; use crate::flash::Error; use crate::pac; -pub const fn is_default_layout() -> bool { +pub(crate) const fn is_default_layout() -> bool { true } @@ -14,7 +14,7 @@ const fn is_dual_bank() -> bool { FLASH_REGIONS.len() >= 2 } -pub fn get_flash_regions() -> &'static [&'static FlashRegion] { +pub(crate) fn get_flash_regions() -> &'static [&'static FlashRegion] { &FLASH_REGIONS } diff --git a/embassy-stm32/src/flash/l.rs b/embassy-stm32/src/flash/l.rs index e0159a3f6..0b332dc61 100644 --- a/embassy-stm32/src/flash/l.rs +++ b/embassy-stm32/src/flash/l.rs @@ -5,11 +5,11 @@ use super::{FlashRegion, FlashSector, FLASH_REGIONS, WRITE_SIZE}; use crate::flash::Error; use crate::pac; -pub const fn is_default_layout() -> bool { +pub(crate) const fn is_default_layout() -> bool { true } -pub const fn get_flash_regions() -> &'static [&'static FlashRegion] { +pub(crate) const fn get_flash_regions() -> &'static [&'static FlashRegion] { &FLASH_REGIONS } diff --git a/embassy-stm32/src/flash/mod.rs b/embassy-stm32/src/flash/mod.rs index 3e8f2830b..6b6b4d41c 100644 --- a/embassy-stm32/src/flash/mod.rs +++ b/embassy-stm32/src/flash/mod.rs @@ -14,50 +14,84 @@ pub use crate::_generated::flash_regions::*; pub use crate::_generated::MAX_ERASE_SIZE; pub use crate::pac::{FLASH_BASE, FLASH_SIZE, WRITE_SIZE}; +/// Get whether the default flash layout is being used. +/// +/// In some chips, dual-bank is not default. This will then return `false` +/// when dual-bank is enabled. +pub fn is_default_layout() -> bool { + family::is_default_layout() +} + +/// Get all flash regions. +pub fn get_flash_regions() -> &'static [&'static FlashRegion] { + family::get_flash_regions() +} + +/// Read size (always 1) pub const READ_SIZE: usize = 1; -pub struct Blocking; -pub struct Async; +/// Blocking flash mode typestate. +pub enum Blocking {} +/// Async flash mode typestate. +pub enum Async {} +/// Flash memory region #[derive(Debug)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] pub struct FlashRegion { + /// Bank number. pub bank: FlashBank, + /// Absolute base address. pub base: u32, + /// Size in bytes. pub size: u32, + /// Erase size (sector size). pub erase_size: u32, + /// Minimum write size. pub write_size: u32, + /// Erase value (usually `0xFF`, but is `0x00` in some chips) pub erase_value: u8, pub(crate) _ensure_internal: (), } -#[derive(Debug, PartialEq)] -#[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub struct FlashSector { - pub bank: FlashBank, - pub index_in_bank: u8, - pub start: u32, - pub size: u32, -} - -#[derive(Clone, Copy, Debug, PartialEq)] -#[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub enum FlashBank { - Bank1 = 0, - Bank2 = 1, - Otp, -} - impl FlashRegion { + /// Absolute end address. pub const fn end(&self) -> u32 { self.base + self.size } + /// Number of sectors in the region. pub const fn sectors(&self) -> u8 { (self.size / self.erase_size) as u8 } } +/// Flash sector. +#[derive(Debug, PartialEq)] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] +pub struct FlashSector { + /// Bank number. + pub bank: FlashBank, + /// Sector number within the bank. + pub index_in_bank: u8, + /// Absolute start address. + pub start: u32, + /// Size in bytes. + pub size: u32, +} + +/// Flash bank. +#[derive(Clone, Copy, Debug, PartialEq)] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] +pub enum FlashBank { + /// Bank 1 + Bank1 = 0, + /// Bank 2 + Bank2 = 1, + /// OTP region + Otp, +} + #[cfg_attr(any(flash_l0, flash_l1, flash_l4, flash_wl, flash_wb), path = "l.rs")] #[cfg_attr(flash_f0, path = "f0.rs")] #[cfg_attr(flash_f3, path = "f3.rs")] @@ -78,6 +112,10 @@ mod family; #[allow(unused_imports)] pub use family::*; +/// Flash error +/// +/// See STM32 Reference Manual for your chip for details. +#[allow(missing_docs)] #[derive(Debug, Copy, Clone, PartialEq, Eq)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] pub enum Error { diff --git a/embassy-stm32/src/flash/other.rs b/embassy-stm32/src/flash/other.rs index a7e8d1d57..20f84a72f 100644 --- a/embassy-stm32/src/flash/other.rs +++ b/embassy-stm32/src/flash/other.rs @@ -2,11 +2,11 @@ use super::{Error, FlashRegion, FlashSector, FLASH_REGIONS, WRITE_SIZE}; -pub const fn is_default_layout() -> bool { +pub(crate) const fn is_default_layout() -> bool { true } -pub const fn get_flash_regions() -> &'static [&'static FlashRegion] { +pub(crate) const fn get_flash_regions() -> &'static [&'static FlashRegion] { &FLASH_REGIONS } diff --git a/embassy-stm32/src/gpio.rs b/embassy-stm32/src/gpio.rs index bb3cf2bc4..083b3237c 100644 --- a/embassy-stm32/src/gpio.rs +++ b/embassy-stm32/src/gpio.rs @@ -29,6 +29,11 @@ impl<'d, T: Pin> Flex<'d, T> { Self { pin } } + /// Type-erase (degrade) this pin into an `AnyPin`. + /// + /// This converts pin singletons (`PA5`, `PB6`, ...), which + /// are all different types, into the same type. It is useful for + /// creating arrays of pins, or avoiding generics. #[inline] pub fn degrade(self) -> Flex<'d, AnyPin> { // Safety: We are about to drop the other copy of this pin, so @@ -141,11 +146,13 @@ impl<'d, T: Pin> Flex<'d, T> { }); } + /// Get whether the pin input level is high. #[inline] pub fn is_high(&mut self) -> bool { !self.ref_is_low() } + /// Get whether the pin input level is low. #[inline] pub fn is_low(&mut self) -> bool { self.ref_is_low() @@ -157,17 +164,19 @@ impl<'d, T: Pin> Flex<'d, T> { state == vals::Idr::LOW } + /// Get the current pin input level. #[inline] pub fn get_level(&mut self) -> Level { self.is_high().into() } + /// Get whether the output level is set to high. #[inline] pub fn is_set_high(&mut self) -> bool { !self.ref_is_set_low() } - /// Is the output pin set as low? + /// Get whether the output level is set to low. #[inline] pub fn is_set_low(&mut self) -> bool { self.ref_is_set_low() @@ -179,12 +188,13 @@ impl<'d, T: Pin> Flex<'d, T> { state == vals::Odr::LOW } - /// What level output is set to + /// Get the current output level. #[inline] pub fn get_output_level(&mut self) -> Level { self.is_set_high().into() } + /// Set the output as high. #[inline] pub fn set_high(&mut self) { self.pin.set_high(); @@ -196,6 +206,7 @@ impl<'d, T: Pin> Flex<'d, T> { self.pin.set_low(); } + /// Set the output level. #[inline] pub fn set_level(&mut self, level: Level) { match level { @@ -204,7 +215,7 @@ impl<'d, T: Pin> Flex<'d, T> { } } - /// Toggle pin output + /// Toggle the output level. #[inline] pub fn toggle(&mut self) { if self.is_set_low() { @@ -242,8 +253,11 @@ impl<'d, T: Pin> Drop for Flex<'d, T> { #[derive(Debug, Eq, PartialEq, Copy, Clone)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] pub enum Pull { + /// No pull None, + /// Pull up Up, + /// Pull down Down, } @@ -261,6 +275,9 @@ impl From for vals::Pupdr { } /// Speed settings +/// +/// These vary dpeending on the chip, ceck the reference manual or datasheet for details. +#[allow(missing_docs)] #[derive(Debug, Copy, Clone)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] pub enum Speed { @@ -305,6 +322,7 @@ pub struct Input<'d, T: Pin> { } impl<'d, T: Pin> Input<'d, T> { + /// Create GPIO input driver for a [Pin] with the provided [Pull] configuration. #[inline] pub fn new(pin: impl Peripheral

+ 'd, pull: Pull) -> Self { let mut pin = Flex::new(pin); @@ -312,6 +330,11 @@ impl<'d, T: Pin> Input<'d, T> { Self { pin } } + /// Type-erase (degrade) this pin into an `AnyPin`. + /// + /// This converts pin singletons (`PA5`, `PB6`, ...), which + /// are all different types, into the same type. It is useful for + /// creating arrays of pins, or avoiding generics. #[inline] pub fn degrade(self) -> Input<'d, AnyPin> { Input { @@ -319,16 +342,19 @@ impl<'d, T: Pin> Input<'d, T> { } } + /// Get whether the pin input level is high. #[inline] pub fn is_high(&mut self) -> bool { self.pin.is_high() } + /// Get whether the pin input level is low. #[inline] pub fn is_low(&mut self) -> bool { self.pin.is_low() } + /// Get the current pin input level. #[inline] pub fn get_level(&mut self) -> Level { self.pin.get_level() @@ -339,7 +365,9 @@ impl<'d, T: Pin> Input<'d, T> { #[derive(Debug, Eq, PartialEq, Copy, Clone)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] pub enum Level { + /// Low Low, + /// High High, } @@ -371,6 +399,7 @@ pub struct Output<'d, T: Pin> { } impl<'d, T: Pin> Output<'d, T> { + /// Create GPIO output driver for a [Pin] with the provided [Level] and [Speed] configuration. #[inline] pub fn new(pin: impl Peripheral

+ 'd, initial_output: Level, speed: Speed) -> Self { let mut pin = Flex::new(pin); @@ -382,6 +411,11 @@ impl<'d, T: Pin> Output<'d, T> { Self { pin } } + /// Type-erase (degrade) this pin into an `AnyPin`. + /// + /// This converts pin singletons (`PA5`, `PB6`, ...), which + /// are all different types, into the same type. It is useful for + /// creating arrays of pins, or avoiding generics. #[inline] pub fn degrade(self) -> Output<'d, AnyPin> { Output { @@ -442,6 +476,7 @@ pub struct OutputOpenDrain<'d, T: Pin> { } impl<'d, T: Pin> OutputOpenDrain<'d, T> { + /// Create a new GPIO open drain output driver for a [Pin] with the provided [Level] and [Speed], [Pull] configuration. #[inline] pub fn new(pin: impl Peripheral

+ 'd, initial_output: Level, speed: Speed, pull: Pull) -> Self { let mut pin = Flex::new(pin); @@ -455,6 +490,11 @@ impl<'d, T: Pin> OutputOpenDrain<'d, T> { Self { pin } } + /// Type-erase (degrade) this pin into an `AnyPin`. + /// + /// This converts pin singletons (`PA5`, `PB6`, ...), which + /// are all different types, into the same type. It is useful for + /// creating arrays of pins, or avoiding generics. #[inline] pub fn degrade(self) -> Output<'d, AnyPin> { Output { @@ -462,17 +502,19 @@ impl<'d, T: Pin> OutputOpenDrain<'d, T> { } } + /// Get whether the pin input level is high. #[inline] pub fn is_high(&mut self) -> bool { !self.pin.is_low() } + /// Get whether the pin input level is low. #[inline] pub fn is_low(&mut self) -> bool { self.pin.is_low() } - /// Returns current pin level + /// Get the current pin input level. #[inline] pub fn get_level(&mut self) -> Level { self.pin.get_level() @@ -496,19 +538,19 @@ impl<'d, T: Pin> OutputOpenDrain<'d, T> { self.pin.set_level(level); } - /// Is the output pin set as high? + /// Get whether the output level is set to high. #[inline] pub fn is_set_high(&mut self) -> bool { self.pin.is_set_high() } - /// Is the output pin set as low? + /// Get whether the output level is set to low. #[inline] pub fn is_set_low(&mut self) -> bool { self.pin.is_set_low() } - /// What level output is set to + /// Get the current output level. #[inline] pub fn get_output_level(&mut self) -> Level { self.pin.get_output_level() @@ -521,8 +563,11 @@ impl<'d, T: Pin> OutputOpenDrain<'d, T> { } } +/// GPIO output type pub enum OutputType { + /// Drive the pin both high or low. PushPull, + /// Drive the pin low, or don't drive it at all if the output level is high. OpenDrain, } @@ -535,6 +580,7 @@ impl From for sealed::AFType { } } +#[allow(missing_docs)] pub(crate) mod sealed { use super::*; @@ -542,8 +588,11 @@ pub(crate) mod sealed { #[derive(Debug, Copy, Clone)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] pub enum AFType { + /// Input Input, + /// Output, drive the pin both high or low. OutputPushPull, + /// Output, drive the pin low, or don't drive it at all if the output level is high. OutputOpenDrain, } @@ -686,7 +735,11 @@ pub(crate) mod sealed { } } +/// GPIO pin trait. pub trait Pin: Peripheral

+ Into + sealed::Pin + Sized + 'static { + /// EXTI channel assigned to this pin. + /// + /// For example, PC4 uses EXTI4. #[cfg(feature = "exti")] type ExtiChannel: crate::exti::Channel; @@ -702,7 +755,11 @@ pub trait Pin: Peripheral

+ Into + sealed::Pin + Sized + 'stat self._port() } - /// Convert from concrete pin type PX_XX to type erased `AnyPin`. + /// Type-erase (degrade) this pin into an `AnyPin`. + /// + /// This converts pin singletons (`PA5`, `PB6`, ...), which + /// are all different types, into the same type. It is useful for + /// creating arrays of pins, or avoiding generics. #[inline] fn degrade(self) -> AnyPin { AnyPin { @@ -711,12 +768,15 @@ pub trait Pin: Peripheral

+ Into + sealed::Pin + Sized + 'stat } } -// Type-erased GPIO pin +/// Type-erased GPIO pin pub struct AnyPin { pin_port: u8, } impl AnyPin { + /// Unsafely create an `AnyPin` from a pin+port number. + /// + /// `pin_port` is `port_num * 16 + pin_num`, where `port_num` is 0 for port `A`, 1 for port `B`, etc... #[inline] pub unsafe fn steal(pin_port: u8) -> Self { Self { pin_port } @@ -727,6 +787,8 @@ impl AnyPin { self.pin_port / 16 } + /// Get the GPIO register block for this pin. + #[cfg(feature = "unstable-pac")] #[inline] pub fn block(&self) -> gpio::Gpio { pac::GPIO(self._port() as _) @@ -1072,6 +1134,7 @@ impl<'d, T: Pin> embedded_hal_1::digital::StatefulOutputPin for Flex<'d, T> { } } +/// Low-level GPIO manipulation. #[cfg(feature = "unstable-pac")] pub mod low_level { pub use super::sealed::*; diff --git a/embassy-stm32/src/i2c/mod.rs b/embassy-stm32/src/i2c/mod.rs index d2a50cf7e..a8dc8e0e5 100644 --- a/embassy-stm32/src/i2c/mod.rs +++ b/embassy-stm32/src/i2c/mod.rs @@ -13,15 +13,23 @@ use embassy_sync::waitqueue::AtomicWaker; use crate::peripherals; +/// I2C error. #[derive(Debug, PartialEq, Eq)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] pub enum Error { + /// Bus error Bus, + /// Arbitration lost Arbitration, + /// ACK not received (either to the address or to a data byte) Nack, + /// Timeout Timeout, + /// CRC error Crc, + /// Overrun error Overrun, + /// Zero-length transfers are not allowed. ZeroLengthTransfer, } @@ -47,8 +55,11 @@ pub(crate) mod sealed { } } +/// I2C peripheral instance pub trait Instance: sealed::Instance + 'static { + /// Event interrupt for this instance type EventInterrupt: interrupt::typelevel::Interrupt; + /// Error interrupt for this instance type ErrorInterrupt: interrupt::typelevel::Interrupt; } @@ -57,7 +68,7 @@ pin_trait!(SdaPin, Instance); dma_trait!(RxDma, Instance); dma_trait!(TxDma, Instance); -/// Interrupt handler. +/// Event interrupt handler. pub struct EventInterruptHandler { _phantom: PhantomData, } @@ -68,6 +79,7 @@ impl interrupt::typelevel::Handler for EventInte } } +/// Error interrupt handler. pub struct ErrorInterruptHandler { _phantom: PhantomData, } diff --git a/embassy-stm32/src/qspi/enums.rs b/embassy-stm32/src/qspi/enums.rs index 0412d991a..e9e7fd482 100644 --- a/embassy-stm32/src/qspi/enums.rs +++ b/embassy-stm32/src/qspi/enums.rs @@ -18,12 +18,17 @@ impl Into for QspiMode { } } +/// QSPI lane width #[allow(dead_code)] #[derive(Copy, Clone)] pub enum QspiWidth { + /// None NONE, + /// Single lane SING, + /// Dual lanes DUAL, + /// Quad lanes QUAD, } @@ -38,10 +43,13 @@ impl Into for QspiWidth { } } +/// Flash bank selection #[allow(dead_code)] #[derive(Copy, Clone)] pub enum FlashSelection { + /// Bank 1 Flash1, + /// Bank 2 Flash2, } @@ -54,6 +62,8 @@ impl Into for FlashSelection { } } +/// QSPI memory size. +#[allow(missing_docs)] #[derive(Copy, Clone)] pub enum MemorySize { _1KiB, @@ -113,11 +123,16 @@ impl Into for MemorySize { } } +/// QSPI Address size #[derive(Copy, Clone)] pub enum AddressSize { + /// 8-bit address _8Bit, + /// 16-bit address _16Bit, + /// 24-bit address _24bit, + /// 32-bit address _32bit, } @@ -132,8 +147,10 @@ impl Into for AddressSize { } } +/// Time the Chip Select line stays high. +#[allow(missing_docs)] #[derive(Copy, Clone)] -pub enum ChipSelectHightTime { +pub enum ChipSelectHighTime { _1Cycle, _2Cycle, _3Cycle, @@ -144,21 +161,23 @@ pub enum ChipSelectHightTime { _8Cycle, } -impl Into for ChipSelectHightTime { +impl Into for ChipSelectHighTime { fn into(self) -> u8 { match self { - ChipSelectHightTime::_1Cycle => 0, - ChipSelectHightTime::_2Cycle => 1, - ChipSelectHightTime::_3Cycle => 2, - ChipSelectHightTime::_4Cycle => 3, - ChipSelectHightTime::_5Cycle => 4, - ChipSelectHightTime::_6Cycle => 5, - ChipSelectHightTime::_7Cycle => 6, - ChipSelectHightTime::_8Cycle => 7, + ChipSelectHighTime::_1Cycle => 0, + ChipSelectHighTime::_2Cycle => 1, + ChipSelectHighTime::_3Cycle => 2, + ChipSelectHighTime::_4Cycle => 3, + ChipSelectHighTime::_5Cycle => 4, + ChipSelectHighTime::_6Cycle => 5, + ChipSelectHighTime::_7Cycle => 6, + ChipSelectHighTime::_8Cycle => 7, } } } +/// FIFO threshold. +#[allow(missing_docs)] #[derive(Copy, Clone)] pub enum FIFOThresholdLevel { _1Bytes, @@ -234,6 +253,8 @@ impl Into for FIFOThresholdLevel { } } +/// Dummy cycle count +#[allow(missing_docs)] #[derive(Copy, Clone)] pub enum DummyCycles { _0, diff --git a/embassy-stm32/src/qspi/mod.rs b/embassy-stm32/src/qspi/mod.rs index 1153455c7..bac91f300 100644 --- a/embassy-stm32/src/qspi/mod.rs +++ b/embassy-stm32/src/qspi/mod.rs @@ -54,7 +54,7 @@ pub struct Config { /// Number of bytes to trigger FIFO threshold flag. pub fifo_threshold: FIFOThresholdLevel, /// Minimum number of cycles that chip select must be high between issued commands - pub cs_high_time: ChipSelectHightTime, + pub cs_high_time: ChipSelectHighTime, } impl Default for Config { @@ -64,7 +64,7 @@ impl Default for Config { address_size: AddressSize::_24bit, prescaler: 128, fifo_threshold: FIFOThresholdLevel::_17Bytes, - cs_high_time: ChipSelectHightTime::_5Cycle, + cs_high_time: ChipSelectHighTime::_5Cycle, } } } diff --git a/embassy-stm32/src/sai/mod.rs b/embassy-stm32/src/sai/mod.rs index a16d38af1..3d7f65996 100644 --- a/embassy-stm32/src/sai/mod.rs +++ b/embassy-stm32/src/sai/mod.rs @@ -583,10 +583,10 @@ fn get_ring_buffer<'d, T: Instance, C: Channel, W: word::Word>( }; match tx_rx { TxRx::Transmitter => RingBuffer::Writable(unsafe { - WritableRingBuffer::new_write(dma, request, dr(T::REGS, sub_block), dma_buf, opts) + WritableRingBuffer::new(dma, request, dr(T::REGS, sub_block), dma_buf, opts) }), TxRx::Receiver => RingBuffer::Readable(unsafe { - ReadableRingBuffer::new_read(dma, request, dr(T::REGS, sub_block), dma_buf, opts) + ReadableRingBuffer::new(dma, request, dr(T::REGS, sub_block), dma_buf, opts) }), } } diff --git a/embassy-stm32/src/traits.rs b/embassy-stm32/src/traits.rs index ffce7bd42..b4166e71a 100644 --- a/embassy-stm32/src/traits.rs +++ b/embassy-stm32/src/traits.rs @@ -2,7 +2,9 @@ macro_rules! pin_trait { ($signal:ident, $instance:path) => { + #[doc = concat!(stringify!($signal), " pin trait")] pub trait $signal: crate::gpio::Pin { + #[doc = concat!("Get the AF number needed to use this pin as", stringify!($signal))] fn af_num(&self) -> u8; } }; @@ -22,7 +24,11 @@ macro_rules! pin_trait_impl { macro_rules! dma_trait { ($signal:ident, $instance:path) => { + #[doc = concat!(stringify!($signal), " DMA request trait")] pub trait $signal: crate::dma::Channel { + #[doc = concat!("Get the DMA request number needed to use this channel as", stringify!($signal))] + /// Note: in some chips, ST calls this the "channel", and calls channels "streams". + /// `embassy-stm32` always uses the "channel" and "request number" names. fn request(&self) -> crate::dma::Request; } }; diff --git a/embassy-stm32/src/usart/ringbuffered.rs b/embassy-stm32/src/usart/ringbuffered.rs index b8d17e4e4..f8ada3926 100644 --- a/embassy-stm32/src/usart/ringbuffered.rs +++ b/embassy-stm32/src/usart/ringbuffered.rs @@ -39,7 +39,7 @@ impl<'d, T: BasicInstance, RxDma: super::RxDma> UartRx<'d, T, RxDma> { let rx_dma = unsafe { self.rx_dma.clone_unchecked() }; let _peri = unsafe { self._peri.clone_unchecked() }; - let ring_buf = unsafe { ReadableRingBuffer::new_read(rx_dma, request, rdr(T::regs()), dma_buf, opts) }; + let ring_buf = unsafe { ReadableRingBuffer::new(rx_dma, request, rdr(T::regs()), dma_buf, opts) }; // Don't disable the clock mem::forget(self); diff --git a/examples/stm32f4/src/bin/flash.rs b/examples/stm32f4/src/bin/flash.rs index 93c54e943..56a35ddee 100644 --- a/examples/stm32f4/src/bin/flash.rs +++ b/examples/stm32f4/src/bin/flash.rs @@ -31,7 +31,7 @@ fn test_flash(f: &mut Flash<'_, Blocking>, offset: u32, size: u32) { info!("Reading..."); let mut buf = [0u8; 32]; - unwrap!(f.read(offset, &mut buf)); + unwrap!(f.blocking_read(offset, &mut buf)); info!("Read: {=[u8]:x}", buf); info!("Erasing..."); @@ -39,7 +39,7 @@ fn test_flash(f: &mut Flash<'_, Blocking>, offset: u32, size: u32) { info!("Reading..."); let mut buf = [0u8; 32]; - unwrap!(f.read(offset, &mut buf)); + unwrap!(f.blocking_read(offset, &mut buf)); info!("Read after erase: {=[u8]:x}", buf); info!("Writing..."); @@ -53,7 +53,7 @@ fn test_flash(f: &mut Flash<'_, Blocking>, offset: u32, size: u32) { info!("Reading..."); let mut buf = [0u8; 32]; - unwrap!(f.read(offset, &mut buf)); + unwrap!(f.blocking_read(offset, &mut buf)); info!("Read: {=[u8]:x}", buf); assert_eq!( &buf[..], diff --git a/examples/stm32f4/src/bin/flash_async.rs b/examples/stm32f4/src/bin/flash_async.rs index f0a65a725..1624d842e 100644 --- a/examples/stm32f4/src/bin/flash_async.rs +++ b/examples/stm32f4/src/bin/flash_async.rs @@ -48,7 +48,7 @@ async fn test_flash<'a>(f: &mut Flash<'a>, offset: u32, size: u32) { info!("Reading..."); let mut buf = [0u8; 32]; - unwrap!(f.read(offset, &mut buf)); + unwrap!(f.blocking_read(offset, &mut buf)); info!("Read: {=[u8]:x}", buf); info!("Erasing..."); @@ -56,7 +56,7 @@ async fn test_flash<'a>(f: &mut Flash<'a>, offset: u32, size: u32) { info!("Reading..."); let mut buf = [0u8; 32]; - unwrap!(f.read(offset, &mut buf)); + unwrap!(f.blocking_read(offset, &mut buf)); info!("Read after erase: {=[u8]:x}", buf); info!("Writing..."); @@ -73,7 +73,7 @@ async fn test_flash<'a>(f: &mut Flash<'a>, offset: u32, size: u32) { info!("Reading..."); let mut buf = [0u8; 32]; - unwrap!(f.read(offset, &mut buf)); + unwrap!(f.blocking_read(offset, &mut buf)); info!("Read: {=[u8]:x}", buf); assert_eq!( &buf[..], From 2a542bc1437dcaa62914b82ae496b1e19e8fee91 Mon Sep 17 00:00:00 2001 From: Ulf Lilleengen Date: Mon, 18 Dec 2023 13:58:12 +0100 Subject: [PATCH 043/124] feat: support multiwrite flash traits if configured --- embassy-nrf/Cargo.toml | 5 +++++ embassy-nrf/src/qspi.rs | 3 +++ 2 files changed, 8 insertions(+) diff --git a/embassy-nrf/Cargo.toml b/embassy-nrf/Cargo.toml index 6d7440519..970f62b0c 100644 --- a/embassy-nrf/Cargo.toml +++ b/embassy-nrf/Cargo.toml @@ -64,6 +64,11 @@ nfc-pins-as-gpio = [] # nrf52820, nrf52833, nrf52840: P0_18 reset-pin-as-gpio = [] +# Implements the MultiwriteNorFlash trait for QSPI. Should only be enabled if your external +# flash supports the semantics described in +# https://docs.rs/embedded-storage/0.3.1/embedded_storage/nor_flash/trait.MultiwriteNorFlash.html +qspi-multiwrite-flash = [] + # Features starting with `_` are for internal use only. They're not intended # to be enabled by other crates, and are not covered by semver guarantees. diff --git a/embassy-nrf/src/qspi.rs b/embassy-nrf/src/qspi.rs index 5e1a4e842..f35b83628 100755 --- a/embassy-nrf/src/qspi.rs +++ b/embassy-nrf/src/qspi.rs @@ -605,6 +605,9 @@ impl<'d, T: Instance> NorFlash for Qspi<'d, T> { } } +#[cfg(feature = "qspi-multiwrite-flash")] +impl<'d, T: Instance> embedded_storage::nor_flash::MultiwriteNorFlash for Qspi<'d, T> {} + mod _eh1 { use embedded_storage_async::nor_flash::{NorFlash as AsyncNorFlash, ReadNorFlash as AsyncReadNorFlash}; From 7044e53af45e472d52d6e523bddf5632f0375487 Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Mon, 18 Dec 2023 18:24:55 +0100 Subject: [PATCH 044/124] stm32/i2c: remove _timeout public API, share more code between v1/v2. --- embassy-stm32/src/i2c/mod.rs | 164 +++++++++++- embassy-stm32/src/i2c/v1.rs | 145 +++-------- embassy-stm32/src/i2c/v2.rs | 470 +++++++---------------------------- 3 files changed, 268 insertions(+), 511 deletions(-) diff --git a/embassy-stm32/src/i2c/mod.rs b/embassy-stm32/src/i2c/mod.rs index a8dc8e0e5..0af291e9c 100644 --- a/embassy-stm32/src/i2c/mod.rs +++ b/embassy-stm32/src/i2c/mod.rs @@ -1,17 +1,23 @@ #![macro_use] -use core::marker::PhantomData; - -use crate::dma::NoDma; -use crate::interrupt; - #[cfg_attr(i2c_v1, path = "v1.rs")] #[cfg_attr(i2c_v2, path = "v2.rs")] mod _version; -pub use _version::*; -use embassy_sync::waitqueue::AtomicWaker; -use crate::peripherals; +use core::future::Future; +use core::marker::PhantomData; + +use embassy_hal_internal::{into_ref, Peripheral, PeripheralRef}; +use embassy_sync::waitqueue::AtomicWaker; +#[cfg(feature = "time")] +use embassy_time::{Duration, Instant}; + +use crate::dma::NoDma; +use crate::gpio::sealed::AFType; +use crate::gpio::Pull; +use crate::interrupt::typelevel::Interrupt; +use crate::time::Hertz; +use crate::{interrupt, peripherals}; /// I2C error. #[derive(Debug, PartialEq, Eq)] @@ -33,6 +39,148 @@ pub enum Error { ZeroLengthTransfer, } +/// I2C config +#[non_exhaustive] +#[derive(Copy, Clone)] +pub struct Config { + /// Enable internal pullup on SDA. + /// + /// Using external pullup resistors is recommended for I2C. If you do + /// have external pullups you should not enable this. + pub sda_pullup: bool, + /// Enable internal pullup on SCL. + /// + /// Using external pullup resistors is recommended for I2C. If you do + /// have external pullups you should not enable this. + pub scl_pullup: bool, + /// Timeout. + #[cfg(feature = "time")] + pub timeout: embassy_time::Duration, +} + +impl Default for Config { + fn default() -> Self { + Self { + sda_pullup: false, + scl_pullup: false, + #[cfg(feature = "time")] + timeout: embassy_time::Duration::from_millis(1000), + } + } +} + +/// I2C driver. +pub struct I2c<'d, T: Instance, TXDMA = NoDma, RXDMA = NoDma> { + _peri: PeripheralRef<'d, T>, + #[allow(dead_code)] + tx_dma: PeripheralRef<'d, TXDMA>, + #[allow(dead_code)] + rx_dma: PeripheralRef<'d, RXDMA>, + #[cfg(feature = "time")] + timeout: Duration, +} + +impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> { + /// Create a new I2C driver. + pub fn new( + peri: impl Peripheral

+ 'd, + scl: impl Peripheral

> + 'd, + sda: impl Peripheral

> + 'd, + _irq: impl interrupt::typelevel::Binding> + + interrupt::typelevel::Binding> + + 'd, + tx_dma: impl Peripheral

+ 'd, + rx_dma: impl Peripheral

+ 'd, + freq: Hertz, + config: Config, + ) -> Self { + into_ref!(peri, scl, sda, tx_dma, rx_dma); + + T::enable_and_reset(); + + scl.set_as_af_pull( + scl.af_num(), + AFType::OutputOpenDrain, + match config.scl_pullup { + true => Pull::Up, + false => Pull::None, + }, + ); + sda.set_as_af_pull( + sda.af_num(), + AFType::OutputOpenDrain, + match config.sda_pullup { + true => Pull::Up, + false => Pull::None, + }, + ); + + unsafe { T::EventInterrupt::enable() }; + unsafe { T::ErrorInterrupt::enable() }; + + let mut this = Self { + _peri: peri, + tx_dma, + rx_dma, + #[cfg(feature = "time")] + timeout: config.timeout, + }; + + this.init(freq, config); + + this + } + + fn timeout(&self) -> Timeout { + Timeout { + #[cfg(feature = "time")] + deadline: Instant::now() + self.timeout, + } + } +} + +#[derive(Copy, Clone)] +struct Timeout { + #[cfg(feature = "time")] + deadline: Instant, +} + +#[allow(dead_code)] +impl Timeout { + #[cfg(not(feature = "time"))] + #[inline] + fn check(self) -> Result<(), Error> { + Ok(()) + } + + #[cfg(feature = "time")] + #[inline] + fn check(self) -> Result<(), Error> { + if Instant::now() > self.deadline { + Err(Error::Timeout) + } else { + Ok(()) + } + } + + #[cfg(not(feature = "time"))] + #[inline] + fn with(self, fut: impl Future>) -> impl Future> { + fut + } + + #[cfg(feature = "time")] + #[inline] + fn with(self, fut: impl Future>) -> impl Future> { + use futures::FutureExt; + + embassy_futures::select::select(embassy_time::Timer::at(self.deadline), fut).map(|r| match r { + embassy_futures::select::Either::First(_) => Err(Error::Timeout), + embassy_futures::select::Either::Second(r) => r, + }) + } +} + pub(crate) mod sealed { use super::*; diff --git a/embassy-stm32/src/i2c/v1.rs b/embassy-stm32/src/i2c/v1.rs index b62ee8246..84802d129 100644 --- a/embassy-stm32/src/i2c/v1.rs +++ b/embassy-stm32/src/i2c/v1.rs @@ -1,20 +1,14 @@ use core::future::poll_fn; -use core::marker::PhantomData; use core::task::Poll; use embassy_embedded_hal::SetConfig; use embassy_futures::select::{select, Either}; use embassy_hal_internal::drop::OnDrop; -use embassy_hal_internal::{into_ref, PeripheralRef}; use super::*; -use crate::dma::{NoDma, Transfer}; -use crate::gpio::sealed::AFType; -use crate::gpio::Pull; -use crate::interrupt::typelevel::Interrupt; +use crate::dma::Transfer; use crate::pac::i2c; use crate::time::Hertz; -use crate::{interrupt, Peripheral}; pub unsafe fn on_interrupt() { let regs = T::regs(); @@ -30,55 +24,8 @@ pub unsafe fn on_interrupt() { }); } -#[non_exhaustive] -#[derive(Copy, Clone, Default)] -pub struct Config { - pub sda_pullup: bool, - pub scl_pullup: bool, -} - -pub struct I2c<'d, T: Instance, TXDMA = NoDma, RXDMA = NoDma> { - phantom: PhantomData<&'d mut T>, - #[allow(dead_code)] - tx_dma: PeripheralRef<'d, TXDMA>, - #[allow(dead_code)] - rx_dma: PeripheralRef<'d, RXDMA>, -} - impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> { - pub fn new( - _peri: impl Peripheral

+ 'd, - scl: impl Peripheral

> + 'd, - sda: impl Peripheral

> + 'd, - _irq: impl interrupt::typelevel::Binding> - + interrupt::typelevel::Binding> - + 'd, - tx_dma: impl Peripheral

+ 'd, - rx_dma: impl Peripheral

+ 'd, - freq: Hertz, - config: Config, - ) -> Self { - into_ref!(scl, sda, tx_dma, rx_dma); - - T::enable_and_reset(); - - scl.set_as_af_pull( - scl.af_num(), - AFType::OutputOpenDrain, - match config.scl_pullup { - true => Pull::Up, - false => Pull::None, - }, - ); - sda.set_as_af_pull( - sda.af_num(), - AFType::OutputOpenDrain, - match config.sda_pullup { - true => Pull::Up, - false => Pull::None, - }, - ); - + pub(crate) fn init(&mut self, freq: Hertz, _config: Config) { T::regs().cr1().modify(|reg| { reg.set_pe(false); //reg.set_anfoff(false); @@ -101,15 +48,6 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> { T::regs().cr1().modify(|reg| { reg.set_pe(true); }); - - unsafe { T::EventInterrupt::enable() }; - unsafe { T::ErrorInterrupt::enable() }; - - Self { - phantom: PhantomData, - tx_dma, - rx_dma, - } } fn check_and_clear_error_flags() -> Result { @@ -169,12 +107,7 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> { Ok(sr1) } - fn write_bytes( - &mut self, - addr: u8, - bytes: &[u8], - check_timeout: impl Fn() -> Result<(), Error>, - ) -> Result<(), Error> { + fn write_bytes(&mut self, addr: u8, bytes: &[u8], timeout: Timeout) -> Result<(), Error> { // Send a START condition T::regs().cr1().modify(|reg| { @@ -183,7 +116,7 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> { // Wait until START condition was generated while !Self::check_and_clear_error_flags()?.start() { - check_timeout()?; + timeout.check()?; } // Also wait until signalled we're master and everything is waiting for us @@ -193,7 +126,7 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> { let sr2 = T::regs().sr2().read(); !sr2.msl() && !sr2.busy() } { - check_timeout()?; + timeout.check()?; } // Set up current address, we're trying to talk to @@ -203,7 +136,7 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> { // Wait for the address to be acknowledged // Check for any I2C errors. If a NACK occurs, the ADDR bit will never be set. while !Self::check_and_clear_error_flags()?.addr() { - check_timeout()?; + timeout.check()?; } // Clear condition by reading SR2 @@ -211,20 +144,20 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> { // Send bytes for c in bytes { - self.send_byte(*c, &check_timeout)?; + self.send_byte(*c, timeout)?; } // Fallthrough is success Ok(()) } - fn send_byte(&self, byte: u8, check_timeout: impl Fn() -> Result<(), Error>) -> Result<(), Error> { + fn send_byte(&self, byte: u8, timeout: Timeout) -> Result<(), Error> { // Wait until we're ready for sending while { // Check for any I2C errors. If a NACK occurs, the ADDR bit will never be set. !Self::check_and_clear_error_flags()?.txe() } { - check_timeout()?; + timeout.check()?; } // Push out a byte of data @@ -235,32 +168,27 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> { // Check for any potential error conditions. !Self::check_and_clear_error_flags()?.btf() } { - check_timeout()?; + timeout.check()?; } Ok(()) } - fn recv_byte(&self, check_timeout: impl Fn() -> Result<(), Error>) -> Result { + fn recv_byte(&self, timeout: Timeout) -> Result { while { // Check for any potential error conditions. Self::check_and_clear_error_flags()?; !T::regs().sr1().read().rxne() } { - check_timeout()?; + timeout.check()?; } let value = T::regs().dr().read().dr(); Ok(value) } - pub fn blocking_read_timeout( - &mut self, - addr: u8, - buffer: &mut [u8], - check_timeout: impl Fn() -> Result<(), Error>, - ) -> Result<(), Error> { + fn blocking_read_timeout(&mut self, addr: u8, buffer: &mut [u8], timeout: Timeout) -> Result<(), Error> { if let Some((last, buffer)) = buffer.split_last_mut() { // Send a START condition and set ACK bit T::regs().cr1().modify(|reg| { @@ -270,7 +198,7 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> { // Wait until START condition was generated while !Self::check_and_clear_error_flags()?.start() { - check_timeout()?; + timeout.check()?; } // Also wait until signalled we're master and everything is waiting for us @@ -278,7 +206,7 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> { let sr2 = T::regs().sr2().read(); !sr2.msl() && !sr2.busy() } { - check_timeout()?; + timeout.check()?; } // Set up current address, we're trying to talk to @@ -287,7 +215,7 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> { // Wait until address was sent // Wait for the address to be acknowledged while !Self::check_and_clear_error_flags()?.addr() { - check_timeout()?; + timeout.check()?; } // Clear condition by reading SR2 @@ -295,7 +223,7 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> { // Receive bytes into buffer for c in buffer { - *c = self.recv_byte(&check_timeout)?; + *c = self.recv_byte(timeout)?; } // Prepare to send NACK then STOP after next byte @@ -305,11 +233,11 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> { }); // Receive last byte - *last = self.recv_byte(&check_timeout)?; + *last = self.recv_byte(timeout)?; // Wait for the STOP to be sent. while T::regs().cr1().read().stop() { - check_timeout()?; + timeout.check()?; } // Fallthrough is success @@ -320,48 +248,33 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> { } pub fn blocking_read(&mut self, addr: u8, read: &mut [u8]) -> Result<(), Error> { - self.blocking_read_timeout(addr, read, || Ok(())) + self.blocking_read_timeout(addr, read, self.timeout()) } - pub fn blocking_write_timeout( - &mut self, - addr: u8, - write: &[u8], - check_timeout: impl Fn() -> Result<(), Error>, - ) -> Result<(), Error> { - self.write_bytes(addr, write, &check_timeout)?; + pub fn blocking_write(&mut self, addr: u8, write: &[u8]) -> Result<(), Error> { + let timeout = self.timeout(); + + self.write_bytes(addr, write, timeout)?; // Send a STOP condition T::regs().cr1().modify(|reg| reg.set_stop(true)); // Wait for STOP condition to transmit. while T::regs().cr1().read().stop() { - check_timeout()?; + timeout.check()?; } // Fallthrough is success Ok(()) } - pub fn blocking_write(&mut self, addr: u8, write: &[u8]) -> Result<(), Error> { - self.blocking_write_timeout(addr, write, || Ok(())) - } + pub fn blocking_write_read(&mut self, addr: u8, write: &[u8], read: &mut [u8]) -> Result<(), Error> { + let timeout = self.timeout(); - pub fn blocking_write_read_timeout( - &mut self, - addr: u8, - write: &[u8], - read: &mut [u8], - check_timeout: impl Fn() -> Result<(), Error>, - ) -> Result<(), Error> { - self.write_bytes(addr, write, &check_timeout)?; - self.blocking_read_timeout(addr, read, &check_timeout)?; + self.write_bytes(addr, write, timeout)?; + self.blocking_read_timeout(addr, read, timeout)?; Ok(()) } - pub fn blocking_write_read(&mut self, addr: u8, write: &[u8], read: &mut [u8]) -> Result<(), Error> { - self.blocking_write_read_timeout(addr, write, read, || Ok(())) - } - // Async #[inline] // pretty sure this should always be inlined diff --git a/embassy-stm32/src/i2c/v2.rs b/embassy-stm32/src/i2c/v2.rs index 8c20e1c54..bd3abaac1 100644 --- a/embassy-stm32/src/i2c/v2.rs +++ b/embassy-stm32/src/i2c/v2.rs @@ -4,37 +4,13 @@ use core::task::Poll; use embassy_embedded_hal::SetConfig; use embassy_hal_internal::drop::OnDrop; -use embassy_hal_internal::{into_ref, PeripheralRef}; -#[cfg(feature = "time")] -use embassy_time::{Duration, Instant}; use super::*; -use crate::dma::{NoDma, Transfer}; -use crate::gpio::sealed::AFType; -use crate::gpio::Pull; -use crate::interrupt::typelevel::Interrupt; +use crate::dma::Transfer; use crate::pac::i2c; use crate::time::Hertz; -use crate::{interrupt, Peripheral}; -#[cfg(feature = "time")] -fn timeout_fn(timeout: Duration) -> impl Fn() -> Result<(), Error> { - let deadline = Instant::now() + timeout; - move || { - if Instant::now() > deadline { - Err(Error::Timeout) - } else { - Ok(()) - } - } -} - -#[cfg(not(feature = "time"))] -pub fn no_timeout_fn() -> impl Fn() -> Result<(), Error> { - move || Ok(()) -} - -pub unsafe fn on_interrupt() { +pub(crate) unsafe fn on_interrupt() { let regs = T::regs(); let isr = regs.isr().read(); @@ -48,70 +24,8 @@ pub unsafe fn on_interrupt() { }); } -#[non_exhaustive] -#[derive(Copy, Clone)] -pub struct Config { - pub sda_pullup: bool, - pub scl_pullup: bool, - #[cfg(feature = "time")] - pub transaction_timeout: Duration, -} - -impl Default for Config { - fn default() -> Self { - Self { - sda_pullup: false, - scl_pullup: false, - #[cfg(feature = "time")] - transaction_timeout: Duration::from_millis(100), - } - } -} - -pub struct I2c<'d, T: Instance, TXDMA = NoDma, RXDMA = NoDma> { - _peri: PeripheralRef<'d, T>, - #[allow(dead_code)] - tx_dma: PeripheralRef<'d, TXDMA>, - #[allow(dead_code)] - rx_dma: PeripheralRef<'d, RXDMA>, - #[cfg(feature = "time")] - timeout: Duration, -} - impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> { - pub fn new( - peri: impl Peripheral

+ 'd, - scl: impl Peripheral

> + 'd, - sda: impl Peripheral

> + 'd, - _irq: impl interrupt::typelevel::Binding> - + interrupt::typelevel::Binding> - + 'd, - tx_dma: impl Peripheral

+ 'd, - rx_dma: impl Peripheral

+ 'd, - freq: Hertz, - config: Config, - ) -> Self { - into_ref!(peri, scl, sda, tx_dma, rx_dma); - - T::enable_and_reset(); - - scl.set_as_af_pull( - scl.af_num(), - AFType::OutputOpenDrain, - match config.scl_pullup { - true => Pull::Up, - false => Pull::None, - }, - ); - sda.set_as_af_pull( - sda.af_num(), - AFType::OutputOpenDrain, - match config.sda_pullup { - true => Pull::Up, - false => Pull::None, - }, - ); - + pub(crate) fn init(&mut self, freq: Hertz, _config: Config) { T::regs().cr1().modify(|reg| { reg.set_pe(false); reg.set_anfoff(false); @@ -130,17 +44,6 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> { T::regs().cr1().modify(|reg| { reg.set_pe(true); }); - - unsafe { T::EventInterrupt::enable() }; - unsafe { T::ErrorInterrupt::enable() }; - - Self { - _peri: peri, - tx_dma, - rx_dma, - #[cfg(feature = "time")] - timeout: config.transaction_timeout, - } } fn master_stop(&mut self) { @@ -153,7 +56,7 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> { stop: Stop, reload: bool, restart: bool, - check_timeout: impl Fn() -> Result<(), Error>, + timeout: Timeout, ) -> Result<(), Error> { assert!(length < 256); @@ -162,7 +65,7 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> { // automatically. This could be up to 50% of a bus // cycle (ie. up to 0.5/freq) while T::regs().cr2().read().start() { - check_timeout()?; + timeout.check()?; } } @@ -189,20 +92,14 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> { Ok(()) } - fn master_write( - address: u8, - length: usize, - stop: Stop, - reload: bool, - check_timeout: impl Fn() -> Result<(), Error>, - ) -> Result<(), Error> { + fn master_write(address: u8, length: usize, stop: Stop, reload: bool, timeout: Timeout) -> Result<(), Error> { assert!(length < 256); // Wait for any previous address sequence to end // automatically. This could be up to 50% of a bus // cycle (ie. up to 0.5/freq) while T::regs().cr2().read().start() { - check_timeout()?; + timeout.check()?; } let reload = if reload { @@ -227,15 +124,11 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> { Ok(()) } - fn master_continue( - length: usize, - reload: bool, - check_timeout: impl Fn() -> Result<(), Error>, - ) -> Result<(), Error> { + fn master_continue(length: usize, reload: bool, timeout: Timeout) -> Result<(), Error> { assert!(length < 256 && length > 0); while !T::regs().isr().read().tcr() { - check_timeout()?; + timeout.check()?; } let reload = if reload { @@ -261,7 +154,7 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> { } } - fn wait_txe(&self, check_timeout: impl Fn() -> Result<(), Error>) -> Result<(), Error> { + fn wait_txe(&self, timeout: Timeout) -> Result<(), Error> { loop { let isr = T::regs().isr().read(); if isr.txe() { @@ -278,11 +171,11 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> { return Err(Error::Nack); } - check_timeout()?; + timeout.check()?; } } - fn wait_rxne(&self, check_timeout: impl Fn() -> Result<(), Error>) -> Result<(), Error> { + fn wait_rxne(&self, timeout: Timeout) -> Result<(), Error> { loop { let isr = T::regs().isr().read(); if isr.rxne() { @@ -299,11 +192,11 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> { return Err(Error::Nack); } - check_timeout()?; + timeout.check()?; } } - fn wait_tc(&self, check_timeout: impl Fn() -> Result<(), Error>) -> Result<(), Error> { + fn wait_tc(&self, timeout: Timeout) -> Result<(), Error> { loop { let isr = T::regs().isr().read(); if isr.tc() { @@ -320,17 +213,11 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> { return Err(Error::Nack); } - check_timeout()?; + timeout.check()?; } } - fn read_internal( - &mut self, - address: u8, - read: &mut [u8], - restart: bool, - check_timeout: impl Fn() -> Result<(), Error>, - ) -> Result<(), Error> { + fn read_internal(&mut self, address: u8, read: &mut [u8], restart: bool, timeout: Timeout) -> Result<(), Error> { let completed_chunks = read.len() / 255; let total_chunks = if completed_chunks * 255 == read.len() { completed_chunks @@ -345,17 +232,17 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> { Stop::Automatic, last_chunk_idx != 0, restart, - &check_timeout, + timeout, )?; for (number, chunk) in read.chunks_mut(255).enumerate() { if number != 0 { - Self::master_continue(chunk.len(), number != last_chunk_idx, &check_timeout)?; + Self::master_continue(chunk.len(), number != last_chunk_idx, timeout)?; } for byte in chunk { // Wait until we have received something - self.wait_rxne(&check_timeout)?; + self.wait_rxne(timeout)?; *byte = T::regs().rxdr().read().rxdata(); } @@ -363,13 +250,7 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> { Ok(()) } - fn write_internal( - &mut self, - address: u8, - write: &[u8], - send_stop: bool, - check_timeout: impl Fn() -> Result<(), Error>, - ) -> Result<(), Error> { + fn write_internal(&mut self, address: u8, write: &[u8], send_stop: bool, timeout: Timeout) -> Result<(), Error> { let completed_chunks = write.len() / 255; let total_chunks = if completed_chunks * 255 == write.len() { completed_chunks @@ -386,7 +267,7 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> { write.len().min(255), Stop::Software, last_chunk_idx != 0, - &check_timeout, + timeout, ) { if send_stop { self.master_stop(); @@ -396,14 +277,14 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> { for (number, chunk) in write.chunks(255).enumerate() { if number != 0 { - Self::master_continue(chunk.len(), number != last_chunk_idx, &check_timeout)?; + Self::master_continue(chunk.len(), number != last_chunk_idx, timeout)?; } for byte in chunk { // Wait until we are allowed to send data // (START has been ACKed or last byte when // through) - if let Err(err) = self.wait_txe(&check_timeout) { + if let Err(err) = self.wait_txe(timeout) { if send_stop { self.master_stop(); } @@ -414,7 +295,7 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> { } } // Wait until the write finishes - let result = self.wait_tc(&check_timeout); + let result = self.wait_tc(timeout); if send_stop { self.master_stop(); } @@ -427,7 +308,7 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> { write: &[u8], first_slice: bool, last_slice: bool, - check_timeout: impl Fn() -> Result<(), Error>, + timeout: Timeout, ) -> Result<(), Error> where TXDMA: crate::i2c::TxDma, @@ -473,10 +354,10 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> { total_len.min(255), Stop::Software, (total_len > 255) || !last_slice, - &check_timeout, + timeout, )?; } else { - Self::master_continue(total_len.min(255), (total_len > 255) || !last_slice, &check_timeout)?; + Self::master_continue(total_len.min(255), (total_len > 255) || !last_slice, timeout)?; T::regs().cr1().modify(|w| w.set_tcie(true)); } } else if !(isr.tcr() || isr.tc()) { @@ -487,7 +368,7 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> { } else { let last_piece = (remaining_len <= 255) && last_slice; - if let Err(e) = Self::master_continue(remaining_len.min(255), !last_piece, &check_timeout) { + if let Err(e) = Self::master_continue(remaining_len.min(255), !last_piece, timeout) { return Poll::Ready(Err(e)); } T::regs().cr1().modify(|w| w.set_tcie(true)); @@ -502,7 +383,7 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> { if last_slice { // This should be done already - self.wait_tc(&check_timeout)?; + self.wait_tc(timeout)?; self.master_stop(); } @@ -516,7 +397,7 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> { address: u8, buffer: &mut [u8], restart: bool, - check_timeout: impl Fn() -> Result<(), Error>, + timeout: Timeout, ) -> Result<(), Error> where RXDMA: crate::i2c::RxDma, @@ -558,7 +439,7 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> { Stop::Software, total_len > 255, restart, - &check_timeout, + timeout, )?; } else if !(isr.tcr() || isr.tc()) { // poll_fn was woken without an interrupt present @@ -568,7 +449,7 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> { } else { let last_piece = remaining_len <= 255; - if let Err(e) = Self::master_continue(remaining_len.min(255), !last_piece, &check_timeout) { + if let Err(e) = Self::master_continue(remaining_len.min(255), !last_piece, timeout) { return Poll::Ready(Err(e)); } T::regs().cr1().modify(|w| w.set_tcie(true)); @@ -582,7 +463,7 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> { dma_transfer.await; // This should be done already - self.wait_tc(&check_timeout)?; + self.wait_tc(timeout)?; self.master_stop(); drop(on_drop); @@ -592,41 +473,31 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> { // ========================= // Async public API - #[cfg(feature = "time")] - pub async fn write(&mut self, address: u8, write: &[u8]) -> Result<(), Error> - where - TXDMA: crate::i2c::TxDma, - { - if write.is_empty() { - self.write_internal(address, write, true, timeout_fn(self.timeout)) - } else { - embassy_time::with_timeout( - self.timeout, - self.write_dma_internal(address, write, true, true, timeout_fn(self.timeout)), - ) - .await - .unwrap_or(Err(Error::Timeout)) - } - } - #[cfg(not(feature = "time"))] + /// Write. pub async fn write(&mut self, address: u8, write: &[u8]) -> Result<(), Error> where TXDMA: crate::i2c::TxDma, { + let timeout = self.timeout(); if write.is_empty() { - self.write_internal(address, write, true, no_timeout_fn()) + self.write_internal(address, write, true, timeout) } else { - self.write_dma_internal(address, write, true, true, no_timeout_fn()) + timeout + .with(self.write_dma_internal(address, write, true, true, timeout)) .await } } - #[cfg(feature = "time")] + /// Write multiple buffers. + /// + /// The buffers are concatenated in a single write transaction. pub async fn write_vectored(&mut self, address: u8, write: &[&[u8]]) -> Result<(), Error> where TXDMA: crate::i2c::TxDma, { + let timeout = self.timeout(); + if write.is_empty() { return Err(Error::ZeroLengthTransfer); } @@ -638,123 +509,49 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> { let next = iter.next(); let is_last = next.is_none(); - embassy_time::with_timeout( - self.timeout, - self.write_dma_internal(address, c, first, is_last, timeout_fn(self.timeout)), - ) - .await - .unwrap_or(Err(Error::Timeout))?; + let fut = self.write_dma_internal(address, c, first, is_last, timeout); + timeout.with(fut).await?; first = false; current = next; } Ok(()) } - #[cfg(not(feature = "time"))] - pub async fn write_vectored(&mut self, address: u8, write: &[&[u8]]) -> Result<(), Error> - where - TXDMA: crate::i2c::TxDma, - { - if write.is_empty() { - return Err(Error::ZeroLengthTransfer); - } - let mut iter = write.iter(); - - let mut first = true; - let mut current = iter.next(); - while let Some(c) = current { - let next = iter.next(); - let is_last = next.is_none(); - - self.write_dma_internal(address, c, first, is_last, no_timeout_fn()) - .await?; - first = false; - current = next; - } - Ok(()) - } - - #[cfg(feature = "time")] + /// Read. pub async fn read(&mut self, address: u8, buffer: &mut [u8]) -> Result<(), Error> where RXDMA: crate::i2c::RxDma, { + let timeout = self.timeout(); + if buffer.is_empty() { - self.read_internal(address, buffer, false, timeout_fn(self.timeout)) + self.read_internal(address, buffer, false, timeout) } else { - embassy_time::with_timeout( - self.timeout, - self.read_dma_internal(address, buffer, false, timeout_fn(self.timeout)), - ) - .await - .unwrap_or(Err(Error::Timeout)) + let fut = self.read_dma_internal(address, buffer, false, timeout); + timeout.with(fut).await } } - #[cfg(not(feature = "time"))] - pub async fn read(&mut self, address: u8, buffer: &mut [u8]) -> Result<(), Error> - where - RXDMA: crate::i2c::RxDma, - { - if buffer.is_empty() { - self.read_internal(address, buffer, false, no_timeout_fn()) - } else { - self.read_dma_internal(address, buffer, false, no_timeout_fn()).await - } - } - - #[cfg(feature = "time")] + /// Write, restart, read. pub async fn write_read(&mut self, address: u8, write: &[u8], read: &mut [u8]) -> Result<(), Error> where TXDMA: super::TxDma, RXDMA: super::RxDma, { - let start_instant = Instant::now(); - let check_timeout = timeout_fn(self.timeout); + let timeout = self.timeout(); + if write.is_empty() { - self.write_internal(address, write, false, &check_timeout)?; + self.write_internal(address, write, false, timeout)?; } else { - embassy_time::with_timeout( - self.timeout, - self.write_dma_internal(address, write, true, true, &check_timeout), - ) - .await - .unwrap_or(Err(Error::Timeout))?; - } - - let time_left_until_timeout = self.timeout - Instant::now().duration_since(start_instant); - - if read.is_empty() { - self.read_internal(address, read, true, &check_timeout)?; - } else { - embassy_time::with_timeout( - time_left_until_timeout, - self.read_dma_internal(address, read, true, &check_timeout), - ) - .await - .unwrap_or(Err(Error::Timeout))?; - } - - Ok(()) - } - - #[cfg(not(feature = "time"))] - pub async fn write_read(&mut self, address: u8, write: &[u8], read: &mut [u8]) -> Result<(), Error> - where - TXDMA: super::TxDma, - RXDMA: super::RxDma, - { - let no_timeout = no_timeout_fn(); - if write.is_empty() { - self.write_internal(address, write, false, &no_timeout)?; - } else { - self.write_dma_internal(address, write, true, true, &no_timeout).await?; + let fut = self.write_dma_internal(address, write, true, true, timeout); + timeout.with(fut).await?; } if read.is_empty() { - self.read_internal(address, read, true, &no_timeout)?; + self.read_internal(address, read, true, timeout)?; } else { - self.read_dma_internal(address, read, true, &no_timeout).await?; + let fut = self.read_dma_internal(address, read, true, timeout); + timeout.with(fut).await?; } Ok(()) @@ -763,105 +560,35 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> { // ========================= // Blocking public API - #[cfg(feature = "time")] - pub fn blocking_read_timeout(&mut self, address: u8, read: &mut [u8], timeout: Duration) -> Result<(), Error> { - self.read_internal(address, read, false, timeout_fn(timeout)) - // Automatic Stop - } - - #[cfg(not(feature = "time"))] - pub fn blocking_read_timeout( - &mut self, - address: u8, - read: &mut [u8], - check_timeout: impl Fn() -> Result<(), Error>, - ) -> Result<(), Error> { - self.read_internal(address, read, false, check_timeout) - // Automatic Stop - } - - #[cfg(feature = "time")] + /// Blocking read. pub fn blocking_read(&mut self, address: u8, read: &mut [u8]) -> Result<(), Error> { - self.blocking_read_timeout(address, read, self.timeout) - } - - #[cfg(not(feature = "time"))] - pub fn blocking_read(&mut self, address: u8, read: &mut [u8]) -> Result<(), Error> { - self.blocking_read_timeout(address, read, || Ok(())) - } - - #[cfg(feature = "time")] - pub fn blocking_write_timeout(&mut self, address: u8, write: &[u8], timeout: Duration) -> Result<(), Error> { - self.write_internal(address, write, true, timeout_fn(timeout)) - } - - #[cfg(not(feature = "time"))] - pub fn blocking_write_timeout( - &mut self, - address: u8, - write: &[u8], - check_timeout: impl Fn() -> Result<(), Error>, - ) -> Result<(), Error> { - self.write_internal(address, write, true, check_timeout) - } - - #[cfg(feature = "time")] - pub fn blocking_write(&mut self, address: u8, write: &[u8]) -> Result<(), Error> { - self.blocking_write_timeout(address, write, self.timeout) - } - - #[cfg(not(feature = "time"))] - pub fn blocking_write(&mut self, address: u8, write: &[u8]) -> Result<(), Error> { - self.blocking_write_timeout(address, write, || Ok(())) - } - - #[cfg(feature = "time")] - pub fn blocking_write_read_timeout( - &mut self, - address: u8, - write: &[u8], - read: &mut [u8], - timeout: Duration, - ) -> Result<(), Error> { - let check_timeout = timeout_fn(timeout); - self.write_internal(address, write, false, &check_timeout)?; - self.read_internal(address, read, true, &check_timeout) + self.read_internal(address, read, false, self.timeout()) // Automatic Stop } - #[cfg(not(feature = "time"))] - pub fn blocking_write_read_timeout( - &mut self, - address: u8, - write: &[u8], - read: &mut [u8], - check_timeout: impl Fn() -> Result<(), Error>, - ) -> Result<(), Error> { - self.write_internal(address, write, false, &check_timeout)?; - self.read_internal(address, read, true, &check_timeout) + /// Blocking write. + pub fn blocking_write(&mut self, address: u8, write: &[u8]) -> Result<(), Error> { + self.write_internal(address, write, true, self.timeout()) + } + + /// Blocking write, restart, read. + pub fn blocking_write_read(&mut self, address: u8, write: &[u8], read: &mut [u8]) -> Result<(), Error> { + let timeout = self.timeout(); + self.write_internal(address, write, false, timeout)?; + self.read_internal(address, read, true, timeout) // Automatic Stop } - #[cfg(feature = "time")] - pub fn blocking_write_read(&mut self, address: u8, write: &[u8], read: &mut [u8]) -> Result<(), Error> { - self.blocking_write_read_timeout(address, write, read, self.timeout) - } - - #[cfg(not(feature = "time"))] - pub fn blocking_write_read(&mut self, address: u8, write: &[u8], read: &mut [u8]) -> Result<(), Error> { - self.blocking_write_read_timeout(address, write, read, || Ok(())) - } - - fn blocking_write_vectored_with_timeout( - &mut self, - address: u8, - write: &[&[u8]], - check_timeout: impl Fn() -> Result<(), Error>, - ) -> Result<(), Error> { + /// Blocking write multiple buffers. + /// + /// The buffers are concatenated in a single write transaction. + pub fn blocking_write_vectored(&mut self, address: u8, write: &[&[u8]]) -> Result<(), Error> { if write.is_empty() { return Err(Error::ZeroLengthTransfer); } + let timeout = self.timeout(); + let first_length = write[0].len(); let last_slice_index = write.len() - 1; @@ -870,7 +597,7 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> { first_length.min(255), Stop::Software, (first_length > 255) || (last_slice_index != 0), - &check_timeout, + timeout, ) { self.master_stop(); return Err(err); @@ -890,7 +617,7 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> { if let Err(err) = Self::master_continue( slice_len.min(255), (idx != last_slice_index) || (slice_len > 255), - &check_timeout, + timeout, ) { self.master_stop(); return Err(err); @@ -902,7 +629,7 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> { if let Err(err) = Self::master_continue( chunk.len(), (number != last_chunk_idx) || (idx != last_slice_index), - &check_timeout, + timeout, ) { self.master_stop(); return Err(err); @@ -913,7 +640,7 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> { // Wait until we are allowed to send data // (START has been ACKed or last byte when // through) - if let Err(err) = self.wait_txe(&check_timeout) { + if let Err(err) = self.wait_txe(timeout) { self.master_stop(); return Err(err); } @@ -925,41 +652,10 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> { } } // Wait until the write finishes - let result = self.wait_tc(&check_timeout); + let result = self.wait_tc(timeout); self.master_stop(); result } - - #[cfg(feature = "time")] - pub fn blocking_write_vectored_timeout( - &mut self, - address: u8, - write: &[&[u8]], - timeout: Duration, - ) -> Result<(), Error> { - let check_timeout = timeout_fn(timeout); - self.blocking_write_vectored_with_timeout(address, write, check_timeout) - } - - #[cfg(not(feature = "time"))] - pub fn blocking_write_vectored_timeout( - &mut self, - address: u8, - write: &[&[u8]], - check_timeout: impl Fn() -> Result<(), Error>, - ) -> Result<(), Error> { - self.blocking_write_vectored_with_timeout(address, write, check_timeout) - } - - #[cfg(feature = "time")] - pub fn blocking_write_vectored(&mut self, address: u8, write: &[&[u8]]) -> Result<(), Error> { - self.blocking_write_vectored_timeout(address, write, self.timeout) - } - - #[cfg(not(feature = "time"))] - pub fn blocking_write_vectored(&mut self, address: u8, write: &[&[u8]]) -> Result<(), Error> { - self.blocking_write_vectored_timeout(address, write, || Ok(())) - } } impl<'d, T: Instance, TXDMA, RXDMA> Drop for I2c<'d, T, TXDMA, RXDMA> { From 2b497c1e578bd08166bee89de8ae824041fbbc70 Mon Sep 17 00:00:00 2001 From: James Munns Date: Mon, 18 Dec 2023 18:38:13 +0100 Subject: [PATCH 045/124] Fix nb on rp uart --- embassy-rp/src/uart/mod.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/embassy-rp/src/uart/mod.rs b/embassy-rp/src/uart/mod.rs index 18705b141..f82b9036b 100644 --- a/embassy-rp/src/uart/mod.rs +++ b/embassy-rp/src/uart/mod.rs @@ -820,6 +820,10 @@ impl<'d, T: Instance, M: Mode> embedded_hal_nb::serial::ErrorType for Uart<'d, T impl<'d, T: Instance, M: Mode> embedded_hal_nb::serial::Read for UartRx<'d, T, M> { fn read(&mut self) -> nb::Result { let r = T::regs(); + if r.uartfr().read().rxfe() { + return Err(nb::Error::WouldBlock); + } + let dr = r.uartdr().read(); if dr.oe() { @@ -830,10 +834,8 @@ impl<'d, T: Instance, M: Mode> embedded_hal_nb::serial::Read for UartRx<'d, T, M Err(nb::Error::Other(Error::Parity)) } else if dr.fe() { Err(nb::Error::Other(Error::Framing)) - } else if dr.fe() { - Ok(dr.data()) } else { - Err(nb::Error::WouldBlock) + Ok(dr.data()) } } } From 21fce1e19501171cfd3a5ddd32556961410bd024 Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Mon, 18 Dec 2023 18:43:01 +0100 Subject: [PATCH 046/124] stm32/can: cleanup interrupt traits. --- embassy-stm32/src/can/bxcan.rs | 52 +++++++--------------------------- 1 file changed, 10 insertions(+), 42 deletions(-) diff --git a/embassy-stm32/src/can/bxcan.rs b/embassy-stm32/src/can/bxcan.rs index 2f7417340..788360249 100644 --- a/embassy-stm32/src/can/bxcan.rs +++ b/embassy-stm32/src/can/bxcan.rs @@ -585,30 +585,18 @@ pub(crate) mod sealed { pub trait Instance { const REGISTERS: *mut bxcan::RegisterBlock; - fn regs() -> &'static crate::pac::can::Can; + fn regs() -> crate::pac::can::Can; fn state() -> &'static State; } } -pub trait TXInstance { +pub trait Instance: sealed::Instance + RccPeripheral + 'static { type TXInterrupt: crate::interrupt::typelevel::Interrupt; -} - -pub trait RX0Instance { type RX0Interrupt: crate::interrupt::typelevel::Interrupt; -} - -pub trait RX1Instance { type RX1Interrupt: crate::interrupt::typelevel::Interrupt; -} - -pub trait SCEInstance { type SCEInterrupt: crate::interrupt::typelevel::Interrupt; } -pub trait InterruptableInstance: TXInstance + RX0Instance + RX1Instance + SCEInstance {} -pub trait Instance: sealed::Instance + RccPeripheral + InterruptableInstance + 'static {} - pub struct BxcanInstance<'a, T>(PeripheralRef<'a, T>); unsafe impl<'d, T: Instance> bxcan::Instance for BxcanInstance<'d, T> { @@ -620,8 +608,8 @@ foreach_peripheral!( impl sealed::Instance for peripherals::$inst { const REGISTERS: *mut bxcan::RegisterBlock = crate::pac::$inst.as_ptr() as *mut _; - fn regs() -> &'static crate::pac::can::Can { - &crate::pac::$inst + fn regs() -> crate::pac::can::Can { + crate::pac::$inst } fn state() -> &'static sealed::State { @@ -630,32 +618,12 @@ foreach_peripheral!( } } - impl Instance for peripherals::$inst {} - - foreach_interrupt!( - ($inst,can,CAN,TX,$irq:ident) => { - impl TXInstance for peripherals::$inst { - type TXInterrupt = crate::interrupt::typelevel::$irq; - } - }; - ($inst,can,CAN,RX0,$irq:ident) => { - impl RX0Instance for peripherals::$inst { - type RX0Interrupt = crate::interrupt::typelevel::$irq; - } - }; - ($inst,can,CAN,RX1,$irq:ident) => { - impl RX1Instance for peripherals::$inst { - type RX1Interrupt = crate::interrupt::typelevel::$irq; - } - }; - ($inst,can,CAN,SCE,$irq:ident) => { - impl SCEInstance for peripherals::$inst { - type SCEInterrupt = crate::interrupt::typelevel::$irq; - } - }; - ); - - impl InterruptableInstance for peripherals::$inst {} + impl Instance for peripherals::$inst { + type TXInterrupt = crate::_generated::peripheral_interrupts::$inst::TX; + type RX0Interrupt = crate::_generated::peripheral_interrupts::$inst::RX0; + type RX1Interrupt = crate::_generated::peripheral_interrupts::$inst::RX1; + type SCEInterrupt = crate::_generated::peripheral_interrupts::$inst::SCE; + } }; ); From 87c8d9df94d222d772013fbb3f8ec60054cde039 Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Mon, 18 Dec 2023 18:44:41 +0100 Subject: [PATCH 047/124] stm32/can: docs. --- embassy-stm32/src/can/bxcan.rs | 45 +++++++++++++++++++++++++++++++--- 1 file changed, 41 insertions(+), 4 deletions(-) diff --git a/embassy-stm32/src/can/bxcan.rs b/embassy-stm32/src/can/bxcan.rs index 788360249..3c663b452 100644 --- a/embassy-stm32/src/can/bxcan.rs +++ b/embassy-stm32/src/can/bxcan.rs @@ -21,8 +21,10 @@ use crate::{interrupt, peripherals, Peripheral}; #[derive(Debug, Clone, PartialEq, Eq)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] pub struct Envelope { + /// Reception time. #[cfg(feature = "time")] pub ts: embassy_time::Instant, + /// The actual CAN frame. pub frame: bxcan::Frame, } @@ -43,6 +45,7 @@ impl interrupt::typelevel::Handler for TxInterruptH } } +/// RX0 interrupt handler. pub struct Rx0InterruptHandler { _phantom: PhantomData, } @@ -54,6 +57,7 @@ impl interrupt::typelevel::Handler for Rx0Interrup } } +/// RX1 interrupt handler. pub struct Rx1InterruptHandler { _phantom: PhantomData, } @@ -65,6 +69,7 @@ impl interrupt::typelevel::Handler for Rx1Interrup } } +/// SCE interrupt handler. pub struct SceInterruptHandler { _phantom: PhantomData, } @@ -82,10 +87,13 @@ impl interrupt::typelevel::Handler for SceInterrup } } +/// CAN driver pub struct Can<'d, T: Instance> { - pub can: bxcan::Can>, + can: bxcan::Can>, } +/// CAN bus error +#[allow(missing_docs)] #[derive(Debug)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] pub enum BusError { @@ -101,6 +109,7 @@ pub enum BusError { BusWarning, } +/// Error returned by `try_read` #[derive(Debug)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] pub enum TryReadError { @@ -110,6 +119,7 @@ pub enum TryReadError { Empty, } +/// Error returned by `try_write` #[derive(Debug)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] pub enum TryWriteError { @@ -177,6 +187,7 @@ impl<'d, T: Instance> Can<'d, T> { Self { can } } + /// Set CAN bit rate. pub fn set_bitrate(&mut self, bitrate: u32) { let bit_timing = Self::calc_bxcan_timings(T::frequency(), bitrate).unwrap(); self.can.modify_config().set_bit_timing(bit_timing).leave_disabled(); @@ -194,7 +205,9 @@ impl<'d, T: Instance> Can<'d, T> { } } - /// Queues the message to be sent but exerts backpressure + /// Queues the message to be sent. + /// + /// If the TX queue is full, this will wait until there is space, therefore exerting backpressure. pub async fn write(&mut self, frame: &Frame) -> bxcan::TransmitStatus { self.split().0.write(frame).await } @@ -221,12 +234,16 @@ impl<'d, T: Instance> Can<'d, T> { CanTx::::flush_all_inner().await } + /// Read a CAN frame. + /// + /// If no CAN frame is in the RX buffer, this will wait until there is one. + /// /// Returns a tuple of the time the message was received and the message frame pub async fn read(&mut self) -> Result { self.split().1.read().await } - /// Attempts to read a can frame without blocking. + /// Attempts to read a CAN frame without blocking. /// /// Returns [Err(TryReadError::Empty)] if there are no frames in the rx queue. pub fn try_read(&mut self) -> Result { @@ -288,7 +305,7 @@ impl<'d, T: Instance> Can<'d, T> { } } - pub const fn calc_bxcan_timings(periph_clock: Hertz, can_bitrate: u32) -> Option { + const fn calc_bxcan_timings(periph_clock: Hertz, can_bitrate: u32) -> Option { const BS1_MAX: u8 = 16; const BS2_MAX: u8 = 8; const MAX_SAMPLE_POINT_PERMILL: u16 = 900; @@ -379,21 +396,29 @@ impl<'d, T: Instance> Can<'d, T> { Some((sjw - 1) << 24 | (bs1 as u32 - 1) << 16 | (bs2 as u32 - 1) << 20 | (prescaler - 1)) } + /// Split the CAN driver into transmit and receive halves. + /// + /// Useful for doing separate transmit/receive tasks. pub fn split<'c>(&'c mut self) -> (CanTx<'c, 'd, T>, CanRx<'c, 'd, T>) { let (tx, rx0, rx1) = self.can.split_by_ref(); (CanTx { tx }, CanRx { rx0, rx1 }) } + /// Get mutable access to the lower-level driver from the `bxcan` crate. pub fn as_mut(&mut self) -> &mut bxcan::Can> { &mut self.can } } +/// CAN driver, transmit half. pub struct CanTx<'c, 'd, T: Instance> { tx: &'c mut bxcan::Tx>, } impl<'c, 'd, T: Instance> CanTx<'c, 'd, T> { + /// Queues the message to be sent. + /// + /// If the TX queue is full, this will wait until there is space, therefore exerting backpressure. pub async fn write(&mut self, frame: &Frame) -> bxcan::TransmitStatus { poll_fn(|cx| { T::state().tx_waker.register(cx.waker()); @@ -475,6 +500,7 @@ impl<'c, 'd, T: Instance> CanTx<'c, 'd, T> { } } +/// CAN driver, receive half. #[allow(dead_code)] pub struct CanRx<'c, 'd, T: Instance> { rx0: &'c mut bxcan::Rx0>, @@ -482,6 +508,11 @@ pub struct CanRx<'c, 'd, T: Instance> { } impl<'c, 'd, T: Instance> CanRx<'c, 'd, T> { + /// Read a CAN frame. + /// + /// If no CAN frame is in the RX buffer, this will wait until there is one. + /// + /// Returns a tuple of the time the message was received and the message frame pub async fn read(&mut self) -> Result { poll_fn(|cx| { T::state().err_waker.register(cx.waker()); @@ -590,13 +621,19 @@ pub(crate) mod sealed { } } +/// CAN instance trait. pub trait Instance: sealed::Instance + RccPeripheral + 'static { + /// TX interrupt for this instance. type TXInterrupt: crate::interrupt::typelevel::Interrupt; + /// RX0 interrupt for this instance. type RX0Interrupt: crate::interrupt::typelevel::Interrupt; + /// RX1 interrupt for this instance. type RX1Interrupt: crate::interrupt::typelevel::Interrupt; + /// SCE interrupt for this instance. type SCEInterrupt: crate::interrupt::typelevel::Interrupt; } +/// BXCAN instance newtype. pub struct BxcanInstance<'a, T>(PeripheralRef<'a, T>); unsafe impl<'d, T: Instance> bxcan::Instance for BxcanInstance<'d, T> { From 124478c5e9df16f0930d019c6f0db358666b3249 Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Mon, 18 Dec 2023 19:11:13 +0100 Subject: [PATCH 048/124] stm32: more docs. --- embassy-stm32/src/adc/mod.rs | 1 + embassy-stm32/src/crc/v1.rs | 4 +++ embassy-stm32/src/dma/mod.rs | 2 ++ embassy-stm32/src/eth/v1/mod.rs | 2 ++ embassy-stm32/src/flash/asynch.rs | 17 ++++++++++ embassy-stm32/src/flash/f4.rs | 2 +- embassy-stm32/src/fmc.rs | 4 +++ embassy-stm32/src/gpio.rs | 2 ++ embassy-stm32/src/i2c/v1.rs | 6 ++++ embassy-stm32/src/i2s.rs | 35 +++++++++++++++++--- embassy-stm32/src/rcc/mod.rs | 3 ++ embassy-stm32/src/rng.rs | 15 ++++++++- embassy-stm32/src/rtc/datetime.rs | 12 +++++-- embassy-stm32/src/rtc/mod.rs | 12 ++++--- embassy-stm32/src/timer/complementary_pwm.rs | 2 ++ embassy-stm32/src/timer/mod.rs | 3 ++ embassy-stm32/src/timer/qei.rs | 2 ++ embassy-stm32/src/timer/simple_pwm.rs | 2 ++ 18 files changed, 112 insertions(+), 14 deletions(-) diff --git a/embassy-stm32/src/adc/mod.rs b/embassy-stm32/src/adc/mod.rs index 2e470662d..ff523ca3b 100644 --- a/embassy-stm32/src/adc/mod.rs +++ b/embassy-stm32/src/adc/mod.rs @@ -1,5 +1,6 @@ //! Analog to Digital (ADC) converter driver. #![macro_use] +#![allow(missing_docs)] // TODO #[cfg(not(adc_f3_v2))] #[cfg_attr(adc_f1, path = "f1.rs")] diff --git a/embassy-stm32/src/crc/v1.rs b/embassy-stm32/src/crc/v1.rs index c0f580830..0166ab819 100644 --- a/embassy-stm32/src/crc/v1.rs +++ b/embassy-stm32/src/crc/v1.rs @@ -5,6 +5,7 @@ use crate::peripherals::CRC; use crate::rcc::sealed::RccPeripheral; use crate::Peripheral; +/// CRC driver. pub struct Crc<'d> { _peri: PeripheralRef<'d, CRC>, } @@ -34,6 +35,7 @@ impl<'d> Crc<'d> { PAC_CRC.dr().write_value(word); self.read() } + /// Feed a slice of words to the peripheral and return the result. pub fn feed_words(&mut self, words: &[u32]) -> u32 { for word in words { @@ -42,6 +44,8 @@ impl<'d> Crc<'d> { self.read() } + + /// Read the CRC result value. pub fn read(&self) -> u32 { PAC_CRC.dr().read() } diff --git a/embassy-stm32/src/dma/mod.rs b/embassy-stm32/src/dma/mod.rs index fb40a4b5e..38945ac33 100644 --- a/embassy-stm32/src/dma/mod.rs +++ b/embassy-stm32/src/dma/mod.rs @@ -1,3 +1,5 @@ +//! Direct Memory Access (DMA) + #[cfg(dma)] pub(crate) mod dma; #[cfg(dma)] diff --git a/embassy-stm32/src/eth/v1/mod.rs b/embassy-stm32/src/eth/v1/mod.rs index 13e53f687..2ce5b3927 100644 --- a/embassy-stm32/src/eth/v1/mod.rs +++ b/embassy-stm32/src/eth/v1/mod.rs @@ -43,6 +43,7 @@ impl interrupt::typelevel::Handler for InterruptHandl } } +/// Ethernet driver. pub struct Ethernet<'d, T: Instance, P: PHY> { _peri: PeripheralRef<'d, T>, pub(crate) tx: TDesRing<'d>, @@ -266,6 +267,7 @@ impl<'d, T: Instance, P: PHY> Ethernet<'d, T, P> { } } +/// Ethernet station management interface. pub struct EthernetStationManagement { peri: PhantomData, clock_range: Cr, diff --git a/embassy-stm32/src/flash/asynch.rs b/embassy-stm32/src/flash/asynch.rs index e3c6d4d67..97eaece81 100644 --- a/embassy-stm32/src/flash/asynch.rs +++ b/embassy-stm32/src/flash/asynch.rs @@ -17,6 +17,7 @@ use crate::{interrupt, Peripheral}; pub(super) static REGION_ACCESS: Mutex = Mutex::new(()); impl<'d> Flash<'d, Async> { + /// Create a new flash driver with async capabilities. pub fn new( p: impl Peripheral

+ 'd, _irq: impl interrupt::typelevel::Binding + 'd, @@ -32,15 +33,26 @@ impl<'d> Flash<'d, Async> { } } + /// Split this flash driver into one instance per flash memory region. + /// + /// See module-level documentation for details on how memory regions work. pub fn into_regions(self) -> FlashLayout<'d, Async> { assert!(family::is_default_layout()); FlashLayout::new(self.inner) } + /// Async write. + /// + /// NOTE: `offset` is an offset from the flash start, NOT an absolute address. + /// For example, to write address `0x0800_1234` you have to use offset `0x1234`. pub async fn write(&mut self, offset: u32, bytes: &[u8]) -> Result<(), Error> { unsafe { write_chunked(FLASH_BASE as u32, FLASH_SIZE as u32, offset, bytes).await } } + /// Async erase. + /// + /// NOTE: `from` and `to` are offsets from the flash start, NOT an absolute address. + /// For example, to erase address `0x0801_0000` you have to use offset `0x1_0000`. pub async fn erase(&mut self, from: u32, to: u32) -> Result<(), Error> { unsafe { erase_sectored(FLASH_BASE as u32, from, to).await } } @@ -141,15 +153,20 @@ pub(super) async unsafe fn erase_sectored(base: u32, from: u32, to: u32) -> Resu foreach_flash_region! { ($type_name:ident, $write_size:literal, $erase_size:literal) => { impl crate::_generated::flash_regions::$type_name<'_, Async> { + /// Async read. + /// + /// Note: reading from flash can't actually block, so this is the same as `blocking_read`. pub async fn read(&mut self, offset: u32, bytes: &mut [u8]) -> Result<(), Error> { blocking_read(self.0.base, self.0.size, offset, bytes) } + /// Async write. pub async fn write(&mut self, offset: u32, bytes: &[u8]) -> Result<(), Error> { let _guard = REGION_ACCESS.lock().await; unsafe { write_chunked(self.0.base, self.0.size, offset, bytes).await } } + /// Async erase. pub async fn erase(&mut self, from: u32, to: u32) -> Result<(), Error> { let _guard = REGION_ACCESS.lock().await; unsafe { erase_sectored(self.0.base, from, to).await } diff --git a/embassy-stm32/src/flash/f4.rs b/embassy-stm32/src/flash/f4.rs index f442c5894..2671dfb04 100644 --- a/embassy-stm32/src/flash/f4.rs +++ b/embassy-stm32/src/flash/f4.rs @@ -9,7 +9,7 @@ use pac::FLASH_SIZE; use super::{FlashBank, FlashRegion, FlashSector, FLASH_REGIONS, WRITE_SIZE}; use crate::flash::Error; use crate::pac; - +#[allow(missing_docs)] // TODO #[cfg(any(stm32f427, stm32f429, stm32f437, stm32f439, stm32f469, stm32f479))] mod alt_regions { use core::marker::PhantomData; diff --git a/embassy-stm32/src/fmc.rs b/embassy-stm32/src/fmc.rs index dd0d27217..23ac82f63 100644 --- a/embassy-stm32/src/fmc.rs +++ b/embassy-stm32/src/fmc.rs @@ -6,6 +6,7 @@ use crate::gpio::sealed::AFType; use crate::gpio::{Pull, Speed}; use crate::Peripheral; +/// FMC driver pub struct Fmc<'d, T: Instance> { peri: PhantomData<&'d mut T>, } @@ -38,6 +39,7 @@ where T::REGS.bcr1().modify(|r| r.set_fmcen(true)); } + /// Get the kernel clock currently in use for this FMC instance. pub fn source_clock_hz(&self) -> u32 { ::frequency().0 } @@ -85,6 +87,7 @@ macro_rules! fmc_sdram_constructor { nbl: [$(($nbl_pin_name:ident: $nbl_signal:ident)),*], ctrl: [$(($ctrl_pin_name:ident: $ctrl_signal:ident)),*] )) => { + /// Create a new FMC instance. pub fn $name( _instance: impl Peripheral

+ 'd, $($addr_pin_name: impl Peripheral

> + 'd),*, @@ -199,6 +202,7 @@ pub(crate) mod sealed { } } +/// FMC instance trait. pub trait Instance: sealed::Instance + 'static {} foreach_peripheral!( diff --git a/embassy-stm32/src/gpio.rs b/embassy-stm32/src/gpio.rs index 083b3237c..c300a079e 100644 --- a/embassy-stm32/src/gpio.rs +++ b/embassy-stm32/src/gpio.rs @@ -1,3 +1,5 @@ +//! General-purpose Input/Output (GPIO) + #![macro_use] use core::convert::Infallible; diff --git a/embassy-stm32/src/i2c/v1.rs b/embassy-stm32/src/i2c/v1.rs index 84802d129..df5b44c2d 100644 --- a/embassy-stm32/src/i2c/v1.rs +++ b/embassy-stm32/src/i2c/v1.rs @@ -247,10 +247,12 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> { } } + /// Blocking read. pub fn blocking_read(&mut self, addr: u8, read: &mut [u8]) -> Result<(), Error> { self.blocking_read_timeout(addr, read, self.timeout()) } + /// Blocking write. pub fn blocking_write(&mut self, addr: u8, write: &[u8]) -> Result<(), Error> { let timeout = self.timeout(); @@ -266,6 +268,7 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> { Ok(()) } + /// Blocking write, restart, read. pub fn blocking_write_read(&mut self, addr: u8, write: &[u8], read: &mut [u8]) -> Result<(), Error> { let timeout = self.timeout(); @@ -435,6 +438,7 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> { Ok(()) } + /// Write. pub async fn write(&mut self, address: u8, write: &[u8]) -> Result<(), Error> where TXDMA: crate::i2c::TxDma, @@ -457,6 +461,7 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> { Ok(()) } + /// Read. pub async fn read(&mut self, address: u8, buffer: &mut [u8]) -> Result<(), Error> where RXDMA: crate::i2c::RxDma, @@ -616,6 +621,7 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> { Ok(()) } + /// Write, restart, read. pub async fn write_read(&mut self, address: u8, write: &[u8], read: &mut [u8]) -> Result<(), Error> where RXDMA: crate::i2c::RxDma, diff --git a/embassy-stm32/src/i2s.rs b/embassy-stm32/src/i2s.rs index 67d40c479..372c86db3 100644 --- a/embassy-stm32/src/i2s.rs +++ b/embassy-stm32/src/i2s.rs @@ -8,30 +8,42 @@ use crate::spi::{Config as SpiConfig, *}; use crate::time::Hertz; use crate::{Peripheral, PeripheralRef}; +/// I2S mode #[derive(Copy, Clone)] pub enum Mode { + /// Master mode Master, + /// Slave mode Slave, } +/// I2S function #[derive(Copy, Clone)] pub enum Function { + /// Transmit audio data Transmit, + /// Receive audio data Receive, } +/// I2C standard #[derive(Copy, Clone)] pub enum Standard { + /// Philips Philips, + /// Most significant bit first. MsbFirst, + /// Least significant bit first. LsbFirst, + /// PCM with long sync. PcmLongSync, + /// PCM with short sync. PcmShortSync, } impl Standard { #[cfg(any(spi_v1, spi_f1))] - pub const fn i2sstd(&self) -> vals::I2sstd { + const fn i2sstd(&self) -> vals::I2sstd { match self { Standard::Philips => vals::I2sstd::PHILIPS, Standard::MsbFirst => vals::I2sstd::MSB, @@ -42,7 +54,7 @@ impl Standard { } #[cfg(any(spi_v1, spi_f1))] - pub const fn pcmsync(&self) -> vals::Pcmsync { + const fn pcmsync(&self) -> vals::Pcmsync { match self { Standard::PcmLongSync => vals::Pcmsync::LONG, _ => vals::Pcmsync::SHORT, @@ -50,6 +62,7 @@ impl Standard { } } +/// I2S data format. #[derive(Copy, Clone)] pub enum Format { /// 16 bit data length on 16 bit wide channel @@ -64,7 +77,7 @@ pub enum Format { impl Format { #[cfg(any(spi_v1, spi_f1))] - pub const fn datlen(&self) -> vals::Datlen { + const fn datlen(&self) -> vals::Datlen { match self { Format::Data16Channel16 => vals::Datlen::SIXTEENBIT, Format::Data16Channel32 => vals::Datlen::SIXTEENBIT, @@ -74,7 +87,7 @@ impl Format { } #[cfg(any(spi_v1, spi_f1))] - pub const fn chlen(&self) -> vals::Chlen { + const fn chlen(&self) -> vals::Chlen { match self { Format::Data16Channel16 => vals::Chlen::SIXTEENBIT, Format::Data16Channel32 => vals::Chlen::THIRTYTWOBIT, @@ -84,15 +97,18 @@ impl Format { } } +/// Clock polarity #[derive(Copy, Clone)] pub enum ClockPolarity { + /// Low on idle. IdleLow, + /// High on idle. IdleHigh, } impl ClockPolarity { #[cfg(any(spi_v1, spi_f1))] - pub const fn ckpol(&self) -> vals::Ckpol { + const fn ckpol(&self) -> vals::Ckpol { match self { ClockPolarity::IdleHigh => vals::Ckpol::IDLEHIGH, ClockPolarity::IdleLow => vals::Ckpol::IDLELOW, @@ -109,11 +125,17 @@ impl ClockPolarity { #[non_exhaustive] #[derive(Copy, Clone)] pub struct Config { + /// Mode pub mode: Mode, + /// Function (transmit, receive) pub function: Function, + /// Which I2S standard to use. pub standard: Standard, + /// Data format. pub format: Format, + /// Clock polarity. pub clock_polarity: ClockPolarity, + /// True to eanble master clock output from this instance. pub master_clock: bool, } @@ -130,6 +152,7 @@ impl Default for Config { } } +/// I2S driver. pub struct I2S<'d, T: Instance, Tx, Rx> { _peri: Spi<'d, T, Tx, Rx>, sd: Option>, @@ -242,6 +265,7 @@ impl<'d, T: Instance, Tx, Rx> I2S<'d, T, Tx, Rx> { } } + /// Write audio data. pub async fn write(&mut self, data: &[W]) -> Result<(), Error> where Tx: TxDma, @@ -249,6 +273,7 @@ impl<'d, T: Instance, Tx, Rx> I2S<'d, T, Tx, Rx> { self._peri.write(data).await } + /// Read audio data. pub async fn read(&mut self, data: &mut [W]) -> Result<(), Error> where Tx: TxDma, diff --git a/embassy-stm32/src/rcc/mod.rs b/embassy-stm32/src/rcc/mod.rs index dc829a9ad..04a51110c 100644 --- a/embassy-stm32/src/rcc/mod.rs +++ b/embassy-stm32/src/rcc/mod.rs @@ -1,4 +1,7 @@ +//! Reset and Clock Control (RCC) + #![macro_use] +#![allow(missing_docs)] // TODO use core::mem::MaybeUninit; diff --git a/embassy-stm32/src/rng.rs b/embassy-stm32/src/rng.rs index 5e6922e9b..b2196b0d5 100644 --- a/embassy-stm32/src/rng.rs +++ b/embassy-stm32/src/rng.rs @@ -13,13 +13,19 @@ use crate::{interrupt, pac, peripherals, Peripheral}; static RNG_WAKER: AtomicWaker = AtomicWaker::new(); +/// RNG error #[derive(Debug, PartialEq, Eq)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] pub enum Error { + /// Seed error. SeedError, + /// Clock error. Double-check the RCC configuration, + /// see the Reference Manual for details on restrictions + /// on RNG clocks. ClockError, } +/// RNG interrupt handler. pub struct InterruptHandler { _phantom: PhantomData, } @@ -34,11 +40,13 @@ impl interrupt::typelevel::Handler for InterruptHandl } } +/// RNG driver. pub struct Rng<'d, T: Instance> { _inner: PeripheralRef<'d, T>, } impl<'d, T: Instance> Rng<'d, T> { + /// Create a new RNG driver. pub fn new( inner: impl Peripheral

+ 'd, _irq: impl interrupt::typelevel::Binding> + 'd, @@ -54,6 +62,7 @@ impl<'d, T: Instance> Rng<'d, T> { random } + /// Reset the RNG. #[cfg(rng_v1)] pub fn reset(&mut self) { T::regs().cr().write(|reg| { @@ -106,7 +115,8 @@ impl<'d, T: Instance> Rng<'d, T> { while T::regs().cr().read().condrst() {} } - pub fn recover_seed_error(&mut self) -> () { + /// Try to recover from a seed error. + pub fn recover_seed_error(&mut self) { self.reset(); // reset should also clear the SEIS flag if T::regs().sr().read().seis() { @@ -117,6 +127,7 @@ impl<'d, T: Instance> Rng<'d, T> { while T::regs().sr().read().secs() {} } + /// Fill the given slice with random values. pub async fn async_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), Error> { for chunk in dest.chunks_mut(4) { let mut bits = T::regs().sr().read(); @@ -217,7 +228,9 @@ pub(crate) mod sealed { } } +/// RNG instance trait. pub trait Instance: sealed::Instance + Peripheral

+ crate::rcc::RccPeripheral + 'static + Send { + /// Interrupt for this RNG instance. type Interrupt: interrupt::typelevel::Interrupt; } diff --git a/embassy-stm32/src/rtc/datetime.rs b/embassy-stm32/src/rtc/datetime.rs index f4e86dd87..ef92fa4bb 100644 --- a/embassy-stm32/src/rtc/datetime.rs +++ b/embassy-stm32/src/rtc/datetime.rs @@ -104,45 +104,51 @@ pub struct DateTime { } impl DateTime { + /// Get the year (0..=4095) pub const fn year(&self) -> u16 { self.year } + /// Get the month (1..=12, 1 is January) pub const fn month(&self) -> u8 { self.month } + /// Get the day (1..=31) pub const fn day(&self) -> u8 { self.day } + /// Get the day of week pub const fn day_of_week(&self) -> DayOfWeek { self.day_of_week } + /// Get the hour (0..=23) pub const fn hour(&self) -> u8 { self.hour } + /// Get the minute (0..=59) pub const fn minute(&self) -> u8 { self.minute } + /// Get the second (0..=59) pub const fn second(&self) -> u8 { self.second } + /// Create a new DateTime with the given information. pub fn from( year: u16, month: u8, day: u8, - day_of_week: u8, + day_of_week: DayOfWeek, hour: u8, minute: u8, second: u8, ) -> Result { - let day_of_week = day_of_week_from_u8(day_of_week)?; - if year > 4095 { Err(Error::InvalidYear) } else if month < 1 || month > 12 { diff --git a/embassy-stm32/src/rtc/mod.rs b/embassy-stm32/src/rtc/mod.rs index b4315f535..fa359cdae 100644 --- a/embassy-stm32/src/rtc/mod.rs +++ b/embassy-stm32/src/rtc/mod.rs @@ -9,9 +9,9 @@ use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex; #[cfg(feature = "low-power")] use embassy_sync::blocking_mutex::Mutex; -use self::datetime::day_of_week_to_u8; #[cfg(not(rtc_v2f2))] use self::datetime::RtcInstant; +use self::datetime::{day_of_week_from_u8, day_of_week_to_u8}; pub use self::datetime::{DateTime, DayOfWeek, Error as DateTimeError}; use crate::pac::rtc::regs::{Dr, Tr}; use crate::time::Hertz; @@ -102,7 +102,7 @@ pub enum RtcError { NotRunning, } -pub struct RtcTimeProvider { +pub(crate) struct RtcTimeProvider { _private: (), } @@ -127,7 +127,7 @@ impl RtcTimeProvider { let minute = bcd2_to_byte((tr.mnt(), tr.mnu())); let hour = bcd2_to_byte((tr.ht(), tr.hu())); - let weekday = dr.wdu(); + let weekday = day_of_week_from_u8(dr.wdu()).map_err(RtcError::InvalidDateTime)?; let day = bcd2_to_byte((dr.dt(), dr.du())); let month = bcd2_to_byte((dr.mt() as u8, dr.mu())); let year = bcd2_to_byte((dr.yt(), dr.yu())) as u16 + 1970_u16; @@ -171,6 +171,7 @@ pub struct Rtc { _private: (), } +/// RTC configuration. #[non_exhaustive] #[derive(Copy, Clone, PartialEq)] pub struct RtcConfig { @@ -188,6 +189,7 @@ impl Default for RtcConfig { } } +/// Calibration cycle period. #[derive(Copy, Clone, Debug, PartialEq)] #[repr(u8)] pub enum RtcCalibrationCyclePeriod { @@ -206,6 +208,7 @@ impl Default for RtcCalibrationCyclePeriod { } impl Rtc { + /// Create a new RTC instance. pub fn new(_rtc: impl Peripheral

, rtc_config: RtcConfig) -> Self { #[cfg(not(any(stm32l0, stm32f3, stm32l1, stm32f0, stm32f2)))] ::enable_and_reset(); @@ -240,7 +243,7 @@ impl Rtc { } /// Acquire a [`RtcTimeProvider`] instance. - pub const fn time_provider(&self) -> RtcTimeProvider { + pub(crate) const fn time_provider(&self) -> RtcTimeProvider { RtcTimeProvider { _private: () } } @@ -315,6 +318,7 @@ impl Rtc { }) } + /// Number of backup registers of this instance. pub const BACKUP_REGISTER_COUNT: usize = RTC::BACKUP_REGISTER_COUNT; /// Read content of the backup register. diff --git a/embassy-stm32/src/timer/complementary_pwm.rs b/embassy-stm32/src/timer/complementary_pwm.rs index 6654366cd..e543a5b43 100644 --- a/embassy-stm32/src/timer/complementary_pwm.rs +++ b/embassy-stm32/src/timer/complementary_pwm.rs @@ -1,3 +1,5 @@ +//! PWM driver with complementary output support. + use core::marker::PhantomData; use embassy_hal_internal::{into_ref, PeripheralRef}; diff --git a/embassy-stm32/src/timer/mod.rs b/embassy-stm32/src/timer/mod.rs index 9f93c6425..42ef878f7 100644 --- a/embassy-stm32/src/timer/mod.rs +++ b/embassy-stm32/src/timer/mod.rs @@ -1,3 +1,5 @@ +//! Timers, PWM, quadrature decoder. + pub mod complementary_pwm; pub mod qei; pub mod simple_pwm; @@ -8,6 +10,7 @@ use crate::interrupt; use crate::rcc::RccPeripheral; use crate::time::Hertz; +/// Low-level timer access. #[cfg(feature = "unstable-pac")] pub mod low_level { pub use super::sealed::*; diff --git a/embassy-stm32/src/timer/qei.rs b/embassy-stm32/src/timer/qei.rs index 01d028bf9..9f9379c20 100644 --- a/embassy-stm32/src/timer/qei.rs +++ b/embassy-stm32/src/timer/qei.rs @@ -1,3 +1,5 @@ +//! Quadrature decoder using a timer. + use core::marker::PhantomData; use embassy_hal_internal::{into_ref, PeripheralRef}; diff --git a/embassy-stm32/src/timer/simple_pwm.rs b/embassy-stm32/src/timer/simple_pwm.rs index 1cf0ad728..234bbaff0 100644 --- a/embassy-stm32/src/timer/simple_pwm.rs +++ b/embassy-stm32/src/timer/simple_pwm.rs @@ -1,3 +1,5 @@ +//! Simple PWM driver. + use core::marker::PhantomData; use embassy_hal_internal::{into_ref, PeripheralRef}; From c952ae0f49a21ade19758e4f6f1e2bec503e413e Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Mon, 18 Dec 2023 23:48:17 +0100 Subject: [PATCH 049/124] stm32/sai: remove unimplemented SetConfig. --- embassy-stm32/src/sai/mod.rs | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/embassy-stm32/src/sai/mod.rs b/embassy-stm32/src/sai/mod.rs index 3d7f65996..96acd9e48 100644 --- a/embassy-stm32/src/sai/mod.rs +++ b/embassy-stm32/src/sai/mod.rs @@ -1,6 +1,5 @@ #![macro_use] -use embassy_embedded_hal::SetConfig; use embassy_hal_internal::{into_ref, PeripheralRef}; pub use crate::dma::word; @@ -988,14 +987,6 @@ impl<'d, T: Instance, C: Channel, W: word::Word> SubBlock<'d, T, C, W> { ch.cr2().modify(|w| w.set_mute(value)); } - #[allow(dead_code)] - /// Reconfigures it with the supplied config. - fn reconfigure(&mut self, _config: Config) {} - - pub fn get_current_config(&self) -> Config { - Config::default() - } - pub async fn write(&mut self, data: &[W]) -> Result<(), Error> { match &mut self.ring_buffer { RingBuffer::Writable(buffer) => { @@ -1060,13 +1051,3 @@ foreach_peripheral!( impl Instance for peripherals::$inst {} }; ); - -impl<'d, T: Instance> SetConfig for Sai<'d, T> { - type Config = Config; - type ConfigError = (); - fn set_config(&mut self, _config: &Self::Config) -> Result<(), ()> { - // self.reconfigure(*config); - - Ok(()) - } -} From 4deae51e656e46e18840bf30e68a976aaaf8ad20 Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Mon, 18 Dec 2023 23:49:37 +0100 Subject: [PATCH 050/124] stm32/sai: deduplicate code for subblocks A/B. --- embassy-stm32/build.rs | 20 +-- embassy-stm32/src/sai/mod.rs | 339 ++++++++++++----------------------- embassy-stm32/src/traits.rs | 26 +-- 3 files changed, 135 insertions(+), 250 deletions(-) diff --git a/embassy-stm32/build.rs b/embassy-stm32/build.rs index bb60d244f..058b8a0fc 100644 --- a/embassy-stm32/build.rs +++ b/embassy-stm32/build.rs @@ -672,14 +672,14 @@ fn main() { (("lpuart", "RTS"), quote!(crate::usart::RtsPin)), (("lpuart", "CK"), quote!(crate::usart::CkPin)), (("lpuart", "DE"), quote!(crate::usart::DePin)), - (("sai", "SCK_A"), quote!(crate::sai::SckAPin)), - (("sai", "SCK_B"), quote!(crate::sai::SckBPin)), - (("sai", "FS_A"), quote!(crate::sai::FsAPin)), - (("sai", "FS_B"), quote!(crate::sai::FsBPin)), - (("sai", "SD_A"), quote!(crate::sai::SdAPin)), - (("sai", "SD_B"), quote!(crate::sai::SdBPin)), - (("sai", "MCLK_A"), quote!(crate::sai::MclkAPin)), - (("sai", "MCLK_B"), quote!(crate::sai::MclkBPin)), + (("sai", "SCK_A"), quote!(crate::sai::SckPin)), + (("sai", "SCK_B"), quote!(crate::sai::SckPin)), + (("sai", "FS_A"), quote!(crate::sai::FsPin)), + (("sai", "FS_B"), quote!(crate::sai::FsPin)), + (("sai", "SD_A"), quote!(crate::sai::SdPin)), + (("sai", "SD_B"), quote!(crate::sai::SdPin)), + (("sai", "MCLK_A"), quote!(crate::sai::MclkPin)), + (("sai", "MCLK_B"), quote!(crate::sai::MclkPin)), (("sai", "WS"), quote!(crate::sai::WsPin)), (("spi", "SCK"), quote!(crate::spi::SckPin)), (("spi", "MOSI"), quote!(crate::spi::MosiPin)), @@ -995,8 +995,8 @@ fn main() { (("usart", "TX"), quote!(crate::usart::TxDma)), (("lpuart", "RX"), quote!(crate::usart::RxDma)), (("lpuart", "TX"), quote!(crate::usart::TxDma)), - (("sai", "A"), quote!(crate::sai::DmaA)), - (("sai", "B"), quote!(crate::sai::DmaB)), + (("sai", "A"), quote!(crate::sai::Dma)), + (("sai", "B"), quote!(crate::sai::Dma)), (("spi", "RX"), quote!(crate::spi::RxDma)), (("spi", "TX"), quote!(crate::spi::TxDma)), (("i2c", "RX"), quote!(crate::i2c::RxDma)), diff --git a/embassy-stm32/src/sai/mod.rs b/embassy-stm32/src/sai/mod.rs index 96acd9e48..e03497529 100644 --- a/embassy-stm32/src/sai/mod.rs +++ b/embassy-stm32/src/sai/mod.rs @@ -1,7 +1,10 @@ #![macro_use] +use core::marker::PhantomData; + use embassy_hal_internal::{into_ref, PeripheralRef}; +use self::sealed::WhichSubBlock; pub use crate::dma::word; use crate::dma::{ringbuffer, Channel, ReadableRingBuffer, Request, TransferOptions, WritableRingBuffer}; use crate::gpio::sealed::{AFType, Pin as _}; @@ -500,23 +503,10 @@ impl Default for Config { } impl Config { - pub fn new_i2s() -> Self { + /// Create a new config with all default values. + pub fn new() -> Self { return Default::default(); } - - pub fn new_msb_first() -> Self { - Self { - bit_order: BitOrder::MsbFirst, - frame_sync_offset: FrameSyncOffset::OnFirstBit, - ..Default::default() - } - } -} - -#[derive(Copy, Clone)] -enum WhichSubBlock { - A = 0, - B = 1, } enum RingBuffer<'d, C: Channel, W: word::Word> { @@ -530,28 +520,6 @@ fn dr(w: crate::pac::sai::Sai, sub_block: WhichSubBlock) -> *mut ch.dr().as_ptr() as _ } -pub struct SubBlock<'d, T: Instance, C: Channel, W: word::Word> { - _peri: PeripheralRef<'d, T>, - sd: Option>, - fs: Option>, - sck: Option>, - mclk: Option>, - ring_buffer: RingBuffer<'d, C, W>, - sub_block: WhichSubBlock, -} - -pub struct SubBlockA {} -pub struct SubBlockB {} - -pub struct SubBlockAPeripheral<'d, T>(PeripheralRef<'d, T>); -pub struct SubBlockBPeripheral<'d, T>(PeripheralRef<'d, T>); - -pub struct Sai<'d, T: Instance> { - _peri: PeripheralRef<'d, T>, - sub_block_a_peri: Option>, - sub_block_b_peri: Option>, -} - // return the type for (sd, sck) fn get_af_types(mode: Mode, tx_rx: TxRx) -> (AFType, AFType) { ( @@ -590,34 +558,6 @@ fn get_ring_buffer<'d, T: Instance, C: Channel, W: word::Word>( } } -impl<'d, T: Instance> Sai<'d, T> { - pub fn new(peri: impl Peripheral

+ 'd) -> Self { - T::enable_and_reset(); - - Self { - _peri: unsafe { peri.clone_unchecked().into_ref() }, - sub_block_a_peri: Some(SubBlockAPeripheral(unsafe { peri.clone_unchecked().into_ref() })), - sub_block_b_peri: Some(SubBlockBPeripheral(peri.into_ref())), - } - } - - pub fn take_sub_block_a(self: &mut Self) -> Option> { - if self.sub_block_a_peri.is_some() { - self.sub_block_a_peri.take() - } else { - None - } - } - - pub fn take_sub_block_b(self: &mut Self) -> Option> { - if self.sub_block_b_peri.is_some() { - self.sub_block_b_peri.take() - } else { - None - } - } -} - fn update_synchronous_config(config: &mut Config) { config.mode = Mode::Slave; config.sync_output = false; @@ -635,19 +575,51 @@ fn update_synchronous_config(config: &mut Config) { } } -impl SubBlockA { - pub fn new_asynchronous_with_mclk<'d, T: Instance, C: Channel, W: word::Word>( - peri: SubBlockAPeripheral<'d, T>, - sck: impl Peripheral

> + 'd, - sd: impl Peripheral

> + 'd, - fs: impl Peripheral

> + 'd, - mclk: impl Peripheral

> + 'd, +pub struct SubBlock<'d, T, S: SubBlockInstance> { + peri: PeripheralRef<'d, T>, + _phantom: PhantomData, +} + +pub fn split_subblocks<'d, T: Instance>(peri: impl Peripheral

+ 'd) -> (SubBlock<'d, T, A>, SubBlock<'d, T, B>) { + into_ref!(peri); + T::enable_and_reset(); + + ( + SubBlock { + peri: unsafe { peri.clone_unchecked() }, + _phantom: PhantomData, + }, + SubBlock { + peri, + _phantom: PhantomData, + }, + ) +} + +/// SAI sub-block driver +pub struct Sai<'d, T: Instance, C: Channel, W: word::Word> { + _peri: PeripheralRef<'d, T>, + sd: Option>, + fs: Option>, + sck: Option>, + mclk: Option>, + ring_buffer: RingBuffer<'d, C, W>, + sub_block: WhichSubBlock, +} + +impl<'d, T: Instance, C: Channel, W: word::Word> Sai<'d, T, C, W> { + pub fn new_asynchronous_with_mclk( + peri: SubBlock<'d, T, S>, + sck: impl Peripheral

> + 'd, + sd: impl Peripheral

> + 'd, + fs: impl Peripheral

> + 'd, + mclk: impl Peripheral

> + 'd, dma: impl Peripheral

+ 'd, dma_buf: &'d mut [W], mut config: Config, - ) -> SubBlock<'d, T, C, W> + ) -> Self where - C: Channel + DmaA, + C: Channel + Dma, { into_ref!(mclk); @@ -663,19 +635,19 @@ impl SubBlockA { Self::new_asynchronous(peri, sck, sd, fs, dma, dma_buf, config) } - pub fn new_asynchronous<'d, T: Instance, C: Channel, W: word::Word>( - peri: SubBlockAPeripheral<'d, T>, - sck: impl Peripheral

> + 'd, - sd: impl Peripheral

> + 'd, - fs: impl Peripheral

> + 'd, + pub fn new_asynchronous( + peri: SubBlock<'d, T, S>, + sck: impl Peripheral

> + 'd, + sd: impl Peripheral

> + 'd, + fs: impl Peripheral

> + 'd, dma: impl Peripheral

+ 'd, dma_buf: &'d mut [W], config: Config, - ) -> SubBlock<'d, T, C, W> + ) -> Self where - C: Channel + DmaA, + C: Channel + Dma, { - let peri = peri.0; + let peri = peri.peri; into_ref!(peri, dma, sck, sd, fs); let (sd_af_type, ck_af_type) = get_af_types(config.mode, config.tx_rx); @@ -687,10 +659,10 @@ impl SubBlockA { fs.set_as_af(fs.af_num(), ck_af_type); fs.set_speed(crate::gpio::Speed::VeryHigh); - let sub_block = WhichSubBlock::A; + let sub_block = S::WHICH; let request = dma.request(); - SubBlock::new_inner( + Self::new_inner( peri, sub_block, Some(sck.map_into()), @@ -702,19 +674,19 @@ impl SubBlockA { ) } - pub fn new_synchronous<'d, T: Instance, C: Channel, W: word::Word>( - peri: SubBlockAPeripheral<'d, T>, - sd: impl Peripheral

> + 'd, + pub fn new_synchronous( + peri: SubBlock<'d, T, S>, + sd: impl Peripheral

> + 'd, dma: impl Peripheral

+ 'd, dma_buf: &'d mut [W], mut config: Config, - ) -> SubBlock<'d, T, C, W> + ) -> Self where - C: Channel + DmaA, + C: Channel + Dma, { update_synchronous_config(&mut config); - let peri = peri.0; + let peri = peri.peri; into_ref!(dma, peri, sd); let (sd_af_type, _ck_af_type) = get_af_types(config.mode, config.tx_rx); @@ -722,10 +694,10 @@ impl SubBlockA { sd.set_as_af(sd.af_num(), sd_af_type); sd.set_speed(crate::gpio::Speed::VeryHigh); - let sub_block = WhichSubBlock::A; + let sub_block = S::WHICH; let request = dma.request(); - SubBlock::new_inner( + Self::new_inner( peri, sub_block, None, @@ -736,129 +708,6 @@ impl SubBlockA { config, ) } -} - -impl SubBlockB { - pub fn new_asynchronous_with_mclk<'d, T: Instance, C: Channel, W: word::Word>( - peri: SubBlockBPeripheral<'d, T>, - sck: impl Peripheral

> + 'd, - sd: impl Peripheral

> + 'd, - fs: impl Peripheral

> + 'd, - mclk: impl Peripheral

> + 'd, - dma: impl Peripheral

+ 'd, - dma_buf: &'d mut [W], - mut config: Config, - ) -> SubBlock<'d, T, C, W> - where - C: Channel + DmaB, - { - into_ref!(mclk); - - let (_sd_af_type, ck_af_type) = get_af_types(config.mode, config.tx_rx); - - mclk.set_as_af(mclk.af_num(), ck_af_type); - mclk.set_speed(crate::gpio::Speed::VeryHigh); - - if config.master_clock_divider == MasterClockDivider::MasterClockDisabled { - config.master_clock_divider = MasterClockDivider::Div1; - } - - Self::new_asynchronous(peri, sck, sd, fs, dma, dma_buf, config) - } - - pub fn new_asynchronous<'d, T: Instance, C: Channel, W: word::Word>( - peri: SubBlockBPeripheral<'d, T>, - sck: impl Peripheral

> + 'd, - sd: impl Peripheral

> + 'd, - fs: impl Peripheral

> + 'd, - dma: impl Peripheral

+ 'd, - dma_buf: &'d mut [W], - config: Config, - ) -> SubBlock<'d, T, C, W> - where - C: Channel + DmaB, - { - let peri = peri.0; - into_ref!(dma, peri, sck, sd, fs); - - let (sd_af_type, ck_af_type) = get_af_types(config.mode, config.tx_rx); - - sd.set_as_af(sd.af_num(), sd_af_type); - sd.set_speed(crate::gpio::Speed::VeryHigh); - - sck.set_as_af(sck.af_num(), ck_af_type); - sck.set_speed(crate::gpio::Speed::VeryHigh); - fs.set_as_af(fs.af_num(), ck_af_type); - fs.set_speed(crate::gpio::Speed::VeryHigh); - - let sub_block = WhichSubBlock::B; - let request = dma.request(); - - SubBlock::new_inner( - peri, - sub_block, - Some(sck.map_into()), - None, - Some(sd.map_into()), - Some(fs.map_into()), - get_ring_buffer::(dma, dma_buf, request, sub_block, config.tx_rx), - config, - ) - } - - pub fn new_synchronous<'d, T: Instance, C: Channel, W: word::Word>( - peri: SubBlockBPeripheral<'d, T>, - sd: impl Peripheral

> + 'd, - dma: impl Peripheral

+ 'd, - dma_buf: &'d mut [W], - mut config: Config, - ) -> SubBlock<'d, T, C, W> - where - C: Channel + DmaB, - { - update_synchronous_config(&mut config); - let peri = peri.0; - into_ref!(dma, peri, sd); - - let (sd_af_type, _ck_af_type) = get_af_types(config.mode, config.tx_rx); - - sd.set_as_af(sd.af_num(), sd_af_type); - sd.set_speed(crate::gpio::Speed::VeryHigh); - - let sub_block = WhichSubBlock::B; - let request = dma.request(); - - SubBlock::new_inner( - peri, - sub_block, - None, - None, - Some(sd.map_into()), - None, - get_ring_buffer::(dma, dma_buf, request, sub_block, config.tx_rx), - config, - ) - } -} - -impl<'d, T: Instance, C: Channel, W: word::Word> SubBlock<'d, T, C, W> { - pub fn start(self: &mut Self) { - match self.ring_buffer { - RingBuffer::Writable(ref mut rb) => { - rb.start(); - } - RingBuffer::Readable(ref mut rb) => { - rb.start(); - } - } - } - - fn is_transmitter(ring_buffer: &RingBuffer) -> bool { - match ring_buffer { - RingBuffer::Writable(_) => true, - _ => false, - } - } fn new_inner( peri: impl Peripheral

+ 'd, @@ -964,6 +813,24 @@ impl<'d, T: Instance, C: Channel, W: word::Word> SubBlock<'d, T, C, W> { } } + pub fn start(&mut self) { + match self.ring_buffer { + RingBuffer::Writable(ref mut rb) => { + rb.start(); + } + RingBuffer::Readable(ref mut rb) => { + rb.start(); + } + } + } + + fn is_transmitter(ring_buffer: &RingBuffer) -> bool { + match ring_buffer { + RingBuffer::Writable(_) => true, + _ => false, + } + } + pub fn reset() { T::enable_and_reset(); } @@ -1008,7 +875,7 @@ impl<'d, T: Instance, C: Channel, W: word::Word> SubBlock<'d, T, C, W> { } } -impl<'d, T: Instance, C: Channel, W: word::Word> Drop for SubBlock<'d, T, C, W> { +impl<'d, T: Instance, C: Channel, W: word::Word> Drop for Sai<'d, T, C, W> { fn drop(&mut self) { let ch = T::REGS.ch(self.sub_block as usize); ch.cr1().modify(|w| w.set_saien(false)); @@ -1025,22 +892,40 @@ pub(crate) mod sealed { pub trait Instance { const REGS: Regs; } + + #[derive(Copy, Clone)] + pub enum WhichSubBlock { + A = 0, + B = 1, + } + + pub trait SubBlock { + const WHICH: WhichSubBlock; + } } pub trait Word: word::Word {} -pub trait Instance: Peripheral

+ sealed::Instance + RccPeripheral {} -pin_trait!(SckAPin, Instance); -pin_trait!(SckBPin, Instance); -pin_trait!(FsAPin, Instance); -pin_trait!(FsBPin, Instance); -pin_trait!(SdAPin, Instance); -pin_trait!(SdBPin, Instance); -pin_trait!(MclkAPin, Instance); -pin_trait!(MclkBPin, Instance); +pub trait SubBlockInstance: sealed::SubBlock {} -dma_trait!(DmaA, Instance); -dma_trait!(DmaB, Instance); +pub enum A {} +impl sealed::SubBlock for A { + const WHICH: WhichSubBlock = WhichSubBlock::A; +} +impl SubBlockInstance for A {} +pub enum B {} +impl sealed::SubBlock for B { + const WHICH: WhichSubBlock = WhichSubBlock::B; +} +impl SubBlockInstance for B {} + +pub trait Instance: Peripheral

+ sealed::Instance + RccPeripheral {} +pin_trait!(SckPin, Instance, SubBlockInstance); +pin_trait!(FsPin, Instance, SubBlockInstance); +pin_trait!(SdPin, Instance, SubBlockInstance); +pin_trait!(MclkPin, Instance, SubBlockInstance); + +dma_trait!(Dma, Instance, SubBlockInstance); foreach_peripheral!( (sai, $inst:ident) => { diff --git a/embassy-stm32/src/traits.rs b/embassy-stm32/src/traits.rs index b4166e71a..13f695821 100644 --- a/embassy-stm32/src/traits.rs +++ b/embassy-stm32/src/traits.rs @@ -1,18 +1,18 @@ #![macro_use] macro_rules! pin_trait { - ($signal:ident, $instance:path) => { + ($signal:ident, $instance:path $(, $mode:path)?) => { #[doc = concat!(stringify!($signal), " pin trait")] - pub trait $signal: crate::gpio::Pin { - #[doc = concat!("Get the AF number needed to use this pin as", stringify!($signal))] + pub trait $signal: crate::gpio::Pin { + #[doc = concat!("Get the AF number needed to use this pin as ", stringify!($signal))] fn af_num(&self) -> u8; } }; } macro_rules! pin_trait_impl { - (crate::$mod:ident::$trait:ident, $instance:ident, $pin:ident, $af:expr) => { - impl crate::$mod::$trait for crate::peripherals::$pin { + (crate::$mod:ident::$trait:ident$(<$mode:ident>)?, $instance:ident, $pin:ident, $af:expr) => { + impl crate::$mod::$trait for crate::peripherals::$pin { fn af_num(&self) -> u8 { $af } @@ -23,9 +23,9 @@ macro_rules! pin_trait_impl { // ==================== macro_rules! dma_trait { - ($signal:ident, $instance:path) => { + ($signal:ident, $instance:path$(, $mode:path)?) => { #[doc = concat!(stringify!($signal), " DMA request trait")] - pub trait $signal: crate::dma::Channel { + pub trait $signal: crate::dma::Channel { #[doc = concat!("Get the DMA request number needed to use this channel as", stringify!($signal))] /// Note: in some chips, ST calls this the "channel", and calls channels "streams". /// `embassy-stm32` always uses the "channel" and "request number" names. @@ -37,8 +37,8 @@ macro_rules! dma_trait { #[allow(unused)] macro_rules! dma_trait_impl { // DMAMUX - (crate::$mod:ident::$trait:ident, $instance:ident, {dmamux: $dmamux:ident}, $request:expr) => { - impl crate::$mod::$trait for T + (crate::$mod:ident::$trait:ident$(<$mode:ident>)?, $instance:ident, {dmamux: $dmamux:ident}, $request:expr) => { + impl crate::$mod::$trait for T where T: crate::dma::Channel + crate::dma::MuxChannel, { @@ -49,8 +49,8 @@ macro_rules! dma_trait_impl { }; // DMAMUX - (crate::$mod:ident::$trait:ident, $instance:ident, {dma: $dma:ident}, $request:expr) => { - impl crate::$mod::$trait for T + (crate::$mod:ident::$trait:ident$(<$mode:ident>)?, $instance:ident, {dma: $dma:ident}, $request:expr) => { + impl crate::$mod::$trait for T where T: crate::dma::Channel, { @@ -61,8 +61,8 @@ macro_rules! dma_trait_impl { }; // DMA/GPDMA, without DMAMUX - (crate::$mod:ident::$trait:ident, $instance:ident, {channel: $channel:ident}, $request:expr) => { - impl crate::$mod::$trait for crate::peripherals::$channel { + (crate::$mod:ident::$trait:ident$(<$mode:ident>)?, $instance:ident, {channel: $channel:ident}, $request:expr) => { + impl crate::$mod::$trait for crate::peripherals::$channel { fn request(&self) -> crate::dma::Request { $request } From c45418787c03a348273591355a1e3e0362696e80 Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Tue, 19 Dec 2023 00:01:36 +0100 Subject: [PATCH 051/124] stm32/sai: remove unused Word trait. --- embassy-stm32/src/sai/mod.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/embassy-stm32/src/sai/mod.rs b/embassy-stm32/src/sai/mod.rs index e03497529..43c912157 100644 --- a/embassy-stm32/src/sai/mod.rs +++ b/embassy-stm32/src/sai/mod.rs @@ -904,8 +904,6 @@ pub(crate) mod sealed { } } -pub trait Word: word::Word {} - pub trait SubBlockInstance: sealed::SubBlock {} pub enum A {} From 138318f6118322af199888bcbd53ef49114f89bd Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Tue, 19 Dec 2023 00:02:19 +0100 Subject: [PATCH 052/124] stm32/sai: docs, remove unused enums. --- embassy-stm32/src/sai/mod.rs | 182 ++++++++++++++++++++--------------- 1 file changed, 104 insertions(+), 78 deletions(-) diff --git a/embassy-stm32/src/sai/mod.rs b/embassy-stm32/src/sai/mod.rs index 43c912157..af936bc7f 100644 --- a/embassy-stm32/src/sai/mod.rs +++ b/embassy-stm32/src/sai/mod.rs @@ -1,3 +1,4 @@ +//! Serial Audio Interface (SAI) #![macro_use] use core::marker::PhantomData; @@ -13,48 +14,32 @@ use crate::pac::sai::{vals, Sai as Regs}; use crate::rcc::RccPeripheral; use crate::{peripherals, Peripheral}; +/// SAI error #[derive(Debug, PartialEq, Eq)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] pub enum Error { + /// `write` called on a SAI in receive mode. NotATransmitter, + /// `read` called on a SAI in transmit mode. NotAReceiver, - OverrunError, + /// Overrun + Overrun, } impl From for Error { fn from(_: ringbuffer::OverrunError) -> Self { - Self::OverrunError + Self::Overrun } } +/// Master/slave mode. #[derive(Copy, Clone)] -pub enum SyncBlock { - None, - Sai1BlockA, - Sai1BlockB, - Sai2BlockA, - Sai2BlockB, -} - -#[derive(Copy, Clone)] -pub enum SyncIn { - None, - ChannelZero, - ChannelOne, -} - -#[derive(Copy, Clone)] +#[allow(missing_docs)] pub enum Mode { Master, Slave, } -#[derive(Copy, Clone)] -pub enum TxRx { - Transmitter, - Receiver, -} - impl Mode { #[cfg(any(sai_v1, sai_v2, sai_v3, sai_v4))] const fn mode(&self, tx_rx: TxRx) -> vals::Mode { @@ -71,7 +56,17 @@ impl Mode { } } +/// Direction: transmit or receive #[derive(Copy, Clone)] +#[allow(missing_docs)] +pub enum TxRx { + Transmitter, + Receiver, +} + +/// Data slot size. +#[derive(Copy, Clone)] +#[allow(missing_docs)] pub enum SlotSize { DataSize, /// 16 bit data length on 16 bit wide channel @@ -82,7 +77,7 @@ pub enum SlotSize { impl SlotSize { #[cfg(any(sai_v1, sai_v2, sai_v3, sai_v4))] - pub const fn slotsz(&self) -> vals::Slotsz { + const fn slotsz(&self) -> vals::Slotsz { match self { SlotSize::DataSize => vals::Slotsz::DATASIZE, SlotSize::Channel16 => vals::Slotsz::BIT16, @@ -91,7 +86,9 @@ impl SlotSize { } } +/// Data size. #[derive(Copy, Clone)] +#[allow(missing_docs)] pub enum DataSize { Data8, Data10, @@ -103,7 +100,7 @@ pub enum DataSize { impl DataSize { #[cfg(any(sai_v1, sai_v2, sai_v3, sai_v4))] - pub const fn ds(&self) -> vals::Ds { + const fn ds(&self) -> vals::Ds { match self { DataSize::Data8 => vals::Ds::BIT8, DataSize::Data10 => vals::Ds::BIT10, @@ -115,7 +112,9 @@ impl DataSize { } } +/// FIFO threshold level. #[derive(Copy, Clone)] +#[allow(missing_docs)] pub enum FifoThreshold { Empty, Quarter, @@ -126,7 +125,7 @@ pub enum FifoThreshold { impl FifoThreshold { #[cfg(any(sai_v1, sai_v2, sai_v3, sai_v4))] - pub const fn fth(&self) -> vals::Fth { + const fn fth(&self) -> vals::Fth { match self { FifoThreshold::Empty => vals::Fth::EMPTY, FifoThreshold::Quarter => vals::Fth::QUARTER1, @@ -137,38 +136,9 @@ impl FifoThreshold { } } +/// Output value on mute. #[derive(Copy, Clone)] -pub enum FifoLevel { - Empty, - FirstQuarter, - SecondQuarter, - ThirdQuarter, - FourthQuarter, - Full, -} - -#[cfg(any(sai_v1, sai_v2, sai_v3, sai_v4))] -impl From for FifoLevel { - fn from(flvl: vals::Flvl) -> Self { - match flvl { - vals::Flvl::EMPTY => FifoLevel::Empty, - vals::Flvl::QUARTER1 => FifoLevel::FirstQuarter, - vals::Flvl::QUARTER2 => FifoLevel::SecondQuarter, - vals::Flvl::QUARTER3 => FifoLevel::ThirdQuarter, - vals::Flvl::QUARTER4 => FifoLevel::FourthQuarter, - vals::Flvl::FULL => FifoLevel::Full, - _ => FifoLevel::Empty, - } - } -} - -#[derive(Copy, Clone)] -pub enum MuteDetection { - NoMute, - Mute, -} - -#[derive(Copy, Clone)] +#[allow(missing_docs)] pub enum MuteValue { Zero, LastValue, @@ -176,7 +146,7 @@ pub enum MuteValue { impl MuteValue { #[cfg(any(sai_v1, sai_v2, sai_v3, sai_v4))] - pub const fn muteval(&self) -> vals::Muteval { + const fn muteval(&self) -> vals::Muteval { match self { MuteValue::Zero => vals::Muteval::SENDZERO, MuteValue::LastValue => vals::Muteval::SENDLAST, @@ -184,13 +154,9 @@ impl MuteValue { } } +/// Protocol variant to use. #[derive(Copy, Clone)] -pub enum OverUnderStatus { - NoError, - OverUnderRunDetected, -} - -#[derive(Copy, Clone)] +#[allow(missing_docs)] pub enum Protocol { Free, Spdif, @@ -199,7 +165,7 @@ pub enum Protocol { impl Protocol { #[cfg(any(sai_v1, sai_v2, sai_v3, sai_v4))] - pub const fn prtcfg(&self) -> vals::Prtcfg { + const fn prtcfg(&self) -> vals::Prtcfg { match self { Protocol::Free => vals::Prtcfg::FREE, Protocol::Spdif => vals::Prtcfg::SPDIF, @@ -208,7 +174,9 @@ impl Protocol { } } +/// Sync input between SAI units/blocks. #[derive(Copy, Clone, PartialEq)] +#[allow(missing_docs)] pub enum SyncInput { /// Not synced to any other SAI unit. None, @@ -220,7 +188,7 @@ pub enum SyncInput { } impl SyncInput { - pub const fn syncen(&self) -> vals::Syncen { + const fn syncen(&self) -> vals::Syncen { match self { SyncInput::None => vals::Syncen::ASYNCHRONOUS, SyncInput::Internal => vals::Syncen::INTERNAL, @@ -230,8 +198,10 @@ impl SyncInput { } } +/// SAI instance to sync from. #[cfg(sai_v4)] #[derive(Copy, Clone, PartialEq)] +#[allow(missing_docs)] pub enum SyncInputInstance { #[cfg(peri_sai1)] Sai1 = 0, @@ -243,7 +213,9 @@ pub enum SyncInputInstance { Sai4 = 3, } +/// Channels (stereo or mono). #[derive(Copy, Clone, PartialEq)] +#[allow(missing_docs)] pub enum StereoMono { Stereo, Mono, @@ -251,7 +223,7 @@ pub enum StereoMono { impl StereoMono { #[cfg(any(sai_v1, sai_v2, sai_v3, sai_v4))] - pub const fn mono(&self) -> vals::Mono { + const fn mono(&self) -> vals::Mono { match self { StereoMono::Stereo => vals::Mono::STEREO, StereoMono::Mono => vals::Mono::MONO, @@ -259,15 +231,18 @@ impl StereoMono { } } +/// Bit order #[derive(Copy, Clone)] pub enum BitOrder { + /// Least significant bit first. LsbFirst, + /// Most significant bit first. MsbFirst, } impl BitOrder { #[cfg(any(sai_v1, sai_v2, sai_v3, sai_v4))] - pub const fn lsbfirst(&self) -> vals::Lsbfirst { + const fn lsbfirst(&self) -> vals::Lsbfirst { match self { BitOrder::LsbFirst => vals::Lsbfirst::LSBFIRST, BitOrder::MsbFirst => vals::Lsbfirst::MSBFIRST, @@ -275,6 +250,7 @@ impl BitOrder { } } +/// Frame sync offset. #[derive(Copy, Clone)] pub enum FrameSyncOffset { /// This is used in modes other than standard I2S phillips mode @@ -285,7 +261,7 @@ pub enum FrameSyncOffset { impl FrameSyncOffset { #[cfg(any(sai_v1, sai_v2, sai_v3, sai_v4))] - pub const fn fsoff(&self) -> vals::Fsoff { + const fn fsoff(&self) -> vals::Fsoff { match self { FrameSyncOffset::OnFirstBit => vals::Fsoff::ONFIRST, FrameSyncOffset::BeforeFirstBit => vals::Fsoff::BEFOREFIRST, @@ -293,15 +269,18 @@ impl FrameSyncOffset { } } +/// Frame sync polarity #[derive(Copy, Clone)] pub enum FrameSyncPolarity { + /// Sync signal is active low. ActiveLow, + /// Sync signal is active high ActiveHigh, } impl FrameSyncPolarity { #[cfg(any(sai_v1, sai_v2, sai_v3, sai_v4))] - pub const fn fspol(&self) -> vals::Fspol { + const fn fspol(&self) -> vals::Fspol { match self { FrameSyncPolarity::ActiveLow => vals::Fspol::FALLINGEDGE, FrameSyncPolarity::ActiveHigh => vals::Fspol::RISINGEDGE, @@ -309,7 +288,9 @@ impl FrameSyncPolarity { } } +/// Sync definition. #[derive(Copy, Clone)] +#[allow(missing_docs)] pub enum FrameSyncDefinition { StartOfFrame, ChannelIdentification, @@ -317,7 +298,7 @@ pub enum FrameSyncDefinition { impl FrameSyncDefinition { #[cfg(any(sai_v1, sai_v2, sai_v3, sai_v4))] - pub const fn fsdef(&self) -> bool { + const fn fsdef(&self) -> bool { match self { FrameSyncDefinition::StartOfFrame => false, FrameSyncDefinition::ChannelIdentification => true, @@ -325,7 +306,9 @@ impl FrameSyncDefinition { } } +/// Clock strobe. #[derive(Copy, Clone)] +#[allow(missing_docs)] pub enum ClockStrobe { Falling, Rising, @@ -333,7 +316,7 @@ pub enum ClockStrobe { impl ClockStrobe { #[cfg(any(sai_v1, sai_v2, sai_v3, sai_v4))] - pub const fn ckstr(&self) -> vals::Ckstr { + const fn ckstr(&self) -> vals::Ckstr { match self { ClockStrobe::Falling => vals::Ckstr::FALLINGEDGE, ClockStrobe::Rising => vals::Ckstr::RISINGEDGE, @@ -341,7 +324,9 @@ impl ClockStrobe { } } +/// Complements format for negative samples. #[derive(Copy, Clone)] +#[allow(missing_docs)] pub enum ComplementFormat { OnesComplement, TwosComplement, @@ -349,7 +334,7 @@ pub enum ComplementFormat { impl ComplementFormat { #[cfg(any(sai_v1, sai_v2, sai_v3, sai_v4))] - pub const fn cpl(&self) -> vals::Cpl { + const fn cpl(&self) -> vals::Cpl { match self { ComplementFormat::OnesComplement => vals::Cpl::ONESCOMPLEMENT, ComplementFormat::TwosComplement => vals::Cpl::TWOSCOMPLEMENT, @@ -357,7 +342,9 @@ impl ComplementFormat { } } +/// Companding setting. #[derive(Copy, Clone)] +#[allow(missing_docs)] pub enum Companding { None, MuLaw, @@ -366,7 +353,7 @@ pub enum Companding { impl Companding { #[cfg(any(sai_v1, sai_v2, sai_v3, sai_v4))] - pub const fn comp(&self) -> vals::Comp { + const fn comp(&self) -> vals::Comp { match self { Companding::None => vals::Comp::NOCOMPANDING, Companding::MuLaw => vals::Comp::MULAW, @@ -375,7 +362,9 @@ impl Companding { } } +/// Output drive #[derive(Copy, Clone)] +#[allow(missing_docs)] pub enum OutputDrive { OnStart, Immediately, @@ -383,7 +372,7 @@ pub enum OutputDrive { impl OutputDrive { #[cfg(any(sai_v1, sai_v2, sai_v3, sai_v4))] - pub const fn outdriv(&self) -> vals::Outdriv { + const fn outdriv(&self) -> vals::Outdriv { match self { OutputDrive::OnStart => vals::Outdriv::ONSTART, OutputDrive::Immediately => vals::Outdriv::IMMEDIATELY, @@ -391,7 +380,9 @@ impl OutputDrive { } } +/// Master clock divider. #[derive(Copy, Clone, PartialEq)] +#[allow(missing_docs)] pub enum MasterClockDivider { MasterClockDisabled, Div1, @@ -414,7 +405,7 @@ pub enum MasterClockDivider { impl MasterClockDivider { #[cfg(any(sai_v1, sai_v2, sai_v3, sai_v4))] - pub const fn mckdiv(&self) -> u8 { + const fn mckdiv(&self) -> u8 { match self { MasterClockDivider::MasterClockDisabled => 0, MasterClockDivider::Div1 => 0, @@ -438,6 +429,7 @@ impl MasterClockDivider { } /// [`SAI`] configuration. +#[allow(missing_docs)] #[non_exhaustive] #[derive(Copy, Clone)] pub struct Config { @@ -575,11 +567,15 @@ fn update_synchronous_config(config: &mut Config) { } } +/// SAI subblock instance. pub struct SubBlock<'d, T, S: SubBlockInstance> { peri: PeripheralRef<'d, T>, _phantom: PhantomData, } +/// Split the main SAIx peripheral into the two subblocks. +/// +/// You can then create a [`Sai`] driver for each each half. pub fn split_subblocks<'d, T: Instance>(peri: impl Peripheral

+ 'd) -> (SubBlock<'d, T, A>, SubBlock<'d, T, B>) { into_ref!(peri); T::enable_and_reset(); @@ -596,7 +592,7 @@ pub fn split_subblocks<'d, T: Instance>(peri: impl Peripheral

+ 'd) -> (S ) } -/// SAI sub-block driver +/// SAI sub-block driver. pub struct Sai<'d, T: Instance, C: Channel, W: word::Word> { _peri: PeripheralRef<'d, T>, sd: Option>, @@ -608,6 +604,9 @@ pub struct Sai<'d, T: Instance, C: Channel, W: word::Word> { } impl<'d, T: Instance, C: Channel, W: word::Word> Sai<'d, T, C, W> { + /// Create a new SAI driver in asynchronous mode with MCLK. + /// + /// You can obtain the [`SubBlock`] with [`split_subblocks`]. pub fn new_asynchronous_with_mclk( peri: SubBlock<'d, T, S>, sck: impl Peripheral

> + 'd, @@ -635,6 +634,9 @@ impl<'d, T: Instance, C: Channel, W: word::Word> Sai<'d, T, C, W> { Self::new_asynchronous(peri, sck, sd, fs, dma, dma_buf, config) } + /// Create a new SAI driver in asynchronous mode without MCLK. + /// + /// You can obtain the [`SubBlock`] with [`split_subblocks`]. pub fn new_asynchronous( peri: SubBlock<'d, T, S>, sck: impl Peripheral

> + 'd, @@ -674,6 +676,9 @@ impl<'d, T: Instance, C: Channel, W: word::Word> Sai<'d, T, C, W> { ) } + /// Create a new SAI driver in synchronous mode. + /// + /// You can obtain the [`SubBlock`] with [`split_subblocks`]. pub fn new_synchronous( peri: SubBlock<'d, T, S>, sd: impl Peripheral

> + 'd, @@ -813,6 +818,7 @@ impl<'d, T: Instance, C: Channel, W: word::Word> Sai<'d, T, C, W> { } } + /// Start the SAI driver. pub fn start(&mut self) { match self.ring_buffer { RingBuffer::Writable(ref mut rb) => { @@ -831,10 +837,12 @@ impl<'d, T: Instance, C: Channel, W: word::Word> Sai<'d, T, C, W> { } } + /// Reset SAI operation. pub fn reset() { T::enable_and_reset(); } + /// Flush. pub fn flush(&mut self) { let ch = T::REGS.ch(self.sub_block as usize); ch.cr1().modify(|w| w.set_saien(false)); @@ -849,11 +857,18 @@ impl<'d, T: Instance, C: Channel, W: word::Word> Sai<'d, T, C, W> { ch.cr1().modify(|w| w.set_saien(true)); } + /// Enable or disable mute. pub fn set_mute(&mut self, value: bool) { let ch = T::REGS.ch(self.sub_block as usize); ch.cr2().modify(|w| w.set_mute(value)); } + /// Write data to the SAI ringbuffer. + /// + /// This appends the data to the buffer and returns immediately. The + /// data will be transmitted in the background. + /// + /// If there's no space in the buffer, this waits until there is. pub async fn write(&mut self, data: &[W]) -> Result<(), Error> { match &mut self.ring_buffer { RingBuffer::Writable(buffer) => { @@ -864,6 +879,12 @@ impl<'d, T: Instance, C: Channel, W: word::Word> Sai<'d, T, C, W> { } } + /// Read data from the SAI ringbuffer. + /// + /// SAI is always receiving data in the background. This function pops already-received + /// data from the buffer. + /// + /// If there's less than `data.len()` data in the buffer, this waits until there is. pub async fn read(&mut self, data: &mut [W]) -> Result<(), Error> { match &mut self.ring_buffer { RingBuffer::Readable(buffer) => { @@ -904,19 +925,24 @@ pub(crate) mod sealed { } } +/// Sub-block instance trait. pub trait SubBlockInstance: sealed::SubBlock {} +/// Sub-block A. pub enum A {} impl sealed::SubBlock for A { const WHICH: WhichSubBlock = WhichSubBlock::A; } impl SubBlockInstance for A {} + +/// Sub-block B. pub enum B {} impl sealed::SubBlock for B { const WHICH: WhichSubBlock = WhichSubBlock::B; } impl SubBlockInstance for B {} +/// SAI instance trait. pub trait Instance: Peripheral

+ sealed::Instance + RccPeripheral {} pin_trait!(SckPin, Instance, SubBlockInstance); pin_trait!(FsPin, Instance, SubBlockInstance); From 49534cd4056f20bdf5fa6058b0865afc5fcf38ee Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Tue, 19 Dec 2023 00:05:54 +0100 Subject: [PATCH 053/124] stm32: more docs. --- embassy-nrf/src/lib.rs | 6 +++++- embassy-stm32/src/adc/mod.rs | 3 ++- embassy-stm32/src/can/mod.rs | 1 + embassy-stm32/src/crc/mod.rs | 1 + embassy-stm32/src/dac/mod.rs | 2 +- embassy-stm32/src/dcmi.rs | 1 + embassy-stm32/src/eth/mod.rs | 1 + embassy-stm32/src/exti.rs | 1 + embassy-stm32/src/flash/mod.rs | 1 + embassy-stm32/src/fmc.rs | 1 + embassy-stm32/src/hrtim/mod.rs | 2 ++ embassy-stm32/src/i2c/mod.rs | 1 + embassy-stm32/src/i2s.rs | 1 + embassy-stm32/src/lib.rs | 24 +++++++++++++++++++++++- embassy-stm32/src/qspi/mod.rs | 2 ++ embassy-stm32/src/rng.rs | 1 + embassy-stm32/src/rtc/mod.rs | 4 ++-- embassy-stm32/src/sdmmc/mod.rs | 1 + embassy-stm32/src/spi/mod.rs | 1 + embassy-stm32/src/uid.rs | 2 ++ embassy-stm32/src/usart/mod.rs | 1 + embassy-stm32/src/usb_otg/mod.rs | 2 ++ embassy-stm32/src/wdg/mod.rs | 1 + 23 files changed, 55 insertions(+), 6 deletions(-) diff --git a/embassy-nrf/src/lib.rs b/embassy-nrf/src/lib.rs index 9093ad919..e3458e2de 100644 --- a/embassy-nrf/src/lib.rs +++ b/embassy-nrf/src/lib.rs @@ -354,7 +354,11 @@ unsafe fn uicr_write_masked(address: *mut u32, value: u32, mask: u32) -> WriteRe WriteResult::Written } -/// Initialize peripherals with the provided configuration. This should only be called once at startup. +/// Initialize the `embassy-nrf` HAL with the provided configuration. +/// +/// This returns the peripheral singletons that can be used for creating drivers. +/// +/// This should only be called once at startup, otherwise it panics. pub fn init(config: config::Config) -> Peripherals { // Do this first, so that it panics if user is calling `init` a second time // before doing anything important. diff --git a/embassy-stm32/src/adc/mod.rs b/embassy-stm32/src/adc/mod.rs index ff523ca3b..e4dd35c34 100644 --- a/embassy-stm32/src/adc/mod.rs +++ b/embassy-stm32/src/adc/mod.rs @@ -1,4 +1,5 @@ -//! Analog to Digital (ADC) converter driver. +//! Analog to Digital Converter (ADC) + #![macro_use] #![allow(missing_docs)] // TODO diff --git a/embassy-stm32/src/can/mod.rs b/embassy-stm32/src/can/mod.rs index 425f9ac2e..915edb3a6 100644 --- a/embassy-stm32/src/can/mod.rs +++ b/embassy-stm32/src/can/mod.rs @@ -1,3 +1,4 @@ +//! Controller Area Network (CAN) #![macro_use] #[cfg_attr(can_bxcan, path = "bxcan.rs")] diff --git a/embassy-stm32/src/crc/mod.rs b/embassy-stm32/src/crc/mod.rs index 63f7ad9ba..29523b92d 100644 --- a/embassy-stm32/src/crc/mod.rs +++ b/embassy-stm32/src/crc/mod.rs @@ -1,3 +1,4 @@ +//! Cyclic Redundancy Check (CRC) #[cfg_attr(crc_v1, path = "v1.rs")] #[cfg_attr(crc_v2, path = "v2v3.rs")] #[cfg_attr(crc_v3, path = "v2v3.rs")] diff --git a/embassy-stm32/src/dac/mod.rs b/embassy-stm32/src/dac/mod.rs index 9c670195d..31dedf06e 100644 --- a/embassy-stm32/src/dac/mod.rs +++ b/embassy-stm32/src/dac/mod.rs @@ -1,4 +1,4 @@ -//! Provide access to the STM32 digital-to-analog converter (DAC). +//! Digital to Analog Converter (DAC) #![macro_use] use core::marker::PhantomData; diff --git a/embassy-stm32/src/dcmi.rs b/embassy-stm32/src/dcmi.rs index 139d8fd1b..4d02284b2 100644 --- a/embassy-stm32/src/dcmi.rs +++ b/embassy-stm32/src/dcmi.rs @@ -1,3 +1,4 @@ +//! Digital Camera Interface (DCMI) use core::future::poll_fn; use core::marker::PhantomData; use core::task::Poll; diff --git a/embassy-stm32/src/eth/mod.rs b/embassy-stm32/src/eth/mod.rs index dbf91eedc..448405507 100644 --- a/embassy-stm32/src/eth/mod.rs +++ b/embassy-stm32/src/eth/mod.rs @@ -1,3 +1,4 @@ +//! Ethernet (ETH) #![macro_use] #[cfg_attr(any(eth_v1a, eth_v1b, eth_v1c), path = "v1/mod.rs")] diff --git a/embassy-stm32/src/exti.rs b/embassy-stm32/src/exti.rs index 371be913e..f83bae3ff 100644 --- a/embassy-stm32/src/exti.rs +++ b/embassy-stm32/src/exti.rs @@ -1,3 +1,4 @@ +//! External Interrupts (EXTI) use core::convert::Infallible; use core::future::Future; use core::marker::PhantomData; diff --git a/embassy-stm32/src/flash/mod.rs b/embassy-stm32/src/flash/mod.rs index 6b6b4d41c..cbf5c25b2 100644 --- a/embassy-stm32/src/flash/mod.rs +++ b/embassy-stm32/src/flash/mod.rs @@ -1,3 +1,4 @@ +//! Flash memory (FLASH) use embedded_storage::nor_flash::{NorFlashError, NorFlashErrorKind}; #[cfg(flash_f4)] diff --git a/embassy-stm32/src/fmc.rs b/embassy-stm32/src/fmc.rs index 23ac82f63..873c8a70c 100644 --- a/embassy-stm32/src/fmc.rs +++ b/embassy-stm32/src/fmc.rs @@ -1,3 +1,4 @@ +//! Flexible Memory Controller (FMC) / Flexible Static Memory Controller (FSMC) use core::marker::PhantomData; use embassy_hal_internal::into_ref; diff --git a/embassy-stm32/src/hrtim/mod.rs b/embassy-stm32/src/hrtim/mod.rs index 17096d48c..6539326b4 100644 --- a/embassy-stm32/src/hrtim/mod.rs +++ b/embassy-stm32/src/hrtim/mod.rs @@ -1,3 +1,5 @@ +//! High Resolution Timer (HRTIM) + mod traits; use core::marker::PhantomData; diff --git a/embassy-stm32/src/i2c/mod.rs b/embassy-stm32/src/i2c/mod.rs index 0af291e9c..9b0b35eca 100644 --- a/embassy-stm32/src/i2c/mod.rs +++ b/embassy-stm32/src/i2c/mod.rs @@ -1,3 +1,4 @@ +//! Inter-Integrated-Circuit (I2C) #![macro_use] #[cfg_attr(i2c_v1, path = "v1.rs")] diff --git a/embassy-stm32/src/i2s.rs b/embassy-stm32/src/i2s.rs index 372c86db3..1f85c0bc5 100644 --- a/embassy-stm32/src/i2s.rs +++ b/embassy-stm32/src/i2s.rs @@ -1,3 +1,4 @@ +//! Inter-IC Sound (I2S) use embassy_hal_internal::into_ref; use crate::gpio::sealed::{AFType, Pin as _}; diff --git a/embassy-stm32/src/lib.rs b/embassy-stm32/src/lib.rs index 5d9b4e6a0..fd691a732 100644 --- a/embassy-stm32/src/lib.rs +++ b/embassy-stm32/src/lib.rs @@ -149,15 +149,33 @@ use crate::interrupt::Priority; pub use crate::pac::NVIC_PRIO_BITS; use crate::rcc::sealed::RccPeripheral; +/// `embassy-stm32` global configuration. #[non_exhaustive] pub struct Config { + /// RCC config. pub rcc: rcc::Config, + + /// Enable debug during sleep. + /// + /// May incrase power consumption. Defaults to true. #[cfg(dbgmcu)] pub enable_debug_during_sleep: bool, + + /// BDMA interrupt priority. + /// + /// Defaults to P0 (highest). #[cfg(bdma)] pub bdma_interrupt_priority: Priority, + + /// DMA interrupt priority. + /// + /// Defaults to P0 (highest). #[cfg(dma)] pub dma_interrupt_priority: Priority, + + /// GPDMA interrupt priority. + /// + /// Defaults to P0 (highest). #[cfg(gpdma)] pub gpdma_interrupt_priority: Priority, } @@ -178,7 +196,11 @@ impl Default for Config { } } -/// Initialize embassy. +/// Initialize the `embassy-stm32` HAL with the provided configuration. +/// +/// This returns the peripheral singletons that can be used for creating drivers. +/// +/// This should only be called once at startup, otherwise it panics. pub fn init(config: Config) -> Peripherals { critical_section::with(|cs| { let p = Peripherals::take_with_cs(cs); diff --git a/embassy-stm32/src/qspi/mod.rs b/embassy-stm32/src/qspi/mod.rs index bac91f300..9ea0a726c 100644 --- a/embassy-stm32/src/qspi/mod.rs +++ b/embassy-stm32/src/qspi/mod.rs @@ -1,3 +1,5 @@ +//! Quad Serial Peripheral Interface (QSPI) + #![macro_use] pub mod enums; diff --git a/embassy-stm32/src/rng.rs b/embassy-stm32/src/rng.rs index b2196b0d5..6ee89a922 100644 --- a/embassy-stm32/src/rng.rs +++ b/embassy-stm32/src/rng.rs @@ -1,3 +1,4 @@ +//! Random Number Generator (RNG) #![macro_use] use core::future::poll_fn; diff --git a/embassy-stm32/src/rtc/mod.rs b/embassy-stm32/src/rtc/mod.rs index fa359cdae..11b252139 100644 --- a/embassy-stm32/src/rtc/mod.rs +++ b/embassy-stm32/src/rtc/mod.rs @@ -1,4 +1,4 @@ -//! RTC peripheral abstraction +//! Real Time Clock (RTC) mod datetime; #[cfg(feature = "low-power")] @@ -163,7 +163,7 @@ impl RtcTimeProvider { } } -/// RTC Abstraction +/// RTC driver. pub struct Rtc { #[cfg(feature = "low-power")] stop_time: Mutex>>, diff --git a/embassy-stm32/src/sdmmc/mod.rs b/embassy-stm32/src/sdmmc/mod.rs index 27a12062c..6099b9f43 100644 --- a/embassy-stm32/src/sdmmc/mod.rs +++ b/embassy-stm32/src/sdmmc/mod.rs @@ -1,3 +1,4 @@ +//! Secure Digital / MultiMedia Card (SDMMC) #![macro_use] use core::default::Default; diff --git a/embassy-stm32/src/spi/mod.rs b/embassy-stm32/src/spi/mod.rs index 92599c75e..5a1ad3e91 100644 --- a/embassy-stm32/src/spi/mod.rs +++ b/embassy-stm32/src/spi/mod.rs @@ -1,3 +1,4 @@ +//! Serial Peripheral Interface (SPI) #![macro_use] use core::ptr; diff --git a/embassy-stm32/src/uid.rs b/embassy-stm32/src/uid.rs index 6dcfcb96e..aa13586f8 100644 --- a/embassy-stm32/src/uid.rs +++ b/embassy-stm32/src/uid.rs @@ -1,3 +1,5 @@ +//! Unique ID (UID) + /// Get this device's unique 96-bit ID. pub fn uid() -> &'static [u8; 12] { unsafe { &*crate::pac::UID.uid(0).as_ptr().cast::<[u8; 12]>() } diff --git a/embassy-stm32/src/usart/mod.rs b/embassy-stm32/src/usart/mod.rs index dfa1f3a6a..e2e3bd3eb 100644 --- a/embassy-stm32/src/usart/mod.rs +++ b/embassy-stm32/src/usart/mod.rs @@ -1,3 +1,4 @@ +//! Universal Synchronous/Asynchronous Receiver Transmitter (USART, UART, LPUART) #![macro_use] use core::future::poll_fn; diff --git a/embassy-stm32/src/usb_otg/mod.rs b/embassy-stm32/src/usb_otg/mod.rs index be54a3d10..1abd031dd 100644 --- a/embassy-stm32/src/usb_otg/mod.rs +++ b/embassy-stm32/src/usb_otg/mod.rs @@ -1,3 +1,5 @@ +//! USB On The Go (OTG) + use crate::rcc::RccPeripheral; use crate::{interrupt, peripherals}; diff --git a/embassy-stm32/src/wdg/mod.rs b/embassy-stm32/src/wdg/mod.rs index c7c2694e0..5751a9ff3 100644 --- a/embassy-stm32/src/wdg/mod.rs +++ b/embassy-stm32/src/wdg/mod.rs @@ -1,3 +1,4 @@ +//! Watchdog Timer (IWDG, WWDG) use core::marker::PhantomData; use embassy_hal_internal::{into_ref, Peripheral}; From e1f588f520c76c6f08a01b2d61c0e980401c19f1 Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Tue, 19 Dec 2023 00:36:50 +0100 Subject: [PATCH 054/124] stm32/sai: fix typo. --- embassy-stm32/src/sai/mod.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/embassy-stm32/src/sai/mod.rs b/embassy-stm32/src/sai/mod.rs index af936bc7f..ef8802184 100644 --- a/embassy-stm32/src/sai/mod.rs +++ b/embassy-stm32/src/sai/mod.rs @@ -453,7 +453,7 @@ pub struct Config { pub clock_strobe: ClockStrobe, pub output_drive: OutputDrive, pub master_clock_divider: MasterClockDivider, - pub is_high_impedenane_on_inactive_slot: bool, + pub is_high_impedance_on_inactive_slot: bool, pub fifo_threshold: FifoThreshold, pub companding: Companding, pub complement_format: ComplementFormat, @@ -484,7 +484,7 @@ impl Default for Config { master_clock_divider: MasterClockDivider::MasterClockDisabled, clock_strobe: ClockStrobe::Rising, output_drive: OutputDrive::Immediately, - is_high_impedenane_on_inactive_slot: false, + is_high_impedance_on_inactive_slot: false, fifo_threshold: FifoThreshold::ThreeQuarters, companding: Companding::None, complement_format: ComplementFormat::TwosComplement, @@ -782,7 +782,7 @@ impl<'d, T: Instance, C: Channel, W: word::Word> Sai<'d, T, C, W> { w.set_cpl(config.complement_format.cpl()); w.set_muteval(config.mute_value.muteval()); w.set_mutecnt(config.mute_detection_counter.0 as u8); - w.set_tris(config.is_high_impedenane_on_inactive_slot); + w.set_tris(config.is_high_impedance_on_inactive_slot); }); ch.frcr().modify(|w| { From 254d5873855535b97f29592b369f5b2ae3097880 Mon Sep 17 00:00:00 2001 From: eZio Pan Date: Tue, 19 Dec 2023 17:12:34 +0800 Subject: [PATCH 055/124] match up with metapac change --- embassy-stm32/src/dma/bdma.rs | 20 +++++++------------- embassy-stm32/src/dma/dma.rs | 27 +++++++++++---------------- 2 files changed, 18 insertions(+), 29 deletions(-) diff --git a/embassy-stm32/src/dma/bdma.rs b/embassy-stm32/src/dma/bdma.rs index 5102330c0..2f37b1edf 100644 --- a/embassy-stm32/src/dma/bdma.rs +++ b/embassy-stm32/src/dma/bdma.rs @@ -303,20 +303,14 @@ impl<'a, C: Channel> Transfer<'a, C> { ch.cr().write(|w| { w.set_psize(data_size.into()); w.set_msize(data_size.into()); - if incr_mem { - w.set_minc(vals::Inc::ENABLED); - } else { - w.set_minc(vals::Inc::DISABLED); - } + w.set_minc(incr_mem); w.set_dir(dir.into()); w.set_teie(true); w.set_tcie(options.complete_transfer_ir); w.set_htie(options.half_transfer_ir); + w.set_circ(options.circular); if options.circular { - w.set_circ(vals::Circ::ENABLED); debug!("Setting circular mode"); - } else { - w.set_circ(vals::Circ::DISABLED); } w.set_pl(vals::Pl::VERYHIGH); w.set_en(true); @@ -352,7 +346,7 @@ impl<'a, C: Channel> Transfer<'a, C> { pub fn is_running(&mut self) -> bool { let ch = self.channel.regs().ch(self.channel.num()); let en = ch.cr().read().en(); - let circular = ch.cr().read().circ() == vals::Circ::ENABLED; + let circular = ch.cr().read().circ(); let tcif = STATE.complete_count[self.channel.index()].load(Ordering::Acquire) != 0; en && (circular || !tcif) } @@ -467,12 +461,12 @@ impl<'a, C: Channel, W: Word> ReadableRingBuffer<'a, C, W> { let mut w = regs::Cr(0); w.set_psize(data_size.into()); w.set_msize(data_size.into()); - w.set_minc(vals::Inc::ENABLED); + w.set_minc(true); w.set_dir(dir.into()); w.set_teie(true); w.set_htie(true); w.set_tcie(true); - w.set_circ(vals::Circ::ENABLED); + w.set_circ(true); w.set_pl(vals::Pl::VERYHIGH); w.set_en(true); @@ -625,12 +619,12 @@ impl<'a, C: Channel, W: Word> WritableRingBuffer<'a, C, W> { let mut w = regs::Cr(0); w.set_psize(data_size.into()); w.set_msize(data_size.into()); - w.set_minc(vals::Inc::ENABLED); + w.set_minc(true); w.set_dir(dir.into()); w.set_teie(true); w.set_htie(true); w.set_tcie(true); - w.set_circ(vals::Circ::ENABLED); + w.set_circ(true); w.set_pl(vals::Pl::VERYHIGH); w.set_en(true); diff --git a/embassy-stm32/src/dma/dma.rs b/embassy-stm32/src/dma/dma.rs index 64e492c10..9b47ca5c3 100644 --- a/embassy-stm32/src/dma/dma.rs +++ b/embassy-stm32/src/dma/dma.rs @@ -382,18 +382,13 @@ impl<'a, C: Channel> Transfer<'a, C> { w.set_msize(data_size.into()); w.set_psize(data_size.into()); w.set_pl(vals::Pl::VERYHIGH); - w.set_minc(match incr_mem { - true => vals::Inc::INCREMENTED, - false => vals::Inc::FIXED, - }); - w.set_pinc(vals::Inc::FIXED); + w.set_minc(incr_mem); + w.set_pinc(false); w.set_teie(true); w.set_tcie(options.complete_transfer_ir); + w.set_circ(options.circular); if options.circular { - w.set_circ(vals::Circ::ENABLED); debug!("Setting circular mode"); - } else { - w.set_circ(vals::Circ::DISABLED); } #[cfg(dma_v1)] w.set_trbuff(true); @@ -545,8 +540,8 @@ impl<'a, C: Channel, W: Word> DoubleBuffered<'a, C, W> { w.set_msize(data_size.into()); w.set_psize(data_size.into()); w.set_pl(vals::Pl::VERYHIGH); - w.set_minc(vals::Inc::INCREMENTED); - w.set_pinc(vals::Inc::FIXED); + w.set_minc(true); + w.set_pinc(false); w.set_teie(true); w.set_tcie(true); #[cfg(dma_v1)] @@ -703,12 +698,12 @@ impl<'a, C: Channel, W: Word> ReadableRingBuffer<'a, C, W> { w.set_msize(data_size.into()); w.set_psize(data_size.into()); w.set_pl(vals::Pl::VERYHIGH); - w.set_minc(vals::Inc::INCREMENTED); - w.set_pinc(vals::Inc::FIXED); + w.set_minc(true); + w.set_pinc(false); w.set_teie(true); w.set_htie(options.half_transfer_ir); w.set_tcie(true); - w.set_circ(vals::Circ::ENABLED); + w.set_circ(true); #[cfg(dma_v1)] w.set_trbuff(true); #[cfg(dma_v2)] @@ -878,12 +873,12 @@ impl<'a, C: Channel, W: Word> WritableRingBuffer<'a, C, W> { w.set_msize(data_size.into()); w.set_psize(data_size.into()); w.set_pl(vals::Pl::VERYHIGH); - w.set_minc(vals::Inc::INCREMENTED); - w.set_pinc(vals::Inc::FIXED); + w.set_minc(true); + w.set_pinc(false); w.set_teie(true); w.set_htie(options.half_transfer_ir); w.set_tcie(true); - w.set_circ(vals::Circ::ENABLED); + w.set_circ(true); #[cfg(dma_v1)] w.set_trbuff(true); #[cfg(dma_v2)] From fc724dd7075fd833bac3f2a25a96aac76a771ec3 Mon Sep 17 00:00:00 2001 From: Priit Laes Date: Tue, 19 Dec 2023 11:48:58 +0200 Subject: [PATCH 056/124] stm32: i2c: Clean up conditional code a bit By moving conditional code inside the functions, we can reduce duplication and in one case we can even eliminate one... --- embassy-stm32/src/i2c/mod.rs | 37 +++++++++++++++--------------------- 1 file changed, 15 insertions(+), 22 deletions(-) diff --git a/embassy-stm32/src/i2c/mod.rs b/embassy-stm32/src/i2c/mod.rs index 9b0b35eca..2416005b5 100644 --- a/embassy-stm32/src/i2c/mod.rs +++ b/embassy-stm32/src/i2c/mod.rs @@ -148,38 +148,31 @@ struct Timeout { #[allow(dead_code)] impl Timeout { - #[cfg(not(feature = "time"))] #[inline] fn check(self) -> Result<(), Error> { + #[cfg(feature = "time")] + if Instant::now() > self.deadline { + return Err(Error::Timeout); + } + Ok(()) } - #[cfg(feature = "time")] #[inline] - fn check(self) -> Result<(), Error> { - if Instant::now() > self.deadline { - Err(Error::Timeout) - } else { - Ok(()) + fn with(self, fut: impl Future>) -> impl Future> { + #[cfg(feature = "time")] + { + use futures::FutureExt; + + embassy_futures::select::select(embassy_time::Timer::at(self.deadline), fut).map(|r| match r { + embassy_futures::select::Either::First(_) => Err(Error::Timeout), + embassy_futures::select::Either::Second(r) => r, + }) } - } - #[cfg(not(feature = "time"))] - #[inline] - fn with(self, fut: impl Future>) -> impl Future> { + #[cfg(not(feature = "time"))] fut } - - #[cfg(feature = "time")] - #[inline] - fn with(self, fut: impl Future>) -> impl Future> { - use futures::FutureExt; - - embassy_futures::select::select(embassy_time::Timer::at(self.deadline), fut).map(|r| match r { - embassy_futures::select::Either::First(_) => Err(Error::Timeout), - embassy_futures::select::Either::Second(r) => r, - }) - } } pub(crate) mod sealed { From e45e3e76b564b0589a24c1ca56599640238fd672 Mon Sep 17 00:00:00 2001 From: Ulf Lilleengen Date: Tue, 19 Dec 2023 10:11:19 +0100 Subject: [PATCH 057/124] docs: embassy-rp rustdoc and refactoring --- cyw43-pio/src/lib.rs | 20 +-- embassy-nrf/README.md | 2 + embassy-rp/README.md | 23 +++ embassy-rp/src/clocks.rs | 26 +++ embassy-rp/src/lib.rs | 12 +- .../src/{pio_instr_util.rs => pio/instr.rs} | 11 ++ embassy-rp/src/{pio.rs => pio/mod.rs} | 151 ++++++++++++++++-- embassy-rp/src/uart/buffered.rs | 20 +++ embassy-rp/src/uart/mod.rs | 4 + embassy-rp/src/usb.rs | 10 ++ 10 files changed, 253 insertions(+), 26 deletions(-) create mode 100644 embassy-rp/README.md rename embassy-rp/src/{pio_instr_util.rs => pio/instr.rs} (86%) rename embassy-rp/src/{pio.rs => pio/mod.rs} (85%) diff --git a/cyw43-pio/src/lib.rs b/cyw43-pio/src/lib.rs index 41b670324..8304740b3 100644 --- a/cyw43-pio/src/lib.rs +++ b/cyw43-pio/src/lib.rs @@ -6,8 +6,8 @@ use core::slice; use cyw43::SpiBusCyw43; use embassy_rp::dma::Channel; use embassy_rp::gpio::{Drive, Level, Output, Pin, Pull, SlewRate}; -use embassy_rp::pio::{Common, Config, Direction, Instance, Irq, PioPin, ShiftDirection, StateMachine}; -use embassy_rp::{pio_instr_util, Peripheral, PeripheralRef}; +use embassy_rp::pio::{instr, Common, Config, Direction, Instance, Irq, PioPin, ShiftDirection, StateMachine}; +use embassy_rp::{Peripheral, PeripheralRef}; use fixed::FixedU32; use pio_proc::pio_asm; @@ -152,10 +152,10 @@ where defmt::trace!("write={} read={}", write_bits, read_bits); unsafe { - pio_instr_util::set_x(&mut self.sm, write_bits as u32); - pio_instr_util::set_y(&mut self.sm, read_bits as u32); - pio_instr_util::set_pindir(&mut self.sm, 0b1); - pio_instr_util::exec_jmp(&mut self.sm, self.wrap_target); + instr::set_x(&mut self.sm, write_bits as u32); + instr::set_y(&mut self.sm, read_bits as u32); + instr::set_pindir(&mut self.sm, 0b1); + instr::exec_jmp(&mut self.sm, self.wrap_target); } self.sm.set_enable(true); @@ -179,10 +179,10 @@ where defmt::trace!("write={} read={}", write_bits, read_bits); unsafe { - pio_instr_util::set_y(&mut self.sm, read_bits as u32); - pio_instr_util::set_x(&mut self.sm, write_bits as u32); - pio_instr_util::set_pindir(&mut self.sm, 0b1); - pio_instr_util::exec_jmp(&mut self.sm, self.wrap_target); + instr::set_y(&mut self.sm, read_bits as u32); + instr::set_x(&mut self.sm, write_bits as u32); + instr::set_pindir(&mut self.sm, 0b1); + instr::exec_jmp(&mut self.sm, self.wrap_target); } // self.cs.set_low(); diff --git a/embassy-nrf/README.md b/embassy-nrf/README.md index 129ec0c01..39de3854b 100644 --- a/embassy-nrf/README.md +++ b/embassy-nrf/README.md @@ -6,6 +6,8 @@ The Embassy nRF HAL targets the Nordic Semiconductor nRF family of hardware. The for many peripherals. The benefit of using the async APIs is that the HAL takes care of waiting for peripherals to complete operations in low power mod and handling interrupts, so that applications can focus on more important matters. +NOTE: The Embassy HALs can be used both for non-async and async operations. For async, you can choose which runtime you want to use. + ## EasyDMA considerations On nRF chips, peripherals can use the so called EasyDMA feature to offload the task of interacting diff --git a/embassy-rp/README.md b/embassy-rp/README.md new file mode 100644 index 000000000..cd79fe501 --- /dev/null +++ b/embassy-rp/README.md @@ -0,0 +1,23 @@ +# Embassy RP HAL + +HALs implement safe, idiomatic Rust APIs to use the hardware capabilities, so raw register manipulation is not needed. + +The Embassy RP HAL targets the Raspberry Pi 2040 family of hardware. The HAL implements both blocking and async APIs +for many peripherals. The benefit of using the async APIs is that the HAL takes care of waiting for peripherals to +complete operations in low power mod and handling interrupts, so that applications can focus on more important matters. + +NOTE: The Embassy HALs can be used both for non-async and async operations. For async, you can choose which runtime you want to use. + +## Minimum supported Rust version (MSRV) + +Embassy is guaranteed to compile on the latest stable Rust version at the time of release. It might compile with older versions but that may change in any new patch release. + +## License + +This work is licensed under either of + +- Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or + ) +- MIT license ([LICENSE-MIT](LICENSE-MIT) or ) + +at your option. diff --git a/embassy-rp/src/clocks.rs b/embassy-rp/src/clocks.rs index 220665462..2f0645615 100644 --- a/embassy-rp/src/clocks.rs +++ b/embassy-rp/src/clocks.rs @@ -1,3 +1,4 @@ +//! Clock configuration for the RP2040 use core::arch::asm; use core::marker::PhantomData; use core::sync::atomic::{AtomicU16, AtomicU32, Ordering}; @@ -44,6 +45,7 @@ static CLOCKS: Clocks = Clocks { rtc: AtomicU16::new(0), }; +/// Enumeration of supported clock sources. #[repr(u8)] #[non_exhaustive] #[derive(Clone, Copy, Debug, PartialEq, Eq)] @@ -57,15 +59,24 @@ pub enum PeriClkSrc { // Gpin1 = ClkPeriCtrlAuxsrc::CLKSRC_GPIN1 as _ , } +/// CLock configuration. #[non_exhaustive] pub struct ClockConfig { + /// Ring oscillator configuration. pub rosc: Option, + /// External oscillator configuration. pub xosc: Option, + /// Reference clock configuration. pub ref_clk: RefClkConfig, + /// System clock configuration. pub sys_clk: SysClkConfig, + /// Peripheral clock source configuration. pub peri_clk_src: Option, + /// USB clock configuration. pub usb_clk: Option, + /// ADC clock configuration. pub adc_clk: Option, + /// RTC clock configuration. pub rtc_clk: Option, // gpin0: Option<(u32, Gpin<'static, AnyPin>)>, // gpin1: Option<(u32, Gpin<'static, AnyPin>)>, @@ -189,31 +200,46 @@ pub enum RoscRange { TooHigh = pac::rosc::vals::FreqRange::TOOHIGH.0, } +/// On-chip ring oscillator configuration. pub struct RoscConfig { /// Final frequency of the oscillator, after the divider has been applied. /// The oscillator has a nominal frequency of 6.5MHz at medium range with /// divider 16 and all drive strengths set to 0, other values should be /// measured in situ. pub hz: u32, + /// Oscillator range. pub range: RoscRange, + /// Drive strength for oscillator. pub drive_strength: [u8; 8], + /// Output divider. pub div: u16, } +/// Crystal oscillator configuration. pub struct XoscConfig { + /// Final frequency of the oscillator. pub hz: u32, + /// Configuring PLL for the system clock. pub sys_pll: Option, + /// Configuring PLL for the USB clock. pub usb_pll: Option, + /// Multiplier for the startup delay. pub delay_multiplier: u32, } +/// PLL configuration. pub struct PllConfig { + /// Reference divisor. pub refdiv: u8, + /// Feedback divisor. pub fbdiv: u16, + /// Output divisor 1. pub post_div1: u8, + /// Output divisor 2. pub post_div2: u8, } +/// Reference pub struct RefClkConfig { pub src: RefClkSrc, pub div: u8, diff --git a/embassy-rp/src/lib.rs b/embassy-rp/src/lib.rs index 5151323a9..2c49787df 100644 --- a/embassy-rp/src/lib.rs +++ b/embassy-rp/src/lib.rs @@ -1,5 +1,6 @@ #![no_std] #![allow(async_fn_in_trait)] +#![doc = include_str!("../README.md")] // This mod MUST go first, so that the others see its macros. pub(crate) mod fmt; @@ -31,9 +32,7 @@ pub mod usb; pub mod watchdog; // PIO -// TODO: move `pio_instr_util` and `relocate` to inside `pio` pub mod pio; -pub mod pio_instr_util; pub(crate) mod relocate; // Reexports @@ -302,11 +301,14 @@ fn install_stack_guard(stack_bottom: *mut usize) -> Result<(), ()> { Ok(()) } +/// HAL configuration for RP. pub mod config { use crate::clocks::ClockConfig; + /// HAL configuration passed when initializing. #[non_exhaustive] pub struct Config { + /// Clock configuration. pub clocks: ClockConfig, } @@ -319,12 +321,18 @@ pub mod config { } impl Config { + /// Create a new configuration with the provided clock config. pub fn new(clocks: ClockConfig) -> Self { Self { clocks } } } } +/// Initialize the `embassy-rp` HAL with the provided configuration. +/// +/// This returns the peripheral singletons that can be used for creating drivers. +/// +/// This should only be called once at startup, otherwise it panics. pub fn init(config: config::Config) -> Peripherals { // Do this first, so that it panics if user is calling `init` a second time // before doing anything important. diff --git a/embassy-rp/src/pio_instr_util.rs b/embassy-rp/src/pio/instr.rs similarity index 86% rename from embassy-rp/src/pio_instr_util.rs rename to embassy-rp/src/pio/instr.rs index 25393b476..9a44088c6 100644 --- a/embassy-rp/src/pio_instr_util.rs +++ b/embassy-rp/src/pio/instr.rs @@ -1,7 +1,9 @@ +//! Instructions controlling the PIO. use pio::{InSource, InstructionOperands, JmpCondition, OutDestination, SetDestination}; use crate::pio::{Instance, StateMachine}; +/// Set value of scratch register X. pub unsafe fn set_x(sm: &mut StateMachine, value: u32) { const OUT: u16 = InstructionOperands::OUT { destination: OutDestination::X, @@ -12,6 +14,7 @@ pub unsafe fn set_x(sm: &mut StateMachine(sm: &mut StateMachine) -> u32 { const IN: u16 = InstructionOperands::IN { source: InSource::X, @@ -22,6 +25,7 @@ pub unsafe fn get_x(sm: &mut StateMachine(sm: &mut StateMachine, value: u32) { const OUT: u16 = InstructionOperands::OUT { destination: OutDestination::Y, @@ -32,6 +36,7 @@ pub unsafe fn set_y(sm: &mut StateMachine(sm: &mut StateMachine) -> u32 { const IN: u16 = InstructionOperands::IN { source: InSource::Y, @@ -43,6 +48,7 @@ pub unsafe fn get_y(sm: &mut StateMachine(sm: &mut StateMachine, data: u8) { let set: u16 = InstructionOperands::SET { destination: SetDestination::PINDIRS, @@ -52,6 +58,7 @@ pub unsafe fn set_pindir(sm: &mut StateMachine

(sm: &mut StateMachine, data: u8) { let set: u16 = InstructionOperands::SET { destination: SetDestination::PINS, @@ -61,6 +68,7 @@ pub unsafe fn set_pin(sm: &mut StateMachine(sm: &mut StateMachine, data: u32) { const OUT: u16 = InstructionOperands::OUT { destination: OutDestination::PINS, @@ -70,6 +78,8 @@ pub unsafe fn set_out_pin(sm: &mut StateMachine< sm.tx().push(data); sm.exec_instr(OUT); } + +/// Out instruction for pindir destination. pub unsafe fn set_out_pindir(sm: &mut StateMachine, data: u32) { const OUT: u16 = InstructionOperands::OUT { destination: OutDestination::PINDIRS, @@ -80,6 +90,7 @@ pub unsafe fn set_out_pindir(sm: &mut StateMachi sm.exec_instr(OUT); } +/// Jump instruction to address. pub unsafe fn exec_jmp(sm: &mut StateMachine, to_addr: u8) { let jmp: u16 = InstructionOperands::JMP { address: to_addr, diff --git a/embassy-rp/src/pio.rs b/embassy-rp/src/pio/mod.rs similarity index 85% rename from embassy-rp/src/pio.rs rename to embassy-rp/src/pio/mod.rs index 97dfce2e6..ae91d1e83 100644 --- a/embassy-rp/src/pio.rs +++ b/embassy-rp/src/pio/mod.rs @@ -19,8 +19,11 @@ use crate::gpio::{self, AnyPin, Drive, Level, Pull, SlewRate}; use crate::interrupt::typelevel::{Binding, Handler, Interrupt}; use crate::pac::dma::vals::TreqSel; use crate::relocate::RelocatedProgram; -use crate::{pac, peripherals, pio_instr_util, RegExt}; +use crate::{pac, peripherals, RegExt}; +pub mod instr; + +/// Wakers for interrupts and FIFOs. pub struct Wakers([AtomicWaker; 12]); impl Wakers { @@ -38,6 +41,7 @@ impl Wakers { } } +/// FIFO config. #[derive(Clone, Copy, PartialEq, Eq, Default, Debug)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] #[repr(u8)] @@ -51,6 +55,8 @@ pub enum FifoJoin { TxOnly, } +/// Shift direction. +#[allow(missing_docs)] #[derive(Clone, Copy, PartialEq, Eq, Default, Debug)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] #[repr(u8)] @@ -60,6 +66,8 @@ pub enum ShiftDirection { Left = 0, } +/// Pin direction. +#[allow(missing_docs)] #[derive(Clone, Copy, PartialEq, Eq, Debug)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] #[repr(u8)] @@ -68,12 +76,15 @@ pub enum Direction { Out = 1, } +/// Which fifo level to use in status check. #[derive(Clone, Copy, PartialEq, Eq, Default, Debug)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] #[repr(u8)] pub enum StatusSource { #[default] + /// All-ones if TX FIFO level < N, otherwise all-zeroes. TxFifoLevel = 0, + /// All-ones if RX FIFO level < N, otherwise all-zeroes. RxFifoLevel = 1, } @@ -81,6 +92,7 @@ const RXNEMPTY_MASK: u32 = 1 << 0; const TXNFULL_MASK: u32 = 1 << 4; const SMIRQ_MASK: u32 = 1 << 8; +/// Interrupt handler for PIO. pub struct InterruptHandler { _pio: PhantomData, } @@ -105,6 +117,7 @@ pub struct FifoOutFuture<'a, 'd, PIO: Instance, const SM: usize> { } impl<'a, 'd, PIO: Instance, const SM: usize> FifoOutFuture<'a, 'd, PIO, SM> { + /// Create a new future waiting for TX-FIFO to become writable. pub fn new(sm: &'a mut StateMachineTx<'d, PIO, SM>, value: u32) -> Self { FifoOutFuture { sm_tx: sm, value } } @@ -136,13 +149,14 @@ impl<'a, 'd, PIO: Instance, const SM: usize> Drop for FifoOutFuture<'a, 'd, PIO, } } -/// Future that waits for RX-FIFO to become readable +/// Future that waits for RX-FIFO to become readable. #[must_use = "futures do nothing unless you `.await` or poll them"] pub struct FifoInFuture<'a, 'd, PIO: Instance, const SM: usize> { sm_rx: &'a mut StateMachineRx<'d, PIO, SM>, } impl<'a, 'd, PIO: Instance, const SM: usize> FifoInFuture<'a, 'd, PIO, SM> { + /// Create future that waits for RX-FIFO to become readable. pub fn new(sm: &'a mut StateMachineRx<'d, PIO, SM>) -> Self { FifoInFuture { sm_rx: sm } } @@ -207,6 +221,7 @@ impl<'a, 'd, PIO: Instance> Drop for IrqFuture<'a, 'd, PIO> { } } +/// Type representing a PIO pin. pub struct Pin<'l, PIO: Instance> { pin: PeripheralRef<'l, AnyPin>, pio: PhantomData, @@ -226,7 +241,7 @@ impl<'l, PIO: Instance> Pin<'l, PIO> { }); } - // Set the pin's slew rate. + /// Set the pin's slew rate. #[inline] pub fn set_slew_rate(&mut self, slew_rate: SlewRate) { self.pin.pad_ctrl().modify(|w| { @@ -251,6 +266,7 @@ impl<'l, PIO: Instance> Pin<'l, PIO> { }); } + /// Set the pin's input sync bypass. pub fn set_input_sync_bypass<'a>(&mut self, bypass: bool) { let mask = 1 << self.pin(); if bypass { @@ -260,28 +276,34 @@ impl<'l, PIO: Instance> Pin<'l, PIO> { } } + /// Get the underlying pin number. pub fn pin(&self) -> u8 { self.pin._pin() } } +/// Type representing a state machine RX FIFO. pub struct StateMachineRx<'d, PIO: Instance, const SM: usize> { pio: PhantomData<&'d mut PIO>, } impl<'d, PIO: Instance, const SM: usize> StateMachineRx<'d, PIO, SM> { + /// Check if RX FIFO is empty. pub fn empty(&self) -> bool { PIO::PIO.fstat().read().rxempty() & (1u8 << SM) != 0 } + /// Check if RX FIFO is full. pub fn full(&self) -> bool { PIO::PIO.fstat().read().rxfull() & (1u8 << SM) != 0 } + /// Check RX FIFO level. pub fn level(&self) -> u8 { (PIO::PIO.flevel().read().0 >> (SM * 8 + 4)) as u8 & 0x0f } + /// Check if state machine has stalled on full RX FIFO. pub fn stalled(&self) -> bool { let fdebug = PIO::PIO.fdebug(); let ret = fdebug.read().rxstall() & (1 << SM) != 0; @@ -291,6 +313,7 @@ impl<'d, PIO: Instance, const SM: usize> StateMachineRx<'d, PIO, SM> { ret } + /// Check if RX FIFO underflow (i.e. read-on-empty by the system) has occurred. pub fn underflowed(&self) -> bool { let fdebug = PIO::PIO.fdebug(); let ret = fdebug.read().rxunder() & (1 << SM) != 0; @@ -300,10 +323,12 @@ impl<'d, PIO: Instance, const SM: usize> StateMachineRx<'d, PIO, SM> { ret } + /// Pull data from RX FIFO. pub fn pull(&mut self) -> u32 { PIO::PIO.rxf(SM).read() } + /// Attempt pulling data from RX FIFO. pub fn try_pull(&mut self) -> Option { if self.empty() { return None; @@ -311,10 +336,12 @@ impl<'d, PIO: Instance, const SM: usize> StateMachineRx<'d, PIO, SM> { Some(self.pull()) } + /// Wait for RX FIFO readable. pub fn wait_pull<'a>(&'a mut self) -> FifoInFuture<'a, 'd, PIO, SM> { FifoInFuture::new(self) } + /// Prepare DMA transfer from RX FIFO. pub fn dma_pull<'a, C: Channel, W: Word>( &'a mut self, ch: PeripheralRef<'a, C>, @@ -340,22 +367,28 @@ impl<'d, PIO: Instance, const SM: usize> StateMachineRx<'d, PIO, SM> { } } +/// Type representing a state machine TX FIFO. pub struct StateMachineTx<'d, PIO: Instance, const SM: usize> { pio: PhantomData<&'d mut PIO>, } impl<'d, PIO: Instance, const SM: usize> StateMachineTx<'d, PIO, SM> { + /// Check if TX FIFO is empty. pub fn empty(&self) -> bool { PIO::PIO.fstat().read().txempty() & (1u8 << SM) != 0 } + + /// Check if TX FIFO is full. pub fn full(&self) -> bool { PIO::PIO.fstat().read().txfull() & (1u8 << SM) != 0 } + /// Check TX FIFO level. pub fn level(&self) -> u8 { (PIO::PIO.flevel().read().0 >> (SM * 8)) as u8 & 0x0f } + /// Check state machine has stalled on empty TX FIFO. pub fn stalled(&self) -> bool { let fdebug = PIO::PIO.fdebug(); let ret = fdebug.read().txstall() & (1 << SM) != 0; @@ -365,6 +398,7 @@ impl<'d, PIO: Instance, const SM: usize> StateMachineTx<'d, PIO, SM> { ret } + /// Check if FIFO overflowed. pub fn overflowed(&self) -> bool { let fdebug = PIO::PIO.fdebug(); let ret = fdebug.read().txover() & (1 << SM) != 0; @@ -374,10 +408,12 @@ impl<'d, PIO: Instance, const SM: usize> StateMachineTx<'d, PIO, SM> { ret } + /// Force push data to TX FIFO. pub fn push(&mut self, v: u32) { PIO::PIO.txf(SM).write_value(v); } + /// Attempt to push data to TX FIFO. pub fn try_push(&mut self, v: u32) -> bool { if self.full() { return false; @@ -386,10 +422,12 @@ impl<'d, PIO: Instance, const SM: usize> StateMachineTx<'d, PIO, SM> { true } + /// Wait until FIFO is ready for writing. pub fn wait_push<'a>(&'a mut self, value: u32) -> FifoOutFuture<'a, 'd, PIO, SM> { FifoOutFuture::new(self, value) } + /// Prepare a DMA transfer to TX FIFO. pub fn dma_push<'a, C: Channel, W: Word>(&'a mut self, ch: PeripheralRef<'a, C>, data: &'a [W]) -> Transfer<'a, C> { let pio_no = PIO::PIO_NO; let p = ch.regs(); @@ -411,6 +449,7 @@ impl<'d, PIO: Instance, const SM: usize> StateMachineTx<'d, PIO, SM> { } } +/// A type representing a single PIO state machine. pub struct StateMachine<'d, PIO: Instance, const SM: usize> { rx: StateMachineRx<'d, PIO, SM>, tx: StateMachineTx<'d, PIO, SM>, @@ -430,52 +469,78 @@ fn assert_consecutive<'d, PIO: Instance>(pins: &[&Pin<'d, PIO>]) { } } +/// PIO Execution config. #[derive(Clone, Copy, Default, Debug)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] #[non_exhaustive] pub struct ExecConfig { + /// If true, the MSB of the Delay/Side-set instruction field is used as side-set enable, rather than a side-set data bit. pub side_en: bool, + /// If true, side-set data is asserted to pin directions, instead of pin values. pub side_pindir: bool, + /// Pin to trigger jump. pub jmp_pin: u8, + /// After reaching this address, execution is wrapped to wrap_bottom. pub wrap_top: u8, + /// After reaching wrap_top, execution is wrapped to this address. pub wrap_bottom: u8, } +/// PIO shift register config for input or output. #[derive(Clone, Copy, Default, Debug)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] pub struct ShiftConfig { + /// Number of bits shifted out of OSR before autopull. pub threshold: u8, + /// Shift direction. pub direction: ShiftDirection, + /// For output: Pull automatically output shift register is emptied. + /// For input: Push automatically when the input shift register is filled. pub auto_fill: bool, } +/// PIO pin config. #[derive(Clone, Copy, Default, Debug)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] pub struct PinConfig { + /// The number of MSBs of the Delay/Side-set instruction field which are used for side-set. pub sideset_count: u8, + /// The number of pins asserted by a SET. In the range 0 to 5 inclusive. pub set_count: u8, + /// The number of pins asserted by an OUT PINS, OUT PINDIRS or MOV PINS instruction. In the range 0 to 32 inclusive. pub out_count: u8, + /// The pin which is mapped to the least-significant bit of a state machine's IN data bus. pub in_base: u8, + /// The lowest-numbered pin that will be affected by a side-set operation. pub sideset_base: u8, + /// The lowest-numbered pin that will be affected by a SET PINS or SET PINDIRS instruction. pub set_base: u8, + /// The lowest-numbered pin that will be affected by an OUT PINS, OUT PINDIRS or MOV PINS instruction. pub out_base: u8, } +/// PIO config. #[derive(Clone, Copy, Debug)] pub struct Config<'d, PIO: Instance> { - // CLKDIV + /// Clock divisor register for state machines. pub clock_divider: FixedU32, - // EXECCTRL + /// Which data bit to use for inline OUT enable. pub out_en_sel: u8, + /// Use a bit of OUT data as an auxiliary write enable When used in conjunction with OUT_STICKY. pub inline_out_en: bool, + /// Continuously assert the most recent OUT/SET to the pins. pub out_sticky: bool, + /// Which source to use for checking status. pub status_sel: StatusSource, + /// Status comparison level. pub status_n: u8, exec: ExecConfig, origin: Option, - // SHIFTCTRL + /// Configure FIFO allocation. pub fifo_join: FifoJoin, + /// Input shifting config. pub shift_in: ShiftConfig, + /// Output shifting config. pub shift_out: ShiftConfig, // PINCTRL pins: PinConfig, @@ -505,16 +570,22 @@ impl<'d, PIO: Instance> Default for Config<'d, PIO> { } impl<'d, PIO: Instance> Config<'d, PIO> { + /// Get execution configuration. pub fn get_exec(&self) -> ExecConfig { self.exec } + + /// Update execution configuration. pub unsafe fn set_exec(&mut self, e: ExecConfig) { self.exec = e; } + /// Get pin configuration. pub fn get_pins(&self) -> PinConfig { self.pins } + + /// Update pin configuration. pub unsafe fn set_pins(&mut self, p: PinConfig) { self.pins = p; } @@ -537,6 +608,7 @@ impl<'d, PIO: Instance> Config<'d, PIO> { self.origin = Some(prog.origin); } + /// Set pin used to signal jump. pub fn set_jmp_pin(&mut self, pin: &Pin<'d, PIO>) { self.exec.jmp_pin = pin.pin(); } @@ -571,6 +643,7 @@ impl<'d, PIO: Instance> Config<'d, PIO> { } impl<'d, PIO: Instance + 'd, const SM: usize> StateMachine<'d, PIO, SM> { + /// Set the config for a given PIO state machine. pub fn set_config(&mut self, config: &Config<'d, PIO>) { // sm expects 0 for 65536, truncation makes that happen assert!(config.clock_divider <= 65536, "clkdiv must be <= 65536"); @@ -617,7 +690,7 @@ impl<'d, PIO: Instance + 'd, const SM: usize> StateMachine<'d, PIO, SM> { w.set_out_base(config.pins.out_base); }); if let Some(origin) = config.origin { - unsafe { pio_instr_util::exec_jmp(self, origin) } + unsafe { instr::exec_jmp(self, origin) } } } @@ -626,10 +699,13 @@ impl<'d, PIO: Instance + 'd, const SM: usize> StateMachine<'d, PIO, SM> { PIO::PIO.sm(SM) } + /// Restart this state machine. pub fn restart(&mut self) { let mask = 1u8 << SM; PIO::PIO.ctrl().write_set(|w| w.set_sm_restart(mask)); } + + /// Enable state machine. pub fn set_enable(&mut self, enable: bool) { let mask = 1u8 << SM; if enable { @@ -639,10 +715,12 @@ impl<'d, PIO: Instance + 'd, const SM: usize> StateMachine<'d, PIO, SM> { } } + /// Check if state machine is enabled. pub fn is_enabled(&self) -> bool { PIO::PIO.ctrl().read().sm_enable() & (1u8 << SM) != 0 } + /// Restart a state machine's clock divider from an initial phase of 0. pub fn clkdiv_restart(&mut self) { let mask = 1u8 << SM; PIO::PIO.ctrl().write_set(|w| w.set_clkdiv_restart(mask)); @@ -690,6 +768,7 @@ impl<'d, PIO: Instance + 'd, const SM: usize> StateMachine<'d, PIO, SM> { }); } + /// Flush FIFOs for state machine. pub fn clear_fifos(&mut self) { // Toggle FJOIN_RX to flush FIFOs let shiftctrl = Self::this_sm().shiftctrl(); @@ -701,21 +780,31 @@ impl<'d, PIO: Instance + 'd, const SM: usize> StateMachine<'d, PIO, SM> { }); } + /// Instruct state machine to execute a given instructions + /// + /// SAFETY: The state machine must be in a state where executing + /// an arbitrary instruction does not crash it. pub unsafe fn exec_instr(&mut self, instr: u16) { Self::this_sm().instr().write(|w| w.set_instr(instr)); } + /// Return a read handle for reading state machine outputs. pub fn rx(&mut self) -> &mut StateMachineRx<'d, PIO, SM> { &mut self.rx } + + /// Return a handle for writing to inputs. pub fn tx(&mut self) -> &mut StateMachineTx<'d, PIO, SM> { &mut self.tx } + + /// Return both read and write handles for the state machine. pub fn rx_tx(&mut self) -> (&mut StateMachineRx<'d, PIO, SM>, &mut StateMachineTx<'d, PIO, SM>) { (&mut self.rx, &mut self.tx) } } +/// PIO handle. pub struct Common<'d, PIO: Instance> { instructions_used: u32, pio: PhantomData<&'d mut PIO>, @@ -727,18 +816,25 @@ impl<'d, PIO: Instance> Drop for Common<'d, PIO> { } } +/// Memory of PIO instance. pub struct InstanceMemory<'d, PIO: Instance> { used_mask: u32, pio: PhantomData<&'d mut PIO>, } +/// A loaded PIO program. pub struct LoadedProgram<'d, PIO: Instance> { + /// Memory used by program. pub used_memory: InstanceMemory<'d, PIO>, + /// Program origin for loading. pub origin: u8, + /// Wrap controls what to do once program is done executing. pub wrap: Wrap, + /// Data for 'side' set instruction parameters. pub side_set: SideSet, } +/// Errors loading a PIO program. #[derive(Clone, Copy, PartialEq, Eq, Debug)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] pub enum LoadError { @@ -834,6 +930,7 @@ impl<'d, PIO: Instance> Common<'d, PIO> { self.instructions_used &= !instrs.used_mask; } + /// Bypass flipflop synchronizer on GPIO inputs. pub fn set_input_sync_bypass<'a>(&'a mut self, bypass: u32, mask: u32) { // this can interfere with per-pin bypass functions. splitting the // modification is going to be fine since nothing that relies on @@ -842,6 +939,7 @@ impl<'d, PIO: Instance> Common<'d, PIO> { PIO::PIO.input_sync_bypass().write_clear(|w| *w = mask & !bypass); } + /// Get bypass configuration. pub fn get_input_sync_bypass(&self) -> u32 { PIO::PIO.input_sync_bypass().read() } @@ -861,6 +959,7 @@ impl<'d, PIO: Instance> Common<'d, PIO> { } } + /// Apply changes to all state machines in a batch. pub fn apply_sm_batch(&mut self, f: impl FnOnce(&mut PioBatch<'d, PIO>)) { let mut batch = PioBatch { clkdiv_restart: 0, @@ -878,6 +977,7 @@ impl<'d, PIO: Instance> Common<'d, PIO> { } } +/// Represents multiple state machines in a single type. pub struct PioBatch<'a, PIO: Instance> { clkdiv_restart: u8, sm_restart: u8, @@ -887,25 +987,25 @@ pub struct PioBatch<'a, PIO: Instance> { } impl<'a, PIO: Instance> PioBatch<'a, PIO> { - pub fn restart_clockdiv(&mut self, _sm: &mut StateMachine<'a, PIO, SM>) { - self.clkdiv_restart |= 1 << SM; - } - + /// Restart a state machine's clock divider from an initial phase of 0. pub fn restart(&mut self, _sm: &mut StateMachine<'a, PIO, SM>) { self.clkdiv_restart |= 1 << SM; } + /// Enable a specific state machine. pub fn set_enable(&mut self, _sm: &mut StateMachine<'a, PIO, SM>, enable: bool) { self.sm_enable_mask |= 1 << SM; self.sm_enable |= (enable as u8) << SM; } } +/// Type representing a PIO interrupt. pub struct Irq<'d, PIO: Instance, const N: usize> { pio: PhantomData<&'d mut PIO>, } impl<'d, PIO: Instance, const N: usize> Irq<'d, PIO, N> { + /// Wait for an IRQ to fire. pub fn wait<'a>(&'a mut self) -> IrqFuture<'a, 'd, PIO> { IrqFuture { pio: PhantomData, @@ -914,59 +1014,79 @@ impl<'d, PIO: Instance, const N: usize> Irq<'d, PIO, N> { } } +/// Interrupt flags for a PIO instance. #[derive(Clone)] pub struct IrqFlags<'d, PIO: Instance> { pio: PhantomData<&'d mut PIO>, } impl<'d, PIO: Instance> IrqFlags<'d, PIO> { + /// Check if interrupt fired. pub fn check(&self, irq_no: u8) -> bool { assert!(irq_no < 8); self.check_any(1 << irq_no) } + /// Check if any of the interrupts in the bitmap fired. pub fn check_any(&self, irqs: u8) -> bool { PIO::PIO.irq().read().irq() & irqs != 0 } + /// Check if all interrupts have fired. pub fn check_all(&self, irqs: u8) -> bool { PIO::PIO.irq().read().irq() & irqs == irqs } + /// Clear interrupt for interrupt number. pub fn clear(&self, irq_no: usize) { assert!(irq_no < 8); self.clear_all(1 << irq_no); } + /// Clear all interrupts set in the bitmap. pub fn clear_all(&self, irqs: u8) { PIO::PIO.irq().write(|w| w.set_irq(irqs)) } + /// Fire a given interrupt. pub fn set(&self, irq_no: usize) { assert!(irq_no < 8); self.set_all(1 << irq_no); } + /// Fire all interrupts. pub fn set_all(&self, irqs: u8) { PIO::PIO.irq_force().write(|w| w.set_irq_force(irqs)) } } +/// An instance of the PIO driver. pub struct Pio<'d, PIO: Instance> { + /// PIO handle. pub common: Common<'d, PIO>, + /// PIO IRQ flags. pub irq_flags: IrqFlags<'d, PIO>, + /// IRQ0 configuration. pub irq0: Irq<'d, PIO, 0>, + /// IRQ1 configuration. pub irq1: Irq<'d, PIO, 1>, + /// IRQ2 configuration. pub irq2: Irq<'d, PIO, 2>, + /// IRQ3 configuration. pub irq3: Irq<'d, PIO, 3>, + /// State machine 0 handle. pub sm0: StateMachine<'d, PIO, 0>, + /// State machine 1 handle. pub sm1: StateMachine<'d, PIO, 1>, + /// State machine 2 handle. pub sm2: StateMachine<'d, PIO, 2>, + /// State machine 3 handle. pub sm3: StateMachine<'d, PIO, 3>, _pio: PhantomData<&'d mut PIO>, } impl<'d, PIO: Instance> Pio<'d, PIO> { + /// Create a new instance of a PIO peripheral. pub fn new(_pio: impl Peripheral

+ 'd, _irq: impl Binding>) -> Self { PIO::state().users.store(5, Ordering::Release); PIO::state().used_pins.store(0, Ordering::Release); @@ -1003,9 +1123,10 @@ impl<'d, PIO: Instance> Pio<'d, PIO> { } } -// we need to keep a record of which pins are assigned to each PIO. make_pio_pin -// notionally takes ownership of the pin it is given, but the wrapped pin cannot -// be treated as an owned resource since dropping it would have to deconfigure +/// Representation of the PIO state keeping a record of which pins are assigned to +/// each PIO. +// make_pio_pin notionally takes ownership of the pin it is given, but the wrapped pin +// cannot be treated as an owned resource since dropping it would have to deconfigure // the pin, breaking running state machines in the process. pins are also shared // between all state machines, which makes ownership even messier to track any // other way. @@ -1059,6 +1180,7 @@ mod sealed { } } +/// PIO instance. pub trait Instance: sealed::Instance + Sized + Unpin {} macro_rules! impl_pio { @@ -1076,6 +1198,7 @@ macro_rules! impl_pio { impl_pio!(PIO0, 0, PIO0, PIO0_0, PIO0_IRQ_0); impl_pio!(PIO1, 1, PIO1, PIO1_0, PIO1_IRQ_0); +/// PIO pin. pub trait PioPin: sealed::PioPin + gpio::Pin {} macro_rules! impl_pio_pin { diff --git a/embassy-rp/src/uart/buffered.rs b/embassy-rp/src/uart/buffered.rs index ca030f560..f14e08525 100644 --- a/embassy-rp/src/uart/buffered.rs +++ b/embassy-rp/src/uart/buffered.rs @@ -38,15 +38,18 @@ impl State { } } +/// Buffered UART driver. pub struct BufferedUart<'d, T: Instance> { pub(crate) rx: BufferedUartRx<'d, T>, pub(crate) tx: BufferedUartTx<'d, T>, } +/// Buffered UART RX handle. pub struct BufferedUartRx<'d, T: Instance> { pub(crate) phantom: PhantomData<&'d mut T>, } +/// Buffered UART TX handle. pub struct BufferedUartTx<'d, T: Instance> { pub(crate) phantom: PhantomData<&'d mut T>, } @@ -84,6 +87,7 @@ pub(crate) fn init_buffers<'d, T: Instance + 'd>( } impl<'d, T: Instance> BufferedUart<'d, T> { + /// Create a buffered UART instance. pub fn new( _uart: impl Peripheral

+ 'd, irq: impl Binding>, @@ -104,6 +108,7 @@ impl<'d, T: Instance> BufferedUart<'d, T> { } } + /// Create a buffered UART instance with flow control. pub fn new_with_rtscts( _uart: impl Peripheral

+ 'd, irq: impl Binding>, @@ -132,32 +137,39 @@ impl<'d, T: Instance> BufferedUart<'d, T> { } } + /// Write to UART TX buffer blocking execution until done. pub fn blocking_write(&mut self, buffer: &[u8]) -> Result { self.tx.blocking_write(buffer) } + /// Flush UART TX blocking execution until done. pub fn blocking_flush(&mut self) -> Result<(), Error> { self.tx.blocking_flush() } + /// Read from UART RX buffer blocking execution until done. pub fn blocking_read(&mut self, buffer: &mut [u8]) -> Result { self.rx.blocking_read(buffer) } + /// Check if UART is busy transmitting. pub fn busy(&self) -> bool { self.tx.busy() } + /// Wait until TX is empty and send break condition. pub async fn send_break(&mut self, bits: u32) { self.tx.send_break(bits).await } + /// Split into separate RX and TX handles. pub fn split(self) -> (BufferedUartRx<'d, T>, BufferedUartTx<'d, T>) { (self.rx, self.tx) } } impl<'d, T: Instance> BufferedUartRx<'d, T> { + /// Create a new buffered UART RX. pub fn new( _uart: impl Peripheral

+ 'd, irq: impl Binding>, @@ -173,6 +185,7 @@ impl<'d, T: Instance> BufferedUartRx<'d, T> { Self { phantom: PhantomData } } + /// Create a new buffered UART RX with flow control. pub fn new_with_rts( _uart: impl Peripheral

+ 'd, irq: impl Binding>, @@ -253,6 +266,7 @@ impl<'d, T: Instance> BufferedUartRx<'d, T> { Poll::Ready(result) } + /// Read from UART RX buffer blocking execution until done. pub fn blocking_read(&mut self, buf: &mut [u8]) -> Result { loop { match Self::try_read(buf) { @@ -303,6 +317,7 @@ impl<'d, T: Instance> BufferedUartRx<'d, T> { } impl<'d, T: Instance> BufferedUartTx<'d, T> { + /// Create a new buffered UART TX. pub fn new( _uart: impl Peripheral

+ 'd, irq: impl Binding>, @@ -318,6 +333,7 @@ impl<'d, T: Instance> BufferedUartTx<'d, T> { Self { phantom: PhantomData } } + /// Create a new buffered UART TX with flow control. pub fn new_with_cts( _uart: impl Peripheral

+ 'd, irq: impl Binding>, @@ -373,6 +389,7 @@ impl<'d, T: Instance> BufferedUartTx<'d, T> { }) } + /// Write to UART TX buffer blocking execution until done. pub fn blocking_write(&mut self, buf: &[u8]) -> Result { if buf.is_empty() { return Ok(0); @@ -398,6 +415,7 @@ impl<'d, T: Instance> BufferedUartTx<'d, T> { } } + /// Flush UART TX blocking execution until done. pub fn blocking_flush(&mut self) -> Result<(), Error> { loop { let state = T::buffered_state(); @@ -407,6 +425,7 @@ impl<'d, T: Instance> BufferedUartTx<'d, T> { } } + /// Check if UART is busy. pub fn busy(&self) -> bool { T::regs().uartfr().read().busy() } @@ -466,6 +485,7 @@ impl<'d, T: Instance> Drop for BufferedUartTx<'d, T> { } } +/// Interrupt handler. pub struct BufferedInterruptHandler { _uart: PhantomData, } diff --git a/embassy-rp/src/uart/mod.rs b/embassy-rp/src/uart/mod.rs index f82b9036b..26f21193a 100644 --- a/embassy-rp/src/uart/mod.rs +++ b/embassy-rp/src/uart/mod.rs @@ -938,9 +938,13 @@ macro_rules! impl_instance { impl_instance!(UART0, UART0_IRQ, 20, 21); impl_instance!(UART1, UART1_IRQ, 22, 23); +/// Trait for TX pins. pub trait TxPin: sealed::TxPin + crate::gpio::Pin {} +/// Trait for RX pins. pub trait RxPin: sealed::RxPin + crate::gpio::Pin {} +/// Trait for Clear To Send (CTS) pins. pub trait CtsPin: sealed::CtsPin + crate::gpio::Pin {} +/// Trait for Request To Send (RTS) pins. pub trait RtsPin: sealed::RtsPin + crate::gpio::Pin {} macro_rules! impl_pin { diff --git a/embassy-rp/src/usb.rs b/embassy-rp/src/usb.rs index 4a74ee6f7..bcd848222 100644 --- a/embassy-rp/src/usb.rs +++ b/embassy-rp/src/usb.rs @@ -20,7 +20,9 @@ pub(crate) mod sealed { } } +/// USB peripheral instance. pub trait Instance: sealed::Instance + 'static { + /// Interrupt for this peripheral. type Interrupt: interrupt::typelevel::Interrupt; } @@ -96,6 +98,7 @@ impl EndpointData { } } +/// RP2040 USB driver handle. pub struct Driver<'d, T: Instance> { phantom: PhantomData<&'d mut T>, ep_in: [EndpointData; EP_COUNT], @@ -104,6 +107,7 @@ pub struct Driver<'d, T: Instance> { } impl<'d, T: Instance> Driver<'d, T> { + /// Create a new USB driver. pub fn new(_usb: impl Peripheral

+ 'd, _irq: impl Binding>) -> Self { T::Interrupt::unpend(); unsafe { T::Interrupt::enable() }; @@ -240,6 +244,7 @@ impl<'d, T: Instance> Driver<'d, T> { } } +/// USB interrupt handler. pub struct InterruptHandler { _uart: PhantomData, } @@ -342,6 +347,7 @@ impl<'d, T: Instance> driver::Driver<'d> for Driver<'d, T> { } } +/// Type representing the RP USB bus. pub struct Bus<'d, T: Instance> { phantom: PhantomData<&'d mut T>, ep_out: [EndpointData; EP_COUNT], @@ -461,6 +467,7 @@ trait Dir { fn waker(i: usize) -> &'static AtomicWaker; } +/// Type for In direction. pub enum In {} impl Dir for In { fn dir() -> Direction { @@ -473,6 +480,7 @@ impl Dir for In { } } +/// Type for Out direction. pub enum Out {} impl Dir for Out { fn dir() -> Direction { @@ -485,6 +493,7 @@ impl Dir for Out { } } +/// Endpoint for RP USB driver. pub struct Endpoint<'d, T: Instance, D> { _phantom: PhantomData<(&'d mut T, D)>, info: EndpointInfo, @@ -616,6 +625,7 @@ impl<'d, T: Instance> driver::EndpointIn for Endpoint<'d, T, In> { } } +/// Control pipe for RP USB driver. pub struct ControlPipe<'d, T: Instance> { _phantom: PhantomData<&'d mut T>, max_packet_size: u16, From 486b67e89522d7e36f6b1078ff8018d64447b39e Mon Sep 17 00:00:00 2001 From: Ulf Lilleengen Date: Tue, 19 Dec 2023 11:26:08 +0100 Subject: [PATCH 058/124] docs: document spi, rtc and rest of uart for embassy-rp --- embassy-rp/src/pwm.rs | 5 ++++ embassy-rp/src/rtc/mod.rs | 1 + embassy-rp/src/spi.rs | 31 ++++++++++++++++++++++++ embassy-rp/src/uart/mod.rs | 48 ++++++++++++++++++++++++++++++++++++-- 4 files changed, 83 insertions(+), 2 deletions(-) diff --git a/embassy-rp/src/pwm.rs b/embassy-rp/src/pwm.rs index 516b8254b..5b96557a3 100644 --- a/embassy-rp/src/pwm.rs +++ b/embassy-rp/src/pwm.rs @@ -61,9 +61,13 @@ impl Default for Config { } } +/// PWM input mode. pub enum InputMode { + /// Level mode. Level, + /// Rising edge mode. RisingEdge, + /// Falling edge mode. FallingEdge, } @@ -77,6 +81,7 @@ impl From for Divmode { } } +/// PWM driver. pub struct Pwm<'d, T: Channel> { inner: PeripheralRef<'d, T>, pin_a: Option>, diff --git a/embassy-rp/src/rtc/mod.rs b/embassy-rp/src/rtc/mod.rs index 60ca8627b..c3df3ee57 100644 --- a/embassy-rp/src/rtc/mod.rs +++ b/embassy-rp/src/rtc/mod.rs @@ -194,6 +194,7 @@ mod sealed { } } +/// RTC peripheral instance. pub trait Instance: sealed::Instance {} impl sealed::Instance for crate::peripherals::RTC { diff --git a/embassy-rp/src/spi.rs b/embassy-rp/src/spi.rs index 6ba985a65..a2a22ffe5 100644 --- a/embassy-rp/src/spi.rs +++ b/embassy-rp/src/spi.rs @@ -11,6 +11,7 @@ use crate::gpio::sealed::Pin as _; use crate::gpio::{AnyPin, Pin as GpioPin}; use crate::{pac, peripherals, Peripheral}; +/// SPI errors. #[derive(Debug, Clone, Copy, PartialEq, Eq)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] #[non_exhaustive] @@ -18,11 +19,15 @@ pub enum Error { // No errors for now } +/// SPI configuration. #[non_exhaustive] #[derive(Clone)] pub struct Config { + /// Frequency. pub frequency: u32, + /// Phase. pub phase: Phase, + /// Polarity. pub polarity: Polarity, } @@ -36,6 +41,7 @@ impl Default for Config { } } +/// SPI driver. pub struct Spi<'d, T: Instance, M: Mode> { inner: PeripheralRef<'d, T>, tx_dma: Option>, @@ -119,6 +125,7 @@ impl<'d, T: Instance, M: Mode> Spi<'d, T, M> { } } + /// Write data to SPI blocking execution until done. pub fn blocking_write(&mut self, data: &[u8]) -> Result<(), Error> { let p = self.inner.regs(); for &b in data { @@ -131,6 +138,7 @@ impl<'d, T: Instance, M: Mode> Spi<'d, T, M> { Ok(()) } + /// Transfer data in place to SPI blocking execution until done. pub fn blocking_transfer_in_place(&mut self, data: &mut [u8]) -> Result<(), Error> { let p = self.inner.regs(); for b in data { @@ -143,6 +151,7 @@ impl<'d, T: Instance, M: Mode> Spi<'d, T, M> { Ok(()) } + /// Read data from SPI blocking execution until done. pub fn blocking_read(&mut self, data: &mut [u8]) -> Result<(), Error> { let p = self.inner.regs(); for b in data { @@ -155,6 +164,7 @@ impl<'d, T: Instance, M: Mode> Spi<'d, T, M> { Ok(()) } + /// Transfer data to SPI blocking execution until done. pub fn blocking_transfer(&mut self, read: &mut [u8], write: &[u8]) -> Result<(), Error> { let p = self.inner.regs(); let len = read.len().max(write.len()); @@ -172,12 +182,14 @@ impl<'d, T: Instance, M: Mode> Spi<'d, T, M> { Ok(()) } + /// Block execution until SPI is done. pub fn flush(&mut self) -> Result<(), Error> { let p = self.inner.regs(); while p.sr().read().bsy() {} Ok(()) } + /// Set SPI frequency. pub fn set_frequency(&mut self, freq: u32) { let (presc, postdiv) = calc_prescs(freq); let p = self.inner.regs(); @@ -196,6 +208,7 @@ impl<'d, T: Instance, M: Mode> Spi<'d, T, M> { } impl<'d, T: Instance> Spi<'d, T, Blocking> { + /// Create an SPI driver in blocking mode. pub fn new_blocking( inner: impl Peripheral

+ 'd, clk: impl Peripheral

+ 'd> + 'd, @@ -216,6 +229,7 @@ impl<'d, T: Instance> Spi<'d, T, Blocking> { ) } + /// Create an SPI driver in blocking mode supporting writes only. pub fn new_blocking_txonly( inner: impl Peripheral

+ 'd, clk: impl Peripheral

+ 'd> + 'd, @@ -235,6 +249,7 @@ impl<'d, T: Instance> Spi<'d, T, Blocking> { ) } + /// Create an SPI driver in blocking mode supporting reads only. pub fn new_blocking_rxonly( inner: impl Peripheral

+ 'd, clk: impl Peripheral

+ 'd> + 'd, @@ -256,6 +271,7 @@ impl<'d, T: Instance> Spi<'d, T, Blocking> { } impl<'d, T: Instance> Spi<'d, T, Async> { + /// Create an SPI driver in async mode supporting DMA operations. pub fn new( inner: impl Peripheral

+ 'd, clk: impl Peripheral

+ 'd> + 'd, @@ -278,6 +294,7 @@ impl<'d, T: Instance> Spi<'d, T, Async> { ) } + /// Create an SPI driver in async mode supporting DMA write operations only. pub fn new_txonly( inner: impl Peripheral

+ 'd, clk: impl Peripheral

+ 'd> + 'd, @@ -298,6 +315,7 @@ impl<'d, T: Instance> Spi<'d, T, Async> { ) } + /// Create an SPI driver in async mode supporting DMA read operations only. pub fn new_rxonly( inner: impl Peripheral

+ 'd, clk: impl Peripheral

+ 'd> + 'd, @@ -318,6 +336,7 @@ impl<'d, T: Instance> Spi<'d, T, Async> { ) } + /// Write data to SPI using DMA. pub async fn write(&mut self, buffer: &[u8]) -> Result<(), Error> { let tx_ch = self.tx_dma.as_mut().unwrap(); let tx_transfer = unsafe { @@ -340,6 +359,7 @@ impl<'d, T: Instance> Spi<'d, T, Async> { Ok(()) } + /// Read data from SPI using DMA. pub async fn read(&mut self, buffer: &mut [u8]) -> Result<(), Error> { // Start RX first. Transfer starts when TX starts, if RX // is not started yet we might lose bytes. @@ -365,10 +385,12 @@ impl<'d, T: Instance> Spi<'d, T, Async> { Ok(()) } + /// Transfer data to SPI using DMA. pub async fn transfer(&mut self, rx_buffer: &mut [u8], tx_buffer: &[u8]) -> Result<(), Error> { self.transfer_inner(rx_buffer, tx_buffer).await } + /// Transfer data in place to SPI using DMA. pub async fn transfer_in_place(&mut self, words: &mut [u8]) -> Result<(), Error> { self.transfer_inner(words, words).await } @@ -434,7 +456,10 @@ mod sealed { } } +/// Mode. pub trait Mode: sealed::Mode {} + +/// SPI instance trait. pub trait Instance: sealed::Instance {} macro_rules! impl_instance { @@ -454,9 +479,13 @@ macro_rules! impl_instance { impl_instance!(SPI0, Spi0, 16, 17); impl_instance!(SPI1, Spi1, 18, 19); +/// CLK pin. pub trait ClkPin: GpioPin {} +/// CS pin. pub trait CsPin: GpioPin {} +/// MOSI pin. pub trait MosiPin: GpioPin {} +/// MISO pin. pub trait MisoPin: GpioPin {} macro_rules! impl_pin { @@ -503,7 +532,9 @@ macro_rules! impl_mode { }; } +/// Blocking mode. pub struct Blocking; +/// Async mode. pub struct Async; impl_mode!(Blocking); diff --git a/embassy-rp/src/uart/mod.rs b/embassy-rp/src/uart/mod.rs index 26f21193a..32be7661d 100644 --- a/embassy-rp/src/uart/mod.rs +++ b/embassy-rp/src/uart/mod.rs @@ -20,11 +20,16 @@ use crate::{interrupt, pac, peripherals, Peripheral, RegExt}; mod buffered; pub use buffered::{BufferedInterruptHandler, BufferedUart, BufferedUartRx, BufferedUartTx}; +/// Word length. #[derive(Clone, Copy, PartialEq, Eq, Debug)] pub enum DataBits { + /// 5 bits. DataBits5, + /// 6 bits. DataBits6, + /// 7 bits. DataBits7, + /// 8 bits. DataBits8, } @@ -39,13 +44,18 @@ impl DataBits { } } +/// Parity bit. #[derive(Clone, Copy, PartialEq, Eq, Debug)] pub enum Parity { + /// No parity. ParityNone, + /// Even parity. ParityEven, + /// Odd parity. ParityOdd, } +/// Stop bits. #[derive(Clone, Copy, PartialEq, Eq, Debug)] pub enum StopBits { #[doc = "1 stop bit"] @@ -54,20 +64,25 @@ pub enum StopBits { STOP2, } +/// UART config. #[non_exhaustive] #[derive(Clone, Copy, PartialEq, Eq, Debug)] pub struct Config { + /// Baud rate. pub baudrate: u32, + /// Word length. pub data_bits: DataBits, + /// Stop bits. pub stop_bits: StopBits, + /// Parity bit. pub parity: Parity, /// Invert the tx pin output pub invert_tx: bool, /// Invert the rx pin input pub invert_rx: bool, - // Invert the rts pin + /// Invert the rts pin pub invert_rts: bool, - // Invert the cts pin + /// Invert the cts pin pub invert_cts: bool, } @@ -102,21 +117,25 @@ pub enum Error { Framing, } +/// Internal DMA state of UART RX. pub struct DmaState { rx_err_waker: AtomicWaker, rx_errs: AtomicU16, } +/// UART driver. pub struct Uart<'d, T: Instance, M: Mode> { tx: UartTx<'d, T, M>, rx: UartRx<'d, T, M>, } +/// UART TX driver. pub struct UartTx<'d, T: Instance, M: Mode> { tx_dma: Option>, phantom: PhantomData<(&'d mut T, M)>, } +/// UART RX driver. pub struct UartRx<'d, T: Instance, M: Mode> { rx_dma: Option>, phantom: PhantomData<(&'d mut T, M)>, @@ -142,6 +161,7 @@ impl<'d, T: Instance, M: Mode> UartTx<'d, T, M> { } } + /// Transmit the provided buffer blocking execution until done. pub fn blocking_write(&mut self, buffer: &[u8]) -> Result<(), Error> { let r = T::regs(); for &b in buffer { @@ -151,12 +171,14 @@ impl<'d, T: Instance, M: Mode> UartTx<'d, T, M> { Ok(()) } + /// Flush UART TX blocking execution until done. pub fn blocking_flush(&mut self) -> Result<(), Error> { let r = T::regs(); while !r.uartfr().read().txfe() {} Ok(()) } + /// Check if UART is busy transmitting. pub fn busy(&self) -> bool { T::regs().uartfr().read().busy() } @@ -191,6 +213,8 @@ impl<'d, T: Instance, M: Mode> UartTx<'d, T, M> { } impl<'d, T: Instance> UartTx<'d, T, Blocking> { + /// Convert this uart TX instance into a buffered uart using the provided + /// irq and transmit buffer. pub fn into_buffered( self, irq: impl Binding>, @@ -203,6 +227,7 @@ impl<'d, T: Instance> UartTx<'d, T, Blocking> { } impl<'d, T: Instance> UartTx<'d, T, Async> { + /// Write to UART TX from the provided buffer using DMA. pub async fn write(&mut self, buffer: &[u8]) -> Result<(), Error> { let ch = self.tx_dma.as_mut().unwrap(); let transfer = unsafe { @@ -246,6 +271,7 @@ impl<'d, T: Instance, M: Mode> UartRx<'d, T, M> { } } + /// Read from UART RX blocking execution until done. pub fn blocking_read(&mut self, mut buffer: &mut [u8]) -> Result<(), Error> { while buffer.len() > 0 { let received = self.drain_fifo(buffer)?; @@ -294,6 +320,7 @@ impl<'d, T: Instance, M: Mode> Drop for UartRx<'d, T, M> { } impl<'d, T: Instance> UartRx<'d, T, Blocking> { + /// Create a new UART RX instance for blocking mode operations. pub fn new_blocking( _uart: impl Peripheral

+ 'd, rx: impl Peripheral

> + 'd, @@ -304,6 +331,8 @@ impl<'d, T: Instance> UartRx<'d, T, Blocking> { Self::new_inner(false, None) } + /// Convert this uart RX instance into a buffered uart using the provided + /// irq and receive buffer. pub fn into_buffered( self, irq: impl Binding>, @@ -315,6 +344,7 @@ impl<'d, T: Instance> UartRx<'d, T, Blocking> { } } +/// Interrupt handler. pub struct InterruptHandler { _uart: PhantomData, } @@ -338,6 +368,7 @@ impl interrupt::typelevel::Handler for InterruptHandl } impl<'d, T: Instance> UartRx<'d, T, Async> { + /// Read from UART RX into the provided buffer. pub async fn read(&mut self, buffer: &mut [u8]) -> Result<(), Error> { // clear error flags before we drain the fifo. errors that have accumulated // in the flags will also be present in the fifo. @@ -458,6 +489,8 @@ impl<'d, T: Instance> Uart<'d, T, Blocking> { ) } + /// Convert this uart instance into a buffered uart using the provided + /// irq, transmit and receive buffers. pub fn into_buffered( self, irq: impl Binding>, @@ -667,22 +700,27 @@ impl<'d, T: Instance + 'd, M: Mode> Uart<'d, T, M> { } impl<'d, T: Instance, M: Mode> Uart<'d, T, M> { + /// Transmit the provided buffer blocking execution until done. pub fn blocking_write(&mut self, buffer: &[u8]) -> Result<(), Error> { self.tx.blocking_write(buffer) } + /// Flush UART TX blocking execution until done. pub fn blocking_flush(&mut self) -> Result<(), Error> { self.tx.blocking_flush() } + /// Read from UART RX blocking execution until done. pub fn blocking_read(&mut self, buffer: &mut [u8]) -> Result<(), Error> { self.rx.blocking_read(buffer) } + /// Check if UART is busy transmitting. pub fn busy(&self) -> bool { self.tx.busy() } + /// Wait until TX is empty and send break condition. pub async fn send_break(&mut self, bits: u32) { self.tx.send_break(bits).await } @@ -695,10 +733,12 @@ impl<'d, T: Instance, M: Mode> Uart<'d, T, M> { } impl<'d, T: Instance> Uart<'d, T, Async> { + /// Write to UART TX from the provided buffer. pub async fn write(&mut self, buffer: &[u8]) -> Result<(), Error> { self.tx.write(buffer).await } + /// Read from UART RX into the provided buffer. pub async fn read(&mut self, buffer: &mut [u8]) -> Result<(), Error> { self.rx.read(buffer).await } @@ -889,6 +929,7 @@ mod sealed { pub trait RtsPin {} } +/// UART mode. pub trait Mode: sealed::Mode {} macro_rules! impl_mode { @@ -898,12 +939,15 @@ macro_rules! impl_mode { }; } +/// Blocking mode. pub struct Blocking; +/// Async mode. pub struct Async; impl_mode!(Blocking); impl_mode!(Async); +/// UART instance trait. pub trait Instance: sealed::Instance {} macro_rules! impl_instance { From 3e2e109437d8f5f4bcdd59dac5fe9f3a7bf9f047 Mon Sep 17 00:00:00 2001 From: eZio Pan Date: Tue, 19 Dec 2023 19:09:06 +0800 Subject: [PATCH 059/124] update metapac dep --- embassy-stm32/Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/embassy-stm32/Cargo.toml b/embassy-stm32/Cargo.toml index 4a7a2f2c9..7f2cf6bfb 100644 --- a/embassy-stm32/Cargo.toml +++ b/embassy-stm32/Cargo.toml @@ -58,7 +58,7 @@ rand_core = "0.6.3" sdio-host = "0.5.0" embedded-sdmmc = { git = "https://github.com/embassy-rs/embedded-sdmmc-rs", rev = "a4f293d3a6f72158385f79c98634cb8a14d0d2fc", optional = true } critical-section = "1.1" -stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-91cee0d1fdcb4e447b65a09756b506f4af91b7e2" } +stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-2234f380f51d16d0398b8e547088b33ea623cc7c" } vcell = "0.1.3" bxcan = "0.7.0" nb = "1.0.0" @@ -76,7 +76,7 @@ critical-section = { version = "1.1", features = ["std"] } [build-dependencies] proc-macro2 = "1.0.36" quote = "1.0.15" -stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-91cee0d1fdcb4e447b65a09756b506f4af91b7e2", default-features = false, features = ["metadata"]} +stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-2234f380f51d16d0398b8e547088b33ea623cc7c", default-features = false, features = ["metadata"]} [features] From f4b77c967fec9edacc6818aa8d935fda60bc743f Mon Sep 17 00:00:00 2001 From: Ulf Lilleengen Date: Tue, 19 Dec 2023 14:19:46 +0100 Subject: [PATCH 060/124] docs: document all embassy-rp public apis Enable missing doc warnings. --- embassy-rp/src/adc.rs | 24 ++++++++ embassy-rp/src/clocks.rs | 97 +++++++++++++++++++++++++++++++-- embassy-rp/src/dma.rs | 20 +++++++ embassy-rp/src/flash.rs | 42 +++++++++++++- embassy-rp/src/gpio.rs | 68 ++++++++++++++++++++++- embassy-rp/src/i2c.rs | 22 ++++++++ embassy-rp/src/i2c_slave.rs | 3 + embassy-rp/src/lib.rs | 1 + embassy-rp/src/pio/mod.rs | 1 + embassy-rp/src/pwm.rs | 20 +++++++ embassy-rp/src/rtc/mod.rs | 1 + embassy-rp/src/timer.rs | 1 + embassy-rp/src/uart/buffered.rs | 1 + embassy-rp/src/uart/mod.rs | 3 +- embassy-rp/src/usb.rs | 1 + 15 files changed, 294 insertions(+), 11 deletions(-) diff --git a/embassy-rp/src/adc.rs b/embassy-rp/src/adc.rs index 5b913f156..21360bf66 100644 --- a/embassy-rp/src/adc.rs +++ b/embassy-rp/src/adc.rs @@ -1,3 +1,4 @@ +//! ADC driver. use core::future::poll_fn; use core::marker::PhantomData; use core::mem; @@ -16,6 +17,7 @@ use crate::{dma, interrupt, pac, peripherals, Peripheral, RegExt}; static WAKER: AtomicWaker = AtomicWaker::new(); +/// ADC config. #[non_exhaustive] pub struct Config {} @@ -30,9 +32,11 @@ enum Source<'p> { TempSensor(PeripheralRef<'p, ADC_TEMP_SENSOR>), } +/// ADC channel. pub struct Channel<'p>(Source<'p>); impl<'p> Channel<'p> { + /// Create a new ADC channel from pin with the provided [Pull] configuration. pub fn new_pin(pin: impl Peripheral

+ 'p, pull: Pull) -> Self { into_ref!(pin); pin.pad_ctrl().modify(|w| { @@ -49,6 +53,7 @@ impl<'p> Channel<'p> { Self(Source::Pin(pin.map_into())) } + /// Create a new ADC channel for the internal temperature sensor. pub fn new_temp_sensor(s: impl Peripheral

+ 'p) -> Self { let r = pac::ADC; r.cs().write_set(|w| w.set_ts_en(true)); @@ -83,35 +88,44 @@ impl<'p> Drop for Source<'p> { } } +/// ADC sample. #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Debug, Default)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] #[repr(transparent)] pub struct Sample(u16); impl Sample { + /// Sample is valid. pub fn good(&self) -> bool { self.0 < 0x8000 } + /// Sample value. pub fn value(&self) -> u16 { self.0 & !0x8000 } } +/// ADC error. #[derive(Debug, Eq, PartialEq, Copy, Clone)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] pub enum Error { + /// Error converting value. ConversionFailed, } +/// ADC mode. pub trait Mode {} +/// ADC async mode. pub struct Async; impl Mode for Async {} +/// ADC blocking mode. pub struct Blocking; impl Mode for Blocking {} +/// ADC driver. pub struct Adc<'d, M: Mode> { phantom: PhantomData<(&'d ADC, M)>, } @@ -150,6 +164,7 @@ impl<'d, M: Mode> Adc<'d, M> { while !r.cs().read().ready() {} } + /// Sample a value from a channel in blocking mode. pub fn blocking_read(&mut self, ch: &mut Channel) -> Result { let r = Self::regs(); r.cs().modify(|w| { @@ -166,6 +181,7 @@ impl<'d, M: Mode> Adc<'d, M> { } impl<'d> Adc<'d, Async> { + /// Create ADC driver in async mode. pub fn new( _inner: impl Peripheral

+ 'd, _irq: impl Binding, @@ -194,6 +210,7 @@ impl<'d> Adc<'d, Async> { .await; } + /// Sample a value from a channel until completed. pub async fn read(&mut self, ch: &mut Channel<'_>) -> Result { let r = Self::regs(); r.cs().modify(|w| { @@ -272,6 +289,7 @@ impl<'d> Adc<'d, Async> { } } + /// Sample multiple values from a channel using DMA. #[inline] pub async fn read_many( &mut self, @@ -283,6 +301,7 @@ impl<'d> Adc<'d, Async> { self.read_many_inner(ch, buf, false, div, dma).await } + /// Sample multiple values from a channel using DMA with errors inlined in samples. #[inline] pub async fn read_many_raw( &mut self, @@ -299,6 +318,7 @@ impl<'d> Adc<'d, Async> { } impl<'d> Adc<'d, Blocking> { + /// Create ADC driver in blocking mode. pub fn new_blocking(_inner: impl Peripheral

+ 'd, _config: Config) -> Self { Self::setup(); @@ -306,6 +326,7 @@ impl<'d> Adc<'d, Blocking> { } } +/// Interrupt handler. pub struct InterruptHandler { _empty: (), } @@ -324,6 +345,7 @@ mod sealed { pub trait AdcChannel {} } +/// ADC sample. pub trait AdcSample: sealed::AdcSample {} impl sealed::AdcSample for u16 {} @@ -332,7 +354,9 @@ impl AdcSample for u16 {} impl sealed::AdcSample for u8 {} impl AdcSample for u8 {} +/// ADC channel. pub trait AdcChannel: sealed::AdcChannel {} +/// ADC pin. pub trait AdcPin: AdcChannel + gpio::Pin {} macro_rules! impl_pin { diff --git a/embassy-rp/src/clocks.rs b/embassy-rp/src/clocks.rs index 2f0645615..19232b801 100644 --- a/embassy-rp/src/clocks.rs +++ b/embassy-rp/src/clocks.rs @@ -45,15 +45,20 @@ static CLOCKS: Clocks = Clocks { rtc: AtomicU16::new(0), }; -/// Enumeration of supported clock sources. +/// Peripheral clock sources. #[repr(u8)] #[non_exhaustive] #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub enum PeriClkSrc { + /// SYS. Sys = ClkPeriCtrlAuxsrc::CLK_SYS as _, + /// PLL SYS. PllSys = ClkPeriCtrlAuxsrc::CLKSRC_PLL_SYS as _, + /// PLL USB. PllUsb = ClkPeriCtrlAuxsrc::CLKSRC_PLL_USB as _, + /// ROSC. Rosc = ClkPeriCtrlAuxsrc::ROSC_CLKSRC_PH as _, + /// XOSC. Xosc = ClkPeriCtrlAuxsrc::XOSC_CLKSRC as _, // Gpin0 = ClkPeriCtrlAuxsrc::CLKSRC_GPIN0 as _ , // Gpin1 = ClkPeriCtrlAuxsrc::CLKSRC_GPIN1 as _ , @@ -83,6 +88,7 @@ pub struct ClockConfig { } impl ClockConfig { + /// Clock configuration derived from external crystal. pub fn crystal(crystal_hz: u32) -> Self { Self { rosc: Some(RoscConfig { @@ -141,6 +147,7 @@ impl ClockConfig { } } + /// Clock configuration from internal oscillator. pub fn rosc() -> Self { Self { rosc: Some(RoscConfig { @@ -190,13 +197,18 @@ impl ClockConfig { // } } +/// ROSC freq range. #[repr(u16)] #[non_exhaustive] #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub enum RoscRange { + /// Low range. Low = pac::rosc::vals::FreqRange::LOW.0, + /// Medium range (1.33x low) Medium = pac::rosc::vals::FreqRange::MEDIUM.0, + /// High range (2x low) High = pac::rosc::vals::FreqRange::HIGH.0, + /// Too high. Should not be used. TooHigh = pac::rosc::vals::FreqRange::TOOHIGH.0, } @@ -239,96 +251,136 @@ pub struct PllConfig { pub post_div2: u8, } -/// Reference +/// Reference clock config. pub struct RefClkConfig { + /// Reference clock source. pub src: RefClkSrc, + /// Reference clock divider. pub div: u8, } +/// Reference clock source. #[non_exhaustive] #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub enum RefClkSrc { - // main sources + /// XOSC. Xosc, + /// ROSC. Rosc, - // aux sources + /// PLL USB. PllUsb, // Gpin0, // Gpin1, } +/// SYS clock source. #[non_exhaustive] #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub enum SysClkSrc { - // main sources + /// REF. Ref, - // aux sources + /// PLL SYS. PllSys, + /// PLL USB. PllUsb, + /// ROSC. Rosc, + /// XOSC. Xosc, // Gpin0, // Gpin1, } +/// SYS clock config. pub struct SysClkConfig { + /// SYS clock source. pub src: SysClkSrc, + /// SYS clock divider. pub div_int: u32, + /// SYS clock fraction. pub div_frac: u8, } +/// USB clock source. #[repr(u8)] #[non_exhaustive] #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub enum UsbClkSrc { + /// PLL USB. PllUsb = ClkUsbCtrlAuxsrc::CLKSRC_PLL_USB as _, + /// PLL SYS. PllSys = ClkUsbCtrlAuxsrc::CLKSRC_PLL_SYS as _, + /// ROSC. Rosc = ClkUsbCtrlAuxsrc::ROSC_CLKSRC_PH as _, + /// XOSC. Xosc = ClkUsbCtrlAuxsrc::XOSC_CLKSRC as _, // Gpin0 = ClkUsbCtrlAuxsrc::CLKSRC_GPIN0 as _ , // Gpin1 = ClkUsbCtrlAuxsrc::CLKSRC_GPIN1 as _ , } +/// USB clock config. pub struct UsbClkConfig { + /// USB clock source. pub src: UsbClkSrc, + /// USB clock divider. pub div: u8, + /// USB clock phase. pub phase: u8, } +/// ADC clock source. #[repr(u8)] #[non_exhaustive] #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub enum AdcClkSrc { + /// PLL USB. PllUsb = ClkAdcCtrlAuxsrc::CLKSRC_PLL_USB as _, + /// PLL SYS. PllSys = ClkAdcCtrlAuxsrc::CLKSRC_PLL_SYS as _, + /// ROSC. Rosc = ClkAdcCtrlAuxsrc::ROSC_CLKSRC_PH as _, + /// XOSC. Xosc = ClkAdcCtrlAuxsrc::XOSC_CLKSRC as _, // Gpin0 = ClkAdcCtrlAuxsrc::CLKSRC_GPIN0 as _ , // Gpin1 = ClkAdcCtrlAuxsrc::CLKSRC_GPIN1 as _ , } +/// ADC clock config. pub struct AdcClkConfig { + /// ADC clock source. pub src: AdcClkSrc, + /// ADC clock divider. pub div: u8, + /// ADC clock phase. pub phase: u8, } +/// RTC clock source. #[repr(u8)] #[non_exhaustive] #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub enum RtcClkSrc { + /// PLL USB. PllUsb = ClkRtcCtrlAuxsrc::CLKSRC_PLL_USB as _, + /// PLL SYS. PllSys = ClkRtcCtrlAuxsrc::CLKSRC_PLL_SYS as _, + /// ROSC. Rosc = ClkRtcCtrlAuxsrc::ROSC_CLKSRC_PH as _, + /// XOSC. Xosc = ClkRtcCtrlAuxsrc::XOSC_CLKSRC as _, // Gpin0 = ClkRtcCtrlAuxsrc::CLKSRC_GPIN0 as _ , // Gpin1 = ClkRtcCtrlAuxsrc::CLKSRC_GPIN1 as _ , } +/// RTC clock config. pub struct RtcClkConfig { + /// RTC clock source. pub src: RtcClkSrc, + /// RTC clock divider. pub div_int: u32, + /// RTC clock divider fraction. pub div_frac: u8, + /// RTC clock phase. pub phase: u8, } @@ -605,10 +657,12 @@ fn configure_rosc(config: RoscConfig) -> u32 { config.hz } +/// ROSC clock frequency. pub fn rosc_freq() -> u32 { CLOCKS.rosc.load(Ordering::Relaxed) } +/// XOSC clock frequency. pub fn xosc_freq() -> u32 { CLOCKS.xosc.load(Ordering::Relaxed) } @@ -620,34 +674,42 @@ pub fn xosc_freq() -> u32 { // CLOCKS.gpin1.load(Ordering::Relaxed) // } +/// PLL SYS clock frequency. pub fn pll_sys_freq() -> u32 { CLOCKS.pll_sys.load(Ordering::Relaxed) } +/// PLL USB clock frequency. pub fn pll_usb_freq() -> u32 { CLOCKS.pll_usb.load(Ordering::Relaxed) } +/// SYS clock frequency. pub fn clk_sys_freq() -> u32 { CLOCKS.sys.load(Ordering::Relaxed) } +/// REF clock frequency. pub fn clk_ref_freq() -> u32 { CLOCKS.reference.load(Ordering::Relaxed) } +/// Peripheral clock frequency. pub fn clk_peri_freq() -> u32 { CLOCKS.peri.load(Ordering::Relaxed) } +/// USB clock frequency. pub fn clk_usb_freq() -> u32 { CLOCKS.usb.load(Ordering::Relaxed) } +/// ADC clock frequency. pub fn clk_adc_freq() -> u32 { CLOCKS.adc.load(Ordering::Relaxed) } +/// RTC clock frequency. pub fn clk_rtc_freq() -> u16 { CLOCKS.rtc.load(Ordering::Relaxed) } @@ -708,7 +770,9 @@ fn configure_pll(p: pac::pll::Pll, input_freq: u32, config: PllConfig) -> u32 { vco_freq / ((config.post_div1 * config.post_div2) as u32) } +/// General purpose input clock pin. pub trait GpinPin: crate::gpio::Pin { + /// Pin number. const NR: usize; } @@ -723,12 +787,14 @@ macro_rules! impl_gpinpin { impl_gpinpin!(PIN_20, 20, 0); impl_gpinpin!(PIN_22, 22, 1); +/// General purpose clock input driver. pub struct Gpin<'d, T: Pin> { gpin: PeripheralRef<'d, AnyPin>, _phantom: PhantomData, } impl<'d, T: Pin> Gpin<'d, T> { + /// Create new gpin driver. pub fn new(gpin: impl Peripheral

+ 'd) -> Gpin<'d, P> { into_ref!(gpin); @@ -754,7 +820,9 @@ impl<'d, T: Pin> Drop for Gpin<'d, T> { } } +/// General purpose clock output pin. pub trait GpoutPin: crate::gpio::Pin { + /// Pin number. fn number(&self) -> usize; } @@ -773,26 +841,38 @@ impl_gpoutpin!(PIN_23, 1); impl_gpoutpin!(PIN_24, 2); impl_gpoutpin!(PIN_25, 3); +/// Gpout clock source. #[repr(u8)] pub enum GpoutSrc { + /// Sys PLL. PllSys = ClkGpoutCtrlAuxsrc::CLKSRC_PLL_SYS as _, // Gpin0 = ClkGpoutCtrlAuxsrc::CLKSRC_GPIN0 as _ , // Gpin1 = ClkGpoutCtrlAuxsrc::CLKSRC_GPIN1 as _ , + /// USB PLL. PllUsb = ClkGpoutCtrlAuxsrc::CLKSRC_PLL_USB as _, + /// ROSC. Rosc = ClkGpoutCtrlAuxsrc::ROSC_CLKSRC as _, + /// XOSC. Xosc = ClkGpoutCtrlAuxsrc::XOSC_CLKSRC as _, + /// SYS. Sys = ClkGpoutCtrlAuxsrc::CLK_SYS as _, + /// USB. Usb = ClkGpoutCtrlAuxsrc::CLK_USB as _, + /// ADC. Adc = ClkGpoutCtrlAuxsrc::CLK_ADC as _, + /// RTC. Rtc = ClkGpoutCtrlAuxsrc::CLK_RTC as _, + /// REF. Ref = ClkGpoutCtrlAuxsrc::CLK_REF as _, } +/// General purpose clock output driver. pub struct Gpout<'d, T: GpoutPin> { gpout: PeripheralRef<'d, T>, } impl<'d, T: GpoutPin> Gpout<'d, T> { + /// Create new general purpose cloud output. pub fn new(gpout: impl Peripheral

+ 'd) -> Self { into_ref!(gpout); @@ -801,6 +881,7 @@ impl<'d, T: GpoutPin> Gpout<'d, T> { Self { gpout } } + /// Set clock divider. pub fn set_div(&self, int: u32, frac: u8) { let c = pac::CLOCKS; c.clk_gpout_div(self.gpout.number()).write(|w| { @@ -809,6 +890,7 @@ impl<'d, T: GpoutPin> Gpout<'d, T> { }); } + /// Set clock source. pub fn set_src(&self, src: GpoutSrc) { let c = pac::CLOCKS; c.clk_gpout_ctrl(self.gpout.number()).modify(|w| { @@ -816,6 +898,7 @@ impl<'d, T: GpoutPin> Gpout<'d, T> { }); } + /// Enable clock. pub fn enable(&self) { let c = pac::CLOCKS; c.clk_gpout_ctrl(self.gpout.number()).modify(|w| { @@ -823,6 +906,7 @@ impl<'d, T: GpoutPin> Gpout<'d, T> { }); } + /// Disable clock. pub fn disable(&self) { let c = pac::CLOCKS; c.clk_gpout_ctrl(self.gpout.number()).modify(|w| { @@ -830,6 +914,7 @@ impl<'d, T: GpoutPin> Gpout<'d, T> { }); } + /// Clock frequency. pub fn get_freq(&self) -> u32 { let c = pac::CLOCKS; let src = c.clk_gpout_ctrl(self.gpout.number()).read().auxsrc(); diff --git a/embassy-rp/src/dma.rs b/embassy-rp/src/dma.rs index 45ca21a75..088a842a1 100644 --- a/embassy-rp/src/dma.rs +++ b/embassy-rp/src/dma.rs @@ -38,6 +38,9 @@ pub(crate) unsafe fn init() { interrupt::DMA_IRQ_0.enable(); } +/// DMA read. +/// +/// SAFETY: Slice must point to a valid location reachable by DMA. pub unsafe fn read<'a, C: Channel, W: Word>( ch: impl Peripheral

+ 'a, from: *const W, @@ -57,6 +60,9 @@ pub unsafe fn read<'a, C: Channel, W: Word>( ) } +/// DMA write. +/// +/// SAFETY: Slice must point to a valid location reachable by DMA. pub unsafe fn write<'a, C: Channel, W: Word>( ch: impl Peripheral

+ 'a, from: *const [W], @@ -79,6 +85,9 @@ pub unsafe fn write<'a, C: Channel, W: Word>( // static mut so that this is allocated in RAM. static mut DUMMY: u32 = 0; +/// DMA repeated write. +/// +/// SAFETY: Slice must point to a valid location reachable by DMA. pub unsafe fn write_repeated<'a, C: Channel, W: Word>( ch: impl Peripheral

+ 'a, to: *mut W, @@ -97,6 +106,9 @@ pub unsafe fn write_repeated<'a, C: Channel, W: Word>( ) } +/// DMA copy between slices. +/// +/// SAFETY: Slices must point to locations reachable by DMA. pub unsafe fn copy<'a, C: Channel, W: Word>( ch: impl Peripheral

+ 'a, from: &[W], @@ -152,6 +164,7 @@ fn copy_inner<'a, C: Channel>( Transfer::new(ch) } +/// DMA transfer driver. #[must_use = "futures do nothing unless you `.await` or poll them"] pub struct Transfer<'a, C: Channel> { channel: PeripheralRef<'a, C>, @@ -201,19 +214,25 @@ mod sealed { pub trait Word {} } +/// DMA channel interface. pub trait Channel: Peripheral

+ sealed::Channel + Into + Sized + 'static { + /// Channel number. fn number(&self) -> u8; + /// Channel registry block. fn regs(&self) -> pac::dma::Channel { pac::DMA.ch(self.number() as _) } + /// Convert into type-erased [AnyChannel]. fn degrade(self) -> AnyChannel { AnyChannel { number: self.number() } } } +/// DMA word. pub trait Word: sealed::Word { + /// Word size. fn size() -> vals::DataSize; } @@ -238,6 +257,7 @@ impl Word for u32 { } } +/// Type erased DMA channel. pub struct AnyChannel { number: u8, } diff --git a/embassy-rp/src/flash.rs b/embassy-rp/src/flash.rs index 1b20561da..2d673cf6c 100644 --- a/embassy-rp/src/flash.rs +++ b/embassy-rp/src/flash.rs @@ -1,3 +1,4 @@ +//! Flash driver. use core::future::Future; use core::marker::PhantomData; use core::pin::Pin; @@ -13,9 +14,10 @@ use crate::dma::{AnyChannel, Channel, Transfer}; use crate::pac; use crate::peripherals::FLASH; +/// Flash base address. pub const FLASH_BASE: *const u32 = 0x10000000 as _; -// If running from RAM, we might have no boot2. Use bootrom `flash_enter_cmd_xip` instead. +/// If running from RAM, we might have no boot2. Use bootrom `flash_enter_cmd_xip` instead. // TODO: when run-from-ram is set, completely skip the "pause cores and jumpp to RAM" dance. pub const USE_BOOT2: bool = !cfg!(feature = "run-from-ram"); @@ -24,10 +26,15 @@ pub const USE_BOOT2: bool = !cfg!(feature = "run-from-ram"); // These limitations are currently enforced because of using the // RP2040 boot-rom flash functions, that are optimized for flash compatibility // rather than performance. +/// Flash page size. pub const PAGE_SIZE: usize = 256; +/// Flash write size. pub const WRITE_SIZE: usize = 1; +/// Flash read size. pub const READ_SIZE: usize = 1; +/// Flash erase size. pub const ERASE_SIZE: usize = 4096; +/// Flash DMA read size. pub const ASYNC_READ_SIZE: usize = 4; /// Error type for NVMC operations. @@ -38,7 +45,9 @@ pub enum Error { OutOfBounds, /// Unaligned operation or using unaligned buffers. Unaligned, + /// Accessed from the wrong core. InvalidCore, + /// Other error Other, } @@ -96,12 +105,18 @@ impl<'a, 'd, T: Instance, const FLASH_SIZE: usize> Drop for BackgroundRead<'a, ' } } +/// Flash driver. pub struct Flash<'d, T: Instance, M: Mode, const FLASH_SIZE: usize> { dma: Option>, phantom: PhantomData<(&'d mut T, M)>, } impl<'d, T: Instance, M: Mode, const FLASH_SIZE: usize> Flash<'d, T, M, FLASH_SIZE> { + /// Blocking read. + /// + /// The offset and buffer must be aligned. + /// + /// NOTE: `offset` is an offset from the flash start, NOT an absolute address. pub fn blocking_read(&mut self, offset: u32, bytes: &mut [u8]) -> Result<(), Error> { trace!( "Reading from 0x{:x} to 0x{:x}", @@ -116,10 +131,14 @@ impl<'d, T: Instance, M: Mode, const FLASH_SIZE: usize> Flash<'d, T, M, FLASH_SI Ok(()) } + /// Flash capacity. pub fn capacity(&self) -> usize { FLASH_SIZE } + /// Blocking erase. + /// + /// NOTE: `offset` is an offset from the flash start, NOT an absolute address. pub fn blocking_erase(&mut self, from: u32, to: u32) -> Result<(), Error> { check_erase(self, from, to)?; @@ -136,6 +155,11 @@ impl<'d, T: Instance, M: Mode, const FLASH_SIZE: usize> Flash<'d, T, M, FLASH_SI Ok(()) } + /// Blocking write. + /// + /// The offset and buffer must be aligned. + /// + /// NOTE: `offset` is an offset from the flash start, NOT an absolute address. pub fn blocking_write(&mut self, offset: u32, bytes: &[u8]) -> Result<(), Error> { check_write(self, offset, bytes.len())?; @@ -219,6 +243,7 @@ impl<'d, T: Instance, M: Mode, const FLASH_SIZE: usize> Flash<'d, T, M, FLASH_SI } impl<'d, T: Instance, const FLASH_SIZE: usize> Flash<'d, T, Blocking, FLASH_SIZE> { + /// Create a new flash driver in blocking mode. pub fn new_blocking(_flash: impl Peripheral

+ 'd) -> Self { Self { dma: None, @@ -228,6 +253,7 @@ impl<'d, T: Instance, const FLASH_SIZE: usize> Flash<'d, T, Blocking, FLASH_SIZE } impl<'d, T: Instance, const FLASH_SIZE: usize> Flash<'d, T, Async, FLASH_SIZE> { + /// Create a new flash driver in async mode. pub fn new(_flash: impl Peripheral

+ 'd, dma: impl Peripheral

+ 'd) -> Self { into_ref!(dma); Self { @@ -236,6 +262,11 @@ impl<'d, T: Instance, const FLASH_SIZE: usize> Flash<'d, T, Async, FLASH_SIZE> { } } + /// Start a background read operation. + /// + /// The offset and buffer must be aligned. + /// + /// NOTE: `offset` is an offset from the flash start, NOT an absolute address. pub fn background_read<'a>( &'a mut self, offset: u32, @@ -279,6 +310,11 @@ impl<'d, T: Instance, const FLASH_SIZE: usize> Flash<'d, T, Async, FLASH_SIZE> { }) } + /// Async read. + /// + /// The offset and buffer must be aligned. + /// + /// NOTE: `offset` is an offset from the flash start, NOT an absolute address. pub async fn read(&mut self, offset: u32, bytes: &mut [u8]) -> Result<(), Error> { use core::mem::MaybeUninit; @@ -874,7 +910,9 @@ mod sealed { pub trait Mode {} } +/// Flash instance. pub trait Instance: sealed::Instance {} +/// Flash mode. pub trait Mode: sealed::Mode {} impl sealed::Instance for FLASH {} @@ -887,7 +925,9 @@ macro_rules! impl_mode { }; } +/// Flash blocking mode. pub struct Blocking; +/// Flash async mode. pub struct Async; impl_mode!(Blocking); diff --git a/embassy-rp/src/gpio.rs b/embassy-rp/src/gpio.rs index 23273e627..2e6692abe 100644 --- a/embassy-rp/src/gpio.rs +++ b/embassy-rp/src/gpio.rs @@ -1,3 +1,4 @@ +//! GPIO driver. #![macro_use] use core::convert::Infallible; use core::future::Future; @@ -23,7 +24,9 @@ static QSPI_WAKERS: [AtomicWaker; QSPI_PIN_COUNT] = [NEW_AW; QSPI_PIN_COUNT]; /// Represents a digital input or output level. #[derive(Debug, Eq, PartialEq, Clone, Copy)] pub enum Level { + /// Logical low. Low, + /// Logical high. High, } @@ -48,48 +51,66 @@ impl From for bool { /// Represents a pull setting for an input. #[derive(Debug, Clone, Copy, Eq, PartialEq)] pub enum Pull { + /// No pull. None, + /// Internal pull-up resistor. Up, + /// Internal pull-down resistor. Down, } /// Drive strength of an output #[derive(Debug, Eq, PartialEq)] pub enum Drive { + /// 2 mA drive. _2mA, + /// 4 mA drive. _4mA, + /// 8 mA drive. _8mA, + /// 1 2mA drive. _12mA, } /// Slew rate of an output #[derive(Debug, Eq, PartialEq)] pub enum SlewRate { + /// Fast slew rate. Fast, + /// Slow slew rate. Slow, } /// A GPIO bank with up to 32 pins. #[derive(Debug, Eq, PartialEq)] pub enum Bank { + /// Bank 0. Bank0 = 0, + /// QSPI. #[cfg(feature = "qspi-as-gpio")] Qspi = 1, } +/// Dormant mode config. #[derive(Debug, Eq, PartialEq, Copy, Clone, Default)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] pub struct DormantWakeConfig { + /// Wake on edge high. pub edge_high: bool, + /// Wake on edge low. pub edge_low: bool, + /// Wake on level high. pub level_high: bool, + /// Wake on level low. pub level_low: bool, } +/// GPIO input driver. pub struct Input<'d, T: Pin> { pin: Flex<'d, T>, } impl<'d, T: Pin> Input<'d, T> { + /// Create GPIO input driver for a [Pin] with the provided [Pull] configuration. #[inline] pub fn new(pin: impl Peripheral

+ 'd, pull: Pull) -> Self { let mut pin = Flex::new(pin); @@ -104,11 +125,13 @@ impl<'d, T: Pin> Input<'d, T> { self.pin.set_schmitt(enable) } + /// Get whether the pin input level is high. #[inline] pub fn is_high(&mut self) -> bool { self.pin.is_high() } + /// Get whether the pin input level is low. #[inline] pub fn is_low(&mut self) -> bool { self.pin.is_low() @@ -120,31 +143,37 @@ impl<'d, T: Pin> Input<'d, T> { self.pin.get_level() } + /// Wait until the pin is high. If it is already high, return immediately. #[inline] pub async fn wait_for_high(&mut self) { self.pin.wait_for_high().await; } + /// Wait until the pin is low. If it is already low, return immediately. #[inline] pub async fn wait_for_low(&mut self) { self.pin.wait_for_low().await; } + /// Wait for the pin to undergo a transition from low to high. #[inline] pub async fn wait_for_rising_edge(&mut self) { self.pin.wait_for_rising_edge().await; } + /// Wait for the pin to undergo a transition from high to low. #[inline] pub async fn wait_for_falling_edge(&mut self) { self.pin.wait_for_falling_edge().await; } + /// Wait for the pin to undergo any transition, i.e low to high OR high to low. #[inline] pub async fn wait_for_any_edge(&mut self) { self.pin.wait_for_any_edge().await; } + /// Configure dormant wake. #[inline] pub fn dormant_wake(&mut self, cfg: DormantWakeConfig) -> DormantWake { self.pin.dormant_wake(cfg) @@ -155,10 +184,15 @@ impl<'d, T: Pin> Input<'d, T> { #[derive(Debug, Eq, PartialEq, Copy, Clone)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] pub enum InterruptTrigger { + /// Trigger on pin low. LevelLow, + /// Trigger on pin high. LevelHigh, + /// Trigger on high to low transition. EdgeLow, + /// Trigger on low to high transition. EdgeHigh, + /// Trigger on any transition. AnyEdge, } @@ -226,6 +260,7 @@ struct InputFuture<'a, T: Pin> { } impl<'d, T: Pin> InputFuture<'d, T> { + /// Create a new future wiating for input trigger. pub fn new(pin: impl Peripheral

+ 'd, level: InterruptTrigger) -> Self { into_ref!(pin); let pin_group = (pin.pin() % 8) as usize; @@ -308,11 +343,13 @@ impl<'d, T: Pin> Future for InputFuture<'d, T> { } } +/// GPIO output driver. pub struct Output<'d, T: Pin> { pin: Flex<'d, T>, } impl<'d, T: Pin> Output<'d, T> { + /// Create GPIO output driver for a [Pin] with the provided [Level]. #[inline] pub fn new(pin: impl Peripheral

+ 'd, initial_output: Level) -> Self { let mut pin = Flex::new(pin); @@ -331,7 +368,7 @@ impl<'d, T: Pin> Output<'d, T> { self.pin.set_drive_strength(strength) } - // Set the pin's slew rate. + /// Set the pin's slew rate. #[inline] pub fn set_slew_rate(&mut self, slew_rate: SlewRate) { self.pin.set_slew_rate(slew_rate) @@ -386,6 +423,7 @@ pub struct OutputOpenDrain<'d, T: Pin> { } impl<'d, T: Pin> OutputOpenDrain<'d, T> { + /// Create GPIO output driver for a [Pin] in open drain mode with the provided [Level]. #[inline] pub fn new(pin: impl Peripheral

+ 'd, initial_output: Level) -> Self { let mut pin = Flex::new(pin); @@ -403,7 +441,7 @@ impl<'d, T: Pin> OutputOpenDrain<'d, T> { self.pin.set_drive_strength(strength) } - // Set the pin's slew rate. + /// Set the pin's slew rate. #[inline] pub fn set_slew_rate(&mut self, slew_rate: SlewRate) { self.pin.set_slew_rate(slew_rate) @@ -456,11 +494,13 @@ impl<'d, T: Pin> OutputOpenDrain<'d, T> { self.pin.toggle_set_as_output() } + /// Get whether the pin input level is high. #[inline] pub fn is_high(&mut self) -> bool { self.pin.is_high() } + /// Get whether the pin input level is low. #[inline] pub fn is_low(&mut self) -> bool { self.pin.is_low() @@ -472,26 +512,31 @@ impl<'d, T: Pin> OutputOpenDrain<'d, T> { self.is_high().into() } + /// Wait until the pin is high. If it is already high, return immediately. #[inline] pub async fn wait_for_high(&mut self) { self.pin.wait_for_high().await; } + /// Wait until the pin is low. If it is already low, return immediately. #[inline] pub async fn wait_for_low(&mut self) { self.pin.wait_for_low().await; } + /// Wait for the pin to undergo a transition from low to high. #[inline] pub async fn wait_for_rising_edge(&mut self) { self.pin.wait_for_rising_edge().await; } + /// Wait for the pin to undergo a transition from high to low. #[inline] pub async fn wait_for_falling_edge(&mut self) { self.pin.wait_for_falling_edge().await; } + /// Wait for the pin to undergo any transition, i.e low to high OR high to low. #[inline] pub async fn wait_for_any_edge(&mut self) { self.pin.wait_for_any_edge().await; @@ -508,6 +553,10 @@ pub struct Flex<'d, T: Pin> { } impl<'d, T: Pin> Flex<'d, T> { + /// Wrap the pin in a `Flex`. + /// + /// The pin remains disconnected. The initial output level is unspecified, but can be changed + /// before the pin is put into output mode. #[inline] pub fn new(pin: impl Peripheral

+ 'd) -> Self { into_ref!(pin); @@ -556,7 +605,7 @@ impl<'d, T: Pin> Flex<'d, T> { }); } - // Set the pin's slew rate. + /// Set the pin's slew rate. #[inline] pub fn set_slew_rate(&mut self, slew_rate: SlewRate) { self.pin.pad_ctrl().modify(|w| { @@ -589,6 +638,7 @@ impl<'d, T: Pin> Flex<'d, T> { self.pin.sio_oe().value_set().write_value(self.bit()) } + /// Set as output pin. #[inline] pub fn is_set_as_output(&mut self) -> bool { self.ref_is_set_as_output() @@ -599,15 +649,18 @@ impl<'d, T: Pin> Flex<'d, T> { (self.pin.sio_oe().value().read() & self.bit()) != 0 } + /// Toggle output pin. #[inline] pub fn toggle_set_as_output(&mut self) { self.pin.sio_oe().value_xor().write_value(self.bit()) } + /// Get whether the pin input level is high. #[inline] pub fn is_high(&mut self) -> bool { !self.is_low() } + /// Get whether the pin input level is low. #[inline] pub fn is_low(&mut self) -> bool { @@ -675,31 +728,37 @@ impl<'d, T: Pin> Flex<'d, T> { self.pin.sio_out().value_xor().write_value(self.bit()) } + /// Wait until the pin is high. If it is already high, return immediately. #[inline] pub async fn wait_for_high(&mut self) { InputFuture::new(&mut self.pin, InterruptTrigger::LevelHigh).await; } + /// Wait until the pin is low. If it is already low, return immediately. #[inline] pub async fn wait_for_low(&mut self) { InputFuture::new(&mut self.pin, InterruptTrigger::LevelLow).await; } + /// Wait for the pin to undergo a transition from low to high. #[inline] pub async fn wait_for_rising_edge(&mut self) { InputFuture::new(&mut self.pin, InterruptTrigger::EdgeHigh).await; } + /// Wait for the pin to undergo a transition from high to low. #[inline] pub async fn wait_for_falling_edge(&mut self) { InputFuture::new(&mut self.pin, InterruptTrigger::EdgeLow).await; } + /// Wait for the pin to undergo any transition, i.e low to high OR high to low. #[inline] pub async fn wait_for_any_edge(&mut self) { InputFuture::new(&mut self.pin, InterruptTrigger::AnyEdge).await; } + /// Configure dormant wake. #[inline] pub fn dormant_wake(&mut self, cfg: DormantWakeConfig) -> DormantWake { let idx = self.pin._pin() as usize; @@ -737,6 +796,7 @@ impl<'d, T: Pin> Drop for Flex<'d, T> { } } +/// Dormant wake driver. pub struct DormantWake<'w, T: Pin> { pin: PeripheralRef<'w, T>, cfg: DormantWakeConfig, @@ -818,6 +878,7 @@ pub(crate) mod sealed { } } +/// Interface for a Pin that can be configured by an [Input] or [Output] driver, or converted to an [AnyPin]. pub trait Pin: Peripheral

+ Into + sealed::Pin + Sized + 'static { /// Degrade to a generic pin struct fn degrade(self) -> AnyPin { @@ -839,6 +900,7 @@ pub trait Pin: Peripheral

+ Into + sealed::Pin + Sized + 'stat } } +/// Type-erased GPIO pin pub struct AnyPin { pin_bank: u8, } diff --git a/embassy-rp/src/i2c.rs b/embassy-rp/src/i2c.rs index 15095236a..74d015792 100644 --- a/embassy-rp/src/i2c.rs +++ b/embassy-rp/src/i2c.rs @@ -1,3 +1,4 @@ +//! I2C driver. use core::future; use core::marker::PhantomData; use core::task::Poll; @@ -22,6 +23,7 @@ pub enum AbortReason { ArbitrationLoss, /// Transmit ended with data still in fifo TxNotEmpty(u16), + /// Other reason. Other(u32), } @@ -41,9 +43,11 @@ pub enum Error { AddressReserved(u16), } +/// I2C config. #[non_exhaustive] #[derive(Copy, Clone)] pub struct Config { + /// Frequency. pub frequency: u32, } @@ -53,13 +57,16 @@ impl Default for Config { } } +/// Size of I2C FIFO. pub const FIFO_SIZE: u8 = 16; +/// I2C driver. pub struct I2c<'d, T: Instance, M: Mode> { phantom: PhantomData<(&'d mut T, M)>, } impl<'d, T: Instance> I2c<'d, T, Blocking> { + /// Create a new driver instance in blocking mode. pub fn new_blocking( peri: impl Peripheral

+ 'd, scl: impl Peripheral

> + 'd, @@ -72,6 +79,7 @@ impl<'d, T: Instance> I2c<'d, T, Blocking> { } impl<'d, T: Instance> I2c<'d, T, Async> { + /// Create a new driver instance in async mode. pub fn new_async( peri: impl Peripheral

+ 'd, scl: impl Peripheral

> + 'd, @@ -292,16 +300,19 @@ impl<'d, T: Instance> I2c<'d, T, Async> { } } + /// Read from address into buffer using DMA. pub async fn read_async(&mut self, addr: u16, buffer: &mut [u8]) -> Result<(), Error> { Self::setup(addr)?; self.read_async_internal(buffer, true, true).await } + /// Write to address from buffer using DMA. pub async fn write_async(&mut self, addr: u16, bytes: impl IntoIterator) -> Result<(), Error> { Self::setup(addr)?; self.write_async_internal(bytes, true).await } + /// Write to address from bytes and read from address into buffer using DMA. pub async fn write_read_async( &mut self, addr: u16, @@ -314,6 +325,7 @@ impl<'d, T: Instance> I2c<'d, T, Async> { } } +/// Interrupt handler. pub struct InterruptHandler { _uart: PhantomData, } @@ -569,17 +581,20 @@ impl<'d, T: Instance + 'd, M: Mode> I2c<'d, T, M> { // Blocking public API // ========================= + /// Read from address into buffer blocking caller until done. pub fn blocking_read(&mut self, address: u8, read: &mut [u8]) -> Result<(), Error> { Self::setup(address.into())?; self.read_blocking_internal(read, true, true) // Automatic Stop } + /// Write to address from buffer blocking caller until done. pub fn blocking_write(&mut self, address: u8, write: &[u8]) -> Result<(), Error> { Self::setup(address.into())?; self.write_blocking_internal(write, true) } + /// Write to address from bytes and read from address into buffer blocking caller until done. pub fn blocking_write_read(&mut self, address: u8, write: &[u8], read: &mut [u8]) -> Result<(), Error> { Self::setup(address.into())?; self.write_blocking_internal(write, false)?; @@ -742,6 +757,7 @@ where } } +/// Check if address is reserved. pub fn i2c_reserved_addr(addr: u16) -> bool { ((addr & 0x78) == 0 || (addr & 0x78) == 0x78) && addr != 0 } @@ -768,6 +784,7 @@ mod sealed { pub trait SclPin {} } +/// Driver mode. pub trait Mode: sealed::Mode {} macro_rules! impl_mode { @@ -777,12 +794,15 @@ macro_rules! impl_mode { }; } +/// Blocking mode. pub struct Blocking; +/// Async mode. pub struct Async; impl_mode!(Blocking); impl_mode!(Async); +/// I2C instance. pub trait Instance: sealed::Instance {} macro_rules! impl_instance { @@ -819,7 +839,9 @@ macro_rules! impl_instance { impl_instance!(I2C0, I2C0_IRQ, set_i2c0, 32, 33); impl_instance!(I2C1, I2C1_IRQ, set_i2c1, 34, 35); +/// SDA pin. pub trait SdaPin: sealed::SdaPin + crate::gpio::Pin {} +/// SCL pin. pub trait SclPin: sealed::SclPin + crate::gpio::Pin {} macro_rules! impl_pin { diff --git a/embassy-rp/src/i2c_slave.rs b/embassy-rp/src/i2c_slave.rs index 9271ede3a..721b7a1f6 100644 --- a/embassy-rp/src/i2c_slave.rs +++ b/embassy-rp/src/i2c_slave.rs @@ -1,3 +1,4 @@ +//! I2C slave driver. use core::future; use core::marker::PhantomData; use core::task::Poll; @@ -63,11 +64,13 @@ impl Default for Config { } } +/// I2CSlave driver. pub struct I2cSlave<'d, T: Instance> { phantom: PhantomData<&'d mut T>, } impl<'d, T: Instance> I2cSlave<'d, T> { + /// Create a new instance. pub fn new( _peri: impl Peripheral

+ 'd, scl: impl Peripheral

> + 'd, diff --git a/embassy-rp/src/lib.rs b/embassy-rp/src/lib.rs index 2c49787df..004b94589 100644 --- a/embassy-rp/src/lib.rs +++ b/embassy-rp/src/lib.rs @@ -1,6 +1,7 @@ #![no_std] #![allow(async_fn_in_trait)] #![doc = include_str!("../README.md")] +#![warn(missing_docs)] // This mod MUST go first, so that the others see its macros. pub(crate) mod fmt; diff --git a/embassy-rp/src/pio/mod.rs b/embassy-rp/src/pio/mod.rs index ae91d1e83..ca9795024 100644 --- a/embassy-rp/src/pio/mod.rs +++ b/embassy-rp/src/pio/mod.rs @@ -1,3 +1,4 @@ +//! PIO driver. use core::future::Future; use core::marker::PhantomData; use core::pin::Pin as FuturePin; diff --git a/embassy-rp/src/pwm.rs b/embassy-rp/src/pwm.rs index 5b96557a3..784a05f92 100644 --- a/embassy-rp/src/pwm.rs +++ b/embassy-rp/src/pwm.rs @@ -119,11 +119,13 @@ impl<'d, T: Channel> Pwm<'d, T> { } } + /// Create PWM driver without any configured pins. #[inline] pub fn new_free(inner: impl Peripheral

+ 'd, config: Config) -> Self { Self::new_inner(inner, None, None, config, Divmode::DIV) } + /// Create PWM driver with a single 'a' as output. #[inline] pub fn new_output_a( inner: impl Peripheral

+ 'd, @@ -134,6 +136,7 @@ impl<'d, T: Channel> Pwm<'d, T> { Self::new_inner(inner, Some(a.map_into()), None, config, Divmode::DIV) } + /// Create PWM driver with a single 'b' pin as output. #[inline] pub fn new_output_b( inner: impl Peripheral

+ 'd, @@ -144,6 +147,7 @@ impl<'d, T: Channel> Pwm<'d, T> { Self::new_inner(inner, None, Some(b.map_into()), config, Divmode::DIV) } + /// Create PWM driver with a 'a' and 'b' pins as output. #[inline] pub fn new_output_ab( inner: impl Peripheral

+ 'd, @@ -155,6 +159,7 @@ impl<'d, T: Channel> Pwm<'d, T> { Self::new_inner(inner, Some(a.map_into()), Some(b.map_into()), config, Divmode::DIV) } + /// Create PWM driver with a single 'b' as input pin. #[inline] pub fn new_input( inner: impl Peripheral

+ 'd, @@ -166,6 +171,7 @@ impl<'d, T: Channel> Pwm<'d, T> { Self::new_inner(inner, None, Some(b.map_into()), config, mode.into()) } + /// Create PWM driver with a 'a' and 'b' pins in the desired input mode. #[inline] pub fn new_output_input( inner: impl Peripheral

+ 'd, @@ -178,6 +184,7 @@ impl<'d, T: Channel> Pwm<'d, T> { Self::new_inner(inner, Some(a.map_into()), Some(b.map_into()), config, mode.into()) } + /// Set the PWM config. pub fn set_config(&mut self, config: &Config) { Self::configure(self.inner.regs(), config); } @@ -221,28 +228,33 @@ impl<'d, T: Channel> Pwm<'d, T> { while p.csr().read().ph_ret() {} } + /// Read PWM counter. #[inline] pub fn counter(&self) -> u16 { self.inner.regs().ctr().read().ctr() } + /// Write PWM counter. #[inline] pub fn set_counter(&self, ctr: u16) { self.inner.regs().ctr().write(|w| w.set_ctr(ctr)) } + /// Wait for channel interrupt. #[inline] pub fn wait_for_wrap(&mut self) { while !self.wrapped() {} self.clear_wrapped(); } + /// Check if interrupt for channel is set. #[inline] pub fn wrapped(&mut self) -> bool { pac::PWM.intr().read().0 & self.bit() != 0 } #[inline] + /// Clear interrupt flag. pub fn clear_wrapped(&mut self) { pac::PWM.intr().write_value(Intr(self.bit() as _)); } @@ -253,15 +265,18 @@ impl<'d, T: Channel> Pwm<'d, T> { } } +/// Batch representation of PWM channels. pub struct PwmBatch(u32); impl PwmBatch { #[inline] + /// Enable a PWM channel in this batch. pub fn enable(&mut self, pwm: &Pwm<'_, impl Channel>) { self.0 |= pwm.bit(); } #[inline] + /// Enable channels in this batch in a PWM. pub fn set_enabled(enabled: bool, batch: impl FnOnce(&mut PwmBatch)) { let mut en = PwmBatch(0); batch(&mut en); @@ -289,9 +304,12 @@ mod sealed { pub trait Channel {} } +/// PWM Channel. pub trait Channel: Peripheral

+ sealed::Channel + Sized + 'static { + /// Channel number. fn number(&self) -> u8; + /// Channel register block. fn regs(&self) -> pac::pwm::Channel { pac::PWM.ch(self.number() as _) } @@ -317,7 +335,9 @@ channel!(PWM_CH5, 5); channel!(PWM_CH6, 6); channel!(PWM_CH7, 7); +/// PWM Pin A. pub trait PwmPinA: GpioPin {} +/// PWM Pin B. pub trait PwmPinB: GpioPin {} macro_rules! impl_pin { diff --git a/embassy-rp/src/rtc/mod.rs b/embassy-rp/src/rtc/mod.rs index c3df3ee57..b696989f5 100644 --- a/embassy-rp/src/rtc/mod.rs +++ b/embassy-rp/src/rtc/mod.rs @@ -1,3 +1,4 @@ +//! RTC driver. mod filter; use embassy_hal_internal::{into_ref, Peripheral, PeripheralRef}; diff --git a/embassy-rp/src/timer.rs b/embassy-rp/src/timer.rs index faa8df037..69c0c85b1 100644 --- a/embassy-rp/src/timer.rs +++ b/embassy-rp/src/timer.rs @@ -1,3 +1,4 @@ +//! Timer driver. use core::cell::Cell; use atomic_polyfill::{AtomicU8, Ordering}; diff --git a/embassy-rp/src/uart/buffered.rs b/embassy-rp/src/uart/buffered.rs index f14e08525..99c958129 100644 --- a/embassy-rp/src/uart/buffered.rs +++ b/embassy-rp/src/uart/buffered.rs @@ -1,3 +1,4 @@ +//! Buffered UART driver. use core::future::{poll_fn, Future}; use core::slice; use core::task::Poll; diff --git a/embassy-rp/src/uart/mod.rs b/embassy-rp/src/uart/mod.rs index 32be7661d..99fce0fc9 100644 --- a/embassy-rp/src/uart/mod.rs +++ b/embassy-rp/src/uart/mod.rs @@ -1,3 +1,4 @@ +//! UART driver. use core::future::poll_fn; use core::marker::PhantomData; use core::task::Poll; @@ -947,7 +948,7 @@ pub struct Async; impl_mode!(Blocking); impl_mode!(Async); -/// UART instance trait. +/// UART instance. pub trait Instance: sealed::Instance {} macro_rules! impl_instance { diff --git a/embassy-rp/src/usb.rs b/embassy-rp/src/usb.rs index bcd848222..905661d64 100644 --- a/embassy-rp/src/usb.rs +++ b/embassy-rp/src/usb.rs @@ -1,3 +1,4 @@ +//! USB driver. use core::future::poll_fn; use core::marker::PhantomData; use core::slice; From 39c166ef9b754c5caa44ef4dd4a4e216078dbcea Mon Sep 17 00:00:00 2001 From: Ulf Lilleengen Date: Tue, 19 Dec 2023 16:08:06 +0100 Subject: [PATCH 061/124] docs: document public apis for cyw43 driver --- cyw43-pio/README.md | 17 +++++++++++++++++ cyw43-pio/src/lib.rs | 6 ++++++ cyw43/README.md | 4 ++++ cyw43/src/control.rs | 16 +++++++++++++++- cyw43/src/lib.rs | 10 ++++++++++ cyw43/src/runner.rs | 2 ++ cyw43/src/structs.rs | 14 +++++++++++++- 7 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 cyw43-pio/README.md diff --git a/cyw43-pio/README.md b/cyw43-pio/README.md new file mode 100644 index 000000000..2b22db360 --- /dev/null +++ b/cyw43-pio/README.md @@ -0,0 +1,17 @@ +# cyw43-pio + +RP2040 PIO driver for the nonstandard half-duplex SPI used in the Pico W. The PIO driver offloads SPI communication with the WiFi chip and improves throughput. + +## Minimum supported Rust version (MSRV) + +Embassy is guaranteed to compile on the latest stable Rust version at the time of release. It might compile with older versions but that may change in any new patch release. + +## License + +This work is licensed under either of + +- Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or + ) +- MIT license ([LICENSE-MIT](LICENSE-MIT) or ) + +at your option. diff --git a/cyw43-pio/src/lib.rs b/cyw43-pio/src/lib.rs index 8304740b3..5efab10e4 100644 --- a/cyw43-pio/src/lib.rs +++ b/cyw43-pio/src/lib.rs @@ -1,5 +1,7 @@ #![no_std] #![allow(async_fn_in_trait)] +#![doc = include_str!("../README.md")] +#![warn(missing_docs)] use core::slice; @@ -11,6 +13,7 @@ use embassy_rp::{Peripheral, PeripheralRef}; use fixed::FixedU32; use pio_proc::pio_asm; +/// SPI comms driven by PIO. pub struct PioSpi<'d, CS: Pin, PIO: Instance, const SM: usize, DMA> { cs: Output<'d, CS>, sm: StateMachine<'d, PIO, SM>, @@ -25,6 +28,7 @@ where CS: Pin, PIO: Instance, { + /// Create a new instance of PioSpi. pub fn new( common: &mut Common<'d, PIO>, mut sm: StateMachine<'d, PIO, SM>, @@ -143,6 +147,7 @@ where } } + /// Write data to peripheral and return status. pub async fn write(&mut self, write: &[u32]) -> u32 { self.sm.set_enable(false); let write_bits = write.len() * 32 - 1; @@ -170,6 +175,7 @@ where status } + /// Send command and read response into buffer. pub async fn cmd_read(&mut self, cmd: u32, read: &mut [u32]) -> u32 { self.sm.set_enable(false); let write_bits = 31; diff --git a/cyw43/README.md b/cyw43/README.md index 5b8f3cf40..2c24c7d36 100644 --- a/cyw43/README.md +++ b/cyw43/README.md @@ -45,6 +45,10 @@ nc 192.168.0.250 1234 ``` Send it some data, you should see it echoed back and printed in the firmware's logs. +## Minimum supported Rust version (MSRV) + +Embassy is guaranteed to compile on the latest stable Rust version at the time of release. It might compile with older versions but that may change in any new patch release. + ## License This work is licensed under either of diff --git a/cyw43/src/control.rs b/cyw43/src/control.rs index 826edfe1a..311fcb08c 100644 --- a/cyw43/src/control.rs +++ b/cyw43/src/control.rs @@ -12,17 +12,23 @@ use crate::ioctl::{IoctlState, IoctlType}; use crate::structs::*; use crate::{countries, events, PowerManagementMode}; +/// Control errors. #[derive(Debug)] pub struct Error { + /// Status code. pub status: u32, } +/// Multicast errors. #[derive(Debug)] pub enum AddMulticastAddressError { + /// Not a multicast address. NotMulticast, + /// No free address slots. NoFreeSlots, } +/// Control driver. pub struct Control<'a> { state_ch: ch::StateRunner<'a>, events: &'a Events, @@ -38,6 +44,7 @@ impl<'a> Control<'a> { } } + /// Initialize WiFi controller. pub async fn init(&mut self, clm: &[u8]) { const CHUNK_SIZE: usize = 1024; @@ -154,6 +161,7 @@ impl<'a> Control<'a> { self.ioctl(IoctlType::Set, IOCTL_CMD_DOWN, 0, &mut []).await; } + /// Set power management mode. pub async fn set_power_management(&mut self, mode: PowerManagementMode) { // power save mode let mode_num = mode.mode(); @@ -166,6 +174,7 @@ impl<'a> Control<'a> { self.ioctl_set_u32(86, 0, mode_num).await; } + /// Join an unprotected network with the provided ssid. pub async fn join_open(&mut self, ssid: &str) -> Result<(), Error> { self.set_iovar_u32("ampdu_ba_wsize", 8).await; @@ -183,6 +192,7 @@ impl<'a> Control<'a> { self.wait_for_join(i).await } + /// Join an protected network with the provided ssid and passphrase. pub async fn join_wpa2(&mut self, ssid: &str, passphrase: &str) -> Result<(), Error> { self.set_iovar_u32("ampdu_ba_wsize", 8).await; @@ -250,16 +260,19 @@ impl<'a> Control<'a> { } } + /// Set GPIO pin on WiFi chip. pub async fn gpio_set(&mut self, gpio_n: u8, gpio_en: bool) { assert!(gpio_n < 3); self.set_iovar_u32x2("gpioout", 1 << gpio_n, if gpio_en { 1 << gpio_n } else { 0 }) .await } + /// Start open access point. pub async fn start_ap_open(&mut self, ssid: &str, channel: u8) { self.start_ap(ssid, "", Security::OPEN, channel).await; } + /// Start WPA2 protected access point. pub async fn start_ap_wpa2(&mut self, ssid: &str, passphrase: &str, channel: u8) { self.start_ap(ssid, passphrase, Security::WPA2_AES_PSK, channel).await; } @@ -494,13 +507,14 @@ impl<'a> Control<'a> { } } +/// WiFi network scanner. pub struct Scanner<'a> { subscriber: EventSubscriber<'a>, events: &'a Events, } impl Scanner<'_> { - /// wait for the next found network + /// Wait for the next found network. pub async fn next(&mut self) -> Option { let event = self.subscriber.next_message_pure().await; if event.header.status != EStatus::PARTIAL { diff --git a/cyw43/src/lib.rs b/cyw43/src/lib.rs index 300465e36..19b0cb194 100644 --- a/cyw43/src/lib.rs +++ b/cyw43/src/lib.rs @@ -2,6 +2,8 @@ #![no_main] #![allow(async_fn_in_trait)] #![deny(unused_must_use)] +#![doc = include_str!("../README.md")] +#![warn(missing_docs)] // This mod MUST go first, so that the others see its macros. pub(crate) mod fmt; @@ -102,6 +104,7 @@ const CHIP: Chip = Chip { chanspec_ctl_sb_mask: 0x0700, }; +/// Driver state. pub struct State { ioctl_state: IoctlState, ch: ch::State, @@ -109,6 +112,7 @@ pub struct State { } impl State { + /// Create new driver state holder. pub fn new() -> Self { Self { ioctl_state: IoctlState::new(), @@ -118,6 +122,7 @@ impl State { } } +/// Power management modes. #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum PowerManagementMode { /// Custom, officially unsupported mode. Use at your own risk. @@ -203,8 +208,13 @@ impl PowerManagementMode { } } +/// Embassy-net driver. pub type NetDriver<'a> = ch::Device<'a, MTU>; +/// Create a new instance of the CYW43 driver. +/// +/// Returns a handle to the network device, control handle and a runner for driving the low level +/// stack. pub async fn new<'a, PWR, SPI>( state: &'a mut State, pwr: PWR, diff --git a/cyw43/src/runner.rs b/cyw43/src/runner.rs index 83aee6b40..b2a9e3e80 100644 --- a/cyw43/src/runner.rs +++ b/cyw43/src/runner.rs @@ -34,6 +34,7 @@ impl Default for LogState { } } +/// Driver communicating with the WiFi chip. pub struct Runner<'a, PWR, SPI> { ch: ch::Runner<'a, MTU>, bus: Bus, @@ -222,6 +223,7 @@ where } } + /// Run the pub async fn run(mut self) -> ! { let mut buf = [0; 512]; loop { diff --git a/cyw43/src/structs.rs b/cyw43/src/structs.rs index 5ba633c74..5ea62d95b 100644 --- a/cyw43/src/structs.rs +++ b/cyw43/src/structs.rs @@ -4,13 +4,16 @@ use crate::fmt::Bytes; macro_rules! impl_bytes { ($t:ident) => { impl $t { + /// Bytes consumed by this type. pub const SIZE: usize = core::mem::size_of::(); + /// Convert to byte array. #[allow(unused)] pub fn to_bytes(&self) -> [u8; Self::SIZE] { unsafe { core::mem::transmute(*self) } } + /// Create from byte array. #[allow(unused)] pub fn from_bytes(bytes: &[u8; Self::SIZE]) -> &Self { let alignment = core::mem::align_of::(); @@ -23,6 +26,7 @@ macro_rules! impl_bytes { unsafe { core::mem::transmute(bytes) } } + /// Create from mutable byte array. #[allow(unused)] pub fn from_bytes_mut(bytes: &mut [u8; Self::SIZE]) -> &mut Self { let alignment = core::mem::align_of::(); @@ -204,6 +208,7 @@ pub struct EthernetHeader { } impl EthernetHeader { + /// Swap endianness. pub fn byteswap(&mut self) { self.ether_type = self.ether_type.to_be(); } @@ -472,19 +477,26 @@ impl ScanResults { #[repr(C, packed(2))] #[non_exhaustive] pub struct BssInfo { + /// Version. pub version: u32, + /// Length. pub length: u32, + /// BSSID. pub bssid: [u8; 6], + /// Beacon period. pub beacon_period: u16, + /// Capability. pub capability: u16, + /// SSID length. pub ssid_len: u8, + /// SSID. pub ssid: [u8; 32], // there will be more stuff here } impl_bytes!(BssInfo); impl BssInfo { - pub fn parse(packet: &mut [u8]) -> Option<&mut Self> { + pub(crate) fn parse(packet: &mut [u8]) -> Option<&mut Self> { if packet.len() < BssInfo::SIZE { return None; } From 1ea87ec6e752dca60e13731863e11d0e0f5c0492 Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Tue, 19 Dec 2023 16:18:24 +0100 Subject: [PATCH 062/124] stm32: document hrtim, qspi, sdmmc, spi. --- embassy-stm32/src/hrtim/mod.rs | 59 +++++++++++++++++++++---------- embassy-stm32/src/hrtim/traits.rs | 6 +--- embassy-stm32/src/lib.rs | 24 +------------ embassy-stm32/src/qspi/enums.rs | 2 ++ embassy-stm32/src/qspi/mod.rs | 11 ++++++ embassy-stm32/src/sdmmc/mod.rs | 39 ++++++++++++++------ embassy-stm32/src/spi/mod.rs | 46 +++++++++++++++++++++++- embassy-stm32/src/time.rs | 3 ++ 8 files changed, 132 insertions(+), 58 deletions(-) diff --git a/embassy-stm32/src/hrtim/mod.rs b/embassy-stm32/src/hrtim/mod.rs index 6539326b4..1e6626a58 100644 --- a/embassy-stm32/src/hrtim/mod.rs +++ b/embassy-stm32/src/hrtim/mod.rs @@ -15,38 +15,42 @@ use crate::rcc::get_freqs; use crate::time::Hertz; use crate::Peripheral; -pub enum Source { - Master, - ChA, - ChB, - ChC, - ChD, - ChE, - #[cfg(hrtim_v2)] - ChF, -} - +/// HRTIM burst controller instance. pub struct BurstController { phantom: PhantomData, } + +/// HRTIM master instance. pub struct Master { phantom: PhantomData, } + +/// HRTIM channel A instance. pub struct ChA { phantom: PhantomData, } + +/// HRTIM channel B instance. pub struct ChB { phantom: PhantomData, } + +/// HRTIM channel C instance. pub struct ChC { phantom: PhantomData, } + +/// HRTIM channel D instance. pub struct ChD { phantom: PhantomData, } + +/// HRTIM channel E instance. pub struct ChE { phantom: PhantomData, } + +/// HRTIM channel F instance. #[cfg(hrtim_v2)] pub struct ChF { phantom: PhantomData, @@ -60,13 +64,16 @@ mod sealed { } } +/// Advanced channel instance trait. pub trait AdvancedChannel: sealed::AdvancedChannel {} +/// HRTIM PWM pin. pub struct PwmPin<'d, Perip, Channel> { _pin: PeripheralRef<'d, AnyPin>, phantom: PhantomData<(Perip, Channel)>, } +/// HRTIM complementary PWM pin. pub struct ComplementaryPwmPin<'d, Perip, Channel> { _pin: PeripheralRef<'d, AnyPin>, phantom: PhantomData<(Perip, Channel)>, @@ -75,6 +82,7 @@ pub struct ComplementaryPwmPin<'d, Perip, Channel> { macro_rules! advanced_channel_impl { ($new_chx:ident, $channel:tt, $ch_num:expr, $pin_trait:ident, $complementary_pin_trait:ident) => { impl<'d, Perip: Instance> PwmPin<'d, Perip, $channel> { + #[doc = concat!("Create a new ", stringify!($channel), " PWM pin instance.")] pub fn $new_chx(pin: impl Peripheral

> + 'd) -> Self { into_ref!(pin); critical_section::with(|_| { @@ -91,6 +99,7 @@ macro_rules! advanced_channel_impl { } impl<'d, Perip: Instance> ComplementaryPwmPin<'d, Perip, $channel> { + #[doc = concat!("Create a new ", stringify!($channel), " complementary PWM pin instance.")] pub fn $new_chx(pin: impl Peripheral

> + 'd) -> Self { into_ref!(pin); critical_section::with(|_| { @@ -126,18 +135,29 @@ advanced_channel_impl!(new_chf, ChF, 5, ChannelFPin, ChannelFComplementaryPin); /// Struct used to divide a high resolution timer into multiple channels pub struct AdvancedPwm<'d, T: Instance> { _inner: PeripheralRef<'d, T>, + /// Master instance. pub master: Master, + /// Burst controller. pub burst_controller: BurstController, + /// Channel A. pub ch_a: ChA, + /// Channel B. pub ch_b: ChB, + /// Channel C. pub ch_c: ChC, + /// Channel D. pub ch_d: ChD, + /// Channel E. pub ch_e: ChE, + /// Channel F. #[cfg(hrtim_v2)] pub ch_f: ChF, } impl<'d, T: Instance> AdvancedPwm<'d, T> { + /// Create a new HRTIM driver. + /// + /// This splits the HRTIM into its constituent parts, which you can then use individually. pub fn new( tim: impl Peripheral

+ 'd, _cha: Option>>, @@ -200,13 +220,7 @@ impl<'d, T: Instance> AdvancedPwm<'d, T> { } } -impl BurstController { - pub fn set_source(&mut self, _source: Source) { - todo!("burst mode control registers not implemented") - } -} - -/// Represents a fixed-frequency bridge converter +/// Fixed-frequency bridge converter driver. /// /// Our implementation of the bridge converter uses a single channel and three compare registers, /// allowing implementation of a synchronous buck or boost converter in continuous or discontinuous @@ -225,6 +239,7 @@ pub struct BridgeConverter> { } impl> BridgeConverter { + /// Create a new HRTIM bridge converter driver. pub fn new(_channel: C, frequency: Hertz) -> Self { use crate::pac::hrtim::vals::{Activeeffect, Inactiveeffect}; @@ -281,14 +296,17 @@ impl> BridgeConverter { } } + /// Start HRTIM. pub fn start(&mut self) { T::regs().mcr().modify(|w| w.set_tcen(C::raw(), true)); } + /// Stop HRTIM. pub fn stop(&mut self) { T::regs().mcr().modify(|w| w.set_tcen(C::raw(), false)); } + /// Enable burst mode. pub fn enable_burst_mode(&mut self) { T::regs().tim(C::raw()).outr().modify(|w| { // Enable Burst Mode @@ -301,6 +319,7 @@ impl> BridgeConverter { }) } + /// Disable burst mode. pub fn disable_burst_mode(&mut self) { T::regs().tim(C::raw()).outr().modify(|w| { // Disable Burst Mode @@ -357,7 +376,7 @@ impl> BridgeConverter { } } -/// Represents a variable-frequency resonant converter +/// Variable-frequency resonant converter driver. /// /// This implementation of a resonsant converter is appropriate for a half or full bridge, /// but does not include secondary rectification, which is appropriate for applications @@ -370,6 +389,7 @@ pub struct ResonantConverter> { } impl> ResonantConverter { + /// Create a new variable-frequency resonant converter driver. pub fn new(_channel: C, min_frequency: Hertz, max_frequency: Hertz) -> Self { T::set_channel_frequency(C::raw(), min_frequency); @@ -408,6 +428,7 @@ impl> ResonantConverter { T::set_channel_dead_time(C::raw(), value); } + /// Set the timer period. pub fn set_period(&mut self, period: u16) { assert!(period < self.max_period); assert!(period > self.min_period); diff --git a/embassy-stm32/src/hrtim/traits.rs b/embassy-stm32/src/hrtim/traits.rs index 34a363a1f..cfd31c47c 100644 --- a/embassy-stm32/src/hrtim/traits.rs +++ b/embassy-stm32/src/hrtim/traits.rs @@ -125,7 +125,6 @@ pub(crate) mod sealed { } /// Set the dead time as a proportion of max_duty - fn set_channel_dead_time(channel: usize, dead_time: u16) { let regs = Self::regs(); @@ -148,13 +147,10 @@ pub(crate) mod sealed { w.set_dtr(dt_val as u16); }); } - - // fn enable_outputs(enable: bool); - // - // fn enable_channel(&mut self, channel: usize, enable: bool); } } +/// HRTIM instance trait. pub trait Instance: sealed::Instance + 'static {} foreach_interrupt! { diff --git a/embassy-stm32/src/lib.rs b/embassy-stm32/src/lib.rs index fd691a732..5d9b4e6a0 100644 --- a/embassy-stm32/src/lib.rs +++ b/embassy-stm32/src/lib.rs @@ -149,33 +149,15 @@ use crate::interrupt::Priority; pub use crate::pac::NVIC_PRIO_BITS; use crate::rcc::sealed::RccPeripheral; -/// `embassy-stm32` global configuration. #[non_exhaustive] pub struct Config { - /// RCC config. pub rcc: rcc::Config, - - /// Enable debug during sleep. - /// - /// May incrase power consumption. Defaults to true. #[cfg(dbgmcu)] pub enable_debug_during_sleep: bool, - - /// BDMA interrupt priority. - /// - /// Defaults to P0 (highest). #[cfg(bdma)] pub bdma_interrupt_priority: Priority, - - /// DMA interrupt priority. - /// - /// Defaults to P0 (highest). #[cfg(dma)] pub dma_interrupt_priority: Priority, - - /// GPDMA interrupt priority. - /// - /// Defaults to P0 (highest). #[cfg(gpdma)] pub gpdma_interrupt_priority: Priority, } @@ -196,11 +178,7 @@ impl Default for Config { } } -/// Initialize the `embassy-stm32` HAL with the provided configuration. -/// -/// This returns the peripheral singletons that can be used for creating drivers. -/// -/// This should only be called once at startup, otherwise it panics. +/// Initialize embassy. pub fn init(config: Config) -> Peripherals { critical_section::with(|cs| { let p = Peripherals::take_with_cs(cs); diff --git a/embassy-stm32/src/qspi/enums.rs b/embassy-stm32/src/qspi/enums.rs index e9e7fd482..ecade9b1a 100644 --- a/embassy-stm32/src/qspi/enums.rs +++ b/embassy-stm32/src/qspi/enums.rs @@ -1,3 +1,5 @@ +//! Enums used in QSPI configuration. + #[allow(dead_code)] #[derive(Copy, Clone)] pub(crate) enum QspiMode { diff --git a/embassy-stm32/src/qspi/mod.rs b/embassy-stm32/src/qspi/mod.rs index 9ea0a726c..8a709a89e 100644 --- a/embassy-stm32/src/qspi/mod.rs +++ b/embassy-stm32/src/qspi/mod.rs @@ -14,6 +14,7 @@ use crate::pac::quadspi::Quadspi as Regs; use crate::rcc::RccPeripheral; use crate::{peripherals, Peripheral}; +/// QSPI transfer configuration. pub struct TransferConfig { /// Instraction width (IMODE) pub iwidth: QspiWidth, @@ -45,6 +46,7 @@ impl Default for TransferConfig { } } +/// QSPI driver configuration. pub struct Config { /// Flash memory size representend as 2^[0-32], as reasonable minimum 1KiB(9) was chosen. /// If you need other value the whose predefined use `Other` variant. @@ -71,6 +73,7 @@ impl Default for Config { } } +/// QSPI driver. #[allow(dead_code)] pub struct Qspi<'d, T: Instance, Dma> { _peri: PeripheralRef<'d, T>, @@ -85,6 +88,7 @@ pub struct Qspi<'d, T: Instance, Dma> { } impl<'d, T: Instance, Dma> Qspi<'d, T, Dma> { + /// Create a new QSPI driver for bank 1. pub fn new_bk1( peri: impl Peripheral

+ 'd, d0: impl Peripheral

> + 'd, @@ -125,6 +129,7 @@ impl<'d, T: Instance, Dma> Qspi<'d, T, Dma> { ) } + /// Create a new QSPI driver for bank 2. pub fn new_bk2( peri: impl Peripheral

+ 'd, d0: impl Peripheral

> + 'd, @@ -223,6 +228,7 @@ impl<'d, T: Instance, Dma> Qspi<'d, T, Dma> { } } + /// Do a QSPI command. pub fn command(&mut self, transaction: TransferConfig) { #[cfg(not(stm32h7))] T::REGS.cr().modify(|v| v.set_dmaen(false)); @@ -232,6 +238,7 @@ impl<'d, T: Instance, Dma> Qspi<'d, T, Dma> { T::REGS.fcr().modify(|v| v.set_ctcf(true)); } + /// Blocking read data. pub fn blocking_read(&mut self, buf: &mut [u8], transaction: TransferConfig) { #[cfg(not(stm32h7))] T::REGS.cr().modify(|v| v.set_dmaen(false)); @@ -256,6 +263,7 @@ impl<'d, T: Instance, Dma> Qspi<'d, T, Dma> { T::REGS.fcr().modify(|v| v.set_ctcf(true)); } + /// Blocking write data. pub fn blocking_write(&mut self, buf: &[u8], transaction: TransferConfig) { // STM32H7 does not have dmaen #[cfg(not(stm32h7))] @@ -278,6 +286,7 @@ impl<'d, T: Instance, Dma> Qspi<'d, T, Dma> { T::REGS.fcr().modify(|v| v.set_ctcf(true)); } + /// Blocking read data, using DMA. pub fn blocking_read_dma(&mut self, buf: &mut [u8], transaction: TransferConfig) where Dma: QuadDma, @@ -310,6 +319,7 @@ impl<'d, T: Instance, Dma> Qspi<'d, T, Dma> { transfer.blocking_wait(); } + /// Blocking write data, using DMA. pub fn blocking_write_dma(&mut self, buf: &[u8], transaction: TransferConfig) where Dma: QuadDma, @@ -379,6 +389,7 @@ pub(crate) mod sealed { } } +/// QSPI instance trait. pub trait Instance: Peripheral

+ sealed::Instance + RccPeripheral {} pin_trait!(SckPin, Instance); diff --git a/embassy-stm32/src/sdmmc/mod.rs b/embassy-stm32/src/sdmmc/mod.rs index 6099b9f43..ab142053a 100644 --- a/embassy-stm32/src/sdmmc/mod.rs +++ b/embassy-stm32/src/sdmmc/mod.rs @@ -54,6 +54,7 @@ const SD_INIT_FREQ: Hertz = Hertz(400_000); /// The signalling scheme used on the SDMMC bus #[non_exhaustive] +#[allow(missing_docs)] #[derive(Debug, Copy, Clone, PartialEq, Eq)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] pub enum Signalling { @@ -70,6 +71,9 @@ impl Default for Signalling { } } +/// Aligned data block for SDMMC transfers. +/// +/// This is a 512-byte array, aligned to 4 bytes to satisfy DMA requirements. #[repr(align(4))] #[derive(Debug, Clone, PartialEq, Eq)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] @@ -94,17 +98,23 @@ impl DerefMut for DataBlock { #[derive(Debug, Copy, Clone, PartialEq, Eq)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] pub enum Error { + /// Timeout reported by the hardware Timeout, + /// Timeout reported by the software driver. SoftwareTimeout, + /// Unsupported card version. UnsupportedCardVersion, + /// Unsupported card type. UnsupportedCardType, + /// CRC error. Crc, - DataCrcFail, - RxOverFlow, + /// No card inserted. NoCard, + /// Bad clock supplied to the SDMMC peripheral. BadClock, + /// Signaling switch failed. SignalingSwitchFailed, - PeripheralBusy, + /// ST bit error. #[cfg(sdmmc_v1)] StBitErr, } @@ -363,6 +373,7 @@ impl<'d, T: Instance, Dma: SdmmcDma> Sdmmc<'d, T, Dma> { #[cfg(sdmmc_v2)] impl<'d, T: Instance> Sdmmc<'d, T, NoDma> { + /// Create a new SDMMC driver, with 1 data lane. pub fn new_1bit( sdmmc: impl Peripheral

+ 'd, _irq: impl interrupt::typelevel::Binding> + 'd, @@ -396,6 +407,7 @@ impl<'d, T: Instance> Sdmmc<'d, T, NoDma> { ) } + /// Create a new SDMMC driver, with 4 data lanes. pub fn new_4bit( sdmmc: impl Peripheral

+ 'd, _irq: impl interrupt::typelevel::Binding> + 'd, @@ -497,7 +509,7 @@ impl<'d, T: Instance, Dma: SdmmcDma + 'd> Sdmmc<'d, T, Dma> { } /// Data transfer is in progress - #[inline(always)] + #[inline] fn data_active() -> bool { let regs = T::regs(); @@ -509,7 +521,7 @@ impl<'d, T: Instance, Dma: SdmmcDma + 'd> Sdmmc<'d, T, Dma> { } /// Coammand transfer is in progress - #[inline(always)] + #[inline] fn cmd_active() -> bool { let regs = T::regs(); @@ -521,7 +533,7 @@ impl<'d, T: Instance, Dma: SdmmcDma + 'd> Sdmmc<'d, T, Dma> { } /// Wait idle on CMDACT, RXACT and TXACT (v1) or DOSNACT and CPSMACT (v2) - #[inline(always)] + #[inline] fn wait_idle() { while Self::data_active() || Self::cmd_active() {} } @@ -837,7 +849,7 @@ impl<'d, T: Instance, Dma: SdmmcDma + 'd> Sdmmc<'d, T, Dma> { } /// Clear flags in interrupt clear register - #[inline(always)] + #[inline] fn clear_interrupt_flags() { let regs = T::regs(); regs.icr().write(|w| { @@ -1152,7 +1164,8 @@ impl<'d, T: Instance, Dma: SdmmcDma + 'd> Sdmmc<'d, T, Dma> { Ok(()) } - #[inline(always)] + /// Read a data block. + #[inline] pub async fn read_block(&mut self, block_idx: u32, buffer: &mut DataBlock) -> Result<(), Error> { let card_capacity = self.card()?.card_type; @@ -1204,6 +1217,7 @@ impl<'d, T: Instance, Dma: SdmmcDma + 'd> Sdmmc<'d, T, Dma> { res } + /// Write a data block. pub async fn write_block(&mut self, block_idx: u32, buffer: &DataBlock) -> Result<(), Error> { let card = self.card.as_mut().ok_or(Error::NoCard)?; @@ -1283,7 +1297,7 @@ impl<'d, T: Instance, Dma: SdmmcDma + 'd> Sdmmc<'d, T, Dma> { /// /// Returns Error::NoCard if [`init_card`](#method.init_card) /// has not previously succeeded - #[inline(always)] + #[inline] pub fn card(&self) -> Result<&Card, Error> { self.card.as_ref().ok_or(Error::NoCard) } @@ -1419,7 +1433,9 @@ pub(crate) mod sealed { pub trait Pins {} } +/// SDMMC instance trait. pub trait Instance: sealed::Instance + RccPeripheral + 'static {} + pin_trait!(CkPin, Instance); pin_trait!(CmdPin, Instance); pin_trait!(D0Pin, Instance); @@ -1434,7 +1450,10 @@ pin_trait!(D7Pin, Instance); #[cfg(sdmmc_v1)] dma_trait!(SdmmcDma, Instance); -// SDMMCv2 uses internal DMA +/// DMA instance trait. +/// +/// This is only implemented for `NoDma`, since SDMMCv2 has DMA built-in, instead of +/// using ST's system-wide DMA peripheral. #[cfg(sdmmc_v2)] pub trait SdmmcDma {} #[cfg(sdmmc_v2)] diff --git a/embassy-stm32/src/spi/mod.rs b/embassy-stm32/src/spi/mod.rs index 5a1ad3e91..674a5d316 100644 --- a/embassy-stm32/src/spi/mod.rs +++ b/embassy-stm32/src/spi/mod.rs @@ -16,27 +16,38 @@ use crate::rcc::RccPeripheral; use crate::time::Hertz; use crate::{peripherals, Peripheral}; +/// SPI error. #[derive(Debug, PartialEq, Eq)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] pub enum Error { + /// Invalid framing. Framing, + /// CRC error (only if hardware CRC checking is enabled). Crc, + /// Mode fault ModeFault, + /// Overrun. Overrun, } -// TODO move upwards in the tree +/// SPI bit order #[derive(Copy, Clone)] pub enum BitOrder { + /// Least significant bit first. LsbFirst, + /// Most significant bit first. MsbFirst, } +/// SPI configuration. #[non_exhaustive] #[derive(Copy, Clone)] pub struct Config { + /// SPI mode. pub mode: Mode, + /// Bit order. pub bit_order: BitOrder, + /// Clock frequency. pub frequency: Hertz, } @@ -73,6 +84,7 @@ impl Config { } } +/// SPI driver. pub struct Spi<'d, T: Instance, Tx, Rx> { _peri: PeripheralRef<'d, T>, sck: Option>, @@ -84,6 +96,7 @@ pub struct Spi<'d, T: Instance, Tx, Rx> { } impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> { + /// Create a new SPI driver. pub fn new( peri: impl Peripheral

+ 'd, sck: impl Peripheral

> + 'd, @@ -118,6 +131,7 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> { ) } + /// Create a new SPI driver, in RX-only mode (only MISO pin, no MOSI). pub fn new_rxonly( peri: impl Peripheral

+ 'd, sck: impl Peripheral

> + 'd, @@ -143,6 +157,7 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> { ) } + /// Create a new SPI driver, in TX-only mode (only MOSI pin, no MISO). pub fn new_txonly( peri: impl Peripheral

+ 'd, sck: impl Peripheral

> + 'd, @@ -168,6 +183,9 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> { ) } + /// Create a new SPI driver, in TX-only mode, without SCK pin. + /// + /// This can be useful for bit-banging non-SPI protocols. pub fn new_txonly_nosck( peri: impl Peripheral

+ 'd, mosi: impl Peripheral

> + 'd, @@ -355,6 +373,7 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> { Ok(()) } + /// Get current SPI configuration. pub fn get_current_config(&self) -> Config { #[cfg(any(spi_v1, spi_f1, spi_v2))] let cfg = T::REGS.cr1().read(); @@ -444,6 +463,7 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> { self.current_word_size = word_size; } + /// SPI write, using DMA. pub async fn write(&mut self, data: &[W]) -> Result<(), Error> where Tx: TxDma, @@ -477,6 +497,7 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> { Ok(()) } + /// SPI read, using DMA. pub async fn read(&mut self, data: &mut [W]) -> Result<(), Error> where Tx: TxDma, @@ -580,6 +601,12 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> { Ok(()) } + /// Bidirectional transfer, using DMA. + /// + /// This transfers both buffers at the same time, so it is NOT equivalent to `write` followed by `read`. + /// + /// The transfer runs for `max(read.len(), write.len())` bytes. If `read` is shorter extra bytes are ignored. + /// If `write` is shorter it is padded with zero bytes. pub async fn transfer(&mut self, read: &mut [W], write: &[W]) -> Result<(), Error> where Tx: TxDma, @@ -588,6 +615,9 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> { self.transfer_inner(read, write).await } + /// In-place bidirectional transfer, using DMA. + /// + /// This writes the contents of `data` on MOSI, and puts the received data on MISO in `data`, at the same time. pub async fn transfer_in_place(&mut self, data: &mut [W]) -> Result<(), Error> where Tx: TxDma, @@ -596,6 +626,7 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> { self.transfer_inner(data, data).await } + /// Blocking write. pub fn blocking_write(&mut self, words: &[W]) -> Result<(), Error> { T::REGS.cr1().modify(|w| w.set_spe(true)); flush_rx_fifo(T::REGS); @@ -606,6 +637,7 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> { Ok(()) } + /// Blocking read. pub fn blocking_read(&mut self, words: &mut [W]) -> Result<(), Error> { T::REGS.cr1().modify(|w| w.set_spe(true)); flush_rx_fifo(T::REGS); @@ -616,6 +648,9 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> { Ok(()) } + /// Blocking in-place bidirectional transfer. + /// + /// This writes the contents of `data` on MOSI, and puts the received data on MISO in `data`, at the same time. pub fn blocking_transfer_in_place(&mut self, words: &mut [W]) -> Result<(), Error> { T::REGS.cr1().modify(|w| w.set_spe(true)); flush_rx_fifo(T::REGS); @@ -626,6 +661,12 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> { Ok(()) } + /// Blocking bidirectional transfer. + /// + /// This transfers both buffers at the same time, so it is NOT equivalent to `write` followed by `read`. + /// + /// The transfer runs for `max(read.len(), write.len())` bytes. If `read` is shorter extra bytes are ignored. + /// If `write` is shorter it is padded with zero bytes. pub fn blocking_transfer(&mut self, read: &mut [W], write: &[W]) -> Result<(), Error> { T::REGS.cr1().modify(|w| w.set_spe(true)); flush_rx_fifo(T::REGS); @@ -946,6 +987,7 @@ pub(crate) mod sealed { } } +/// Word sizes usable for SPI. pub trait Word: word::Word + sealed::Word {} macro_rules! impl_word { @@ -1025,7 +1067,9 @@ mod word_impl { impl_word!(u32, 32 - 1); } +/// SPI instance trait. pub trait Instance: Peripheral

+ sealed::Instance + RccPeripheral {} + pin_trait!(SckPin, Instance); pin_trait!(MosiPin, Instance); pin_trait!(MisoPin, Instance); diff --git a/embassy-stm32/src/time.rs b/embassy-stm32/src/time.rs index a0bc33944..17690aefc 100644 --- a/embassy-stm32/src/time.rs +++ b/embassy-stm32/src/time.rs @@ -8,14 +8,17 @@ use core::ops::{Div, Mul}; pub struct Hertz(pub u32); impl Hertz { + /// Create a `Hertz` from the given hertz. pub const fn hz(hertz: u32) -> Self { Self(hertz) } + /// Create a `Hertz` from the given kilohertz. pub const fn khz(kilohertz: u32) -> Self { Self(kilohertz * 1_000) } + /// Create a `Hertz` from the given megahertz. pub const fn mhz(megahertz: u32) -> Self { Self(megahertz * 1_000_000) } From 9ddf8b08e448caca3825fc47aa737247323d8725 Mon Sep 17 00:00:00 2001 From: Ulf Lilleengen Date: Tue, 19 Dec 2023 16:33:05 +0100 Subject: [PATCH 063/124] docs: document usb-logger and usb-dfu --- embassy-usb-dfu/README.md | 20 +++++++++++++++++++ embassy-usb-dfu/src/application.rs | 1 + embassy-usb-dfu/src/consts.rs | 12 ++++++++--- embassy-usb-dfu/src/{bootloader.rs => dfu.rs} | 1 + embassy-usb-dfu/src/lib.rs | 11 +++++++--- embassy-usb-logger/README.md | 14 +++++++++++++ 6 files changed, 53 insertions(+), 6 deletions(-) create mode 100644 embassy-usb-dfu/README.md rename embassy-usb-dfu/src/{bootloader.rs => dfu.rs} (99%) diff --git a/embassy-usb-dfu/README.md b/embassy-usb-dfu/README.md new file mode 100644 index 000000000..d8bc19bfd --- /dev/null +++ b/embassy-usb-dfu/README.md @@ -0,0 +1,20 @@ +# embassy-usb-dfu + +An implementation of the USB DFU 1.1 protocol using embassy-boot. It has 2 components depending on which feature is enabled by the user. + +* DFU protocol mode, enabled by the `dfu` feature. This mode corresponds to the transfer phase DFU protocol described by the USB IF. It supports DFU_DNLOAD requests if marked by the user, and will automatically reset the chip once a DFU transaction has been completed. It also responds to DFU_GETSTATUS, DFU_GETSTATE, DFU_ABORT, and DFU_CLRSTATUS with no user intervention. +* DFU runtime mode, enabled by the `application feature`. This mode allows users to expose a DFU interface on their USB device, informing the host of the capability to DFU over USB, and allowing the host to reset the device into its bootloader to complete a DFU operation. Supports DFU_GETSTATUS and DFU_DETACH. When detach/reset is seen by the device as described by the standard, will write a new DFU magic number into the bootloader state in flash, and reset the system. + +## Minimum supported Rust version (MSRV) + +Embassy is guaranteed to compile on the latest stable Rust version at the time of release. It might compile with older versions but that may change in any new patch release. + +## License + +This work is licensed under either of + +- Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or + ) +- MIT license ([LICENSE-MIT](LICENSE-MIT) or ) + +at your option. diff --git a/embassy-usb-dfu/src/application.rs b/embassy-usb-dfu/src/application.rs index 75689db26..f0d7626f6 100644 --- a/embassy-usb-dfu/src/application.rs +++ b/embassy-usb-dfu/src/application.rs @@ -24,6 +24,7 @@ pub struct Control<'d, STATE: NorFlash, RST: Reset> { } impl<'d, STATE: NorFlash, RST: Reset> Control<'d, STATE, RST> { + /// Create a new DFU instance to expose a DFU interface. pub fn new(firmware_state: BlockingFirmwareState<'d, STATE>, attrs: DfuAttributes) -> Self { Control { firmware_state, diff --git a/embassy-usb-dfu/src/consts.rs b/embassy-usb-dfu/src/consts.rs index b359a107e..f8a056e5c 100644 --- a/embassy-usb-dfu/src/consts.rs +++ b/embassy-usb-dfu/src/consts.rs @@ -1,3 +1,4 @@ +//! USB DFU constants. pub(crate) const USB_CLASS_APPN_SPEC: u8 = 0xFE; pub(crate) const APPN_SPEC_SUBCLASS_DFU: u8 = 0x01; #[allow(unused)] @@ -18,10 +19,15 @@ defmt::bitflags! { #[cfg(not(feature = "defmt"))] bitflags::bitflags! { + /// Attributes supported by the DFU controller. pub struct DfuAttributes: u8 { + /// Generate WillDetache sequence on bus. const WILL_DETACH = 0b0000_1000; + /// Device can communicate during manifestation phase. const MANIFESTATION_TOLERANT = 0b0000_0100; + /// Capable of upload. const CAN_UPLOAD = 0b0000_0010; + /// Capable of download. const CAN_DOWNLOAD = 0b0000_0001; } } @@ -29,7 +35,7 @@ bitflags::bitflags! { #[derive(Copy, Clone, PartialEq, Eq)] #[repr(u8)] #[allow(unused)] -pub enum State { +pub(crate) enum State { AppIdle = 0, AppDetach = 1, DfuIdle = 2, @@ -46,7 +52,7 @@ pub enum State { #[derive(Copy, Clone, PartialEq, Eq)] #[repr(u8)] #[allow(unused)] -pub enum Status { +pub(crate) enum Status { Ok = 0x00, ErrTarget = 0x01, ErrFile = 0x02, @@ -67,7 +73,7 @@ pub enum Status { #[derive(Copy, Clone, PartialEq, Eq)] #[repr(u8)] -pub enum Request { +pub(crate) enum Request { Detach = 0, Dnload = 1, Upload = 2, diff --git a/embassy-usb-dfu/src/bootloader.rs b/embassy-usb-dfu/src/dfu.rs similarity index 99% rename from embassy-usb-dfu/src/bootloader.rs rename to embassy-usb-dfu/src/dfu.rs index d41e6280d..e99aa70c3 100644 --- a/embassy-usb-dfu/src/bootloader.rs +++ b/embassy-usb-dfu/src/dfu.rs @@ -23,6 +23,7 @@ pub struct Control<'d, DFU: NorFlash, STATE: NorFlash, RST: Reset, const BLOCK_S } impl<'d, DFU: NorFlash, STATE: NorFlash, RST: Reset, const BLOCK_SIZE: usize> Control<'d, DFU, STATE, RST, BLOCK_SIZE> { + /// Create a new DFU instance to handle DFU transfers. pub fn new(updater: BlockingFirmwareUpdater<'d, DFU, STATE>, attrs: DfuAttributes) -> Self { Self { updater, diff --git a/embassy-usb-dfu/src/lib.rs b/embassy-usb-dfu/src/lib.rs index 389bb33f2..eaa4b6e33 100644 --- a/embassy-usb-dfu/src/lib.rs +++ b/embassy-usb-dfu/src/lib.rs @@ -1,12 +1,14 @@ #![no_std] +#![doc = include_str!("../README.md")] +#![warn(missing_docs)] mod fmt; pub mod consts; #[cfg(feature = "dfu")] -mod bootloader; +mod dfu; #[cfg(feature = "dfu")] -pub use self::bootloader::*; +pub use self::dfu::*; #[cfg(feature = "application")] mod application; @@ -17,7 +19,7 @@ pub use self::application::*; all(feature = "dfu", feature = "application"), not(any(feature = "dfu", feature = "application")) ))] -compile_error!("usb-dfu must be compiled with exactly one of `bootloader`, or `application` features"); +compile_error!("usb-dfu must be compiled with exactly one of `dfu`, or `application` features"); /// Provides a platform-agnostic interface for initiating a system reset. /// @@ -26,9 +28,11 @@ compile_error!("usb-dfu must be compiled with exactly one of `bootloader`, or `a /// /// If alternate behaviour is desired, a custom implementation of Reset can be provided as a type argument to the usb_dfu function. pub trait Reset { + /// Reset the device. fn sys_reset() -> !; } +/// Reset immediately. #[cfg(feature = "esp32c3-hal")] pub struct ResetImmediate; @@ -40,6 +44,7 @@ impl Reset for ResetImmediate { } } +/// Reset immediately. #[cfg(feature = "cortex-m")] pub struct ResetImmediate; diff --git a/embassy-usb-logger/README.md b/embassy-usb-logger/README.md index 81b0dcd0e..6cb18e87d 100644 --- a/embassy-usb-logger/README.md +++ b/embassy-usb-logger/README.md @@ -13,3 +13,17 @@ async fn logger_task(driver: Driver<'static, USB>) { embassy_usb_logger::run!(1024, log::LevelFilter::Info, driver); } ``` + +## Minimum supported Rust version (MSRV) + +Embassy is guaranteed to compile on the latest stable Rust version at the time of release. It might compile with older versions but that may change in any new patch release. + +## License + +This work is licensed under either of + +- Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or + ) +- MIT license ([LICENSE-MIT](LICENSE-MIT) or ) + +at your option. From f97ef61ef896fa3abff7e35d78823c36ff50d9a8 Mon Sep 17 00:00:00 2001 From: Barnaby Walters Date: Tue, 19 Dec 2023 16:41:00 +0100 Subject: [PATCH 064/124] Documented usart public API --- .vscode/settings.json | 6 +-- embassy-stm32/src/usart/buffered.rs | 12 ++++++ embassy-stm32/src/usart/mod.rs | 54 +++++++++++++++++++++++-- embassy-stm32/src/usart/ringbuffered.rs | 7 +++- 4 files changed, 70 insertions(+), 9 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index d46ce603b..016df796d 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -17,12 +17,12 @@ //"rust-analyzer.cargo.target": "thumbv8m.main-none-eabihf", "rust-analyzer.cargo.features": [ // Uncomment if the example has a "nightly" feature. - "nightly", + //"nightly", ], "rust-analyzer.linkedProjects": [ // Uncomment ONE line for the chip you want to work on. // This makes rust-analyzer work on the example crate and all its dependencies. - "examples/nrf52840/Cargo.toml", + //"examples/nrf52840/Cargo.toml", // "examples/nrf52840-rtic/Cargo.toml", // "examples/nrf5340/Cargo.toml", // "examples/nrf-rtos-trace/Cargo.toml", @@ -39,7 +39,7 @@ // "examples/stm32g0/Cargo.toml", // "examples/stm32g4/Cargo.toml", // "examples/stm32h5/Cargo.toml", - // "examples/stm32h7/Cargo.toml", + "examples/stm32h7/Cargo.toml", // "examples/stm32l0/Cargo.toml", // "examples/stm32l1/Cargo.toml", // "examples/stm32l4/Cargo.toml", diff --git a/embassy-stm32/src/usart/buffered.rs b/embassy-stm32/src/usart/buffered.rs index a2e4ceaae..962547bd7 100644 --- a/embassy-stm32/src/usart/buffered.rs +++ b/embassy-stm32/src/usart/buffered.rs @@ -82,6 +82,7 @@ impl interrupt::typelevel::Handler for Interrupt } } +/// Buffered UART State pub struct State { rx_waker: AtomicWaker, rx_buf: RingBuffer, @@ -91,6 +92,7 @@ pub struct State { } impl State { + /// Create new state pub const fn new() -> Self { Self { rx_buf: RingBuffer::new(), @@ -101,15 +103,18 @@ impl State { } } +/// Bidirectional buffered UART pub struct BufferedUart<'d, T: BasicInstance> { rx: BufferedUartRx<'d, T>, tx: BufferedUartTx<'d, T>, } +/// Tx-only buffered UART pub struct BufferedUartTx<'d, T: BasicInstance> { phantom: PhantomData<&'d mut T>, } +/// Rx-only buffered UART pub struct BufferedUartRx<'d, T: BasicInstance> { phantom: PhantomData<&'d mut T>, } @@ -142,6 +147,7 @@ impl<'d, T: BasicInstance> SetConfig for BufferedUartTx<'d, T> { } impl<'d, T: BasicInstance> BufferedUart<'d, T> { + /// Create a new bidirectional buffered UART driver pub fn new( peri: impl Peripheral

+ 'd, _irq: impl interrupt::typelevel::Binding> + 'd, @@ -158,6 +164,7 @@ impl<'d, T: BasicInstance> BufferedUart<'d, T> { Self::new_inner(peri, rx, tx, tx_buffer, rx_buffer, config) } + /// Create a new bidirectional buffered UART driver with request-to-send and clear-to-send pins pub fn new_with_rtscts( peri: impl Peripheral

+ 'd, _irq: impl interrupt::typelevel::Binding> + 'd, @@ -185,6 +192,7 @@ impl<'d, T: BasicInstance> BufferedUart<'d, T> { Self::new_inner(peri, rx, tx, tx_buffer, rx_buffer, config) } + /// Create a new bidirectional buffered UART driver with a driver-enable pin #[cfg(not(any(usart_v1, usart_v2)))] pub fn new_with_de( peri: impl Peripheral

+ 'd, @@ -246,10 +254,12 @@ impl<'d, T: BasicInstance> BufferedUart<'d, T> { }) } + /// Split the driver into a Tx and Rx part (useful for sending to separate tasks) pub fn split(self) -> (BufferedUartTx<'d, T>, BufferedUartRx<'d, T>) { (self.tx, self.rx) } + /// Reconfigure the driver pub fn set_config(&mut self, config: &Config) -> Result<(), ConfigError> { reconfigure::(config)?; @@ -337,6 +347,7 @@ impl<'d, T: BasicInstance> BufferedUartRx<'d, T> { } } + /// Reconfigure the driver pub fn set_config(&mut self, config: &Config) -> Result<(), ConfigError> { reconfigure::(config)?; @@ -418,6 +429,7 @@ impl<'d, T: BasicInstance> BufferedUartTx<'d, T> { } } + /// Reconfigure the driver pub fn set_config(&mut self, config: &Config) -> Result<(), ConfigError> { reconfigure::(config)?; diff --git a/embassy-stm32/src/usart/mod.rs b/embassy-stm32/src/usart/mod.rs index e2e3bd3eb..8a0c85d2c 100644 --- a/embassy-stm32/src/usart/mod.rs +++ b/embassy-stm32/src/usart/mod.rs @@ -1,5 +1,6 @@ //! Universal Synchronous/Asynchronous Receiver Transmitter (USART, UART, LPUART) #![macro_use] +#![warn(missing_docs)] use core::future::poll_fn; use core::marker::PhantomData; @@ -77,21 +78,29 @@ impl interrupt::typelevel::Handler for Interrupt #[derive(Clone, Copy, PartialEq, Eq, Debug)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] +/// Number of data bits pub enum DataBits { + /// 8 Data Bits DataBits8, + /// 9 Data Bits DataBits9, } #[derive(Clone, Copy, PartialEq, Eq, Debug)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] +/// Parity pub enum Parity { + /// No parity ParityNone, + /// Even Parity ParityEven, + /// Odd Parity ParityOdd, } #[derive(Clone, Copy, PartialEq, Eq, Debug)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] +/// Number of stop bits pub enum StopBits { #[doc = "1 stop bit"] STOP1, @@ -106,26 +115,37 @@ pub enum StopBits { #[non_exhaustive] #[derive(Clone, Copy, PartialEq, Eq, Debug)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] +/// Config Error pub enum ConfigError { + /// Baudrate too low BaudrateTooLow, + /// Baudrate too high BaudrateTooHigh, + /// Rx or Tx not enabled RxOrTxNotEnabled, } #[non_exhaustive] #[derive(Clone, Copy, PartialEq, Eq, Debug)] +/// Config pub struct Config { + /// Baud rate pub baudrate: u32, + /// Number of data bits pub data_bits: DataBits, + /// Number of stop bits pub stop_bits: StopBits, + /// Parity type pub parity: Parity, - /// if true, on read-like method, if there is a latent error pending, - /// read will abort, the error reported and cleared - /// if false, the error is ignored and cleared + + /// If true: on a read-like method, if there is a latent error pending, + /// the read will abort and the error will be reported and cleared + /// + /// If false: the error is ignored and cleared pub detect_previous_overrun: bool, /// Set this to true if the line is considered noise free. - /// This will increase the receivers tolerance to clock deviations, + /// This will increase the receiver’s tolerance to clock deviations, /// but will effectively disable noise detection. #[cfg(not(usart_v1))] pub assume_noise_free: bool, @@ -188,6 +208,7 @@ enum ReadCompletionEvent { Idle(usize), } +/// Bidirectional UART Driver pub struct Uart<'d, T: BasicInstance, TxDma = NoDma, RxDma = NoDma> { tx: UartTx<'d, T, TxDma>, rx: UartRx<'d, T, RxDma>, @@ -203,6 +224,7 @@ impl<'d, T: BasicInstance, TxDma, RxDma> SetConfig for Uart<'d, T, TxDma, RxDma> } } +/// Tx-only UART Driver pub struct UartTx<'d, T: BasicInstance, TxDma = NoDma> { phantom: PhantomData<&'d mut T>, tx_dma: PeripheralRef<'d, TxDma>, @@ -217,6 +239,7 @@ impl<'d, T: BasicInstance, TxDma> SetConfig for UartTx<'d, T, TxDma> { } } +/// Rx-only UART Driver pub struct UartRx<'d, T: BasicInstance, RxDma = NoDma> { _peri: PeripheralRef<'d, T>, rx_dma: PeripheralRef<'d, RxDma>, @@ -247,6 +270,7 @@ impl<'d, T: BasicInstance, TxDma> UartTx<'d, T, TxDma> { Self::new_inner(peri, tx, tx_dma, config) } + /// Create a new tx-only UART with a clear-to-send pin pub fn new_with_cts( peri: impl Peripheral

+ 'd, tx: impl Peripheral

> + 'd, @@ -288,10 +312,12 @@ impl<'d, T: BasicInstance, TxDma> UartTx<'d, T, TxDma> { }) } + /// Reconfigure the driver pub fn set_config(&mut self, config: &Config) -> Result<(), ConfigError> { reconfigure::(config) } + /// Initiate an asynchronous UART write pub async fn write(&mut self, buffer: &[u8]) -> Result<(), Error> where TxDma: crate::usart::TxDma, @@ -308,6 +334,7 @@ impl<'d, T: BasicInstance, TxDma> UartTx<'d, T, TxDma> { Ok(()) } + /// Perform a blocking UART write pub fn blocking_write(&mut self, buffer: &[u8]) -> Result<(), Error> { let r = T::regs(); for &b in buffer { @@ -317,6 +344,7 @@ impl<'d, T: BasicInstance, TxDma> UartTx<'d, T, TxDma> { Ok(()) } + /// Block until transmission complete pub fn blocking_flush(&mut self) -> Result<(), Error> { let r = T::regs(); while !sr(r).read().tc() {} @@ -338,6 +366,7 @@ impl<'d, T: BasicInstance, RxDma> UartRx<'d, T, RxDma> { Self::new_inner(peri, rx, rx_dma, config) } + /// Create a new rx-only UART with a request-to-send pin pub fn new_with_rts( peri: impl Peripheral

+ 'd, _irq: impl interrupt::typelevel::Binding> + 'd, @@ -387,6 +416,7 @@ impl<'d, T: BasicInstance, RxDma> UartRx<'d, T, RxDma> { }) } + /// Reconfigure the driver pub fn set_config(&mut self, config: &Config) -> Result<(), ConfigError> { reconfigure::(config) } @@ -444,6 +474,7 @@ impl<'d, T: BasicInstance, RxDma> UartRx<'d, T, RxDma> { Ok(sr.rxne()) } + /// Initiate an asynchronous UART read pub async fn read(&mut self, buffer: &mut [u8]) -> Result<(), Error> where RxDma: crate::usart::RxDma, @@ -453,6 +484,7 @@ impl<'d, T: BasicInstance, RxDma> UartRx<'d, T, RxDma> { Ok(()) } + /// Read a single u8 if there is one available, otherwise return WouldBlock pub fn nb_read(&mut self) -> Result> { let r = T::regs(); if self.check_rx_flags()? { @@ -462,6 +494,7 @@ impl<'d, T: BasicInstance, RxDma> UartRx<'d, T, RxDma> { } } + /// Perform a blocking read into `buffer` pub fn blocking_read(&mut self, buffer: &mut [u8]) -> Result<(), Error> { let r = T::regs(); for b in buffer { @@ -471,6 +504,7 @@ impl<'d, T: BasicInstance, RxDma> UartRx<'d, T, RxDma> { Ok(()) } + /// Initiate an asynchronous read with idle line detection enabled pub async fn read_until_idle(&mut self, buffer: &mut [u8]) -> Result where RxDma: crate::usart::RxDma, @@ -695,6 +729,7 @@ impl<'d, T: BasicInstance, TxDma> Drop for UartRx<'d, T, TxDma> { } impl<'d, T: BasicInstance, TxDma, RxDma> Uart<'d, T, TxDma, RxDma> { + /// Create a new bidirectional UART pub fn new( peri: impl Peripheral

+ 'd, rx: impl Peripheral

> + 'd, @@ -711,6 +746,7 @@ impl<'d, T: BasicInstance, TxDma, RxDma> Uart<'d, T, TxDma, RxDma> { Self::new_inner(peri, rx, tx, tx_dma, rx_dma, config) } + /// Create a new bidirectional UART with request-to-send and clear-to-send pins pub fn new_with_rtscts( peri: impl Peripheral

+ 'd, rx: impl Peripheral

> + 'd, @@ -738,6 +774,7 @@ impl<'d, T: BasicInstance, TxDma, RxDma> Uart<'d, T, TxDma, RxDma> { } #[cfg(not(any(usart_v1, usart_v2)))] + /// Create a new bidirectional UART with a driver-enable pin pub fn new_with_de( peri: impl Peripheral

+ 'd, rx: impl Peripheral

> + 'd, @@ -813,6 +850,7 @@ impl<'d, T: BasicInstance, TxDma, RxDma> Uart<'d, T, TxDma, RxDma> { }) } + /// Initiate an asynchronous write pub async fn write(&mut self, buffer: &[u8]) -> Result<(), Error> where TxDma: crate::usart::TxDma, @@ -820,14 +858,17 @@ impl<'d, T: BasicInstance, TxDma, RxDma> Uart<'d, T, TxDma, RxDma> { self.tx.write(buffer).await } + /// Perform a blocking write pub fn blocking_write(&mut self, buffer: &[u8]) -> Result<(), Error> { self.tx.blocking_write(buffer) } + /// Block until transmission complete pub fn blocking_flush(&mut self) -> Result<(), Error> { self.tx.blocking_flush() } + /// Initiate an asynchronous read into `buffer` pub async fn read(&mut self, buffer: &mut [u8]) -> Result<(), Error> where RxDma: crate::usart::RxDma, @@ -835,14 +876,17 @@ impl<'d, T: BasicInstance, TxDma, RxDma> Uart<'d, T, TxDma, RxDma> { self.rx.read(buffer).await } + /// Read a single `u8` or return `WouldBlock` pub fn nb_read(&mut self) -> Result> { self.rx.nb_read() } + /// Perform a blocking read into `buffer` pub fn blocking_read(&mut self, buffer: &mut [u8]) -> Result<(), Error> { self.rx.blocking_read(buffer) } + /// Initiate an an asynchronous read with idle line detection enabled pub async fn read_until_idle(&mut self, buffer: &mut [u8]) -> Result where RxDma: crate::usart::RxDma, @@ -1292,8 +1336,10 @@ pub(crate) mod sealed { } } +/// Basic UART driver instance pub trait BasicInstance: Peripheral

+ sealed::BasicInstance + 'static + Send {} +/// Full UART driver instance pub trait FullInstance: sealed::FullInstance {} pin_trait!(RxPin, BasicInstance); diff --git a/embassy-stm32/src/usart/ringbuffered.rs b/embassy-stm32/src/usart/ringbuffered.rs index f8ada3926..4391bfef7 100644 --- a/embassy-stm32/src/usart/ringbuffered.rs +++ b/embassy-stm32/src/usart/ringbuffered.rs @@ -11,6 +11,7 @@ use super::{clear_interrupt_flags, rdr, reconfigure, sr, BasicInstance, Config, use crate::dma::ReadableRingBuffer; use crate::usart::{Regs, Sr}; +/// Rx-only Ring-buffered UART Driver pub struct RingBufferedUartRx<'d, T: BasicInstance, RxDma: super::RxDma> { _peri: PeripheralRef<'d, T>, ring_buf: ReadableRingBuffer<'d, RxDma, u8>, @@ -27,8 +28,8 @@ impl<'d, T: BasicInstance, RxDma: super::RxDma> SetConfig for RingBufferedUar impl<'d, T: BasicInstance, RxDma: super::RxDma> UartRx<'d, T, RxDma> { /// Turn the `UartRx` into a buffered uart which can continously receive in the background - /// without the possibility of loosing bytes. The `dma_buf` is a buffer registered to the - /// DMA controller, and must be sufficiently large, such that it will not overflow. + /// without the possibility of losing bytes. The `dma_buf` is a buffer registered to the + /// DMA controller, and must be large enough to prevent overflows. pub fn into_ring_buffered(self, dma_buf: &'d mut [u8]) -> RingBufferedUartRx<'d, T, RxDma> { assert!(!dma_buf.is_empty() && dma_buf.len() <= 0xFFFF); @@ -49,6 +50,7 @@ impl<'d, T: BasicInstance, RxDma: super::RxDma> UartRx<'d, T, RxDma> { } impl<'d, T: BasicInstance, RxDma: super::RxDma> RingBufferedUartRx<'d, T, RxDma> { + /// Clear the ring buffer and start receiving in the background pub fn start(&mut self) -> Result<(), Error> { // Clear the ring buffer so that it is ready to receive data self.ring_buf.clear(); @@ -64,6 +66,7 @@ impl<'d, T: BasicInstance, RxDma: super::RxDma> RingBufferedUartRx<'d, T, RxD Err(err) } + /// Cleanly stop and reconfigure the driver pub fn set_config(&mut self, config: &Config) -> Result<(), ConfigError> { self.teardown_uart(); reconfigure::(config) From 6564c045317defa309921fed74c0c096973330e4 Mon Sep 17 00:00:00 2001 From: Barnaby Walters Date: Tue, 19 Dec 2023 16:42:51 +0100 Subject: [PATCH 065/124] Reset .vscode/settings.json (doh) --- .vscode/settings.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 016df796d..d46ce603b 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -17,12 +17,12 @@ //"rust-analyzer.cargo.target": "thumbv8m.main-none-eabihf", "rust-analyzer.cargo.features": [ // Uncomment if the example has a "nightly" feature. - //"nightly", + "nightly", ], "rust-analyzer.linkedProjects": [ // Uncomment ONE line for the chip you want to work on. // This makes rust-analyzer work on the example crate and all its dependencies. - //"examples/nrf52840/Cargo.toml", + "examples/nrf52840/Cargo.toml", // "examples/nrf52840-rtic/Cargo.toml", // "examples/nrf5340/Cargo.toml", // "examples/nrf-rtos-trace/Cargo.toml", @@ -39,7 +39,7 @@ // "examples/stm32g0/Cargo.toml", // "examples/stm32g4/Cargo.toml", // "examples/stm32h5/Cargo.toml", - "examples/stm32h7/Cargo.toml", + // "examples/stm32h7/Cargo.toml", // "examples/stm32l0/Cargo.toml", // "examples/stm32l1/Cargo.toml", // "examples/stm32l4/Cargo.toml", From 189b15c426a3a9ef7d4024ba7e5de6a255f88ee7 Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Tue, 19 Dec 2023 17:35:38 +0100 Subject: [PATCH 066/124] stm32/timer: docs. --- embassy-stm32/src/hrtim/mod.rs | 16 +- embassy-stm32/src/lib.rs | 25 ++- embassy-stm32/src/timer/complementary_pwm.rs | 31 +++- embassy-stm32/src/timer/mod.rs | 158 +++++++++++++++--- embassy-stm32/src/timer/qei.rs | 23 ++- embassy-stm32/src/timer/simple_pwm.rs | 43 +++-- examples/stm32f4/src/bin/ws2812_pwm_dma.rs | 2 +- .../stm32h7/src/bin/low_level_timer_api.rs | 10 +- 8 files changed, 247 insertions(+), 61 deletions(-) diff --git a/embassy-stm32/src/hrtim/mod.rs b/embassy-stm32/src/hrtim/mod.rs index 1e6626a58..faefaabbc 100644 --- a/embassy-stm32/src/hrtim/mod.rs +++ b/embassy-stm32/src/hrtim/mod.rs @@ -68,22 +68,22 @@ mod sealed { pub trait AdvancedChannel: sealed::AdvancedChannel {} /// HRTIM PWM pin. -pub struct PwmPin<'d, Perip, Channel> { +pub struct PwmPin<'d, T, C> { _pin: PeripheralRef<'d, AnyPin>, - phantom: PhantomData<(Perip, Channel)>, + phantom: PhantomData<(T, C)>, } /// HRTIM complementary PWM pin. -pub struct ComplementaryPwmPin<'d, Perip, Channel> { +pub struct ComplementaryPwmPin<'d, T, C> { _pin: PeripheralRef<'d, AnyPin>, - phantom: PhantomData<(Perip, Channel)>, + phantom: PhantomData<(T, C)>, } macro_rules! advanced_channel_impl { ($new_chx:ident, $channel:tt, $ch_num:expr, $pin_trait:ident, $complementary_pin_trait:ident) => { - impl<'d, Perip: Instance> PwmPin<'d, Perip, $channel> { + impl<'d, T: Instance> PwmPin<'d, T, $channel> { #[doc = concat!("Create a new ", stringify!($channel), " PWM pin instance.")] - pub fn $new_chx(pin: impl Peripheral

> + 'd) -> Self { + pub fn $new_chx(pin: impl Peripheral

> + 'd) -> Self { into_ref!(pin); critical_section::with(|_| { pin.set_low(); @@ -98,9 +98,9 @@ macro_rules! advanced_channel_impl { } } - impl<'d, Perip: Instance> ComplementaryPwmPin<'d, Perip, $channel> { + impl<'d, T: Instance> ComplementaryPwmPin<'d, T, $channel> { #[doc = concat!("Create a new ", stringify!($channel), " complementary PWM pin instance.")] - pub fn $new_chx(pin: impl Peripheral

> + 'd) -> Self { + pub fn $new_chx(pin: impl Peripheral

> + 'd) -> Self { into_ref!(pin); critical_section::with(|_| { pin.set_low(); diff --git a/embassy-stm32/src/lib.rs b/embassy-stm32/src/lib.rs index 5d9b4e6a0..4952d26eb 100644 --- a/embassy-stm32/src/lib.rs +++ b/embassy-stm32/src/lib.rs @@ -79,6 +79,7 @@ pub(crate) mod _generated { #![allow(dead_code)] #![allow(unused_imports)] #![allow(non_snake_case)] + #![allow(missing_docs)] include!(concat!(env!("OUT_DIR"), "/_generated.rs")); } @@ -149,15 +150,33 @@ use crate::interrupt::Priority; pub use crate::pac::NVIC_PRIO_BITS; use crate::rcc::sealed::RccPeripheral; +/// `embassy-stm32` global configuration. #[non_exhaustive] pub struct Config { + /// RCC config. pub rcc: rcc::Config, + + /// Enable debug during sleep. + /// + /// May incrase power consumption. Defaults to true. #[cfg(dbgmcu)] pub enable_debug_during_sleep: bool, + + /// BDMA interrupt priority. + /// + /// Defaults to P0 (highest). #[cfg(bdma)] pub bdma_interrupt_priority: Priority, + + /// DMA interrupt priority. + /// + /// Defaults to P0 (highest). #[cfg(dma)] pub dma_interrupt_priority: Priority, + + /// GPDMA interrupt priority. + /// + /// Defaults to P0 (highest). #[cfg(gpdma)] pub gpdma_interrupt_priority: Priority, } @@ -178,7 +197,11 @@ impl Default for Config { } } -/// Initialize embassy. +/// Initialize the `embassy-stm32` HAL with the provided configuration. +/// +/// This returns the peripheral singletons that can be used for creating drivers. +/// +/// This should only be called once at startup, otherwise it panics. pub fn init(config: Config) -> Peripherals { critical_section::with(|cs| { let p = Peripherals::take_with_cs(cs); diff --git a/embassy-stm32/src/timer/complementary_pwm.rs b/embassy-stm32/src/timer/complementary_pwm.rs index e543a5b43..71d7110b5 100644 --- a/embassy-stm32/src/timer/complementary_pwm.rs +++ b/embassy-stm32/src/timer/complementary_pwm.rs @@ -13,15 +13,19 @@ use crate::gpio::{AnyPin, OutputType}; use crate::time::Hertz; use crate::Peripheral; -pub struct ComplementaryPwmPin<'d, Perip, Channel> { +/// Complementary PWM pin wrapper. +/// +/// This wraps a pin to make it usable with PWM. +pub struct ComplementaryPwmPin<'d, T, C> { _pin: PeripheralRef<'d, AnyPin>, - phantom: PhantomData<(Perip, Channel)>, + phantom: PhantomData<(T, C)>, } macro_rules! complementary_channel_impl { ($new_chx:ident, $channel:ident, $pin_trait:ident) => { - impl<'d, Perip: CaptureCompare16bitInstance> ComplementaryPwmPin<'d, Perip, $channel> { - pub fn $new_chx(pin: impl Peripheral

> + 'd, output_type: OutputType) -> Self { + impl<'d, T: CaptureCompare16bitInstance> ComplementaryPwmPin<'d, T, $channel> { + #[doc = concat!("Create a new ", stringify!($channel), " complementary PWM pin instance.")] + pub fn $new_chx(pin: impl Peripheral

> + 'd, output_type: OutputType) -> Self { into_ref!(pin); critical_section::with(|_| { pin.set_low(); @@ -43,11 +47,13 @@ complementary_channel_impl!(new_ch2, Ch2, Channel2ComplementaryPin); complementary_channel_impl!(new_ch3, Ch3, Channel3ComplementaryPin); complementary_channel_impl!(new_ch4, Ch4, Channel4ComplementaryPin); +/// PWM driver with support for standard and complementary outputs. pub struct ComplementaryPwm<'d, T> { inner: PeripheralRef<'d, T>, } impl<'d, T: ComplementaryCaptureCompare16bitInstance> ComplementaryPwm<'d, T> { + /// Create a new complementary PWM driver. pub fn new( tim: impl Peripheral

+ 'd, _ch1: Option>, @@ -72,7 +78,7 @@ impl<'d, T: ComplementaryCaptureCompare16bitInstance> ComplementaryPwm<'d, T> { let mut this = Self { inner: tim }; this.inner.set_counting_mode(counting_mode); - this.set_freq(freq); + this.set_frequency(freq); this.inner.start(); this.inner.enable_outputs(); @@ -88,17 +94,23 @@ impl<'d, T: ComplementaryCaptureCompare16bitInstance> ComplementaryPwm<'d, T> { this } + /// Enable the given channel. pub fn enable(&mut self, channel: Channel) { self.inner.enable_channel(channel, true); self.inner.enable_complementary_channel(channel, true); } + /// Disable the given channel. pub fn disable(&mut self, channel: Channel) { self.inner.enable_complementary_channel(channel, false); self.inner.enable_channel(channel, false); } - pub fn set_freq(&mut self, freq: Hertz) { + /// Set PWM frequency. + /// + /// Note: when you call this, the max duty value changes, so you will have to + /// call `set_duty` on all channels with the duty calculated based on the new max duty. + pub fn set_frequency(&mut self, freq: Hertz) { let multiplier = if self.inner.get_counting_mode().is_center_aligned() { 2u8 } else { @@ -107,15 +119,22 @@ impl<'d, T: ComplementaryCaptureCompare16bitInstance> ComplementaryPwm<'d, T> { self.inner.set_frequency(freq * multiplier); } + /// Get max duty value. + /// + /// This value depends on the configured frequency and the timer's clock rate from RCC. pub fn get_max_duty(&self) -> u16 { self.inner.get_max_compare_value() + 1 } + /// Set the duty for a given channel. + /// + /// The value ranges from 0 for 0% duty, to [`get_max_duty`](Self::get_max_duty) for 100% duty, both included. pub fn set_duty(&mut self, channel: Channel, duty: u16) { assert!(duty <= self.get_max_duty()); self.inner.set_compare_value(channel, duty) } + /// Set the output polarity for a given channel. pub fn set_polarity(&mut self, channel: Channel, polarity: OutputPolarity) { self.inner.set_output_polarity(channel, polarity); self.inner.set_complementary_output_polarity(channel, polarity); diff --git a/embassy-stm32/src/timer/mod.rs b/embassy-stm32/src/timer/mod.rs index 42ef878f7..74120adad 100644 --- a/embassy-stm32/src/timer/mod.rs +++ b/embassy-stm32/src/timer/mod.rs @@ -17,17 +17,27 @@ pub mod low_level { } pub(crate) mod sealed { - use super::*; + + /// Basic 16-bit timer instance. pub trait Basic16bitInstance: RccPeripheral { + /// Interrupt for this timer. type Interrupt: interrupt::typelevel::Interrupt; + /// Get access to the basic 16bit timer registers. + /// + /// Note: This works even if the timer is more capable, because registers + /// for the less capable timers are a subset. This allows writing a driver + /// for a given set of capabilities, and having it transparently work with + /// more capable timers. fn regs() -> crate::pac::timer::TimBasic; + /// Start the timer. fn start(&mut self) { Self::regs().cr1().modify(|r| r.set_cen(true)); } + /// Stop the timer. fn stop(&mut self) { Self::regs().cr1().modify(|r| r.set_cen(false)); } @@ -63,6 +73,9 @@ pub(crate) mod sealed { regs.cr1().modify(|r| r.set_urs(vals::Urs::ANYEVENT)); } + /// Clear update interrupt. + /// + /// Returns whether the update interrupt flag was set. fn clear_update_interrupt(&mut self) -> bool { let regs = Self::regs(); let sr = regs.sr().read(); @@ -76,14 +89,17 @@ pub(crate) mod sealed { } } + /// Enable/disable the update interrupt. fn enable_update_interrupt(&mut self, enable: bool) { Self::regs().dier().write(|r| r.set_uie(enable)); } + /// Enable/disable autoreload preload. fn set_autoreload_preload(&mut self, enable: bool) { Self::regs().cr1().modify(|r| r.set_arpe(enable)); } + /// Get the timer frequency. fn get_frequency(&self) -> Hertz { let timer_f = Self::frequency(); @@ -95,9 +111,17 @@ pub(crate) mod sealed { } } + /// Gneral-purpose 16-bit timer instance. pub trait GeneralPurpose16bitInstance: Basic16bitInstance { + /// Get access to the general purpose 16bit timer registers. + /// + /// Note: This works even if the timer is more capable, because registers + /// for the less capable timers are a subset. This allows writing a driver + /// for a given set of capabilities, and having it transparently work with + /// more capable timers. fn regs_gp16() -> crate::pac::timer::TimGp16; + /// Set counting mode. fn set_counting_mode(&mut self, mode: CountingMode) { let (cms, dir) = mode.into(); @@ -110,19 +134,29 @@ pub(crate) mod sealed { Self::regs_gp16().cr1().modify(|r| r.set_cms(cms)) } + /// Get counting mode. fn get_counting_mode(&self) -> CountingMode { let cr1 = Self::regs_gp16().cr1().read(); (cr1.cms(), cr1.dir()).into() } + /// Set clock divider. fn set_clock_division(&mut self, ckd: vals::Ckd) { Self::regs_gp16().cr1().modify(|r| r.set_ckd(ckd)); } } + /// Gneral-purpose 32-bit timer instance. pub trait GeneralPurpose32bitInstance: GeneralPurpose16bitInstance { + /// Get access to the general purpose 32bit timer registers. + /// + /// Note: This works even if the timer is more capable, because registers + /// for the less capable timers are a subset. This allows writing a driver + /// for a given set of capabilities, and having it transparently work with + /// more capable timers. fn regs_gp32() -> crate::pac::timer::TimGp32; + /// Set timer frequency. fn set_frequency(&mut self, frequency: Hertz) { let f = frequency.0; assert!(f > 0); @@ -140,6 +174,7 @@ pub(crate) mod sealed { regs.cr1().modify(|r| r.set_urs(vals::Urs::ANYEVENT)); } + /// Get timer frequency. fn get_frequency(&self) -> Hertz { let timer_f = Self::frequency(); @@ -151,141 +186,177 @@ pub(crate) mod sealed { } } + /// Advanced control timer instance. pub trait AdvancedControlInstance: GeneralPurpose16bitInstance { + /// Get access to the advanced timer registers. fn regs_advanced() -> crate::pac::timer::TimAdv; } + /// Capture/Compare 16-bit timer instance. pub trait CaptureCompare16bitInstance: GeneralPurpose16bitInstance { + /// Set input capture filter. fn set_input_capture_filter(&mut self, channel: Channel, icf: vals::Icf) { - let raw_channel = channel.raw(); + let raw_channel = channel.index(); Self::regs_gp16() .ccmr_input(raw_channel / 2) .modify(|r| r.set_icf(raw_channel % 2, icf)); } + /// Clear input interrupt. fn clear_input_interrupt(&mut self, channel: Channel) { - Self::regs_gp16().sr().modify(|r| r.set_ccif(channel.raw(), false)); + Self::regs_gp16().sr().modify(|r| r.set_ccif(channel.index(), false)); } + /// Enable input interrupt. fn enable_input_interrupt(&mut self, channel: Channel, enable: bool) { - Self::regs_gp16().dier().modify(|r| r.set_ccie(channel.raw(), enable)); + Self::regs_gp16().dier().modify(|r| r.set_ccie(channel.index(), enable)); } + + /// Set input capture prescaler. fn set_input_capture_prescaler(&mut self, channel: Channel, factor: u8) { - let raw_channel = channel.raw(); + let raw_channel = channel.index(); Self::regs_gp16() .ccmr_input(raw_channel / 2) .modify(|r| r.set_icpsc(raw_channel % 2, factor)); } + /// Set input TI selection. fn set_input_ti_selection(&mut self, channel: Channel, tisel: InputTISelection) { - let raw_channel = channel.raw(); + let raw_channel = channel.index(); Self::regs_gp16() .ccmr_input(raw_channel / 2) .modify(|r| r.set_ccs(raw_channel % 2, tisel.into())); } + + /// Set input capture mode. fn set_input_capture_mode(&mut self, channel: Channel, mode: InputCaptureMode) { Self::regs_gp16().ccer().modify(|r| match mode { InputCaptureMode::Rising => { - r.set_ccnp(channel.raw(), false); - r.set_ccp(channel.raw(), false); + r.set_ccnp(channel.index(), false); + r.set_ccp(channel.index(), false); } InputCaptureMode::Falling => { - r.set_ccnp(channel.raw(), false); - r.set_ccp(channel.raw(), true); + r.set_ccnp(channel.index(), false); + r.set_ccp(channel.index(), true); } InputCaptureMode::BothEdges => { - r.set_ccnp(channel.raw(), true); - r.set_ccp(channel.raw(), true); + r.set_ccnp(channel.index(), true); + r.set_ccp(channel.index(), true); } }); } + + /// Enable timer outputs. fn enable_outputs(&mut self); + /// Set output compare mode. fn set_output_compare_mode(&mut self, channel: Channel, mode: OutputCompareMode) { let r = Self::regs_gp16(); - let raw_channel: usize = channel.raw(); + let raw_channel: usize = channel.index(); r.ccmr_output(raw_channel / 2) .modify(|w| w.set_ocm(raw_channel % 2, mode.into())); } + /// Set output polarity. fn set_output_polarity(&mut self, channel: Channel, polarity: OutputPolarity) { Self::regs_gp16() .ccer() - .modify(|w| w.set_ccp(channel.raw(), polarity.into())); + .modify(|w| w.set_ccp(channel.index(), polarity.into())); } + /// Enable/disable a channel. fn enable_channel(&mut self, channel: Channel, enable: bool) { - Self::regs_gp16().ccer().modify(|w| w.set_cce(channel.raw(), enable)); + Self::regs_gp16().ccer().modify(|w| w.set_cce(channel.index(), enable)); } + /// Set compare value for a channel. fn set_compare_value(&mut self, channel: Channel, value: u16) { - Self::regs_gp16().ccr(channel.raw()).modify(|w| w.set_ccr(value)); + Self::regs_gp16().ccr(channel.index()).modify(|w| w.set_ccr(value)); } + /// Get capture value for a channel. fn get_capture_value(&mut self, channel: Channel) -> u16 { - Self::regs_gp16().ccr(channel.raw()).read().ccr() + Self::regs_gp16().ccr(channel.index()).read().ccr() } + /// Get max compare value. This depends on the timer frequency and the clock frequency from RCC. fn get_max_compare_value(&self) -> u16 { Self::regs_gp16().arr().read().arr() } + /// Get compare value for a channel. fn get_compare_value(&self, channel: Channel) -> u16 { - Self::regs_gp16().ccr(channel.raw()).read().ccr() + Self::regs_gp16().ccr(channel.index()).read().ccr() } } + /// Capture/Compare 16-bit timer instance with complementary pin support. pub trait ComplementaryCaptureCompare16bitInstance: CaptureCompare16bitInstance + AdvancedControlInstance { + /// Set complementary output polarity. fn set_complementary_output_polarity(&mut self, channel: Channel, polarity: OutputPolarity) { Self::regs_advanced() .ccer() - .modify(|w| w.set_ccnp(channel.raw(), polarity.into())); + .modify(|w| w.set_ccnp(channel.index(), polarity.into())); } + /// Set clock divider for the dead time. fn set_dead_time_clock_division(&mut self, value: vals::Ckd) { Self::regs_advanced().cr1().modify(|w| w.set_ckd(value)); } + /// Set dead time, as a fraction of the max duty value. fn set_dead_time_value(&mut self, value: u8) { Self::regs_advanced().bdtr().modify(|w| w.set_dtg(value)); } + /// Enable/disable a complementary channel. fn enable_complementary_channel(&mut self, channel: Channel, enable: bool) { Self::regs_advanced() .ccer() - .modify(|w| w.set_ccne(channel.raw(), enable)); + .modify(|w| w.set_ccne(channel.index(), enable)); } } + /// Capture/Compare 32-bit timer instance. pub trait CaptureCompare32bitInstance: GeneralPurpose32bitInstance + CaptureCompare16bitInstance { + /// Set comapre value for a channel. fn set_compare_value(&mut self, channel: Channel, value: u32) { - Self::regs_gp32().ccr(channel.raw()).modify(|w| w.set_ccr(value)); + Self::regs_gp32().ccr(channel.index()).modify(|w| w.set_ccr(value)); } + /// Get capture value for a channel. fn get_capture_value(&mut self, channel: Channel) -> u32 { - Self::regs_gp32().ccr(channel.raw()).read().ccr() + Self::regs_gp32().ccr(channel.index()).read().ccr() } + /// Get max compare value. This depends on the timer frequency and the clock frequency from RCC. fn get_max_compare_value(&self) -> u32 { Self::regs_gp32().arr().read().arr() } + /// Get compare value for a channel. fn get_compare_value(&self, channel: Channel) -> u32 { - Self::regs_gp32().ccr(channel.raw()).read().ccr() + Self::regs_gp32().ccr(channel.index()).read().ccr() } } } +/// Timer channel. #[derive(Clone, Copy)] pub enum Channel { + /// Channel 1. Ch1, + /// Channel 2. Ch2, + /// Channel 3. Ch3, + /// Channel 4. Ch4, } impl Channel { - pub fn raw(&self) -> usize { + /// Get the channel index (0..3) + pub fn index(&self) -> usize { match self { Channel::Ch1 => 0, Channel::Ch2 => 1, @@ -295,17 +366,25 @@ impl Channel { } } +/// Input capture mode. #[derive(Clone, Copy)] pub enum InputCaptureMode { + /// Rising edge only. Rising, + /// Falling edge only. Falling, + /// Both rising or falling edges. BothEdges, } +/// Input TI selection. #[derive(Clone, Copy)] pub enum InputTISelection { + /// Normal Normal, + /// Alternate Alternate, + /// TRC TRC, } @@ -319,6 +398,7 @@ impl From for stm32_metapac::timer::vals::CcmrInputCcs { } } +/// Timer counting mode. #[repr(u8)] #[derive(Debug, Clone, Copy, PartialEq, Eq, Default)] pub enum CountingMode { @@ -345,6 +425,7 @@ pub enum CountingMode { } impl CountingMode { + /// Return whether this mode is edge-aligned (up or down). pub fn is_edge_aligned(&self) -> bool { match self { CountingMode::EdgeAlignedUp | CountingMode::EdgeAlignedDown => true, @@ -352,6 +433,7 @@ impl CountingMode { } } + /// Return whether this mode is center-aligned. pub fn is_center_aligned(&self) -> bool { match self { CountingMode::CenterAlignedDownInterrupts @@ -386,16 +468,34 @@ impl From<(vals::Cms, vals::Dir)> for CountingMode { } } +/// Output compare mode. #[derive(Clone, Copy)] pub enum OutputCompareMode { + /// The comparison between the output compare register TIMx_CCRx and + /// the counter TIMx_CNT has no effect on the outputs. + /// (this mode is used to generate a timing base). Frozen, + /// Set channel to active level on match. OCxREF signal is forced high when the + /// counter TIMx_CNT matches the capture/compare register x (TIMx_CCRx). ActiveOnMatch, + /// Set channel to inactive level on match. OCxREF signal is forced low when the + /// counter TIMx_CNT matches the capture/compare register x (TIMx_CCRx). InactiveOnMatch, + /// Toggle - OCxREF toggles when TIMx_CNT=TIMx_CCRx. Toggle, + /// Force inactive level - OCxREF is forced low. ForceInactive, + /// Force active level - OCxREF is forced high. ForceActive, + /// PWM mode 1 - In upcounting, channel is active as long as TIMx_CNTTIMx_CCRx else active (OCxREF=1). PwmMode1, + /// PWM mode 2 - In upcounting, channel is inactive as long as + /// TIMx_CNTTIMx_CCRx else inactive. PwmMode2, + // TODO: there's more modes here depending on the chip family. } impl From for stm32_metapac::timer::vals::Ocm { @@ -413,9 +513,12 @@ impl From for stm32_metapac::timer::vals::Ocm { } } +/// Timer output pin polarity. #[derive(Clone, Copy)] pub enum OutputPolarity { + /// Active high (higher duty value makes the pin spend more time high). ActiveHigh, + /// Active low (higher duty value makes the pin spend more time low). ActiveLow, } @@ -428,24 +531,31 @@ impl From for bool { } } +/// Basic 16-bit timer instance. pub trait Basic16bitInstance: sealed::Basic16bitInstance + 'static {} +/// Gneral-purpose 16-bit timer instance. pub trait GeneralPurpose16bitInstance: sealed::GeneralPurpose16bitInstance + 'static {} +/// Gneral-purpose 32-bit timer instance. pub trait GeneralPurpose32bitInstance: sealed::GeneralPurpose32bitInstance + 'static {} +/// Advanced control timer instance. pub trait AdvancedControlInstance: sealed::AdvancedControlInstance + 'static {} +/// Capture/Compare 16-bit timer instance. pub trait CaptureCompare16bitInstance: sealed::CaptureCompare16bitInstance + GeneralPurpose16bitInstance + 'static { } +/// Capture/Compare 16-bit timer instance with complementary pin support. pub trait ComplementaryCaptureCompare16bitInstance: sealed::ComplementaryCaptureCompare16bitInstance + AdvancedControlInstance + 'static { } +/// Capture/Compare 32-bit timer instance. pub trait CaptureCompare32bitInstance: sealed::CaptureCompare32bitInstance + CaptureCompare16bitInstance + GeneralPurpose32bitInstance + 'static { diff --git a/embassy-stm32/src/timer/qei.rs b/embassy-stm32/src/timer/qei.rs index 9f9379c20..59efb72ba 100644 --- a/embassy-stm32/src/timer/qei.rs +++ b/embassy-stm32/src/timer/qei.rs @@ -9,23 +9,30 @@ use crate::gpio::sealed::AFType; use crate::gpio::AnyPin; use crate::Peripheral; +/// Counting direction pub enum Direction { + /// Counting up. Upcounting, + /// Counting down. Downcounting, } -pub struct Ch1; -pub struct Ch2; +/// Channel 1 marker type. +pub enum Ch1 {} +/// Channel 2 marker type. +pub enum Ch2 {} -pub struct QeiPin<'d, Perip, Channel> { +/// Wrapper for using a pin with QEI. +pub struct QeiPin<'d, T, Channel> { _pin: PeripheralRef<'d, AnyPin>, - phantom: PhantomData<(Perip, Channel)>, + phantom: PhantomData<(T, Channel)>, } macro_rules! channel_impl { ($new_chx:ident, $channel:ident, $pin_trait:ident) => { - impl<'d, Perip: CaptureCompare16bitInstance> QeiPin<'d, Perip, $channel> { - pub fn $new_chx(pin: impl Peripheral

> + 'd) -> Self { + impl<'d, T: CaptureCompare16bitInstance> QeiPin<'d, T, $channel> { + #[doc = concat!("Create a new ", stringify!($channel), " QEI pin instance.")] + pub fn $new_chx(pin: impl Peripheral

> + 'd) -> Self { into_ref!(pin); critical_section::with(|_| { pin.set_low(); @@ -45,11 +52,13 @@ macro_rules! channel_impl { channel_impl!(new_ch1, Ch1, Channel1Pin); channel_impl!(new_ch2, Ch2, Channel2Pin); +/// Quadrature decoder driver. pub struct Qei<'d, T> { _inner: PeripheralRef<'d, T>, } impl<'d, T: CaptureCompare16bitInstance> Qei<'d, T> { + /// Create a new quadrature decoder driver. pub fn new(tim: impl Peripheral

+ 'd, _ch1: QeiPin<'d, T, Ch1>, _ch2: QeiPin<'d, T, Ch2>) -> Self { Self::new_inner(tim) } @@ -84,6 +93,7 @@ impl<'d, T: CaptureCompare16bitInstance> Qei<'d, T> { Self { _inner: tim } } + /// Get direction. pub fn read_direction(&self) -> Direction { match T::regs_gp16().cr1().read().dir() { vals::Dir::DOWN => Direction::Downcounting, @@ -91,6 +101,7 @@ impl<'d, T: CaptureCompare16bitInstance> Qei<'d, T> { } } + /// Get count. pub fn count(&self) -> u16 { T::regs_gp16().cnt().read().cnt() } diff --git a/embassy-stm32/src/timer/simple_pwm.rs b/embassy-stm32/src/timer/simple_pwm.rs index 234bbaff0..e6072aa15 100644 --- a/embassy-stm32/src/timer/simple_pwm.rs +++ b/embassy-stm32/src/timer/simple_pwm.rs @@ -11,20 +11,28 @@ use crate::gpio::{AnyPin, OutputType}; use crate::time::Hertz; use crate::Peripheral; -pub struct Ch1; -pub struct Ch2; -pub struct Ch3; -pub struct Ch4; +/// Channel 1 marker type. +pub enum Ch1 {} +/// Channel 2 marker type. +pub enum Ch2 {} +/// Channel 3 marker type. +pub enum Ch3 {} +/// Channel 4 marker type. +pub enum Ch4 {} -pub struct PwmPin<'d, Perip, Channel> { +/// PWM pin wrapper. +/// +/// This wraps a pin to make it usable with PWM. +pub struct PwmPin<'d, T, C> { _pin: PeripheralRef<'d, AnyPin>, - phantom: PhantomData<(Perip, Channel)>, + phantom: PhantomData<(T, C)>, } macro_rules! channel_impl { ($new_chx:ident, $channel:ident, $pin_trait:ident) => { - impl<'d, Perip: CaptureCompare16bitInstance> PwmPin<'d, Perip, $channel> { - pub fn $new_chx(pin: impl Peripheral

> + 'd, output_type: OutputType) -> Self { + impl<'d, T: CaptureCompare16bitInstance> PwmPin<'d, T, $channel> { + #[doc = concat!("Create a new ", stringify!($channel), " PWM pin instance.")] + pub fn $new_chx(pin: impl Peripheral

> + 'd, output_type: OutputType) -> Self { into_ref!(pin); critical_section::with(|_| { pin.set_low(); @@ -46,11 +54,13 @@ channel_impl!(new_ch2, Ch2, Channel2Pin); channel_impl!(new_ch3, Ch3, Channel3Pin); channel_impl!(new_ch4, Ch4, Channel4Pin); +/// Simple PWM driver. pub struct SimplePwm<'d, T> { inner: PeripheralRef<'d, T>, } impl<'d, T: CaptureCompare16bitInstance> SimplePwm<'d, T> { + /// Create a new simple PWM driver. pub fn new( tim: impl Peripheral

+ 'd, _ch1: Option>, @@ -71,7 +81,7 @@ impl<'d, T: CaptureCompare16bitInstance> SimplePwm<'d, T> { let mut this = Self { inner: tim }; this.inner.set_counting_mode(counting_mode); - this.set_freq(freq); + this.set_frequency(freq); this.inner.start(); this.inner.enable_outputs(); @@ -87,15 +97,21 @@ impl<'d, T: CaptureCompare16bitInstance> SimplePwm<'d, T> { this } + /// Enable the given channel. pub fn enable(&mut self, channel: Channel) { self.inner.enable_channel(channel, true); } + /// Disable the given channel. pub fn disable(&mut self, channel: Channel) { self.inner.enable_channel(channel, false); } - pub fn set_freq(&mut self, freq: Hertz) { + /// Set PWM frequency. + /// + /// Note: when you call this, the max duty value changes, so you will have to + /// call `set_duty` on all channels with the duty calculated based on the new max duty. + pub fn set_frequency(&mut self, freq: Hertz) { let multiplier = if self.inner.get_counting_mode().is_center_aligned() { 2u8 } else { @@ -104,15 +120,22 @@ impl<'d, T: CaptureCompare16bitInstance> SimplePwm<'d, T> { self.inner.set_frequency(freq * multiplier); } + /// Get max duty value. + /// + /// This value depends on the configured frequency and the timer's clock rate from RCC. pub fn get_max_duty(&self) -> u16 { self.inner.get_max_compare_value() + 1 } + /// Set the duty for a given channel. + /// + /// The value ranges from 0 for 0% duty, to [`get_max_duty`](Self::get_max_duty) for 100% duty, both included. pub fn set_duty(&mut self, channel: Channel, duty: u16) { assert!(duty <= self.get_max_duty()); self.inner.set_compare_value(channel, duty) } + /// Set the output polarity for a given channel. pub fn set_polarity(&mut self, channel: Channel, polarity: OutputPolarity) { self.inner.set_output_polarity(channel, polarity); } diff --git a/examples/stm32f4/src/bin/ws2812_pwm_dma.rs b/examples/stm32f4/src/bin/ws2812_pwm_dma.rs index 52cc665c7..39f5d3421 100644 --- a/examples/stm32f4/src/bin/ws2812_pwm_dma.rs +++ b/examples/stm32f4/src/bin/ws2812_pwm_dma.rs @@ -110,7 +110,7 @@ async fn main(_spawner: Spawner) { &mut dp.DMA1_CH2, 5, color_list[color_list_index], - pac::TIM3.ccr(pwm_channel.raw()).as_ptr() as *mut _, + pac::TIM3.ccr(pwm_channel.index()).as_ptr() as *mut _, dma_transfer_option, ) .await; diff --git a/examples/stm32h7/src/bin/low_level_timer_api.rs b/examples/stm32h7/src/bin/low_level_timer_api.rs index e0be495d1..394ed3281 100644 --- a/examples/stm32h7/src/bin/low_level_timer_api.rs +++ b/examples/stm32h7/src/bin/low_level_timer_api.rs @@ -85,7 +85,7 @@ impl<'d, T: CaptureCompare32bitInstance> SimplePwm32<'d, T> { let mut this = Self { inner: tim }; - this.set_freq(freq); + this.set_frequency(freq); this.inner.start(); let r = T::regs_gp32(); @@ -102,14 +102,14 @@ impl<'d, T: CaptureCompare32bitInstance> SimplePwm32<'d, T> { } pub fn enable(&mut self, channel: Channel) { - T::regs_gp32().ccer().modify(|w| w.set_cce(channel.raw(), true)); + T::regs_gp32().ccer().modify(|w| w.set_cce(channel.index(), true)); } pub fn disable(&mut self, channel: Channel) { - T::regs_gp32().ccer().modify(|w| w.set_cce(channel.raw(), false)); + T::regs_gp32().ccer().modify(|w| w.set_cce(channel.index(), false)); } - pub fn set_freq(&mut self, freq: Hertz) { + pub fn set_frequency(&mut self, freq: Hertz) { ::set_frequency(&mut self.inner, freq); } @@ -119,6 +119,6 @@ impl<'d, T: CaptureCompare32bitInstance> SimplePwm32<'d, T> { pub fn set_duty(&mut self, channel: Channel, duty: u32) { defmt::assert!(duty < self.get_max_duty()); - T::regs_gp32().ccr(channel.raw()).modify(|w| w.set_ccr(duty)) + T::regs_gp32().ccr(channel.index()).modify(|w| w.set_ccr(duty)) } } From c8c8b89104acb396476b72ff9192d7b14a46752d Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Tue, 19 Dec 2023 18:03:20 +0100 Subject: [PATCH 067/124] stm32: doc everything else. --- embassy-stm32/src/dma/gpdma.rs | 18 ++++++ embassy-stm32/src/ipcc.rs | 8 +++ embassy-stm32/src/lib.rs | 1 + embassy-stm32/src/low_power.rs | 106 +++++++++++++++++-------------- embassy-stm32/src/opamp.rs | 9 +++ embassy-stm32/src/rng.rs | 1 + embassy-stm32/src/sdmmc/mod.rs | 2 + embassy-stm32/src/usb/mod.rs | 4 ++ embassy-stm32/src/usb/usb.rs | 7 ++ embassy-stm32/src/usb_otg/mod.rs | 2 + embassy-stm32/src/usb_otg/usb.rs | 13 +++- embassy-stm32/src/wdg/mod.rs | 4 ++ 12 files changed, 127 insertions(+), 48 deletions(-) diff --git a/embassy-stm32/src/dma/gpdma.rs b/embassy-stm32/src/dma/gpdma.rs index b061415eb..34b2426b9 100644 --- a/embassy-stm32/src/dma/gpdma.rs +++ b/embassy-stm32/src/dma/gpdma.rs @@ -16,6 +16,7 @@ use crate::interrupt::Priority; use crate::pac; use crate::pac::gpdma::vals; +/// GPDMA transfer options. #[derive(Debug, Copy, Clone, PartialEq, Eq)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] #[non_exhaustive] @@ -113,10 +114,13 @@ pub(crate) unsafe fn on_irq_inner(dma: pac::gpdma::Gpdma, channel_num: usize, in } } +/// DMA request type alias. (also known as DMA channel number in some chips) pub type Request = u8; +/// DMA channel. #[cfg(dmamux)] pub trait Channel: sealed::Channel + Peripheral

+ 'static + super::dmamux::MuxChannel {} +/// DMA channel. #[cfg(not(dmamux))] pub trait Channel: sealed::Channel + Peripheral

+ 'static {} @@ -131,12 +135,14 @@ pub(crate) mod sealed { } } +/// DMA transfer. #[must_use = "futures do nothing unless you `.await` or poll them"] pub struct Transfer<'a, C: Channel> { channel: PeripheralRef<'a, C>, } impl<'a, C: Channel> Transfer<'a, C> { + /// Create a new read DMA transfer (peripheral to memory). pub unsafe fn new_read( channel: impl Peripheral

+ 'a, request: Request, @@ -147,6 +153,7 @@ impl<'a, C: Channel> Transfer<'a, C> { Self::new_read_raw(channel, request, peri_addr, buf, options) } + /// Create a new read DMA transfer (peripheral to memory), using raw pointers. pub unsafe fn new_read_raw( channel: impl Peripheral

+ 'a, request: Request, @@ -172,6 +179,7 @@ impl<'a, C: Channel> Transfer<'a, C> { ) } + /// Create a new write DMA transfer (memory to peripheral). pub unsafe fn new_write( channel: impl Peripheral

+ 'a, request: Request, @@ -182,6 +190,7 @@ impl<'a, C: Channel> Transfer<'a, C> { Self::new_write_raw(channel, request, buf, peri_addr, options) } + /// Create a new write DMA transfer (memory to peripheral), using raw pointers. pub unsafe fn new_write_raw( channel: impl Peripheral

+ 'a, request: Request, @@ -207,6 +216,7 @@ impl<'a, C: Channel> Transfer<'a, C> { ) } + /// Create a new write DMA transfer (memory to peripheral), writing the same value repeatedly. pub unsafe fn new_write_repeated( channel: impl Peripheral

+ 'a, request: Request, @@ -297,6 +307,9 @@ impl<'a, C: Channel> Transfer<'a, C> { this } + /// Request the transfer to stop. + /// + /// This doesn't immediately stop the transfer, you have to wait until [`is_running`](Self::is_running) returns false. pub fn request_stop(&mut self) { let ch = self.channel.regs().ch(self.channel.num()); ch.cr().modify(|w| { @@ -304,6 +317,10 @@ impl<'a, C: Channel> Transfer<'a, C> { }) } + /// Return whether this transfer is still running. + /// + /// If this returns `false`, it can be because either the transfer finished, or + /// it was requested to stop early with [`request_stop`](Self::request_stop). pub fn is_running(&mut self) -> bool { let ch = self.channel.regs().ch(self.channel.num()); let sr = ch.sr().read(); @@ -317,6 +334,7 @@ impl<'a, C: Channel> Transfer<'a, C> { ch.br1().read().bndt() } + /// Blocking wait until the transfer finishes. pub fn blocking_wait(mut self) { while self.is_running() {} diff --git a/embassy-stm32/src/ipcc.rs b/embassy-stm32/src/ipcc.rs index 4006dee19..663a7f59d 100644 --- a/embassy-stm32/src/ipcc.rs +++ b/embassy-stm32/src/ipcc.rs @@ -1,3 +1,5 @@ +//! Inter-Process Communication Controller (IPCC) + use core::future::poll_fn; use core::sync::atomic::{compiler_fence, Ordering}; use core::task::Poll; @@ -41,6 +43,7 @@ impl interrupt::typelevel::Handler for Receive } } +/// TX interrupt handler. pub struct TransmitInterruptHandler {} impl interrupt::typelevel::Handler for TransmitInterruptHandler { @@ -72,6 +75,7 @@ impl interrupt::typelevel::Handler for Transmi } } +/// IPCC config. #[non_exhaustive] #[derive(Clone, Copy, Default)] pub struct Config { @@ -79,6 +83,8 @@ pub struct Config { // reserved for future use } +/// Channel. +#[allow(missing_docs)] #[derive(Debug, Clone, Copy)] #[repr(C)] pub enum IpccChannel { @@ -90,9 +96,11 @@ pub enum IpccChannel { Channel6 = 5, } +/// IPCC driver. pub struct Ipcc; impl Ipcc { + /// Enable IPCC. pub fn enable(_config: Config) { IPCC::enable_and_reset(); IPCC::set_cpu2(true); diff --git a/embassy-stm32/src/lib.rs b/embassy-stm32/src/lib.rs index 4952d26eb..207f7ed8f 100644 --- a/embassy-stm32/src/lib.rs +++ b/embassy-stm32/src/lib.rs @@ -1,5 +1,6 @@ #![cfg_attr(not(test), no_std)] #![allow(async_fn_in_trait)] +#![warn(missing_docs)] //! ## Feature flags #![doc = document_features::document_features!(feature_label = r#"{feature}"#)] diff --git a/embassy-stm32/src/low_power.rs b/embassy-stm32/src/low_power.rs index 20d8f9045..a41c40eba 100644 --- a/embassy-stm32/src/low_power.rs +++ b/embassy-stm32/src/low_power.rs @@ -1,50 +1,53 @@ -/// The STM32 line of microcontrollers support various deep-sleep modes which exploit clock-gating -/// to reduce power consumption. `embassy-stm32` provides a low-power executor, [`Executor`] which -/// can use knowledge of which peripherals are currently blocked upon to transparently and safely -/// enter such low-power modes (currently, only `STOP2`) when idle. -/// -/// The executor determines which peripherals are active by their RCC state; consequently, -/// low-power states can only be entered if all peripherals have been `drop`'d. There are a few -/// exceptions to this rule: -/// -/// * `GPIO` -/// * `RCC` -/// -/// Since entering and leaving low-power modes typically incurs a significant latency, the -/// low-power executor will only attempt to enter when the next timer event is at least -/// [`time_driver::MIN_STOP_PAUSE`] in the future. -/// -/// Currently there is no macro analogous to `embassy_executor::main` for this executor; -/// consequently one must define their entrypoint manually. Moveover, you must relinquish control -/// of the `RTC` peripheral to the executor. This will typically look like -/// -/// ```rust,no_run -/// use embassy_executor::Spawner; -/// use embassy_stm32::low_power::Executor; -/// use embassy_stm32::rtc::{Rtc, RtcConfig}; -/// use static_cell::make_static; -/// -/// #[cortex_m_rt::entry] -/// fn main() -> ! { -/// Executor::take().run(|spawner| { -/// unwrap!(spawner.spawn(async_main(spawner))); -/// }); -/// } -/// -/// #[embassy_executor::task] -/// async fn async_main(spawner: Spawner) { -/// // initialize the platform... -/// let mut config = embassy_stm32::Config::default(); -/// let p = embassy_stm32::init(config); -/// -/// // give the RTC to the executor... -/// let mut rtc = Rtc::new(p.RTC, RtcConfig::default()); -/// let rtc = make_static!(rtc); -/// embassy_stm32::low_power::stop_with_rtc(rtc); -/// -/// // your application here... -/// } -/// ``` +//! Low-power support. +//! +//! The STM32 line of microcontrollers support various deep-sleep modes which exploit clock-gating +//! to reduce power consumption. `embassy-stm32` provides a low-power executor, [`Executor`] which +//! can use knowledge of which peripherals are currently blocked upon to transparently and safely +//! enter such low-power modes (currently, only `STOP2`) when idle. +//! +//! The executor determines which peripherals are active by their RCC state; consequently, +//! low-power states can only be entered if all peripherals have been `drop`'d. There are a few +//! exceptions to this rule: +//! +//! * `GPIO` +//! * `RCC` +//! +//! Since entering and leaving low-power modes typically incurs a significant latency, the +//! low-power executor will only attempt to enter when the next timer event is at least +//! [`time_driver::MIN_STOP_PAUSE`] in the future. +//! +//! Currently there is no macro analogous to `embassy_executor::main` for this executor; +//! consequently one must define their entrypoint manually. Moveover, you must relinquish control +//! of the `RTC` peripheral to the executor. This will typically look like +//! +//! ```rust,no_run +//! use embassy_executor::Spawner; +//! use embassy_stm32::low_power::Executor; +//! use embassy_stm32::rtc::{Rtc, RtcConfig}; +//! use static_cell::make_static; +//! +//! #[cortex_m_rt::entry] +//! fn main() -> ! { +//! Executor::take().run(|spawner| { +//! unwrap!(spawner.spawn(async_main(spawner))); +//! }); +//! } +//! +//! #[embassy_executor::task] +//! async fn async_main(spawner: Spawner) { +//! // initialize the platform... +//! let mut config = embassy_stm32::Config::default(); +//! let p = embassy_stm32::init(config); +//! +//! // give the RTC to the executor... +//! let mut rtc = Rtc::new(p.RTC, RtcConfig::default()); +//! let rtc = make_static!(rtc); +//! embassy_stm32::low_power::stop_with_rtc(rtc); +//! +//! // your application here... +//! } +//! ``` + use core::arch::asm; use core::marker::PhantomData; use core::sync::atomic::{compiler_fence, Ordering}; @@ -64,6 +67,7 @@ static mut EXECUTOR: Option = None; foreach_interrupt! { (RTC, rtc, $block:ident, WKUP, $irq:ident) => { #[interrupt] + #[allow(non_snake_case)] unsafe fn $irq() { EXECUTOR.as_mut().unwrap().on_wakeup_irq(); } @@ -75,10 +79,15 @@ pub(crate) unsafe fn on_wakeup_irq() { EXECUTOR.as_mut().unwrap().on_wakeup_irq(); } +/// Configure STOP mode with RTC. pub fn stop_with_rtc(rtc: &'static Rtc) { unsafe { EXECUTOR.as_mut().unwrap() }.stop_with_rtc(rtc) } +/// Get whether the core is ready to enter the given stop mode. +/// +/// This will return false if some peripheral driver is in use that +/// prevents entering the given stop mode. pub fn stop_ready(stop_mode: StopMode) -> bool { match unsafe { EXECUTOR.as_mut().unwrap() }.stop_mode() { Some(StopMode::Stop2) => true, @@ -87,10 +96,13 @@ pub fn stop_ready(stop_mode: StopMode) -> bool { } } +/// Available stop modes. #[non_exhaustive] #[derive(PartialEq)] pub enum StopMode { + /// STOP 1 Stop1, + /// STOP 2 Stop2, } diff --git a/embassy-stm32/src/opamp.rs b/embassy-stm32/src/opamp.rs index e1eb031d1..df8a78bcc 100644 --- a/embassy-stm32/src/opamp.rs +++ b/embassy-stm32/src/opamp.rs @@ -1,9 +1,12 @@ +//! Operational Amplifier (OPAMP) #![macro_use] use embassy_hal_internal::{into_ref, PeripheralRef}; use crate::Peripheral; +/// Gain +#[allow(missing_docs)] #[derive(Clone, Copy)] pub enum OpAmpGain { Mul1, @@ -13,6 +16,8 @@ pub enum OpAmpGain { Mul16, } +/// Speed +#[allow(missing_docs)] #[derive(Clone, Copy)] pub enum OpAmpSpeed { Normal, @@ -180,6 +185,7 @@ impl<'d, T: Instance> Drop for OpAmpInternalOutput<'d, T> { } } +/// Opamp instance trait. pub trait Instance: sealed::Instance + 'static {} pub(crate) mod sealed { @@ -198,8 +204,11 @@ pub(crate) mod sealed { pub trait OutputPin {} } +/// Non-inverting pin trait. pub trait NonInvertingPin: sealed::NonInvertingPin {} +/// Inverting pin trait. pub trait InvertingPin: sealed::InvertingPin {} +/// Output pin trait. pub trait OutputPin: sealed::OutputPin {} macro_rules! impl_opamp_external_output { diff --git a/embassy-stm32/src/rng.rs b/embassy-stm32/src/rng.rs index 6ee89a922..ca641f352 100644 --- a/embassy-stm32/src/rng.rs +++ b/embassy-stm32/src/rng.rs @@ -80,6 +80,7 @@ impl<'d, T: Instance> Rng<'d, T> { let _ = self.next_u32(); } + /// Reset the RNG. #[cfg(not(rng_v1))] pub fn reset(&mut self) { T::regs().cr().write(|reg| { diff --git a/embassy-stm32/src/sdmmc/mod.rs b/embassy-stm32/src/sdmmc/mod.rs index ab142053a..10006baff 100644 --- a/embassy-stm32/src/sdmmc/mod.rs +++ b/embassy-stm32/src/sdmmc/mod.rs @@ -293,6 +293,7 @@ pub struct Sdmmc<'d, T: Instance, Dma: SdmmcDma = NoDma> { #[cfg(sdmmc_v1)] impl<'d, T: Instance, Dma: SdmmcDma> Sdmmc<'d, T, Dma> { + /// Create a new SDMMC driver, with 1 data lane. pub fn new_1bit( sdmmc: impl Peripheral

+ 'd, _irq: impl interrupt::typelevel::Binding> + 'd, @@ -327,6 +328,7 @@ impl<'d, T: Instance, Dma: SdmmcDma> Sdmmc<'d, T, Dma> { ) } + /// Create a new SDMMC driver, with 4 data lanes. pub fn new_4bit( sdmmc: impl Peripheral

+ 'd, _irq: impl interrupt::typelevel::Binding> + 'd, diff --git a/embassy-stm32/src/usb/mod.rs b/embassy-stm32/src/usb/mod.rs index d0b289462..4debd4e54 100644 --- a/embassy-stm32/src/usb/mod.rs +++ b/embassy-stm32/src/usb/mod.rs @@ -1,3 +1,5 @@ +//! Universal Serial Bus (USB) + use crate::interrupt; use crate::rcc::RccPeripheral; @@ -10,7 +12,9 @@ pub(crate) mod sealed { } } +/// USB instance trait. pub trait Instance: sealed::Instance + RccPeripheral + 'static { + /// Interrupt for this USB instance. type Interrupt: interrupt::typelevel::Interrupt; } diff --git a/embassy-stm32/src/usb/usb.rs b/embassy-stm32/src/usb/usb.rs index 295dc9198..a8aebfe1f 100644 --- a/embassy-stm32/src/usb/usb.rs +++ b/embassy-stm32/src/usb/usb.rs @@ -244,6 +244,7 @@ struct EndpointData { used_out: bool, } +/// USB driver. pub struct Driver<'d, T: Instance> { phantom: PhantomData<&'d mut T>, alloc: [EndpointData; EP_COUNT], @@ -251,6 +252,7 @@ pub struct Driver<'d, T: Instance> { } impl<'d, T: Instance> Driver<'d, T> { + /// Create a new USB driver. pub fn new( _usb: impl Peripheral

+ 'd, _irq: impl interrupt::typelevel::Binding> + 'd, @@ -465,6 +467,7 @@ impl<'d, T: Instance> driver::Driver<'d> for Driver<'d, T> { } } +/// USB bus. pub struct Bus<'d, T: Instance> { phantom: PhantomData<&'d mut T>, ep_types: [EpType; EP_COUNT - 1], @@ -640,6 +643,7 @@ trait Dir { fn waker(i: usize) -> &'static AtomicWaker; } +/// Marker type for the "IN" direction. pub enum In {} impl Dir for In { fn dir() -> Direction { @@ -652,6 +656,7 @@ impl Dir for In { } } +/// Marker type for the "OUT" direction. pub enum Out {} impl Dir for Out { fn dir() -> Direction { @@ -664,6 +669,7 @@ impl Dir for Out { } } +/// USB endpoint. pub struct Endpoint<'d, T: Instance, D> { _phantom: PhantomData<(&'d mut T, D)>, info: EndpointInfo, @@ -813,6 +819,7 @@ impl<'d, T: Instance> driver::EndpointIn for Endpoint<'d, T, In> { } } +/// USB control pipe. pub struct ControlPipe<'d, T: Instance> { _phantom: PhantomData<&'d mut T>, max_packet_size: u16, diff --git a/embassy-stm32/src/usb_otg/mod.rs b/embassy-stm32/src/usb_otg/mod.rs index 1abd031dd..0649e684b 100644 --- a/embassy-stm32/src/usb_otg/mod.rs +++ b/embassy-stm32/src/usb_otg/mod.rs @@ -20,7 +20,9 @@ pub(crate) mod sealed { } } +/// USB OTG instance. pub trait Instance: sealed::Instance + RccPeripheral { + /// Interrupt for this USB OTG instance. type Interrupt: interrupt::typelevel::Interrupt; } diff --git a/embassy-stm32/src/usb_otg/usb.rs b/embassy-stm32/src/usb_otg/usb.rs index ba77bfb16..190fb274f 100644 --- a/embassy-stm32/src/usb_otg/usb.rs +++ b/embassy-stm32/src/usb_otg/usb.rs @@ -204,6 +204,7 @@ pub enum PhyType { } impl PhyType { + /// Get whether this PHY is any of the internal types. pub fn internal(&self) -> bool { match self { PhyType::InternalFullSpeed | PhyType::InternalHighSpeed => true, @@ -211,6 +212,7 @@ impl PhyType { } } + /// Get whether this PHY is any of the high-speed types. pub fn high_speed(&self) -> bool { match self { PhyType::InternalFullSpeed => false, @@ -218,7 +220,7 @@ impl PhyType { } } - pub fn to_dspd(&self) -> vals::Dspd { + fn to_dspd(&self) -> vals::Dspd { match self { PhyType::InternalFullSpeed => vals::Dspd::FULL_SPEED_INTERNAL, PhyType::InternalHighSpeed => vals::Dspd::HIGH_SPEED, @@ -230,6 +232,7 @@ impl PhyType { /// Indicates that [State::ep_out_buffers] is empty. const EP_OUT_BUFFER_EMPTY: u16 = u16::MAX; +/// USB OTG driver state. pub struct State { /// Holds received SETUP packets. Available if [State::ep0_setup_ready] is true. ep0_setup_data: UnsafeCell<[u8; 8]>, @@ -247,6 +250,7 @@ unsafe impl Send for State {} unsafe impl Sync for State {} impl State { + /// Create a new State. pub const fn new() -> Self { const NEW_AW: AtomicWaker = AtomicWaker::new(); const NEW_BUF: UnsafeCell<*mut u8> = UnsafeCell::new(0 as _); @@ -271,6 +275,7 @@ struct EndpointData { fifo_size_words: u16, } +/// USB driver config. #[non_exhaustive] #[derive(Clone, Copy, PartialEq, Eq, Debug)] pub struct Config { @@ -297,6 +302,7 @@ impl Default for Config { } } +/// USB driver. pub struct Driver<'d, T: Instance> { config: Config, phantom: PhantomData<&'d mut T>, @@ -527,6 +533,7 @@ impl<'d, T: Instance> embassy_usb_driver::Driver<'d> for Driver<'d, T> { } } +/// USB bus. pub struct Bus<'d, T: Instance> { config: Config, phantom: PhantomData<&'d mut T>, @@ -1092,6 +1099,7 @@ trait Dir { fn dir() -> Direction; } +/// Marker type for the "IN" direction. pub enum In {} impl Dir for In { fn dir() -> Direction { @@ -1099,6 +1107,7 @@ impl Dir for In { } } +/// Marker type for the "OUT" direction. pub enum Out {} impl Dir for Out { fn dir() -> Direction { @@ -1106,6 +1115,7 @@ impl Dir for Out { } } +/// USB endpoint. pub struct Endpoint<'d, T: Instance, D> { _phantom: PhantomData<(&'d mut T, D)>, info: EndpointInfo, @@ -1299,6 +1309,7 @@ impl<'d, T: Instance> embassy_usb_driver::EndpointIn for Endpoint<'d, T, In> { } } +/// USB control pipe. pub struct ControlPipe<'d, T: Instance> { _phantom: PhantomData<&'d mut T>, max_packet_size: u16, diff --git a/embassy-stm32/src/wdg/mod.rs b/embassy-stm32/src/wdg/mod.rs index 5751a9ff3..dc701ef64 100644 --- a/embassy-stm32/src/wdg/mod.rs +++ b/embassy-stm32/src/wdg/mod.rs @@ -6,6 +6,7 @@ use stm32_metapac::iwdg::vals::{Key, Pr}; use crate::rcc::LSI_FREQ; +/// Independent watchdog (IWDG) driver. pub struct IndependentWatchdog<'d, T: Instance> { wdg: PhantomData<&'d mut T>, } @@ -64,10 +65,12 @@ impl<'d, T: Instance> IndependentWatchdog<'d, T> { IndependentWatchdog { wdg: PhantomData } } + /// Unleash (start) the watchdog. pub fn unleash(&mut self) { T::regs().kr().write(|w| w.set_key(Key::START)); } + /// Pet (reload, refresh) the watchdog. pub fn pet(&mut self) { T::regs().kr().write(|w| w.set_key(Key::RESET)); } @@ -79,6 +82,7 @@ mod sealed { } } +/// IWDG instance trait. pub trait Instance: sealed::Instance {} foreach_peripheral!( From 9d46ee0758dbc7a8625174370aff5fb8334f8170 Mon Sep 17 00:00:00 2001 From: Ulf Lilleengen Date: Tue, 19 Dec 2023 20:24:55 +0100 Subject: [PATCH 068/124] fix: update salty to released version --- embassy-boot/boot/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/embassy-boot/boot/Cargo.toml b/embassy-boot/boot/Cargo.toml index dd2ff8158..f0810f418 100644 --- a/embassy-boot/boot/Cargo.toml +++ b/embassy-boot/boot/Cargo.toml @@ -31,7 +31,7 @@ embassy-embedded-hal = { version = "0.1.0", path = "../../embassy-embedded-hal" embassy-sync = { version = "0.5.0", path = "../../embassy-sync" } embedded-storage = "0.3.1" embedded-storage-async = { version = "0.4.1" } -salty = { git = "https://github.com/ycrypto/salty.git", rev = "a9f17911a5024698406b75c0fac56ab5ccf6a8c7", optional = true } +salty = { version = "0.3", optional = true } signature = { version = "1.6.4", default-features = false } [dev-dependencies] From efd5dbe0196a71527777d949261cb7bbb7bee376 Mon Sep 17 00:00:00 2001 From: Ulf Lilleengen Date: Tue, 19 Dec 2023 20:25:20 +0100 Subject: [PATCH 069/124] fix: build warnings --- embassy-boot/boot/Cargo.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/embassy-boot/boot/Cargo.toml b/embassy-boot/boot/Cargo.toml index f0810f418..f63ea92cf 100644 --- a/embassy-boot/boot/Cargo.toml +++ b/embassy-boot/boot/Cargo.toml @@ -43,6 +43,7 @@ sha1 = "0.10.5" critical-section = { version = "1.1.1", features = ["std"] } [dev-dependencies.ed25519-dalek] +version = "1.0.1" default_features = false features = ["rand", "std", "u32_backend"] From 871ed538b1fb0836bdc12f5d59dbc7f5fea53920 Mon Sep 17 00:00:00 2001 From: dragonn Date: Tue, 19 Dec 2023 21:17:42 +0100 Subject: [PATCH 070/124] fix stm32 rtc year from 1970 base 2000 --- embassy-stm32/src/rtc/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/embassy-stm32/src/rtc/mod.rs b/embassy-stm32/src/rtc/mod.rs index 11b252139..40cd752a2 100644 --- a/embassy-stm32/src/rtc/mod.rs +++ b/embassy-stm32/src/rtc/mod.rs @@ -130,7 +130,7 @@ impl RtcTimeProvider { let weekday = day_of_week_from_u8(dr.wdu()).map_err(RtcError::InvalidDateTime)?; let day = bcd2_to_byte((dr.dt(), dr.du())); let month = bcd2_to_byte((dr.mt() as u8, dr.mu())); - let year = bcd2_to_byte((dr.yt(), dr.yu())) as u16 + 1970_u16; + let year = bcd2_to_byte((dr.yt(), dr.yu())) as u16 + 2000_u16; DateTime::from(year, month, day, weekday, hour, minute, second).map_err(RtcError::InvalidDateTime) }) @@ -261,7 +261,7 @@ impl Rtc { let (dt, du) = byte_to_bcd2(t.day() as u8); let (mt, mu) = byte_to_bcd2(t.month() as u8); let yr = t.year() as u16; - let yr_offset = (yr - 1970_u16) as u8; + let yr_offset = (yr - 2000_u16) as u8; let (yt, yu) = byte_to_bcd2(yr_offset); use crate::pac::rtc::vals::Ampm; From 12de90e13dd564e3f3f445f00ca2be622ad2c7fe Mon Sep 17 00:00:00 2001 From: Ulf Lilleengen Date: Tue, 19 Dec 2023 21:20:30 +0100 Subject: [PATCH 071/124] fix: update ed25519-dalek to new version --- embassy-boot/boot/Cargo.toml | 4 ++-- .../boot/src/digest_adapters/ed25519_dalek.rs | 4 ++-- .../boot/src/firmware_updater/asynch.rs | 17 +++++++---------- .../boot/src/firmware_updater/blocking.rs | 17 +++++++---------- 4 files changed, 18 insertions(+), 24 deletions(-) diff --git a/embassy-boot/boot/Cargo.toml b/embassy-boot/boot/Cargo.toml index f63ea92cf..e47776d62 100644 --- a/embassy-boot/boot/Cargo.toml +++ b/embassy-boot/boot/Cargo.toml @@ -26,13 +26,13 @@ features = ["defmt"] defmt = { version = "0.3", optional = true } digest = "0.10" log = { version = "0.4", optional = true } -ed25519-dalek = { version = "1.0.1", default_features = false, features = ["u32_backend"], optional = true } +ed25519-dalek = { version = "2", default_features = false, features = ["digest"], optional = true } embassy-embedded-hal = { version = "0.1.0", path = "../../embassy-embedded-hal" } embassy-sync = { version = "0.5.0", path = "../../embassy-sync" } embedded-storage = "0.3.1" embedded-storage-async = { version = "0.4.1" } salty = { version = "0.3", optional = true } -signature = { version = "1.6.4", default-features = false } +signature = { version = "2.2", default-features = false } [dev-dependencies] log = "0.4" diff --git a/embassy-boot/boot/src/digest_adapters/ed25519_dalek.rs b/embassy-boot/boot/src/digest_adapters/ed25519_dalek.rs index a184d1c51..2e4e03da3 100644 --- a/embassy-boot/boot/src/digest_adapters/ed25519_dalek.rs +++ b/embassy-boot/boot/src/digest_adapters/ed25519_dalek.rs @@ -1,6 +1,6 @@ use digest::typenum::U64; use digest::{FixedOutput, HashMarker, OutputSizeUser, Update}; -use ed25519_dalek::Digest as _; +use ed25519_dalek::Digest; pub struct Sha512(ed25519_dalek::Sha512); @@ -12,7 +12,7 @@ impl Default for Sha512 { impl Update for Sha512 { fn update(&mut self, data: &[u8]) { - self.0.update(data) + Digest::update(&mut self.0, data) } } diff --git a/embassy-boot/boot/src/firmware_updater/asynch.rs b/embassy-boot/boot/src/firmware_updater/asynch.rs index d8d85c3d2..4af5a087d 100644 --- a/embassy-boot/boot/src/firmware_updater/asynch.rs +++ b/embassy-boot/boot/src/firmware_updater/asynch.rs @@ -79,8 +79,8 @@ impl<'d, DFU: NorFlash, STATE: NorFlash> FirmwareUpdater<'d, DFU, STATE> { #[cfg(feature = "_verify")] pub async fn verify_and_mark_updated( &mut self, - _public_key: &[u8], - _signature: &[u8], + _public_key: &[u8; 32], + _signature: &[u8; 64], _update_len: u32, ) -> Result<(), FirmwareUpdaterError> { assert!(_update_len <= self.dfu.capacity() as u32); @@ -89,14 +89,14 @@ impl<'d, DFU: NorFlash, STATE: NorFlash> FirmwareUpdater<'d, DFU, STATE> { #[cfg(feature = "ed25519-dalek")] { - use ed25519_dalek::{PublicKey, Signature, SignatureError, Verifier}; + use ed25519_dalek::{VerifyingKey, Signature, SignatureError, Verifier}; use crate::digest_adapters::ed25519_dalek::Sha512; let into_signature_error = |e: SignatureError| FirmwareUpdaterError::Signature(e.into()); - let public_key = PublicKey::from_bytes(_public_key).map_err(into_signature_error)?; - let signature = Signature::from_bytes(_signature).map_err(into_signature_error)?; + let public_key = VerifyingKey::from_bytes(_public_key).map_err(into_signature_error)?; + let signature = Signature::from_bytes(_signature); let mut chunk_buf = [0; 2]; let mut message = [0; 64]; @@ -106,7 +106,6 @@ impl<'d, DFU: NorFlash, STATE: NorFlash> FirmwareUpdater<'d, DFU, STATE> { } #[cfg(feature = "ed25519-salty")] { - use salty::constants::{PUBLICKEY_SERIALIZED_LENGTH, SIGNATURE_SERIALIZED_LENGTH}; use salty::{PublicKey, Signature}; use crate::digest_adapters::salty::Sha512; @@ -115,10 +114,8 @@ impl<'d, DFU: NorFlash, STATE: NorFlash> FirmwareUpdater<'d, DFU, STATE> { FirmwareUpdaterError::Signature(signature::Error::default()) } - let public_key: [u8; PUBLICKEY_SERIALIZED_LENGTH] = _public_key.try_into().map_err(into_signature_error)?; - let public_key = PublicKey::try_from(&public_key).map_err(into_signature_error)?; - let signature: [u8; SIGNATURE_SERIALIZED_LENGTH] = _signature.try_into().map_err(into_signature_error)?; - let signature = Signature::try_from(&signature).map_err(into_signature_error)?; + let public_key = PublicKey::try_from(_public_key).map_err(into_signature_error)?; + let signature = Signature::try_from(_signature).map_err(into_signature_error)?; let mut message = [0; 64]; let mut chunk_buf = [0; 2]; diff --git a/embassy-boot/boot/src/firmware_updater/blocking.rs b/embassy-boot/boot/src/firmware_updater/blocking.rs index c4c142169..f1368540d 100644 --- a/embassy-boot/boot/src/firmware_updater/blocking.rs +++ b/embassy-boot/boot/src/firmware_updater/blocking.rs @@ -86,8 +86,8 @@ impl<'d, DFU: NorFlash, STATE: NorFlash> BlockingFirmwareUpdater<'d, DFU, STATE> #[cfg(feature = "_verify")] pub fn verify_and_mark_updated( &mut self, - _public_key: &[u8], - _signature: &[u8], + _public_key: &[u8; 32], + _signature: &[u8; 64], _update_len: u32, ) -> Result<(), FirmwareUpdaterError> { assert!(_update_len <= self.dfu.capacity() as u32); @@ -96,14 +96,14 @@ impl<'d, DFU: NorFlash, STATE: NorFlash> BlockingFirmwareUpdater<'d, DFU, STATE> #[cfg(feature = "ed25519-dalek")] { - use ed25519_dalek::{PublicKey, Signature, SignatureError, Verifier}; + use ed25519_dalek::{Signature, SignatureError, Verifier, VerifyingKey}; use crate::digest_adapters::ed25519_dalek::Sha512; let into_signature_error = |e: SignatureError| FirmwareUpdaterError::Signature(e.into()); - let public_key = PublicKey::from_bytes(_public_key).map_err(into_signature_error)?; - let signature = Signature::from_bytes(_signature).map_err(into_signature_error)?; + let public_key = VerifyingKey::from_bytes(_public_key).map_err(into_signature_error)?; + let signature = Signature::from_bytes(_signature); let mut message = [0; 64]; let mut chunk_buf = [0; 2]; @@ -113,7 +113,6 @@ impl<'d, DFU: NorFlash, STATE: NorFlash> BlockingFirmwareUpdater<'d, DFU, STATE> } #[cfg(feature = "ed25519-salty")] { - use salty::constants::{PUBLICKEY_SERIALIZED_LENGTH, SIGNATURE_SERIALIZED_LENGTH}; use salty::{PublicKey, Signature}; use crate::digest_adapters::salty::Sha512; @@ -122,10 +121,8 @@ impl<'d, DFU: NorFlash, STATE: NorFlash> BlockingFirmwareUpdater<'d, DFU, STATE> FirmwareUpdaterError::Signature(signature::Error::default()) } - let public_key: [u8; PUBLICKEY_SERIALIZED_LENGTH] = _public_key.try_into().map_err(into_signature_error)?; - let public_key = PublicKey::try_from(&public_key).map_err(into_signature_error)?; - let signature: [u8; SIGNATURE_SERIALIZED_LENGTH] = _signature.try_into().map_err(into_signature_error)?; - let signature = Signature::try_from(&signature).map_err(into_signature_error)?; + let public_key = PublicKey::try_from(_public_key).map_err(into_signature_error)?; + let signature = Signature::try_from(_signature).map_err(into_signature_error)?; let mut message = [0; 64]; let mut chunk_buf = [0; 2]; From 4567b874826e30f54dbd0e5d12b6f0243e284be3 Mon Sep 17 00:00:00 2001 From: Ulf Lilleengen Date: Tue, 19 Dec 2023 21:21:52 +0100 Subject: [PATCH 072/124] cargo fmt --- embassy-boot/boot/src/firmware_updater/asynch.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/embassy-boot/boot/src/firmware_updater/asynch.rs b/embassy-boot/boot/src/firmware_updater/asynch.rs index 4af5a087d..64a4b32ec 100644 --- a/embassy-boot/boot/src/firmware_updater/asynch.rs +++ b/embassy-boot/boot/src/firmware_updater/asynch.rs @@ -89,7 +89,7 @@ impl<'d, DFU: NorFlash, STATE: NorFlash> FirmwareUpdater<'d, DFU, STATE> { #[cfg(feature = "ed25519-dalek")] { - use ed25519_dalek::{VerifyingKey, Signature, SignatureError, Verifier}; + use ed25519_dalek::{Signature, SignatureError, Verifier, VerifyingKey}; use crate::digest_adapters::ed25519_dalek::Sha512; From c7841a37fab60a9f017c4aa7ea3f0c9b0c2aba0d Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Tue, 19 Dec 2023 22:26:50 +0100 Subject: [PATCH 073/124] boot: update ed25519-dalek in dev-dependencies. --- embassy-boot/boot/Cargo.toml | 10 +++------- embassy-boot/boot/src/lib.rs | 8 +++----- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/embassy-boot/boot/Cargo.toml b/embassy-boot/boot/Cargo.toml index e47776d62..3c84ffcd3 100644 --- a/embassy-boot/boot/Cargo.toml +++ b/embassy-boot/boot/Cargo.toml @@ -32,20 +32,16 @@ embassy-sync = { version = "0.5.0", path = "../../embassy-sync" } embedded-storage = "0.3.1" embedded-storage-async = { version = "0.4.1" } salty = { version = "0.3", optional = true } -signature = { version = "2.2", default-features = false } +signature = { version = "2.0", default-features = false } [dev-dependencies] log = "0.4" env_logger = "0.9" -rand = "0.7" # ed25519-dalek v1.0.1 depends on this exact version +rand = "0.8" futures = { version = "0.3", features = ["executor"] } sha1 = "0.10.5" critical-section = { version = "1.1.1", features = ["std"] } - -[dev-dependencies.ed25519-dalek] -version = "1.0.1" -default_features = false -features = ["rand", "std", "u32_backend"] +ed25519-dalek = { version = "2", default_features = false, features = ["std", "rand_core", "digest"] } [features] ed25519-dalek = ["dep:ed25519-dalek", "_verify"] diff --git a/embassy-boot/boot/src/lib.rs b/embassy-boot/boot/src/lib.rs index 15b69f69d..b4f03e01e 100644 --- a/embassy-boot/boot/src/lib.rs +++ b/embassy-boot/boot/src/lib.rs @@ -275,21 +275,19 @@ mod tests { // The following key setup is based on: // https://docs.rs/ed25519-dalek/latest/ed25519_dalek/#example - use ed25519_dalek::Keypair; + use ed25519_dalek::{Digest, Sha512, Signature, Signer, SigningKey, VerifyingKey}; use rand::rngs::OsRng; let mut csprng = OsRng {}; - let keypair: Keypair = Keypair::generate(&mut csprng); + let keypair = SigningKey::generate(&mut csprng); - use ed25519_dalek::{Digest, Sha512, Signature, Signer}; let firmware: &[u8] = b"This are bytes that would otherwise be firmware bytes for DFU."; let mut digest = Sha512::new(); digest.update(&firmware); let message = digest.finalize(); let signature: Signature = keypair.sign(&message); - use ed25519_dalek::PublicKey; - let public_key: PublicKey = keypair.public; + let public_key = keypair.verifying_key(); // Setup flash let flash = BlockingTestFlash::new(BootLoaderConfig { From f9d0daad80827dd1b379ca727a2e27870a497122 Mon Sep 17 00:00:00 2001 From: Rasmus Melchior Jacobsen Date: Wed, 20 Dec 2023 08:37:15 +0100 Subject: [PATCH 074/124] feat(embassy-sync): Add try_take() to signal --- embassy-sync/src/signal.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/embassy-sync/src/signal.rs b/embassy-sync/src/signal.rs index bea67d8be..97d76b463 100644 --- a/embassy-sync/src/signal.rs +++ b/embassy-sync/src/signal.rs @@ -111,6 +111,17 @@ where poll_fn(move |cx| self.poll_wait(cx)) } + /// non-blocking method to try and take the signal value. + pub fn try_take(&self) -> Option { + self.state.lock(|cell| { + let state = cell.replace(State::None); + match state { + State::Signaled(res) => Some(res), + _ => None, + } + }) + } + /// non-blocking method to check whether this signal has been signaled. pub fn signaled(&self) -> bool { self.state.lock(|cell| { From fc6e70caa5afb2e6b37e45516fad9a233e32d108 Mon Sep 17 00:00:00 2001 From: Ulf Lilleengen Date: Wed, 20 Dec 2023 09:24:10 +0100 Subject: [PATCH 075/124] docs: document public apis of embassy-net-driver-channel --- embassy-net-driver-channel/src/lib.rs | 58 ++++++++++++++++++++++++++- 1 file changed, 57 insertions(+), 1 deletion(-) diff --git a/embassy-net-driver-channel/src/lib.rs b/embassy-net-driver-channel/src/lib.rs index bfb2c9c03..7ad4d449e 100644 --- a/embassy-net-driver-channel/src/lib.rs +++ b/embassy-net-driver-channel/src/lib.rs @@ -1,5 +1,6 @@ #![no_std] #![doc = include_str!("../README.md")] +#![warn(missing_docs)] // must go first! mod fmt; @@ -15,6 +16,9 @@ use embassy_sync::blocking_mutex::Mutex; use embassy_sync::waitqueue::WakerRegistration; use embassy_sync::zerocopy_channel; +/// Channel state. +/// +/// Holds a buffer of packets with size MTU, for both TX and RX. pub struct State { rx: [PacketBuf; N_RX], tx: [PacketBuf; N_TX], @@ -24,6 +28,7 @@ pub struct State { impl State { const NEW_PACKET: PacketBuf = PacketBuf::new(); + /// Create a new channel state. pub const fn new() -> Self { Self { rx: [Self::NEW_PACKET; N_RX], @@ -39,33 +44,45 @@ struct StateInner<'d, const MTU: usize> { shared: Mutex>, } -/// State of the LinkState struct Shared { link_state: LinkState, waker: WakerRegistration, hardware_address: driver::HardwareAddress, } +/// Channel runner. +/// +/// Holds the shared state and the lower end of channels for inbound and outbound packets. pub struct Runner<'d, const MTU: usize> { tx_chan: zerocopy_channel::Receiver<'d, NoopRawMutex, PacketBuf>, rx_chan: zerocopy_channel::Sender<'d, NoopRawMutex, PacketBuf>, shared: &'d Mutex>, } +/// State runner. +/// +/// Holds the shared state of the channel such as link state. #[derive(Clone, Copy)] pub struct StateRunner<'d> { shared: &'d Mutex>, } +/// RX runner. +/// +/// Holds the lower end of the channel for passing inbound packets up the stack. pub struct RxRunner<'d, const MTU: usize> { rx_chan: zerocopy_channel::Sender<'d, NoopRawMutex, PacketBuf>, } +/// TX runner. +/// +/// Holds the lower end of the channel for passing outbound packets down the stack. pub struct TxRunner<'d, const MTU: usize> { tx_chan: zerocopy_channel::Receiver<'d, NoopRawMutex, PacketBuf>, } impl<'d, const MTU: usize> Runner<'d, MTU> { + /// Split the runner into separate runners for controlling state, rx and tx. pub fn split(self) -> (StateRunner<'d>, RxRunner<'d, MTU>, TxRunner<'d, MTU>) { ( StateRunner { shared: self.shared }, @@ -74,6 +91,7 @@ impl<'d, const MTU: usize> Runner<'d, MTU> { ) } + /// Split the runner into separate runners for controlling state, rx and tx borrowing the underlying state. pub fn borrow_split(&mut self) -> (StateRunner<'_>, RxRunner<'_, MTU>, TxRunner<'_, MTU>) { ( StateRunner { shared: self.shared }, @@ -86,10 +104,12 @@ impl<'d, const MTU: usize> Runner<'d, MTU> { ) } + /// Create a state runner sharing the state channel. pub fn state_runner(&self) -> StateRunner<'d> { StateRunner { shared: self.shared } } + /// Set the link state. pub fn set_link_state(&mut self, state: LinkState) { self.shared.lock(|s| { let s = &mut *s.borrow_mut(); @@ -98,6 +118,7 @@ impl<'d, const MTU: usize> Runner<'d, MTU> { }); } + /// Set the hardware address. pub fn set_hardware_address(&mut self, address: driver::HardwareAddress) { self.shared.lock(|s| { let s = &mut *s.borrow_mut(); @@ -106,16 +127,19 @@ impl<'d, const MTU: usize> Runner<'d, MTU> { }); } + /// Wait until there is space for more inbound packets and return a slice they can be copied into. pub async fn rx_buf(&mut self) -> &mut [u8] { let p = self.rx_chan.send().await; &mut p.buf } + /// Check if there is space for more inbound packets right now. pub fn try_rx_buf(&mut self) -> Option<&mut [u8]> { let p = self.rx_chan.try_send()?; Some(&mut p.buf) } + /// Polling the inbound channel if there is space for packets. pub fn poll_rx_buf(&mut self, cx: &mut Context) -> Poll<&mut [u8]> { match self.rx_chan.poll_send(cx) { Poll::Ready(p) => Poll::Ready(&mut p.buf), @@ -123,22 +147,26 @@ impl<'d, const MTU: usize> Runner<'d, MTU> { } } + /// Mark packet of len bytes as pushed to the inbound channel. pub fn rx_done(&mut self, len: usize) { let p = self.rx_chan.try_send().unwrap(); p.len = len; self.rx_chan.send_done(); } + /// Wait until there is space for more outbound packets and return a slice they can be copied into. pub async fn tx_buf(&mut self) -> &mut [u8] { let p = self.tx_chan.receive().await; &mut p.buf[..p.len] } + /// Check if there is space for more outbound packets right now. pub fn try_tx_buf(&mut self) -> Option<&mut [u8]> { let p = self.tx_chan.try_receive()?; Some(&mut p.buf[..p.len]) } + /// Polling the outbound channel if there is space for packets. pub fn poll_tx_buf(&mut self, cx: &mut Context) -> Poll<&mut [u8]> { match self.tx_chan.poll_receive(cx) { Poll::Ready(p) => Poll::Ready(&mut p.buf[..p.len]), @@ -146,12 +174,14 @@ impl<'d, const MTU: usize> Runner<'d, MTU> { } } + /// Mark outbound packet as copied. pub fn tx_done(&mut self) { self.tx_chan.receive_done(); } } impl<'d> StateRunner<'d> { + /// Set link state. pub fn set_link_state(&self, state: LinkState) { self.shared.lock(|s| { let s = &mut *s.borrow_mut(); @@ -160,6 +190,7 @@ impl<'d> StateRunner<'d> { }); } + /// Set the hardware address. pub fn set_hardware_address(&self, address: driver::HardwareAddress) { self.shared.lock(|s| { let s = &mut *s.borrow_mut(); @@ -170,16 +201,19 @@ impl<'d> StateRunner<'d> { } impl<'d, const MTU: usize> RxRunner<'d, MTU> { + /// Wait until there is space for more inbound packets and return a slice they can be copied into. pub async fn rx_buf(&mut self) -> &mut [u8] { let p = self.rx_chan.send().await; &mut p.buf } + /// Check if there is space for more inbound packets right now. pub fn try_rx_buf(&mut self) -> Option<&mut [u8]> { let p = self.rx_chan.try_send()?; Some(&mut p.buf) } + /// Polling the inbound channel if there is space for packets. pub fn poll_rx_buf(&mut self, cx: &mut Context) -> Poll<&mut [u8]> { match self.rx_chan.poll_send(cx) { Poll::Ready(p) => Poll::Ready(&mut p.buf), @@ -187,6 +221,7 @@ impl<'d, const MTU: usize> RxRunner<'d, MTU> { } } + /// Mark packet of len bytes as pushed to the inbound channel. pub fn rx_done(&mut self, len: usize) { let p = self.rx_chan.try_send().unwrap(); p.len = len; @@ -195,16 +230,19 @@ impl<'d, const MTU: usize> RxRunner<'d, MTU> { } impl<'d, const MTU: usize> TxRunner<'d, MTU> { + /// Wait until there is space for more outbound packets and return a slice they can be copied into. pub async fn tx_buf(&mut self) -> &mut [u8] { let p = self.tx_chan.receive().await; &mut p.buf[..p.len] } + /// Check if there is space for more outbound packets right now. pub fn try_tx_buf(&mut self) -> Option<&mut [u8]> { let p = self.tx_chan.try_receive()?; Some(&mut p.buf[..p.len]) } + /// Polling the outbound channel if there is space for packets. pub fn poll_tx_buf(&mut self, cx: &mut Context) -> Poll<&mut [u8]> { match self.tx_chan.poll_receive(cx) { Poll::Ready(p) => Poll::Ready(&mut p.buf[..p.len]), @@ -212,11 +250,18 @@ impl<'d, const MTU: usize> TxRunner<'d, MTU> { } } + /// Mark outbound packet as copied. pub fn tx_done(&mut self) { self.tx_chan.receive_done(); } } +/// Create a channel. +/// +/// Returns a pair of handles for interfacing with the peripheral and the networking stack. +/// +/// The runner is interfacing with the peripheral at the lower part of the stack. +/// The device is interfacing with the networking stack on the layer above. pub fn new<'d, const MTU: usize, const N_RX: usize, const N_TX: usize>( state: &'d mut State, hardware_address: driver::HardwareAddress, @@ -257,17 +302,22 @@ pub fn new<'d, const MTU: usize, const N_RX: usize, const N_TX: usize>( ) } +/// Represents a packet of size MTU. pub struct PacketBuf { len: usize, buf: [u8; MTU], } impl PacketBuf { + /// Create a new packet buffer. pub const fn new() -> Self { Self { len: 0, buf: [0; MTU] } } } +/// Channel device. +/// +/// Holds the shared state and upper end of channels for inbound and outbound packets. pub struct Device<'d, const MTU: usize> { rx: zerocopy_channel::Receiver<'d, NoopRawMutex, PacketBuf>, tx: zerocopy_channel::Sender<'d, NoopRawMutex, PacketBuf>, @@ -314,6 +364,9 @@ impl<'d, const MTU: usize> embassy_net_driver::Driver for Device<'d, MTU> { } } +/// A rx token. +/// +/// Holds inbound receive channel and interfaces with embassy-net-driver. pub struct RxToken<'a, const MTU: usize> { rx: zerocopy_channel::Receiver<'a, NoopRawMutex, PacketBuf>, } @@ -331,6 +384,9 @@ impl<'a, const MTU: usize> embassy_net_driver::RxToken for RxToken<'a, MTU> { } } +/// A tx token. +/// +/// Holds outbound transmit channel and interfaces with embassy-net-driver. pub struct TxToken<'a, const MTU: usize> { tx: zerocopy_channel::Sender<'a, NoopRawMutex, PacketBuf>, } From abea4dde3d30388f8338985e323203d8792dabeb Mon Sep 17 00:00:00 2001 From: Ulf Lilleengen Date: Wed, 20 Dec 2023 10:09:05 +0100 Subject: [PATCH 076/124] docs: document most of esp-hosted driver --- embassy-net-esp-hosted/src/control.rs | 17 +++++++++++++++++ embassy-net-esp-hosted/src/lib.rs | 9 +++++++++ embassy-net-esp-hosted/src/proto.rs | 2 ++ 3 files changed, 28 insertions(+) diff --git a/embassy-net-esp-hosted/src/control.rs b/embassy-net-esp-hosted/src/control.rs index c86891bc3..b141bd6d2 100644 --- a/embassy-net-esp-hosted/src/control.rs +++ b/embassy-net-esp-hosted/src/control.rs @@ -5,6 +5,7 @@ use heapless::String; use crate::ioctl::Shared; use crate::proto::{self, CtrlMsg}; +/// Errors reported by control. #[derive(Copy, Clone, PartialEq, Eq, Debug)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] pub enum Error { @@ -13,30 +14,42 @@ pub enum Error { Internal, } +/// Handle for managing the network and WiFI state. pub struct Control<'a> { state_ch: ch::StateRunner<'a>, shared: &'a Shared, } +/// WiFi mode. #[allow(unused)] #[derive(Copy, Clone, PartialEq, Eq, Debug)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] enum WifiMode { + /// No mode. None = 0, + /// Client station. Sta = 1, + /// Access point mode. Ap = 2, + /// Repeater mode. ApSta = 3, } pub use proto::CtrlWifiSecProt as Security; +/// WiFi status. #[derive(Clone, Debug)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] pub struct Status { + /// Service Set Identifier. pub ssid: String<32>, + /// Basic Service Set Identifier. pub bssid: [u8; 6], + /// Received Signal Strength Indicator. pub rssi: i32, + /// WiFi channel. pub channel: u32, + /// Security mode. pub security: Security, } @@ -65,6 +78,7 @@ impl<'a> Control<'a> { Self { state_ch, shared } } + /// Initialize device. pub async fn init(&mut self) -> Result<(), Error> { debug!("wait for init event..."); self.shared.init_wait().await; @@ -82,6 +96,7 @@ impl<'a> Control<'a> { Ok(()) } + /// Get the current status. pub async fn get_status(&mut self) -> Result { let req = proto::CtrlMsgReqGetApConfig {}; ioctl!(self, ReqGetApConfig, RespGetApConfig, req, resp); @@ -95,6 +110,7 @@ impl<'a> Control<'a> { }) } + /// Connect to the network identified by ssid using the provided password. pub async fn connect(&mut self, ssid: &str, password: &str) -> Result<(), Error> { let req = proto::CtrlMsgReqConnectAp { ssid: unwrap!(String::try_from(ssid)), @@ -108,6 +124,7 @@ impl<'a> Control<'a> { Ok(()) } + /// Disconnect from any currently connected network. pub async fn disconnect(&mut self) -> Result<(), Error> { let req = proto::CtrlMsgReqGetStatus {}; ioctl!(self, ReqDisconnectAp, RespDisconnectAp, req, resp); diff --git a/embassy-net-esp-hosted/src/lib.rs b/embassy-net-esp-hosted/src/lib.rs index d61eaef3a..ce7f39dc1 100644 --- a/embassy-net-esp-hosted/src/lib.rs +++ b/embassy-net-esp-hosted/src/lib.rs @@ -97,12 +97,14 @@ enum InterfaceType { const MAX_SPI_BUFFER_SIZE: usize = 1600; const HEARTBEAT_MAX_GAP: Duration = Duration::from_secs(20); +/// Shared driver state. pub struct State { shared: Shared, ch: ch::State, } impl State { + /// Shared state for the pub fn new() -> Self { Self { shared: Shared::new(), @@ -111,8 +113,13 @@ impl State { } } +/// Type alias for network driver. pub type NetDriver<'a> = ch::Device<'a, MTU>; +/// Create a new esp-hosted driver using the provided state, SPI peripheral and pins. +/// +/// Returns a device handle for interfacing with embassy-net, a control handle for +/// interacting with the driver, and a runner for communicating with the WiFi device. pub async fn new<'a, SPI, IN, OUT>( state: &'a mut State, spi: SPI, @@ -144,6 +151,7 @@ where (device, Control::new(state_ch, &state.shared), runner) } +/// Runner for communicating with the WiFi device. pub struct Runner<'a, SPI, IN, OUT> { ch: ch::Runner<'a, MTU>, state_ch: ch::StateRunner<'a>, @@ -166,6 +174,7 @@ where { async fn init(&mut self) {} + /// Run the packet processing. pub async fn run(mut self) -> ! { debug!("resetting..."); self.reset.set_low().unwrap(); diff --git a/embassy-net-esp-hosted/src/proto.rs b/embassy-net-esp-hosted/src/proto.rs index 8ceb1579d..b42ff62f1 100644 --- a/embassy-net-esp-hosted/src/proto.rs +++ b/embassy-net-esp-hosted/src/proto.rs @@ -1,3 +1,5 @@ +#![allow(missing_docs)] + use heapless::{String, Vec}; /// internal supporting structures for CtrlMsg From 89cfdcb9f554c835d1228c1b9a191786d065df6a Mon Sep 17 00:00:00 2001 From: Ulf Lilleengen Date: Wed, 20 Dec 2023 12:06:49 +0100 Subject: [PATCH 077/124] fix suddenly ending comment --- embassy-net-esp-hosted/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/embassy-net-esp-hosted/src/lib.rs b/embassy-net-esp-hosted/src/lib.rs index ce7f39dc1..a5e9ddb4f 100644 --- a/embassy-net-esp-hosted/src/lib.rs +++ b/embassy-net-esp-hosted/src/lib.rs @@ -97,14 +97,14 @@ enum InterfaceType { const MAX_SPI_BUFFER_SIZE: usize = 1600; const HEARTBEAT_MAX_GAP: Duration = Duration::from_secs(20); -/// Shared driver state. +/// State for the esp-hosted driver. pub struct State { shared: Shared, ch: ch::State, } impl State { - /// Shared state for the + /// Create a new state. pub fn new() -> Self { Self { shared: Shared::new(), From afb01e3fc51d44a637e99db3a16d0243a5921f6b Mon Sep 17 00:00:00 2001 From: Ulf Lilleengen Date: Wed, 20 Dec 2023 12:05:17 +0100 Subject: [PATCH 078/124] docs: document embassy-net-tuntap --- embassy-net-tuntap/src/lib.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/embassy-net-tuntap/src/lib.rs b/embassy-net-tuntap/src/lib.rs index 75c54c487..de30934eb 100644 --- a/embassy-net-tuntap/src/lib.rs +++ b/embassy-net-tuntap/src/lib.rs @@ -1,3 +1,5 @@ +#![warn(missing_docs)] +#![doc = include_str!("../README.md")] use std::io; use std::io::{Read, Write}; use std::os::unix::io::{AsRawFd, RawFd}; @@ -7,12 +9,19 @@ use async_io::Async; use embassy_net_driver::{self, Capabilities, Driver, HardwareAddress, LinkState}; use log::*; +/// Get the MTU of the given interface. pub const SIOCGIFMTU: libc::c_ulong = 0x8921; +/// Get the index of the given interface. pub const _SIOCGIFINDEX: libc::c_ulong = 0x8933; +/// Capture all packages. pub const _ETH_P_ALL: libc::c_short = 0x0003; +/// Set the interface flags. pub const TUNSETIFF: libc::c_ulong = 0x400454CA; +/// TUN device. pub const _IFF_TUN: libc::c_int = 0x0001; +/// TAP device. pub const IFF_TAP: libc::c_int = 0x0002; +/// No packet information. pub const IFF_NO_PI: libc::c_int = 0x1000; const ETHERNET_HEADER_LEN: usize = 14; @@ -47,6 +56,7 @@ fn ifreq_ioctl(lower: libc::c_int, ifreq: &mut ifreq, cmd: libc::c_ulong) -> io: Ok(ifreq.ifr_data) } +/// A TUN/TAP device. #[derive(Debug)] pub struct TunTap { fd: libc::c_int, @@ -60,6 +70,7 @@ impl AsRawFd for TunTap { } impl TunTap { + /// Create a new TUN/TAP device. pub fn new(name: &str) -> io::Result { unsafe { let fd = libc::open( @@ -126,11 +137,13 @@ impl io::Write for TunTap { } } +/// A TUN/TAP device, wrapped in an async interface. pub struct TunTapDevice { device: Async, } impl TunTapDevice { + /// Create a new TUN/TAP device. pub fn new(name: &str) -> io::Result { Ok(Self { device: Async::new(TunTap::new(name)?)?, From 4a2dd7b944a4b81afdba6a4b1648f2c938d51096 Mon Sep 17 00:00:00 2001 From: Ulf Lilleengen Date: Wed, 20 Dec 2023 12:14:25 +0100 Subject: [PATCH 079/124] docs: document public apis of wiznet driver --- embassy-net-wiznet/Cargo.toml | 1 + embassy-net-wiznet/src/chip/mod.rs | 2 ++ embassy-net-wiznet/src/chip/w5100s.rs | 1 + embassy-net-wiznet/src/chip/w5500.rs | 1 + embassy-net-wiznet/src/lib.rs | 2 ++ 5 files changed, 7 insertions(+) diff --git a/embassy-net-wiznet/Cargo.toml b/embassy-net-wiznet/Cargo.toml index a1f0b0c51..f628d8bd1 100644 --- a/embassy-net-wiznet/Cargo.toml +++ b/embassy-net-wiznet/Cargo.toml @@ -6,6 +6,7 @@ keywords = ["embedded", "wiznet", "embassy-net", "embedded-hal-async", "ethernet categories = ["embedded", "hardware-support", "no-std", "network-programming", "async"] license = "MIT OR Apache-2.0" edition = "2021" +repository = "https://github.com/embassy-rs/embassy" [dependencies] embedded-hal = { version = "1.0.0-rc.3" } diff --git a/embassy-net-wiznet/src/chip/mod.rs b/embassy-net-wiznet/src/chip/mod.rs index 562db515a..b987c2b36 100644 --- a/embassy-net-wiznet/src/chip/mod.rs +++ b/embassy-net-wiznet/src/chip/mod.rs @@ -1,3 +1,4 @@ +//! Wiznet W5100s and W5500 family driver. mod w5500; pub use w5500::W5500; mod w5100s; @@ -45,4 +46,5 @@ pub(crate) mod sealed { } } +/// Trait for Wiznet chips. pub trait Chip: sealed::Chip {} diff --git a/embassy-net-wiznet/src/chip/w5100s.rs b/embassy-net-wiznet/src/chip/w5100s.rs index 07a840370..7d328bce5 100644 --- a/embassy-net-wiznet/src/chip/w5100s.rs +++ b/embassy-net-wiznet/src/chip/w5100s.rs @@ -4,6 +4,7 @@ const SOCKET_BASE: u16 = 0x400; const TX_BASE: u16 = 0x4000; const RX_BASE: u16 = 0x6000; +/// Wizard W5100S chip. pub enum W5100S {} impl super::Chip for W5100S {} diff --git a/embassy-net-wiznet/src/chip/w5500.rs b/embassy-net-wiznet/src/chip/w5500.rs index 61e512946..16236126d 100644 --- a/embassy-net-wiznet/src/chip/w5500.rs +++ b/embassy-net-wiznet/src/chip/w5500.rs @@ -8,6 +8,7 @@ pub enum RegisterBlock { RxBuf = 0x03, } +/// Wiznet W5500 chip. pub enum W5500 {} impl super::Chip for W5500 {} diff --git a/embassy-net-wiznet/src/lib.rs b/embassy-net-wiznet/src/lib.rs index f26f2bbb7..da70d22bd 100644 --- a/embassy-net-wiznet/src/lib.rs +++ b/embassy-net-wiznet/src/lib.rs @@ -1,6 +1,7 @@ #![no_std] #![allow(async_fn_in_trait)] #![doc = include_str!("../README.md")] +#![warn(missing_docs)] pub mod chip; mod device; @@ -47,6 +48,7 @@ pub struct Runner<'d, C: Chip, SPI: SpiDevice, INT: Wait, RST: OutputPin> { /// You must call this in a background task for the driver to operate. impl<'d, C: Chip, SPI: SpiDevice, INT: Wait, RST: OutputPin> Runner<'d, C, SPI, INT, RST> { + /// Run the driver. pub async fn run(mut self) -> ! { let (state_chan, mut rx_chan, mut tx_chan) = self.ch.split(); let mut tick = Ticker::every(Duration::from_millis(500)); From 73f8cd7ade632a9905252698d09f71bd7ac3714c Mon Sep 17 00:00:00 2001 From: Ulf Lilleengen Date: Wed, 20 Dec 2023 12:16:01 +0100 Subject: [PATCH 080/124] fix: add repository to manifest --- embassy-net-tuntap/Cargo.toml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/embassy-net-tuntap/Cargo.toml b/embassy-net-tuntap/Cargo.toml index 4e374c365..7e2c7bfd5 100644 --- a/embassy-net-tuntap/Cargo.toml +++ b/embassy-net-tuntap/Cargo.toml @@ -6,6 +6,7 @@ keywords = ["embedded", "tuntap", "embassy-net", "embedded-hal-async", "ethernet categories = ["embedded", "hardware-support", "no-std", "network-programming", "async"] license = "MIT OR Apache-2.0" edition = "2021" +repository = "https://github.com/embassy-rs/embassy" [dependencies] embassy-net-driver = { version = "0.2.0", path = "../embassy-net-driver" } @@ -16,4 +17,4 @@ libc = "0.2.101" [package.metadata.embassy_docs] src_base = "https://github.com/embassy-rs/embassy/blob/embassy-net-tuntap-v$VERSION/embassy-net-tuntap/src/" src_base_git = "https://github.com/embassy-rs/embassy/blob/$COMMIT/embassy-net-tuntap/src/" -target = "thumbv7em-none-eabi" \ No newline at end of file +target = "thumbv7em-none-eabi" From 4dfae9328e75ea5e7797b32b9c3a42f1babf6e35 Mon Sep 17 00:00:00 2001 From: Ulf Lilleengen Date: Wed, 20 Dec 2023 12:18:02 +0100 Subject: [PATCH 081/124] add missing guards --- embassy-net-esp-hosted/src/lib.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/embassy-net-esp-hosted/src/lib.rs b/embassy-net-esp-hosted/src/lib.rs index a5e9ddb4f..c78578bf1 100644 --- a/embassy-net-esp-hosted/src/lib.rs +++ b/embassy-net-esp-hosted/src/lib.rs @@ -1,4 +1,6 @@ #![no_std] +#![doc = include_str!("../README.md")] +#![warn(missing_docs)] use embassy_futures::select::{select4, Either4}; use embassy_net_driver_channel as ch; From c3b827d8cd66ed64e22987ca27cf16e371755227 Mon Sep 17 00:00:00 2001 From: Ulf Lilleengen Date: Wed, 20 Dec 2023 12:24:51 +0100 Subject: [PATCH 082/124] fix: add readme and fix remaining warnings --- embassy-net-esp-hosted/Cargo.toml | 4 ++++ embassy-net-esp-hosted/README.md | 27 +++++++++++++++++++++++++++ embassy-net-esp-hosted/src/control.rs | 3 +++ 3 files changed, 34 insertions(+) create mode 100644 embassy-net-esp-hosted/README.md diff --git a/embassy-net-esp-hosted/Cargo.toml b/embassy-net-esp-hosted/Cargo.toml index 70b1bbe2a..b051b37ad 100644 --- a/embassy-net-esp-hosted/Cargo.toml +++ b/embassy-net-esp-hosted/Cargo.toml @@ -2,6 +2,10 @@ name = "embassy-net-esp-hosted" version = "0.1.0" edition = "2021" +description = "embassy-net driver for ESP-Hosted" +keywords = ["embedded", "esp-hosted", "embassy-net", "embedded-hal-async", "wifi", "async"] +categories = ["embedded", "hardware-support", "no-std", "network-programming", "async"] +license = "MIT OR Apache-2.0" [dependencies] defmt = { version = "0.3", optional = true } diff --git a/embassy-net-esp-hosted/README.md b/embassy-net-esp-hosted/README.md new file mode 100644 index 000000000..3c9cc4c9e --- /dev/null +++ b/embassy-net-esp-hosted/README.md @@ -0,0 +1,27 @@ +# ESP-Hosted `embassy-net` integration + +[`embassy-net`](https://crates.io/crates/embassy-net) integration for Espressif SoCs running the the ESP-Hosted stack. + +See [`examples`](https://github.com/embassy-rs/embassy/tree/main/examples/nrf52840) directory for usage examples with the nRF52840. + +## Supported chips + +- W5500 +- W5100S + +## Interoperability + +This crate can run on any executor. + +It supports any SPI driver implementing [`embedded-hal-async`](https://crates.io/crates/embedded-hal-async). + + +## License + +This work is licensed under either of + +- Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or + http://www.apache.org/licenses/LICENSE-2.0) +- MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) + +at your option. diff --git a/embassy-net-esp-hosted/src/control.rs b/embassy-net-esp-hosted/src/control.rs index b141bd6d2..c8cea8503 100644 --- a/embassy-net-esp-hosted/src/control.rs +++ b/embassy-net-esp-hosted/src/control.rs @@ -9,8 +9,11 @@ use crate::proto::{self, CtrlMsg}; #[derive(Copy, Clone, PartialEq, Eq, Debug)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] pub enum Error { + /// The operation failed with the given error code. Failed(u32), + /// The operation timed out. Timeout, + /// Internal error. Internal, } From 246c49621c30f1fb66fb328045934a8a0234855e Mon Sep 17 00:00:00 2001 From: Ulf Lilleengen Date: Wed, 20 Dec 2023 12:51:47 +0100 Subject: [PATCH 083/124] docs: embassy-net-adin1110 --- embassy-net-adin1110/Cargo.toml | 3 +-- embassy-net-adin1110/src/crc32.rs | 7 +++++++ embassy-net-adin1110/src/lib.rs | 2 ++ embassy-net-adin1110/src/mdio.rs | 1 + embassy-net-adin1110/src/phy.rs | 5 +++++ embassy-net-adin1110/src/regs.rs | 1 + 6 files changed, 17 insertions(+), 2 deletions(-) diff --git a/embassy-net-adin1110/Cargo.toml b/embassy-net-adin1110/Cargo.toml index b1582ac9b..f1be52da5 100644 --- a/embassy-net-adin1110/Cargo.toml +++ b/embassy-net-adin1110/Cargo.toml @@ -6,8 +6,7 @@ keywords = ["embedded", "ADIN1110", "embassy-net", "embedded-hal-async", "ethern categories = ["embedded", "hardware-support", "no-std", "network-programming", "async"] license = "MIT OR Apache-2.0" edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +repository = "https://github.com/embassy-rs/embassy" [dependencies] heapless = "0.8" diff --git a/embassy-net-adin1110/src/crc32.rs b/embassy-net-adin1110/src/crc32.rs index ec020b70c..d7c8346aa 100644 --- a/embassy-net-adin1110/src/crc32.rs +++ b/embassy-net-adin1110/src/crc32.rs @@ -1,3 +1,4 @@ +/// CRC32 lookup table. pub const CRC32R_LOOKUP_TABLE: [u32; 256] = [ 0x0000_0000, 0x7707_3096, @@ -263,8 +264,10 @@ pub const CRC32R_LOOKUP_TABLE: [u32; 256] = [ pub struct ETH_FCS(pub u32); impl ETH_FCS { + /// CRC32_OK pub const CRC32_OK: u32 = 0x2144_df1c; + /// Create a new frame check sequence from `data`. #[must_use] pub fn new(data: &[u8]) -> Self { let fcs = data.iter().fold(u32::MAX, |crc, byte| { @@ -274,6 +277,7 @@ impl ETH_FCS { Self(fcs) } + /// Update the frame check sequence with `data`. #[must_use] pub fn update(self, data: &[u8]) -> Self { let fcs = data.iter().fold(self.0 ^ u32::MAX, |crc, byte| { @@ -283,16 +287,19 @@ impl ETH_FCS { Self(fcs) } + /// Check if the frame check sequence is correct. #[must_use] pub fn crc_ok(&self) -> bool { self.0 == Self::CRC32_OK } + /// Switch byte order. #[must_use] pub fn hton_bytes(&self) -> [u8; 4] { self.0.to_le_bytes() } + /// Switch byte order as a u32. #[must_use] pub fn hton(&self) -> u32 { self.0.to_le() diff --git a/embassy-net-adin1110/src/lib.rs b/embassy-net-adin1110/src/lib.rs index 080b3f94d..4dafc8b0f 100644 --- a/embassy-net-adin1110/src/lib.rs +++ b/embassy-net-adin1110/src/lib.rs @@ -5,6 +5,7 @@ #![allow(clippy::missing_errors_doc)] #![allow(clippy::missing_panics_doc)] #![doc = include_str!("../README.md")] +#![warn(missing_docs)] // must go first! mod fmt; @@ -446,6 +447,7 @@ pub struct Runner<'d, SPI, INT, RST> { } impl<'d, SPI: SpiDevice, INT: Wait, RST: OutputPin> Runner<'d, SPI, INT, RST> { + /// Run the driver. #[allow(clippy::too_many_lines)] pub async fn run(mut self) -> ! { loop { diff --git a/embassy-net-adin1110/src/mdio.rs b/embassy-net-adin1110/src/mdio.rs index 1ae5f0043..6fea9370e 100644 --- a/embassy-net-adin1110/src/mdio.rs +++ b/embassy-net-adin1110/src/mdio.rs @@ -39,6 +39,7 @@ enum Reg13Op { /// /// Clause 45 methodes are bases on pub trait MdioBus { + /// Error type. type Error; /// Read, Clause 22 diff --git a/embassy-net-adin1110/src/phy.rs b/embassy-net-adin1110/src/phy.rs index d54d843d2..a37b2baa3 100644 --- a/embassy-net-adin1110/src/phy.rs +++ b/embassy-net-adin1110/src/phy.rs @@ -30,6 +30,7 @@ pub mod RegsC45 { } impl DA1 { + /// Convert. #[must_use] pub fn into(self) -> (u8, u16) { (0x01, self as u16) @@ -49,6 +50,7 @@ pub mod RegsC45 { } impl DA3 { + /// Convert. #[must_use] pub fn into(self) -> (u8, u16) { (0x03, self as u16) @@ -64,6 +66,7 @@ pub mod RegsC45 { } impl DA7 { + /// Convert. #[must_use] pub fn into(self) -> (u8, u16) { (0x07, self as u16) @@ -87,6 +90,7 @@ pub mod RegsC45 { } impl DA1E { + /// Convert. #[must_use] pub fn into(self) -> (u8, u16) { (0x1e, self as u16) @@ -104,6 +108,7 @@ pub mod RegsC45 { } impl DA1F { + /// Convert. #[must_use] pub fn into(self) -> (u8, u16) { (0x1f, self as u16) diff --git a/embassy-net-adin1110/src/regs.rs b/embassy-net-adin1110/src/regs.rs index beaf9466e..8780c2b9d 100644 --- a/embassy-net-adin1110/src/regs.rs +++ b/embassy-net-adin1110/src/regs.rs @@ -2,6 +2,7 @@ use core::fmt::{Debug, Display}; use bitfield::{bitfield, bitfield_bitrange, bitfield_fields}; +#[allow(missing_docs)] #[allow(non_camel_case_types)] #[derive(Debug, Copy, Clone)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] From b0583b17cbbf13988c37dcb1291d3acf6a78977c Mon Sep 17 00:00:00 2001 From: Ulf Lilleengen Date: Wed, 20 Dec 2023 13:08:06 +0100 Subject: [PATCH 084/124] fix: make non-public instead --- embassy-net-adin1110/src/crc32.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/embassy-net-adin1110/src/crc32.rs b/embassy-net-adin1110/src/crc32.rs index d7c8346aa..4b3c69f23 100644 --- a/embassy-net-adin1110/src/crc32.rs +++ b/embassy-net-adin1110/src/crc32.rs @@ -264,8 +264,7 @@ pub const CRC32R_LOOKUP_TABLE: [u32; 256] = [ pub struct ETH_FCS(pub u32); impl ETH_FCS { - /// CRC32_OK - pub const CRC32_OK: u32 = 0x2144_df1c; + const CRC32_OK: u32 = 0x2144_df1c; /// Create a new frame check sequence from `data`. #[must_use] From 13c107e81582e2249df2fd940791b611a1ddbd62 Mon Sep 17 00:00:00 2001 From: Rasmus Melchior Jacobsen Date: Wed, 20 Dec 2023 13:09:16 +0100 Subject: [PATCH 085/124] Put waiting state back if any --- embassy-sync/src/signal.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/embassy-sync/src/signal.rs b/embassy-sync/src/signal.rs index 97d76b463..d75750ce7 100644 --- a/embassy-sync/src/signal.rs +++ b/embassy-sync/src/signal.rs @@ -117,7 +117,10 @@ where let state = cell.replace(State::None); match state { State::Signaled(res) => Some(res), - _ => None, + state => { + cell.set(state); + None + } } }) } From b8777eaea2e2f7966c1c0789e261bffcdc2a1be4 Mon Sep 17 00:00:00 2001 From: Ulf Lilleengen Date: Wed, 20 Dec 2023 13:12:32 +0100 Subject: [PATCH 086/124] better keep missing docs for into --- embassy-net-adin1110/src/phy.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/embassy-net-adin1110/src/phy.rs b/embassy-net-adin1110/src/phy.rs index a37b2baa3..9966e1f6a 100644 --- a/embassy-net-adin1110/src/phy.rs +++ b/embassy-net-adin1110/src/phy.rs @@ -30,7 +30,7 @@ pub mod RegsC45 { } impl DA1 { - /// Convert. + #[allow(missing_docs)] #[must_use] pub fn into(self) -> (u8, u16) { (0x01, self as u16) @@ -50,7 +50,7 @@ pub mod RegsC45 { } impl DA3 { - /// Convert. + #[allow(missing_docs)] #[must_use] pub fn into(self) -> (u8, u16) { (0x03, self as u16) @@ -66,7 +66,7 @@ pub mod RegsC45 { } impl DA7 { - /// Convert. + #[allow(missing_docs)] #[must_use] pub fn into(self) -> (u8, u16) { (0x07, self as u16) @@ -90,7 +90,7 @@ pub mod RegsC45 { } impl DA1E { - /// Convert. + #[allow(missing_docs)] #[must_use] pub fn into(self) -> (u8, u16) { (0x1e, self as u16) @@ -108,7 +108,7 @@ pub mod RegsC45 { } impl DA1F { - /// Convert. + #[allow(missing_docs)] #[must_use] pub fn into(self) -> (u8, u16) { (0x1f, self as u16) From 1c3cf347cbd1b650f55a0c88a07210af83608157 Mon Sep 17 00:00:00 2001 From: Ulf Lilleengen Date: Wed, 20 Dec 2023 13:20:43 +0100 Subject: [PATCH 087/124] remove embedded-sdmmc Remove support for embedded-sdmmc due to lack of maintainership. Bring it back once the upstream includes the async functionality. --- ci.sh | 4 +-- embassy-stm32/Cargo.toml | 1 - embassy-stm32/src/sdmmc/mod.rs | 50 ---------------------------------- examples/stm32f4/Cargo.toml | 2 +- 4 files changed, 3 insertions(+), 54 deletions(-) diff --git a/ci.sh b/ci.sh index 83c05d1b9..e3918783f 100755 --- a/ci.sh +++ b/ci.sh @@ -91,12 +91,12 @@ cargo batch \ --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32f417zg,defmt,exti,time-driver-any,time \ --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32f423zh,defmt,exti,time-driver-any,time \ --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32f427zi,defmt,exti,time-driver-any,time \ - --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32f429zi,log,exti,time-driver-any,embedded-sdmmc,time \ + --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32f429zi,log,exti,time-driver-any,time \ --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32f437zi,log,exti,time-driver-any,time \ --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32f439zi,defmt,exti,time-driver-any,time \ --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32f446ze,defmt,exti,time-driver-any,time \ --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32f469zi,defmt,exti,time-driver-any,time \ - --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32f479zi,defmt,exti,time-driver-any,embedded-sdmmc,time \ + --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32f479zi,defmt,exti,time-driver-any,time \ --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32f730i8,defmt,exti,time-driver-any,time \ --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32h753zi,defmt,exti,time-driver-any,time \ --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32h735zg,defmt,exti,time-driver-any,time \ diff --git a/embassy-stm32/Cargo.toml b/embassy-stm32/Cargo.toml index 7f2cf6bfb..83db7c4bf 100644 --- a/embassy-stm32/Cargo.toml +++ b/embassy-stm32/Cargo.toml @@ -56,7 +56,6 @@ cortex-m = "0.7.6" futures = { version = "0.3.17", default-features = false, features = ["async-await"] } rand_core = "0.6.3" sdio-host = "0.5.0" -embedded-sdmmc = { git = "https://github.com/embassy-rs/embedded-sdmmc-rs", rev = "a4f293d3a6f72158385f79c98634cb8a14d0d2fc", optional = true } critical-section = "1.1" stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-2234f380f51d16d0398b8e547088b33ea623cc7c" } vcell = "0.1.3" diff --git a/embassy-stm32/src/sdmmc/mod.rs b/embassy-stm32/src/sdmmc/mod.rs index 10006baff..debe26c88 100644 --- a/embassy-stm32/src/sdmmc/mod.rs +++ b/embassy-stm32/src/sdmmc/mod.rs @@ -1538,53 +1538,3 @@ foreach_peripheral!( impl Instance for peripherals::$inst {} }; ); - -#[cfg(feature = "embedded-sdmmc")] -mod sdmmc_rs { - use embedded_sdmmc::{Block, BlockCount, BlockDevice, BlockIdx}; - - use super::*; - - impl<'d, T: Instance, Dma: SdmmcDma> BlockDevice for Sdmmc<'d, T, Dma> { - type Error = Error; - - async fn read( - &mut self, - blocks: &mut [Block], - start_block_idx: BlockIdx, - _reason: &str, - ) -> Result<(), Self::Error> { - let mut address = start_block_idx.0; - - for block in blocks.iter_mut() { - let block: &mut [u8; 512] = &mut block.contents; - - // NOTE(unsafe) Block uses align(4) - let block = unsafe { &mut *(block as *mut _ as *mut DataBlock) }; - self.read_block(address, block).await?; - address += 1; - } - Ok(()) - } - - async fn write(&mut self, blocks: &[Block], start_block_idx: BlockIdx) -> Result<(), Self::Error> { - let mut address = start_block_idx.0; - - for block in blocks.iter() { - let block: &[u8; 512] = &block.contents; - - // NOTE(unsafe) DataBlock uses align 4 - let block = unsafe { &*(block as *const _ as *const DataBlock) }; - self.write_block(address, block).await?; - address += 1; - } - Ok(()) - } - - fn num_blocks(&self) -> Result { - let card = self.card()?; - let count = card.csd.block_count(); - Ok(BlockCount(count)) - } - } -} diff --git a/examples/stm32f4/Cargo.toml b/examples/stm32f4/Cargo.toml index 6ea0018cd..e24fbee82 100644 --- a/examples/stm32f4/Cargo.toml +++ b/examples/stm32f4/Cargo.toml @@ -6,7 +6,7 @@ license = "MIT OR Apache-2.0" [dependencies] # Change stm32f429zi to your chip name, if necessary. -embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = [ "defmt", "stm32f429zi", "unstable-pac", "memory-x", "time-driver-any", "exti", "embedded-sdmmc", "chrono"] } +embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = [ "defmt", "stm32f429zi", "unstable-pac", "memory-x", "time-driver-any", "exti", "chrono"] } embassy-sync = { version = "0.5.0", path = "../../embassy-sync", features = ["defmt"] } embassy-executor = { version = "0.4.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "executor-interrupt", "defmt", "integrated-timers"] } embassy-time = { version = "0.2", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } From 51a67cb69ab72e44c6cbeea677c4c6bd1e5c2550 Mon Sep 17 00:00:00 2001 From: Ulf Lilleengen Date: Wed, 20 Dec 2023 13:34:34 +0100 Subject: [PATCH 088/124] fix: expose less --- embassy-net-adin1110/src/lib.rs | 5 +++-- embassy-net-adin1110/src/phy.rs | 5 ----- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/embassy-net-adin1110/src/lib.rs b/embassy-net-adin1110/src/lib.rs index 4dafc8b0f..6ecfa587d 100644 --- a/embassy-net-adin1110/src/lib.rs +++ b/embassy-net-adin1110/src/lib.rs @@ -27,8 +27,9 @@ use embedded_hal_async::digital::Wait; use embedded_hal_async::spi::{Error, Operation, SpiDevice}; use heapless::Vec; pub use mdio::MdioBus; -pub use phy::{Phy10BaseT1x, RegsC22, RegsC45}; -pub use regs::{Config0, Config2, SpiRegisters as sr, Status0, Status1}; +pub use phy::Phy10BaseT1x; +use phy::{RegsC22, RegsC45}; +use regs::{Config0, Config2, SpiRegisters as sr, Status0, Status1}; use crate::fmt::Bytes; use crate::regs::{LedCntrl, LedFunc, LedPol, LedPolarity, SpiHeader}; diff --git a/embassy-net-adin1110/src/phy.rs b/embassy-net-adin1110/src/phy.rs index 9966e1f6a..d54d843d2 100644 --- a/embassy-net-adin1110/src/phy.rs +++ b/embassy-net-adin1110/src/phy.rs @@ -30,7 +30,6 @@ pub mod RegsC45 { } impl DA1 { - #[allow(missing_docs)] #[must_use] pub fn into(self) -> (u8, u16) { (0x01, self as u16) @@ -50,7 +49,6 @@ pub mod RegsC45 { } impl DA3 { - #[allow(missing_docs)] #[must_use] pub fn into(self) -> (u8, u16) { (0x03, self as u16) @@ -66,7 +64,6 @@ pub mod RegsC45 { } impl DA7 { - #[allow(missing_docs)] #[must_use] pub fn into(self) -> (u8, u16) { (0x07, self as u16) @@ -90,7 +87,6 @@ pub mod RegsC45 { } impl DA1E { - #[allow(missing_docs)] #[must_use] pub fn into(self) -> (u8, u16) { (0x1e, self as u16) @@ -108,7 +104,6 @@ pub mod RegsC45 { } impl DA1F { - #[allow(missing_docs)] #[must_use] pub fn into(self) -> (u8, u16) { (0x1f, self as u16) From 93bb34d8d1304a87ba62017834f4be848a1757e5 Mon Sep 17 00:00:00 2001 From: Ulf Lilleengen Date: Wed, 20 Dec 2023 13:39:45 +0100 Subject: [PATCH 089/124] fix: expose less --- embassy-net-esp-hosted/src/proto.rs | 110 ++++++++++++++-------------- 1 file changed, 55 insertions(+), 55 deletions(-) diff --git a/embassy-net-esp-hosted/src/proto.rs b/embassy-net-esp-hosted/src/proto.rs index b42ff62f1..034d5bf84 100644 --- a/embassy-net-esp-hosted/src/proto.rs +++ b/embassy-net-esp-hosted/src/proto.rs @@ -1,12 +1,10 @@ -#![allow(missing_docs)] - use heapless::{String, Vec}; /// internal supporting structures for CtrlMsg #[derive(Debug, Default, Clone, Eq, PartialEq, noproto::Message)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub struct ScanResult { +pub(crate) struct ScanResult { #[noproto(tag = "1")] pub ssid: String<32>, #[noproto(tag = "2")] @@ -21,7 +19,7 @@ pub struct ScanResult { #[derive(Debug, Default, Clone, Eq, PartialEq, noproto::Message)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub struct ConnectedStaList { +pub(crate) struct ConnectedStaList { #[noproto(tag = "1")] pub mac: String<32>, #[noproto(tag = "2")] @@ -31,14 +29,14 @@ pub struct ConnectedStaList { #[derive(Debug, Default, Clone, Eq, PartialEq, noproto::Message)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub struct CtrlMsgReqGetMacAddress { +pub(crate) struct CtrlMsgReqGetMacAddress { #[noproto(tag = "1")] pub mode: u32, } #[derive(Debug, Default, Clone, Eq, PartialEq, noproto::Message)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub struct CtrlMsgRespGetMacAddress { +pub(crate) struct CtrlMsgRespGetMacAddress { #[noproto(tag = "1")] pub mac: String<32>, #[noproto(tag = "2")] @@ -47,11 +45,11 @@ pub struct CtrlMsgRespGetMacAddress { #[derive(Debug, Default, Clone, Eq, PartialEq, noproto::Message)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub struct CtrlMsgReqGetMode {} +pub(crate) struct CtrlMsgReqGetMode {} #[derive(Debug, Default, Clone, Eq, PartialEq, noproto::Message)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub struct CtrlMsgRespGetMode { +pub(crate) struct CtrlMsgRespGetMode { #[noproto(tag = "1")] pub mode: u32, #[noproto(tag = "2")] @@ -60,32 +58,32 @@ pub struct CtrlMsgRespGetMode { #[derive(Debug, Default, Clone, Eq, PartialEq, noproto::Message)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub struct CtrlMsgReqSetMode { +pub(crate) struct CtrlMsgReqSetMode { #[noproto(tag = "1")] pub mode: u32, } #[derive(Debug, Default, Clone, Eq, PartialEq, noproto::Message)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub struct CtrlMsgRespSetMode { +pub(crate) struct CtrlMsgRespSetMode { #[noproto(tag = "1")] pub resp: u32, } #[derive(Debug, Default, Clone, Eq, PartialEq, noproto::Message)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub struct CtrlMsgReqGetStatus {} +pub(crate) struct CtrlMsgReqGetStatus {} #[derive(Debug, Default, Clone, Eq, PartialEq, noproto::Message)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub struct CtrlMsgRespGetStatus { +pub(crate) struct CtrlMsgRespGetStatus { #[noproto(tag = "1")] pub resp: u32, } #[derive(Debug, Default, Clone, Eq, PartialEq, noproto::Message)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub struct CtrlMsgReqSetMacAddress { +pub(crate) struct CtrlMsgReqSetMacAddress { #[noproto(tag = "1")] pub mac: String<32>, #[noproto(tag = "2")] @@ -94,18 +92,18 @@ pub struct CtrlMsgReqSetMacAddress { #[derive(Debug, Default, Clone, Eq, PartialEq, noproto::Message)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub struct CtrlMsgRespSetMacAddress { +pub(crate) struct CtrlMsgRespSetMacAddress { #[noproto(tag = "1")] pub resp: u32, } #[derive(Debug, Default, Clone, Eq, PartialEq, noproto::Message)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub struct CtrlMsgReqGetApConfig {} +pub(crate) struct CtrlMsgReqGetApConfig {} #[derive(Debug, Default, Clone, Eq, PartialEq, noproto::Message)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub struct CtrlMsgRespGetApConfig { +pub(crate) struct CtrlMsgRespGetApConfig { #[noproto(tag = "1")] pub ssid: String<32>, #[noproto(tag = "2")] @@ -122,7 +120,7 @@ pub struct CtrlMsgRespGetApConfig { #[derive(Debug, Default, Clone, Eq, PartialEq, noproto::Message)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub struct CtrlMsgReqConnectAp { +pub(crate) struct CtrlMsgReqConnectAp { #[noproto(tag = "1")] pub ssid: String<32>, #[noproto(tag = "2")] @@ -137,7 +135,7 @@ pub struct CtrlMsgReqConnectAp { #[derive(Debug, Default, Clone, Eq, PartialEq, noproto::Message)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub struct CtrlMsgRespConnectAp { +pub(crate) struct CtrlMsgRespConnectAp { #[noproto(tag = "1")] pub resp: u32, #[noproto(tag = "2")] @@ -146,11 +144,11 @@ pub struct CtrlMsgRespConnectAp { #[derive(Debug, Default, Clone, Eq, PartialEq, noproto::Message)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub struct CtrlMsgReqGetSoftApConfig {} +pub(crate) struct CtrlMsgReqGetSoftApConfig {} #[derive(Debug, Default, Clone, Eq, PartialEq, noproto::Message)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub struct CtrlMsgRespGetSoftApConfig { +pub(crate) struct CtrlMsgRespGetSoftApConfig { #[noproto(tag = "1")] pub ssid: String<32>, #[noproto(tag = "2")] @@ -171,7 +169,7 @@ pub struct CtrlMsgRespGetSoftApConfig { #[derive(Debug, Default, Clone, Eq, PartialEq, noproto::Message)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub struct CtrlMsgReqStartSoftAp { +pub(crate) struct CtrlMsgReqStartSoftAp { #[noproto(tag = "1")] pub ssid: String<32>, #[noproto(tag = "2")] @@ -190,7 +188,7 @@ pub struct CtrlMsgReqStartSoftAp { #[derive(Debug, Default, Clone, Eq, PartialEq, noproto::Message)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub struct CtrlMsgRespStartSoftAp { +pub(crate) struct CtrlMsgRespStartSoftAp { #[noproto(tag = "1")] pub resp: u32, #[noproto(tag = "2")] @@ -199,11 +197,11 @@ pub struct CtrlMsgRespStartSoftAp { #[derive(Debug, Default, Clone, Eq, PartialEq, noproto::Message)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub struct CtrlMsgReqScanResult {} +pub(crate) struct CtrlMsgReqScanResult {} #[derive(Debug, Default, Clone, Eq, PartialEq, noproto::Message)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub struct CtrlMsgRespScanResult { +pub(crate) struct CtrlMsgRespScanResult { #[noproto(tag = "1")] pub count: u32, #[noproto(repeated, tag = "2")] @@ -214,11 +212,11 @@ pub struct CtrlMsgRespScanResult { #[derive(Debug, Default, Clone, Eq, PartialEq, noproto::Message)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub struct CtrlMsgReqSoftApConnectedSta {} +pub(crate) struct CtrlMsgReqSoftApConnectedSta {} #[derive(Debug, Default, Clone, Eq, PartialEq, noproto::Message)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub struct CtrlMsgRespSoftApConnectedSta { +pub(crate) struct CtrlMsgRespSoftApConnectedSta { #[noproto(tag = "1")] pub num: u32, #[noproto(repeated, tag = "2")] @@ -229,43 +227,43 @@ pub struct CtrlMsgRespSoftApConnectedSta { #[derive(Debug, Default, Clone, Eq, PartialEq, noproto::Message)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub struct CtrlMsgReqOtaBegin {} +pub(crate) struct CtrlMsgReqOtaBegin {} #[derive(Debug, Default, Clone, Eq, PartialEq, noproto::Message)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub struct CtrlMsgRespOtaBegin { +pub(crate) struct CtrlMsgRespOtaBegin { #[noproto(tag = "1")] pub resp: u32, } #[derive(Debug, Default, Clone, Eq, PartialEq, noproto::Message)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub struct CtrlMsgReqOtaWrite { +pub(crate) struct CtrlMsgReqOtaWrite { #[noproto(tag = "1")] pub ota_data: Vec, } #[derive(Debug, Default, Clone, Eq, PartialEq, noproto::Message)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub struct CtrlMsgRespOtaWrite { +pub(crate) struct CtrlMsgRespOtaWrite { #[noproto(tag = "1")] pub resp: u32, } #[derive(Debug, Default, Clone, Eq, PartialEq, noproto::Message)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub struct CtrlMsgReqOtaEnd {} +pub(crate) struct CtrlMsgReqOtaEnd {} #[derive(Debug, Default, Clone, Eq, PartialEq, noproto::Message)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub struct CtrlMsgRespOtaEnd { +pub(crate) struct CtrlMsgRespOtaEnd { #[noproto(tag = "1")] pub resp: u32, } #[derive(Debug, Default, Clone, Eq, PartialEq, noproto::Message)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub struct CtrlMsgReqVendorIeData { +pub(crate) struct CtrlMsgReqVendorIeData { #[noproto(tag = "1")] pub element_id: u32, #[noproto(tag = "2")] @@ -280,7 +278,7 @@ pub struct CtrlMsgReqVendorIeData { #[derive(Debug, Default, Clone, Eq, PartialEq, noproto::Message)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub struct CtrlMsgReqSetSoftApVendorSpecificIe { +pub(crate) struct CtrlMsgReqSetSoftApVendorSpecificIe { #[noproto(tag = "1")] pub enable: bool, #[noproto(tag = "2")] @@ -293,32 +291,32 @@ pub struct CtrlMsgReqSetSoftApVendorSpecificIe { #[derive(Debug, Default, Clone, Eq, PartialEq, noproto::Message)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub struct CtrlMsgRespSetSoftApVendorSpecificIe { +pub(crate) struct CtrlMsgRespSetSoftApVendorSpecificIe { #[noproto(tag = "1")] pub resp: u32, } #[derive(Debug, Default, Clone, Eq, PartialEq, noproto::Message)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub struct CtrlMsgReqSetWifiMaxTxPower { +pub(crate) struct CtrlMsgReqSetWifiMaxTxPower { #[noproto(tag = "1")] pub wifi_max_tx_power: u32, } #[derive(Debug, Default, Clone, Eq, PartialEq, noproto::Message)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub struct CtrlMsgRespSetWifiMaxTxPower { +pub(crate) struct CtrlMsgRespSetWifiMaxTxPower { #[noproto(tag = "1")] pub resp: u32, } #[derive(Debug, Default, Clone, Eq, PartialEq, noproto::Message)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub struct CtrlMsgReqGetWifiCurrTxPower {} +pub(crate) struct CtrlMsgReqGetWifiCurrTxPower {} #[derive(Debug, Default, Clone, Eq, PartialEq, noproto::Message)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub struct CtrlMsgRespGetWifiCurrTxPower { +pub(crate) struct CtrlMsgRespGetWifiCurrTxPower { #[noproto(tag = "1")] pub wifi_curr_tx_power: u32, #[noproto(tag = "2")] @@ -327,7 +325,7 @@ pub struct CtrlMsgRespGetWifiCurrTxPower { #[derive(Debug, Default, Clone, Eq, PartialEq, noproto::Message)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub struct CtrlMsgReqConfigHeartbeat { +pub(crate) struct CtrlMsgReqConfigHeartbeat { #[noproto(tag = "1")] pub enable: bool, #[noproto(tag = "2")] @@ -336,7 +334,7 @@ pub struct CtrlMsgReqConfigHeartbeat { #[derive(Debug, Default, Clone, Eq, PartialEq, noproto::Message)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub struct CtrlMsgRespConfigHeartbeat { +pub(crate) struct CtrlMsgRespConfigHeartbeat { #[noproto(tag = "1")] pub resp: u32, } @@ -344,28 +342,28 @@ pub struct CtrlMsgRespConfigHeartbeat { #[derive(Debug, Default, Clone, Eq, PartialEq, noproto::Message)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub struct CtrlMsgEventEspInit { +pub(crate) struct CtrlMsgEventEspInit { #[noproto(tag = "1")] pub init_data: Vec, } #[derive(Debug, Default, Clone, Eq, PartialEq, noproto::Message)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub struct CtrlMsgEventHeartbeat { +pub(crate) struct CtrlMsgEventHeartbeat { #[noproto(tag = "1")] pub hb_num: u32, } #[derive(Debug, Default, Clone, Eq, PartialEq, noproto::Message)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub struct CtrlMsgEventStationDisconnectFromAp { +pub(crate) struct CtrlMsgEventStationDisconnectFromAp { #[noproto(tag = "1")] pub resp: u32, } #[derive(Debug, Default, Clone, Eq, PartialEq, noproto::Message)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub struct CtrlMsgEventStationDisconnectFromEspSoftAp { +pub(crate) struct CtrlMsgEventStationDisconnectFromEspSoftAp { #[noproto(tag = "1")] pub resp: u32, #[noproto(tag = "2")] @@ -374,7 +372,7 @@ pub struct CtrlMsgEventStationDisconnectFromEspSoftAp { #[derive(Debug, Default, Clone, Eq, PartialEq, noproto::Message)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub struct CtrlMsg { +pub(crate) struct CtrlMsg { /// msg_type could be req, resp or Event #[noproto(tag = "1")] pub msg_type: CtrlMsgType, @@ -392,7 +390,7 @@ pub struct CtrlMsg { /// union of all msg ids #[derive(Debug, Clone, Eq, PartialEq, noproto::Oneof)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub enum CtrlMsgPayload { +pub(crate) enum CtrlMsgPayload { /// * Requests * #[noproto(tag = "101")] ReqGetMacAddress(CtrlMsgReqGetMacAddress), @@ -494,7 +492,7 @@ pub enum CtrlMsgPayload { #[derive(Debug, Default, Clone, Copy, Eq, PartialEq, Hash, PartialOrd, Ord, noproto::Enumeration)] #[repr(u32)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub enum CtrlVendorIeType { +pub(crate) enum CtrlVendorIeType { #[default] Beacon = 0, ProbeReq = 1, @@ -506,7 +504,7 @@ pub enum CtrlVendorIeType { #[derive(Debug, Default, Clone, Copy, Eq, PartialEq, Hash, PartialOrd, Ord, noproto::Enumeration)] #[repr(u32)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub enum CtrlVendorIeid { +pub(crate) enum CtrlVendorIeid { #[default] Id0 = 0, Id1 = 1, @@ -515,7 +513,7 @@ pub enum CtrlVendorIeid { #[derive(Debug, Default, Clone, Copy, Eq, PartialEq, Hash, PartialOrd, Ord, noproto::Enumeration)] #[repr(u32)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub enum CtrlWifiMode { +pub(crate) enum CtrlWifiMode { #[default] None = 0, Sta = 1, @@ -526,7 +524,7 @@ pub enum CtrlWifiMode { #[derive(Debug, Default, Clone, Copy, Eq, PartialEq, Hash, PartialOrd, Ord, noproto::Enumeration)] #[repr(u32)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub enum CtrlWifiBw { +pub(crate) enum CtrlWifiBw { #[default] BwInvalid = 0, Ht20 = 1, @@ -536,13 +534,15 @@ pub enum CtrlWifiBw { #[derive(Debug, Default, Clone, Copy, Eq, PartialEq, Hash, PartialOrd, Ord, noproto::Enumeration)] #[repr(u32)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub enum CtrlWifiPowerSave { +pub(crate) enum CtrlWifiPowerSave { #[default] PsInvalid = 0, MinModem = 1, MaxModem = 2, } +/// Wifi Security Settings +#[allow(missing_docs)] #[derive(Debug, Default, Clone, Copy, Eq, PartialEq, Hash, PartialOrd, Ord, noproto::Enumeration)] #[repr(u32)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] @@ -562,7 +562,7 @@ pub enum CtrlWifiSecProt { #[derive(Debug, Default, Clone, Copy, Eq, PartialEq, Hash, PartialOrd, Ord, noproto::Enumeration)] #[repr(u32)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub enum CtrlStatus { +pub(crate) enum CtrlStatus { #[default] Connected = 0, NotConnected = 1, @@ -575,7 +575,7 @@ pub enum CtrlStatus { #[derive(Debug, Default, Clone, Copy, Eq, PartialEq, Hash, PartialOrd, Ord, noproto::Enumeration)] #[repr(u32)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub enum CtrlMsgType { +pub(crate) enum CtrlMsgType { #[default] MsgTypeInvalid = 0, Req = 1, @@ -587,7 +587,7 @@ pub enum CtrlMsgType { #[derive(Debug, Default, Clone, Copy, Eq, PartialEq, Hash, PartialOrd, Ord, noproto::Enumeration)] #[repr(u32)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub enum CtrlMsgId { +pub(crate) enum CtrlMsgId { #[default] MsgIdInvalid = 0, /// * Request Msgs * From 896690c41573f1c06c4efa02d367b70741322cdb Mon Sep 17 00:00:00 2001 From: Ulf Lilleengen Date: Wed, 20 Dec 2023 13:46:43 +0100 Subject: [PATCH 090/124] fix: remove git dependency in embassy-boot --- embassy-boot/nrf/Cargo.toml | 8 +++++++- embassy-boot/rp/Cargo.toml | 6 ++++++ embassy-boot/stm32/Cargo.toml | 6 ++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/embassy-boot/nrf/Cargo.toml b/embassy-boot/nrf/Cargo.toml index eea29cf2e..9f74fb126 100644 --- a/embassy-boot/nrf/Cargo.toml +++ b/embassy-boot/nrf/Cargo.toml @@ -4,6 +4,12 @@ name = "embassy-boot-nrf" version = "0.1.0" description = "Bootloader lib for nRF chips" license = "MIT OR Apache-2.0" +repository = "https://github.com/embassy-rs/embassy" +categories = [ + "embedded", + "no-std", + "asynchronous", +] [package.metadata.embassy_docs] src_base = "https://github.com/embassy-rs/embassy/blob/embassy-boot-nrf-v$VERSION/embassy-boot/nrf/src/" @@ -25,7 +31,7 @@ embedded-storage = "0.3.1" embedded-storage-async = { version = "0.4.1" } cfg-if = "1.0.0" -nrf-softdevice-mbr = { version = "0.1.0", git = "https://github.com/embassy-rs/nrf-softdevice.git", branch = "master", optional = true } +nrf-softdevice-mbr = { version = "0.2.0", optional = true } [features] defmt = [ diff --git a/embassy-boot/rp/Cargo.toml b/embassy-boot/rp/Cargo.toml index 0f2dc4628..90bab0996 100644 --- a/embassy-boot/rp/Cargo.toml +++ b/embassy-boot/rp/Cargo.toml @@ -4,6 +4,12 @@ name = "embassy-boot-rp" version = "0.1.0" description = "Bootloader lib for RP2040 chips" license = "MIT OR Apache-2.0" +repository = "https://github.com/embassy-rs/embassy" +categories = [ + "embedded", + "no-std", + "asynchronous", +] [package.metadata.embassy_docs] src_base = "https://github.com/embassy-rs/embassy/blob/embassy-boot-rp-v$VERSION/src/" diff --git a/embassy-boot/stm32/Cargo.toml b/embassy-boot/stm32/Cargo.toml index bc8da6738..70919b76d 100644 --- a/embassy-boot/stm32/Cargo.toml +++ b/embassy-boot/stm32/Cargo.toml @@ -4,6 +4,12 @@ name = "embassy-boot-stm32" version = "0.1.0" description = "Bootloader lib for STM32 chips" license = "MIT OR Apache-2.0" +repository = "https://github.com/embassy-rs/embassy" +categories = [ + "embedded", + "no-std", + "asynchronous", +] [package.metadata.embassy_docs] src_base = "https://github.com/embassy-rs/embassy/blob/embassy-boot-nrf-v$VERSION/embassy-boot/stm32/src/" From d6fda686bce8b0f6e0ccc1196d22ddc86baa34e6 Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Wed, 20 Dec 2023 14:13:52 +0100 Subject: [PATCH 091/124] net-esp-hosted: use released noproto version. --- embassy-net-esp-hosted/Cargo.toml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/embassy-net-esp-hosted/Cargo.toml b/embassy-net-esp-hosted/Cargo.toml index b051b37ad..61984dd53 100644 --- a/embassy-net-esp-hosted/Cargo.toml +++ b/embassy-net-esp-hosted/Cargo.toml @@ -19,8 +19,7 @@ embassy-net-driver-channel = { version = "0.2.0", path = "../embassy-net-driver- embedded-hal = { version = "1.0.0-rc.3" } embedded-hal-async = { version = "=1.0.0-rc.3" } -noproto = { git="https://github.com/embassy-rs/noproto", rev = "f5e6d1f325b6ad4e344f60452b09576e24671f62", default-features = false, features = ["derive"] } -#noproto = { version = "0.1", path = "/home/dirbaio/noproto", default-features = false, features = ["derive"] } +noproto = "0.1.0" heapless = "0.8" [package.metadata.embassy_docs] From 745d618ab7f40f518c25d8db2116cfd774c16623 Mon Sep 17 00:00:00 2001 From: eZio Pan Date: Thu, 21 Dec 2023 16:59:20 +0800 Subject: [PATCH 092/124] note on circular mode DMA --- embassy-stm32/src/dma/bdma.rs | 4 ++++ embassy-stm32/src/dma/dma.rs | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/embassy-stm32/src/dma/bdma.rs b/embassy-stm32/src/dma/bdma.rs index 2f37b1edf..a2b83716d 100644 --- a/embassy-stm32/src/dma/bdma.rs +++ b/embassy-stm32/src/dma/bdma.rs @@ -23,6 +23,10 @@ use crate::pac::bdma::{regs, vals}; #[non_exhaustive] pub struct TransferOptions { /// Enable circular DMA + /// + /// Note: + /// If you enable circular mode manually, you may want to build and `.await` the `Transfer` in a separate task. + /// Since DMA in circular mode need manually stop, `.await` in current task would block the task forever. pub circular: bool, /// Enable half transfer interrupt pub half_transfer_ir: bool, diff --git a/embassy-stm32/src/dma/dma.rs b/embassy-stm32/src/dma/dma.rs index 9b47ca5c3..16d02f273 100644 --- a/embassy-stm32/src/dma/dma.rs +++ b/embassy-stm32/src/dma/dma.rs @@ -30,6 +30,10 @@ pub struct TransferOptions { /// FIFO threshold for DMA FIFO mode. If none, direct mode is used. pub fifo_threshold: Option, /// Enable circular DMA + /// + /// Note: + /// If you enable circular mode manually, you may want to build and `.await` the `Transfer` in a separate task. + /// Since DMA in circular mode need manually stop, `.await` in current task would block the task forever. pub circular: bool, /// Enable half transfer interrupt pub half_transfer_ir: bool, From 0acf7b09c3bc9176d00479d601356d8df2537a9b Mon Sep 17 00:00:00 2001 From: Ulf Lilleengen Date: Thu, 21 Dec 2023 08:50:54 +0100 Subject: [PATCH 093/124] chore: replace make_static! macro usage with non-macro version --- embassy-net/src/lib.rs | 6 ++-- embassy-stm32/src/low_power.rs | 5 +-- .../nrf52840/src/bin/ethernet_enc28j60.rs | 17 +++++++--- examples/nrf52840/src/bin/usb_ethernet.rs | 32 +++++++++++-------- .../nrf52840/src/bin/usb_serial_multitask.rs | 20 ++++++++---- examples/nrf52840/src/bin/wifi_esp_hosted.rs | 13 +++++--- .../rp/src/bin/ethernet_w5500_multisocket.rs | 13 +++++--- .../rp/src/bin/ethernet_w5500_tcp_client.rs | 13 +++++--- .../rp/src/bin/ethernet_w5500_tcp_server.rs | 13 +++++--- examples/rp/src/bin/ethernet_w5500_udp.rs | 13 +++++--- examples/rp/src/bin/uart_buffered_split.rs | 8 +++-- examples/rp/src/bin/usb_ethernet.rs | 28 ++++++++++------ examples/rp/src/bin/wifi_ap_tcp_server.rs | 13 +++++--- examples/rp/src/bin/wifi_blinky.rs | 5 +-- examples/rp/src/bin/wifi_scan.rs | 5 +-- examples/rp/src/bin/wifi_tcp_server.rs | 13 +++++--- examples/std/src/bin/net.rs | 10 +++--- examples/std/src/bin/net_dns.rs | 10 +++--- examples/std/src/bin/net_ppp.rs | 13 +++++--- examples/std/src/bin/net_udp.rs | 10 +++--- examples/std/src/bin/tcp_accept.rs | 10 +++--- examples/stm32f4/src/bin/eth.rs | 13 +++++--- examples/stm32f4/src/bin/usb_ethernet.rs | 31 +++++++++++------- examples/stm32f7/src/bin/can.rs | 7 ++-- examples/stm32f7/src/bin/eth.rs | 13 +++++--- examples/stm32h5/src/bin/eth.rs | 13 +++++--- examples/stm32h7/src/bin/eth.rs | 13 +++++--- examples/stm32h7/src/bin/eth_client.rs | 13 +++++--- .../src/bin/spe_adin1110_http_server.rs | 13 +++++--- examples/stm32l5/src/bin/usb_ethernet.rs | 28 ++++++++++------ examples/stm32wb/src/bin/mac_ffd_net.rs | 20 ++++++++---- tests/nrf/src/bin/ethernet_enc28j60_perf.rs | 10 +++--- tests/nrf/src/bin/wifi_esp_hosted_perf.rs | 13 +++++--- tests/rp/src/bin/cyw43-perf.rs | 13 +++++--- tests/rp/src/bin/ethernet_w5100s_perf.rs | 13 +++++--- tests/stm32/src/bin/eth.rs | 13 +++++--- tests/stm32/src/bin/stop.rs | 5 +-- 37 files changed, 313 insertions(+), 188 deletions(-) diff --git a/embassy-net/src/lib.rs b/embassy-net/src/lib.rs index bf1468642..d970d0332 100644 --- a/embassy-net/src/lib.rs +++ b/embassy-net/src/lib.rs @@ -411,10 +411,12 @@ impl Stack { /// ```ignore /// let config = embassy_net::Config::dhcpv4(Default::default()); ///// Init network stack - /// let stack = &*make_static!(embassy_net::Stack::new( + /// static RESOURCES: StaticCell = StaticCell::new(); + /// static STACK: StaticCell = StaticCell::new(); + /// let stack = &*STACK.init(embassy_net::Stack::new( /// device, /// config, - /// make_static!(embassy_net::StackResources::<2>::new()), + /// RESOURCES.init(embassy_net::StackResources::new()), /// seed /// )); /// // Launch network task that runs `stack.run().await` diff --git a/embassy-stm32/src/low_power.rs b/embassy-stm32/src/low_power.rs index a41c40eba..4fab8dae4 100644 --- a/embassy-stm32/src/low_power.rs +++ b/embassy-stm32/src/low_power.rs @@ -24,7 +24,7 @@ //! use embassy_executor::Spawner; //! use embassy_stm32::low_power::Executor; //! use embassy_stm32::rtc::{Rtc, RtcConfig}; -//! use static_cell::make_static; +//! use static_cell::StaticCell; //! //! #[cortex_m_rt::entry] //! fn main() -> ! { @@ -41,7 +41,8 @@ //! //! // give the RTC to the executor... //! let mut rtc = Rtc::new(p.RTC, RtcConfig::default()); -//! let rtc = make_static!(rtc); +//! static RTC: StaticCell = StaticCell::new(); +//! let rtc = RTC.init(rtc); //! embassy_stm32::low_power::stop_with_rtc(rtc); //! //! // your application here... diff --git a/examples/nrf52840/src/bin/ethernet_enc28j60.rs b/examples/nrf52840/src/bin/ethernet_enc28j60.rs index d1b796fab..840a16556 100644 --- a/examples/nrf52840/src/bin/ethernet_enc28j60.rs +++ b/examples/nrf52840/src/bin/ethernet_enc28j60.rs @@ -14,7 +14,7 @@ use embassy_nrf::{bind_interrupts, peripherals, spim}; use embassy_time::Delay; use embedded_hal_bus::spi::ExclusiveDevice; use embedded_io_async::Write; -use static_cell::make_static; +use static_cell::StaticCell; use {defmt_rtt as _, panic_probe as _}; bind_interrupts!(struct Irqs { @@ -70,11 +70,20 @@ async fn main(spawner: Spawner) { let seed = u64::from_le_bytes(seed); // Init network stack - let stack = &*make_static!(Stack::new( + static RESOURCES: StaticCell> = StaticCell::new(); + static STACK: StaticCell< + Stack< + Enc28j60< + ExclusiveDevice, Output<'static, peripherals::P0_15>, Delay>, + Output<'static, peripherals::P0_13>, + >, + >, + > = StaticCell::new(); + let stack = STACK.init(Stack::new( device, config, - make_static!(StackResources::<2>::new()), - seed + RESOURCES.init(StackResources::<2>::new()), + seed, )); unwrap!(spawner.spawn(net_task(stack))); diff --git a/examples/nrf52840/src/bin/usb_ethernet.rs b/examples/nrf52840/src/bin/usb_ethernet.rs index b7806f418..de661c019 100644 --- a/examples/nrf52840/src/bin/usb_ethernet.rs +++ b/examples/nrf52840/src/bin/usb_ethernet.rs @@ -16,7 +16,7 @@ use embassy_usb::class::cdc_ncm::embassy_net::{Device, Runner, State as NetState use embassy_usb::class::cdc_ncm::{CdcNcmClass, State}; use embassy_usb::{Builder, Config, UsbDevice}; use embedded_io_async::Write; -use static_cell::make_static; +use static_cell::StaticCell; use {defmt_rtt as _, panic_probe as _}; bind_interrupts!(struct Irqs { @@ -71,14 +71,19 @@ async fn main(spawner: Spawner) { config.device_protocol = 0x01; // Create embassy-usb DeviceBuilder using the driver and config. + static DEVICE_DESC: StaticCell<[u8; 256]> = StaticCell::new(); + static CONFIG_DESC: StaticCell<[u8; 256]> = StaticCell::new(); + static BOS_DESC: StaticCell<[u8; 256]> = StaticCell::new(); + static MSOS_DESC: StaticCell<[u8; 128]> = StaticCell::new(); + static CONTROL_BUF: StaticCell<[u8; 128]> = StaticCell::new(); let mut builder = Builder::new( driver, config, - &mut make_static!([0; 256])[..], - &mut make_static!([0; 256])[..], - &mut make_static!([0; 256])[..], - &mut make_static!([0; 128])[..], - &mut make_static!([0; 128])[..], + &mut DEVICE_DESC.init([0; 256])[..], + &mut CONFIG_DESC.init([0; 256])[..], + &mut BOS_DESC.init([0; 256])[..], + &mut MSOS_DESC.init([0; 128])[..], + &mut CONTROL_BUF.init([0; 128])[..], ); // Our MAC addr. @@ -87,14 +92,16 @@ async fn main(spawner: Spawner) { let host_mac_addr = [0x88, 0x88, 0x88, 0x88, 0x88, 0x88]; // Create classes on the builder. - let class = CdcNcmClass::new(&mut builder, make_static!(State::new()), host_mac_addr, 64); + static STATE: StaticCell = StaticCell::new(); + let class = CdcNcmClass::new(&mut builder, STATE.init(State::new()), host_mac_addr, 64); // Build the builder. let usb = builder.build(); unwrap!(spawner.spawn(usb_task(usb))); - let (runner, device) = class.into_embassy_net_device::(make_static!(NetState::new()), our_mac_addr); + static NET_STATE: StaticCell> = StaticCell::new(); + let (runner, device) = class.into_embassy_net_device::(NET_STATE.init(NetState::new()), our_mac_addr); unwrap!(spawner.spawn(usb_ncm_task(runner))); let config = embassy_net::Config::dhcpv4(Default::default()); @@ -111,12 +118,9 @@ async fn main(spawner: Spawner) { let seed = u64::from_le_bytes(seed); // Init network stack - let stack = &*make_static!(Stack::new( - device, - config, - make_static!(StackResources::<2>::new()), - seed - )); + static RESOURCES: StaticCell> = StaticCell::new(); + static STACK: StaticCell>> = StaticCell::new(); + let stack = &*STACK.init(Stack::new(device, config, RESOURCES.init(StackResources::new()), seed)); unwrap!(spawner.spawn(net_task(stack))); diff --git a/examples/nrf52840/src/bin/usb_serial_multitask.rs b/examples/nrf52840/src/bin/usb_serial_multitask.rs index cd4392903..7a7bf962b 100644 --- a/examples/nrf52840/src/bin/usb_serial_multitask.rs +++ b/examples/nrf52840/src/bin/usb_serial_multitask.rs @@ -12,7 +12,7 @@ use embassy_nrf::{bind_interrupts, pac, peripherals, usb}; use embassy_usb::class::cdc_acm::{CdcAcmClass, State}; use embassy_usb::driver::EndpointError; use embassy_usb::{Builder, Config, UsbDevice}; -use static_cell::make_static; +use static_cell::StaticCell; use {defmt_rtt as _, panic_probe as _}; bind_interrupts!(struct Irqs { @@ -64,17 +64,23 @@ async fn main(spawner: Spawner) { config.device_protocol = 0x01; config.composite_with_iads = true; - let state = make_static!(State::new()); + static STATE: StaticCell = StaticCell::new(); + let state = STATE.init(State::new()); // Create embassy-usb DeviceBuilder using the driver and config. + static DEVICE_DESC: StaticCell<[u8; 256]> = StaticCell::new(); + static CONFIG_DESC: StaticCell<[u8; 256]> = StaticCell::new(); + static BOS_DESC: StaticCell<[u8; 256]> = StaticCell::new(); + static MSOS_DESC: StaticCell<[u8; 128]> = StaticCell::new(); + static CONTROL_BUF: StaticCell<[u8; 128]> = StaticCell::new(); let mut builder = Builder::new( driver, config, - &mut make_static!([0; 256])[..], - &mut make_static!([0; 256])[..], - &mut make_static!([0; 256])[..], - &mut make_static!([0; 128])[..], - &mut make_static!([0; 128])[..], + &mut DEVICE_DESC.init([0; 256])[..], + &mut CONFIG_DESC.init([0; 256])[..], + &mut BOS_DESC.init([0; 256])[..], + &mut MSOS_DESC.init([0; 128])[..], + &mut CONTROL_BUF.init([0; 128])[..], ); // Create classes on the builder. diff --git a/examples/nrf52840/src/bin/wifi_esp_hosted.rs b/examples/nrf52840/src/bin/wifi_esp_hosted.rs index a60822fd9..b56c9bd8d 100644 --- a/examples/nrf52840/src/bin/wifi_esp_hosted.rs +++ b/examples/nrf52840/src/bin/wifi_esp_hosted.rs @@ -13,7 +13,7 @@ use embassy_nrf::{bind_interrupts, peripherals}; use embassy_time::Delay; use embedded_hal_bus::spi::ExclusiveDevice; use embedded_io_async::Write; -use static_cell::make_static; +use static_cell::StaticCell; use {defmt_rtt as _, embassy_net_esp_hosted as hosted, panic_probe as _}; const WIFI_NETWORK: &str = "EmbassyTest"; @@ -61,8 +61,9 @@ async fn main(spawner: Spawner) { let spi = spim::Spim::new(p.SPI3, Irqs, sck, miso, mosi, config); let spi = ExclusiveDevice::new(spi, cs, Delay); + static ESP_STATE: StaticCell = StaticCell::new(); let (device, mut control, runner) = embassy_net_esp_hosted::new( - make_static!(embassy_net_esp_hosted::State::new()), + ESP_STATE.init(embassy_net_esp_hosted::State::new()), spi, handshake, ready, @@ -89,11 +90,13 @@ async fn main(spawner: Spawner) { let seed = u64::from_le_bytes(seed); // Init network stack - let stack = &*make_static!(Stack::new( + static RESOURCES: StaticCell> = StaticCell::new(); + static STACK: StaticCell>> = StaticCell::new(); + let stack = &*STACK.init(Stack::new( device, config, - make_static!(StackResources::<2>::new()), - seed + RESOURCES.init(StackResources::<2>::new()), + seed, )); unwrap!(spawner.spawn(net_task(stack))); diff --git a/examples/rp/src/bin/ethernet_w5500_multisocket.rs b/examples/rp/src/bin/ethernet_w5500_multisocket.rs index c0fde62ab..b9dba0f1d 100644 --- a/examples/rp/src/bin/ethernet_w5500_multisocket.rs +++ b/examples/rp/src/bin/ethernet_w5500_multisocket.rs @@ -20,7 +20,7 @@ use embassy_time::{Delay, Duration}; use embedded_hal_bus::spi::ExclusiveDevice; use embedded_io_async::Write; use rand::RngCore; -use static_cell::make_static; +use static_cell::StaticCell; use {defmt_rtt as _, panic_probe as _}; #[embassy_executor::task] @@ -55,7 +55,8 @@ async fn main(spawner: Spawner) { let w5500_reset = Output::new(p.PIN_20, Level::High); let mac_addr = [0x02, 0x00, 0x00, 0x00, 0x00, 0x00]; - let state = make_static!(State::<8, 8>::new()); + static STATE: StaticCell> = StaticCell::new(); + let state = STATE.init(State::<8, 8>::new()); let (device, runner) = embassy_net_wiznet::new( mac_addr, state, @@ -70,11 +71,13 @@ async fn main(spawner: Spawner) { let seed = rng.next_u64(); // Init network stack - let stack = &*make_static!(Stack::new( + static STACK: StaticCell>> = StaticCell::new(); + static RESOURCES: StaticCell> = StaticCell::new(); + let stack = &*STACK.init(Stack::new( device, embassy_net::Config::dhcpv4(Default::default()), - make_static!(StackResources::<3>::new()), - seed + RESOURCES.init(StackResources::<3>::new()), + seed, )); // Launch network task diff --git a/examples/rp/src/bin/ethernet_w5500_tcp_client.rs b/examples/rp/src/bin/ethernet_w5500_tcp_client.rs index b19362fc1..36073f20b 100644 --- a/examples/rp/src/bin/ethernet_w5500_tcp_client.rs +++ b/examples/rp/src/bin/ethernet_w5500_tcp_client.rs @@ -22,7 +22,7 @@ use embassy_time::{Delay, Duration, Timer}; use embedded_hal_bus::spi::ExclusiveDevice; use embedded_io_async::Write; use rand::RngCore; -use static_cell::make_static; +use static_cell::StaticCell; use {defmt_rtt as _, panic_probe as _}; #[embassy_executor::task] @@ -58,7 +58,8 @@ async fn main(spawner: Spawner) { let w5500_reset = Output::new(p.PIN_20, Level::High); let mac_addr = [0x02, 0x00, 0x00, 0x00, 0x00, 0x00]; - let state = make_static!(State::<8, 8>::new()); + static STATE: StaticCell> = StaticCell::new(); + let state = STATE.init(State::<8, 8>::new()); let (device, runner) = embassy_net_wiznet::new( mac_addr, state, @@ -73,11 +74,13 @@ async fn main(spawner: Spawner) { let seed = rng.next_u64(); // Init network stack - let stack = &*make_static!(Stack::new( + static STACK: StaticCell>> = StaticCell::new(); + static RESOURCES: StaticCell> = StaticCell::new(); + let stack = &*STACK.init(Stack::new( device, embassy_net::Config::dhcpv4(Default::default()), - make_static!(StackResources::<2>::new()), - seed + RESOURCES.init(StackResources::<2>::new()), + seed, )); // Launch network task diff --git a/examples/rp/src/bin/ethernet_w5500_tcp_server.rs b/examples/rp/src/bin/ethernet_w5500_tcp_server.rs index c62caed7a..d523a8772 100644 --- a/examples/rp/src/bin/ethernet_w5500_tcp_server.rs +++ b/examples/rp/src/bin/ethernet_w5500_tcp_server.rs @@ -21,7 +21,7 @@ use embassy_time::{Delay, Duration}; use embedded_hal_bus::spi::ExclusiveDevice; use embedded_io_async::Write; use rand::RngCore; -use static_cell::make_static; +use static_cell::StaticCell; use {defmt_rtt as _, panic_probe as _}; #[embassy_executor::task] @@ -57,7 +57,8 @@ async fn main(spawner: Spawner) { let w5500_reset = Output::new(p.PIN_20, Level::High); let mac_addr = [0x02, 0x00, 0x00, 0x00, 0x00, 0x00]; - let state = make_static!(State::<8, 8>::new()); + static STATE: StaticCell> = StaticCell::new(); + let state = STATE.init(State::<8, 8>::new()); let (device, runner) = embassy_net_wiznet::new( mac_addr, state, @@ -72,11 +73,13 @@ async fn main(spawner: Spawner) { let seed = rng.next_u64(); // Init network stack - let stack = &*make_static!(Stack::new( + static STACK: StaticCell>> = StaticCell::new(); + static RESOURCES: StaticCell> = StaticCell::new(); + let stack = &*STACK.init(Stack::new( device, embassy_net::Config::dhcpv4(Default::default()), - make_static!(StackResources::<2>::new()), - seed + RESOURCES.init(StackResources::<2>::new()), + seed, )); // Launch network task diff --git a/examples/rp/src/bin/ethernet_w5500_udp.rs b/examples/rp/src/bin/ethernet_w5500_udp.rs index 76dabce1c..0cc47cb56 100644 --- a/examples/rp/src/bin/ethernet_w5500_udp.rs +++ b/examples/rp/src/bin/ethernet_w5500_udp.rs @@ -20,7 +20,7 @@ use embassy_rp::spi::{Async, Config as SpiConfig, Spi}; use embassy_time::Delay; use embedded_hal_bus::spi::ExclusiveDevice; use rand::RngCore; -use static_cell::make_static; +use static_cell::StaticCell; use {defmt_rtt as _, panic_probe as _}; #[embassy_executor::task] @@ -55,7 +55,8 @@ async fn main(spawner: Spawner) { let w5500_reset = Output::new(p.PIN_20, Level::High); let mac_addr = [0x02, 0x00, 0x00, 0x00, 0x00, 0x00]; - let state = make_static!(State::<8, 8>::new()); + static STATE: StaticCell> = StaticCell::new(); + let state = STATE.init(State::<8, 8>::new()); let (device, runner) = embassy_net_wiznet::new( mac_addr, state, @@ -70,11 +71,13 @@ async fn main(spawner: Spawner) { let seed = rng.next_u64(); // Init network stack - let stack = &*make_static!(Stack::new( + static STACK: StaticCell>> = StaticCell::new(); + static RESOURCES: StaticCell> = StaticCell::new(); + let stack = &*STACK.init(Stack::new( device, embassy_net::Config::dhcpv4(Default::default()), - make_static!(StackResources::<2>::new()), - seed + RESOURCES.init(StackResources::<2>::new()), + seed, )); // Launch network task diff --git a/examples/rp/src/bin/uart_buffered_split.rs b/examples/rp/src/bin/uart_buffered_split.rs index 14e8810a4..dc57d89c7 100644 --- a/examples/rp/src/bin/uart_buffered_split.rs +++ b/examples/rp/src/bin/uart_buffered_split.rs @@ -15,7 +15,7 @@ use embassy_rp::peripherals::UART0; use embassy_rp::uart::{BufferedInterruptHandler, BufferedUart, BufferedUartRx, Config}; use embassy_time::Timer; use embedded_io_async::{Read, Write}; -use static_cell::make_static; +use static_cell::StaticCell; use {defmt_rtt as _, panic_probe as _}; bind_interrupts!(struct Irqs { @@ -27,8 +27,10 @@ async fn main(spawner: Spawner) { let p = embassy_rp::init(Default::default()); let (tx_pin, rx_pin, uart) = (p.PIN_0, p.PIN_1, p.UART0); - let tx_buf = &mut make_static!([0u8; 16])[..]; - let rx_buf = &mut make_static!([0u8; 16])[..]; + static TX_BUF: StaticCell<[u8; 16]> = StaticCell::new(); + let tx_buf = &mut TX_BUF.init([0; 16])[..]; + static RX_BUF: StaticCell<[u8; 16]> = StaticCell::new(); + let rx_buf = &mut RX_BUF.init([0; 16])[..]; let uart = BufferedUart::new(uart, Irqs, tx_pin, rx_pin, tx_buf, rx_buf, Config::default()); let (rx, mut tx) = uart.split(); diff --git a/examples/rp/src/bin/usb_ethernet.rs b/examples/rp/src/bin/usb_ethernet.rs index cc63029fb..674b83f5d 100644 --- a/examples/rp/src/bin/usb_ethernet.rs +++ b/examples/rp/src/bin/usb_ethernet.rs @@ -17,7 +17,7 @@ use embassy_usb::class::cdc_ncm::embassy_net::{Device, Runner, State as NetState use embassy_usb::class::cdc_ncm::{CdcNcmClass, State}; use embassy_usb::{Builder, Config, UsbDevice}; use embedded_io_async::Write; -use static_cell::make_static; +use static_cell::StaticCell; use {defmt_rtt as _, panic_probe as _}; bind_interrupts!(struct Irqs { @@ -65,14 +65,18 @@ async fn main(spawner: Spawner) { config.device_protocol = 0x01; // Create embassy-usb DeviceBuilder using the driver and config. + static DEVICE_DESC: StaticCell<[u8; 256]> = StaticCell::new(); + static CONFIG_DESC: StaticCell<[u8; 256]> = StaticCell::new(); + static BOS_DESC: StaticCell<[u8; 256]> = StaticCell::new(); + static CONTROL_BUF: StaticCell<[u8; 128]> = StaticCell::new(); let mut builder = Builder::new( driver, config, - &mut make_static!([0; 256])[..], - &mut make_static!([0; 256])[..], - &mut make_static!([0; 256])[..], + &mut DEVICE_DESC.init([0; 256])[..], + &mut CONFIG_DESC.init([0; 256])[..], + &mut BOS_DESC.init([0; 256])[..], &mut [], // no msos descriptors - &mut make_static!([0; 128])[..], + &mut CONTROL_BUF.init([0; 128])[..], ); // Our MAC addr. @@ -81,14 +85,16 @@ async fn main(spawner: Spawner) { let host_mac_addr = [0x88, 0x88, 0x88, 0x88, 0x88, 0x88]; // Create classes on the builder. - let class = CdcNcmClass::new(&mut builder, make_static!(State::new()), host_mac_addr, 64); + static STATE: StaticCell = StaticCell::new(); + let class = CdcNcmClass::new(&mut builder, STATE.init(State::new()), host_mac_addr, 64); // Build the builder. let usb = builder.build(); unwrap!(spawner.spawn(usb_task(usb))); - let (runner, device) = class.into_embassy_net_device::(make_static!(NetState::new()), our_mac_addr); + static NET_STATE: StaticCell> = StaticCell::new(); + let (runner, device) = class.into_embassy_net_device::(NET_STATE.init(NetState::new()), our_mac_addr); unwrap!(spawner.spawn(usb_ncm_task(runner))); let config = embassy_net::Config::dhcpv4(Default::default()); @@ -102,11 +108,13 @@ async fn main(spawner: Spawner) { let seed = 1234; // guaranteed random, chosen by a fair dice roll // Init network stack - let stack = &*make_static!(Stack::new( + static STACK: StaticCell>> = StaticCell::new(); + static RESOURCES: StaticCell> = StaticCell::new(); + let stack = &*STACK.init(Stack::new( device, config, - make_static!(StackResources::<2>::new()), - seed + RESOURCES.init(StackResources::<2>::new()), + seed, )); unwrap!(spawner.spawn(net_task(stack))); diff --git a/examples/rp/src/bin/wifi_ap_tcp_server.rs b/examples/rp/src/bin/wifi_ap_tcp_server.rs index ad1fa6462..20b8aad15 100644 --- a/examples/rp/src/bin/wifi_ap_tcp_server.rs +++ b/examples/rp/src/bin/wifi_ap_tcp_server.rs @@ -19,7 +19,7 @@ use embassy_rp::peripherals::{DMA_CH0, PIN_23, PIN_25, PIO0}; use embassy_rp::pio::{InterruptHandler, Pio}; use embassy_time::Duration; use embedded_io_async::Write; -use static_cell::make_static; +use static_cell::StaticCell; use {defmt_rtt as _, panic_probe as _}; bind_interrupts!(struct Irqs { @@ -59,7 +59,8 @@ async fn main(spawner: Spawner) { let mut pio = Pio::new(p.PIO0, Irqs); let spi = PioSpi::new(&mut pio.common, pio.sm0, pio.irq0, cs, p.PIN_24, p.PIN_29, p.DMA_CH0); - let state = make_static!(cyw43::State::new()); + static STATE: StaticCell = StaticCell::new(); + let state = STATE.init(cyw43::State::new()); let (net_device, mut control, runner) = cyw43::new(state, pwr, spi, fw).await; unwrap!(spawner.spawn(wifi_task(runner))); @@ -79,11 +80,13 @@ async fn main(spawner: Spawner) { let seed = 0x0123_4567_89ab_cdef; // chosen by fair dice roll. guarenteed to be random. // Init network stack - let stack = &*make_static!(Stack::new( + static STACK: StaticCell>> = StaticCell::new(); + static RESOURCES: StaticCell> = StaticCell::new(); + let stack = &*STACK.init(Stack::new( net_device, config, - make_static!(StackResources::<2>::new()), - seed + RESOURCES.init(StackResources::<2>::new()), + seed, )); unwrap!(spawner.spawn(net_task(stack))); diff --git a/examples/rp/src/bin/wifi_blinky.rs b/examples/rp/src/bin/wifi_blinky.rs index 14ace74e9..b89447b7d 100644 --- a/examples/rp/src/bin/wifi_blinky.rs +++ b/examples/rp/src/bin/wifi_blinky.rs @@ -14,7 +14,7 @@ use embassy_rp::gpio::{Level, Output}; use embassy_rp::peripherals::{DMA_CH0, PIN_23, PIN_25, PIO0}; use embassy_rp::pio::{InterruptHandler, Pio}; use embassy_time::{Duration, Timer}; -use static_cell::make_static; +use static_cell::StaticCell; use {defmt_rtt as _, panic_probe as _}; bind_interrupts!(struct Irqs { @@ -46,7 +46,8 @@ async fn main(spawner: Spawner) { let mut pio = Pio::new(p.PIO0, Irqs); let spi = PioSpi::new(&mut pio.common, pio.sm0, pio.irq0, cs, p.PIN_24, p.PIN_29, p.DMA_CH0); - let state = make_static!(cyw43::State::new()); + static STATE: StaticCell = StaticCell::new(); + let state = STATE.init(cyw43::State::new()); let (_net_device, mut control, runner) = cyw43::new(state, pwr, spi, fw).await; unwrap!(spawner.spawn(wifi_task(runner))); diff --git a/examples/rp/src/bin/wifi_scan.rs b/examples/rp/src/bin/wifi_scan.rs index 7adf52b88..0f7ad27dd 100644 --- a/examples/rp/src/bin/wifi_scan.rs +++ b/examples/rp/src/bin/wifi_scan.rs @@ -16,7 +16,7 @@ use embassy_rp::bind_interrupts; use embassy_rp::gpio::{Level, Output}; use embassy_rp::peripherals::{DMA_CH0, PIN_23, PIN_25, PIO0}; use embassy_rp::pio::{InterruptHandler, Pio}; -use static_cell::make_static; +use static_cell::StaticCell; use {defmt_rtt as _, panic_probe as _}; bind_interrupts!(struct Irqs { @@ -56,7 +56,8 @@ async fn main(spawner: Spawner) { let mut pio = Pio::new(p.PIO0, Irqs); let spi = PioSpi::new(&mut pio.common, pio.sm0, pio.irq0, cs, p.PIN_24, p.PIN_29, p.DMA_CH0); - let state = make_static!(cyw43::State::new()); + static STATE: StaticCell = StaticCell::new(); + let state = STATE.init(cyw43::State::new()); let (_net_device, mut control, runner) = cyw43::new(state, pwr, spi, fw).await; unwrap!(spawner.spawn(wifi_task(runner))); diff --git a/examples/rp/src/bin/wifi_tcp_server.rs b/examples/rp/src/bin/wifi_tcp_server.rs index ec6b4ee74..f6cc48d8f 100644 --- a/examples/rp/src/bin/wifi_tcp_server.rs +++ b/examples/rp/src/bin/wifi_tcp_server.rs @@ -19,7 +19,7 @@ use embassy_rp::peripherals::{DMA_CH0, PIN_23, PIN_25, PIO0}; use embassy_rp::pio::{InterruptHandler, Pio}; use embassy_time::{Duration, Timer}; use embedded_io_async::Write; -use static_cell::make_static; +use static_cell::StaticCell; use {defmt_rtt as _, panic_probe as _}; bind_interrupts!(struct Irqs { @@ -62,7 +62,8 @@ async fn main(spawner: Spawner) { let mut pio = Pio::new(p.PIO0, Irqs); let spi = PioSpi::new(&mut pio.common, pio.sm0, pio.irq0, cs, p.PIN_24, p.PIN_29, p.DMA_CH0); - let state = make_static!(cyw43::State::new()); + static STATE: StaticCell = StaticCell::new(); + let state = STATE.init(cyw43::State::new()); let (net_device, mut control, runner) = cyw43::new(state, pwr, spi, fw).await; unwrap!(spawner.spawn(wifi_task(runner))); @@ -82,11 +83,13 @@ async fn main(spawner: Spawner) { let seed = 0x0123_4567_89ab_cdef; // chosen by fair dice roll. guarenteed to be random. // Init network stack - let stack = &*make_static!(Stack::new( + static STACK: StaticCell>> = StaticCell::new(); + static RESOURCES: StaticCell> = StaticCell::new(); + let stack = &*STACK.init(Stack::new( net_device, config, - make_static!(StackResources::<2>::new()), - seed + RESOURCES.init(StackResources::<2>::new()), + seed, )); unwrap!(spawner.spawn(net_task(stack))); diff --git a/examples/std/src/bin/net.rs b/examples/std/src/bin/net.rs index 8d8345057..c62a38d07 100644 --- a/examples/std/src/bin/net.rs +++ b/examples/std/src/bin/net.rs @@ -12,7 +12,7 @@ use embedded_io_async::Write; use heapless::Vec; use log::*; use rand_core::{OsRng, RngCore}; -use static_cell::{make_static, StaticCell}; +use static_cell::StaticCell; #[derive(Parser)] #[clap(version = "1.0")] @@ -54,11 +54,13 @@ async fn main_task(spawner: Spawner) { let seed = u64::from_le_bytes(seed); // Init network stack - let stack = &*make_static!(Stack::new( + static STACK: StaticCell> = StaticCell::new(); + static RESOURCES: StaticCell> = StaticCell::new(); + let stack = &*STACK.init(Stack::new( device, config, - make_static!(StackResources::<3>::new()), - seed + RESOURCES.init(StackResources::<3>::new()), + seed, )); // Launch network task diff --git a/examples/std/src/bin/net_dns.rs b/examples/std/src/bin/net_dns.rs index 6c19874d5..e1e015bc8 100644 --- a/examples/std/src/bin/net_dns.rs +++ b/examples/std/src/bin/net_dns.rs @@ -10,7 +10,7 @@ use embassy_net_tuntap::TunTapDevice; use heapless::Vec; use log::*; use rand_core::{OsRng, RngCore}; -use static_cell::{make_static, StaticCell}; +use static_cell::StaticCell; #[derive(Parser)] #[clap(version = "1.0")] @@ -53,11 +53,13 @@ async fn main_task(spawner: Spawner) { let seed = u64::from_le_bytes(seed); // Init network stack - let stack: &Stack<_> = &*make_static!(Stack::new( + static STACK: StaticCell> = StaticCell::new(); + static RESOURCES: StaticCell> = StaticCell::new(); + let stack: &Stack<_> = &*STACK.init(Stack::new( device, config, - make_static!(StackResources::<3>::new()), - seed + RESOURCES.init(StackResources::<3>::new()), + seed, )); // Launch network task diff --git a/examples/std/src/bin/net_ppp.rs b/examples/std/src/bin/net_ppp.rs index cee04e558..8c80c4beb 100644 --- a/examples/std/src/bin/net_ppp.rs +++ b/examples/std/src/bin/net_ppp.rs @@ -25,7 +25,7 @@ use heapless::Vec; use log::*; use nix::sys::termios; use rand_core::{OsRng, RngCore}; -use static_cell::{make_static, StaticCell}; +use static_cell::StaticCell; use crate::serial_port::SerialPort; @@ -88,7 +88,8 @@ async fn main_task(spawner: Spawner) { let port = SerialPort::new(opts.device.as_str(), baudrate).unwrap(); // Init network device - let state = make_static!(embassy_net_ppp::State::<4, 4>::new()); + static STATE: StaticCell> = StaticCell::new(); + let state = STATE.init(embassy_net_ppp::State::<4, 4>::new()); let (device, runner) = embassy_net_ppp::new(state); // Generate random seed @@ -97,11 +98,13 @@ async fn main_task(spawner: Spawner) { let seed = u64::from_le_bytes(seed); // Init network stack - let stack = &*make_static!(Stack::new( + static STACK: StaticCell>> = StaticCell::new(); + static RESOURCES: StaticCell> = StaticCell::new(); + let stack = &*STACK.init(Stack::new( device, Config::default(), // don't configure IP yet - make_static!(StackResources::<3>::new()), - seed + RESOURCES.init(StackResources::<3>::new()), + seed, )); // Launch network task diff --git a/examples/std/src/bin/net_udp.rs b/examples/std/src/bin/net_udp.rs index 98dcc9925..ac99ec626 100644 --- a/examples/std/src/bin/net_udp.rs +++ b/examples/std/src/bin/net_udp.rs @@ -8,7 +8,7 @@ use embassy_net_tuntap::TunTapDevice; use heapless::Vec; use log::*; use rand_core::{OsRng, RngCore}; -use static_cell::{make_static, StaticCell}; +use static_cell::StaticCell; #[derive(Parser)] #[clap(version = "1.0")] @@ -50,11 +50,13 @@ async fn main_task(spawner: Spawner) { let seed = u64::from_le_bytes(seed); // Init network stack - let stack = &*make_static!(Stack::new( + static STACK: StaticCell> = StaticCell::new(); + static RESOURCES: StaticCell> = StaticCell::new(); + let stack = &*STACK.init(Stack::new( device, config, - make_static!(StackResources::<3>::new()), - seed + RESOURCES.init(StackResources::<3>::new()), + seed, )); // Launch network task diff --git a/examples/std/src/bin/tcp_accept.rs b/examples/std/src/bin/tcp_accept.rs index 79fa375cd..54ef0156b 100644 --- a/examples/std/src/bin/tcp_accept.rs +++ b/examples/std/src/bin/tcp_accept.rs @@ -13,7 +13,7 @@ use embedded_io_async::Write as _; use heapless::Vec; use log::*; use rand_core::{OsRng, RngCore}; -use static_cell::{make_static, StaticCell}; +use static_cell::StaticCell; #[derive(Parser)] #[clap(version = "1.0")] @@ -65,11 +65,13 @@ async fn main_task(spawner: Spawner) { let seed = u64::from_le_bytes(seed); // Init network stack - let stack = &*make_static!(Stack::new( + static STACK: StaticCell> = StaticCell::new(); + static RESOURCES: StaticCell> = StaticCell::new(); + let stack = &*STACK.init(Stack::new( device, config, - make_static!(StackResources::<3>::new()), - seed + RESOURCES.init(StackResources::<3>::new()), + seed, )); // Launch network task diff --git a/examples/stm32f4/src/bin/eth.rs b/examples/stm32f4/src/bin/eth.rs index 088d83c06..17a14aac4 100644 --- a/examples/stm32f4/src/bin/eth.rs +++ b/examples/stm32f4/src/bin/eth.rs @@ -14,7 +14,7 @@ use embassy_stm32::time::Hertz; use embassy_stm32::{bind_interrupts, eth, peripherals, rng, Config}; use embassy_time::Timer; use embedded_io_async::Write; -use static_cell::make_static; +use static_cell::StaticCell; use {defmt_rtt as _, panic_probe as _}; bind_interrupts!(struct Irqs { @@ -63,8 +63,9 @@ async fn main(spawner: Spawner) -> ! { let mac_addr = [0x00, 0x00, 0xDE, 0xAD, 0xBE, 0xEF]; + static PACKETS: StaticCell> = StaticCell::new(); let device = Ethernet::new( - make_static!(PacketQueue::<16, 16>::new()), + PACKETS.init(PacketQueue::<16, 16>::new()), p.ETH, Irqs, p.PA1, @@ -88,11 +89,13 @@ async fn main(spawner: Spawner) -> ! { //}); // Init network stack - let stack = &*make_static!(Stack::new( + static STACK: StaticCell> = StaticCell::new(); + static RESOURCES: StaticCell> = StaticCell::new(); + let stack = &*STACK.init(Stack::new( device, config, - make_static!(StackResources::<2>::new()), - seed + RESOURCES.init(StackResources::<2>::new()), + seed, )); // Launch network task diff --git a/examples/stm32f4/src/bin/usb_ethernet.rs b/examples/stm32f4/src/bin/usb_ethernet.rs index 6bf5b1cba..57ee35e97 100644 --- a/examples/stm32f4/src/bin/usb_ethernet.rs +++ b/examples/stm32f4/src/bin/usb_ethernet.rs @@ -14,7 +14,7 @@ use embassy_usb::class::cdc_ncm::embassy_net::{Device, Runner, State as NetState use embassy_usb::class::cdc_ncm::{CdcNcmClass, State}; use embassy_usb::{Builder, UsbDevice}; use embedded_io_async::Write; -use static_cell::make_static; +use static_cell::StaticCell; use {defmt_rtt as _, panic_probe as _}; type UsbDriver = Driver<'static, embassy_stm32::peripherals::USB_OTG_FS>; @@ -68,7 +68,8 @@ async fn main(spawner: Spawner) { let p = embassy_stm32::init(config); // Create the driver, from the HAL. - let ep_out_buffer = &mut make_static!([0; 256])[..]; + static OUTPUT_BUFFER: StaticCell<[u8; 256]> = StaticCell::new(); + let ep_out_buffer = &mut OUTPUT_BUFFER.init([0; 256])[..]; let mut config = embassy_stm32::usb_otg::Config::default(); config.vbus_detection = true; let driver = Driver::new_fs(p.USB_OTG_FS, Irqs, p.PA12, p.PA11, ep_out_buffer, config); @@ -88,14 +89,18 @@ async fn main(spawner: Spawner) { config.device_protocol = 0x01; // Create embassy-usb DeviceBuilder using the driver and config. + static DEVICE_DESC: StaticCell<[u8; 256]> = StaticCell::new(); + static CONFIG_DESC: StaticCell<[u8; 256]> = StaticCell::new(); + static BOS_DESC: StaticCell<[u8; 256]> = StaticCell::new(); + static CONTROL_BUF: StaticCell<[u8; 128]> = StaticCell::new(); let mut builder = Builder::new( driver, config, - &mut make_static!([0; 256])[..], - &mut make_static!([0; 256])[..], - &mut make_static!([0; 256])[..], + &mut DEVICE_DESC.init([0; 256])[..], + &mut CONFIG_DESC.init([0; 256])[..], + &mut BOS_DESC.init([0; 256])[..], &mut [], // no msos descriptors - &mut make_static!([0; 128])[..], + &mut CONTROL_BUF.init([0; 128])[..], ); // Our MAC addr. @@ -104,14 +109,16 @@ async fn main(spawner: Spawner) { let host_mac_addr = [0x88, 0x88, 0x88, 0x88, 0x88, 0x88]; // Create classes on the builder. - let class = CdcNcmClass::new(&mut builder, make_static!(State::new()), host_mac_addr, 64); + static STATE: StaticCell = StaticCell::new(); + let class = CdcNcmClass::new(&mut builder, STATE.init(State::new()), host_mac_addr, 64); // Build the builder. let usb = builder.build(); unwrap!(spawner.spawn(usb_task(usb))); - let (runner, device) = class.into_embassy_net_device::(make_static!(NetState::new()), our_mac_addr); + static NET_STATE: StaticCell> = StaticCell::new(); + let (runner, device) = class.into_embassy_net_device::(NET_STATE.init(NetState::new()), our_mac_addr); unwrap!(spawner.spawn(usb_ncm_task(runner))); let config = embassy_net::Config::dhcpv4(Default::default()); @@ -128,11 +135,13 @@ async fn main(spawner: Spawner) { let seed = u64::from_le_bytes(seed); // Init network stack - let stack = &*make_static!(Stack::new( + static STACK: StaticCell>> = StaticCell::new(); + static RESOURCES: StaticCell> = StaticCell::new(); + let stack = &*STACK.init(Stack::new( device, config, - make_static!(StackResources::<2>::new()), - seed + RESOURCES.init(StackResources::<2>::new()), + seed, )); unwrap!(spawner.spawn(net_task(stack))); diff --git a/examples/stm32f7/src/bin/can.rs b/examples/stm32f7/src/bin/can.rs index 78b21ceaa..06cd1ac7e 100644 --- a/examples/stm32f7/src/bin/can.rs +++ b/examples/stm32f7/src/bin/can.rs @@ -12,6 +12,7 @@ use embassy_stm32::can::{ }; use embassy_stm32::gpio::{Input, Pull}; use embassy_stm32::peripherals::CAN3; +use static_cell::StaticCell; use {defmt_rtt as _, panic_probe as _}; bind_interrupts!(struct Irqs { @@ -43,7 +44,8 @@ async fn main(spawner: Spawner) { let rx_pin = Input::new(&mut p.PA15, Pull::Up); core::mem::forget(rx_pin); - let can: &'static mut Can<'static, CAN3> = static_cell::make_static!(Can::new(p.CAN3, p.PA8, p.PA15, Irqs)); + static CAN: StaticCell> = StaticCell::new(); + let can = CAN.init(Can::new(p.CAN3, p.PA8, p.PA15, Irqs)); can.as_mut() .modify_filters() .enable_bank(0, Fifo::Fifo0, Mask32::accept_all()); @@ -56,7 +58,8 @@ async fn main(spawner: Spawner) { let (tx, mut rx) = can.split(); - let tx: &'static mut CanTx<'static, 'static, CAN3> = static_cell::make_static!(tx); + static CAN_TX: StaticCell> = StaticCell::new(); + let tx = CAN_TX.init(tx); spawner.spawn(send_can_message(tx)).unwrap(); loop { diff --git a/examples/stm32f7/src/bin/eth.rs b/examples/stm32f7/src/bin/eth.rs index dd0069447..86c709852 100644 --- a/examples/stm32f7/src/bin/eth.rs +++ b/examples/stm32f7/src/bin/eth.rs @@ -15,7 +15,7 @@ use embassy_stm32::{bind_interrupts, eth, peripherals, rng, Config}; use embassy_time::Timer; use embedded_io_async::Write; use rand_core::RngCore; -use static_cell::make_static; +use static_cell::StaticCell; use {defmt_rtt as _, panic_probe as _}; bind_interrupts!(struct Irqs { @@ -64,8 +64,9 @@ async fn main(spawner: Spawner) -> ! { let mac_addr = [0x00, 0x00, 0xDE, 0xAD, 0xBE, 0xEF]; + static PACKETS: StaticCell> = StaticCell::new(); let device = Ethernet::new( - make_static!(PacketQueue::<16, 16>::new()), + PACKETS.init(PacketQueue::<16, 16>::new()), p.ETH, Irqs, p.PA1, @@ -89,11 +90,13 @@ async fn main(spawner: Spawner) -> ! { //}); // Init network stack - let stack = &*make_static!(Stack::new( + static STACK: StaticCell> = StaticCell::new(); + static RESOURCES: StaticCell> = StaticCell::new(); + let stack = &*STACK.init(Stack::new( device, config, - make_static!(StackResources::<2>::new()), - seed + RESOURCES.init(StackResources::<2>::new()), + seed, )); // Launch network task diff --git a/examples/stm32h5/src/bin/eth.rs b/examples/stm32h5/src/bin/eth.rs index b2758cba0..8789e4e0b 100644 --- a/examples/stm32h5/src/bin/eth.rs +++ b/examples/stm32h5/src/bin/eth.rs @@ -18,7 +18,7 @@ use embassy_stm32::{bind_interrupts, eth, peripherals, rng, Config}; use embassy_time::Timer; use embedded_io_async::Write; use rand_core::RngCore; -use static_cell::make_static; +use static_cell::StaticCell; use {defmt_rtt as _, panic_probe as _}; bind_interrupts!(struct Irqs { @@ -67,8 +67,9 @@ async fn main(spawner: Spawner) -> ! { let mac_addr = [0x00, 0x00, 0xDE, 0xAD, 0xBE, 0xEF]; + static PACKETS: StaticCell> = StaticCell::new(); let device = Ethernet::new( - make_static!(PacketQueue::<4, 4>::new()), + PACKETS.init(PacketQueue::<4, 4>::new()), p.ETH, Irqs, p.PA1, @@ -92,11 +93,13 @@ async fn main(spawner: Spawner) -> ! { //}); // Init network stack - let stack = &*make_static!(Stack::new( + static STACK: StaticCell> = StaticCell::new(); + static RESOURCES: StaticCell> = StaticCell::new(); + let stack = &*STACK.init(Stack::new( device, config, - make_static!(StackResources::<2>::new()), - seed + RESOURCES.init(StackResources::<2>::new()), + seed, )); // Launch network task diff --git a/examples/stm32h7/src/bin/eth.rs b/examples/stm32h7/src/bin/eth.rs index dbddfc22f..a64b3253a 100644 --- a/examples/stm32h7/src/bin/eth.rs +++ b/examples/stm32h7/src/bin/eth.rs @@ -14,7 +14,7 @@ use embassy_stm32::{bind_interrupts, eth, peripherals, rng, Config}; use embassy_time::Timer; use embedded_io_async::Write; use rand_core::RngCore; -use static_cell::make_static; +use static_cell::StaticCell; use {defmt_rtt as _, panic_probe as _}; bind_interrupts!(struct Irqs { @@ -64,8 +64,9 @@ async fn main(spawner: Spawner) -> ! { let mac_addr = [0x00, 0x00, 0xDE, 0xAD, 0xBE, 0xEF]; + static PACKETS: StaticCell> = StaticCell::new(); let device = Ethernet::new( - make_static!(PacketQueue::<16, 16>::new()), + PACKETS.init(PacketQueue::<4, 4>::new()), p.ETH, Irqs, p.PA1, @@ -89,11 +90,13 @@ async fn main(spawner: Spawner) -> ! { //}); // Init network stack - let stack = &*make_static!(Stack::new( + static STACK: StaticCell> = StaticCell::new(); + static RESOURCES: StaticCell> = StaticCell::new(); + let stack = &*STACK.init(Stack::new( device, config, - make_static!(StackResources::<3>::new()), - seed + RESOURCES.init(StackResources::<3>::new()), + seed, )); // Launch network task diff --git a/examples/stm32h7/src/bin/eth_client.rs b/examples/stm32h7/src/bin/eth_client.rs index 17e1d9fb7..8e84d9964 100644 --- a/examples/stm32h7/src/bin/eth_client.rs +++ b/examples/stm32h7/src/bin/eth_client.rs @@ -15,7 +15,7 @@ use embassy_time::Timer; use embedded_io_async::Write; use embedded_nal_async::{Ipv4Addr, SocketAddr, SocketAddrV4, TcpConnect}; use rand_core::RngCore; -use static_cell::make_static; +use static_cell::StaticCell; use {defmt_rtt as _, panic_probe as _}; bind_interrupts!(struct Irqs { @@ -65,8 +65,9 @@ async fn main(spawner: Spawner) -> ! { let mac_addr = [0x00, 0x00, 0xDE, 0xAD, 0xBE, 0xEF]; + static PACKETS: StaticCell> = StaticCell::new(); let device = Ethernet::new( - make_static!(PacketQueue::<16, 16>::new()), + PACKETS.init(PacketQueue::<16, 16>::new()), p.ETH, Irqs, p.PA1, @@ -90,11 +91,13 @@ async fn main(spawner: Spawner) -> ! { //}); // Init network stack - let stack = &*make_static!(Stack::new( + static STACK: StaticCell> = StaticCell::new(); + static RESOURCES: StaticCell> = StaticCell::new(); + let stack = &*STACK.init(Stack::new( device, config, - make_static!(StackResources::<3>::new()), - seed + RESOURCES.init(StackResources::<3>::new()), + seed, )); // Launch network task diff --git a/examples/stm32l4/src/bin/spe_adin1110_http_server.rs b/examples/stm32l4/src/bin/spe_adin1110_http_server.rs index 8ec810c7f..eb04fe5e6 100644 --- a/examples/stm32l4/src/bin/spe_adin1110_http_server.rs +++ b/examples/stm32l4/src/bin/spe_adin1110_http_server.rs @@ -36,7 +36,7 @@ use hal::rng::{self, Rng}; use hal::{bind_interrupts, exti, pac, peripherals}; use heapless::Vec; use rand::RngCore; -use static_cell::make_static; +use static_cell::StaticCell; use {embassy_stm32 as hal, panic_probe as _}; bind_interrupts!(struct Irqs { @@ -180,7 +180,8 @@ async fn main(spawner: Spawner) { } }; - let state = make_static!(embassy_net_adin1110::State::<8, 8>::new()); + static STATE: StaticCell> = StaticCell::new(); + let state = STATE.init(embassy_net_adin1110::State::<8, 8>::new()); let (device, runner) = embassy_net_adin1110::new( MAC, @@ -217,11 +218,13 @@ async fn main(spawner: Spawner) { }; // Init network stack - let stack = &*make_static!(Stack::new( + static STACK: StaticCell>> = StaticCell::new(); + static RESOURCES: StaticCell> = StaticCell::new(); + let stack = &*STACK.init(Stack::new( device, ip_cfg, - make_static!(StackResources::<2>::new()), - seed + RESOURCES.init(StackResources::<2>::new()), + seed, )); // Launch network task diff --git a/examples/stm32l5/src/bin/usb_ethernet.rs b/examples/stm32l5/src/bin/usb_ethernet.rs index 0b0a0e2db..214235bd5 100644 --- a/examples/stm32l5/src/bin/usb_ethernet.rs +++ b/examples/stm32l5/src/bin/usb_ethernet.rs @@ -15,7 +15,7 @@ use embassy_usb::class::cdc_ncm::{CdcNcmClass, State}; use embassy_usb::{Builder, UsbDevice}; use embedded_io_async::Write; use rand_core::RngCore; -use static_cell::make_static; +use static_cell::StaticCell; use {defmt_rtt as _, panic_probe as _}; type MyDriver = Driver<'static, embassy_stm32::peripherals::USB>; @@ -76,14 +76,18 @@ async fn main(spawner: Spawner) { config.device_protocol = 0x01; // Create embassy-usb DeviceBuilder using the driver and config. + static DEVICE_DESC: StaticCell<[u8; 256]> = StaticCell::new(); + static CONFIG_DESC: StaticCell<[u8; 256]> = StaticCell::new(); + static BOS_DESC: StaticCell<[u8; 256]> = StaticCell::new(); + static CONTROL_BUF: StaticCell<[u8; 128]> = StaticCell::new(); let mut builder = Builder::new( driver, config, - &mut make_static!([0; 256])[..], - &mut make_static!([0; 256])[..], - &mut make_static!([0; 256])[..], + &mut DEVICE_DESC.init([0; 256])[..], + &mut CONFIG_DESC.init([0; 256])[..], + &mut BOS_DESC.init([0; 256])[..], &mut [], // no msos descriptors - &mut make_static!([0; 128])[..], + &mut CONTROL_BUF.init([0; 128])[..], ); // Our MAC addr. @@ -92,14 +96,16 @@ async fn main(spawner: Spawner) { let host_mac_addr = [0x88, 0x88, 0x88, 0x88, 0x88, 0x88]; // Create classes on the builder. - let class = CdcNcmClass::new(&mut builder, make_static!(State::new()), host_mac_addr, 64); + static STATE: StaticCell = StaticCell::new(); + let class = CdcNcmClass::new(&mut builder, STATE.init(State::new()), host_mac_addr, 64); // Build the builder. let usb = builder.build(); unwrap!(spawner.spawn(usb_task(usb))); - let (runner, device) = class.into_embassy_net_device::(make_static!(NetState::new()), our_mac_addr); + static NET_STATE: StaticCell> = StaticCell::new(); + let (runner, device) = class.into_embassy_net_device::(NET_STATE.init(NetState::new()), our_mac_addr); unwrap!(spawner.spawn(usb_ncm_task(runner))); let config = embassy_net::Config::dhcpv4(Default::default()); @@ -114,11 +120,13 @@ async fn main(spawner: Spawner) { let seed = rng.next_u64(); // Init network stack - let stack = &*make_static!(Stack::new( + static STACK: StaticCell>> = StaticCell::new(); + static RESOURCES: StaticCell> = StaticCell::new(); + let stack = &*STACK.init(Stack::new( device, config, - make_static!(StackResources::<2>::new()), - seed + RESOURCES.init(StackResources::<2>::new()), + seed, )); unwrap!(spawner.spawn(net_task(stack))); diff --git a/examples/stm32wb/src/bin/mac_ffd_net.rs b/examples/stm32wb/src/bin/mac_ffd_net.rs index f8c76b5a4..454530c03 100644 --- a/examples/stm32wb/src/bin/mac_ffd_net.rs +++ b/examples/stm32wb/src/bin/mac_ffd_net.rs @@ -12,7 +12,7 @@ use embassy_stm32_wpan::mac::typedefs::{MacChannel, PanId, PibId}; use embassy_stm32_wpan::mac::{self, Runner}; use embassy_stm32_wpan::sub::mm; use embassy_stm32_wpan::TlMbox; -use static_cell::make_static; +use static_cell::StaticCell; use {defmt_rtt as _, panic_probe as _}; bind_interrupts!(struct Irqs{ @@ -154,15 +154,21 @@ async fn main(spawner: Spawner) { .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 = [ - make_static!([0u8; 127]), - make_static!([0u8; 127]), - make_static!([0u8; 127]), - make_static!([0u8; 127]), - make_static!([0u8; 127]), + TX1.init([0u8; 127]), + TX2.init([0u8; 127]), + TX3.init([0u8; 127]), + TX4.init([0u8; 127]), + TX5.init([0u8; 127]), ]; - let runner = make_static!(Runner::new(mbox.mac_subsystem, tx_queue)); + static RUNNER: StaticCell = StaticCell::new(); + let runner = RUNNER.init(Runner::new(mbox.mac_subsystem, tx_queue)); spawner.spawn(run_mac(runner)).unwrap(); diff --git a/tests/nrf/src/bin/ethernet_enc28j60_perf.rs b/tests/nrf/src/bin/ethernet_enc28j60_perf.rs index 60d30a2ff..c26c0d066 100644 --- a/tests/nrf/src/bin/ethernet_enc28j60_perf.rs +++ b/tests/nrf/src/bin/ethernet_enc28j60_perf.rs @@ -14,7 +14,7 @@ use embassy_nrf::spim::{self, Spim}; use embassy_nrf::{bind_interrupts, peripherals}; use embassy_time::Delay; use embedded_hal_bus::spi::ExclusiveDevice; -use static_cell::make_static; +use static_cell::StaticCell; use {defmt_rtt as _, panic_probe as _}; bind_interrupts!(struct Irqs { @@ -68,11 +68,13 @@ async fn main(spawner: Spawner) { let seed = u64::from_le_bytes(seed); // Init network stack - let stack = &*make_static!(Stack::new( + static STACK: StaticCell> = StaticCell::new(); + static RESOURCES: StaticCell> = StaticCell::new(); + let stack = &*STACK.init(Stack::new( device, config, - make_static!(StackResources::<2>::new()), - seed + RESOURCES.init(StackResources::<2>::new()), + seed, )); unwrap!(spawner.spawn(net_task(stack))); diff --git a/tests/nrf/src/bin/wifi_esp_hosted_perf.rs b/tests/nrf/src/bin/wifi_esp_hosted_perf.rs index 9eee39ccf..5b43b75d7 100644 --- a/tests/nrf/src/bin/wifi_esp_hosted_perf.rs +++ b/tests/nrf/src/bin/wifi_esp_hosted_perf.rs @@ -13,7 +13,7 @@ use embassy_nrf::spim::{self, Spim}; use embassy_nrf::{bind_interrupts, peripherals}; use embassy_time::Delay; use embedded_hal_bus::spi::ExclusiveDevice; -use static_cell::make_static; +use static_cell::StaticCell; use {defmt_rtt as _, embassy_net_esp_hosted as hosted, panic_probe as _}; bind_interrupts!(struct Irqs { @@ -64,8 +64,9 @@ async fn main(spawner: Spawner) { let spi = spim::Spim::new(p.SPI3, Irqs, sck, miso, mosi, config); let spi = ExclusiveDevice::new(spi, cs, Delay); + static STATE: StaticCell = StaticCell::new(); let (device, mut control, runner) = embassy_net_esp_hosted::new( - make_static!(embassy_net_esp_hosted::State::new()), + STATE.init(embassy_net_esp_hosted::State::new()), spi, handshake, ready, @@ -85,11 +86,13 @@ async fn main(spawner: Spawner) { let seed = u64::from_le_bytes(seed); // Init network stack - let stack = &*make_static!(Stack::new( + static STACK: StaticCell> = StaticCell::new(); + static RESOURCES: StaticCell> = StaticCell::new(); + let stack = &*STACK.init(Stack::new( device, Config::dhcpv4(Default::default()), - make_static!(StackResources::<2>::new()), - seed + RESOURCES.init(StackResources::<2>::new()), + seed, )); unwrap!(spawner.spawn(net_task(stack))); diff --git a/tests/rp/src/bin/cyw43-perf.rs b/tests/rp/src/bin/cyw43-perf.rs index de29c06dd..d70ef8ef3 100644 --- a/tests/rp/src/bin/cyw43-perf.rs +++ b/tests/rp/src/bin/cyw43-perf.rs @@ -11,7 +11,7 @@ use embassy_rp::gpio::{Level, Output}; use embassy_rp::peripherals::{DMA_CH0, PIN_23, PIN_25, PIO0}; use embassy_rp::pio::{InterruptHandler, Pio}; use embassy_rp::{bind_interrupts, rom_data}; -use static_cell::make_static; +use static_cell::StaticCell; use {defmt_rtt as _, panic_probe as _}; bind_interrupts!(struct Irqs { @@ -58,7 +58,8 @@ async fn main(spawner: Spawner) { let mut pio = Pio::new(p.PIO0, Irqs); let spi = PioSpi::new(&mut pio.common, pio.sm0, pio.irq0, cs, p.PIN_24, p.PIN_29, p.DMA_CH0); - let state = make_static!(cyw43::State::new()); + static STATE: StaticCell = StaticCell::new(); + let state = STATE.init(cyw43::State::new()); let (net_device, mut control, runner) = cyw43::new(state, pwr, spi, fw).await; unwrap!(spawner.spawn(wifi_task(runner))); @@ -71,11 +72,13 @@ async fn main(spawner: Spawner) { let seed = 0x0123_4567_89ab_cdef; // chosen by fair dice roll. guarenteed to be random. // Init network stack - let stack = &*make_static!(Stack::new( + static STACK: StaticCell>> = StaticCell::new(); + static RESOURCES: StaticCell> = StaticCell::new(); + let stack = &*STACK.init(Stack::new( net_device, Config::dhcpv4(Default::default()), - make_static!(StackResources::<2>::new()), - seed + RESOURCES.init(StackResources::<2>::new()), + seed, )); unwrap!(spawner.spawn(net_task(stack))); diff --git a/tests/rp/src/bin/ethernet_w5100s_perf.rs b/tests/rp/src/bin/ethernet_w5100s_perf.rs index a4d253b3c..5588b6427 100644 --- a/tests/rp/src/bin/ethernet_w5100s_perf.rs +++ b/tests/rp/src/bin/ethernet_w5100s_perf.rs @@ -16,7 +16,7 @@ use embassy_rp::spi::{Async, Config as SpiConfig, Spi}; use embassy_time::Delay; use embedded_hal_bus::spi::ExclusiveDevice; use rand::RngCore; -use static_cell::make_static; +use static_cell::StaticCell; use {defmt_rtt as _, panic_probe as _}; #[embassy_executor::task] @@ -51,7 +51,8 @@ async fn main(spawner: Spawner) { let w5500_reset = Output::new(p.PIN_20, Level::High); let mac_addr = [0x02, 0x00, 0x00, 0x00, 0x00, 0x00]; - let state = make_static!(State::<8, 8>::new()); + static STATE: StaticCell> = StaticCell::new(); + let state = STATE.init(State::<8, 8>::new()); let (device, runner) = embassy_net_wiznet::new( mac_addr, state, @@ -66,11 +67,13 @@ async fn main(spawner: Spawner) { let seed = rng.next_u64(); // Init network stack - let stack = &*make_static!(Stack::new( + static STACK: StaticCell>> = StaticCell::new(); + static RESOURCES: StaticCell> = StaticCell::new(); + let stack = &*STACK.init(Stack::new( device, embassy_net::Config::dhcpv4(Default::default()), - make_static!(StackResources::<2>::new()), - seed + RESOURCES.init(StackResources::<2>::new()), + seed, )); // Launch network task diff --git a/tests/stm32/src/bin/eth.rs b/tests/stm32/src/bin/eth.rs index 754354944..c01f33a97 100644 --- a/tests/stm32/src/bin/eth.rs +++ b/tests/stm32/src/bin/eth.rs @@ -14,7 +14,7 @@ use embassy_stm32::peripherals::ETH; use embassy_stm32::rng::Rng; use embassy_stm32::{bind_interrupts, eth, peripherals, rng}; use rand_core::RngCore; -use static_cell::make_static; +use static_cell::StaticCell; use {defmt_rtt as _, panic_probe as _}; teleprobe_meta::timeout!(120); @@ -71,8 +71,9 @@ async fn main(spawner: Spawner) { #[cfg(not(feature = "stm32f207zg"))] const PACKET_QUEUE_SIZE: usize = 4; + static PACKETS: StaticCell> = StaticCell::new(); let device = Ethernet::new( - make_static!(PacketQueue::::new()), + PACKETS.init(PacketQueue::::new()), p.ETH, Irqs, p.PA1, @@ -99,11 +100,13 @@ async fn main(spawner: Spawner) { //}); // Init network stack - let stack = &*make_static!(Stack::new( + static STACK: StaticCell> = StaticCell::new(); + static RESOURCES: StaticCell> = StaticCell::new(); + let stack = &*STACK.init(Stack::new( device, config, - make_static!(StackResources::<2>::new()), - seed + RESOURCES.init(StackResources::<2>::new()), + seed, )); // Launch network task diff --git a/tests/stm32/src/bin/stop.rs b/tests/stm32/src/bin/stop.rs index b9810673a..f8e3c43d7 100644 --- a/tests/stm32/src/bin/stop.rs +++ b/tests/stm32/src/bin/stop.rs @@ -15,7 +15,7 @@ use embassy_stm32::rcc::LsConfig; use embassy_stm32::rtc::{Rtc, RtcConfig}; use embassy_stm32::Config; use embassy_time::Timer; -use static_cell::make_static; +use static_cell::StaticCell; #[entry] fn main() -> ! { @@ -64,7 +64,8 @@ async fn async_main(spawner: Spawner) { rtc.set_datetime(now.into()).expect("datetime not set"); - let rtc = make_static!(rtc); + static RTC: StaticCell = StaticCell::new(); + let rtc = RTC.init(rtc); stop_with_rtc(rtc); From cf0e5e32add134aefb8ffc1bfac9f49f48bdc9c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1niel=20Buga?= Date: Thu, 21 Dec 2023 14:22:56 +0100 Subject: [PATCH 094/124] Remove Xtensa specifier --- docs/modules/ROOT/pages/faq.adoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/modules/ROOT/pages/faq.adoc b/docs/modules/ROOT/pages/faq.adoc index d1a012978..1fe9bde37 100644 --- a/docs/modules/ROOT/pages/faq.adoc +++ b/docs/modules/ROOT/pages/faq.adoc @@ -35,7 +35,7 @@ For Cortex-M targets, consider making sure that ALL of the following features ar * `executor-thread` * `nightly` -For Xtensa ESP32, consider using the executors and `#[main]` macro provided by your appropriate link:https://crates.io/crates/esp-hal-common[HAL crate]. +For ESP32, consider using the executors and `#[main]` macro provided by your appropriate link:https://crates.io/crates/esp-hal-common[HAL crate]. == Why is my binary so big? From 8b36a32ed5d834b23e970d5b723dd7df1f1c94a2 Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Thu, 21 Dec 2023 14:57:49 +0100 Subject: [PATCH 095/124] ci: use beta, add secondary nightly ci. --- .../ci/{build-stable.sh => build-nightly.sh} | 5 +- .github/ci/rustfmt.sh | 12 +++ .github/ci/test-nightly.sh | 13 ++++ .github/ci/test.sh | 3 - .vscode/settings.json | 8 +- ci-nightly.sh | 30 ++++++++ ci.sh | 37 ++++----- ci_stable.sh | 77 ------------------- docs/modules/ROOT/examples/basic/src/main.rs | 1 - .../layer-by-layer/blinky-async/Cargo.toml | 2 +- .../layer-by-layer/blinky-async/src/main.rs | 1 - embassy-executor/Cargo.toml | 4 +- embassy-rp/Cargo.toml | 2 +- embassy-rp/src/lib.rs | 1 - embassy-rp/src/multicore.rs | 1 - embassy-stm32-wpan/Cargo.toml | 2 +- embassy-time/src/timer.rs | 7 -- examples/boot/application/nrf/Cargo.toml | 2 +- examples/boot/application/nrf/src/bin/a.rs | 1 - examples/boot/application/nrf/src/bin/b.rs | 1 - examples/boot/application/rp/Cargo.toml | 2 +- examples/boot/application/rp/src/bin/a.rs | 1 - examples/boot/application/rp/src/bin/b.rs | 1 - examples/boot/application/stm32f3/Cargo.toml | 2 +- .../boot/application/stm32f3/src/bin/a.rs | 1 - .../boot/application/stm32f3/src/bin/b.rs | 1 - examples/boot/application/stm32f7/Cargo.toml | 2 +- .../boot/application/stm32f7/src/bin/a.rs | 1 - .../boot/application/stm32f7/src/bin/b.rs | 1 - examples/boot/application/stm32h7/Cargo.toml | 2 +- .../boot/application/stm32h7/src/bin/a.rs | 1 - .../boot/application/stm32h7/src/bin/b.rs | 1 - examples/boot/application/stm32l0/Cargo.toml | 2 +- .../boot/application/stm32l0/src/bin/a.rs | 1 - .../boot/application/stm32l0/src/bin/b.rs | 1 - examples/boot/application/stm32l1/Cargo.toml | 2 +- .../boot/application/stm32l1/src/bin/a.rs | 1 - .../boot/application/stm32l1/src/bin/b.rs | 1 - examples/boot/application/stm32l4/Cargo.toml | 2 +- .../boot/application/stm32l4/src/bin/a.rs | 1 - .../boot/application/stm32l4/src/bin/b.rs | 1 - .../boot/application/stm32wb-dfu/Cargo.toml | 2 +- .../boot/application/stm32wb-dfu/src/main.rs | 1 - examples/boot/application/stm32wl/Cargo.toml | 2 +- .../boot/application/stm32wl/src/bin/a.rs | 1 - .../boot/application/stm32wl/src/bin/b.rs | 1 - examples/nrf-rtos-trace/src/bin/rtos_trace.rs | 1 - examples/nrf52840/Cargo.toml | 6 -- examples/nrf52840/src/bin/blinky.rs | 1 - examples/nrf52840/src/bin/buffered_uart.rs | 1 - examples/nrf52840/src/bin/channel.rs | 1 - .../src/bin/channel_sender_receiver.rs | 1 - .../nrf52840/src/bin/ethernet_enc28j60.rs | 1 - .../src/bin/executor_fairness_test.rs | 1 - examples/nrf52840/src/bin/gpiote_channel.rs | 1 - examples/nrf52840/src/bin/gpiote_port.rs | 1 - examples/nrf52840/src/bin/i2s_effect.rs | 1 - examples/nrf52840/src/bin/i2s_monitor.rs | 1 - examples/nrf52840/src/bin/i2s_waveform.rs | 1 - .../src/bin/manually_create_executor.rs | 1 - examples/nrf52840/src/bin/multiprio.rs | 1 - examples/nrf52840/src/bin/mutex.rs | 1 - examples/nrf52840/src/bin/nvmc.rs | 1 - examples/nrf52840/src/bin/pdm.rs | 1 - examples/nrf52840/src/bin/pdm_continuous.rs | 1 - examples/nrf52840/src/bin/ppi.rs | 1 - examples/nrf52840/src/bin/pubsub.rs | 1 - examples/nrf52840/src/bin/pwm.rs | 1 - .../nrf52840/src/bin/pwm_double_sequence.rs | 1 - examples/nrf52840/src/bin/pwm_sequence.rs | 1 - examples/nrf52840/src/bin/pwm_sequence_ppi.rs | 1 - .../nrf52840/src/bin/pwm_sequence_ws2812b.rs | 1 - examples/nrf52840/src/bin/pwm_servo.rs | 1 - examples/nrf52840/src/bin/qdec.rs | 1 - examples/nrf52840/src/bin/qspi.rs | 1 - examples/nrf52840/src/bin/qspi_lowpower.rs | 1 - examples/nrf52840/src/bin/rng.rs | 1 - examples/nrf52840/src/bin/saadc.rs | 1 - examples/nrf52840/src/bin/saadc_continuous.rs | 1 - examples/nrf52840/src/bin/self_spawn.rs | 1 - .../src/bin/self_spawn_current_executor.rs | 1 - examples/nrf52840/src/bin/spim.rs | 1 - examples/nrf52840/src/bin/spis.rs | 1 - examples/nrf52840/src/bin/temp.rs | 1 - examples/nrf52840/src/bin/timer.rs | 1 - examples/nrf52840/src/bin/twim.rs | 1 - examples/nrf52840/src/bin/twim_lowpower.rs | 1 - examples/nrf52840/src/bin/twis.rs | 1 - examples/nrf52840/src/bin/uart.rs | 1 - examples/nrf52840/src/bin/uart_idle.rs | 1 - examples/nrf52840/src/bin/uart_split.rs | 1 - examples/nrf52840/src/bin/usb_ethernet.rs | 1 - examples/nrf52840/src/bin/usb_hid_keyboard.rs | 1 - examples/nrf52840/src/bin/usb_hid_mouse.rs | 1 - examples/nrf52840/src/bin/usb_serial.rs | 1 - .../nrf52840/src/bin/usb_serial_multitask.rs | 1 - .../nrf52840/src/bin/usb_serial_winusb.rs | 1 - examples/nrf52840/src/bin/wdt.rs | 1 - examples/nrf52840/src/bin/wifi_esp_hosted.rs | 1 - examples/nrf5340/Cargo.toml | 4 +- examples/nrf5340/src/bin/blinky.rs | 1 - examples/nrf5340/src/bin/gpiote_channel.rs | 1 - examples/nrf5340/src/bin/uart.rs | 1 - examples/rp/Cargo.toml | 4 +- examples/rp/src/bin/adc.rs | 1 - examples/rp/src/bin/blinky.rs | 1 - examples/rp/src/bin/button.rs | 1 - .../rp/src/bin/ethernet_w5500_multisocket.rs | 1 - .../rp/src/bin/ethernet_w5500_tcp_client.rs | 1 - .../rp/src/bin/ethernet_w5500_tcp_server.rs | 1 - examples/rp/src/bin/ethernet_w5500_udp.rs | 1 - examples/rp/src/bin/flash.rs | 1 - examples/rp/src/bin/gpio_async.rs | 1 - examples/rp/src/bin/gpout.rs | 1 - examples/rp/src/bin/i2c_async.rs | 1 - examples/rp/src/bin/i2c_blocking.rs | 1 - examples/rp/src/bin/i2c_slave.rs | 1 - examples/rp/src/bin/multicore.rs | 1 - examples/rp/src/bin/multiprio.rs | 1 - examples/rp/src/bin/pio_async.rs | 1 - examples/rp/src/bin/pio_dma.rs | 1 - examples/rp/src/bin/pio_hd44780.rs | 1 - examples/rp/src/bin/pio_rotary_encoder.rs | 1 - examples/rp/src/bin/pio_stepper.rs | 1 - examples/rp/src/bin/pio_uart.rs | 1 - examples/rp/src/bin/pio_ws2812.rs | 1 - examples/rp/src/bin/pwm.rs | 1 - examples/rp/src/bin/pwm_input.rs | 1 - examples/rp/src/bin/rosc.rs | 1 - examples/rp/src/bin/rtc.rs | 1 - examples/rp/src/bin/spi.rs | 1 - examples/rp/src/bin/spi_async.rs | 1 - examples/rp/src/bin/spi_display.rs | 1 - examples/rp/src/bin/uart.rs | 1 - examples/rp/src/bin/uart_buffered_split.rs | 1 - examples/rp/src/bin/uart_unidir.rs | 1 - examples/rp/src/bin/usb_ethernet.rs | 1 - examples/rp/src/bin/usb_hid_keyboard.rs | 1 - examples/rp/src/bin/usb_logger.rs | 1 - examples/rp/src/bin/usb_midi.rs | 1 - examples/rp/src/bin/usb_raw.rs | 1 - examples/rp/src/bin/usb_raw_bulk.rs | 1 - examples/rp/src/bin/usb_serial.rs | 1 - examples/rp/src/bin/watchdog.rs | 1 - examples/rp/src/bin/wifi_ap_tcp_server.rs | 1 - examples/rp/src/bin/wifi_blinky.rs | 1 - examples/rp/src/bin/wifi_scan.rs | 1 - examples/rp/src/bin/wifi_tcp_server.rs | 1 - examples/std/Cargo.toml | 4 +- examples/std/src/bin/net.rs | 2 - examples/std/src/bin/net_dns.rs | 2 - examples/std/src/bin/net_ppp.rs | 1 - examples/std/src/bin/net_udp.rs | 2 - examples/std/src/bin/serial.rs | 2 - examples/std/src/bin/tcp_accept.rs | 2 - examples/std/src/bin/tick.rs | 2 - examples/stm32c0/Cargo.toml | 2 +- examples/stm32c0/src/bin/blinky.rs | 1 - examples/stm32c0/src/bin/button.rs | 1 - examples/stm32c0/src/bin/button_exti.rs | 1 - examples/stm32f0/Cargo.toml | 4 +- examples/stm32f0/src/bin/adc.rs | 1 - examples/stm32f0/src/bin/blinky.rs | 1 - .../src/bin/button_controlled_blink.rs | 1 - examples/stm32f0/src/bin/button_exti.rs | 1 - examples/stm32f0/src/bin/hello.rs | 1 - examples/stm32f0/src/bin/multiprio.rs | 1 - examples/stm32f0/src/bin/wdg.rs | 1 - examples/stm32f1/Cargo.toml | 2 +- examples/stm32f1/src/bin/adc.rs | 1 - examples/stm32f1/src/bin/blinky.rs | 1 - examples/stm32f1/src/bin/can.rs | 1 - examples/stm32f1/src/bin/hello.rs | 1 - examples/stm32f1/src/bin/usb_serial.rs | 1 - examples/stm32f2/Cargo.toml | 2 +- examples/stm32f2/src/bin/blinky.rs | 1 - examples/stm32f2/src/bin/pll.rs | 1 - examples/stm32f3/Cargo.toml | 4 +- examples/stm32f3/src/bin/blinky.rs | 1 - examples/stm32f3/src/bin/button.rs | 1 - examples/stm32f3/src/bin/button_events.rs | 1 - examples/stm32f3/src/bin/button_exti.rs | 1 - examples/stm32f3/src/bin/flash.rs | 1 - examples/stm32f3/src/bin/hello.rs | 1 - examples/stm32f3/src/bin/multiprio.rs | 1 - examples/stm32f3/src/bin/spi_dma.rs | 1 - examples/stm32f3/src/bin/usart_dma.rs | 1 - examples/stm32f3/src/bin/usb_serial.rs | 1 - examples/stm32f334/Cargo.toml | 4 +- examples/stm32f334/src/bin/adc.rs | 1 - examples/stm32f334/src/bin/button.rs | 1 - examples/stm32f334/src/bin/hello.rs | 1 - examples/stm32f334/src/bin/opamp.rs | 1 - examples/stm32f334/src/bin/pwm.rs | 1 - examples/stm32f4/Cargo.toml | 4 +- examples/stm32f4/src/bin/adc.rs | 1 - examples/stm32f4/src/bin/blinky.rs | 1 - examples/stm32f4/src/bin/button.rs | 1 - examples/stm32f4/src/bin/button_exti.rs | 1 - examples/stm32f4/src/bin/can.rs | 1 - examples/stm32f4/src/bin/dac.rs | 1 - examples/stm32f4/src/bin/eth.rs | 1 - examples/stm32f4/src/bin/flash.rs | 1 - examples/stm32f4/src/bin/flash_async.rs | 1 - examples/stm32f4/src/bin/hello.rs | 1 - examples/stm32f4/src/bin/i2c.rs | 1 - examples/stm32f4/src/bin/i2c_async.rs | 1 - examples/stm32f4/src/bin/i2c_comparison.rs | 1 - examples/stm32f4/src/bin/i2s_dma.rs | 1 - examples/stm32f4/src/bin/mco.rs | 1 - examples/stm32f4/src/bin/multiprio.rs | 1 - examples/stm32f4/src/bin/pwm.rs | 1 - examples/stm32f4/src/bin/pwm_complementary.rs | 1 - examples/stm32f4/src/bin/rtc.rs | 1 - examples/stm32f4/src/bin/sdmmc.rs | 1 - examples/stm32f4/src/bin/spi.rs | 1 - examples/stm32f4/src/bin/spi_dma.rs | 1 - examples/stm32f4/src/bin/usart.rs | 1 - examples/stm32f4/src/bin/usart_buffered.rs | 1 - examples/stm32f4/src/bin/usart_dma.rs | 1 - examples/stm32f4/src/bin/usb_ethernet.rs | 1 - examples/stm32f4/src/bin/usb_raw.rs | 1 - examples/stm32f4/src/bin/usb_serial.rs | 1 - examples/stm32f4/src/bin/wdt.rs | 1 - examples/stm32f4/src/bin/ws2812_pwm_dma.rs | 1 - examples/stm32f7/Cargo.toml | 4 +- examples/stm32f7/src/bin/adc.rs | 1 - examples/stm32f7/src/bin/blinky.rs | 1 - examples/stm32f7/src/bin/button.rs | 1 - examples/stm32f7/src/bin/button_exti.rs | 1 - examples/stm32f7/src/bin/can.rs | 1 - examples/stm32f7/src/bin/eth.rs | 1 - examples/stm32f7/src/bin/flash.rs | 1 - examples/stm32f7/src/bin/hello.rs | 1 - examples/stm32f7/src/bin/sdmmc.rs | 1 - examples/stm32f7/src/bin/usart_dma.rs | 1 - examples/stm32f7/src/bin/usb_serial.rs | 1 - examples/stm32g0/Cargo.toml | 2 +- examples/stm32g0/src/bin/blinky.rs | 1 - examples/stm32g0/src/bin/button.rs | 1 - examples/stm32g0/src/bin/button_exti.rs | 1 - examples/stm32g0/src/bin/flash.rs | 1 - examples/stm32g0/src/bin/spi_neopixel.rs | 1 - examples/stm32g4/Cargo.toml | 2 +- examples/stm32g4/src/bin/adc.rs | 1 - examples/stm32g4/src/bin/blinky.rs | 1 - examples/stm32g4/src/bin/button.rs | 1 - examples/stm32g4/src/bin/button_exti.rs | 1 - examples/stm32g4/src/bin/pll.rs | 1 - examples/stm32g4/src/bin/pwm.rs | 1 - examples/stm32g4/src/bin/usb_serial.rs | 1 - examples/stm32h5/Cargo.toml | 4 +- examples/stm32h5/src/bin/blinky.rs | 1 - examples/stm32h5/src/bin/button_exti.rs | 1 - examples/stm32h5/src/bin/eth.rs | 1 - examples/stm32h5/src/bin/i2c.rs | 1 - examples/stm32h5/src/bin/rng.rs | 1 - examples/stm32h5/src/bin/usart.rs | 1 - examples/stm32h5/src/bin/usart_dma.rs | 1 - examples/stm32h5/src/bin/usart_split.rs | 1 - examples/stm32h5/src/bin/usb_serial.rs | 1 - examples/stm32h7/Cargo.toml | 4 +- examples/stm32h7/src/bin/adc.rs | 1 - examples/stm32h7/src/bin/blinky.rs | 1 - examples/stm32h7/src/bin/button_exti.rs | 1 - examples/stm32h7/src/bin/camera.rs | 1 - examples/stm32h7/src/bin/dac.rs | 1 - examples/stm32h7/src/bin/dac_dma.rs | 1 - examples/stm32h7/src/bin/eth.rs | 1 - examples/stm32h7/src/bin/eth_client.rs | 1 - examples/stm32h7/src/bin/flash.rs | 1 - examples/stm32h7/src/bin/fmc.rs | 1 - examples/stm32h7/src/bin/i2c.rs | 1 - .../stm32h7/src/bin/low_level_timer_api.rs | 1 - examples/stm32h7/src/bin/mco.rs | 1 - examples/stm32h7/src/bin/pwm.rs | 1 - examples/stm32h7/src/bin/rng.rs | 1 - examples/stm32h7/src/bin/rtc.rs | 1 - examples/stm32h7/src/bin/sdmmc.rs | 1 - examples/stm32h7/src/bin/signal.rs | 1 - examples/stm32h7/src/bin/spi.rs | 1 - examples/stm32h7/src/bin/spi_dma.rs | 1 - examples/stm32h7/src/bin/usart.rs | 1 - examples/stm32h7/src/bin/usart_dma.rs | 1 - examples/stm32h7/src/bin/usart_split.rs | 1 - examples/stm32h7/src/bin/usb_serial.rs | 1 - examples/stm32h7/src/bin/wdg.rs | 1 - examples/stm32l0/Cargo.toml | 4 - examples/stm32l0/src/bin/blinky.rs | 1 - examples/stm32l0/src/bin/button.rs | 1 - examples/stm32l0/src/bin/button_exti.rs | 1 - examples/stm32l0/src/bin/flash.rs | 1 - examples/stm32l0/src/bin/spi.rs | 1 - examples/stm32l0/src/bin/usart_dma.rs | 1 - examples/stm32l0/src/bin/usart_irq.rs | 1 - examples/stm32l1/Cargo.toml | 2 +- examples/stm32l1/src/bin/blinky.rs | 1 - examples/stm32l1/src/bin/flash.rs | 1 - examples/stm32l1/src/bin/spi.rs | 1 - examples/stm32l4/Cargo.toml | 4 +- examples/stm32l4/src/bin/adc.rs | 1 - examples/stm32l4/src/bin/blinky.rs | 1 - examples/stm32l4/src/bin/button.rs | 1 - examples/stm32l4/src/bin/button_exti.rs | 1 - examples/stm32l4/src/bin/dac.rs | 1 - examples/stm32l4/src/bin/dac_dma.rs | 1 - examples/stm32l4/src/bin/i2c.rs | 1 - .../stm32l4/src/bin/i2c_blocking_async.rs | 1 - examples/stm32l4/src/bin/i2c_dma.rs | 1 - examples/stm32l4/src/bin/mco.rs | 1 - examples/stm32l4/src/bin/rng.rs | 1 - examples/stm32l4/src/bin/rtc.rs | 1 - .../src/bin/spe_adin1110_http_server.rs | 7 +- examples/stm32l4/src/bin/spi.rs | 1 - .../stm32l4/src/bin/spi_blocking_async.rs | 1 - examples/stm32l4/src/bin/spi_dma.rs | 1 - examples/stm32l4/src/bin/usart.rs | 1 - examples/stm32l4/src/bin/usart_dma.rs | 1 - examples/stm32l4/src/bin/usb_serial.rs | 1 - examples/stm32l5/Cargo.toml | 4 +- examples/stm32l5/src/bin/button_exti.rs | 1 - examples/stm32l5/src/bin/rng.rs | 1 - examples/stm32l5/src/bin/usb_ethernet.rs | 1 - examples/stm32l5/src/bin/usb_hid_mouse.rs | 1 - examples/stm32l5/src/bin/usb_serial.rs | 1 - examples/stm32u5/Cargo.toml | 2 +- examples/stm32u5/src/bin/blinky.rs | 1 - examples/stm32u5/src/bin/boot.rs | 1 - examples/stm32u5/src/bin/usb_serial.rs | 1 - examples/stm32wb/Cargo.toml | 4 +- examples/stm32wb/src/bin/blinky.rs | 1 - examples/stm32wb/src/bin/button_exti.rs | 1 - examples/stm32wb/src/bin/eddystone_beacon.rs | 1 - examples/stm32wb/src/bin/gatt_server.rs | 1 - examples/stm32wb/src/bin/mac_ffd.rs | 1 - examples/stm32wb/src/bin/mac_ffd_net.rs | 1 - examples/stm32wb/src/bin/mac_rfd.rs | 1 - examples/stm32wb/src/bin/tl_mbox.rs | 1 - examples/stm32wb/src/bin/tl_mbox_ble.rs | 1 - examples/stm32wb/src/bin/tl_mbox_mac.rs | 1 - examples/stm32wba/Cargo.toml | 4 +- examples/stm32wba/src/bin/blinky.rs | 1 - examples/stm32wba/src/bin/button_exti.rs | 1 - examples/stm32wl/Cargo.toml | 2 +- examples/stm32wl/src/bin/blinky.rs | 1 - examples/stm32wl/src/bin/button.rs | 1 - examples/stm32wl/src/bin/button_exti.rs | 1 - examples/stm32wl/src/bin/flash.rs | 1 - examples/stm32wl/src/bin/random.rs | 1 - examples/stm32wl/src/bin/rtc.rs | 1 - examples/stm32wl/src/bin/uart_async.rs | 1 - examples/wasm/Cargo.toml | 2 +- examples/wasm/src/lib.rs | 2 - rust-toolchain-nightly.toml | 12 +++ rust-toolchain.toml | 8 +- tests/nrf/Cargo.toml | 2 +- tests/nrf/src/bin/ethernet_enc28j60_perf.rs | 1 - tests/nrf/src/bin/wifi_esp_hosted_perf.rs | 1 - tests/rp/Cargo.toml | 2 +- tests/rp/src/bin/cyw43-perf.rs | 1 - tests/rp/src/bin/ethernet_w5100s_perf.rs | 1 - tests/stm32/Cargo.toml | 2 +- tests/stm32/src/bin/eth.rs | 1 - tests/stm32/src/bin/stop.rs | 1 - 364 files changed, 148 insertions(+), 508 deletions(-) rename .github/ci/{build-stable.sh => build-nightly.sh} (90%) create mode 100755 .github/ci/rustfmt.sh create mode 100755 .github/ci/test-nightly.sh create mode 100755 ci-nightly.sh delete mode 100755 ci_stable.sh create mode 100644 rust-toolchain-nightly.toml diff --git a/.github/ci/build-stable.sh b/.github/ci/build-nightly.sh similarity index 90% rename from .github/ci/build-stable.sh rename to .github/ci/build-nightly.sh index e0bd77867..95cb4100c 100755 --- a/.github/ci/build-stable.sh +++ b/.github/ci/build-nightly.sh @@ -7,6 +7,7 @@ set -euo pipefail export RUSTUP_HOME=/ci/cache/rustup export CARGO_HOME=/ci/cache/cargo export CARGO_TARGET_DIR=/ci/cache/target +mv rust-toolchain-nightly.toml rust-toolchain.toml # needed for "dumb HTTP" transport support # used when pointing stm32-metapac to a CI-built one. @@ -21,9 +22,7 @@ fi hashtime restore /ci/cache/filetime.json || true hashtime save /ci/cache/filetime.json -sed -i 's/channel.*/channel = "beta"/g' rust-toolchain.toml - -./ci_stable.sh +./ci-nightly.sh # Save lockfiles echo Saving lockfiles... diff --git a/.github/ci/rustfmt.sh b/.github/ci/rustfmt.sh new file mode 100755 index 000000000..369239cfe --- /dev/null +++ b/.github/ci/rustfmt.sh @@ -0,0 +1,12 @@ +#!/bin/bash +## on push branch~=gh-readonly-queue/main/.* +## on pull_request + +set -euo pipefail + +export RUSTUP_HOME=/ci/cache/rustup +export CARGO_HOME=/ci/cache/cargo +export CARGO_TARGET_DIR=/ci/cache/target +mv rust-toolchain-nightly.toml rust-toolchain.toml + +find . -name '*.rs' -not -path '*target*' | xargs rustfmt --check --skip-children --unstable-features --edition 2021 diff --git a/.github/ci/test-nightly.sh b/.github/ci/test-nightly.sh new file mode 100755 index 000000000..d6e5dc574 --- /dev/null +++ b/.github/ci/test-nightly.sh @@ -0,0 +1,13 @@ +#!/bin/bash +## on push branch~=gh-readonly-queue/main/.* +## on pull_request + +set -euo pipefail + +export RUSTUP_HOME=/ci/cache/rustup +export CARGO_HOME=/ci/cache/cargo +export CARGO_TARGET_DIR=/ci/cache/target +mv rust-toolchain-nightly.toml rust-toolchain.toml + +MIRIFLAGS=-Zmiri-ignore-leaks cargo miri test --manifest-path ./embassy-executor/Cargo.toml +MIRIFLAGS=-Zmiri-ignore-leaks cargo miri test --manifest-path ./embassy-executor/Cargo.toml --features nightly diff --git a/.github/ci/test.sh b/.github/ci/test.sh index 0ec65d2a1..369f6d221 100755 --- a/.github/ci/test.sh +++ b/.github/ci/test.sh @@ -8,9 +8,6 @@ export RUSTUP_HOME=/ci/cache/rustup export CARGO_HOME=/ci/cache/cargo export CARGO_TARGET_DIR=/ci/cache/target -MIRIFLAGS=-Zmiri-ignore-leaks cargo miri test --manifest-path ./embassy-executor/Cargo.toml -MIRIFLAGS=-Zmiri-ignore-leaks cargo miri test --manifest-path ./embassy-executor/Cargo.toml --features nightly - cargo test --manifest-path ./embassy-sync/Cargo.toml cargo test --manifest-path ./embassy-embedded-hal/Cargo.toml cargo test --manifest-path ./embassy-hal-internal/Cargo.toml diff --git a/.vscode/settings.json b/.vscode/settings.json index d46ce603b..a5b23175a 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -15,14 +15,10 @@ //"rust-analyzer.cargo.target": "thumbv7m-none-eabi", "rust-analyzer.cargo.target": "thumbv7em-none-eabi", //"rust-analyzer.cargo.target": "thumbv8m.main-none-eabihf", - "rust-analyzer.cargo.features": [ - // Uncomment if the example has a "nightly" feature. - "nightly", - ], "rust-analyzer.linkedProjects": [ // Uncomment ONE line for the chip you want to work on. // This makes rust-analyzer work on the example crate and all its dependencies. - "examples/nrf52840/Cargo.toml", + "examples/stm32l4/Cargo.toml", // "examples/nrf52840-rtic/Cargo.toml", // "examples/nrf5340/Cargo.toml", // "examples/nrf-rtos-trace/Cargo.toml", @@ -49,4 +45,4 @@ // "examples/stm32wl/Cargo.toml", // "examples/wasm/Cargo.toml", ], -} \ No newline at end of file +} diff --git a/ci-nightly.sh b/ci-nightly.sh new file mode 100755 index 000000000..1fc9692b5 --- /dev/null +++ b/ci-nightly.sh @@ -0,0 +1,30 @@ +#!/bin/bash + +set -eo pipefail + +export RUSTFLAGS=-Dwarnings +export DEFMT_LOG=trace,embassy_hal_internal=debug,embassy_net_esp_hosted=debug,cyw43=info,cyw43_pio=info,smoltcp=info +if [[ -z "${CARGO_TARGET_DIR}" ]]; then + export CARGO_TARGET_DIR=target_ci +fi + +cargo batch \ + --- build --release --manifest-path embassy-executor/Cargo.toml --target thumbv7em-none-eabi --features nightly \ + --- build --release --manifest-path embassy-executor/Cargo.toml --target thumbv7em-none-eabi --features nightly,log \ + --- build --release --manifest-path embassy-executor/Cargo.toml --target thumbv7em-none-eabi --features nightly,defmt \ + --- build --release --manifest-path embassy-executor/Cargo.toml --target thumbv6m-none-eabi --features nightly,defmt \ + --- build --release --manifest-path embassy-executor/Cargo.toml --target thumbv6m-none-eabi --features nightly,defmt,arch-cortex-m,executor-thread,executor-interrupt,integrated-timers \ + --- build --release --manifest-path embassy-executor/Cargo.toml --target thumbv7em-none-eabi --features nightly,arch-cortex-m \ + --- build --release --manifest-path embassy-executor/Cargo.toml --target thumbv7em-none-eabi --features nightly,arch-cortex-m,integrated-timers \ + --- build --release --manifest-path embassy-executor/Cargo.toml --target thumbv7em-none-eabi --features nightly,arch-cortex-m,executor-thread \ + --- build --release --manifest-path embassy-executor/Cargo.toml --target thumbv7em-none-eabi --features nightly,arch-cortex-m,executor-thread,integrated-timers \ + --- build --release --manifest-path embassy-executor/Cargo.toml --target thumbv7em-none-eabi --features nightly,arch-cortex-m,executor-interrupt \ + --- build --release --manifest-path embassy-executor/Cargo.toml --target thumbv7em-none-eabi --features nightly,arch-cortex-m,executor-interrupt,integrated-timers \ + --- build --release --manifest-path embassy-executor/Cargo.toml --target thumbv7em-none-eabi --features nightly,arch-cortex-m,executor-thread,executor-interrupt \ + --- build --release --manifest-path embassy-executor/Cargo.toml --target thumbv7em-none-eabi --features nightly,arch-cortex-m,executor-thread,executor-interrupt,integrated-timers \ + --- build --release --manifest-path embassy-executor/Cargo.toml --target riscv32imac-unknown-none-elf --features nightly,arch-riscv32 \ + --- build --release --manifest-path embassy-executor/Cargo.toml --target riscv32imac-unknown-none-elf --features nightly,arch-riscv32,integrated-timers \ + --- build --release --manifest-path embassy-executor/Cargo.toml --target riscv32imac-unknown-none-elf --features nightly,arch-riscv32,executor-thread \ + --- build --release --manifest-path embassy-executor/Cargo.toml --target riscv32imac-unknown-none-elf --features nightly,arch-riscv32,executor-thread,integrated-timers \ + --- build --release --manifest-path examples/nrf52840-rtic/Cargo.toml --target thumbv7em-none-eabi --out-dir out/examples/nrf52840-rtic \ + diff --git a/ci.sh b/ci.sh index e3918783f..933e54a80 100755 --- a/ci.sh +++ b/ci.sh @@ -15,26 +15,24 @@ if [ $TARGET = "x86_64-unknown-linux-gnu" ]; then BUILD_EXTRA="--- build --release --manifest-path examples/std/Cargo.toml --target $TARGET --out-dir out/examples/std" fi -find . -name '*.rs' -not -path '*target*' | xargs rustfmt --check --skip-children --unstable-features --edition 2021 - cargo batch \ - --- build --release --manifest-path embassy-executor/Cargo.toml --target thumbv7em-none-eabi --features nightly \ - --- build --release --manifest-path embassy-executor/Cargo.toml --target thumbv7em-none-eabi --features nightly,log \ - --- build --release --manifest-path embassy-executor/Cargo.toml --target thumbv7em-none-eabi --features nightly,defmt \ - --- build --release --manifest-path embassy-executor/Cargo.toml --target thumbv6m-none-eabi --features nightly,defmt \ - --- build --release --manifest-path embassy-executor/Cargo.toml --target thumbv6m-none-eabi --features nightly,defmt,arch-cortex-m,executor-thread,executor-interrupt,integrated-timers \ - --- build --release --manifest-path embassy-executor/Cargo.toml --target thumbv7em-none-eabi --features nightly,arch-cortex-m \ - --- build --release --manifest-path embassy-executor/Cargo.toml --target thumbv7em-none-eabi --features nightly,arch-cortex-m,integrated-timers \ - --- build --release --manifest-path embassy-executor/Cargo.toml --target thumbv7em-none-eabi --features nightly,arch-cortex-m,executor-thread \ - --- build --release --manifest-path embassy-executor/Cargo.toml --target thumbv7em-none-eabi --features nightly,arch-cortex-m,executor-thread,integrated-timers \ - --- build --release --manifest-path embassy-executor/Cargo.toml --target thumbv7em-none-eabi --features nightly,arch-cortex-m,executor-interrupt \ - --- build --release --manifest-path embassy-executor/Cargo.toml --target thumbv7em-none-eabi --features nightly,arch-cortex-m,executor-interrupt,integrated-timers \ - --- build --release --manifest-path embassy-executor/Cargo.toml --target thumbv7em-none-eabi --features nightly,arch-cortex-m,executor-thread,executor-interrupt \ - --- build --release --manifest-path embassy-executor/Cargo.toml --target thumbv7em-none-eabi --features nightly,arch-cortex-m,executor-thread,executor-interrupt,integrated-timers \ - --- build --release --manifest-path embassy-executor/Cargo.toml --target riscv32imac-unknown-none-elf --features nightly,arch-riscv32 \ - --- build --release --manifest-path embassy-executor/Cargo.toml --target riscv32imac-unknown-none-elf --features nightly,arch-riscv32,integrated-timers \ - --- build --release --manifest-path embassy-executor/Cargo.toml --target riscv32imac-unknown-none-elf --features nightly,arch-riscv32,executor-thread \ - --- build --release --manifest-path embassy-executor/Cargo.toml --target riscv32imac-unknown-none-elf --features nightly,arch-riscv32,executor-thread,integrated-timers \ + --- build --release --manifest-path embassy-executor/Cargo.toml --target thumbv7em-none-eabi \ + --- build --release --manifest-path embassy-executor/Cargo.toml --target thumbv7em-none-eabi --features log \ + --- build --release --manifest-path embassy-executor/Cargo.toml --target thumbv7em-none-eabi --features defmt \ + --- build --release --manifest-path embassy-executor/Cargo.toml --target thumbv6m-none-eabi --features defmt \ + --- build --release --manifest-path embassy-executor/Cargo.toml --target thumbv6m-none-eabi --features defmt,arch-cortex-m,executor-thread,executor-interrupt,integrated-timers \ + --- build --release --manifest-path embassy-executor/Cargo.toml --target thumbv7em-none-eabi --features arch-cortex-m \ + --- build --release --manifest-path embassy-executor/Cargo.toml --target thumbv7em-none-eabi --features arch-cortex-m,integrated-timers \ + --- build --release --manifest-path embassy-executor/Cargo.toml --target thumbv7em-none-eabi --features arch-cortex-m,executor-thread \ + --- build --release --manifest-path embassy-executor/Cargo.toml --target thumbv7em-none-eabi --features arch-cortex-m,executor-thread,integrated-timers \ + --- build --release --manifest-path embassy-executor/Cargo.toml --target thumbv7em-none-eabi --features arch-cortex-m,executor-interrupt \ + --- build --release --manifest-path embassy-executor/Cargo.toml --target thumbv7em-none-eabi --features arch-cortex-m,executor-interrupt,integrated-timers \ + --- build --release --manifest-path embassy-executor/Cargo.toml --target thumbv7em-none-eabi --features arch-cortex-m,executor-thread,executor-interrupt \ + --- build --release --manifest-path embassy-executor/Cargo.toml --target thumbv7em-none-eabi --features arch-cortex-m,executor-thread,executor-interrupt,integrated-timers \ + --- build --release --manifest-path embassy-executor/Cargo.toml --target riscv32imac-unknown-none-elf --features arch-riscv32 \ + --- build --release --manifest-path embassy-executor/Cargo.toml --target riscv32imac-unknown-none-elf --features arch-riscv32,integrated-timers \ + --- build --release --manifest-path embassy-executor/Cargo.toml --target riscv32imac-unknown-none-elf --features arch-riscv32,executor-thread \ + --- build --release --manifest-path embassy-executor/Cargo.toml --target riscv32imac-unknown-none-elf --features arch-riscv32,executor-thread,integrated-timers \ --- build --release --manifest-path embassy-sync/Cargo.toml --target thumbv6m-none-eabi --features defmt \ --- build --release --manifest-path embassy-time/Cargo.toml --target thumbv6m-none-eabi --features defmt,defmt-timestamp-uptime,tick-hz-32_768,generic-queue-8 \ --- build --release --manifest-path embassy-net/Cargo.toml --target thumbv7em-none-eabi --features defmt,tcp,udp,dns,proto-ipv4,medium-ethernet \ @@ -140,7 +138,6 @@ cargo batch \ --- 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/nrf52840/Cargo.toml --target thumbv7em-none-eabi --out-dir out/examples/nrf52840 \ - --- build --release --manifest-path examples/nrf52840-rtic/Cargo.toml --target thumbv7em-none-eabi --out-dir out/examples/nrf52840-rtic \ --- 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 \ diff --git a/ci_stable.sh b/ci_stable.sh deleted file mode 100755 index 66ed8f79d..000000000 --- a/ci_stable.sh +++ /dev/null @@ -1,77 +0,0 @@ -#!/bin/bash - -set -euo pipefail - -export RUSTFLAGS=-Dwarnings -export DEFMT_LOG=trace - -cargo batch \ - --- build --release --manifest-path embassy-boot/nrf/Cargo.toml --target thumbv7em-none-eabi --features embassy-nrf/nrf52840 \ - --- build --release --manifest-path embassy-boot/nrf/Cargo.toml --target thumbv8m.main-none-eabihf --features embassy-nrf/nrf9160-ns \ - --- build --release --manifest-path embassy-boot/rp/Cargo.toml --target thumbv6m-none-eabi \ - --- build --release --manifest-path embassy-boot/stm32/Cargo.toml --target thumbv7em-none-eabi --features embassy-stm32/stm32wl55jc-cm4 \ - --- build --release --manifest-path embassy-executor/Cargo.toml --target thumbv7em-none-eabi \ - --- build --release --manifest-path embassy-executor/Cargo.toml --target thumbv7em-none-eabi --features log \ - --- build --release --manifest-path embassy-executor/Cargo.toml --target thumbv7em-none-eabi --features defmt \ - --- build --release --manifest-path embassy-executor/Cargo.toml --target thumbv6m-none-eabi --features defmt \ - --- build --release --manifest-path embassy-net/Cargo.toml --target thumbv7em-none-eabi --features defmt,tcp,udp,dns,proto-ipv4,medium-ethernet \ - --- build --release --manifest-path embassy-net/Cargo.toml --target thumbv7em-none-eabi --features defmt,tcp,udp,dns,dhcpv4,medium-ethernet \ - --- build --release --manifest-path embassy-net/Cargo.toml --target thumbv7em-none-eabi --features defmt,tcp,udp,dns,proto-ipv6,medium-ethernet \ - --- build --release --manifest-path embassy-nrf/Cargo.toml --target thumbv7em-none-eabi --features nrf52805,gpiote,time-driver-rtc1 \ - --- build --release --manifest-path embassy-nrf/Cargo.toml --target thumbv7em-none-eabi --features nrf52810,gpiote,time-driver-rtc1 \ - --- build --release --manifest-path embassy-nrf/Cargo.toml --target thumbv7em-none-eabi --features nrf52811,gpiote,time-driver-rtc1 \ - --- build --release --manifest-path embassy-nrf/Cargo.toml --target thumbv7em-none-eabi --features nrf52820,gpiote,time-driver-rtc1 \ - --- build --release --manifest-path embassy-nrf/Cargo.toml --target thumbv7em-none-eabi --features nrf52832,gpiote,time-driver-rtc1 \ - --- build --release --manifest-path embassy-nrf/Cargo.toml --target thumbv7em-none-eabi --features nrf52833,gpiote,time-driver-rtc1 \ - --- build --release --manifest-path embassy-nrf/Cargo.toml --target thumbv8m.main-none-eabihf --features nrf9160-s,gpiote,time-driver-rtc1 \ - --- build --release --manifest-path embassy-nrf/Cargo.toml --target thumbv8m.main-none-eabihf --features nrf9160-ns,gpiote,time-driver-rtc1 \ - --- build --release --manifest-path embassy-nrf/Cargo.toml --target thumbv8m.main-none-eabihf --features nrf5340-app-s,gpiote,time-driver-rtc1 \ - --- build --release --manifest-path embassy-nrf/Cargo.toml --target thumbv8m.main-none-eabihf --features nrf5340-app-ns,gpiote,time-driver-rtc1 \ - --- build --release --manifest-path embassy-nrf/Cargo.toml --target thumbv8m.main-none-eabihf --features nrf5340-net,gpiote,time-driver-rtc1 \ - --- build --release --manifest-path embassy-nrf/Cargo.toml --target thumbv7em-none-eabi --features nrf52840,gpiote,time-driver-rtc1 \ - --- build --release --manifest-path embassy-nrf/Cargo.toml --target thumbv7em-none-eabi --features nrf52840,log,gpiote,time-driver-rtc1 \ - --- build --release --manifest-path embassy-nrf/Cargo.toml --target thumbv7em-none-eabi --features nrf52840,defmt,gpiote,time-driver-rtc1 \ - --- build --release --manifest-path embassy-rp/Cargo.toml --target thumbv6m-none-eabi --features defmt \ - --- build --release --manifest-path embassy-rp/Cargo.toml --target thumbv6m-none-eabi --features log \ - --- build --release --manifest-path embassy-rp/Cargo.toml --target thumbv6m-none-eabi \ - --- build --release --manifest-path embassy-rp/Cargo.toml --target thumbv6m-none-eabi --features qspi-as-gpio \ - --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32g473cc,defmt,exti,time-driver-any \ - --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32g491re,defmt,exti,time-driver-any \ - --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32u585zi,defmt,exti,time-driver-any \ - --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32wb55vy,defmt,exti,time-driver-any \ - --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32wl55cc-cm4,defmt,exti,time-driver-any \ - --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32g473cc,defmt,exti,time-driver-any,time \ - --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32g491re,defmt,exti,time-driver-any,time \ - --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32u585zi,defmt,exti,time-driver-any,time \ - --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32wb55vy,defmt,exti,time-driver-any,time \ - --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32wl55cc-cm4,defmt,exti,time-driver-any,time \ - --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32l4r9zi,defmt,exti,time-driver-any,time \ - --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32f303vc,defmt,exti,time-driver-any,time \ - --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32f411ce,defmt,time-driver-any,time \ - --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32f411ce,defmt,time-driver-any,time \ - --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32f429zi,log,time-driver-any,time \ - --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32f429zi,log,time-driver-any,time \ - --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32h755zi-cm7,defmt,time-driver-any,time \ - --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32h755zi-cm7,defmt,time-driver-any,time \ - --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32l476vg,defmt,time-driver-any,time \ - --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32l476vg,defmt,time-driver-any,time \ - --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv6m-none-eabi --features stm32l072cz,defmt,time-driver-any,time \ - --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv6m-none-eabi --features stm32l072cz,defmt,time-driver-any,time \ - --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7m-none-eabi --features stm32l151cb-a,defmt,time-driver-any,time \ - --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7m-none-eabi --features stm32l151cb-a,defmt,time-driver-any,time \ - --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32f410tb,defmt,exti,time-driver-any,time \ - --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32f410tb,defmt,exti,time-driver-any,time \ - --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32f429zi,log,exti,time-driver-any,time \ - --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32f429zi,log,exti,time-driver-any,time \ - --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32h755zi-cm7,defmt,exti,time-driver-any,time \ - --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32h755zi-cm7,defmt,exti,time-driver-any,time \ - --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32l476vg,defmt,exti,time-driver-any,time \ - --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32l476vg,defmt,exti,time-driver-any,time \ - --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv6m-none-eabi --features stm32l072cz,defmt,exti,time-driver-any,time \ - --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv6m-none-eabi --features stm32l072cz,defmt,exti,time-driver-any,time \ - --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7m-none-eabi --features stm32l151cb-a,defmt,exti,time-driver-any,time \ - --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7m-none-eabi --features stm32l151cb-a,defmt,exti,time-driver-any,time \ - --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7m-none-eabi --features stm32f217zg,defmt,exti,time-driver-any,time \ - --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7m-none-eabi --features stm32f217zg,defmt,exti,time-driver-any,time \ - --- 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/examples/basic/src/main.rs b/docs/modules/ROOT/examples/basic/src/main.rs index 04170db55..2a4ee5968 100644 --- a/docs/modules/ROOT/examples/basic/src/main.rs +++ b/docs/modules/ROOT/examples/basic/src/main.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/docs/modules/ROOT/examples/layer-by-layer/blinky-async/Cargo.toml b/docs/modules/ROOT/examples/layer-by-layer/blinky-async/Cargo.toml index dcdb71e7b..2d47dccf4 100644 --- a/docs/modules/ROOT/examples/layer-by-layer/blinky-async/Cargo.toml +++ b/docs/modules/ROOT/examples/layer-by-layer/blinky-async/Cargo.toml @@ -8,7 +8,7 @@ license = "MIT OR Apache-2.0" cortex-m = "0.7" cortex-m-rt = "0.7" embassy-stm32 = { version = "0.1.0", features = ["stm32l475vg", "memory-x", "exti"] } -embassy-executor = { version = "0.4.0", features = ["nightly", "arch-cortex-m", "executor-thread"] } +embassy-executor = { version = "0.4.0", features = ["arch-cortex-m", "executor-thread"] } defmt = "0.3.0" defmt-rtt = "0.3.0" diff --git a/docs/modules/ROOT/examples/layer-by-layer/blinky-async/src/main.rs b/docs/modules/ROOT/examples/layer-by-layer/blinky-async/src/main.rs index 8df632240..e6753be28 100644 --- a/docs/modules/ROOT/examples/layer-by-layer/blinky-async/src/main.rs +++ b/docs/modules/ROOT/examples/layer-by-layer/blinky-async/src/main.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use embassy_executor::Spawner; use embassy_stm32::exti::ExtiInput; diff --git a/embassy-executor/Cargo.toml b/embassy-executor/Cargo.toml index ec5aca46d..4dcd03b0f 100644 --- a/embassy-executor/Cargo.toml +++ b/embassy-executor/Cargo.toml @@ -14,7 +14,7 @@ categories = [ [package.metadata.embassy_docs] src_base = "https://github.com/embassy-rs/embassy/blob/embassy-executor-v$VERSION/embassy-executor/src/" src_base_git = "https://github.com/embassy-rs/embassy/blob/$COMMIT/embassy-executor/src/" -features = ["nightly", "defmt"] +features = ["defmt"] flavors = [ { name = "std", target = "x86_64-unknown-linux-gnu", features = ["arch-std", "executor-thread"] }, { name = "wasm", target = "wasm32-unknown-unknown", features = ["arch-wasm", "executor-thread"] }, @@ -25,7 +25,7 @@ flavors = [ [package.metadata.docs.rs] default-target = "thumbv7em-none-eabi" targets = ["thumbv7em-none-eabi"] -features = ["nightly", "defmt", "arch-cortex-m", "executor-thread", "executor-interrupt"] +features = ["defmt", "arch-cortex-m", "executor-thread", "executor-interrupt"] [dependencies] defmt = { version = "0.3", optional = true } diff --git a/embassy-rp/Cargo.toml b/embassy-rp/Cargo.toml index c557940b1..93dad68ce 100644 --- a/embassy-rp/Cargo.toml +++ b/embassy-rp/Cargo.toml @@ -87,5 +87,5 @@ pio = {version= "0.2.1" } rp2040-boot2 = "0.3" [dev-dependencies] -embassy-executor = { version = "0.4.0", path = "../embassy-executor", features = ["nightly", "arch-std", "executor-thread"] } +embassy-executor = { version = "0.4.0", path = "../embassy-executor", features = ["arch-std", "executor-thread"] } static_cell = { version = "2" } diff --git a/embassy-rp/src/lib.rs b/embassy-rp/src/lib.rs index 004b94589..fdacf4965 100644 --- a/embassy-rp/src/lib.rs +++ b/embassy-rp/src/lib.rs @@ -247,7 +247,6 @@ select_bootloader! { /// # Usage /// /// ```no_run -/// #![feature(type_alias_impl_trait)] /// use embassy_rp::install_core0_stack_guard; /// use embassy_executor::{Executor, Spawner}; /// diff --git a/embassy-rp/src/multicore.rs b/embassy-rp/src/multicore.rs index 915761801..252f30dc1 100644 --- a/embassy-rp/src/multicore.rs +++ b/embassy-rp/src/multicore.rs @@ -11,7 +11,6 @@ //! # Usage //! //! ```no_run -//! # #![feature(type_alias_impl_trait)] //! use embassy_rp::multicore::Stack; //! use static_cell::StaticCell; //! use embassy_executor::Executor; diff --git a/embassy-stm32-wpan/Cargo.toml b/embassy-stm32-wpan/Cargo.toml index f887b8171..1780688cd 100644 --- a/embassy-stm32-wpan/Cargo.toml +++ b/embassy-stm32-wpan/Cargo.toml @@ -26,7 +26,7 @@ aligned = "0.4.1" bit_field = "0.10.2" stm32-device-signature = { version = "0.3.3", features = ["stm32wb5x"] } -stm32wb-hci = { version = "0.1.4", optional = true } +stm32wb-hci = { git = "https://github.com/Dirbaio/stm32wb-hci", rev = "0aff47e009c30c5fc5d520672625173d75f7505c", optional = true } futures = { version = "0.3.17", default-features = false, features = ["async-await"] } bitflags = { version = "2.3.3", optional = true } diff --git a/embassy-time/src/timer.rs b/embassy-time/src/timer.rs index 574d715da..2705ba03f 100644 --- a/embassy-time/src/timer.rs +++ b/embassy-time/src/timer.rs @@ -47,9 +47,6 @@ impl Timer { /// /// Example: /// ``` no_run - /// # #![feature(type_alias_impl_trait)] - /// # - /// # fn foo() {} /// use embassy_time::{Duration, Timer}; /// /// #[embassy_executor::task] @@ -132,8 +129,6 @@ impl Future for Timer { /// /// For instance, consider the following code fragment. /// ``` no_run -/// # #![feature(type_alias_impl_trait)] -/// # /// use embassy_time::{Duration, Timer}; /// # fn foo() {} /// @@ -152,8 +147,6 @@ impl Future for Timer { /// Example using ticker, which will consistently call `foo` once a second. /// /// ``` no_run -/// # #![feature(type_alias_impl_trait)] -/// # /// use embassy_time::{Duration, Ticker}; /// # fn foo(){} /// diff --git a/examples/boot/application/nrf/Cargo.toml b/examples/boot/application/nrf/Cargo.toml index 5f11750b2..b52bac650 100644 --- a/examples/boot/application/nrf/Cargo.toml +++ b/examples/boot/application/nrf/Cargo.toml @@ -6,7 +6,7 @@ license = "MIT OR Apache-2.0" [dependencies] embassy-sync = { version = "0.5.0", path = "../../../../embassy-sync" } -embassy-executor = { version = "0.4.0", path = "../../../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "nightly", "integrated-timers", "arch-cortex-m", "executor-thread"] } +embassy-executor = { version = "0.4.0", path = "../../../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "integrated-timers", "arch-cortex-m", "executor-thread"] } embassy-time = { version = "0.2", path = "../../../../embassy-time", features = [] } embassy-nrf = { version = "0.1.0", path = "../../../../embassy-nrf", features = ["time-driver-rtc1", "gpiote", ] } embassy-boot = { version = "0.1.0", path = "../../../../embassy-boot/boot", features = [] } diff --git a/examples/boot/application/nrf/src/bin/a.rs b/examples/boot/application/nrf/src/bin/a.rs index 8b510ed35..f3abfddbc 100644 --- a/examples/boot/application/nrf/src/bin/a.rs +++ b/examples/boot/application/nrf/src/bin/a.rs @@ -1,7 +1,6 @@ #![no_std] #![no_main] #![macro_use] -#![feature(type_alias_impl_trait)] use embassy_boot_nrf::{FirmwareUpdater, FirmwareUpdaterConfig}; use embassy_embedded_hal::adapter::BlockingAsync; diff --git a/examples/boot/application/nrf/src/bin/b.rs b/examples/boot/application/nrf/src/bin/b.rs index a88c3c56c..de97b6a22 100644 --- a/examples/boot/application/nrf/src/bin/b.rs +++ b/examples/boot/application/nrf/src/bin/b.rs @@ -1,7 +1,6 @@ #![no_std] #![no_main] #![macro_use] -#![feature(type_alias_impl_trait)] use embassy_executor::Spawner; use embassy_nrf::gpio::{Level, Output, OutputDrive}; diff --git a/examples/boot/application/rp/Cargo.toml b/examples/boot/application/rp/Cargo.toml index 89ac5a8f6..08ce16877 100644 --- a/examples/boot/application/rp/Cargo.toml +++ b/examples/boot/application/rp/Cargo.toml @@ -6,7 +6,7 @@ license = "MIT OR Apache-2.0" [dependencies] embassy-sync = { version = "0.5.0", path = "../../../../embassy-sync" } -embassy-executor = { version = "0.4.0", path = "../../../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "nightly", "integrated-timers", "arch-cortex-m", "executor-thread"] } +embassy-executor = { version = "0.4.0", path = "../../../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "integrated-timers", "arch-cortex-m", "executor-thread"] } embassy-time = { version = "0.2", path = "../../../../embassy-time", features = [] } embassy-rp = { version = "0.1.0", path = "../../../../embassy-rp", features = ["time-driver", ] } embassy-boot-rp = { version = "0.1.0", path = "../../../../embassy-boot/rp", features = [] } diff --git a/examples/boot/application/rp/src/bin/a.rs b/examples/boot/application/rp/src/bin/a.rs index 6fd5d7f60..3f0bf90e2 100644 --- a/examples/boot/application/rp/src/bin/a.rs +++ b/examples/boot/application/rp/src/bin/a.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use core::cell::RefCell; diff --git a/examples/boot/application/rp/src/bin/b.rs b/examples/boot/application/rp/src/bin/b.rs index 1eca5b4a2..a46d095bf 100644 --- a/examples/boot/application/rp/src/bin/b.rs +++ b/examples/boot/application/rp/src/bin/b.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use embassy_executor::Spawner; use embassy_rp::gpio; diff --git a/examples/boot/application/stm32f3/Cargo.toml b/examples/boot/application/stm32f3/Cargo.toml index 1a0f8cee5..248ec6dce 100644 --- a/examples/boot/application/stm32f3/Cargo.toml +++ b/examples/boot/application/stm32f3/Cargo.toml @@ -6,7 +6,7 @@ license = "MIT OR Apache-2.0" [dependencies] embassy-sync = { version = "0.5.0", path = "../../../../embassy-sync" } -embassy-executor = { version = "0.4.0", path = "../../../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "nightly", "integrated-timers"] } +embassy-executor = { version = "0.4.0", path = "../../../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "integrated-timers"] } embassy-time = { version = "0.2", path = "../../../../embassy-time", features = [ "tick-hz-32_768"] } embassy-stm32 = { version = "0.1.0", path = "../../../../embassy-stm32", features = ["stm32f303re", "time-driver-any", "exti"] } embassy-boot-stm32 = { version = "0.1.0", path = "../../../../embassy-boot/stm32" } diff --git a/examples/boot/application/stm32f3/src/bin/a.rs b/examples/boot/application/stm32f3/src/bin/a.rs index 8be39bfb7..96ae5c47b 100644 --- a/examples/boot/application/stm32f3/src/bin/a.rs +++ b/examples/boot/application/stm32f3/src/bin/a.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] #[cfg(feature = "defmt-rtt")] use defmt_rtt::*; diff --git a/examples/boot/application/stm32f3/src/bin/b.rs b/examples/boot/application/stm32f3/src/bin/b.rs index 8411f384c..22ba82d5e 100644 --- a/examples/boot/application/stm32f3/src/bin/b.rs +++ b/examples/boot/application/stm32f3/src/bin/b.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] #[cfg(feature = "defmt-rtt")] use defmt_rtt::*; diff --git a/examples/boot/application/stm32f7/Cargo.toml b/examples/boot/application/stm32f7/Cargo.toml index e42d1d421..aa5f87615 100644 --- a/examples/boot/application/stm32f7/Cargo.toml +++ b/examples/boot/application/stm32f7/Cargo.toml @@ -6,7 +6,7 @@ license = "MIT OR Apache-2.0" [dependencies] embassy-sync = { version = "0.5.0", path = "../../../../embassy-sync" } -embassy-executor = { version = "0.4.0", path = "../../../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "nightly", "integrated-timers"] } +embassy-executor = { version = "0.4.0", path = "../../../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "integrated-timers"] } embassy-time = { version = "0.2", path = "../../../../embassy-time", features = [ "tick-hz-32_768"] } embassy-stm32 = { version = "0.1.0", path = "../../../../embassy-stm32", features = ["stm32f767zi", "time-driver-any", "exti"] } embassy-boot-stm32 = { version = "0.1.0", path = "../../../../embassy-boot/stm32", features = [] } diff --git a/examples/boot/application/stm32f7/src/bin/a.rs b/examples/boot/application/stm32f7/src/bin/a.rs index 0c3819bed..a6107386a 100644 --- a/examples/boot/application/stm32f7/src/bin/a.rs +++ b/examples/boot/application/stm32f7/src/bin/a.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use core::cell::RefCell; diff --git a/examples/boot/application/stm32f7/src/bin/b.rs b/examples/boot/application/stm32f7/src/bin/b.rs index 4c2ad06a2..190477204 100644 --- a/examples/boot/application/stm32f7/src/bin/b.rs +++ b/examples/boot/application/stm32f7/src/bin/b.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] #[cfg(feature = "defmt-rtt")] use defmt_rtt::*; diff --git a/examples/boot/application/stm32h7/Cargo.toml b/examples/boot/application/stm32h7/Cargo.toml index 8450d8639..78e33de28 100644 --- a/examples/boot/application/stm32h7/Cargo.toml +++ b/examples/boot/application/stm32h7/Cargo.toml @@ -6,7 +6,7 @@ license = "MIT OR Apache-2.0" [dependencies] embassy-sync = { version = "0.5.0", path = "../../../../embassy-sync" } -embassy-executor = { version = "0.4.0", path = "../../../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "nightly", "integrated-timers"] } +embassy-executor = { version = "0.4.0", path = "../../../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "integrated-timers"] } embassy-time = { version = "0.2", path = "../../../../embassy-time", features = [ "tick-hz-32_768"] } embassy-stm32 = { version = "0.1.0", path = "../../../../embassy-stm32", features = ["stm32h743zi", "time-driver-any", "exti"] } embassy-boot-stm32 = { version = "0.1.0", path = "../../../../embassy-boot/stm32", features = [] } diff --git a/examples/boot/application/stm32h7/src/bin/a.rs b/examples/boot/application/stm32h7/src/bin/a.rs index f239e3732..b73506cf3 100644 --- a/examples/boot/application/stm32h7/src/bin/a.rs +++ b/examples/boot/application/stm32h7/src/bin/a.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use core::cell::RefCell; diff --git a/examples/boot/application/stm32h7/src/bin/b.rs b/examples/boot/application/stm32h7/src/bin/b.rs index 5c03e2d0c..5f3f35207 100644 --- a/examples/boot/application/stm32h7/src/bin/b.rs +++ b/examples/boot/application/stm32h7/src/bin/b.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] #[cfg(feature = "defmt-rtt")] use defmt_rtt::*; diff --git a/examples/boot/application/stm32l0/Cargo.toml b/examples/boot/application/stm32l0/Cargo.toml index d6684bedb..240afe4c6 100644 --- a/examples/boot/application/stm32l0/Cargo.toml +++ b/examples/boot/application/stm32l0/Cargo.toml @@ -6,7 +6,7 @@ license = "MIT OR Apache-2.0" [dependencies] embassy-sync = { version = "0.5.0", path = "../../../../embassy-sync" } -embassy-executor = { version = "0.4.0", path = "../../../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "nightly", "integrated-timers"] } +embassy-executor = { version = "0.4.0", path = "../../../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "integrated-timers"] } embassy-time = { version = "0.2", path = "../../../../embassy-time", features = [ "tick-hz-32_768"] } embassy-stm32 = { version = "0.1.0", path = "../../../../embassy-stm32", features = ["stm32l072cz", "time-driver-any", "exti", "memory-x"] } embassy-boot-stm32 = { version = "0.1.0", path = "../../../../embassy-boot/stm32", features = [] } diff --git a/examples/boot/application/stm32l0/src/bin/a.rs b/examples/boot/application/stm32l0/src/bin/a.rs index 42e1a71eb..02f74bdef 100644 --- a/examples/boot/application/stm32l0/src/bin/a.rs +++ b/examples/boot/application/stm32l0/src/bin/a.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] #[cfg(feature = "defmt-rtt")] use defmt_rtt::*; diff --git a/examples/boot/application/stm32l0/src/bin/b.rs b/examples/boot/application/stm32l0/src/bin/b.rs index 52d42395f..6bf00f41a 100644 --- a/examples/boot/application/stm32l0/src/bin/b.rs +++ b/examples/boot/application/stm32l0/src/bin/b.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] #[cfg(feature = "defmt-rtt")] use defmt_rtt::*; diff --git a/examples/boot/application/stm32l1/Cargo.toml b/examples/boot/application/stm32l1/Cargo.toml index cca8bf443..97f1e277b 100644 --- a/examples/boot/application/stm32l1/Cargo.toml +++ b/examples/boot/application/stm32l1/Cargo.toml @@ -6,7 +6,7 @@ license = "MIT OR Apache-2.0" [dependencies] embassy-sync = { version = "0.5.0", path = "../../../../embassy-sync" } -embassy-executor = { version = "0.4.0", path = "../../../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "nightly", "integrated-timers"] } +embassy-executor = { version = "0.4.0", path = "../../../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "integrated-timers"] } embassy-time = { version = "0.2", path = "../../../../embassy-time", features = [ "tick-hz-32_768"] } embassy-stm32 = { version = "0.1.0", path = "../../../../embassy-stm32", features = ["stm32l151cb-a", "time-driver-any", "exti"] } embassy-boot-stm32 = { version = "0.1.0", path = "../../../../embassy-boot/stm32", features = [] } diff --git a/examples/boot/application/stm32l1/src/bin/a.rs b/examples/boot/application/stm32l1/src/bin/a.rs index 42e1a71eb..02f74bdef 100644 --- a/examples/boot/application/stm32l1/src/bin/a.rs +++ b/examples/boot/application/stm32l1/src/bin/a.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] #[cfg(feature = "defmt-rtt")] use defmt_rtt::*; diff --git a/examples/boot/application/stm32l1/src/bin/b.rs b/examples/boot/application/stm32l1/src/bin/b.rs index 52d42395f..6bf00f41a 100644 --- a/examples/boot/application/stm32l1/src/bin/b.rs +++ b/examples/boot/application/stm32l1/src/bin/b.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] #[cfg(feature = "defmt-rtt")] use defmt_rtt::*; diff --git a/examples/boot/application/stm32l4/Cargo.toml b/examples/boot/application/stm32l4/Cargo.toml index 30d61056c..0c3830f97 100644 --- a/examples/boot/application/stm32l4/Cargo.toml +++ b/examples/boot/application/stm32l4/Cargo.toml @@ -6,7 +6,7 @@ license = "MIT OR Apache-2.0" [dependencies] embassy-sync = { version = "0.5.0", path = "../../../../embassy-sync" } -embassy-executor = { version = "0.4.0", path = "../../../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "nightly", "integrated-timers"] } +embassy-executor = { version = "0.4.0", path = "../../../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "integrated-timers"] } embassy-time = { version = "0.2", path = "../../../../embassy-time", features = [ "tick-hz-32_768"] } embassy-stm32 = { version = "0.1.0", path = "../../../../embassy-stm32", features = ["stm32l475vg", "time-driver-any", "exti"] } embassy-boot-stm32 = { version = "0.1.0", path = "../../../../embassy-boot/stm32", features = [] } diff --git a/examples/boot/application/stm32l4/src/bin/a.rs b/examples/boot/application/stm32l4/src/bin/a.rs index eefa25f75..892446968 100644 --- a/examples/boot/application/stm32l4/src/bin/a.rs +++ b/examples/boot/application/stm32l4/src/bin/a.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] #[cfg(feature = "defmt-rtt")] use defmt_rtt::*; diff --git a/examples/boot/application/stm32l4/src/bin/b.rs b/examples/boot/application/stm32l4/src/bin/b.rs index 8411f384c..22ba82d5e 100644 --- a/examples/boot/application/stm32l4/src/bin/b.rs +++ b/examples/boot/application/stm32l4/src/bin/b.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] #[cfg(feature = "defmt-rtt")] use defmt_rtt::*; diff --git a/examples/boot/application/stm32wb-dfu/Cargo.toml b/examples/boot/application/stm32wb-dfu/Cargo.toml index f6beea498..cdaee802e 100644 --- a/examples/boot/application/stm32wb-dfu/Cargo.toml +++ b/examples/boot/application/stm32wb-dfu/Cargo.toml @@ -6,7 +6,7 @@ license = "MIT OR Apache-2.0" [dependencies] embassy-sync = { version = "0.5.0", path = "../../../../embassy-sync" } -embassy-executor = { version = "0.4.0", path = "../../../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "nightly", "integrated-timers"] } +embassy-executor = { version = "0.4.0", path = "../../../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "integrated-timers"] } embassy-time = { version = "0.2", path = "../../../../embassy-time", features = [ "tick-hz-32_768"] } embassy-stm32 = { version = "0.1.0", path = "../../../../embassy-stm32", features = ["stm32wb55rg", "time-driver-any", "exti"] } embassy-boot-stm32 = { version = "0.1.0", path = "../../../../embassy-boot/stm32", features = [] } diff --git a/examples/boot/application/stm32wb-dfu/src/main.rs b/examples/boot/application/stm32wb-dfu/src/main.rs index fbecbf23b..b2ccb9e1a 100644 --- a/examples/boot/application/stm32wb-dfu/src/main.rs +++ b/examples/boot/application/stm32wb-dfu/src/main.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use core::cell::RefCell; diff --git a/examples/boot/application/stm32wl/Cargo.toml b/examples/boot/application/stm32wl/Cargo.toml index 7489a2fe9..b5677e148 100644 --- a/examples/boot/application/stm32wl/Cargo.toml +++ b/examples/boot/application/stm32wl/Cargo.toml @@ -6,7 +6,7 @@ license = "MIT OR Apache-2.0" [dependencies] embassy-sync = { version = "0.5.0", path = "../../../../embassy-sync" } -embassy-executor = { version = "0.4.0", path = "../../../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "nightly", "integrated-timers"] } +embassy-executor = { version = "0.4.0", path = "../../../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "integrated-timers"] } embassy-time = { version = "0.2", path = "../../../../embassy-time", features = [ "tick-hz-32_768"] } embassy-stm32 = { version = "0.1.0", path = "../../../../embassy-stm32", features = ["stm32wl55jc-cm4", "time-driver-any", "exti"] } embassy-boot-stm32 = { version = "0.1.0", path = "../../../../embassy-boot/stm32", features = [] } diff --git a/examples/boot/application/stm32wl/src/bin/a.rs b/examples/boot/application/stm32wl/src/bin/a.rs index c837e47b5..d9665e6ee 100644 --- a/examples/boot/application/stm32wl/src/bin/a.rs +++ b/examples/boot/application/stm32wl/src/bin/a.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] #[cfg(feature = "defmt-rtt")] use defmt_rtt::*; diff --git a/examples/boot/application/stm32wl/src/bin/b.rs b/examples/boot/application/stm32wl/src/bin/b.rs index 1ca3c6ea8..8dd15d8cd 100644 --- a/examples/boot/application/stm32wl/src/bin/b.rs +++ b/examples/boot/application/stm32wl/src/bin/b.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] #[cfg(feature = "defmt-rtt")] use defmt_rtt::*; diff --git a/examples/nrf-rtos-trace/src/bin/rtos_trace.rs b/examples/nrf-rtos-trace/src/bin/rtos_trace.rs index 888375693..41cc06417 100644 --- a/examples/nrf-rtos-trace/src/bin/rtos_trace.rs +++ b/examples/nrf-rtos-trace/src/bin/rtos_trace.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use core::future::poll_fn; use core::task::Poll; diff --git a/examples/nrf52840/Cargo.toml b/examples/nrf52840/Cargo.toml index 1c49c32e1..bc8a7f2d6 100644 --- a/examples/nrf52840/Cargo.toml +++ b/examples/nrf52840/Cargo.toml @@ -4,12 +4,6 @@ name = "embassy-nrf52840-examples" version = "0.1.0" license = "MIT OR Apache-2.0" -[features] -default = ["nightly"] -nightly = [ - "static_cell/nightly", -] - [dependencies] embassy-futures = { version = "0.1.0", path = "../../embassy-futures" } embassy-sync = { version = "0.5.0", path = "../../embassy-sync", features = ["defmt"] } diff --git a/examples/nrf52840/src/bin/blinky.rs b/examples/nrf52840/src/bin/blinky.rs index d3d1a7122..58a3d2cd9 100644 --- a/examples/nrf52840/src/bin/blinky.rs +++ b/examples/nrf52840/src/bin/blinky.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use embassy_executor::Spawner; use embassy_nrf::gpio::{Level, Output, OutputDrive}; diff --git a/examples/nrf52840/src/bin/buffered_uart.rs b/examples/nrf52840/src/bin/buffered_uart.rs index d9c505786..6ac72bcaf 100644 --- a/examples/nrf52840/src/bin/buffered_uart.rs +++ b/examples/nrf52840/src/bin/buffered_uart.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/nrf52840/src/bin/channel.rs b/examples/nrf52840/src/bin/channel.rs index d3c7b47d2..7fcea9dbd 100644 --- a/examples/nrf52840/src/bin/channel.rs +++ b/examples/nrf52840/src/bin/channel.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::unwrap; use embassy_executor::Spawner; diff --git a/examples/nrf52840/src/bin/channel_sender_receiver.rs b/examples/nrf52840/src/bin/channel_sender_receiver.rs index 79d2c4048..3095a04ec 100644 --- a/examples/nrf52840/src/bin/channel_sender_receiver.rs +++ b/examples/nrf52840/src/bin/channel_sender_receiver.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::unwrap; use embassy_executor::Spawner; diff --git a/examples/nrf52840/src/bin/ethernet_enc28j60.rs b/examples/nrf52840/src/bin/ethernet_enc28j60.rs index 840a16556..a8e64b38a 100644 --- a/examples/nrf52840/src/bin/ethernet_enc28j60.rs +++ b/examples/nrf52840/src/bin/ethernet_enc28j60.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/nrf52840/src/bin/executor_fairness_test.rs b/examples/nrf52840/src/bin/executor_fairness_test.rs index f111b272e..df6e7af3f 100644 --- a/examples/nrf52840/src/bin/executor_fairness_test.rs +++ b/examples/nrf52840/src/bin/executor_fairness_test.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use core::future::poll_fn; use core::task::Poll; diff --git a/examples/nrf52840/src/bin/gpiote_channel.rs b/examples/nrf52840/src/bin/gpiote_channel.rs index 5bfd02465..e254d613d 100644 --- a/examples/nrf52840/src/bin/gpiote_channel.rs +++ b/examples/nrf52840/src/bin/gpiote_channel.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::info; use embassy_executor::Spawner; diff --git a/examples/nrf52840/src/bin/gpiote_port.rs b/examples/nrf52840/src/bin/gpiote_port.rs index 0155d539e..c1afe2f20 100644 --- a/examples/nrf52840/src/bin/gpiote_port.rs +++ b/examples/nrf52840/src/bin/gpiote_port.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::{info, unwrap}; use embassy_executor::Spawner; diff --git a/examples/nrf52840/src/bin/i2s_effect.rs b/examples/nrf52840/src/bin/i2s_effect.rs index 391514d93..9eadeb4e4 100644 --- a/examples/nrf52840/src/bin/i2s_effect.rs +++ b/examples/nrf52840/src/bin/i2s_effect.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use core::f32::consts::PI; diff --git a/examples/nrf52840/src/bin/i2s_monitor.rs b/examples/nrf52840/src/bin/i2s_monitor.rs index 4ed597c0d..799be351f 100644 --- a/examples/nrf52840/src/bin/i2s_monitor.rs +++ b/examples/nrf52840/src/bin/i2s_monitor.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::{debug, error, info}; use embassy_executor::Spawner; diff --git a/examples/nrf52840/src/bin/i2s_waveform.rs b/examples/nrf52840/src/bin/i2s_waveform.rs index f2c1166b1..137d82840 100644 --- a/examples/nrf52840/src/bin/i2s_waveform.rs +++ b/examples/nrf52840/src/bin/i2s_waveform.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use core::f32::consts::PI; diff --git a/examples/nrf52840/src/bin/manually_create_executor.rs b/examples/nrf52840/src/bin/manually_create_executor.rs index 80364d34a..7ca39348e 100644 --- a/examples/nrf52840/src/bin/manually_create_executor.rs +++ b/examples/nrf52840/src/bin/manually_create_executor.rs @@ -3,7 +3,6 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use cortex_m_rt::entry; use defmt::{info, unwrap}; diff --git a/examples/nrf52840/src/bin/multiprio.rs b/examples/nrf52840/src/bin/multiprio.rs index 352f62bf2..b634d8569 100644 --- a/examples/nrf52840/src/bin/multiprio.rs +++ b/examples/nrf52840/src/bin/multiprio.rs @@ -55,7 +55,6 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use cortex_m_rt::entry; use defmt::{info, unwrap}; diff --git a/examples/nrf52840/src/bin/mutex.rs b/examples/nrf52840/src/bin/mutex.rs index 11b47d991..5c22279b5 100644 --- a/examples/nrf52840/src/bin/mutex.rs +++ b/examples/nrf52840/src/bin/mutex.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::{info, unwrap}; use embassy_executor::Spawner; diff --git a/examples/nrf52840/src/bin/nvmc.rs b/examples/nrf52840/src/bin/nvmc.rs index 624829863..a79385b98 100644 --- a/examples/nrf52840/src/bin/nvmc.rs +++ b/examples/nrf52840/src/bin/nvmc.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::{info, unwrap}; use embassy_executor::Spawner; diff --git a/examples/nrf52840/src/bin/pdm.rs b/examples/nrf52840/src/bin/pdm.rs index bff323974..52dadc805 100644 --- a/examples/nrf52840/src/bin/pdm.rs +++ b/examples/nrf52840/src/bin/pdm.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::info; use embassy_executor::Spawner; diff --git a/examples/nrf52840/src/bin/pdm_continuous.rs b/examples/nrf52840/src/bin/pdm_continuous.rs index 7d8531475..e948203a5 100644 --- a/examples/nrf52840/src/bin/pdm_continuous.rs +++ b/examples/nrf52840/src/bin/pdm_continuous.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use core::cmp::Ordering; diff --git a/examples/nrf52840/src/bin/ppi.rs b/examples/nrf52840/src/bin/ppi.rs index d74ce4064..129ad06e7 100644 --- a/examples/nrf52840/src/bin/ppi.rs +++ b/examples/nrf52840/src/bin/ppi.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use core::future::pending; diff --git a/examples/nrf52840/src/bin/pubsub.rs b/examples/nrf52840/src/bin/pubsub.rs index 17d902227..5ebea9220 100644 --- a/examples/nrf52840/src/bin/pubsub.rs +++ b/examples/nrf52840/src/bin/pubsub.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::unwrap; use embassy_executor::Spawner; diff --git a/examples/nrf52840/src/bin/pwm.rs b/examples/nrf52840/src/bin/pwm.rs index 9750935c8..a5bb1347a 100644 --- a/examples/nrf52840/src/bin/pwm.rs +++ b/examples/nrf52840/src/bin/pwm.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/nrf52840/src/bin/pwm_double_sequence.rs b/examples/nrf52840/src/bin/pwm_double_sequence.rs index 1bfe6e15a..386c483b8 100644 --- a/examples/nrf52840/src/bin/pwm_double_sequence.rs +++ b/examples/nrf52840/src/bin/pwm_double_sequence.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/nrf52840/src/bin/pwm_sequence.rs b/examples/nrf52840/src/bin/pwm_sequence.rs index f282cf910..87eda265f 100644 --- a/examples/nrf52840/src/bin/pwm_sequence.rs +++ b/examples/nrf52840/src/bin/pwm_sequence.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/nrf52840/src/bin/pwm_sequence_ppi.rs b/examples/nrf52840/src/bin/pwm_sequence_ppi.rs index 6594fa348..60ea712b5 100644 --- a/examples/nrf52840/src/bin/pwm_sequence_ppi.rs +++ b/examples/nrf52840/src/bin/pwm_sequence_ppi.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use core::future::pending; diff --git a/examples/nrf52840/src/bin/pwm_sequence_ws2812b.rs b/examples/nrf52840/src/bin/pwm_sequence_ws2812b.rs index 8596e6545..751cf4425 100644 --- a/examples/nrf52840/src/bin/pwm_sequence_ws2812b.rs +++ b/examples/nrf52840/src/bin/pwm_sequence_ws2812b.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/nrf52840/src/bin/pwm_servo.rs b/examples/nrf52840/src/bin/pwm_servo.rs index 92ded1f88..d772d2f5d 100644 --- a/examples/nrf52840/src/bin/pwm_servo.rs +++ b/examples/nrf52840/src/bin/pwm_servo.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/nrf52840/src/bin/qdec.rs b/examples/nrf52840/src/bin/qdec.rs index 59783d312..ea849be63 100644 --- a/examples/nrf52840/src/bin/qdec.rs +++ b/examples/nrf52840/src/bin/qdec.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::info; use embassy_executor::Spawner; diff --git a/examples/nrf52840/src/bin/qspi.rs b/examples/nrf52840/src/bin/qspi.rs index 9e8a01f4e..4539dd0e3 100644 --- a/examples/nrf52840/src/bin/qspi.rs +++ b/examples/nrf52840/src/bin/qspi.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::{assert_eq, info, unwrap}; use embassy_executor::Spawner; diff --git a/examples/nrf52840/src/bin/qspi_lowpower.rs b/examples/nrf52840/src/bin/qspi_lowpower.rs index 42b5454e0..516c9b481 100644 --- a/examples/nrf52840/src/bin/qspi_lowpower.rs +++ b/examples/nrf52840/src/bin/qspi_lowpower.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use core::mem; diff --git a/examples/nrf52840/src/bin/rng.rs b/examples/nrf52840/src/bin/rng.rs index 855743f50..326054c9a 100644 --- a/examples/nrf52840/src/bin/rng.rs +++ b/examples/nrf52840/src/bin/rng.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use embassy_executor::Spawner; use embassy_nrf::rng::Rng; diff --git a/examples/nrf52840/src/bin/saadc.rs b/examples/nrf52840/src/bin/saadc.rs index d651834f5..653b7d606 100644 --- a/examples/nrf52840/src/bin/saadc.rs +++ b/examples/nrf52840/src/bin/saadc.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::info; use embassy_executor::Spawner; diff --git a/examples/nrf52840/src/bin/saadc_continuous.rs b/examples/nrf52840/src/bin/saadc_continuous.rs index a5f8a4dd7..f76fa3570 100644 --- a/examples/nrf52840/src/bin/saadc_continuous.rs +++ b/examples/nrf52840/src/bin/saadc_continuous.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::info; use embassy_executor::Spawner; diff --git a/examples/nrf52840/src/bin/self_spawn.rs b/examples/nrf52840/src/bin/self_spawn.rs index 8a58396a4..5bfefc2af 100644 --- a/examples/nrf52840/src/bin/self_spawn.rs +++ b/examples/nrf52840/src/bin/self_spawn.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::{info, unwrap}; use embassy_executor::Spawner; diff --git a/examples/nrf52840/src/bin/self_spawn_current_executor.rs b/examples/nrf52840/src/bin/self_spawn_current_executor.rs index 65d50f8c3..ec9569a64 100644 --- a/examples/nrf52840/src/bin/self_spawn_current_executor.rs +++ b/examples/nrf52840/src/bin/self_spawn_current_executor.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::{info, unwrap}; use embassy_executor::Spawner; diff --git a/examples/nrf52840/src/bin/spim.rs b/examples/nrf52840/src/bin/spim.rs index 9d1843a8f..131187660 100644 --- a/examples/nrf52840/src/bin/spim.rs +++ b/examples/nrf52840/src/bin/spim.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::{info, unwrap}; use embassy_executor::Spawner; diff --git a/examples/nrf52840/src/bin/spis.rs b/examples/nrf52840/src/bin/spis.rs index 77b6e8b64..613cd37ab 100644 --- a/examples/nrf52840/src/bin/spis.rs +++ b/examples/nrf52840/src/bin/spis.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::info; use embassy_executor::Spawner; diff --git a/examples/nrf52840/src/bin/temp.rs b/examples/nrf52840/src/bin/temp.rs index d94dea38d..1d28f8ecf 100644 --- a/examples/nrf52840/src/bin/temp.rs +++ b/examples/nrf52840/src/bin/temp.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::info; use embassy_executor::Spawner; diff --git a/examples/nrf52840/src/bin/timer.rs b/examples/nrf52840/src/bin/timer.rs index 9b9bb3eb4..365695a20 100644 --- a/examples/nrf52840/src/bin/timer.rs +++ b/examples/nrf52840/src/bin/timer.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::{info, unwrap}; use embassy_executor::Spawner; diff --git a/examples/nrf52840/src/bin/twim.rs b/examples/nrf52840/src/bin/twim.rs index 959e3a4be..a9a0765e8 100644 --- a/examples/nrf52840/src/bin/twim.rs +++ b/examples/nrf52840/src/bin/twim.rs @@ -4,7 +4,6 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/nrf52840/src/bin/twim_lowpower.rs b/examples/nrf52840/src/bin/twim_lowpower.rs index bf9f966ef..c743614b8 100644 --- a/examples/nrf52840/src/bin/twim_lowpower.rs +++ b/examples/nrf52840/src/bin/twim_lowpower.rs @@ -6,7 +6,6 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use core::mem; diff --git a/examples/nrf52840/src/bin/twis.rs b/examples/nrf52840/src/bin/twis.rs index aa42b679e..88bd4cceb 100644 --- a/examples/nrf52840/src/bin/twis.rs +++ b/examples/nrf52840/src/bin/twis.rs @@ -2,7 +2,6 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/nrf52840/src/bin/uart.rs b/examples/nrf52840/src/bin/uart.rs index 50d5cab8c..accaccea1 100644 --- a/examples/nrf52840/src/bin/uart.rs +++ b/examples/nrf52840/src/bin/uart.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/nrf52840/src/bin/uart_idle.rs b/examples/nrf52840/src/bin/uart_idle.rs index e1f42fa6c..fa93bcf21 100644 --- a/examples/nrf52840/src/bin/uart_idle.rs +++ b/examples/nrf52840/src/bin/uart_idle.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/nrf52840/src/bin/uart_split.rs b/examples/nrf52840/src/bin/uart_split.rs index b748bfcd8..c7510a9a8 100644 --- a/examples/nrf52840/src/bin/uart_split.rs +++ b/examples/nrf52840/src/bin/uart_split.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/nrf52840/src/bin/usb_ethernet.rs b/examples/nrf52840/src/bin/usb_ethernet.rs index de661c019..3469c6e5f 100644 --- a/examples/nrf52840/src/bin/usb_ethernet.rs +++ b/examples/nrf52840/src/bin/usb_ethernet.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use core::mem; diff --git a/examples/nrf52840/src/bin/usb_hid_keyboard.rs b/examples/nrf52840/src/bin/usb_hid_keyboard.rs index 7ccd2946a..45850b4a4 100644 --- a/examples/nrf52840/src/bin/usb_hid_keyboard.rs +++ b/examples/nrf52840/src/bin/usb_hid_keyboard.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use core::mem; use core::sync::atomic::{AtomicBool, Ordering}; diff --git a/examples/nrf52840/src/bin/usb_hid_mouse.rs b/examples/nrf52840/src/bin/usb_hid_mouse.rs index 96fcf8a66..04ad841b7 100644 --- a/examples/nrf52840/src/bin/usb_hid_mouse.rs +++ b/examples/nrf52840/src/bin/usb_hid_mouse.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use core::mem; diff --git a/examples/nrf52840/src/bin/usb_serial.rs b/examples/nrf52840/src/bin/usb_serial.rs index dc95cde84..aff539b1b 100644 --- a/examples/nrf52840/src/bin/usb_serial.rs +++ b/examples/nrf52840/src/bin/usb_serial.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use core::mem; diff --git a/examples/nrf52840/src/bin/usb_serial_multitask.rs b/examples/nrf52840/src/bin/usb_serial_multitask.rs index 7a7bf962b..4e8118fb8 100644 --- a/examples/nrf52840/src/bin/usb_serial_multitask.rs +++ b/examples/nrf52840/src/bin/usb_serial_multitask.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use core::mem; diff --git a/examples/nrf52840/src/bin/usb_serial_winusb.rs b/examples/nrf52840/src/bin/usb_serial_winusb.rs index 1d39d3841..060f9ba94 100644 --- a/examples/nrf52840/src/bin/usb_serial_winusb.rs +++ b/examples/nrf52840/src/bin/usb_serial_winusb.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use core::mem; diff --git a/examples/nrf52840/src/bin/wdt.rs b/examples/nrf52840/src/bin/wdt.rs index 058746518..ede88cc26 100644 --- a/examples/nrf52840/src/bin/wdt.rs +++ b/examples/nrf52840/src/bin/wdt.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/nrf52840/src/bin/wifi_esp_hosted.rs b/examples/nrf52840/src/bin/wifi_esp_hosted.rs index b56c9bd8d..fc2086f75 100644 --- a/examples/nrf52840/src/bin/wifi_esp_hosted.rs +++ b/examples/nrf52840/src/bin/wifi_esp_hosted.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::{info, unwrap, warn}; use embassy_executor::Spawner; diff --git a/examples/nrf5340/Cargo.toml b/examples/nrf5340/Cargo.toml index 17d3e30e4..fc0346f90 100644 --- a/examples/nrf5340/Cargo.toml +++ b/examples/nrf5340/Cargo.toml @@ -7,7 +7,7 @@ license = "MIT OR Apache-2.0" [dependencies] embassy-futures = { version = "0.1.0", path = "../../embassy-futures" } embassy-sync = { version = "0.5.0", path = "../../embassy-sync", features = ["defmt"] } -embassy-executor = { version = "0.4.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "nightly", "defmt", "integrated-timers"] } +embassy-executor = { version = "0.4.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } embassy-time = { version = "0.2", 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.2.0", path = "../../embassy-net", features = ["defmt", "tcp", "dhcpv4", "medium-ethernet"] } @@ -17,7 +17,7 @@ embedded-io-async = { version = "0.6.1" } defmt = "0.3" defmt-rtt = "0.4" -static_cell = { version = "2", features = ["nightly"]} +static_cell = "2" cortex-m = { version = "0.7.6", features = ["inline-asm", "critical-section-single-core"] } cortex-m-rt = "0.7.0" panic-probe = { version = "0.3", features = ["print-defmt"] } diff --git a/examples/nrf5340/src/bin/blinky.rs b/examples/nrf5340/src/bin/blinky.rs index b784564a5..5c533c9b1 100644 --- a/examples/nrf5340/src/bin/blinky.rs +++ b/examples/nrf5340/src/bin/blinky.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use embassy_executor::Spawner; use embassy_nrf::gpio::{Level, Output, OutputDrive}; diff --git a/examples/nrf5340/src/bin/gpiote_channel.rs b/examples/nrf5340/src/bin/gpiote_channel.rs index ceab1194a..c0a55142f 100644 --- a/examples/nrf5340/src/bin/gpiote_channel.rs +++ b/examples/nrf5340/src/bin/gpiote_channel.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::info; use embassy_executor::Spawner; diff --git a/examples/nrf5340/src/bin/uart.rs b/examples/nrf5340/src/bin/uart.rs index d68539702..7b41d7463 100644 --- a/examples/nrf5340/src/bin/uart.rs +++ b/examples/nrf5340/src/bin/uart.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/rp/Cargo.toml b/examples/rp/Cargo.toml index 521f17b82..07de83203 100644 --- a/examples/rp/Cargo.toml +++ b/examples/rp/Cargo.toml @@ -8,7 +8,7 @@ license = "MIT OR Apache-2.0" [dependencies] embassy-embedded-hal = { version = "0.1.0", path = "../../embassy-embedded-hal", features = ["defmt"] } embassy-sync = { version = "0.5.0", path = "../../embassy-sync", features = ["defmt"] } -embassy-executor = { version = "0.4.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "executor-interrupt", "defmt", "integrated-timers"] } +embassy-executor = { version = "0.4.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "executor-interrupt", "defmt", "integrated-timers"] } embassy-time = { version = "0.2", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime"] } embassy-rp = { version = "0.1.0", path = "../../embassy-rp", features = ["defmt", "unstable-pac", "time-driver", "critical-section-impl"] } embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] } @@ -43,7 +43,7 @@ embedded-hal-async = "1.0.0-rc.3" embedded-hal-bus = { version = "0.1.0-rc.3", features = ["async"] } embedded-io-async = { version = "0.6.1", features = ["defmt-03"] } embedded-storage = { version = "0.3" } -static_cell = { version = "2", features = ["nightly"]} +static_cell = "2" portable-atomic = { version = "1.5", features = ["critical-section"] } log = "0.4" pio-proc = "0.2" diff --git a/examples/rp/src/bin/adc.rs b/examples/rp/src/bin/adc.rs index a579be139..1bb7c2249 100644 --- a/examples/rp/src/bin/adc.rs +++ b/examples/rp/src/bin/adc.rs @@ -3,7 +3,6 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/rp/src/bin/blinky.rs b/examples/rp/src/bin/blinky.rs index 66c8773fa..60fc45a70 100644 --- a/examples/rp/src/bin/blinky.rs +++ b/examples/rp/src/bin/blinky.rs @@ -4,7 +4,6 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/rp/src/bin/button.rs b/examples/rp/src/bin/button.rs index a9f34ab5d..e9054fd48 100644 --- a/examples/rp/src/bin/button.rs +++ b/examples/rp/src/bin/button.rs @@ -4,7 +4,6 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use embassy_executor::Spawner; use embassy_rp::gpio::{Input, Level, Output, Pull}; diff --git a/examples/rp/src/bin/ethernet_w5500_multisocket.rs b/examples/rp/src/bin/ethernet_w5500_multisocket.rs index b9dba0f1d..a16ea0007 100644 --- a/examples/rp/src/bin/ethernet_w5500_multisocket.rs +++ b/examples/rp/src/bin/ethernet_w5500_multisocket.rs @@ -4,7 +4,6 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/rp/src/bin/ethernet_w5500_tcp_client.rs b/examples/rp/src/bin/ethernet_w5500_tcp_client.rs index 36073f20b..975b3d385 100644 --- a/examples/rp/src/bin/ethernet_w5500_tcp_client.rs +++ b/examples/rp/src/bin/ethernet_w5500_tcp_client.rs @@ -4,7 +4,6 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use core::str::FromStr; diff --git a/examples/rp/src/bin/ethernet_w5500_tcp_server.rs b/examples/rp/src/bin/ethernet_w5500_tcp_server.rs index d523a8772..489af2c76 100644 --- a/examples/rp/src/bin/ethernet_w5500_tcp_server.rs +++ b/examples/rp/src/bin/ethernet_w5500_tcp_server.rs @@ -5,7 +5,6 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/rp/src/bin/ethernet_w5500_udp.rs b/examples/rp/src/bin/ethernet_w5500_udp.rs index 0cc47cb56..41bd7d077 100644 --- a/examples/rp/src/bin/ethernet_w5500_udp.rs +++ b/examples/rp/src/bin/ethernet_w5500_udp.rs @@ -4,7 +4,6 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/rp/src/bin/flash.rs b/examples/rp/src/bin/flash.rs index 129a8497f..eb3e6a2b9 100644 --- a/examples/rp/src/bin/flash.rs +++ b/examples/rp/src/bin/flash.rs @@ -2,7 +2,6 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/rp/src/bin/gpio_async.rs b/examples/rp/src/bin/gpio_async.rs index 98209fe41..b79fb2a15 100644 --- a/examples/rp/src/bin/gpio_async.rs +++ b/examples/rp/src/bin/gpio_async.rs @@ -4,7 +4,6 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/rp/src/bin/gpout.rs b/examples/rp/src/bin/gpout.rs index 896cc15ee..011359253 100644 --- a/examples/rp/src/bin/gpout.rs +++ b/examples/rp/src/bin/gpout.rs @@ -4,7 +4,6 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/rp/src/bin/i2c_async.rs b/examples/rp/src/bin/i2c_async.rs index 7b53aae72..e31cc894c 100644 --- a/examples/rp/src/bin/i2c_async.rs +++ b/examples/rp/src/bin/i2c_async.rs @@ -5,7 +5,6 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/rp/src/bin/i2c_blocking.rs b/examples/rp/src/bin/i2c_blocking.rs index 9ddb48d69..c9c8a2760 100644 --- a/examples/rp/src/bin/i2c_blocking.rs +++ b/examples/rp/src/bin/i2c_blocking.rs @@ -5,7 +5,6 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/rp/src/bin/i2c_slave.rs b/examples/rp/src/bin/i2c_slave.rs index 151b083a4..479f9a16a 100644 --- a/examples/rp/src/bin/i2c_slave.rs +++ b/examples/rp/src/bin/i2c_slave.rs @@ -1,7 +1,6 @@ //! This example shows how to use the 2040 as an i2c slave. #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/rp/src/bin/multicore.rs b/examples/rp/src/bin/multicore.rs index 43eaf8b0a..a1678d99a 100644 --- a/examples/rp/src/bin/multicore.rs +++ b/examples/rp/src/bin/multicore.rs @@ -4,7 +4,6 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Executor; diff --git a/examples/rp/src/bin/multiprio.rs b/examples/rp/src/bin/multiprio.rs index 28f621437..26b80c11d 100644 --- a/examples/rp/src/bin/multiprio.rs +++ b/examples/rp/src/bin/multiprio.rs @@ -55,7 +55,6 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use cortex_m_rt::entry; use defmt::{info, unwrap}; diff --git a/examples/rp/src/bin/pio_async.rs b/examples/rp/src/bin/pio_async.rs index a6d6144be..ee248591b 100644 --- a/examples/rp/src/bin/pio_async.rs +++ b/examples/rp/src/bin/pio_async.rs @@ -2,7 +2,6 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::info; use embassy_executor::Spawner; use embassy_rp::bind_interrupts; diff --git a/examples/rp/src/bin/pio_dma.rs b/examples/rp/src/bin/pio_dma.rs index 86e5017ac..02700269c 100644 --- a/examples/rp/src/bin/pio_dma.rs +++ b/examples/rp/src/bin/pio_dma.rs @@ -2,7 +2,6 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::info; use embassy_executor::Spawner; use embassy_futures::join::join; diff --git a/examples/rp/src/bin/pio_hd44780.rs b/examples/rp/src/bin/pio_hd44780.rs index 5e5a6f9a3..3fab7b5f2 100644 --- a/examples/rp/src/bin/pio_hd44780.rs +++ b/examples/rp/src/bin/pio_hd44780.rs @@ -3,7 +3,6 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use core::fmt::Write; diff --git a/examples/rp/src/bin/pio_rotary_encoder.rs b/examples/rp/src/bin/pio_rotary_encoder.rs index 6d9d59df6..58bdadbc0 100644 --- a/examples/rp/src/bin/pio_rotary_encoder.rs +++ b/examples/rp/src/bin/pio_rotary_encoder.rs @@ -2,7 +2,6 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::info; use embassy_executor::Spawner; diff --git a/examples/rp/src/bin/pio_stepper.rs b/examples/rp/src/bin/pio_stepper.rs index 02fb20699..ab9ecf623 100644 --- a/examples/rp/src/bin/pio_stepper.rs +++ b/examples/rp/src/bin/pio_stepper.rs @@ -3,7 +3,6 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use core::mem::{self, MaybeUninit}; use defmt::info; diff --git a/examples/rp/src/bin/pio_uart.rs b/examples/rp/src/bin/pio_uart.rs index c0ea23607..a07f1c180 100644 --- a/examples/rp/src/bin/pio_uart.rs +++ b/examples/rp/src/bin/pio_uart.rs @@ -8,7 +8,6 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] #![allow(async_fn_in_trait)] use defmt::{info, panic, trace}; diff --git a/examples/rp/src/bin/pio_ws2812.rs b/examples/rp/src/bin/pio_ws2812.rs index 7b3259538..9a97cb8a7 100644 --- a/examples/rp/src/bin/pio_ws2812.rs +++ b/examples/rp/src/bin/pio_ws2812.rs @@ -3,7 +3,6 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/rp/src/bin/pwm.rs b/examples/rp/src/bin/pwm.rs index a99e88003..4fb62546d 100644 --- a/examples/rp/src/bin/pwm.rs +++ b/examples/rp/src/bin/pwm.rs @@ -4,7 +4,6 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/rp/src/bin/pwm_input.rs b/examples/rp/src/bin/pwm_input.rs index 0fc2e40c3..e7bcbfbd4 100644 --- a/examples/rp/src/bin/pwm_input.rs +++ b/examples/rp/src/bin/pwm_input.rs @@ -2,7 +2,6 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/rp/src/bin/rosc.rs b/examples/rp/src/bin/rosc.rs index f841043b6..942b72319 100644 --- a/examples/rp/src/bin/rosc.rs +++ b/examples/rp/src/bin/rosc.rs @@ -4,7 +4,6 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/rp/src/bin/rtc.rs b/examples/rp/src/bin/rtc.rs index 667876db5..e9a5e43a8 100644 --- a/examples/rp/src/bin/rtc.rs +++ b/examples/rp/src/bin/rtc.rs @@ -2,7 +2,6 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/rp/src/bin/spi.rs b/examples/rp/src/bin/spi.rs index 602348f7a..4cc4f5210 100644 --- a/examples/rp/src/bin/spi.rs +++ b/examples/rp/src/bin/spi.rs @@ -4,7 +4,6 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/rp/src/bin/spi_async.rs b/examples/rp/src/bin/spi_async.rs index f5a2d334e..266584efc 100644 --- a/examples/rp/src/bin/spi_async.rs +++ b/examples/rp/src/bin/spi_async.rs @@ -3,7 +3,6 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/rp/src/bin/spi_display.rs b/examples/rp/src/bin/spi_display.rs index 26c258e1c..e937b9d0a 100644 --- a/examples/rp/src/bin/spi_display.rs +++ b/examples/rp/src/bin/spi_display.rs @@ -5,7 +5,6 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use core::cell::RefCell; diff --git a/examples/rp/src/bin/uart.rs b/examples/rp/src/bin/uart.rs index 451c3c396..6a2816cd0 100644 --- a/examples/rp/src/bin/uart.rs +++ b/examples/rp/src/bin/uart.rs @@ -6,7 +6,6 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use embassy_executor::Spawner; use embassy_rp::uart; diff --git a/examples/rp/src/bin/uart_buffered_split.rs b/examples/rp/src/bin/uart_buffered_split.rs index dc57d89c7..fac61aa04 100644 --- a/examples/rp/src/bin/uart_buffered_split.rs +++ b/examples/rp/src/bin/uart_buffered_split.rs @@ -6,7 +6,6 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/rp/src/bin/uart_unidir.rs b/examples/rp/src/bin/uart_unidir.rs index 42c8b432e..a45f40756 100644 --- a/examples/rp/src/bin/uart_unidir.rs +++ b/examples/rp/src/bin/uart_unidir.rs @@ -7,7 +7,6 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/rp/src/bin/usb_ethernet.rs b/examples/rp/src/bin/usb_ethernet.rs index 674b83f5d..01f0d5967 100644 --- a/examples/rp/src/bin/usb_ethernet.rs +++ b/examples/rp/src/bin/usb_ethernet.rs @@ -4,7 +4,6 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/rp/src/bin/usb_hid_keyboard.rs b/examples/rp/src/bin/usb_hid_keyboard.rs index 569c9b12b..b5ac16245 100644 --- a/examples/rp/src/bin/usb_hid_keyboard.rs +++ b/examples/rp/src/bin/usb_hid_keyboard.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use core::sync::atomic::{AtomicBool, Ordering}; diff --git a/examples/rp/src/bin/usb_logger.rs b/examples/rp/src/bin/usb_logger.rs index 791f15e56..af401ed63 100644 --- a/examples/rp/src/bin/usb_logger.rs +++ b/examples/rp/src/bin/usb_logger.rs @@ -4,7 +4,6 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use embassy_executor::Spawner; use embassy_rp::bind_interrupts; diff --git a/examples/rp/src/bin/usb_midi.rs b/examples/rp/src/bin/usb_midi.rs index d5cdae319..95306a35c 100644 --- a/examples/rp/src/bin/usb_midi.rs +++ b/examples/rp/src/bin/usb_midi.rs @@ -4,7 +4,6 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::{info, panic}; use embassy_executor::Spawner; diff --git a/examples/rp/src/bin/usb_raw.rs b/examples/rp/src/bin/usb_raw.rs index f59262e5c..a6c8a5b2e 100644 --- a/examples/rp/src/bin/usb_raw.rs +++ b/examples/rp/src/bin/usb_raw.rs @@ -48,7 +48,6 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::info; use embassy_executor::Spawner; diff --git a/examples/rp/src/bin/usb_raw_bulk.rs b/examples/rp/src/bin/usb_raw_bulk.rs index 288be5a4e..0dc8e9f72 100644 --- a/examples/rp/src/bin/usb_raw_bulk.rs +++ b/examples/rp/src/bin/usb_raw_bulk.rs @@ -26,7 +26,6 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::info; use embassy_executor::Spawner; diff --git a/examples/rp/src/bin/usb_serial.rs b/examples/rp/src/bin/usb_serial.rs index 30347d920..ab24a994c 100644 --- a/examples/rp/src/bin/usb_serial.rs +++ b/examples/rp/src/bin/usb_serial.rs @@ -4,7 +4,6 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::{info, panic}; use embassy_executor::Spawner; diff --git a/examples/rp/src/bin/watchdog.rs b/examples/rp/src/bin/watchdog.rs index b6af518af..b9d4ef22f 100644 --- a/examples/rp/src/bin/watchdog.rs +++ b/examples/rp/src/bin/watchdog.rs @@ -4,7 +4,6 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::info; use embassy_executor::Spawner; diff --git a/examples/rp/src/bin/wifi_ap_tcp_server.rs b/examples/rp/src/bin/wifi_ap_tcp_server.rs index 20b8aad15..1bd75607e 100644 --- a/examples/rp/src/bin/wifi_ap_tcp_server.rs +++ b/examples/rp/src/bin/wifi_ap_tcp_server.rs @@ -3,7 +3,6 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] #![allow(async_fn_in_trait)] use core::str::from_utf8; diff --git a/examples/rp/src/bin/wifi_blinky.rs b/examples/rp/src/bin/wifi_blinky.rs index b89447b7d..1ed74993c 100644 --- a/examples/rp/src/bin/wifi_blinky.rs +++ b/examples/rp/src/bin/wifi_blinky.rs @@ -4,7 +4,6 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use cyw43_pio::PioSpi; use defmt::*; diff --git a/examples/rp/src/bin/wifi_scan.rs b/examples/rp/src/bin/wifi_scan.rs index 0f7ad27dd..45bb5b76c 100644 --- a/examples/rp/src/bin/wifi_scan.rs +++ b/examples/rp/src/bin/wifi_scan.rs @@ -3,7 +3,6 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] #![allow(async_fn_in_trait)] use core::str; diff --git a/examples/rp/src/bin/wifi_tcp_server.rs b/examples/rp/src/bin/wifi_tcp_server.rs index f6cc48d8f..c346f1ded 100644 --- a/examples/rp/src/bin/wifi_tcp_server.rs +++ b/examples/rp/src/bin/wifi_tcp_server.rs @@ -3,7 +3,6 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] #![allow(async_fn_in_trait)] use core::str::from_utf8; diff --git a/examples/std/Cargo.toml b/examples/std/Cargo.toml index ccc0a4afc..a4f306865 100644 --- a/examples/std/Cargo.toml +++ b/examples/std/Cargo.toml @@ -6,7 +6,7 @@ license = "MIT OR Apache-2.0" [dependencies] embassy-sync = { version = "0.5.0", path = "../../embassy-sync", features = ["log"] } -embassy-executor = { version = "0.4.0", path = "../../embassy-executor", features = ["arch-std", "executor-thread", "log", "nightly", "integrated-timers"] } +embassy-executor = { version = "0.4.0", path = "../../embassy-executor", features = ["arch-std", "executor-thread", "log", "integrated-timers"] } embassy-time = { version = "0.2", path = "../../embassy-time", features = ["log", "std", ] } embassy-net = { version = "0.2.0", path = "../../embassy-net", features=[ "std", "log", "medium-ethernet", "medium-ip", "tcp", "udp", "dns", "dhcpv4", "proto-ipv6"] } embassy-net-tuntap = { version = "0.1.0", path = "../../embassy-net-tuntap" } @@ -23,7 +23,7 @@ nix = "0.26.2" clap = { version = "3.0.0-beta.5", features = ["derive"] } rand_core = { version = "0.6.3", features = ["std"] } heapless = { version = "0.8", default-features = false } -static_cell = { version = "2", features = ["nightly"]} +static_cell = "2" [profile.release] debug = 2 diff --git a/examples/std/src/bin/net.rs b/examples/std/src/bin/net.rs index c62a38d07..dad93d0a1 100644 --- a/examples/std/src/bin/net.rs +++ b/examples/std/src/bin/net.rs @@ -1,5 +1,3 @@ -#![feature(type_alias_impl_trait)] - use std::default::Default; use clap::Parser; diff --git a/examples/std/src/bin/net_dns.rs b/examples/std/src/bin/net_dns.rs index e1e015bc8..fca1e076e 100644 --- a/examples/std/src/bin/net_dns.rs +++ b/examples/std/src/bin/net_dns.rs @@ -1,5 +1,3 @@ -#![feature(type_alias_impl_trait)] - use std::default::Default; use clap::Parser; diff --git a/examples/std/src/bin/net_ppp.rs b/examples/std/src/bin/net_ppp.rs index 8c80c4beb..9ec0ea91f 100644 --- a/examples/std/src/bin/net_ppp.rs +++ b/examples/std/src/bin/net_ppp.rs @@ -7,7 +7,6 @@ //! ping 192.168.7.10 //! nc 192.168.7.10 1234 -#![feature(type_alias_impl_trait)] #![allow(async_fn_in_trait)] #[path = "../serial_port.rs"] diff --git a/examples/std/src/bin/net_udp.rs b/examples/std/src/bin/net_udp.rs index ac99ec626..bee91990d 100644 --- a/examples/std/src/bin/net_udp.rs +++ b/examples/std/src/bin/net_udp.rs @@ -1,5 +1,3 @@ -#![feature(type_alias_impl_trait)] - use clap::Parser; use embassy_executor::{Executor, Spawner}; use embassy_net::udp::{PacketMetadata, UdpSocket}; diff --git a/examples/std/src/bin/serial.rs b/examples/std/src/bin/serial.rs index 0b289c74d..435089aad 100644 --- a/examples/std/src/bin/serial.rs +++ b/examples/std/src/bin/serial.rs @@ -1,5 +1,3 @@ -#![feature(type_alias_impl_trait)] - #[path = "../serial_port.rs"] mod serial_port; diff --git a/examples/std/src/bin/tcp_accept.rs b/examples/std/src/bin/tcp_accept.rs index 54ef0156b..00ccd83a7 100644 --- a/examples/std/src/bin/tcp_accept.rs +++ b/examples/std/src/bin/tcp_accept.rs @@ -1,5 +1,3 @@ -#![feature(type_alias_impl_trait)] - use core::fmt::Write as _; use std::default::Default; diff --git a/examples/std/src/bin/tick.rs b/examples/std/src/bin/tick.rs index a3f99067e..f23cf3549 100644 --- a/examples/std/src/bin/tick.rs +++ b/examples/std/src/bin/tick.rs @@ -1,5 +1,3 @@ -#![feature(type_alias_impl_trait)] - use embassy_executor::Spawner; use embassy_time::Timer; use log::*; diff --git a/examples/stm32c0/Cargo.toml b/examples/stm32c0/Cargo.toml index 2d831ba5d..0fd3939c6 100644 --- a/examples/stm32c0/Cargo.toml +++ b/examples/stm32c0/Cargo.toml @@ -8,7 +8,7 @@ license = "MIT OR Apache-2.0" # Change stm32c031c6 to your chip name, if necessary. embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = [ "defmt", "time-driver-any", "stm32c031c6", "memory-x", "unstable-pac", "exti"] } embassy-sync = { version = "0.5.0", path = "../../embassy-sync", features = ["defmt"] } -embassy-executor = { version = "0.4.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } +embassy-executor = { version = "0.4.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } embassy-time = { version = "0.2", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } defmt = "0.3" diff --git a/examples/stm32c0/src/bin/blinky.rs b/examples/stm32c0/src/bin/blinky.rs index cbeb0dee1..90e479aae 100644 --- a/examples/stm32c0/src/bin/blinky.rs +++ b/examples/stm32c0/src/bin/blinky.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/stm32c0/src/bin/button.rs b/examples/stm32c0/src/bin/button.rs index 40c58013b..265200132 100644 --- a/examples/stm32c0/src/bin/button.rs +++ b/examples/stm32c0/src/bin/button.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use cortex_m_rt::entry; use defmt::*; diff --git a/examples/stm32c0/src/bin/button_exti.rs b/examples/stm32c0/src/bin/button_exti.rs index ef32d4c4a..1e970fdd6 100644 --- a/examples/stm32c0/src/bin/button_exti.rs +++ b/examples/stm32c0/src/bin/button_exti.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/stm32f0/Cargo.toml b/examples/stm32f0/Cargo.toml index 2b066d731..9fdc4798a 100644 --- a/examples/stm32f0/Cargo.toml +++ b/examples/stm32f0/Cargo.toml @@ -15,9 +15,9 @@ defmt = "0.3" defmt-rtt = "0.4" panic-probe = "0.3" embassy-sync = { version = "0.5.0", path = "../../embassy-sync", features = ["defmt"] } -embassy-executor = { version = "0.4.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "executor-interrupt", "defmt", "integrated-timers"] } +embassy-executor = { version = "0.4.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "executor-interrupt", "defmt", "integrated-timers"] } embassy-time = { version = "0.2", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } -static_cell = { version = "2", features = ["nightly"]} +static_cell = "2" portable-atomic = { version = "1.5", features = ["unsafe-assume-single-core"] } [profile.release] diff --git a/examples/stm32f0/src/bin/adc.rs b/examples/stm32f0/src/bin/adc.rs index 96f234402..8fef062b3 100644 --- a/examples/stm32f0/src/bin/adc.rs +++ b/examples/stm32f0/src/bin/adc.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/stm32f0/src/bin/blinky.rs b/examples/stm32f0/src/bin/blinky.rs index 899394546..2572be1bc 100644 --- a/examples/stm32f0/src/bin/blinky.rs +++ b/examples/stm32f0/src/bin/blinky.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/stm32f0/src/bin/button_controlled_blink.rs b/examples/stm32f0/src/bin/button_controlled_blink.rs index 306df1752..360d153c3 100644 --- a/examples/stm32f0/src/bin/button_controlled_blink.rs +++ b/examples/stm32f0/src/bin/button_controlled_blink.rs @@ -2,7 +2,6 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use core::sync::atomic::{AtomicU32, Ordering}; diff --git a/examples/stm32f0/src/bin/button_exti.rs b/examples/stm32f0/src/bin/button_exti.rs index 40c0d5848..ce17c1a48 100644 --- a/examples/stm32f0/src/bin/button_exti.rs +++ b/examples/stm32f0/src/bin/button_exti.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/stm32f0/src/bin/hello.rs b/examples/stm32f0/src/bin/hello.rs index 0f98d9865..ccd6a0a39 100644 --- a/examples/stm32f0/src/bin/hello.rs +++ b/examples/stm32f0/src/bin/hello.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::info; use embassy_executor::Spawner; diff --git a/examples/stm32f0/src/bin/multiprio.rs b/examples/stm32f0/src/bin/multiprio.rs index 870c7c45b..e49951726 100644 --- a/examples/stm32f0/src/bin/multiprio.rs +++ b/examples/stm32f0/src/bin/multiprio.rs @@ -55,7 +55,6 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use cortex_m_rt::entry; use defmt::*; diff --git a/examples/stm32f0/src/bin/wdg.rs b/examples/stm32f0/src/bin/wdg.rs index b51dee8ee..b974bff91 100644 --- a/examples/stm32f0/src/bin/wdg.rs +++ b/examples/stm32f0/src/bin/wdg.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/stm32f1/Cargo.toml b/examples/stm32f1/Cargo.toml index f04d41317..c933a4368 100644 --- a/examples/stm32f1/Cargo.toml +++ b/examples/stm32f1/Cargo.toml @@ -8,7 +8,7 @@ license = "MIT OR Apache-2.0" # Change stm32f103c8 to your chip name, if necessary. embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = [ "defmt", "stm32f103c8", "unstable-pac", "memory-x", "time-driver-any" ] } embassy-sync = { version = "0.5.0", path = "../../embassy-sync", features = ["defmt"] } -embassy-executor = { version = "0.4.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } +embassy-executor = { version = "0.4.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } embassy-time = { version = "0.2", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] } embassy-futures = { version = "0.1.0", path = "../../embassy-futures" } diff --git a/examples/stm32f1/src/bin/adc.rs b/examples/stm32f1/src/bin/adc.rs index 1edac3d83..1440460a9 100644 --- a/examples/stm32f1/src/bin/adc.rs +++ b/examples/stm32f1/src/bin/adc.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/stm32f1/src/bin/blinky.rs b/examples/stm32f1/src/bin/blinky.rs index 3425b0536..cc43f85f4 100644 --- a/examples/stm32f1/src/bin/blinky.rs +++ b/examples/stm32f1/src/bin/blinky.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/stm32f1/src/bin/can.rs b/examples/stm32f1/src/bin/can.rs index a5ce819d4..c1c4f8359 100644 --- a/examples/stm32f1/src/bin/can.rs +++ b/examples/stm32f1/src/bin/can.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/stm32f1/src/bin/hello.rs b/examples/stm32f1/src/bin/hello.rs index e63bcaae0..7b761ecc1 100644 --- a/examples/stm32f1/src/bin/hello.rs +++ b/examples/stm32f1/src/bin/hello.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::info; use embassy_executor::Spawner; diff --git a/examples/stm32f1/src/bin/usb_serial.rs b/examples/stm32f1/src/bin/usb_serial.rs index 31519555f..e28381893 100644 --- a/examples/stm32f1/src/bin/usb_serial.rs +++ b/examples/stm32f1/src/bin/usb_serial.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::{panic, *}; use embassy_executor::Spawner; diff --git a/examples/stm32f2/Cargo.toml b/examples/stm32f2/Cargo.toml index 66cc1e15b..eaaadeec5 100644 --- a/examples/stm32f2/Cargo.toml +++ b/examples/stm32f2/Cargo.toml @@ -8,7 +8,7 @@ license = "MIT OR Apache-2.0" # Change stm32f207zg to your chip name, if necessary. embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = [ "defmt", "stm32f207zg", "unstable-pac", "memory-x", "time-driver-any", "exti"] } embassy-sync = { version = "0.5.0", path = "../../embassy-sync", features = ["defmt"] } -embassy-executor = { version = "0.4.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } +embassy-executor = { version = "0.4.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } embassy-time = { version = "0.2", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } defmt = "0.3" diff --git a/examples/stm32f2/src/bin/blinky.rs b/examples/stm32f2/src/bin/blinky.rs index f6d7a0005..d9833ba8b 100644 --- a/examples/stm32f2/src/bin/blinky.rs +++ b/examples/stm32f2/src/bin/blinky.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/stm32f2/src/bin/pll.rs b/examples/stm32f2/src/bin/pll.rs index aae7637dc..e32f283d1 100644 --- a/examples/stm32f2/src/bin/pll.rs +++ b/examples/stm32f2/src/bin/pll.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use core::convert::TryFrom; diff --git a/examples/stm32f3/Cargo.toml b/examples/stm32f3/Cargo.toml index ed1367858..d5ab0b25a 100644 --- a/examples/stm32f3/Cargo.toml +++ b/examples/stm32f3/Cargo.toml @@ -8,7 +8,7 @@ license = "MIT OR Apache-2.0" # Change stm32f303ze to your chip name, if necessary. embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = [ "defmt", "stm32f303ze", "unstable-pac", "memory-x", "time-driver-any", "exti"] } embassy-sync = { version = "0.5.0", path = "../../embassy-sync", features = ["defmt"] } -embassy-executor = { version = "0.4.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "executor-interrupt", "defmt", "integrated-timers"] } +embassy-executor = { version = "0.4.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "executor-interrupt", "defmt", "integrated-timers"] } embassy-time = { version = "0.2", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] } embassy-futures = { version = "0.1.0", path = "../../embassy-futures" } @@ -24,7 +24,7 @@ futures = { version = "0.3.17", default-features = false, features = ["async-awa heapless = { version = "0.8", default-features = false } nb = "1.0.0" embedded-storage = "0.3.1" -static_cell = { version = "2", features = ["nightly"]} +static_cell = "2" [profile.release] debug = 2 diff --git a/examples/stm32f3/src/bin/blinky.rs b/examples/stm32f3/src/bin/blinky.rs index e71031b30..0ea10522d 100644 --- a/examples/stm32f3/src/bin/blinky.rs +++ b/examples/stm32f3/src/bin/blinky.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/stm32f3/src/bin/button.rs b/examples/stm32f3/src/bin/button.rs index 2f47d8f80..2cd356787 100644 --- a/examples/stm32f3/src/bin/button.rs +++ b/examples/stm32f3/src/bin/button.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use cortex_m_rt::entry; use defmt::*; diff --git a/examples/stm32f3/src/bin/button_events.rs b/examples/stm32f3/src/bin/button_events.rs index 9df6d680d..2f7da4ef5 100644 --- a/examples/stm32f3/src/bin/button_events.rs +++ b/examples/stm32f3/src/bin/button_events.rs @@ -8,7 +8,6 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/stm32f3/src/bin/button_exti.rs b/examples/stm32f3/src/bin/button_exti.rs index 1266778c1..86ff68492 100644 --- a/examples/stm32f3/src/bin/button_exti.rs +++ b/examples/stm32f3/src/bin/button_exti.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/stm32f3/src/bin/flash.rs b/examples/stm32f3/src/bin/flash.rs index 236fb36c1..28125697d 100644 --- a/examples/stm32f3/src/bin/flash.rs +++ b/examples/stm32f3/src/bin/flash.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::{info, unwrap}; use embassy_executor::Spawner; diff --git a/examples/stm32f3/src/bin/hello.rs b/examples/stm32f3/src/bin/hello.rs index b3285f3c1..fd54da53d 100644 --- a/examples/stm32f3/src/bin/hello.rs +++ b/examples/stm32f3/src/bin/hello.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::info; use embassy_executor::Spawner; diff --git a/examples/stm32f3/src/bin/multiprio.rs b/examples/stm32f3/src/bin/multiprio.rs index 74f3bb1c5..328447210 100644 --- a/examples/stm32f3/src/bin/multiprio.rs +++ b/examples/stm32f3/src/bin/multiprio.rs @@ -55,7 +55,6 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use cortex_m_rt::entry; use defmt::*; diff --git a/examples/stm32f3/src/bin/spi_dma.rs b/examples/stm32f3/src/bin/spi_dma.rs index a27c1d547..54498d53d 100644 --- a/examples/stm32f3/src/bin/spi_dma.rs +++ b/examples/stm32f3/src/bin/spi_dma.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use core::fmt::Write; use core::str::from_utf8; diff --git a/examples/stm32f3/src/bin/usart_dma.rs b/examples/stm32f3/src/bin/usart_dma.rs index ce8c212ae..5234e53b9 100644 --- a/examples/stm32f3/src/bin/usart_dma.rs +++ b/examples/stm32f3/src/bin/usart_dma.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use core::fmt::Write; diff --git a/examples/stm32f3/src/bin/usb_serial.rs b/examples/stm32f3/src/bin/usb_serial.rs index d5d068d62..cf9ecedfa 100644 --- a/examples/stm32f3/src/bin/usb_serial.rs +++ b/examples/stm32f3/src/bin/usb_serial.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::{panic, *}; use embassy_executor::Spawner; diff --git a/examples/stm32f334/Cargo.toml b/examples/stm32f334/Cargo.toml index 320cf7d7b..b29a08e7c 100644 --- a/examples/stm32f334/Cargo.toml +++ b/examples/stm32f334/Cargo.toml @@ -6,7 +6,7 @@ license = "MIT OR Apache-2.0" [dependencies] embassy-sync = { version = "0.5.0", path = "../../embassy-sync", features = ["defmt"] } -embassy-executor = { version = "0.4.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "executor-interrupt", "defmt", "integrated-timers"] } +embassy-executor = { version = "0.4.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "executor-interrupt", "defmt", "integrated-timers"] } embassy-time = { version = "0.2.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = [ "defmt", "stm32f334r8", "unstable-pac", "memory-x", "time-driver-any", "exti"] } embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] } @@ -23,4 +23,4 @@ futures = { version = "0.3.17", default-features = false, features = ["async-awa heapless = { version = "0.8", default-features = false } nb = "1.0.0" embedded-storage = "0.3.1" -static_cell = { version = "2", features = ["nightly"]} +static_cell = "2" diff --git a/examples/stm32f334/src/bin/adc.rs b/examples/stm32f334/src/bin/adc.rs index f259135d2..063ee9dac 100644 --- a/examples/stm32f334/src/bin/adc.rs +++ b/examples/stm32f334/src/bin/adc.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::info; use embassy_executor::Spawner; diff --git a/examples/stm32f334/src/bin/button.rs b/examples/stm32f334/src/bin/button.rs index 501fb080c..256f9a44a 100644 --- a/examples/stm32f334/src/bin/button.rs +++ b/examples/stm32f334/src/bin/button.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/stm32f334/src/bin/hello.rs b/examples/stm32f334/src/bin/hello.rs index b3285f3c1..fd54da53d 100644 --- a/examples/stm32f334/src/bin/hello.rs +++ b/examples/stm32f334/src/bin/hello.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::info; use embassy_executor::Spawner; diff --git a/examples/stm32f334/src/bin/opamp.rs b/examples/stm32f334/src/bin/opamp.rs index 10e7b3543..850a0e335 100644 --- a/examples/stm32f334/src/bin/opamp.rs +++ b/examples/stm32f334/src/bin/opamp.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::info; use embassy_executor::Spawner; diff --git a/examples/stm32f334/src/bin/pwm.rs b/examples/stm32f334/src/bin/pwm.rs index 8040c3f18..c149cad92 100644 --- a/examples/stm32f334/src/bin/pwm.rs +++ b/examples/stm32f334/src/bin/pwm.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/stm32f4/Cargo.toml b/examples/stm32f4/Cargo.toml index e24fbee82..a74e0f674 100644 --- a/examples/stm32f4/Cargo.toml +++ b/examples/stm32f4/Cargo.toml @@ -8,7 +8,7 @@ license = "MIT OR Apache-2.0" # Change stm32f429zi to your chip name, if necessary. embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = [ "defmt", "stm32f429zi", "unstable-pac", "memory-x", "time-driver-any", "exti", "chrono"] } embassy-sync = { version = "0.5.0", path = "../../embassy-sync", features = ["defmt"] } -embassy-executor = { version = "0.4.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "executor-interrupt", "defmt", "integrated-timers"] } +embassy-executor = { version = "0.4.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "executor-interrupt", "defmt", "integrated-timers"] } embassy-time = { version = "0.2", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt" ] } embassy-net = { version = "0.2.0", path = "../../embassy-net", features = ["defmt", "tcp", "dhcpv4", "medium-ethernet", ] } @@ -27,7 +27,7 @@ heapless = { version = "0.8", default-features = false } nb = "1.0.0" embedded-storage = "0.3.1" micromath = "2.0.0" -static_cell = { version = "2", features = ["nightly"]} +static_cell = "2" chrono = { version = "^0.4", default-features = false} [profile.release] diff --git a/examples/stm32f4/src/bin/adc.rs b/examples/stm32f4/src/bin/adc.rs index f19328727..699c29c05 100644 --- a/examples/stm32f4/src/bin/adc.rs +++ b/examples/stm32f4/src/bin/adc.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use cortex_m::prelude::_embedded_hal_blocking_delay_DelayUs; use defmt::*; diff --git a/examples/stm32f4/src/bin/blinky.rs b/examples/stm32f4/src/bin/blinky.rs index 4bfc5a50d..31cce8225 100644 --- a/examples/stm32f4/src/bin/blinky.rs +++ b/examples/stm32f4/src/bin/blinky.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/stm32f4/src/bin/button.rs b/examples/stm32f4/src/bin/button.rs index aa1eed46f..ad30a56a2 100644 --- a/examples/stm32f4/src/bin/button.rs +++ b/examples/stm32f4/src/bin/button.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use cortex_m_rt::entry; use defmt::*; diff --git a/examples/stm32f4/src/bin/button_exti.rs b/examples/stm32f4/src/bin/button_exti.rs index dfe587d41..67751187d 100644 --- a/examples/stm32f4/src/bin/button_exti.rs +++ b/examples/stm32f4/src/bin/button_exti.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/stm32f4/src/bin/can.rs b/examples/stm32f4/src/bin/can.rs index 20ce4edce..d074b4265 100644 --- a/examples/stm32f4/src/bin/can.rs +++ b/examples/stm32f4/src/bin/can.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/stm32f4/src/bin/dac.rs b/examples/stm32f4/src/bin/dac.rs index 8f14d6078..9c7754c4f 100644 --- a/examples/stm32f4/src/bin/dac.rs +++ b/examples/stm32f4/src/bin/dac.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/stm32f4/src/bin/eth.rs b/examples/stm32f4/src/bin/eth.rs index 17a14aac4..7f5c8fdb1 100644 --- a/examples/stm32f4/src/bin/eth.rs +++ b/examples/stm32f4/src/bin/eth.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/stm32f4/src/bin/flash.rs b/examples/stm32f4/src/bin/flash.rs index 56a35ddee..1e8cabab4 100644 --- a/examples/stm32f4/src/bin/flash.rs +++ b/examples/stm32f4/src/bin/flash.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::{info, unwrap}; use embassy_executor::Spawner; diff --git a/examples/stm32f4/src/bin/flash_async.rs b/examples/stm32f4/src/bin/flash_async.rs index 1624d842e..493a536f3 100644 --- a/examples/stm32f4/src/bin/flash_async.rs +++ b/examples/stm32f4/src/bin/flash_async.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::{info, unwrap}; use embassy_executor::Spawner; diff --git a/examples/stm32f4/src/bin/hello.rs b/examples/stm32f4/src/bin/hello.rs index a2a287110..3c295612c 100644 --- a/examples/stm32f4/src/bin/hello.rs +++ b/examples/stm32f4/src/bin/hello.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::info; use embassy_executor::Spawner; diff --git a/examples/stm32f4/src/bin/i2c.rs b/examples/stm32f4/src/bin/i2c.rs index 4f4adde28..4b5da774d 100644 --- a/examples/stm32f4/src/bin/i2c.rs +++ b/examples/stm32f4/src/bin/i2c.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/stm32f4/src/bin/i2c_async.rs b/examples/stm32f4/src/bin/i2c_async.rs index 9f59e4d41..90d11d4b4 100644 --- a/examples/stm32f4/src/bin/i2c_async.rs +++ b/examples/stm32f4/src/bin/i2c_async.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] // Example originally designed for stm32f411ceu6 reading an A1454 hall effect sensor on I2C1 // DMA peripherals changed to compile for stm32f429zi, for the CI. diff --git a/examples/stm32f4/src/bin/i2c_comparison.rs b/examples/stm32f4/src/bin/i2c_comparison.rs index 6d23c0ed8..30cfbdf57 100644 --- a/examples/stm32f4/src/bin/i2c_comparison.rs +++ b/examples/stm32f4/src/bin/i2c_comparison.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] // Example originally designed for stm32f411ceu6 with three A1454 hall effect sensors, connected to I2C1, 2 and 3 // on the pins referenced in the peripheral definitions. diff --git a/examples/stm32f4/src/bin/i2s_dma.rs b/examples/stm32f4/src/bin/i2s_dma.rs index e8d7b5f77..97a04b2aa 100644 --- a/examples/stm32f4/src/bin/i2s_dma.rs +++ b/examples/stm32f4/src/bin/i2s_dma.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use core::fmt::Write; diff --git a/examples/stm32f4/src/bin/mco.rs b/examples/stm32f4/src/bin/mco.rs index 3315e7652..eb7bb6261 100644 --- a/examples/stm32f4/src/bin/mco.rs +++ b/examples/stm32f4/src/bin/mco.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/stm32f4/src/bin/multiprio.rs b/examples/stm32f4/src/bin/multiprio.rs index 74f3bb1c5..328447210 100644 --- a/examples/stm32f4/src/bin/multiprio.rs +++ b/examples/stm32f4/src/bin/multiprio.rs @@ -55,7 +55,6 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use cortex_m_rt::entry; use defmt::*; diff --git a/examples/stm32f4/src/bin/pwm.rs b/examples/stm32f4/src/bin/pwm.rs index 8e41d0e78..8844a9f0e 100644 --- a/examples/stm32f4/src/bin/pwm.rs +++ b/examples/stm32f4/src/bin/pwm.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/stm32f4/src/bin/pwm_complementary.rs b/examples/stm32f4/src/bin/pwm_complementary.rs index d925f26d9..161f43c48 100644 --- a/examples/stm32f4/src/bin/pwm_complementary.rs +++ b/examples/stm32f4/src/bin/pwm_complementary.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/stm32f4/src/bin/rtc.rs b/examples/stm32f4/src/bin/rtc.rs index 44b4303c0..abab07b6b 100644 --- a/examples/stm32f4/src/bin/rtc.rs +++ b/examples/stm32f4/src/bin/rtc.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use chrono::{NaiveDate, NaiveDateTime}; use defmt::*; diff --git a/examples/stm32f4/src/bin/sdmmc.rs b/examples/stm32f4/src/bin/sdmmc.rs index 91747b2d5..66e4e527c 100644 --- a/examples/stm32f4/src/bin/sdmmc.rs +++ b/examples/stm32f4/src/bin/sdmmc.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/stm32f4/src/bin/spi.rs b/examples/stm32f4/src/bin/spi.rs index 0919e9874..dc9141c62 100644 --- a/examples/stm32f4/src/bin/spi.rs +++ b/examples/stm32f4/src/bin/spi.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use cortex_m_rt::entry; use defmt::*; diff --git a/examples/stm32f4/src/bin/spi_dma.rs b/examples/stm32f4/src/bin/spi_dma.rs index f291f7dba..7249c831a 100644 --- a/examples/stm32f4/src/bin/spi_dma.rs +++ b/examples/stm32f4/src/bin/spi_dma.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use core::fmt::Write; use core::str::from_utf8; diff --git a/examples/stm32f4/src/bin/usart.rs b/examples/stm32f4/src/bin/usart.rs index 45e94715f..40d9d70f1 100644 --- a/examples/stm32f4/src/bin/usart.rs +++ b/examples/stm32f4/src/bin/usart.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use cortex_m_rt::entry; use defmt::*; diff --git a/examples/stm32f4/src/bin/usart_buffered.rs b/examples/stm32f4/src/bin/usart_buffered.rs index 71abc2893..c99807f11 100644 --- a/examples/stm32f4/src/bin/usart_buffered.rs +++ b/examples/stm32f4/src/bin/usart_buffered.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/stm32f4/src/bin/usart_dma.rs b/examples/stm32f4/src/bin/usart_dma.rs index dca25a78c..dd6de599c 100644 --- a/examples/stm32f4/src/bin/usart_dma.rs +++ b/examples/stm32f4/src/bin/usart_dma.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use core::fmt::Write; diff --git a/examples/stm32f4/src/bin/usb_ethernet.rs b/examples/stm32f4/src/bin/usb_ethernet.rs index 57ee35e97..a196259a8 100644 --- a/examples/stm32f4/src/bin/usb_ethernet.rs +++ b/examples/stm32f4/src/bin/usb_ethernet.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/stm32f4/src/bin/usb_raw.rs b/examples/stm32f4/src/bin/usb_raw.rs index 719b22bb9..afff55187 100644 --- a/examples/stm32f4/src/bin/usb_raw.rs +++ b/examples/stm32f4/src/bin/usb_raw.rs @@ -48,7 +48,6 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/stm32f4/src/bin/usb_serial.rs b/examples/stm32f4/src/bin/usb_serial.rs index e2ccc9142..58d994a61 100644 --- a/examples/stm32f4/src/bin/usb_serial.rs +++ b/examples/stm32f4/src/bin/usb_serial.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::{panic, *}; use embassy_executor::Spawner; diff --git a/examples/stm32f4/src/bin/wdt.rs b/examples/stm32f4/src/bin/wdt.rs index 0443b61c5..ea27ebce0 100644 --- a/examples/stm32f4/src/bin/wdt.rs +++ b/examples/stm32f4/src/bin/wdt.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/stm32f4/src/bin/ws2812_pwm_dma.rs b/examples/stm32f4/src/bin/ws2812_pwm_dma.rs index 39f5d3421..9835c07e4 100644 --- a/examples/stm32f4/src/bin/ws2812_pwm_dma.rs +++ b/examples/stm32f4/src/bin/ws2812_pwm_dma.rs @@ -8,7 +8,6 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use embassy_executor::Spawner; use embassy_stm32::gpio::OutputType; diff --git a/examples/stm32f7/Cargo.toml b/examples/stm32f7/Cargo.toml index 4cca0d93c..b76a848a8 100644 --- a/examples/stm32f7/Cargo.toml +++ b/examples/stm32f7/Cargo.toml @@ -8,7 +8,7 @@ license = "MIT OR Apache-2.0" # Change stm32f767zi to your chip name, if necessary. embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["defmt", "stm32f767zi", "memory-x", "unstable-pac", "time-driver-any", "exti"] } embassy-sync = { version = "0.5.0", path = "../../embassy-sync", features = ["defmt"] } -embassy-executor = { version = "0.4.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } +embassy-executor = { version = "0.4.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } embassy-time = { version = "0.2", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } embassy-net = { version = "0.2.0", path = "../../embassy-net", features = ["defmt", "tcp", "dhcpv4", "medium-ethernet"] } embedded-io-async = { version = "0.6.1" } @@ -27,7 +27,7 @@ nb = "1.0.0" rand_core = "0.6.3" critical-section = "1.1" embedded-storage = "0.3.1" -static_cell = { version = "2", features = ["nightly"]} +static_cell = "2" [profile.release] debug = 2 diff --git a/examples/stm32f7/src/bin/adc.rs b/examples/stm32f7/src/bin/adc.rs index 48c59eaf0..f8d7b691f 100644 --- a/examples/stm32f7/src/bin/adc.rs +++ b/examples/stm32f7/src/bin/adc.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/stm32f7/src/bin/blinky.rs b/examples/stm32f7/src/bin/blinky.rs index 4bfc5a50d..31cce8225 100644 --- a/examples/stm32f7/src/bin/blinky.rs +++ b/examples/stm32f7/src/bin/blinky.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/stm32f7/src/bin/button.rs b/examples/stm32f7/src/bin/button.rs index aa1eed46f..ad30a56a2 100644 --- a/examples/stm32f7/src/bin/button.rs +++ b/examples/stm32f7/src/bin/button.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use cortex_m_rt::entry; use defmt::*; diff --git a/examples/stm32f7/src/bin/button_exti.rs b/examples/stm32f7/src/bin/button_exti.rs index dfe587d41..67751187d 100644 --- a/examples/stm32f7/src/bin/button_exti.rs +++ b/examples/stm32f7/src/bin/button_exti.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/stm32f7/src/bin/can.rs b/examples/stm32f7/src/bin/can.rs index 06cd1ac7e..bcfdb67a8 100644 --- a/examples/stm32f7/src/bin/can.rs +++ b/examples/stm32f7/src/bin/can.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/stm32f7/src/bin/eth.rs b/examples/stm32f7/src/bin/eth.rs index 86c709852..5bff48197 100644 --- a/examples/stm32f7/src/bin/eth.rs +++ b/examples/stm32f7/src/bin/eth.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/stm32f7/src/bin/flash.rs b/examples/stm32f7/src/bin/flash.rs index 06a94f1c8..885570478 100644 --- a/examples/stm32f7/src/bin/flash.rs +++ b/examples/stm32f7/src/bin/flash.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::{info, unwrap}; use embassy_executor::Spawner; diff --git a/examples/stm32f7/src/bin/hello.rs b/examples/stm32f7/src/bin/hello.rs index a2a287110..3c295612c 100644 --- a/examples/stm32f7/src/bin/hello.rs +++ b/examples/stm32f7/src/bin/hello.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::info; use embassy_executor::Spawner; diff --git a/examples/stm32f7/src/bin/sdmmc.rs b/examples/stm32f7/src/bin/sdmmc.rs index 990de0ab1..6d36ef518 100644 --- a/examples/stm32f7/src/bin/sdmmc.rs +++ b/examples/stm32f7/src/bin/sdmmc.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/stm32f7/src/bin/usart_dma.rs b/examples/stm32f7/src/bin/usart_dma.rs index ba064081e..fb604b34f 100644 --- a/examples/stm32f7/src/bin/usart_dma.rs +++ b/examples/stm32f7/src/bin/usart_dma.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use core::fmt::Write; diff --git a/examples/stm32f7/src/bin/usb_serial.rs b/examples/stm32f7/src/bin/usb_serial.rs index 4991edbf0..97daf6bd1 100644 --- a/examples/stm32f7/src/bin/usb_serial.rs +++ b/examples/stm32f7/src/bin/usb_serial.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::{panic, *}; use embassy_executor::Spawner; diff --git a/examples/stm32g0/Cargo.toml b/examples/stm32g0/Cargo.toml index b1e749440..0abc0a638 100644 --- a/examples/stm32g0/Cargo.toml +++ b/examples/stm32g0/Cargo.toml @@ -8,7 +8,7 @@ license = "MIT OR Apache-2.0" # Change stm32g071rb to your chip name, if necessary. embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = [ "defmt", "time-driver-any", "stm32g071rb", "memory-x", "unstable-pac", "exti"] } embassy-sync = { version = "0.5.0", path = "../../embassy-sync", features = ["defmt"] } -embassy-executor = { version = "0.4.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } +embassy-executor = { version = "0.4.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } embassy-time = { version = "0.2", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } defmt = "0.3" diff --git a/examples/stm32g0/src/bin/blinky.rs b/examples/stm32g0/src/bin/blinky.rs index 4bfc5a50d..31cce8225 100644 --- a/examples/stm32g0/src/bin/blinky.rs +++ b/examples/stm32g0/src/bin/blinky.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/stm32g0/src/bin/button.rs b/examples/stm32g0/src/bin/button.rs index 40c58013b..265200132 100644 --- a/examples/stm32g0/src/bin/button.rs +++ b/examples/stm32g0/src/bin/button.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use cortex_m_rt::entry; use defmt::*; diff --git a/examples/stm32g0/src/bin/button_exti.rs b/examples/stm32g0/src/bin/button_exti.rs index ef32d4c4a..1e970fdd6 100644 --- a/examples/stm32g0/src/bin/button_exti.rs +++ b/examples/stm32g0/src/bin/button_exti.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/stm32g0/src/bin/flash.rs b/examples/stm32g0/src/bin/flash.rs index ed9f2e843..acef87b92 100644 --- a/examples/stm32g0/src/bin/flash.rs +++ b/examples/stm32g0/src/bin/flash.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/stm32g0/src/bin/spi_neopixel.rs b/examples/stm32g0/src/bin/spi_neopixel.rs index 214462d0e..c5ea51721 100644 --- a/examples/stm32g0/src/bin/spi_neopixel.rs +++ b/examples/stm32g0/src/bin/spi_neopixel.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/stm32g4/Cargo.toml b/examples/stm32g4/Cargo.toml index c56a63623..987f23b3a 100644 --- a/examples/stm32g4/Cargo.toml +++ b/examples/stm32g4/Cargo.toml @@ -8,7 +8,7 @@ license = "MIT OR Apache-2.0" # Change stm32g491re to your chip name, if necessary. embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = [ "defmt", "time-driver-any", "stm32g491re", "memory-x", "unstable-pac", "exti"] } embassy-sync = { version = "0.5.0", path = "../../embassy-sync", features = ["defmt"] } -embassy-executor = { version = "0.4.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } +embassy-executor = { version = "0.4.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } embassy-time = { version = "0.2", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] } embassy-futures = { version = "0.1.0", path = "../../embassy-futures" } diff --git a/examples/stm32g4/src/bin/adc.rs b/examples/stm32g4/src/bin/adc.rs index 63b20c0d4..35324d931 100644 --- a/examples/stm32g4/src/bin/adc.rs +++ b/examples/stm32g4/src/bin/adc.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/stm32g4/src/bin/blinky.rs b/examples/stm32g4/src/bin/blinky.rs index cbeb0dee1..90e479aae 100644 --- a/examples/stm32g4/src/bin/blinky.rs +++ b/examples/stm32g4/src/bin/blinky.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/stm32g4/src/bin/button.rs b/examples/stm32g4/src/bin/button.rs index 127efb08a..6f3db0819 100644 --- a/examples/stm32g4/src/bin/button.rs +++ b/examples/stm32g4/src/bin/button.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use cortex_m_rt::entry; use defmt::*; diff --git a/examples/stm32g4/src/bin/button_exti.rs b/examples/stm32g4/src/bin/button_exti.rs index dfe587d41..67751187d 100644 --- a/examples/stm32g4/src/bin/button_exti.rs +++ b/examples/stm32g4/src/bin/button_exti.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/stm32g4/src/bin/pll.rs b/examples/stm32g4/src/bin/pll.rs index 09ef59d44..46ebe0b0d 100644 --- a/examples/stm32g4/src/bin/pll.rs +++ b/examples/stm32g4/src/bin/pll.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/stm32g4/src/bin/pwm.rs b/examples/stm32g4/src/bin/pwm.rs index a84394005..d4809a481 100644 --- a/examples/stm32g4/src/bin/pwm.rs +++ b/examples/stm32g4/src/bin/pwm.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/stm32g4/src/bin/usb_serial.rs b/examples/stm32g4/src/bin/usb_serial.rs index 565b25d60..c26fa76b7 100644 --- a/examples/stm32g4/src/bin/usb_serial.rs +++ b/examples/stm32g4/src/bin/usb_serial.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::{panic, *}; use embassy_executor::Spawner; diff --git a/examples/stm32h5/Cargo.toml b/examples/stm32h5/Cargo.toml index f714a3984..8815b8e47 100644 --- a/examples/stm32h5/Cargo.toml +++ b/examples/stm32h5/Cargo.toml @@ -8,7 +8,7 @@ license = "MIT OR Apache-2.0" # Change stm32h563zi to your chip name, if necessary. embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = [ "defmt", "stm32h563zi", "memory-x", "time-driver-any", "exti", "unstable-pac"] } embassy-sync = { version = "0.5.0", path = "../../embassy-sync", features = ["defmt"] } -embassy-executor = { version = "0.4.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } +embassy-executor = { version = "0.4.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } embassy-time = { version = "0.2", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } embassy-net = { version = "0.2.0", path = "../../embassy-net", features = ["defmt", "tcp", "dhcpv4", "medium-ethernet", "proto-ipv6"] } embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] } @@ -31,7 +31,7 @@ critical-section = "1.1" micromath = "2.0.0" stm32-fmc = "0.3.0" embedded-storage = "0.3.1" -static_cell = { version = "2", features = ["nightly"]} +static_cell = "2" # cargo build/run [profile.dev] diff --git a/examples/stm32h5/src/bin/blinky.rs b/examples/stm32h5/src/bin/blinky.rs index 1394f03fa..f37e8b1d8 100644 --- a/examples/stm32h5/src/bin/blinky.rs +++ b/examples/stm32h5/src/bin/blinky.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/stm32h5/src/bin/button_exti.rs b/examples/stm32h5/src/bin/button_exti.rs index dfe587d41..67751187d 100644 --- a/examples/stm32h5/src/bin/button_exti.rs +++ b/examples/stm32h5/src/bin/button_exti.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/stm32h5/src/bin/eth.rs b/examples/stm32h5/src/bin/eth.rs index 8789e4e0b..2370656e6 100644 --- a/examples/stm32h5/src/bin/eth.rs +++ b/examples/stm32h5/src/bin/eth.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/stm32h5/src/bin/i2c.rs b/examples/stm32h5/src/bin/i2c.rs index 31783a2bf..31e83cbb5 100644 --- a/examples/stm32h5/src/bin/i2c.rs +++ b/examples/stm32h5/src/bin/i2c.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/stm32h5/src/bin/rng.rs b/examples/stm32h5/src/bin/rng.rs index 7c8c50eca..9c0d704b5 100644 --- a/examples/stm32h5/src/bin/rng.rs +++ b/examples/stm32h5/src/bin/rng.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/stm32h5/src/bin/usart.rs b/examples/stm32h5/src/bin/usart.rs index db04d4e55..f9cbad6af 100644 --- a/examples/stm32h5/src/bin/usart.rs +++ b/examples/stm32h5/src/bin/usart.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use cortex_m_rt::entry; use defmt::*; diff --git a/examples/stm32h5/src/bin/usart_dma.rs b/examples/stm32h5/src/bin/usart_dma.rs index bafe50839..caae0dd18 100644 --- a/examples/stm32h5/src/bin/usart_dma.rs +++ b/examples/stm32h5/src/bin/usart_dma.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use core::fmt::Write; diff --git a/examples/stm32h5/src/bin/usart_split.rs b/examples/stm32h5/src/bin/usart_split.rs index d9037c014..92047de8d 100644 --- a/examples/stm32h5/src/bin/usart_split.rs +++ b/examples/stm32h5/src/bin/usart_split.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/stm32h5/src/bin/usb_serial.rs b/examples/stm32h5/src/bin/usb_serial.rs index 7d45818af..208493d8c 100644 --- a/examples/stm32h5/src/bin/usb_serial.rs +++ b/examples/stm32h5/src/bin/usb_serial.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::{panic, *}; use embassy_executor::Spawner; diff --git a/examples/stm32h7/Cargo.toml b/examples/stm32h7/Cargo.toml index c6aea3e11..31feeda45 100644 --- a/examples/stm32h7/Cargo.toml +++ b/examples/stm32h7/Cargo.toml @@ -8,7 +8,7 @@ license = "MIT OR Apache-2.0" # Change stm32h743bi to your chip name, if necessary. embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["defmt", "stm32h743bi", "time-driver-any", "exti", "memory-x", "unstable-pac", "chrono"] } embassy-sync = { version = "0.5.0", path = "../../embassy-sync", features = ["defmt"] } -embassy-executor = { version = "0.4.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } +embassy-executor = { version = "0.4.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } embassy-time = { version = "0.2", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } embassy-net = { version = "0.2.0", path = "../../embassy-net", features = ["defmt", "tcp", "dhcpv4", "medium-ethernet", "proto-ipv6", "dns"] } embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] } @@ -31,7 +31,7 @@ critical-section = "1.1" micromath = "2.0.0" stm32-fmc = "0.3.0" embedded-storage = "0.3.1" -static_cell = { version = "2", features = ["nightly"]} +static_cell = "2" chrono = { version = "^0.4", default-features = false } # cargo build/run diff --git a/examples/stm32h7/src/bin/adc.rs b/examples/stm32h7/src/bin/adc.rs index e367827e9..fe6fe69a1 100644 --- a/examples/stm32h7/src/bin/adc.rs +++ b/examples/stm32h7/src/bin/adc.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/stm32h7/src/bin/blinky.rs b/examples/stm32h7/src/bin/blinky.rs index a9cab1ff4..1ee90a870 100644 --- a/examples/stm32h7/src/bin/blinky.rs +++ b/examples/stm32h7/src/bin/blinky.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/stm32h7/src/bin/button_exti.rs b/examples/stm32h7/src/bin/button_exti.rs index dfe587d41..67751187d 100644 --- a/examples/stm32h7/src/bin/button_exti.rs +++ b/examples/stm32h7/src/bin/button_exti.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/stm32h7/src/bin/camera.rs b/examples/stm32h7/src/bin/camera.rs index 489fb03dd..e5a104baf 100644 --- a/examples/stm32h7/src/bin/camera.rs +++ b/examples/stm32h7/src/bin/camera.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use embassy_executor::Spawner; use embassy_stm32::dcmi::{self, *}; diff --git a/examples/stm32h7/src/bin/dac.rs b/examples/stm32h7/src/bin/dac.rs index f66268151..a9bf46de0 100644 --- a/examples/stm32h7/src/bin/dac.rs +++ b/examples/stm32h7/src/bin/dac.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use cortex_m_rt::entry; use defmt::*; diff --git a/examples/stm32h7/src/bin/dac_dma.rs b/examples/stm32h7/src/bin/dac_dma.rs index c19fdd623..1481dd967 100644 --- a/examples/stm32h7/src/bin/dac_dma.rs +++ b/examples/stm32h7/src/bin/dac_dma.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/stm32h7/src/bin/eth.rs b/examples/stm32h7/src/bin/eth.rs index a64b3253a..cd9a27fcd 100644 --- a/examples/stm32h7/src/bin/eth.rs +++ b/examples/stm32h7/src/bin/eth.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/stm32h7/src/bin/eth_client.rs b/examples/stm32h7/src/bin/eth_client.rs index 8e84d9964..dcc6e36e2 100644 --- a/examples/stm32h7/src/bin/eth_client.rs +++ b/examples/stm32h7/src/bin/eth_client.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/stm32h7/src/bin/flash.rs b/examples/stm32h7/src/bin/flash.rs index 89c0c8a66..4f9f6bb0a 100644 --- a/examples/stm32h7/src/bin/flash.rs +++ b/examples/stm32h7/src/bin/flash.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::{info, unwrap}; use embassy_executor::Spawner; diff --git a/examples/stm32h7/src/bin/fmc.rs b/examples/stm32h7/src/bin/fmc.rs index 54e2c3629..5e5e6ccc8 100644 --- a/examples/stm32h7/src/bin/fmc.rs +++ b/examples/stm32h7/src/bin/fmc.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/stm32h7/src/bin/i2c.rs b/examples/stm32h7/src/bin/i2c.rs index aea21ec6f..3bf39eb44 100644 --- a/examples/stm32h7/src/bin/i2c.rs +++ b/examples/stm32h7/src/bin/i2c.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/stm32h7/src/bin/low_level_timer_api.rs b/examples/stm32h7/src/bin/low_level_timer_api.rs index 394ed3281..cc508c3cf 100644 --- a/examples/stm32h7/src/bin/low_level_timer_api.rs +++ b/examples/stm32h7/src/bin/low_level_timer_api.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/stm32h7/src/bin/mco.rs b/examples/stm32h7/src/bin/mco.rs index c023f4584..a6ee27625 100644 --- a/examples/stm32h7/src/bin/mco.rs +++ b/examples/stm32h7/src/bin/mco.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/stm32h7/src/bin/pwm.rs b/examples/stm32h7/src/bin/pwm.rs index c55d780a0..1e48ba67b 100644 --- a/examples/stm32h7/src/bin/pwm.rs +++ b/examples/stm32h7/src/bin/pwm.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/stm32h7/src/bin/rng.rs b/examples/stm32h7/src/bin/rng.rs index 1fb4cfec0..a9ef7200d 100644 --- a/examples/stm32h7/src/bin/rng.rs +++ b/examples/stm32h7/src/bin/rng.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/stm32h7/src/bin/rtc.rs b/examples/stm32h7/src/bin/rtc.rs index 78cea9c89..c6b9cf57e 100644 --- a/examples/stm32h7/src/bin/rtc.rs +++ b/examples/stm32h7/src/bin/rtc.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use chrono::{NaiveDate, NaiveDateTime}; use defmt::*; diff --git a/examples/stm32h7/src/bin/sdmmc.rs b/examples/stm32h7/src/bin/sdmmc.rs index be968ff77..abe2d4ba7 100644 --- a/examples/stm32h7/src/bin/sdmmc.rs +++ b/examples/stm32h7/src/bin/sdmmc.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/stm32h7/src/bin/signal.rs b/examples/stm32h7/src/bin/signal.rs index b5f583289..b73360f32 100644 --- a/examples/stm32h7/src/bin/signal.rs +++ b/examples/stm32h7/src/bin/signal.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::{info, unwrap}; use embassy_executor::Spawner; diff --git a/examples/stm32h7/src/bin/spi.rs b/examples/stm32h7/src/bin/spi.rs index a8db0ff77..aed27723a 100644 --- a/examples/stm32h7/src/bin/spi.rs +++ b/examples/stm32h7/src/bin/spi.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use core::fmt::Write; use core::str::from_utf8; diff --git a/examples/stm32h7/src/bin/spi_dma.rs b/examples/stm32h7/src/bin/spi_dma.rs index 561052e48..54d4d7656 100644 --- a/examples/stm32h7/src/bin/spi_dma.rs +++ b/examples/stm32h7/src/bin/spi_dma.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use core::fmt::Write; use core::str::from_utf8; diff --git a/examples/stm32h7/src/bin/usart.rs b/examples/stm32h7/src/bin/usart.rs index db04d4e55..f9cbad6af 100644 --- a/examples/stm32h7/src/bin/usart.rs +++ b/examples/stm32h7/src/bin/usart.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use cortex_m_rt::entry; use defmt::*; diff --git a/examples/stm32h7/src/bin/usart_dma.rs b/examples/stm32h7/src/bin/usart_dma.rs index 249050fd1..ae1f3a2e9 100644 --- a/examples/stm32h7/src/bin/usart_dma.rs +++ b/examples/stm32h7/src/bin/usart_dma.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use core::fmt::Write; diff --git a/examples/stm32h7/src/bin/usart_split.rs b/examples/stm32h7/src/bin/usart_split.rs index 61c9f1954..b98c40877 100644 --- a/examples/stm32h7/src/bin/usart_split.rs +++ b/examples/stm32h7/src/bin/usart_split.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/stm32h7/src/bin/usb_serial.rs b/examples/stm32h7/src/bin/usb_serial.rs index f80cf63ec..d81efb541 100644 --- a/examples/stm32h7/src/bin/usb_serial.rs +++ b/examples/stm32h7/src/bin/usb_serial.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::{panic, *}; use embassy_executor::Spawner; diff --git a/examples/stm32h7/src/bin/wdg.rs b/examples/stm32h7/src/bin/wdg.rs index 76fd9dfc0..a4184aa96 100644 --- a/examples/stm32h7/src/bin/wdg.rs +++ b/examples/stm32h7/src/bin/wdg.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/stm32l0/Cargo.toml b/examples/stm32l0/Cargo.toml index 7c8264739..739aa6cb1 100644 --- a/examples/stm32l0/Cargo.toml +++ b/examples/stm32l0/Cargo.toml @@ -4,10 +4,6 @@ name = "embassy-stm32l0-examples" version = "0.1.0" license = "MIT OR Apache-2.0" -[features] -default = ["nightly"] -nightly = ["embassy-executor/nightly"] - [dependencies] # Change stm32l072cz to your chip name, if necessary. embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["defmt", "stm32l072cz", "time-driver-any", "exti", "memory-x"] } diff --git a/examples/stm32l0/src/bin/blinky.rs b/examples/stm32l0/src/bin/blinky.rs index ea40bfc48..caca5759f 100644 --- a/examples/stm32l0/src/bin/blinky.rs +++ b/examples/stm32l0/src/bin/blinky.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/stm32l0/src/bin/button.rs b/examples/stm32l0/src/bin/button.rs index 3e56160e9..165a714a5 100644 --- a/examples/stm32l0/src/bin/button.rs +++ b/examples/stm32l0/src/bin/button.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/stm32l0/src/bin/button_exti.rs b/examples/stm32l0/src/bin/button_exti.rs index ffede253e..f517fce04 100644 --- a/examples/stm32l0/src/bin/button_exti.rs +++ b/examples/stm32l0/src/bin/button_exti.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/stm32l0/src/bin/flash.rs b/examples/stm32l0/src/bin/flash.rs index 86f6c70b9..1865748fd 100644 --- a/examples/stm32l0/src/bin/flash.rs +++ b/examples/stm32l0/src/bin/flash.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::{info, unwrap}; use embassy_executor::Spawner; diff --git a/examples/stm32l0/src/bin/spi.rs b/examples/stm32l0/src/bin/spi.rs index 583e3d127..f23a537b8 100644 --- a/examples/stm32l0/src/bin/spi.rs +++ b/examples/stm32l0/src/bin/spi.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/stm32l0/src/bin/usart_dma.rs b/examples/stm32l0/src/bin/usart_dma.rs index 62c9b5595..74889c838 100644 --- a/examples/stm32l0/src/bin/usart_dma.rs +++ b/examples/stm32l0/src/bin/usart_dma.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/stm32l0/src/bin/usart_irq.rs b/examples/stm32l0/src/bin/usart_irq.rs index 5107a1a0a..2c96a8bc2 100644 --- a/examples/stm32l0/src/bin/usart_irq.rs +++ b/examples/stm32l0/src/bin/usart_irq.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/stm32l1/Cargo.toml b/examples/stm32l1/Cargo.toml index 23dd0ef87..071d6a502 100644 --- a/examples/stm32l1/Cargo.toml +++ b/examples/stm32l1/Cargo.toml @@ -6,7 +6,7 @@ license = "MIT OR Apache-2.0" [dependencies] embassy-sync = { version = "0.5.0", path = "../../embassy-sync", features = ["defmt"] } -embassy-executor = { version = "0.4.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } +embassy-executor = { version = "0.4.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } embassy-time = { version = "0.2", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = [ "defmt", "stm32l151cb-a", "time-driver-any", "memory-x"] } diff --git a/examples/stm32l1/src/bin/blinky.rs b/examples/stm32l1/src/bin/blinky.rs index 06f732eb7..da6777b2d 100644 --- a/examples/stm32l1/src/bin/blinky.rs +++ b/examples/stm32l1/src/bin/blinky.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/stm32l1/src/bin/flash.rs b/examples/stm32l1/src/bin/flash.rs index aeb535cca..e9ce4eae8 100644 --- a/examples/stm32l1/src/bin/flash.rs +++ b/examples/stm32l1/src/bin/flash.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::{info, unwrap}; use embassy_executor::Spawner; diff --git a/examples/stm32l1/src/bin/spi.rs b/examples/stm32l1/src/bin/spi.rs index 905b4d75c..8be686c5a 100644 --- a/examples/stm32l1/src/bin/spi.rs +++ b/examples/stm32l1/src/bin/spi.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/stm32l4/Cargo.toml b/examples/stm32l4/Cargo.toml index 2861216d4..8a5fb5749 100644 --- a/examples/stm32l4/Cargo.toml +++ b/examples/stm32l4/Cargo.toml @@ -8,7 +8,7 @@ license = "MIT OR Apache-2.0" # Change stm32l4s5vi to your chip name, if necessary. embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = [ "defmt", "unstable-pac", "stm32l4s5qi", "memory-x", "time-driver-any", "exti", "chrono"] } embassy-sync = { version = "0.5.0", path = "../../embassy-sync", features = ["defmt"] } -embassy-executor = { version = "0.4.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } +embassy-executor = { version = "0.4.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } embassy-time = { version = "0.2", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768", ] } embassy-embedded-hal = { version = "0.1.0", path = "../../embassy-embedded-hal" } embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] } @@ -32,7 +32,7 @@ futures = { version = "0.3.17", default-features = false, features = ["async-awa heapless = { version = "0.8", default-features = false } chrono = { version = "^0.4", default-features = false } rand = { version = "0.8.5", default-features = false } -static_cell = { version = "2", features = ["nightly"]} +static_cell = "2" micromath = "2.0.0" diff --git a/examples/stm32l4/src/bin/adc.rs b/examples/stm32l4/src/bin/adc.rs index a0ec5c33e..d01e9f1b3 100644 --- a/examples/stm32l4/src/bin/adc.rs +++ b/examples/stm32l4/src/bin/adc.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_stm32::adc::{Adc, Resolution}; diff --git a/examples/stm32l4/src/bin/blinky.rs b/examples/stm32l4/src/bin/blinky.rs index 6202fe2f7..b55dfd35e 100644 --- a/examples/stm32l4/src/bin/blinky.rs +++ b/examples/stm32l4/src/bin/blinky.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/stm32l4/src/bin/button.rs b/examples/stm32l4/src/bin/button.rs index 0a102c2d6..15288c61e 100644 --- a/examples/stm32l4/src/bin/button.rs +++ b/examples/stm32l4/src/bin/button.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_stm32::gpio::{Input, Pull}; diff --git a/examples/stm32l4/src/bin/button_exti.rs b/examples/stm32l4/src/bin/button_exti.rs index ef32d4c4a..1e970fdd6 100644 --- a/examples/stm32l4/src/bin/button_exti.rs +++ b/examples/stm32l4/src/bin/button_exti.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/stm32l4/src/bin/dac.rs b/examples/stm32l4/src/bin/dac.rs index d6a7ff624..fdbf1d374 100644 --- a/examples/stm32l4/src/bin/dac.rs +++ b/examples/stm32l4/src/bin/dac.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_stm32::dac::{DacCh1, Value}; diff --git a/examples/stm32l4/src/bin/dac_dma.rs b/examples/stm32l4/src/bin/dac_dma.rs index dc86dbf43..64c541caa 100644 --- a/examples/stm32l4/src/bin/dac_dma.rs +++ b/examples/stm32l4/src/bin/dac_dma.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/stm32l4/src/bin/i2c.rs b/examples/stm32l4/src/bin/i2c.rs index 07dc12e8c..f553deb82 100644 --- a/examples/stm32l4/src/bin/i2c.rs +++ b/examples/stm32l4/src/bin/i2c.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/stm32l4/src/bin/i2c_blocking_async.rs b/examples/stm32l4/src/bin/i2c_blocking_async.rs index 60a4e2eb3..1b8652bcc 100644 --- a/examples/stm32l4/src/bin/i2c_blocking_async.rs +++ b/examples/stm32l4/src/bin/i2c_blocking_async.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_embedded_hal::adapter::BlockingAsync; diff --git a/examples/stm32l4/src/bin/i2c_dma.rs b/examples/stm32l4/src/bin/i2c_dma.rs index 4c2c224a6..794972a33 100644 --- a/examples/stm32l4/src/bin/i2c_dma.rs +++ b/examples/stm32l4/src/bin/i2c_dma.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/stm32l4/src/bin/mco.rs b/examples/stm32l4/src/bin/mco.rs index 504879887..36c002952 100644 --- a/examples/stm32l4/src/bin/mco.rs +++ b/examples/stm32l4/src/bin/mco.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/stm32l4/src/bin/rng.rs b/examples/stm32l4/src/bin/rng.rs index e5ad56fb9..638b3e9e4 100644 --- a/examples/stm32l4/src/bin/rng.rs +++ b/examples/stm32l4/src/bin/rng.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/stm32l4/src/bin/rtc.rs b/examples/stm32l4/src/bin/rtc.rs index d2a2aa1f2..526620bfb 100644 --- a/examples/stm32l4/src/bin/rtc.rs +++ b/examples/stm32l4/src/bin/rtc.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use chrono::{NaiveDate, NaiveDateTime}; use defmt::*; diff --git a/examples/stm32l4/src/bin/spe_adin1110_http_server.rs b/examples/stm32l4/src/bin/spe_adin1110_http_server.rs index eb04fe5e6..9565ae168 100644 --- a/examples/stm32l4/src/bin/spe_adin1110_http_server.rs +++ b/examples/stm32l4/src/bin/spe_adin1110_http_server.rs @@ -1,10 +1,7 @@ -#![deny(clippy::pedantic)] -#![allow(clippy::doc_markdown)] #![no_main] #![no_std] -// Needed unitl https://github.com/rust-lang/rust/issues/63063 is stablised. -#![feature(type_alias_impl_trait)] -#![feature(associated_type_bounds)] +#![deny(clippy::pedantic)] +#![allow(clippy::doc_markdown)] #![allow(clippy::missing_errors_doc)] // This example works on a ANALOG DEVICE EVAL-ADIN110EBZ board. diff --git a/examples/stm32l4/src/bin/spi.rs b/examples/stm32l4/src/bin/spi.rs index 54cf68f7b..6653e4516 100644 --- a/examples/stm32l4/src/bin/spi.rs +++ b/examples/stm32l4/src/bin/spi.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_stm32::dma::NoDma; diff --git a/examples/stm32l4/src/bin/spi_blocking_async.rs b/examples/stm32l4/src/bin/spi_blocking_async.rs index 903ca58df..a989a5a4a 100644 --- a/examples/stm32l4/src/bin/spi_blocking_async.rs +++ b/examples/stm32l4/src/bin/spi_blocking_async.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_embedded_hal::adapter::BlockingAsync; diff --git a/examples/stm32l4/src/bin/spi_dma.rs b/examples/stm32l4/src/bin/spi_dma.rs index 58cf2e51e..7922165df 100644 --- a/examples/stm32l4/src/bin/spi_dma.rs +++ b/examples/stm32l4/src/bin/spi_dma.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/stm32l4/src/bin/usart.rs b/examples/stm32l4/src/bin/usart.rs index f4da6b5ae..7bab23950 100644 --- a/examples/stm32l4/src/bin/usart.rs +++ b/examples/stm32l4/src/bin/usart.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_stm32::dma::NoDma; diff --git a/examples/stm32l4/src/bin/usart_dma.rs b/examples/stm32l4/src/bin/usart_dma.rs index 2f3b2a0f0..031888f70 100644 --- a/examples/stm32l4/src/bin/usart_dma.rs +++ b/examples/stm32l4/src/bin/usart_dma.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use core::fmt::Write; diff --git a/examples/stm32l4/src/bin/usb_serial.rs b/examples/stm32l4/src/bin/usb_serial.rs index 4baf5f05d..8cc9a7aed 100644 --- a/examples/stm32l4/src/bin/usb_serial.rs +++ b/examples/stm32l4/src/bin/usb_serial.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::{panic, *}; use defmt_rtt as _; // global logger diff --git a/examples/stm32l5/Cargo.toml b/examples/stm32l5/Cargo.toml index 2557ef42d..0d236ec90 100644 --- a/examples/stm32l5/Cargo.toml +++ b/examples/stm32l5/Cargo.toml @@ -8,7 +8,7 @@ license = "MIT OR Apache-2.0" # Change stm32l552ze to your chip name, if necessary. embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = [ "defmt", "unstable-pac", "stm32l552ze", "time-driver-any", "exti", "memory-x"] } embassy-sync = { version = "0.5.0", path = "../../embassy-sync", features = ["defmt"] } -embassy-executor = { version = "0.4.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } +embassy-executor = { version = "0.4.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } embassy-time = { version = "0.2", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] } embassy-net = { version = "0.2.0", path = "../../embassy-net", features = ["defmt", "tcp", "dhcpv4", "medium-ethernet"] } @@ -26,7 +26,7 @@ futures = { version = "0.3.17", default-features = false, features = ["async-awa heapless = { version = "0.8", default-features = false } rand_core = { version = "0.6.3", default-features = false } embedded-io-async = { version = "0.6.1" } -static_cell = { version = "2", features = ["nightly"]} +static_cell = "2" [profile.release] debug = 2 diff --git a/examples/stm32l5/src/bin/button_exti.rs b/examples/stm32l5/src/bin/button_exti.rs index e80ad2b3a..91d0ccc2e 100644 --- a/examples/stm32l5/src/bin/button_exti.rs +++ b/examples/stm32l5/src/bin/button_exti.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/stm32l5/src/bin/rng.rs b/examples/stm32l5/src/bin/rng.rs index 279f4f65d..50da6c946 100644 --- a/examples/stm32l5/src/bin/rng.rs +++ b/examples/stm32l5/src/bin/rng.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/stm32l5/src/bin/usb_ethernet.rs b/examples/stm32l5/src/bin/usb_ethernet.rs index 214235bd5..88060b6b0 100644 --- a/examples/stm32l5/src/bin/usb_ethernet.rs +++ b/examples/stm32l5/src/bin/usb_ethernet.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/stm32l5/src/bin/usb_hid_mouse.rs b/examples/stm32l5/src/bin/usb_hid_mouse.rs index 3614a8e0a..7c8a8ebfb 100644 --- a/examples/stm32l5/src/bin/usb_hid_mouse.rs +++ b/examples/stm32l5/src/bin/usb_hid_mouse.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/stm32l5/src/bin/usb_serial.rs b/examples/stm32l5/src/bin/usb_serial.rs index f2b894b68..75053ce4b 100644 --- a/examples/stm32l5/src/bin/usb_serial.rs +++ b/examples/stm32l5/src/bin/usb_serial.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::{panic, *}; use embassy_executor::Spawner; diff --git a/examples/stm32u5/Cargo.toml b/examples/stm32u5/Cargo.toml index 1afbd8db4..029b2cfe0 100644 --- a/examples/stm32u5/Cargo.toml +++ b/examples/stm32u5/Cargo.toml @@ -8,7 +8,7 @@ license = "MIT OR Apache-2.0" # Change stm32u585ai to your chip name, if necessary. embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = [ "defmt", "unstable-pac", "stm32u585ai", "time-driver-any", "memory-x" ] } embassy-sync = { version = "0.5.0", path = "../../embassy-sync", features = ["defmt"] } -embassy-executor = { version = "0.4.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } +embassy-executor = { version = "0.4.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } embassy-time = { version = "0.2", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] } diff --git a/examples/stm32u5/src/bin/blinky.rs b/examples/stm32u5/src/bin/blinky.rs index 4b44cb12b..7fe88c183 100644 --- a/examples/stm32u5/src/bin/blinky.rs +++ b/examples/stm32u5/src/bin/blinky.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/stm32u5/src/bin/boot.rs b/examples/stm32u5/src/bin/boot.rs index e2112ce5c..23c7f8b22 100644 --- a/examples/stm32u5/src/bin/boot.rs +++ b/examples/stm32u5/src/bin/boot.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use {defmt_rtt as _, embassy_stm32 as _, panic_probe as _}; diff --git a/examples/stm32u5/src/bin/usb_serial.rs b/examples/stm32u5/src/bin/usb_serial.rs index 839d6472f..44d1df4f1 100644 --- a/examples/stm32u5/src/bin/usb_serial.rs +++ b/examples/stm32u5/src/bin/usb_serial.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::{panic, *}; use defmt_rtt as _; // global logger diff --git a/examples/stm32wb/Cargo.toml b/examples/stm32wb/Cargo.toml index ada1f32e9..bce53c440 100644 --- a/examples/stm32wb/Cargo.toml +++ b/examples/stm32wb/Cargo.toml @@ -9,7 +9,7 @@ license = "MIT OR Apache-2.0" embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = [ "defmt", "stm32wb55rg", "time-driver-any", "memory-x", "exti"] } embassy-stm32-wpan = { version = "0.1.0", path = "../../embassy-stm32-wpan", features = ["defmt", "stm32wb55rg"] } embassy-sync = { version = "0.5.0", path = "../../embassy-sync", features = ["defmt"] } -embassy-executor = { version = "0.4.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } +embassy-executor = { version = "0.4.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } embassy-time = { version = "0.2", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } embassy-net = { version = "0.2.0", path = "../../embassy-net", features = ["defmt", "udp", "proto-ipv6", "medium-ieee802154", ], optional=true } @@ -22,7 +22,7 @@ embedded-hal = "0.2.6" panic-probe = { version = "0.3", features = ["print-defmt"] } futures = { version = "0.3.17", default-features = false, features = ["async-await"] } heapless = { version = "0.8", default-features = false } -static_cell = { version = "2", features = ["nightly"]} +static_cell = "2" [features] default = ["ble", "mac"] diff --git a/examples/stm32wb/src/bin/blinky.rs b/examples/stm32wb/src/bin/blinky.rs index 1394f03fa..f37e8b1d8 100644 --- a/examples/stm32wb/src/bin/blinky.rs +++ b/examples/stm32wb/src/bin/blinky.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/stm32wb/src/bin/button_exti.rs b/examples/stm32wb/src/bin/button_exti.rs index 3648db6ff..d34dde3e9 100644 --- a/examples/stm32wb/src/bin/button_exti.rs +++ b/examples/stm32wb/src/bin/button_exti.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/stm32wb/src/bin/eddystone_beacon.rs b/examples/stm32wb/src/bin/eddystone_beacon.rs index e58da8e35..cf9a5aa28 100644 --- a/examples/stm32wb/src/bin/eddystone_beacon.rs +++ b/examples/stm32wb/src/bin/eddystone_beacon.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use core::time::Duration; diff --git a/examples/stm32wb/src/bin/gatt_server.rs b/examples/stm32wb/src/bin/gatt_server.rs index 80e835c1d..5ce620350 100644 --- a/examples/stm32wb/src/bin/gatt_server.rs +++ b/examples/stm32wb/src/bin/gatt_server.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use core::time::Duration; diff --git a/examples/stm32wb/src/bin/mac_ffd.rs b/examples/stm32wb/src/bin/mac_ffd.rs index 881dc488d..5cd660543 100644 --- a/examples/stm32wb/src/bin/mac_ffd.rs +++ b/examples/stm32wb/src/bin/mac_ffd.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/stm32wb/src/bin/mac_ffd_net.rs b/examples/stm32wb/src/bin/mac_ffd_net.rs index 454530c03..7a42bf577 100644 --- a/examples/stm32wb/src/bin/mac_ffd_net.rs +++ b/examples/stm32wb/src/bin/mac_ffd_net.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/stm32wb/src/bin/mac_rfd.rs b/examples/stm32wb/src/bin/mac_rfd.rs index 000355de6..7949211fb 100644 --- a/examples/stm32wb/src/bin/mac_rfd.rs +++ b/examples/stm32wb/src/bin/mac_rfd.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/stm32wb/src/bin/tl_mbox.rs b/examples/stm32wb/src/bin/tl_mbox.rs index 9d0e0070c..cb92d462d 100644 --- a/examples/stm32wb/src/bin/tl_mbox.rs +++ b/examples/stm32wb/src/bin/tl_mbox.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/stm32wb/src/bin/tl_mbox_ble.rs b/examples/stm32wb/src/bin/tl_mbox_ble.rs index 12c6aeebb..2599e1151 100644 --- a/examples/stm32wb/src/bin/tl_mbox_ble.rs +++ b/examples/stm32wb/src/bin/tl_mbox_ble.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/stm32wb/src/bin/tl_mbox_mac.rs b/examples/stm32wb/src/bin/tl_mbox_mac.rs index f32e07d96..5d868412a 100644 --- a/examples/stm32wb/src/bin/tl_mbox_mac.rs +++ b/examples/stm32wb/src/bin/tl_mbox_mac.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/stm32wba/Cargo.toml b/examples/stm32wba/Cargo.toml index c97605937..84eb6c831 100644 --- a/examples/stm32wba/Cargo.toml +++ b/examples/stm32wba/Cargo.toml @@ -7,7 +7,7 @@ license = "MIT OR Apache-2.0" [dependencies] embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = [ "defmt", "stm32wba52cg", "time-driver-any", "memory-x", "exti"] } embassy-sync = { version = "0.5.0", path = "../../embassy-sync", features = ["defmt"] } -embassy-executor = { version = "0.4.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } +embassy-executor = { version = "0.4.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } embassy-time = { version = "0.2", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } embassy-net = { version = "0.2.0", path = "../../embassy-net", features = ["defmt", "udp", "proto-ipv6", "medium-ieee802154", ], optional=true } @@ -20,7 +20,7 @@ embedded-hal = "0.2.6" panic-probe = { version = "0.3", features = ["print-defmt"] } futures = { version = "0.3.17", default-features = false, features = ["async-await"] } heapless = { version = "0.8", default-features = false } -static_cell = { version = "2", features = ["nightly"]} +static_cell = "2" [profile.release] debug = 2 diff --git a/examples/stm32wba/src/bin/blinky.rs b/examples/stm32wba/src/bin/blinky.rs index 6b9635e66..0d803b257 100644 --- a/examples/stm32wba/src/bin/blinky.rs +++ b/examples/stm32wba/src/bin/blinky.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/stm32wba/src/bin/button_exti.rs b/examples/stm32wba/src/bin/button_exti.rs index ef32d4c4a..1e970fdd6 100644 --- a/examples/stm32wba/src/bin/button_exti.rs +++ b/examples/stm32wba/src/bin/button_exti.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/stm32wl/Cargo.toml b/examples/stm32wl/Cargo.toml index 070d27cb6..62c34b792 100644 --- a/examples/stm32wl/Cargo.toml +++ b/examples/stm32wl/Cargo.toml @@ -8,7 +8,7 @@ license = "MIT OR Apache-2.0" # Change stm32wl55jc-cm4 to your chip name, if necessary. embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["defmt", "stm32wl55jc-cm4", "time-driver-any", "memory-x", "unstable-pac", "exti", "chrono"] } embassy-sync = { version = "0.5.0", path = "../../embassy-sync", features = ["defmt"] } -embassy-executor = { version = "0.4.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } +embassy-executor = { version = "0.4.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } embassy-time = { version = "0.2", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } embassy-embedded-hal = { version = "0.1.0", path = "../../embassy-embedded-hal" } diff --git a/examples/stm32wl/src/bin/blinky.rs b/examples/stm32wl/src/bin/blinky.rs index 5bd5745f0..347bd093f 100644 --- a/examples/stm32wl/src/bin/blinky.rs +++ b/examples/stm32wl/src/bin/blinky.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/stm32wl/src/bin/button.rs b/examples/stm32wl/src/bin/button.rs index 6c1f5a5ef..3397e5ba6 100644 --- a/examples/stm32wl/src/bin/button.rs +++ b/examples/stm32wl/src/bin/button.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use cortex_m_rt::entry; use defmt::*; diff --git a/examples/stm32wl/src/bin/button_exti.rs b/examples/stm32wl/src/bin/button_exti.rs index 1f02db5cf..e6ad4b80b 100644 --- a/examples/stm32wl/src/bin/button_exti.rs +++ b/examples/stm32wl/src/bin/button_exti.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/stm32wl/src/bin/flash.rs b/examples/stm32wl/src/bin/flash.rs index 5e52d49ec..0b7417c01 100644 --- a/examples/stm32wl/src/bin/flash.rs +++ b/examples/stm32wl/src/bin/flash.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::{info, unwrap}; use embassy_executor::Spawner; diff --git a/examples/stm32wl/src/bin/random.rs b/examples/stm32wl/src/bin/random.rs index 2fd234966..3610392be 100644 --- a/examples/stm32wl/src/bin/random.rs +++ b/examples/stm32wl/src/bin/random.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/stm32wl/src/bin/rtc.rs b/examples/stm32wl/src/bin/rtc.rs index 4ffb0bb58..4738d5770 100644 --- a/examples/stm32wl/src/bin/rtc.rs +++ b/examples/stm32wl/src/bin/rtc.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use chrono::{NaiveDate, NaiveDateTime}; use defmt::*; diff --git a/examples/stm32wl/src/bin/uart_async.rs b/examples/stm32wl/src/bin/uart_async.rs index 44e8f83a2..8e545834c 100644 --- a/examples/stm32wl/src/bin/uart_async.rs +++ b/examples/stm32wl/src/bin/uart_async.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; diff --git a/examples/wasm/Cargo.toml b/examples/wasm/Cargo.toml index c96a428b9..305ebd526 100644 --- a/examples/wasm/Cargo.toml +++ b/examples/wasm/Cargo.toml @@ -9,7 +9,7 @@ crate-type = ["cdylib"] [dependencies] embassy-sync = { version = "0.5.0", path = "../../embassy-sync", features = ["log"] } -embassy-executor = { version = "0.4.0", path = "../../embassy-executor", features = ["arch-wasm", "executor-thread", "log", "nightly", "integrated-timers"] } +embassy-executor = { version = "0.4.0", path = "../../embassy-executor", features = ["arch-wasm", "executor-thread", "log", "integrated-timers"] } embassy-time = { version = "0.2", path = "../../embassy-time", features = ["log", "wasm", ] } wasm-logger = "0.2.0" diff --git a/examples/wasm/src/lib.rs b/examples/wasm/src/lib.rs index 1141096fb..71cf980dd 100644 --- a/examples/wasm/src/lib.rs +++ b/examples/wasm/src/lib.rs @@ -1,5 +1,3 @@ -#![feature(type_alias_impl_trait)] - use embassy_executor::Spawner; use embassy_time::Timer; diff --git a/rust-toolchain-nightly.toml b/rust-toolchain-nightly.toml new file mode 100644 index 000000000..b8a7db353 --- /dev/null +++ b/rust-toolchain-nightly.toml @@ -0,0 +1,12 @@ +[toolchain] +channel = "nightly-2023-12-20" +components = [ "rust-src", "rustfmt", "llvm-tools", "miri" ] +targets = [ + "thumbv7em-none-eabi", + "thumbv7m-none-eabi", + "thumbv6m-none-eabi", + "thumbv7em-none-eabihf", + "thumbv8m.main-none-eabihf", + "riscv32imac-unknown-none-elf", + "wasm32-unknown-unknown", +] diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 11f53ee4a..e1af0b647 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,8 +1,6 @@ -# Before upgrading check that everything is available on all tier1 targets here: -# https://rust-lang.github.io/rustup-components-history [toolchain] -channel = "nightly-2023-11-01" -components = [ "rust-src", "rustfmt", "llvm-tools", "miri" ] +channel = "beta-2023-12-17" +components = [ "rust-src", "rustfmt", "llvm-tools" ] targets = [ "thumbv7em-none-eabi", "thumbv7m-none-eabi", @@ -11,4 +9,4 @@ targets = [ "thumbv8m.main-none-eabihf", "riscv32imac-unknown-none-elf", "wasm32-unknown-unknown", -] \ No newline at end of file +] diff --git a/tests/nrf/Cargo.toml b/tests/nrf/Cargo.toml index b6067abcc..ccdca0844 100644 --- a/tests/nrf/Cargo.toml +++ b/tests/nrf/Cargo.toml @@ -18,7 +18,7 @@ embassy-net-esp-hosted = { version = "0.1.0", path = "../../embassy-net-esp-host embassy-net-enc28j60 = { version = "0.1.0", path = "../../embassy-net-enc28j60", features = ["defmt"] } embedded-hal-async = { version = "1.0.0-rc.3" } embedded-hal-bus = { version = "0.1.0-rc.3", features = ["async"] } -static_cell = { version = "2", features = [ "nightly" ] } +static_cell = "2" perf-client = { path = "../perf-client" } defmt = "0.3" diff --git a/tests/nrf/src/bin/ethernet_enc28j60_perf.rs b/tests/nrf/src/bin/ethernet_enc28j60_perf.rs index c26c0d066..7dc1941d7 100644 --- a/tests/nrf/src/bin/ethernet_enc28j60_perf.rs +++ b/tests/nrf/src/bin/ethernet_enc28j60_perf.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] teleprobe_meta::target!(b"ak-gwe-r7"); teleprobe_meta::timeout!(120); diff --git a/tests/nrf/src/bin/wifi_esp_hosted_perf.rs b/tests/nrf/src/bin/wifi_esp_hosted_perf.rs index 5b43b75d7..c96064f84 100644 --- a/tests/nrf/src/bin/wifi_esp_hosted_perf.rs +++ b/tests/nrf/src/bin/wifi_esp_hosted_perf.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] teleprobe_meta::target!(b"nrf52840-dk"); teleprobe_meta::timeout!(120); diff --git a/tests/rp/Cargo.toml b/tests/rp/Cargo.toml index 028ce43ee..c38aa8004 100644 --- a/tests/rp/Cargo.toml +++ b/tests/rp/Cargo.toml @@ -31,7 +31,7 @@ panic-probe = { version = "0.3.0", features = ["print-defmt"] } futures = { version = "0.3.17", default-features = false, features = ["async-await"] } embedded-io-async = { version = "0.6.1" } embedded-storage = { version = "0.3" } -static_cell = { version = "2", features = ["nightly"]} +static_cell = "2" portable-atomic = { version = "1.5", features = ["critical-section"] } pio = "0.2" pio-proc = "0.2" diff --git a/tests/rp/src/bin/cyw43-perf.rs b/tests/rp/src/bin/cyw43-perf.rs index d70ef8ef3..a1b2946e6 100644 --- a/tests/rp/src/bin/cyw43-perf.rs +++ b/tests/rp/src/bin/cyw43-perf.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] teleprobe_meta::target!(b"rpi-pico"); use cyw43_pio::PioSpi; diff --git a/tests/rp/src/bin/ethernet_w5100s_perf.rs b/tests/rp/src/bin/ethernet_w5100s_perf.rs index 5588b6427..8c9089d0e 100644 --- a/tests/rp/src/bin/ethernet_w5100s_perf.rs +++ b/tests/rp/src/bin/ethernet_w5100s_perf.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] teleprobe_meta::target!(b"w5100s-evb-pico"); teleprobe_meta::timeout!(120); diff --git a/tests/stm32/Cargo.toml b/tests/stm32/Cargo.toml index bdec41571..c60b28a7a 100644 --- a/tests/stm32/Cargo.toml +++ b/tests/stm32/Cargo.toml @@ -69,7 +69,7 @@ micromath = "2.0.0" panic-probe = { version = "0.3.0", features = ["print-defmt"] } rand_core = { version = "0.6", default-features = false } rand_chacha = { version = "0.3", default-features = false } -static_cell = { version = "2", features = ["nightly"] } +static_cell = "2" portable-atomic = { version = "1.5", features = [] } chrono = { version = "^0.4", default-features = false, optional = true} diff --git a/tests/stm32/src/bin/eth.rs b/tests/stm32/src/bin/eth.rs index c01f33a97..7c02f0354 100644 --- a/tests/stm32/src/bin/eth.rs +++ b/tests/stm32/src/bin/eth.rs @@ -1,7 +1,6 @@ // required-features: eth #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] #[path = "../common.rs"] mod common; diff --git a/tests/stm32/src/bin/stop.rs b/tests/stm32/src/bin/stop.rs index f8e3c43d7..000296d46 100644 --- a/tests/stm32/src/bin/stop.rs +++ b/tests/stm32/src/bin/stop.rs @@ -2,7 +2,6 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] #[path = "../common.rs"] mod common; From 53fc344e4d46388cc742c139a263c1cdf0c16589 Mon Sep 17 00:00:00 2001 From: eZio Pan Date: Fri, 22 Dec 2023 01:24:31 +0800 Subject: [PATCH 096/124] fix timing, turn TIM UDE on only necessary, clean DMA FEIF after each Transfer --- examples/stm32f4/src/bin/ws2812_pwm_dma.rs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/examples/stm32f4/src/bin/ws2812_pwm_dma.rs b/examples/stm32f4/src/bin/ws2812_pwm_dma.rs index dc397eff1..c4181d024 100644 --- a/examples/stm32f4/src/bin/ws2812_pwm_dma.rs +++ b/examples/stm32f4/src/bin/ws2812_pwm_dma.rs @@ -64,9 +64,6 @@ async fn main(_spawner: Spawner) { CountingMode::EdgeAlignedUp, ); - // PAC level hacking, enable timer-update-event trigger DMA - pac::TIM3.dier().modify(|v| v.set_ude(true)); - // construct ws2812 non-return-to-zero (NRZ) code bit by bit // ws2812 only need 24 bits for each LED, but we add one bit more to keep PWM output low @@ -104,13 +101,16 @@ async fn main(_spawner: Spawner) { dma_transfer_option.mburst = Burst::Incr8; // flip color at 2 Hz - let mut ticker = Ticker::every(Duration::from_micros(500)); + let mut ticker = Ticker::every(Duration::from_millis(500)); loop { for &color in color_list { // start PWM output ws2812_pwm.enable(pwm_channel); + // PAC level hacking, enable timer-update-event trigger DMA + pac::TIM3.dier().modify(|v| v.set_ude(true)); + unsafe { Transfer::new_write( // with &mut, we can easily reuse same DMA channel multiple times @@ -121,6 +121,14 @@ async fn main(_spawner: Spawner) { dma_transfer_option, ) .await; + + // Turn off timer-update-event trigger DMA as soon as possible. + // Then clean the FIFO Error Flag if set. + pac::TIM3.dier().modify(|v| v.set_ude(false)); + if pac::DMA1.isr(0).read().feif(2) { + pac::DMA1.ifcr(0).write(|v| v.set_feif(2, true)); + } + // ws2812 need at least 50 us low level input to confirm the input data and change it's state Timer::after_micros(50).await; } From 2f75ffb2333904e1370a845ead88442c45b5ba5d Mon Sep 17 00:00:00 2001 From: eZio Pan Date: Fri, 22 Dec 2023 01:31:25 +0800 Subject: [PATCH 097/124] remove unused feature attribute --- examples/stm32f4/src/bin/ws2812_spi.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/stm32f4/src/bin/ws2812_spi.rs b/examples/stm32f4/src/bin/ws2812_spi.rs index eca657900..a280a3b77 100644 --- a/examples/stm32f4/src/bin/ws2812_spi.rs +++ b/examples/stm32f4/src/bin/ws2812_spi.rs @@ -12,7 +12,6 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use embassy_stm32::time::khz; use embassy_stm32::{dma, spi}; From 0fb57ef87d678830e2ccb3753432535897bbb1c3 Mon Sep 17 00:00:00 2001 From: Barnaby Walters Date: Fri, 22 Dec 2023 17:08:39 +0100 Subject: [PATCH 098/124] Improved documentation * Documented features including all tick rates * Corrected some out-of-date information * Sorted tick rate features * Removed gen_tick.py dependency on toml * Restructured README.md to better explain tick rate, more clearly prioritise time driver docs, correct header levels --- embassy-time/Cargo.toml | 366 ++++++++++++++++++++++++++---------- embassy-time/README.md | 54 +++--- embassy-time/gen_tick.py | 23 ++- embassy-time/src/lib.rs | 8 +- embassy-time/src/tick.rs | 396 +++++++++++++++++++-------------------- 5 files changed, 519 insertions(+), 328 deletions(-) diff --git a/embassy-time/Cargo.toml b/embassy-time/Cargo.toml index 6d9b7aa69..534894b20 100644 --- a/embassy-time/Cargo.toml +++ b/embassy-time/Cargo.toml @@ -32,204 +32,376 @@ features = ["defmt", "std"] std = ["tick-hz-1_000_000", "critical-section/std"] wasm = ["dep:wasm-bindgen", "dep:js-sys", "dep:wasm-timer", "tick-hz-1_000_000"] -# Display a timestamp of the number of seconds since startup next to defmt log messages -# To use this you must have a time driver provided. +## Display a timestamp of the number of seconds since startup next to defmt log messages +## To use this you must have a time driver provided. defmt-timestamp-uptime = ["defmt"] -# Create a global, generic queue that can be used with any executor -# To use this you must have a time driver provided. -generic-queue = [] - -# Set the number of timers for the generic queue. -# -# At most 1 `generic-queue-*` feature can be enabled. If none is enabled, a default of 64 timers is used. -# -# When using embassy-time from libraries, you should *not* enable any `generic-queue-*` feature, to allow the -# end user to pick. -generic-queue-8 = ["generic-queue"] -generic-queue-16 = ["generic-queue"] -generic-queue-32 = ["generic-queue"] -generic-queue-64 = ["generic-queue"] -generic-queue-128 = ["generic-queue"] - -# Create a `MockDriver` that can be manually advanced for testing purposes. +## Create a `MockDriver` that can be manually advanced for testing purposes. mock-driver = ["tick-hz-1_000_000"] -# Set the `embassy_time` tick rate. -# -# At most 1 `tick-*` feature can be enabled. If none is enabled, a default of 1MHz is used. -# -# If the time driver in use supports using arbitrary tick rates, you can enable one `tick-*` -# feature from your binary crate to set the tick rate. The driver will use configured tick rate. -# If the time driver supports a fixed tick rate, it will enable one feature itself, so you should -# not enable one. Check the time driver documentation for details. -# -# When using embassy-time from libraries, you should *not* enable any `tick-*` feature, to allow the -# end user or the driver to pick. +#! ### Generic Queue + +## Create a global, generic queue that can be used with any executor +## To use this you must have a time driver provided. +generic-queue = [] + +#! The following features set how many timers are used for the generic queue. At most 1 +#! `generic-queue-*` feature can be enabled. If none is enabled, a default of 64 timers is used. +#! +#! When using embassy-time from libraries, you should *not* enable any `generic-queue-*` feature, to allow the +#! end user to pick. + +## Generic Queue with 8 timers +generic-queue-8 = ["generic-queue"] +## Generic Queue with 16 timers +generic-queue-16 = ["generic-queue"] +## Generic Queue with 32 timers +generic-queue-32 = ["generic-queue"] +## Generic Queue with 64 timers +generic-queue-64 = ["generic-queue"] +## Generic Queue with 128 timers +generic-queue-128 = ["generic-queue"] + +#! ### Tick Rate +#! +#! At most 1 `tick-*` feature can be enabled. If none is enabled, a default of 1MHz is used. +#! +#! If the time driver in use supports using arbitrary tick rates, you can enable one `tick-*` +#! feature from your binary crate to set the tick rate. The driver will use configured tick rate. +#! If the time driver supports a fixed tick rate, it will enable one feature itself, so you should +#! not enable one. Check the time driver documentation for details. +#! +#! When using embassy-time from libraries, you should *not* enable any `tick-*` feature, to allow the +#! end user or the driver to pick. +#!

+#! Available tick rates: +#! +#! # BEGIN TICKS # Generated by gen_tick.py. DO NOT EDIT. +## 1Hz Tick Rate tick-hz-1 = [] -tick-hz-10 = [] -tick-hz-100 = [] -tick-hz-1_000 = [] -tick-hz-10_000 = [] -tick-hz-100_000 = [] -tick-hz-1_000_000 = [] -tick-hz-10_000_000 = [] -tick-hz-100_000_000 = [] -tick-hz-1_000_000_000 = [] +## 2Hz Tick Rate tick-hz-2 = [] +## 4Hz Tick Rate tick-hz-4 = [] +## 8Hz Tick Rate tick-hz-8 = [] +## 10Hz Tick Rate +tick-hz-10 = [] +## 16Hz Tick Rate tick-hz-16 = [] +## 32Hz Tick Rate tick-hz-32 = [] +## 64Hz Tick Rate tick-hz-64 = [] +## 100Hz Tick Rate +tick-hz-100 = [] +## 128Hz Tick Rate tick-hz-128 = [] +## 256Hz Tick Rate tick-hz-256 = [] +## 512Hz Tick Rate tick-hz-512 = [] +## 1.0kHz Tick Rate +tick-hz-1_000 = [] +## 1.024kHz Tick Rate tick-hz-1_024 = [] -tick-hz-2_048 = [] -tick-hz-4_096 = [] -tick-hz-8_192 = [] -tick-hz-16_384 = [] -tick-hz-32_768 = [] -tick-hz-65_536 = [] -tick-hz-131_072 = [] -tick-hz-262_144 = [] -tick-hz-524_288 = [] -tick-hz-1_048_576 = [] -tick-hz-2_097_152 = [] -tick-hz-4_194_304 = [] -tick-hz-8_388_608 = [] -tick-hz-16_777_216 = [] +## 2.0kHz Tick Rate tick-hz-2_000 = [] +## 2.048kHz Tick Rate +tick-hz-2_048 = [] +## 4.0kHz Tick Rate tick-hz-4_000 = [] +## 4.096kHz Tick Rate +tick-hz-4_096 = [] +## 8.0kHz Tick Rate tick-hz-8_000 = [] +## 8.192kHz Tick Rate +tick-hz-8_192 = [] +## 10.0kHz Tick Rate +tick-hz-10_000 = [] +## 16.0kHz Tick Rate tick-hz-16_000 = [] -tick-hz-32_000 = [] -tick-hz-64_000 = [] -tick-hz-128_000 = [] -tick-hz-256_000 = [] -tick-hz-512_000 = [] -tick-hz-1_024_000 = [] -tick-hz-2_048_000 = [] -tick-hz-4_096_000 = [] -tick-hz-8_192_000 = [] -tick-hz-16_384_000 = [] -tick-hz-32_768_000 = [] -tick-hz-65_536_000 = [] -tick-hz-131_072_000 = [] -tick-hz-262_144_000 = [] -tick-hz-524_288_000 = [] +## 16.384kHz Tick Rate +tick-hz-16_384 = [] +## 20.0kHz Tick Rate tick-hz-20_000 = [] +## 32.0kHz Tick Rate +tick-hz-32_000 = [] +## 32.768kHz Tick Rate +tick-hz-32_768 = [] +## 40.0kHz Tick Rate tick-hz-40_000 = [] +## 64.0kHz Tick Rate +tick-hz-64_000 = [] +## 65.536kHz Tick Rate +tick-hz-65_536 = [] +## 80.0kHz Tick Rate tick-hz-80_000 = [] +## 100.0kHz Tick Rate +tick-hz-100_000 = [] +## 128.0kHz Tick Rate +tick-hz-128_000 = [] +## 131.072kHz Tick Rate +tick-hz-131_072 = [] +## 160.0kHz Tick Rate tick-hz-160_000 = [] +## 256.0kHz Tick Rate +tick-hz-256_000 = [] +## 262.144kHz Tick Rate +tick-hz-262_144 = [] +## 320.0kHz Tick Rate tick-hz-320_000 = [] +## 512.0kHz Tick Rate +tick-hz-512_000 = [] +## 524.288kHz Tick Rate +tick-hz-524_288 = [] +## 640.0kHz Tick Rate tick-hz-640_000 = [] +## 1.0MHz Tick Rate +tick-hz-1_000_000 = [] +## 1.024MHz Tick Rate +tick-hz-1_024_000 = [] +## 1.048576MHz Tick Rate +tick-hz-1_048_576 = [] +## 1.28MHz Tick Rate tick-hz-1_280_000 = [] -tick-hz-2_560_000 = [] -tick-hz-5_120_000 = [] -tick-hz-10_240_000 = [] -tick-hz-20_480_000 = [] -tick-hz-40_960_000 = [] -tick-hz-81_920_000 = [] -tick-hz-163_840_000 = [] -tick-hz-327_680_000 = [] -tick-hz-655_360_000 = [] -tick-hz-1_310_720_000 = [] -tick-hz-2_621_440_000 = [] -tick-hz-5_242_880_000 = [] +## 2.0MHz Tick Rate tick-hz-2_000_000 = [] +## 2.048MHz Tick Rate +tick-hz-2_048_000 = [] +## 2.097152MHz Tick Rate +tick-hz-2_097_152 = [] +## 2.56MHz Tick Rate +tick-hz-2_560_000 = [] +## 3.0MHz Tick Rate tick-hz-3_000_000 = [] +## 4.0MHz Tick Rate tick-hz-4_000_000 = [] +## 4.096MHz Tick Rate +tick-hz-4_096_000 = [] +## 4.194304MHz Tick Rate +tick-hz-4_194_304 = [] +## 5.12MHz Tick Rate +tick-hz-5_120_000 = [] +## 6.0MHz Tick Rate tick-hz-6_000_000 = [] +## 8.0MHz Tick Rate tick-hz-8_000_000 = [] +## 8.192MHz Tick Rate +tick-hz-8_192_000 = [] +## 8.388608MHz Tick Rate +tick-hz-8_388_608 = [] +## 9.0MHz Tick Rate tick-hz-9_000_000 = [] +## 10.0MHz Tick Rate +tick-hz-10_000_000 = [] +## 10.24MHz Tick Rate +tick-hz-10_240_000 = [] +## 12.0MHz Tick Rate tick-hz-12_000_000 = [] +## 16.0MHz Tick Rate tick-hz-16_000_000 = [] +## 16.384MHz Tick Rate +tick-hz-16_384_000 = [] +## 16.777216MHz Tick Rate +tick-hz-16_777_216 = [] +## 18.0MHz Tick Rate tick-hz-18_000_000 = [] -tick-hz-24_000_000 = [] -tick-hz-32_000_000 = [] -tick-hz-36_000_000 = [] -tick-hz-48_000_000 = [] -tick-hz-64_000_000 = [] -tick-hz-72_000_000 = [] -tick-hz-96_000_000 = [] -tick-hz-128_000_000 = [] -tick-hz-144_000_000 = [] -tick-hz-192_000_000 = [] -tick-hz-256_000_000 = [] -tick-hz-288_000_000 = [] -tick-hz-384_000_000 = [] -tick-hz-512_000_000 = [] -tick-hz-576_000_000 = [] -tick-hz-768_000_000 = [] +## 20.0MHz Tick Rate tick-hz-20_000_000 = [] +## 20.48MHz Tick Rate +tick-hz-20_480_000 = [] +## 24.0MHz Tick Rate +tick-hz-24_000_000 = [] +## 30.0MHz Tick Rate tick-hz-30_000_000 = [] +## 32.0MHz Tick Rate +tick-hz-32_000_000 = [] +## 32.768MHz Tick Rate +tick-hz-32_768_000 = [] +## 36.0MHz Tick Rate +tick-hz-36_000_000 = [] +## 40.0MHz Tick Rate tick-hz-40_000_000 = [] +## 40.96MHz Tick Rate +tick-hz-40_960_000 = [] +## 48.0MHz Tick Rate +tick-hz-48_000_000 = [] +## 50.0MHz Tick Rate tick-hz-50_000_000 = [] +## 60.0MHz Tick Rate tick-hz-60_000_000 = [] +## 64.0MHz Tick Rate +tick-hz-64_000_000 = [] +## 65.536MHz Tick Rate +tick-hz-65_536_000 = [] +## 70.0MHz Tick Rate tick-hz-70_000_000 = [] +## 72.0MHz Tick Rate +tick-hz-72_000_000 = [] +## 80.0MHz Tick Rate tick-hz-80_000_000 = [] +## 81.92MHz Tick Rate +tick-hz-81_920_000 = [] +## 90.0MHz Tick Rate tick-hz-90_000_000 = [] +## 96.0MHz Tick Rate +tick-hz-96_000_000 = [] +## 100.0MHz Tick Rate +tick-hz-100_000_000 = [] +## 110.0MHz Tick Rate tick-hz-110_000_000 = [] +## 120.0MHz Tick Rate tick-hz-120_000_000 = [] +## 128.0MHz Tick Rate +tick-hz-128_000_000 = [] +## 130.0MHz Tick Rate tick-hz-130_000_000 = [] +## 131.072MHz Tick Rate +tick-hz-131_072_000 = [] +## 140.0MHz Tick Rate tick-hz-140_000_000 = [] +## 144.0MHz Tick Rate +tick-hz-144_000_000 = [] +## 150.0MHz Tick Rate tick-hz-150_000_000 = [] +## 160.0MHz Tick Rate tick-hz-160_000_000 = [] +## 163.84MHz Tick Rate +tick-hz-163_840_000 = [] +## 170.0MHz Tick Rate tick-hz-170_000_000 = [] +## 180.0MHz Tick Rate tick-hz-180_000_000 = [] +## 190.0MHz Tick Rate tick-hz-190_000_000 = [] +## 192.0MHz Tick Rate +tick-hz-192_000_000 = [] +## 200.0MHz Tick Rate tick-hz-200_000_000 = [] +## 210.0MHz Tick Rate tick-hz-210_000_000 = [] +## 220.0MHz Tick Rate tick-hz-220_000_000 = [] +## 230.0MHz Tick Rate tick-hz-230_000_000 = [] +## 240.0MHz Tick Rate tick-hz-240_000_000 = [] +## 250.0MHz Tick Rate tick-hz-250_000_000 = [] +## 256.0MHz Tick Rate +tick-hz-256_000_000 = [] +## 260.0MHz Tick Rate tick-hz-260_000_000 = [] +## 262.144MHz Tick Rate +tick-hz-262_144_000 = [] +## 270.0MHz Tick Rate tick-hz-270_000_000 = [] +## 280.0MHz Tick Rate tick-hz-280_000_000 = [] +## 288.0MHz Tick Rate +tick-hz-288_000_000 = [] +## 290.0MHz Tick Rate tick-hz-290_000_000 = [] +## 300.0MHz Tick Rate tick-hz-300_000_000 = [] +## 320.0MHz Tick Rate tick-hz-320_000_000 = [] +## 327.68MHz Tick Rate +tick-hz-327_680_000 = [] +## 340.0MHz Tick Rate tick-hz-340_000_000 = [] +## 360.0MHz Tick Rate tick-hz-360_000_000 = [] +## 380.0MHz Tick Rate tick-hz-380_000_000 = [] +## 384.0MHz Tick Rate +tick-hz-384_000_000 = [] +## 400.0MHz Tick Rate tick-hz-400_000_000 = [] +## 420.0MHz Tick Rate tick-hz-420_000_000 = [] +## 440.0MHz Tick Rate tick-hz-440_000_000 = [] +## 460.0MHz Tick Rate tick-hz-460_000_000 = [] +## 480.0MHz Tick Rate tick-hz-480_000_000 = [] +## 500.0MHz Tick Rate tick-hz-500_000_000 = [] +## 512.0MHz Tick Rate +tick-hz-512_000_000 = [] +## 520.0MHz Tick Rate tick-hz-520_000_000 = [] +## 524.288MHz Tick Rate +tick-hz-524_288_000 = [] +## 540.0MHz Tick Rate tick-hz-540_000_000 = [] +## 560.0MHz Tick Rate tick-hz-560_000_000 = [] +## 576.0MHz Tick Rate +tick-hz-576_000_000 = [] +## 580.0MHz Tick Rate tick-hz-580_000_000 = [] +## 600.0MHz Tick Rate tick-hz-600_000_000 = [] +## 620.0MHz Tick Rate tick-hz-620_000_000 = [] +## 640.0MHz Tick Rate tick-hz-640_000_000 = [] +## 655.36MHz Tick Rate +tick-hz-655_360_000 = [] +## 660.0MHz Tick Rate tick-hz-660_000_000 = [] +## 680.0MHz Tick Rate tick-hz-680_000_000 = [] +## 700.0MHz Tick Rate tick-hz-700_000_000 = [] +## 720.0MHz Tick Rate tick-hz-720_000_000 = [] +## 740.0MHz Tick Rate tick-hz-740_000_000 = [] +## 760.0MHz Tick Rate tick-hz-760_000_000 = [] +## 768.0MHz Tick Rate +tick-hz-768_000_000 = [] +## 780.0MHz Tick Rate tick-hz-780_000_000 = [] +## 800.0MHz Tick Rate tick-hz-800_000_000 = [] +## 820.0MHz Tick Rate tick-hz-820_000_000 = [] +## 840.0MHz Tick Rate tick-hz-840_000_000 = [] +## 860.0MHz Tick Rate tick-hz-860_000_000 = [] +## 880.0MHz Tick Rate tick-hz-880_000_000 = [] +## 900.0MHz Tick Rate tick-hz-900_000_000 = [] +## 920.0MHz Tick Rate tick-hz-920_000_000 = [] +## 940.0MHz Tick Rate tick-hz-940_000_000 = [] +## 960.0MHz Tick Rate tick-hz-960_000_000 = [] +## 980.0MHz Tick Rate tick-hz-980_000_000 = [] +## 1.0GHz Tick Rate +tick-hz-1_000_000_000 = [] +## 1.31072GHz Tick Rate +tick-hz-1_310_720_000 = [] +## 2.62144GHz Tick Rate +tick-hz-2_621_440_000 = [] +## 5.24288GHz Tick Rate +tick-hz-5_242_880_000 = [] # END TICKS +#!
+ [dependencies] defmt = { version = "0.3", optional = true } log = { version = "0.4.14", optional = true } @@ -243,6 +415,8 @@ critical-section = "1.1" cfg-if = "1.0.0" heapless = "0.8" +document-features = "0.2.7" + # WASM dependencies wasm-bindgen = { version = "0.2.81", optional = true } js-sys = { version = "0.3", optional = true } diff --git a/embassy-time/README.md b/embassy-time/README.md index 2be80ff9c..a4a622700 100644 --- a/embassy-time/README.md +++ b/embassy-time/README.md @@ -3,35 +3,16 @@ Timekeeping, delays and timeouts. Timekeeping is done with elapsed time since system boot. Time is represented in -ticks, where the tick rate is defined by the current driver, usually to match -the tick rate of the hardware. +ticks, where the tick rate is defined either by the driver (in the case of a fixed- +rate tick) or chosen by the user with a [tick rate](#tick-rate) feature. The chosen +tick rate applies to everything in `embassy-time` and thus determines the maximum +timing resolution of (1 / tick_rate) seconds. -Tick counts are 64 bits. At the highest supported tick rate of 1Mhz this supports +Tick counts are 64 bits. The default tick rate of 1Mhz supports representing time spans of up to ~584558 years, which is big enough for all practical purposes and allows not having to worry about overflows. -[`Instant`] represents a given instant of time (relative to system boot), and [`Duration`] -represents the duration of a span of time. They implement the math operations you'd expect, -like addition and substraction. - -# Delays and timeouts - -[`Timer`] allows performing async delays. [`Ticker`] allows periodic delays without drifting over time. - -An implementation of the `embedded-hal` delay traits is provided by [`Delay`], for compatibility -with libraries from the ecosystem. - -# Wall-clock time - -The `time` module deals exclusively with a monotonically increasing tick count. -Therefore it has no direct support for wall-clock time ("real life" datetimes -like `2021-08-24 13:33:21`). - -If persistence across reboots is not needed, support can be built on top of -`embassy_time` by storing the offset between "seconds elapsed since boot" -and "seconds since unix epoch". - -# Time driver +## Time driver The `time` module is backed by a global "time driver" specified at build time. Only one driver can be active in a program. @@ -41,3 +22,26 @@ possible for libraries to use `embassy_time` in a driver-agnostic way without requiring generic parameters. For more details, check the [`driver`] module. + +## Instants and Durations + +[`Instant`] represents a given instant of time (relative to system boot), and [`Duration`] +represents the duration of a span of time. They implement the math operations you'd expect, +like addition and substraction. + +## Delays and timeouts + +[`Timer`] allows performing async delays. [`Ticker`] allows periodic delays without drifting over time. + +An implementation of the `embedded-hal` delay traits is provided by [`Delay`], for compatibility +with libraries from the ecosystem. + +## Wall-clock time + +The `time` module deals exclusively with a monotonically increasing tick count. +Therefore it has no direct support for wall-clock time ("real life" datetimes +like `2021-08-24 13:33:21`). + +If persistence across reboots is not needed, support can be built on top of +`embassy_time` by storing the offset between "seconds elapsed since boot" +and "seconds since unix epoch". diff --git a/embassy-time/gen_tick.py b/embassy-time/gen_tick.py index d4a175914..8961fb7e6 100644 --- a/embassy-time/gen_tick.py +++ b/embassy-time/gen_tick.py @@ -1,5 +1,4 @@ import os -import toml from glob import glob abspath = os.path.abspath(__file__) @@ -25,11 +24,11 @@ for i in range(15, 50): ticks.append(20 * i * 1_000_000) seen = set() -ticks = [x for x in ticks if not (x in seen or seen.add(x))] +ticks = sorted([x for x in ticks if not (x in seen or seen.add(x))]) # ========= Update Cargo.toml -things = {f'tick-hz-{hz:_}': [] for hz in ticks} +things = [(hz, f'tick-hz-{hz:_}') for hz in ticks] SEPARATOR_START = '# BEGIN TICKS\n' SEPARATOR_END = '# END TICKS\n' @@ -38,8 +37,22 @@ with open('Cargo.toml', 'r') as f: data = f.read() before, data = data.split(SEPARATOR_START, maxsplit=1) _, after = data.split(SEPARATOR_END, maxsplit=1) -data = before + SEPARATOR_START + HELP + \ - toml.dumps(things) + SEPARATOR_END + after + +data = before + SEPARATOR_START + HELP +for freq, feature in things: + if freq >= 1_000_000_000: + freq_human = f"{freq / 1_000_000_000}GHz" + elif freq >= 1_000_000: + freq_human = f"{freq / 1_000_000}MHz" + elif freq >= 1_000: + freq_human = f"{freq / 1000}kHz" + else: + freq_human = f"{freq}Hz" + + data += f"## {freq_human} Tick Rate\n" + data += f"{feature} = []\n" +data += SEPARATOR_END + after + with open('Cargo.toml', 'w') as f: f.write(data) diff --git a/embassy-time/src/lib.rs b/embassy-time/src/lib.rs index 82a7ee0df..a59ee68d2 100644 --- a/embassy-time/src/lib.rs +++ b/embassy-time/src/lib.rs @@ -6,6 +6,9 @@ #![allow(clippy::new_without_default)] #![warn(missing_docs)] +//! ## Feature flags +#![doc = document_features::document_features!(feature_label = r#"{feature}"#)] + // This mod MUST go first, so that the others see its macros. pub(crate) mod fmt; @@ -37,10 +40,7 @@ pub use timer::{with_timeout, Ticker, TimeoutError, Timer}; /// Ticks per second of the global timebase. /// -/// This value is specified by the `tick-*` Cargo features, which -/// should be set by the time driver. Some drivers support a fixed tick rate, others -/// allow you to choose a tick rate with Cargo features of their own. You should not -/// set the `tick-*` features for embassy yourself as an end user. +/// This value is specified by the [`tick-*` Cargo features](crate#tick-rate) pub const TICK_HZ: u64 = tick::TICK_HZ; const fn gcd(a: u64, b: u64) -> u64 { diff --git a/embassy-time/src/tick.rs b/embassy-time/src/tick.rs index 834e7c095..916ae9498 100644 --- a/embassy-time/src/tick.rs +++ b/embassy-time/src/tick.rs @@ -2,232 +2,204 @@ #[cfg(feature = "tick-hz-1")] pub const TICK_HZ: u64 = 1; -#[cfg(feature = "tick-hz-10")] -pub const TICK_HZ: u64 = 10; -#[cfg(feature = "tick-hz-100")] -pub const TICK_HZ: u64 = 100; -#[cfg(feature = "tick-hz-1_000")] -pub const TICK_HZ: u64 = 1_000; -#[cfg(feature = "tick-hz-10_000")] -pub const TICK_HZ: u64 = 10_000; -#[cfg(feature = "tick-hz-100_000")] -pub const TICK_HZ: u64 = 100_000; -#[cfg(feature = "tick-hz-1_000_000")] -pub const TICK_HZ: u64 = 1_000_000; -#[cfg(feature = "tick-hz-10_000_000")] -pub const TICK_HZ: u64 = 10_000_000; -#[cfg(feature = "tick-hz-100_000_000")] -pub const TICK_HZ: u64 = 100_000_000; -#[cfg(feature = "tick-hz-1_000_000_000")] -pub const TICK_HZ: u64 = 1_000_000_000; #[cfg(feature = "tick-hz-2")] pub const TICK_HZ: u64 = 2; #[cfg(feature = "tick-hz-4")] pub const TICK_HZ: u64 = 4; #[cfg(feature = "tick-hz-8")] pub const TICK_HZ: u64 = 8; +#[cfg(feature = "tick-hz-10")] +pub const TICK_HZ: u64 = 10; #[cfg(feature = "tick-hz-16")] pub const TICK_HZ: u64 = 16; #[cfg(feature = "tick-hz-32")] pub const TICK_HZ: u64 = 32; #[cfg(feature = "tick-hz-64")] pub const TICK_HZ: u64 = 64; +#[cfg(feature = "tick-hz-100")] +pub const TICK_HZ: u64 = 100; #[cfg(feature = "tick-hz-128")] pub const TICK_HZ: u64 = 128; #[cfg(feature = "tick-hz-256")] pub const TICK_HZ: u64 = 256; #[cfg(feature = "tick-hz-512")] pub const TICK_HZ: u64 = 512; +#[cfg(feature = "tick-hz-1_000")] +pub const TICK_HZ: u64 = 1_000; #[cfg(feature = "tick-hz-1_024")] pub const TICK_HZ: u64 = 1_024; -#[cfg(feature = "tick-hz-2_048")] -pub const TICK_HZ: u64 = 2_048; -#[cfg(feature = "tick-hz-4_096")] -pub const TICK_HZ: u64 = 4_096; -#[cfg(feature = "tick-hz-8_192")] -pub const TICK_HZ: u64 = 8_192; -#[cfg(feature = "tick-hz-16_384")] -pub const TICK_HZ: u64 = 16_384; -#[cfg(feature = "tick-hz-32_768")] -pub const TICK_HZ: u64 = 32_768; -#[cfg(feature = "tick-hz-65_536")] -pub const TICK_HZ: u64 = 65_536; -#[cfg(feature = "tick-hz-131_072")] -pub const TICK_HZ: u64 = 131_072; -#[cfg(feature = "tick-hz-262_144")] -pub const TICK_HZ: u64 = 262_144; -#[cfg(feature = "tick-hz-524_288")] -pub const TICK_HZ: u64 = 524_288; -#[cfg(feature = "tick-hz-1_048_576")] -pub const TICK_HZ: u64 = 1_048_576; -#[cfg(feature = "tick-hz-2_097_152")] -pub const TICK_HZ: u64 = 2_097_152; -#[cfg(feature = "tick-hz-4_194_304")] -pub const TICK_HZ: u64 = 4_194_304; -#[cfg(feature = "tick-hz-8_388_608")] -pub const TICK_HZ: u64 = 8_388_608; -#[cfg(feature = "tick-hz-16_777_216")] -pub const TICK_HZ: u64 = 16_777_216; #[cfg(feature = "tick-hz-2_000")] pub const TICK_HZ: u64 = 2_000; +#[cfg(feature = "tick-hz-2_048")] +pub const TICK_HZ: u64 = 2_048; #[cfg(feature = "tick-hz-4_000")] pub const TICK_HZ: u64 = 4_000; +#[cfg(feature = "tick-hz-4_096")] +pub const TICK_HZ: u64 = 4_096; #[cfg(feature = "tick-hz-8_000")] pub const TICK_HZ: u64 = 8_000; +#[cfg(feature = "tick-hz-8_192")] +pub const TICK_HZ: u64 = 8_192; +#[cfg(feature = "tick-hz-10_000")] +pub const TICK_HZ: u64 = 10_000; #[cfg(feature = "tick-hz-16_000")] pub const TICK_HZ: u64 = 16_000; -#[cfg(feature = "tick-hz-32_000")] -pub const TICK_HZ: u64 = 32_000; -#[cfg(feature = "tick-hz-64_000")] -pub const TICK_HZ: u64 = 64_000; -#[cfg(feature = "tick-hz-128_000")] -pub const TICK_HZ: u64 = 128_000; -#[cfg(feature = "tick-hz-256_000")] -pub const TICK_HZ: u64 = 256_000; -#[cfg(feature = "tick-hz-512_000")] -pub const TICK_HZ: u64 = 512_000; -#[cfg(feature = "tick-hz-1_024_000")] -pub const TICK_HZ: u64 = 1_024_000; -#[cfg(feature = "tick-hz-2_048_000")] -pub const TICK_HZ: u64 = 2_048_000; -#[cfg(feature = "tick-hz-4_096_000")] -pub const TICK_HZ: u64 = 4_096_000; -#[cfg(feature = "tick-hz-8_192_000")] -pub const TICK_HZ: u64 = 8_192_000; -#[cfg(feature = "tick-hz-16_384_000")] -pub const TICK_HZ: u64 = 16_384_000; -#[cfg(feature = "tick-hz-32_768_000")] -pub const TICK_HZ: u64 = 32_768_000; -#[cfg(feature = "tick-hz-65_536_000")] -pub const TICK_HZ: u64 = 65_536_000; -#[cfg(feature = "tick-hz-131_072_000")] -pub const TICK_HZ: u64 = 131_072_000; -#[cfg(feature = "tick-hz-262_144_000")] -pub const TICK_HZ: u64 = 262_144_000; -#[cfg(feature = "tick-hz-524_288_000")] -pub const TICK_HZ: u64 = 524_288_000; +#[cfg(feature = "tick-hz-16_384")] +pub const TICK_HZ: u64 = 16_384; #[cfg(feature = "tick-hz-20_000")] pub const TICK_HZ: u64 = 20_000; +#[cfg(feature = "tick-hz-32_000")] +pub const TICK_HZ: u64 = 32_000; +#[cfg(feature = "tick-hz-32_768")] +pub const TICK_HZ: u64 = 32_768; #[cfg(feature = "tick-hz-40_000")] pub const TICK_HZ: u64 = 40_000; +#[cfg(feature = "tick-hz-64_000")] +pub const TICK_HZ: u64 = 64_000; +#[cfg(feature = "tick-hz-65_536")] +pub const TICK_HZ: u64 = 65_536; #[cfg(feature = "tick-hz-80_000")] pub const TICK_HZ: u64 = 80_000; +#[cfg(feature = "tick-hz-100_000")] +pub const TICK_HZ: u64 = 100_000; +#[cfg(feature = "tick-hz-128_000")] +pub const TICK_HZ: u64 = 128_000; +#[cfg(feature = "tick-hz-131_072")] +pub const TICK_HZ: u64 = 131_072; #[cfg(feature = "tick-hz-160_000")] pub const TICK_HZ: u64 = 160_000; +#[cfg(feature = "tick-hz-256_000")] +pub const TICK_HZ: u64 = 256_000; +#[cfg(feature = "tick-hz-262_144")] +pub const TICK_HZ: u64 = 262_144; #[cfg(feature = "tick-hz-320_000")] pub const TICK_HZ: u64 = 320_000; +#[cfg(feature = "tick-hz-512_000")] +pub const TICK_HZ: u64 = 512_000; +#[cfg(feature = "tick-hz-524_288")] +pub const TICK_HZ: u64 = 524_288; #[cfg(feature = "tick-hz-640_000")] pub const TICK_HZ: u64 = 640_000; +#[cfg(feature = "tick-hz-1_000_000")] +pub const TICK_HZ: u64 = 1_000_000; +#[cfg(feature = "tick-hz-1_024_000")] +pub const TICK_HZ: u64 = 1_024_000; +#[cfg(feature = "tick-hz-1_048_576")] +pub const TICK_HZ: u64 = 1_048_576; #[cfg(feature = "tick-hz-1_280_000")] pub const TICK_HZ: u64 = 1_280_000; -#[cfg(feature = "tick-hz-2_560_000")] -pub const TICK_HZ: u64 = 2_560_000; -#[cfg(feature = "tick-hz-5_120_000")] -pub const TICK_HZ: u64 = 5_120_000; -#[cfg(feature = "tick-hz-10_240_000")] -pub const TICK_HZ: u64 = 10_240_000; -#[cfg(feature = "tick-hz-20_480_000")] -pub const TICK_HZ: u64 = 20_480_000; -#[cfg(feature = "tick-hz-40_960_000")] -pub const TICK_HZ: u64 = 40_960_000; -#[cfg(feature = "tick-hz-81_920_000")] -pub const TICK_HZ: u64 = 81_920_000; -#[cfg(feature = "tick-hz-163_840_000")] -pub const TICK_HZ: u64 = 163_840_000; -#[cfg(feature = "tick-hz-327_680_000")] -pub const TICK_HZ: u64 = 327_680_000; -#[cfg(feature = "tick-hz-655_360_000")] -pub const TICK_HZ: u64 = 655_360_000; -#[cfg(feature = "tick-hz-1_310_720_000")] -pub const TICK_HZ: u64 = 1_310_720_000; -#[cfg(feature = "tick-hz-2_621_440_000")] -pub const TICK_HZ: u64 = 2_621_440_000; -#[cfg(feature = "tick-hz-5_242_880_000")] -pub const TICK_HZ: u64 = 5_242_880_000; #[cfg(feature = "tick-hz-2_000_000")] pub const TICK_HZ: u64 = 2_000_000; +#[cfg(feature = "tick-hz-2_048_000")] +pub const TICK_HZ: u64 = 2_048_000; +#[cfg(feature = "tick-hz-2_097_152")] +pub const TICK_HZ: u64 = 2_097_152; +#[cfg(feature = "tick-hz-2_560_000")] +pub const TICK_HZ: u64 = 2_560_000; #[cfg(feature = "tick-hz-3_000_000")] pub const TICK_HZ: u64 = 3_000_000; #[cfg(feature = "tick-hz-4_000_000")] pub const TICK_HZ: u64 = 4_000_000; +#[cfg(feature = "tick-hz-4_096_000")] +pub const TICK_HZ: u64 = 4_096_000; +#[cfg(feature = "tick-hz-4_194_304")] +pub const TICK_HZ: u64 = 4_194_304; +#[cfg(feature = "tick-hz-5_120_000")] +pub const TICK_HZ: u64 = 5_120_000; #[cfg(feature = "tick-hz-6_000_000")] pub const TICK_HZ: u64 = 6_000_000; #[cfg(feature = "tick-hz-8_000_000")] pub const TICK_HZ: u64 = 8_000_000; +#[cfg(feature = "tick-hz-8_192_000")] +pub const TICK_HZ: u64 = 8_192_000; +#[cfg(feature = "tick-hz-8_388_608")] +pub const TICK_HZ: u64 = 8_388_608; #[cfg(feature = "tick-hz-9_000_000")] pub const TICK_HZ: u64 = 9_000_000; +#[cfg(feature = "tick-hz-10_000_000")] +pub const TICK_HZ: u64 = 10_000_000; +#[cfg(feature = "tick-hz-10_240_000")] +pub const TICK_HZ: u64 = 10_240_000; #[cfg(feature = "tick-hz-12_000_000")] pub const TICK_HZ: u64 = 12_000_000; #[cfg(feature = "tick-hz-16_000_000")] pub const TICK_HZ: u64 = 16_000_000; +#[cfg(feature = "tick-hz-16_384_000")] +pub const TICK_HZ: u64 = 16_384_000; +#[cfg(feature = "tick-hz-16_777_216")] +pub const TICK_HZ: u64 = 16_777_216; #[cfg(feature = "tick-hz-18_000_000")] pub const TICK_HZ: u64 = 18_000_000; -#[cfg(feature = "tick-hz-24_000_000")] -pub const TICK_HZ: u64 = 24_000_000; -#[cfg(feature = "tick-hz-32_000_000")] -pub const TICK_HZ: u64 = 32_000_000; -#[cfg(feature = "tick-hz-36_000_000")] -pub const TICK_HZ: u64 = 36_000_000; -#[cfg(feature = "tick-hz-48_000_000")] -pub const TICK_HZ: u64 = 48_000_000; -#[cfg(feature = "tick-hz-64_000_000")] -pub const TICK_HZ: u64 = 64_000_000; -#[cfg(feature = "tick-hz-72_000_000")] -pub const TICK_HZ: u64 = 72_000_000; -#[cfg(feature = "tick-hz-96_000_000")] -pub const TICK_HZ: u64 = 96_000_000; -#[cfg(feature = "tick-hz-128_000_000")] -pub const TICK_HZ: u64 = 128_000_000; -#[cfg(feature = "tick-hz-144_000_000")] -pub const TICK_HZ: u64 = 144_000_000; -#[cfg(feature = "tick-hz-192_000_000")] -pub const TICK_HZ: u64 = 192_000_000; -#[cfg(feature = "tick-hz-256_000_000")] -pub const TICK_HZ: u64 = 256_000_000; -#[cfg(feature = "tick-hz-288_000_000")] -pub const TICK_HZ: u64 = 288_000_000; -#[cfg(feature = "tick-hz-384_000_000")] -pub const TICK_HZ: u64 = 384_000_000; -#[cfg(feature = "tick-hz-512_000_000")] -pub const TICK_HZ: u64 = 512_000_000; -#[cfg(feature = "tick-hz-576_000_000")] -pub const TICK_HZ: u64 = 576_000_000; -#[cfg(feature = "tick-hz-768_000_000")] -pub const TICK_HZ: u64 = 768_000_000; #[cfg(feature = "tick-hz-20_000_000")] pub const TICK_HZ: u64 = 20_000_000; +#[cfg(feature = "tick-hz-20_480_000")] +pub const TICK_HZ: u64 = 20_480_000; +#[cfg(feature = "tick-hz-24_000_000")] +pub const TICK_HZ: u64 = 24_000_000; #[cfg(feature = "tick-hz-30_000_000")] pub const TICK_HZ: u64 = 30_000_000; +#[cfg(feature = "tick-hz-32_000_000")] +pub const TICK_HZ: u64 = 32_000_000; +#[cfg(feature = "tick-hz-32_768_000")] +pub const TICK_HZ: u64 = 32_768_000; +#[cfg(feature = "tick-hz-36_000_000")] +pub const TICK_HZ: u64 = 36_000_000; #[cfg(feature = "tick-hz-40_000_000")] pub const TICK_HZ: u64 = 40_000_000; +#[cfg(feature = "tick-hz-40_960_000")] +pub const TICK_HZ: u64 = 40_960_000; +#[cfg(feature = "tick-hz-48_000_000")] +pub const TICK_HZ: u64 = 48_000_000; #[cfg(feature = "tick-hz-50_000_000")] pub const TICK_HZ: u64 = 50_000_000; #[cfg(feature = "tick-hz-60_000_000")] pub const TICK_HZ: u64 = 60_000_000; +#[cfg(feature = "tick-hz-64_000_000")] +pub const TICK_HZ: u64 = 64_000_000; +#[cfg(feature = "tick-hz-65_536_000")] +pub const TICK_HZ: u64 = 65_536_000; #[cfg(feature = "tick-hz-70_000_000")] pub const TICK_HZ: u64 = 70_000_000; +#[cfg(feature = "tick-hz-72_000_000")] +pub const TICK_HZ: u64 = 72_000_000; #[cfg(feature = "tick-hz-80_000_000")] pub const TICK_HZ: u64 = 80_000_000; +#[cfg(feature = "tick-hz-81_920_000")] +pub const TICK_HZ: u64 = 81_920_000; #[cfg(feature = "tick-hz-90_000_000")] pub const TICK_HZ: u64 = 90_000_000; +#[cfg(feature = "tick-hz-96_000_000")] +pub const TICK_HZ: u64 = 96_000_000; +#[cfg(feature = "tick-hz-100_000_000")] +pub const TICK_HZ: u64 = 100_000_000; #[cfg(feature = "tick-hz-110_000_000")] pub const TICK_HZ: u64 = 110_000_000; #[cfg(feature = "tick-hz-120_000_000")] pub const TICK_HZ: u64 = 120_000_000; +#[cfg(feature = "tick-hz-128_000_000")] +pub const TICK_HZ: u64 = 128_000_000; #[cfg(feature = "tick-hz-130_000_000")] pub const TICK_HZ: u64 = 130_000_000; +#[cfg(feature = "tick-hz-131_072_000")] +pub const TICK_HZ: u64 = 131_072_000; #[cfg(feature = "tick-hz-140_000_000")] pub const TICK_HZ: u64 = 140_000_000; +#[cfg(feature = "tick-hz-144_000_000")] +pub const TICK_HZ: u64 = 144_000_000; #[cfg(feature = "tick-hz-150_000_000")] pub const TICK_HZ: u64 = 150_000_000; #[cfg(feature = "tick-hz-160_000_000")] pub const TICK_HZ: u64 = 160_000_000; +#[cfg(feature = "tick-hz-163_840_000")] +pub const TICK_HZ: u64 = 163_840_000; #[cfg(feature = "tick-hz-170_000_000")] pub const TICK_HZ: u64 = 170_000_000; #[cfg(feature = "tick-hz-180_000_000")] pub const TICK_HZ: u64 = 180_000_000; #[cfg(feature = "tick-hz-190_000_000")] pub const TICK_HZ: u64 = 190_000_000; +#[cfg(feature = "tick-hz-192_000_000")] +pub const TICK_HZ: u64 = 192_000_000; #[cfg(feature = "tick-hz-200_000_000")] pub const TICK_HZ: u64 = 200_000_000; #[cfg(feature = "tick-hz-210_000_000")] @@ -240,24 +212,34 @@ pub const TICK_HZ: u64 = 230_000_000; pub const TICK_HZ: u64 = 240_000_000; #[cfg(feature = "tick-hz-250_000_000")] pub const TICK_HZ: u64 = 250_000_000; +#[cfg(feature = "tick-hz-256_000_000")] +pub const TICK_HZ: u64 = 256_000_000; #[cfg(feature = "tick-hz-260_000_000")] pub const TICK_HZ: u64 = 260_000_000; +#[cfg(feature = "tick-hz-262_144_000")] +pub const TICK_HZ: u64 = 262_144_000; #[cfg(feature = "tick-hz-270_000_000")] pub const TICK_HZ: u64 = 270_000_000; #[cfg(feature = "tick-hz-280_000_000")] pub const TICK_HZ: u64 = 280_000_000; +#[cfg(feature = "tick-hz-288_000_000")] +pub const TICK_HZ: u64 = 288_000_000; #[cfg(feature = "tick-hz-290_000_000")] pub const TICK_HZ: u64 = 290_000_000; #[cfg(feature = "tick-hz-300_000_000")] pub const TICK_HZ: u64 = 300_000_000; #[cfg(feature = "tick-hz-320_000_000")] pub const TICK_HZ: u64 = 320_000_000; +#[cfg(feature = "tick-hz-327_680_000")] +pub const TICK_HZ: u64 = 327_680_000; #[cfg(feature = "tick-hz-340_000_000")] pub const TICK_HZ: u64 = 340_000_000; #[cfg(feature = "tick-hz-360_000_000")] pub const TICK_HZ: u64 = 360_000_000; #[cfg(feature = "tick-hz-380_000_000")] pub const TICK_HZ: u64 = 380_000_000; +#[cfg(feature = "tick-hz-384_000_000")] +pub const TICK_HZ: u64 = 384_000_000; #[cfg(feature = "tick-hz-400_000_000")] pub const TICK_HZ: u64 = 400_000_000; #[cfg(feature = "tick-hz-420_000_000")] @@ -270,12 +252,18 @@ pub const TICK_HZ: u64 = 460_000_000; pub const TICK_HZ: u64 = 480_000_000; #[cfg(feature = "tick-hz-500_000_000")] pub const TICK_HZ: u64 = 500_000_000; +#[cfg(feature = "tick-hz-512_000_000")] +pub const TICK_HZ: u64 = 512_000_000; #[cfg(feature = "tick-hz-520_000_000")] pub const TICK_HZ: u64 = 520_000_000; +#[cfg(feature = "tick-hz-524_288_000")] +pub const TICK_HZ: u64 = 524_288_000; #[cfg(feature = "tick-hz-540_000_000")] pub const TICK_HZ: u64 = 540_000_000; #[cfg(feature = "tick-hz-560_000_000")] pub const TICK_HZ: u64 = 560_000_000; +#[cfg(feature = "tick-hz-576_000_000")] +pub const TICK_HZ: u64 = 576_000_000; #[cfg(feature = "tick-hz-580_000_000")] pub const TICK_HZ: u64 = 580_000_000; #[cfg(feature = "tick-hz-600_000_000")] @@ -284,6 +272,8 @@ pub const TICK_HZ: u64 = 600_000_000; pub const TICK_HZ: u64 = 620_000_000; #[cfg(feature = "tick-hz-640_000_000")] pub const TICK_HZ: u64 = 640_000_000; +#[cfg(feature = "tick-hz-655_360_000")] +pub const TICK_HZ: u64 = 655_360_000; #[cfg(feature = "tick-hz-660_000_000")] pub const TICK_HZ: u64 = 660_000_000; #[cfg(feature = "tick-hz-680_000_000")] @@ -296,6 +286,8 @@ pub const TICK_HZ: u64 = 720_000_000; pub const TICK_HZ: u64 = 740_000_000; #[cfg(feature = "tick-hz-760_000_000")] pub const TICK_HZ: u64 = 760_000_000; +#[cfg(feature = "tick-hz-768_000_000")] +pub const TICK_HZ: u64 = 768_000_000; #[cfg(feature = "tick-hz-780_000_000")] pub const TICK_HZ: u64 = 780_000_000; #[cfg(feature = "tick-hz-800_000_000")] @@ -318,155 +310,159 @@ pub const TICK_HZ: u64 = 940_000_000; pub const TICK_HZ: u64 = 960_000_000; #[cfg(feature = "tick-hz-980_000_000")] pub const TICK_HZ: u64 = 980_000_000; +#[cfg(feature = "tick-hz-1_000_000_000")] +pub const TICK_HZ: u64 = 1_000_000_000; +#[cfg(feature = "tick-hz-1_310_720_000")] +pub const TICK_HZ: u64 = 1_310_720_000; +#[cfg(feature = "tick-hz-2_621_440_000")] +pub const TICK_HZ: u64 = 2_621_440_000; +#[cfg(feature = "tick-hz-5_242_880_000")] +pub const TICK_HZ: u64 = 5_242_880_000; #[cfg(not(any( feature = "tick-hz-1", - feature = "tick-hz-10", - feature = "tick-hz-100", - feature = "tick-hz-1_000", - feature = "tick-hz-10_000", - feature = "tick-hz-100_000", - feature = "tick-hz-1_000_000", - feature = "tick-hz-10_000_000", - feature = "tick-hz-100_000_000", - feature = "tick-hz-1_000_000_000", feature = "tick-hz-2", feature = "tick-hz-4", feature = "tick-hz-8", + feature = "tick-hz-10", feature = "tick-hz-16", feature = "tick-hz-32", feature = "tick-hz-64", + feature = "tick-hz-100", feature = "tick-hz-128", feature = "tick-hz-256", feature = "tick-hz-512", + feature = "tick-hz-1_000", feature = "tick-hz-1_024", - feature = "tick-hz-2_048", - feature = "tick-hz-4_096", - feature = "tick-hz-8_192", - feature = "tick-hz-16_384", - feature = "tick-hz-32_768", - feature = "tick-hz-65_536", - feature = "tick-hz-131_072", - feature = "tick-hz-262_144", - feature = "tick-hz-524_288", - feature = "tick-hz-1_048_576", - feature = "tick-hz-2_097_152", - feature = "tick-hz-4_194_304", - feature = "tick-hz-8_388_608", - feature = "tick-hz-16_777_216", feature = "tick-hz-2_000", + feature = "tick-hz-2_048", feature = "tick-hz-4_000", + feature = "tick-hz-4_096", feature = "tick-hz-8_000", + feature = "tick-hz-8_192", + feature = "tick-hz-10_000", feature = "tick-hz-16_000", - feature = "tick-hz-32_000", - feature = "tick-hz-64_000", - feature = "tick-hz-128_000", - feature = "tick-hz-256_000", - feature = "tick-hz-512_000", - feature = "tick-hz-1_024_000", - feature = "tick-hz-2_048_000", - feature = "tick-hz-4_096_000", - feature = "tick-hz-8_192_000", - feature = "tick-hz-16_384_000", - feature = "tick-hz-32_768_000", - feature = "tick-hz-65_536_000", - feature = "tick-hz-131_072_000", - feature = "tick-hz-262_144_000", - feature = "tick-hz-524_288_000", + feature = "tick-hz-16_384", feature = "tick-hz-20_000", + feature = "tick-hz-32_000", + feature = "tick-hz-32_768", feature = "tick-hz-40_000", + feature = "tick-hz-64_000", + feature = "tick-hz-65_536", feature = "tick-hz-80_000", + feature = "tick-hz-100_000", + feature = "tick-hz-128_000", + feature = "tick-hz-131_072", feature = "tick-hz-160_000", + feature = "tick-hz-256_000", + feature = "tick-hz-262_144", feature = "tick-hz-320_000", + feature = "tick-hz-512_000", + feature = "tick-hz-524_288", feature = "tick-hz-640_000", + feature = "tick-hz-1_000_000", + feature = "tick-hz-1_024_000", + feature = "tick-hz-1_048_576", feature = "tick-hz-1_280_000", - feature = "tick-hz-2_560_000", - feature = "tick-hz-5_120_000", - feature = "tick-hz-10_240_000", - feature = "tick-hz-20_480_000", - feature = "tick-hz-40_960_000", - feature = "tick-hz-81_920_000", - feature = "tick-hz-163_840_000", - feature = "tick-hz-327_680_000", - feature = "tick-hz-655_360_000", - feature = "tick-hz-1_310_720_000", - feature = "tick-hz-2_621_440_000", - feature = "tick-hz-5_242_880_000", feature = "tick-hz-2_000_000", + feature = "tick-hz-2_048_000", + feature = "tick-hz-2_097_152", + feature = "tick-hz-2_560_000", feature = "tick-hz-3_000_000", feature = "tick-hz-4_000_000", + feature = "tick-hz-4_096_000", + feature = "tick-hz-4_194_304", + feature = "tick-hz-5_120_000", feature = "tick-hz-6_000_000", feature = "tick-hz-8_000_000", + feature = "tick-hz-8_192_000", + feature = "tick-hz-8_388_608", feature = "tick-hz-9_000_000", + feature = "tick-hz-10_000_000", + feature = "tick-hz-10_240_000", feature = "tick-hz-12_000_000", feature = "tick-hz-16_000_000", + feature = "tick-hz-16_384_000", + feature = "tick-hz-16_777_216", feature = "tick-hz-18_000_000", - feature = "tick-hz-24_000_000", - feature = "tick-hz-32_000_000", - feature = "tick-hz-36_000_000", - feature = "tick-hz-48_000_000", - feature = "tick-hz-64_000_000", - feature = "tick-hz-72_000_000", - feature = "tick-hz-96_000_000", - feature = "tick-hz-128_000_000", - feature = "tick-hz-144_000_000", - feature = "tick-hz-192_000_000", - feature = "tick-hz-256_000_000", - feature = "tick-hz-288_000_000", - feature = "tick-hz-384_000_000", - feature = "tick-hz-512_000_000", - feature = "tick-hz-576_000_000", - feature = "tick-hz-768_000_000", feature = "tick-hz-20_000_000", + feature = "tick-hz-20_480_000", + feature = "tick-hz-24_000_000", feature = "tick-hz-30_000_000", + feature = "tick-hz-32_000_000", + feature = "tick-hz-32_768_000", + feature = "tick-hz-36_000_000", feature = "tick-hz-40_000_000", + feature = "tick-hz-40_960_000", + feature = "tick-hz-48_000_000", feature = "tick-hz-50_000_000", feature = "tick-hz-60_000_000", + feature = "tick-hz-64_000_000", + feature = "tick-hz-65_536_000", feature = "tick-hz-70_000_000", + feature = "tick-hz-72_000_000", feature = "tick-hz-80_000_000", + feature = "tick-hz-81_920_000", feature = "tick-hz-90_000_000", + feature = "tick-hz-96_000_000", + feature = "tick-hz-100_000_000", feature = "tick-hz-110_000_000", feature = "tick-hz-120_000_000", + feature = "tick-hz-128_000_000", feature = "tick-hz-130_000_000", + feature = "tick-hz-131_072_000", feature = "tick-hz-140_000_000", + feature = "tick-hz-144_000_000", feature = "tick-hz-150_000_000", feature = "tick-hz-160_000_000", + feature = "tick-hz-163_840_000", feature = "tick-hz-170_000_000", feature = "tick-hz-180_000_000", feature = "tick-hz-190_000_000", + feature = "tick-hz-192_000_000", feature = "tick-hz-200_000_000", feature = "tick-hz-210_000_000", feature = "tick-hz-220_000_000", feature = "tick-hz-230_000_000", feature = "tick-hz-240_000_000", feature = "tick-hz-250_000_000", + feature = "tick-hz-256_000_000", feature = "tick-hz-260_000_000", + feature = "tick-hz-262_144_000", feature = "tick-hz-270_000_000", feature = "tick-hz-280_000_000", + feature = "tick-hz-288_000_000", feature = "tick-hz-290_000_000", feature = "tick-hz-300_000_000", feature = "tick-hz-320_000_000", + feature = "tick-hz-327_680_000", feature = "tick-hz-340_000_000", feature = "tick-hz-360_000_000", feature = "tick-hz-380_000_000", + feature = "tick-hz-384_000_000", feature = "tick-hz-400_000_000", feature = "tick-hz-420_000_000", feature = "tick-hz-440_000_000", feature = "tick-hz-460_000_000", feature = "tick-hz-480_000_000", feature = "tick-hz-500_000_000", + feature = "tick-hz-512_000_000", feature = "tick-hz-520_000_000", + feature = "tick-hz-524_288_000", feature = "tick-hz-540_000_000", feature = "tick-hz-560_000_000", + feature = "tick-hz-576_000_000", feature = "tick-hz-580_000_000", feature = "tick-hz-600_000_000", feature = "tick-hz-620_000_000", feature = "tick-hz-640_000_000", + feature = "tick-hz-655_360_000", feature = "tick-hz-660_000_000", feature = "tick-hz-680_000_000", feature = "tick-hz-700_000_000", feature = "tick-hz-720_000_000", feature = "tick-hz-740_000_000", feature = "tick-hz-760_000_000", + feature = "tick-hz-768_000_000", feature = "tick-hz-780_000_000", feature = "tick-hz-800_000_000", feature = "tick-hz-820_000_000", @@ -478,5 +474,9 @@ pub const TICK_HZ: u64 = 980_000_000; feature = "tick-hz-940_000_000", feature = "tick-hz-960_000_000", feature = "tick-hz-980_000_000", + feature = "tick-hz-1_000_000_000", + feature = "tick-hz-1_310_720_000", + feature = "tick-hz-2_621_440_000", + feature = "tick-hz-5_242_880_000", )))] pub const TICK_HZ: u64 = 1_000_000; From 5150deb70b171ef536d1d08946e72199c458180b Mon Sep 17 00:00:00 2001 From: Barnaby Walters Date: Fri, 22 Dec 2023 17:33:24 +0100 Subject: [PATCH 099/124] Minor typo corrections --- embassy-time/Cargo.toml | 4 ++-- embassy-time/README.md | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/embassy-time/Cargo.toml b/embassy-time/Cargo.toml index 534894b20..7259169cd 100644 --- a/embassy-time/Cargo.toml +++ b/embassy-time/Cargo.toml @@ -41,11 +41,11 @@ mock-driver = ["tick-hz-1_000_000"] #! ### Generic Queue -## Create a global, generic queue that can be used with any executor +## Create a global, generic queue that can be used with any executor. ## To use this you must have a time driver provided. generic-queue = [] -#! The following features set how many timers are used for the generic queue. At most 1 +#! The following features set how many timers are used for the generic queue. At most one #! `generic-queue-*` feature can be enabled. If none is enabled, a default of 64 timers is used. #! #! When using embassy-time from libraries, you should *not* enable any `generic-queue-*` feature, to allow the diff --git a/embassy-time/README.md b/embassy-time/README.md index a4a622700..a4e150c14 100644 --- a/embassy-time/README.md +++ b/embassy-time/README.md @@ -3,8 +3,8 @@ Timekeeping, delays and timeouts. Timekeeping is done with elapsed time since system boot. Time is represented in -ticks, where the tick rate is defined either by the driver (in the case of a fixed- -rate tick) or chosen by the user with a [tick rate](#tick-rate) feature. The chosen +ticks, where the tick rate is defined either by the driver (in the case of a fixed-rate +tick) or chosen by the user with a [tick rate](#tick-rate) feature. The chosen tick rate applies to everything in `embassy-time` and thus determines the maximum timing resolution of (1 / tick_rate) seconds. From 6bbc316312b2ba372ea05c52924d99bc4fb5382a Mon Sep 17 00:00:00 2001 From: Barnaby Walters Date: Fri, 22 Dec 2023 19:05:16 +0100 Subject: [PATCH 100/124] [embassy-executor] improved documentation * Feature auto-documentation * Task arena sizes in a
list * Non-documented comment explaining turbowakers with see-also link Further improvements: * Are the task-arena-size-* numbers sizes in bytes? or something else? * Task arena section could benefit from advice about how to choose a suitable size --- embassy-executor/Cargo.toml | 88 +++++++++++++++++++++++++++++----- embassy-executor/README.md | 2 +- embassy-executor/gen_config.py | 6 +++ embassy-executor/src/lib.rs | 3 ++ 4 files changed, 85 insertions(+), 14 deletions(-) diff --git a/embassy-executor/Cargo.toml b/embassy-executor/Cargo.toml index 4dcd03b0f..c71452398 100644 --- a/embassy-executor/Cargo.toml +++ b/embassy-executor/Cargo.toml @@ -36,6 +36,8 @@ embassy-executor-macros = { version = "0.4.0", path = "../embassy-executor-macro embassy-time = { version = "0.2", path = "../embassy-time", optional = true} critical-section = "1.1" +document-features = "0.2.7" + # needed for riscv # remove when https://github.com/rust-lang/rust/pull/114499 is merged portable-atomic = { version = "1.5", optional = true } @@ -53,66 +55,126 @@ critical-section = { version = "1.1", features = ["std"] } [features] -# Architecture -_arch = [] # some arch was picked -arch-std = ["_arch", "critical-section/std"] -arch-cortex-m = ["_arch", "dep:cortex-m"] -arch-riscv32 = ["_arch", "dep:portable-atomic"] -arch-wasm = ["_arch", "dep:wasm-bindgen", "dep:js-sys"] - -# Enable the thread-mode executor (using WFE/SEV in Cortex-M, WFI in other embedded archs) -executor-thread = [] -# Enable the interrupt-mode executor (available in Cortex-M only) -executor-interrupt = [] - -# Enable nightly-only features +## Enable nightly-only features nightly = ["embassy-executor-macros/nightly"] +# Enables turbo wakers, which requires patching core. Not surfaced in the docs by default due to +# being an complicated advanced and undocumented feature. +# See: https://github.com/embassy-rs/embassy/pull/1263 turbowakers = [] +## Use timers from `embassy-time` integrated-timers = ["dep:embassy-time"] +#! ### Architecture +_arch = [] # some arch was picked +## std +arch-std = ["_arch", "critical-section/std"] +## Cortex-M +arch-cortex-m = ["_arch", "dep:cortex-m"] +## RISC-V 32 +arch-riscv32 = ["_arch", "dep:portable-atomic"] +## WASM +arch-wasm = ["_arch", "dep:wasm-bindgen", "dep:js-sys"] + +#! ### Executor + +## Enable the thread-mode executor (using WFE/SEV in Cortex-M, WFI in other embedded archs) +executor-thread = [] +## Enable the interrupt-mode executor (available in Cortex-M only) +executor-interrupt = [] + +#! ### Task Arena Size +#! Sets the [task arena](#task-arena) size. Necessary if you’re not using `nightly`. +#! +#!
+#! Preconfigured Task Arena Sizes: +#! +#! + # BEGIN AUTOGENERATED CONFIG FEATURES # Generated by gen_config.py. DO NOT EDIT. +## 64 task-arena-size-64 = [] +## 128 task-arena-size-128 = [] +## 192 task-arena-size-192 = [] +## 256 task-arena-size-256 = [] +## 320 task-arena-size-320 = [] +## 384 task-arena-size-384 = [] +## 512 task-arena-size-512 = [] +## 640 task-arena-size-640 = [] +## 768 task-arena-size-768 = [] +## 1024 task-arena-size-1024 = [] +## 1280 task-arena-size-1280 = [] +## 1536 task-arena-size-1536 = [] +## 2048 task-arena-size-2048 = [] +## 2560 task-arena-size-2560 = [] +## 3072 task-arena-size-3072 = [] +## 4096 (default) task-arena-size-4096 = [] # Default +## 5120 task-arena-size-5120 = [] +## 6144 task-arena-size-6144 = [] +## 8192 task-arena-size-8192 = [] +## 10240 task-arena-size-10240 = [] +## 12288 task-arena-size-12288 = [] +## 16384 task-arena-size-16384 = [] +## 20480 task-arena-size-20480 = [] +## 24576 task-arena-size-24576 = [] +## 32768 task-arena-size-32768 = [] +## 40960 task-arena-size-40960 = [] +## 49152 task-arena-size-49152 = [] +## 65536 task-arena-size-65536 = [] +## 81920 task-arena-size-81920 = [] +## 98304 task-arena-size-98304 = [] +## 131072 task-arena-size-131072 = [] +## 163840 task-arena-size-163840 = [] +## 196608 task-arena-size-196608 = [] +## 262144 task-arena-size-262144 = [] +## 327680 task-arena-size-327680 = [] +## 393216 task-arena-size-393216 = [] +## 524288 task-arena-size-524288 = [] +## 655360 task-arena-size-655360 = [] +## 786432 task-arena-size-786432 = [] +## 1048576 task-arena-size-1048576 = [] # END AUTOGENERATED CONFIG FEATURES + +#!
\ No newline at end of file diff --git a/embassy-executor/README.md b/embassy-executor/README.md index 80ecfc71a..aa9d59907 100644 --- a/embassy-executor/README.md +++ b/embassy-executor/README.md @@ -22,7 +22,7 @@ Tasks are allocated from the arena when spawned for the first time. If the task The arena size can be configured in two ways: - Via Cargo features: enable a Cargo feature like `task-arena-size-8192`. Only a selection of values - is available, check `Cargo.toml` for the list. + is available, see [Task Area Sizes](#task-arena-size) for reference. - Via environment variables at build time: set the variable named `EMBASSY_EXECUTOR_TASK_ARENA_SIZE`. For example `EMBASSY_EXECUTOR_TASK_ARENA_SIZE=4321 cargo build`. You can also set them in the `[env]` section of `.cargo/config.toml`. Any value can be set, unlike with Cargo features. diff --git a/embassy-executor/gen_config.py b/embassy-executor/gen_config.py index e427d29f4..cf32bd530 100644 --- a/embassy-executor/gen_config.py +++ b/embassy-executor/gen_config.py @@ -45,6 +45,12 @@ things = "" for f in features: name = f["name"].replace("_", "-") for val in f["vals"]: + things += f"## {val}" + if val == f["default"]: + things += " (default)\n" + else: + things += "\n" + things += f"{name}-{val} = []" if val == f["default"]: things += " # Default" diff --git a/embassy-executor/src/lib.rs b/embassy-executor/src/lib.rs index 4c6900a6d..eea118ade 100644 --- a/embassy-executor/src/lib.rs +++ b/embassy-executor/src/lib.rs @@ -3,6 +3,9 @@ #![doc = include_str!("../README.md")] #![warn(missing_docs)] +//! ## Feature flags +#![doc = document_features::document_features!(feature_label = r#"{feature}"#)] + // This mod MUST go first, so that the others see its macros. pub(crate) mod fmt; From c1156d73d3f15f8f6c364faabdc2ea7432d21da6 Mon Sep 17 00:00:00 2001 From: Barnaby Walters Date: Fri, 22 Dec 2023 19:40:41 +0100 Subject: [PATCH 101/124] Updated driver implementation docs --- embassy-time/src/driver.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/embassy-time/src/driver.rs b/embassy-time/src/driver.rs index 81ee1b0f5..2afa454fe 100644 --- a/embassy-time/src/driver.rs +++ b/embassy-time/src/driver.rs @@ -7,11 +7,16 @@ //! - Define a struct `MyDriver` //! - Implement [`Driver`] for it //! - Register it as the global driver with [`time_driver_impl`](crate::time_driver_impl). -//! - Enable the Cargo features `embassy-executor/time` and one of `embassy-time/tick-*` corresponding to the -//! tick rate of your driver. +//! - Enable the Cargo feature `embassy-executor/time` //! -//! If you wish to make the tick rate configurable by the end user, you should do so by exposing your own -//! Cargo features and having each enable the corresponding `embassy-time/tick-*`. +//! If your driver has a single set tick rate, enable the corresponding [`tick-hz-*`](crate#tick-rate) feature, +//! which will prevent users from needing to configure it themselves (or selecting an incorrect configuration). +//! +//! If your driver supports a small number of set tick rates, expose your own cargo features and have each one +//! enable the corresponding `embassy-time/tick-*`. +//! +//! Otherwise, don’t enable any `tick-hz-*` feature to let the user configure the tick rate themselves by +//! enabling a feature on `embassy-time`. //! //! # Linkage details //! From d63590cb61e0fb9164996677be790c4213ef4a9e Mon Sep 17 00:00:00 2001 From: Barnaby Walters Date: Fri, 22 Dec 2023 23:20:43 +0100 Subject: [PATCH 102/124] [embassy-net] Auto-documented feature flags --- embassy-net/Cargo.toml | 17 +++++++++++++++++ embassy-net/src/lib.rs | 3 +++ 2 files changed, 20 insertions(+) diff --git a/embassy-net/Cargo.toml b/embassy-net/Cargo.toml index 0c07e3651..e6c5ea74f 100644 --- a/embassy-net/Cargo.toml +++ b/embassy-net/Cargo.toml @@ -25,18 +25,34 @@ features = ["defmt", "tcp", "udp", "dns", "dhcpv4", "proto-ipv6", "medium-ethern default = [] std = [] +## Enable defmt defmt = ["dep:defmt", "smoltcp/defmt", "embassy-net-driver/defmt", "heapless/defmt-03"] +#! Many of the following feature flags are re-exports of smoltcp feature flags. See +#! the [smoltcp feature flag documentation](https://github.com/smoltcp-rs/smoltcp#feature-flags) +#! for more details + +## Enable UDP support udp = ["smoltcp/socket-udp"] +## Enable TCP support tcp = ["smoltcp/socket-tcp"] +## Enable DNS support dns = ["smoltcp/socket-dns", "smoltcp/proto-dns"] +## Enable DHCPv4 support dhcpv4 = ["proto-ipv4", "medium-ethernet", "smoltcp/socket-dhcpv4"] +## Enable DHCPv4 support with hostname dhcpv4-hostname = ["dhcpv4"] +## Enable IPv4 support proto-ipv4 = ["smoltcp/proto-ipv4"] +## Enable IPv6 support proto-ipv6 = ["smoltcp/proto-ipv6"] +## Enable the Ethernet medium medium-ethernet = ["smoltcp/medium-ethernet"] +## Enable the IP medium medium-ip = ["smoltcp/medium-ip"] +## Enable the IEEE 802.15.4 medium medium-ieee802154 = ["smoltcp/medium-ieee802154"] +## Enable IGMP support igmp = ["smoltcp/proto-igmp"] [dependencies] @@ -62,3 +78,4 @@ stable_deref_trait = { version = "1.2.0", default-features = false } futures = { version = "0.3.17", default-features = false, features = [ "async-await" ] } atomic-pool = "1.0" embedded-nal-async = { version = "0.7.1" } +document-features = "0.2.7" diff --git a/embassy-net/src/lib.rs b/embassy-net/src/lib.rs index d970d0332..2cef2232c 100644 --- a/embassy-net/src/lib.rs +++ b/embassy-net/src/lib.rs @@ -5,6 +5,9 @@ #![warn(missing_docs)] #![doc = include_str!("../README.md")] +//! ## Feature flags +#![doc = document_features::document_features!(feature_label = r#"{feature}"#)] + #[cfg(not(any(feature = "proto-ipv4", feature = "proto-ipv6")))] compile_error!("You must enable at least one of the following features: proto-ipv4, proto-ipv6"); From 05c8d410a229f838c1acbe415f44f6f0574e1562 Mon Sep 17 00:00:00 2001 From: Barnaby Walters Date: Fri, 22 Dec 2023 23:37:29 +0100 Subject: [PATCH 103/124] [embassy-nrf] auto-documented features --- embassy-nrf/Cargo.toml | 63 +++++++++++++++++++++++++++--------------- embassy-nrf/src/lib.rs | 3 ++ 2 files changed, 44 insertions(+), 22 deletions(-) diff --git a/embassy-nrf/Cargo.toml b/embassy-nrf/Cargo.toml index 970f62b0c..4648d56d9 100644 --- a/embassy-nrf/Cargo.toml +++ b/embassy-nrf/Cargo.toml @@ -17,6 +17,7 @@ flavors = [ [features] default = ["rt"] +## Cortex-M runtime (enabled by default) rt = [ "nrf52805-pac?/rt", "nrf52810-pac?/rt", @@ -30,45 +31,62 @@ rt = [ "nrf9160-pac?/rt", ] +## Enable features requiring `embassy-time` time = ["dep:embassy-time"] +## Enable defmt defmt = ["dep:defmt", "embassy-hal-internal/defmt", "embassy-sync/defmt", "embassy-usb-driver/defmt", "embassy-embedded-hal/defmt"] -# Reexport the PAC for the currently enabled chip at `embassy_nrf::pac`. +## Reexport the PAC for the currently enabled chip at `embassy_nrf::pac` (unstable) +unstable-pac = [] # This is unstable because semver-minor (non-breaking) releases of embassy-nrf may major-bump (breaking) the PAC version. # If this is an issue for you, you're encouraged to directly depend on a fixed version of the PAC. # There are no plans to make this stable. -unstable-pac = [] - -nrf52805 = ["nrf52805-pac", "_nrf52"] -nrf52810 = ["nrf52810-pac", "_nrf52"] -nrf52811 = ["nrf52811-pac", "_nrf52"] -nrf52820 = ["nrf52820-pac", "_nrf52"] -nrf52832 = ["nrf52832-pac", "_nrf52", "_nrf52832_anomaly_109"] -nrf52833 = ["nrf52833-pac", "_nrf52", "_gpio-p1"] -nrf52840 = ["nrf52840-pac", "_nrf52", "_gpio-p1"] -nrf5340-app-s = ["_nrf5340-app", "_s"] -nrf5340-app-ns = ["_nrf5340-app", "_ns"] -nrf5340-net = ["_nrf5340-net"] -nrf9160-s = ["_nrf9160", "_s"] -nrf9160-ns = ["_nrf9160", "_ns"] +## Enable GPIO tasks and events gpiote = [] + +## Use RTC1 as the time driver for `embassy-time`, with a tick rate of 32.768khz time-driver-rtc1 = ["_time-driver"] -# Allow using the NFC pins as regular GPIO pins (P0_09/P0_10 on nRF52, P0_02/P0_03 on nRF53) +## Allow using the NFC pins as regular GPIO pins (P0_09/P0_10 on nRF52, P0_02/P0_03 on nRF53) nfc-pins-as-gpio = [] -# Allow using the RST pin as a regular GPIO pin. -# nrf52805, nrf52810, nrf52811, nrf52832: P0_21 -# nrf52820, nrf52833, nrf52840: P0_18 +## Allow using the RST pin as a regular GPIO pin. +## * nrf52805, nrf52810, nrf52811, nrf52832: P0_21 +## * nrf52820, nrf52833, nrf52840: P0_18 reset-pin-as-gpio = [] -# Implements the MultiwriteNorFlash trait for QSPI. Should only be enabled if your external -# flash supports the semantics described in -# https://docs.rs/embedded-storage/0.3.1/embedded_storage/nor_flash/trait.MultiwriteNorFlash.html +## Implements the MultiwriteNorFlash trait for QSPI. Should only be enabled if your external +## flash supports the semantics described [here](https://docs.rs/embedded-storage/0.3.1/embedded_storage/nor_flash/trait.MultiwriteNorFlash.html) qspi-multiwrite-flash = [] +#! ### Chip selection features +## NRF52805 +nrf52805 = ["nrf52805-pac", "_nrf52"] +## NRF52810 +nrf52810 = ["nrf52810-pac", "_nrf52"] +## NRF52811 +nrf52811 = ["nrf52811-pac", "_nrf52"] +## NRF52820 +nrf52820 = ["nrf52820-pac", "_nrf52"] +## NRF52832 +nrf52832 = ["nrf52832-pac", "_nrf52", "_nrf52832_anomaly_109"] +## NRF52833 +nrf52833 = ["nrf52833-pac", "_nrf52", "_gpio-p1"] +## NRF52840 +nrf52840 = ["nrf52840-pac", "_nrf52", "_gpio-p1"] +## NRF5340-app-s +nrf5340-app-s = ["_nrf5340-app", "_s"] +## NRF5340-app-ns +nrf5340-app-ns = ["_nrf5340-app", "_ns"] +## NRF5340-net +nrf5340-net = ["_nrf5340-net"] +## NRF9160-s +nrf9160-s = ["_nrf9160", "_s"] +## NRF9160-ns +nrf9160-ns = ["_nrf9160", "_ns"] + # Features starting with `_` are for internal use only. They're not intended # to be enabled by other crates, and are not covered by semver guarantees. @@ -114,6 +132,7 @@ fixed = "1.10.0" embedded-storage = "0.3.1" embedded-storage-async = "0.4.0" cfg-if = "1.0.0" +document-features = "0.2.7" nrf52805-pac = { version = "0.12.0", optional = true } nrf52810-pac = { version = "0.12.0", optional = true } diff --git a/embassy-nrf/src/lib.rs b/embassy-nrf/src/lib.rs index e3458e2de..1510b7265 100644 --- a/embassy-nrf/src/lib.rs +++ b/embassy-nrf/src/lib.rs @@ -3,6 +3,9 @@ #![doc = include_str!("../README.md")] #![warn(missing_docs)] +//! ## Feature flags +#![doc = document_features::document_features!(feature_label = r#"{feature}"#)] + #[cfg(not(any( feature = "nrf51", feature = "nrf52805", From 6a1bdb7e3b86b066e9fa8c0a4c08cc5e7212c6b9 Mon Sep 17 00:00:00 2001 From: Barnaby Walters Date: Fri, 22 Dec 2023 23:50:37 +0100 Subject: [PATCH 104/124] [embassy-rp] auto-documented feature flags --- embassy-rp/Cargo.toml | 53 +++++++++++++++++++++++++++---------------- embassy-rp/src/lib.rs | 3 +++ 2 files changed, 37 insertions(+), 19 deletions(-) diff --git a/embassy-rp/Cargo.toml b/embassy-rp/Cargo.toml index 93dad68ce..d185090db 100644 --- a/embassy-rp/Cargo.toml +++ b/embassy-rp/Cargo.toml @@ -14,43 +14,57 @@ flavors = [ [features] default = [ "rt" ] +## Enable the RP runtime. On by default rt = [ "rp-pac/rt" ] +## Enable defmt defmt = ["dep:defmt", "embassy-usb-driver/defmt", "embassy-hal-internal/defmt"] -# critical section that is safe for multicore use +## critical section that is safe for multicore use critical-section-impl = ["critical-section/restore-state-u8"] -# Reexport the PAC for the currently enabled chip at `embassy_rp::pac`. -# This is unstable because semver-minor (non-breaking) releases of embassy-rp may major-bump (breaking) the PAC version. -# If this is an issue for you, you're encouraged to directly depend on a fixed version of the PAC. -# There are no plans to make this stable. +## Reexport the PAC for the currently enabled chip at `embassy_rp::pac`. +## This is unstable because semver-minor (non-breaking) releases of embassy-rp may major-bump (breaking) the PAC version. +## If this is an issue for you, you're encouraged to directly depend on a fixed version of the PAC. +## There are no plans to make this stable. unstable-pac = [] +## Enable the timer for use with `embassy-time` with a 1MHz tick rate time-driver = [] +## Enable ROM function cache rom-func-cache = [] +## Enable intrinsics intrinsics = [] +## Enable ROM v2 intrinsics rom-v2-intrinsics = [] -# boot2 flash chip support. if none of these is enabled we'll default to w25q080 (used on the pico) -boot2-at25sf128a = [] -boot2-gd25q64cs = [] -boot2-generic-03h = [] -boot2-is25lp080 = [] -boot2-ram-memcpy = [] -boot2-w25q080 = [] -boot2-w25x10cl = [] - -# Allow using QSPI pins as GPIO pins. This is mostly not what you want (because your flash lives there) -# and would add both code and memory overhead when enabled needlessly. +## Allow using QSPI pins as GPIO pins. This is mostly not what you want (because your flash lives there) +## and would add both code and memory overhead when enabled needlessly. qspi-as-gpio = [] -# Indicate code is running from RAM. -# Set this if all code is in RAM, and the cores never access memory-mapped flash memory through XIP. -# This allows the flash driver to not force pausing execution on both cores when doing flash operations. +## Indicate code is running from RAM. +## Set this if all code is in RAM, and the cores never access memory-mapped flash memory through XIP. +## This allows the flash driver to not force pausing execution on both cores when doing flash operations. run-from-ram = [] +#! ### boot2 flash chip support +#! If none of these are enabled, w25q080 is used by default (used on the pico) +## AT25SF128a +boot2-at25sf128a = [] +## GD25Q64cs +boot2-gd25q64cs = [] +## generic-03h +boot2-generic-03h = [] +## IS25LP080 +boot2-is25lp080 = [] +## ram-memcpy +boot2-ram-memcpy = [] +## W25Q080 +boot2-w25q080 = [] +## W25X10cl +boot2-w25x10cl = [] + [dependencies] embassy-sync = { version = "0.5.0", path = "../embassy-sync" } embassy-time = { version = "0.2", path = "../embassy-time", features = [ "tick-hz-1_000_000" ] } @@ -85,6 +99,7 @@ embedded-hal-nb = { version = "=1.0.0-rc.3" } pio-proc = {version= "0.2" } pio = {version= "0.2.1" } rp2040-boot2 = "0.3" +document-features = "0.2.7" [dev-dependencies] embassy-executor = { version = "0.4.0", path = "../embassy-executor", features = ["arch-std", "executor-thread"] } diff --git a/embassy-rp/src/lib.rs b/embassy-rp/src/lib.rs index fdacf4965..0a3714777 100644 --- a/embassy-rp/src/lib.rs +++ b/embassy-rp/src/lib.rs @@ -3,6 +3,9 @@ #![doc = include_str!("../README.md")] #![warn(missing_docs)] +//! ## Feature flags +#![doc = document_features::document_features!(feature_label = r#"{feature}"#)] + // This mod MUST go first, so that the others see its macros. pub(crate) mod fmt; From 562680cb139fc39d2fbb728c36ea3ce76731ca50 Mon Sep 17 00:00:00 2001 From: Barnaby Walters Date: Fri, 22 Dec 2023 23:51:10 +0100 Subject: [PATCH 105/124] Removed unnecessary note --- embassy-rp/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/embassy-rp/Cargo.toml b/embassy-rp/Cargo.toml index d185090db..669d79f40 100644 --- a/embassy-rp/Cargo.toml +++ b/embassy-rp/Cargo.toml @@ -14,7 +14,7 @@ flavors = [ [features] default = [ "rt" ] -## Enable the RP runtime. On by default +## Enable the RP runtime. rt = [ "rp-pac/rt" ] ## Enable defmt From 487a6324ef3897a283bff5356bd511c7f570ed12 Mon Sep 17 00:00:00 2001 From: Scott Mabin Date: Sat, 23 Dec 2023 00:14:10 +0000 Subject: [PATCH 106/124] stm32: make time provider public again --- embassy-stm32/src/rtc/mod.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/embassy-stm32/src/rtc/mod.rs b/embassy-stm32/src/rtc/mod.rs index 40cd752a2..65e8713f0 100644 --- a/embassy-stm32/src/rtc/mod.rs +++ b/embassy-stm32/src/rtc/mod.rs @@ -102,7 +102,8 @@ pub enum RtcError { NotRunning, } -pub(crate) struct RtcTimeProvider { +/// Provides immutable access to the current time of the RTC. +pub struct RtcTimeProvider { _private: (), } @@ -243,7 +244,7 @@ impl Rtc { } /// Acquire a [`RtcTimeProvider`] instance. - pub(crate) const fn time_provider(&self) -> RtcTimeProvider { + pub const fn time_provider(&self) -> RtcTimeProvider { RtcTimeProvider { _private: () } } From dcd4e6384e3fab32809d01738ecd84011b4f0cc7 Mon Sep 17 00:00:00 2001 From: eZio Pan Date: Sat, 23 Dec 2023 19:45:56 +0800 Subject: [PATCH 107/124] enable output compare preload for TIM keep output waveform integrity --- examples/stm32f4/src/bin/ws2812_pwm_dma.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/examples/stm32f4/src/bin/ws2812_pwm_dma.rs b/examples/stm32f4/src/bin/ws2812_pwm_dma.rs index c4181d024..cdce36f2e 100644 --- a/examples/stm32f4/src/bin/ws2812_pwm_dma.rs +++ b/examples/stm32f4/src/bin/ws2812_pwm_dma.rs @@ -21,6 +21,7 @@ use embassy_executor::Spawner; use embassy_stm32::gpio::OutputType; use embassy_stm32::pac; +use embassy_stm32::pac::timer::vals::Ocpe; use embassy_stm32::time::khz; use embassy_stm32::timer::simple_pwm::{PwmPin, SimplePwm}; use embassy_stm32::timer::{Channel, CountingMode}; @@ -89,6 +90,12 @@ async fn main(_spawner: Spawner) { let pwm_channel = Channel::Ch1; + // PAC level hacking, enable output compare preload + // keep output waveform integrity + pac::TIM3 + .ccmr_output(pwm_channel.index()) + .modify(|v| v.set_ocpe(0, Ocpe::ENABLED)); + // make sure PWM output keep low on first start ws2812_pwm.set_duty(pwm_channel, 0); From c46b076d5b40ddbe74ddeb7f9296b394c078538f Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Sat, 23 Dec 2023 15:48:47 +0100 Subject: [PATCH 108/124] nrf: some doc fixes. --- embassy-nrf/Cargo.toml | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/embassy-nrf/Cargo.toml b/embassy-nrf/Cargo.toml index 4648d56d9..837a941a9 100644 --- a/embassy-nrf/Cargo.toml +++ b/embassy-nrf/Cargo.toml @@ -53,8 +53,8 @@ time-driver-rtc1 = ["_time-driver"] nfc-pins-as-gpio = [] ## Allow using the RST pin as a regular GPIO pin. -## * nrf52805, nrf52810, nrf52811, nrf52832: P0_21 -## * nrf52820, nrf52833, nrf52840: P0_18 +## * nRF52805, nRF52810, nRF52811, nRF52832: P0_21 +## * nRF52820, nRF52833, nRF52840: P0_18 reset-pin-as-gpio = [] ## Implements the MultiwriteNorFlash trait for QSPI. Should only be enabled if your external @@ -62,29 +62,29 @@ reset-pin-as-gpio = [] qspi-multiwrite-flash = [] #! ### Chip selection features -## NRF52805 +## nRF52805 nrf52805 = ["nrf52805-pac", "_nrf52"] -## NRF52810 +## nRF52810 nrf52810 = ["nrf52810-pac", "_nrf52"] -## NRF52811 +## nRF52811 nrf52811 = ["nrf52811-pac", "_nrf52"] -## NRF52820 +## nRF52820 nrf52820 = ["nrf52820-pac", "_nrf52"] -## NRF52832 +## nRF52832 nrf52832 = ["nrf52832-pac", "_nrf52", "_nrf52832_anomaly_109"] -## NRF52833 +## nRF52833 nrf52833 = ["nrf52833-pac", "_nrf52", "_gpio-p1"] -## NRF52840 +## nRF52840 nrf52840 = ["nrf52840-pac", "_nrf52", "_gpio-p1"] -## NRF5340-app-s +## nRF5340 application core in Secure mode nrf5340-app-s = ["_nrf5340-app", "_s"] -## NRF5340-app-ns +## nRF5340 application core in Non-Secure mode nrf5340-app-ns = ["_nrf5340-app", "_ns"] -## NRF5340-net +## nRF5340 network core nrf5340-net = ["_nrf5340-net"] -## NRF9160-s +## nRF9160 in Secure mode nrf9160-s = ["_nrf9160", "_s"] -## NRF9160-ns +## nRF9160 in Non-Secure mode nrf9160-ns = ["_nrf9160", "_ns"] # Features starting with `_` are for internal use only. They're not intended From 92758c3119739b80373428f0a640e08c1db7e27c Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Sat, 23 Dec 2023 16:01:08 +0100 Subject: [PATCH 109/124] ci: use nightly for building docs. --- .github/ci/doc.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/ci/doc.sh b/.github/ci/doc.sh index ed3036f2f..fbed2752a 100755 --- a/.github/ci/doc.sh +++ b/.github/ci/doc.sh @@ -8,6 +8,7 @@ export CARGO_HOME=/ci/cache/cargo export CARGO_TARGET_DIR=/ci/cache/target export BUILDER_THREADS=4 export BUILDER_COMPRESS=true +mv rust-toolchain-nightly.toml rust-toolchain.toml # force rustup to download the toolchain before starting building. # Otherwise, the docs builder is running multiple instances of cargo rustdoc concurrently. From f625f6b89328a14b0bc31ff35841cff1cf6380d9 Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Sat, 23 Dec 2023 20:41:33 +0100 Subject: [PATCH 110/124] Upgrade to smoltcp v0.11. --- embassy-net/Cargo.toml | 2 +- embassy-net/src/udp.rs | 25 +++++++++++++++++-------- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/embassy-net/Cargo.toml b/embassy-net/Cargo.toml index e6c5ea74f..612a3d689 100644 --- a/embassy-net/Cargo.toml +++ b/embassy-net/Cargo.toml @@ -60,7 +60,7 @@ igmp = ["smoltcp/proto-igmp"] defmt = { version = "0.3", optional = true } log = { version = "0.4.14", optional = true } -smoltcp = { git = "https://github.com/smoltcp-rs/smoltcp.git", rev = "b57e2f9e70e82a13f31d5ea17e55232c11cc2b2d", default-features = false, features = [ +smoltcp = { version = "0.11.0", default-features = false, features = [ "socket", "async", ] } diff --git a/embassy-net/src/udp.rs b/embassy-net/src/udp.rs index 61058c1ba..d9df5b29d 100644 --- a/embassy-net/src/udp.rs +++ b/embassy-net/src/udp.rs @@ -26,13 +26,21 @@ pub enum BindError { /// Error returned by [`UdpSocket::recv_from`] and [`UdpSocket::send_to`]. #[derive(PartialEq, Eq, Clone, Copy, Debug)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub enum Error { +pub enum SendError { /// No route to host. NoRoute, /// Socket not bound to an outgoing port. SocketNotBound, } +/// Error returned by [`UdpSocket::recv_from`] and [`UdpSocket::send_to`]. +#[derive(PartialEq, Eq, Clone, Copy, Debug)] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] +pub enum RecvError { + /// Provided buffer was smaller than the received packet. + Truncated, +} + /// An UDP socket. pub struct UdpSocket<'a> { stack: &'a RefCell, @@ -103,7 +111,7 @@ impl<'a> UdpSocket<'a> { /// This method will wait until a datagram is received. /// /// Returns the number of bytes received and the remote endpoint. - pub async fn recv_from(&self, buf: &mut [u8]) -> Result<(usize, IpEndpoint), Error> { + pub async fn recv_from(&self, buf: &mut [u8]) -> Result<(usize, IpEndpoint), RecvError> { poll_fn(move |cx| self.poll_recv_from(buf, cx)).await } @@ -114,10 +122,11 @@ impl<'a> UdpSocket<'a> { /// /// When a datagram is received, this method will return `Poll::Ready` with the /// number of bytes received and the remote endpoint. - pub fn poll_recv_from(&self, buf: &mut [u8], cx: &mut Context<'_>) -> Poll> { + pub fn poll_recv_from(&self, buf: &mut [u8], cx: &mut Context<'_>) -> Poll> { self.with_mut(|s, _| match s.recv_slice(buf) { Ok((n, meta)) => Poll::Ready(Ok((n, meta.endpoint))), // No data ready + Err(udp::RecvError::Truncated) => Poll::Ready(Err(RecvError::Truncated)), Err(udp::RecvError::Exhausted) => { s.register_recv_waker(cx.waker()); Poll::Pending @@ -129,8 +138,8 @@ impl<'a> UdpSocket<'a> { /// /// This method will wait until the datagram has been sent. /// - /// When the remote endpoint is not reachable, this method will return `Err(Error::NoRoute)` - pub async fn send_to(&self, buf: &[u8], remote_endpoint: T) -> Result<(), Error> + /// When the remote endpoint is not reachable, this method will return `Err(SendError::NoRoute)` + pub async fn send_to(&self, buf: &[u8], remote_endpoint: T) -> Result<(), SendError> where T: Into, { @@ -146,7 +155,7 @@ impl<'a> UdpSocket<'a> { /// and register the current task to be notified when the buffer has space available. /// /// When the remote endpoint is not reachable, this method will return `Poll::Ready(Err(Error::NoRoute))`. - pub fn poll_send_to(&self, buf: &[u8], remote_endpoint: T, cx: &mut Context<'_>) -> Poll> + pub fn poll_send_to(&self, buf: &[u8], remote_endpoint: T, cx: &mut Context<'_>) -> Poll> where T: Into, { @@ -160,9 +169,9 @@ impl<'a> UdpSocket<'a> { Err(udp::SendError::Unaddressable) => { // If no sender/outgoing port is specified, there is not really "no route" if s.endpoint().port == 0 { - Poll::Ready(Err(Error::SocketNotBound)) + Poll::Ready(Err(SendError::SocketNotBound)) } else { - Poll::Ready(Err(Error::NoRoute)) + Poll::Ready(Err(SendError::NoRoute)) } } }) From d90a97aa4c5977e3d071fb4ed94656e6666d965c Mon Sep 17 00:00:00 2001 From: eZio Pan Date: Mon, 25 Dec 2023 21:29:17 +0800 Subject: [PATCH 111/124] update metapac after stm32-data PR323 and refactor a few code with cargo clippy --- embassy-stm32/Cargo.toml | 4 ++-- embassy-stm32/src/can/bxcan.rs | 21 ++++++++++----------- embassy-stm32/src/rtc/v2.rs | 8 ++++---- embassy-stm32/src/rtc/v3.rs | 8 ++++---- embassy-stm32/src/spi/mod.rs | 2 +- examples/stm32f4/src/bin/ws2812_pwm_dma.rs | 3 +-- examples/stm32h7/src/bin/dac_dma.rs | 6 +++--- examples/stm32l4/src/bin/dac_dma.rs | 6 +++--- 8 files changed, 28 insertions(+), 30 deletions(-) diff --git a/embassy-stm32/Cargo.toml b/embassy-stm32/Cargo.toml index 83db7c4bf..16d1cca4c 100644 --- a/embassy-stm32/Cargo.toml +++ b/embassy-stm32/Cargo.toml @@ -57,7 +57,7 @@ futures = { version = "0.3.17", default-features = false, features = ["async-awa rand_core = "0.6.3" sdio-host = "0.5.0" critical-section = "1.1" -stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-2234f380f51d16d0398b8e547088b33ea623cc7c" } +stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-8caf2f0bda28baf4393899dc67ba57f058087f5a" } vcell = "0.1.3" bxcan = "0.7.0" nb = "1.0.0" @@ -75,7 +75,7 @@ critical-section = { version = "1.1", features = ["std"] } [build-dependencies] proc-macro2 = "1.0.36" quote = "1.0.15" -stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-2234f380f51d16d0398b8e547088b33ea623cc7c", default-features = false, features = ["metadata"]} +stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-8caf2f0bda28baf4393899dc67ba57f058087f5a", default-features = false, features = ["metadata"]} [features] diff --git a/embassy-stm32/src/can/bxcan.rs b/embassy-stm32/src/can/bxcan.rs index 3c663b452..cc87b2565 100644 --- a/embassy-stm32/src/can/bxcan.rs +++ b/embassy-stm32/src/can/bxcan.rs @@ -1,3 +1,4 @@ +use core::convert::AsMut; use core::future::poll_fn; use core::marker::PhantomData; use core::ops::{Deref, DerefMut}; @@ -10,7 +11,7 @@ use futures::FutureExt; use crate::gpio::sealed::AFType; use crate::interrupt::typelevel::Interrupt; -use crate::pac::can::vals::{Lec, RirIde}; +use crate::pac::can::vals::{Ide, Lec}; use crate::rcc::RccPeripheral; use crate::time::Hertz; use crate::{interrupt, peripherals, Peripheral}; @@ -148,15 +149,11 @@ impl<'d, T: Instance> Can<'d, T> { T::enable_and_reset(); { - use crate::pac::can::vals::{Errie, Fmpie, Tmeie}; - T::regs().ier().write(|w| { - // TODO: fix metapac - - w.set_errie(Errie::from_bits(1)); - w.set_fmpie(0, Fmpie::from_bits(1)); - w.set_fmpie(1, Fmpie::from_bits(1)); - w.set_tmeie(Tmeie::from_bits(1)); + w.set_errie(true); + w.set_fmpie(0, true); + w.set_fmpie(1, true); + w.set_tmeie(true); }); T::regs().mcr().write(|w| { @@ -276,7 +273,7 @@ impl<'d, T: Instance> Can<'d, T> { } let rir = fifo.rir().read(); - let id = if rir.ide() == RirIde::STANDARD { + let id = if rir.ide() == Ide::STANDARD { Id::from(StandardId::new_unchecked(rir.stid())) } else { let stid = (rir.stid() & 0x7FF) as u32; @@ -403,9 +400,11 @@ impl<'d, T: Instance> Can<'d, T> { let (tx, rx0, rx1) = self.can.split_by_ref(); (CanTx { tx }, CanRx { rx0, rx1 }) } +} +impl<'d, T: Instance> AsMut>> for Can<'d, T> { /// Get mutable access to the lower-level driver from the `bxcan` crate. - pub fn as_mut(&mut self) -> &mut bxcan::Can> { + fn as_mut(&mut self) -> &mut bxcan::Can> { &mut self.can } } diff --git a/embassy-stm32/src/rtc/v2.rs b/embassy-stm32/src/rtc/v2.rs index 91f08fae4..1eda097a7 100644 --- a/embassy-stm32/src/rtc/v2.rs +++ b/embassy-stm32/src/rtc/v2.rs @@ -1,4 +1,4 @@ -use stm32_metapac::rtc::vals::{Init, Osel, Pol}; +use stm32_metapac::rtc::vals::{Osel, Pol}; use super::sealed; use crate::pac::rtc::Rtc; @@ -49,7 +49,7 @@ impl super::Rtc { clock_drift = RTC_CALR_MAX_PPM; } - clock_drift = clock_drift / RTC_CALR_RESOLUTION_PPM; + clock_drift /= RTC_CALR_RESOLUTION_PPM; self.write(false, |rtc| { rtc.calr().write(|w| { @@ -107,7 +107,7 @@ impl super::Rtc { // true if initf bit indicates RTC peripheral is in init mode if init_mode && !r.isr().read().initf() { // to update calendar date/time, time format, and prescaler configuration, RTC must be in init mode - r.isr().modify(|w| w.set_init(Init::INITMODE)); + r.isr().modify(|w| w.set_init(true)); // wait till init state entered // ~2 RTCCLK cycles while !r.isr().read().initf() {} @@ -116,7 +116,7 @@ impl super::Rtc { let result = f(&r); if init_mode { - r.isr().modify(|w| w.set_init(Init::FREERUNNINGMODE)); // Exits init mode + r.isr().modify(|w| w.set_init(false)); // Exits init mode } // Re-enable write protection. diff --git a/embassy-stm32/src/rtc/v3.rs b/embassy-stm32/src/rtc/v3.rs index d2d0d9309..902776b0a 100644 --- a/embassy-stm32/src/rtc/v3.rs +++ b/embassy-stm32/src/rtc/v3.rs @@ -1,4 +1,4 @@ -use stm32_metapac::rtc::vals::{Calp, Calw16, Calw8, Fmt, Init, Key, Osel, Pol, TampalrmPu, TampalrmType}; +use stm32_metapac::rtc::vals::{Calp, Calw16, Calw8, Fmt, Key, Osel, Pol, TampalrmType}; use super::{sealed, RtcCalibrationCyclePeriod}; use crate::pac::rtc::Rtc; @@ -26,7 +26,7 @@ impl super::Rtc { rtc.cr().modify(|w| { w.set_out2en(false); w.set_tampalrm_type(TampalrmType::PUSHPULL); - w.set_tampalrm_pu(TampalrmPu::NOPULLUP); + w.set_tampalrm_pu(false); }); }); } @@ -106,7 +106,7 @@ impl super::Rtc { r.wpr().write(|w| w.set_key(Key::DEACTIVATE2)); if init_mode && !r.icsr().read().initf() { - r.icsr().modify(|w| w.set_init(Init::INITMODE)); + r.icsr().modify(|w| w.set_init(true)); // wait till init state entered // ~2 RTCCLK cycles while !r.icsr().read().initf() {} @@ -115,7 +115,7 @@ impl super::Rtc { let result = f(&r); if init_mode { - r.icsr().modify(|w| w.set_init(Init::FREERUNNINGMODE)); // Exits init mode + r.icsr().modify(|w| w.set_init(false)); // Exits init mode } // Re-enable write protection. diff --git a/embassy-stm32/src/spi/mod.rs b/embassy-stm32/src/spi/mod.rs index 674a5d316..23f027e70 100644 --- a/embassy-stm32/src/spi/mod.rs +++ b/embassy-stm32/src/spi/mod.rs @@ -311,7 +311,7 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> { w.set_ssom(vals::Ssom::ASSERTED); w.set_midi(0); w.set_mssi(0); - w.set_afcntr(vals::Afcntr::CONTROLLED); + w.set_afcntr(true); w.set_ssiop(vals::Ssiop::ACTIVEHIGH); }); T::REGS.cfg1().modify(|w| { diff --git a/examples/stm32f4/src/bin/ws2812_pwm_dma.rs b/examples/stm32f4/src/bin/ws2812_pwm_dma.rs index cdce36f2e..4458b643f 100644 --- a/examples/stm32f4/src/bin/ws2812_pwm_dma.rs +++ b/examples/stm32f4/src/bin/ws2812_pwm_dma.rs @@ -21,7 +21,6 @@ use embassy_executor::Spawner; use embassy_stm32::gpio::OutputType; use embassy_stm32::pac; -use embassy_stm32::pac::timer::vals::Ocpe; use embassy_stm32::time::khz; use embassy_stm32::timer::simple_pwm::{PwmPin, SimplePwm}; use embassy_stm32::timer::{Channel, CountingMode}; @@ -94,7 +93,7 @@ async fn main(_spawner: Spawner) { // keep output waveform integrity pac::TIM3 .ccmr_output(pwm_channel.index()) - .modify(|v| v.set_ocpe(0, Ocpe::ENABLED)); + .modify(|v| v.set_ocpe(0, true)); // make sure PWM output keep low on first start ws2812_pwm.set_duty(pwm_channel, 0); diff --git a/examples/stm32h7/src/bin/dac_dma.rs b/examples/stm32h7/src/bin/dac_dma.rs index 1481dd967..8e5c41a43 100644 --- a/examples/stm32h7/src/bin/dac_dma.rs +++ b/examples/stm32h7/src/bin/dac_dma.rs @@ -4,7 +4,7 @@ use defmt::*; use embassy_executor::Spawner; use embassy_stm32::dac::{DacCh1, DacCh2, ValueArray}; -use embassy_stm32::pac::timer::vals::{Mms, Opm}; +use embassy_stm32::pac::timer::vals::Mms; use embassy_stm32::peripherals::{DAC1, DMA1_CH3, DMA1_CH4, TIM6, TIM7}; use embassy_stm32::rcc::low_level::RccPeripheral; use embassy_stm32::time::Hertz; @@ -78,7 +78,7 @@ async fn dac_task1(mut dac: DacCh1<'static, DAC1, DMA1_CH3>) { TIM6::regs().arr().modify(|w| w.set_arr(reload as u16 - 1)); TIM6::regs().cr2().modify(|w| w.set_mms(Mms::UPDATE)); TIM6::regs().cr1().modify(|w| { - w.set_opm(Opm::DISABLED); + w.set_opm(false); w.set_cen(true); }); @@ -115,7 +115,7 @@ async fn dac_task2(mut dac: DacCh2<'static, DAC1, DMA1_CH4>) { TIM7::regs().arr().modify(|w| w.set_arr(reload as u16 - 1)); TIM7::regs().cr2().modify(|w| w.set_mms(Mms::UPDATE)); TIM7::regs().cr1().modify(|w| { - w.set_opm(Opm::DISABLED); + w.set_opm(false); w.set_cen(true); }); diff --git a/examples/stm32l4/src/bin/dac_dma.rs b/examples/stm32l4/src/bin/dac_dma.rs index 64c541caa..8e5098557 100644 --- a/examples/stm32l4/src/bin/dac_dma.rs +++ b/examples/stm32l4/src/bin/dac_dma.rs @@ -4,7 +4,7 @@ use defmt::*; use embassy_executor::Spawner; use embassy_stm32::dac::{DacCh1, DacCh2, ValueArray}; -use embassy_stm32::pac::timer::vals::{Mms, Opm}; +use embassy_stm32::pac::timer::vals::Mms; use embassy_stm32::peripherals::{DAC1, DMA1_CH3, DMA1_CH4, TIM6, TIM7}; use embassy_stm32::rcc::low_level::RccPeripheral; use embassy_stm32::time::Hertz; @@ -49,7 +49,7 @@ async fn dac_task1(mut dac: DacCh1<'static, DAC1, DMA1_CH3>) { TIM6::regs().arr().modify(|w| w.set_arr(reload as u16 - 1)); TIM6::regs().cr2().modify(|w| w.set_mms(Mms::UPDATE)); TIM6::regs().cr1().modify(|w| { - w.set_opm(Opm::DISABLED); + w.set_opm(false); w.set_cen(true); }); @@ -86,7 +86,7 @@ async fn dac_task2(mut dac: DacCh2<'static, DAC1, DMA1_CH4>) { TIM7::regs().arr().modify(|w| w.set_arr(reload as u16 - 1)); TIM7::regs().cr2().modify(|w| w.set_mms(Mms::UPDATE)); TIM7::regs().cr1().modify(|w| { - w.set_opm(Opm::DISABLED); + w.set_opm(false); w.set_cen(true); }); From 30023c3bcccaffe4ff16d6600ba5ff80cf1ee488 Mon Sep 17 00:00:00 2001 From: Christian Enderle Date: Tue, 26 Dec 2023 11:58:38 +0100 Subject: [PATCH 112/124] Add low-power support for stm32l5 --- embassy-stm32/src/rtc/mod.rs | 20 +++++++++++++------- embassy-stm32/src/rtc/v3.rs | 6 ++++++ 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/embassy-stm32/src/rtc/mod.rs b/embassy-stm32/src/rtc/mod.rs index 65e8713f0..1ffb567b3 100644 --- a/embassy-stm32/src/rtc/mod.rs +++ b/embassy-stm32/src/rtc/mod.rs @@ -24,7 +24,7 @@ use crate::time::Hertz; ), path = "v2.rs" )] -#[cfg_attr(any(rtc_v3, rtc_v3u5), path = "v3.rs")] +#[cfg_attr(any(rtc_v3, rtc_v3u5, rtc_v3l5), path = "v3.rs")] mod _version; #[allow(unused_imports)] pub use _version::*; @@ -43,7 +43,7 @@ pub(crate) enum WakeupPrescaler { Div16 = 16, } -#[cfg(any(stm32wb, stm32f4, stm32l0, stm32g4))] +#[cfg(any(stm32wb, stm32f4, stm32l0, stm32g4, stm32l5))] impl From for crate::pac::rtc::vals::Wucksel { fn from(val: WakeupPrescaler) -> Self { use crate::pac::rtc::vals::Wucksel; @@ -57,7 +57,7 @@ impl From for crate::pac::rtc::vals::Wucksel { } } -#[cfg(any(stm32wb, stm32f4, stm32l0, stm32g4))] +#[cfg(any(stm32wb, stm32f4, stm32l0, stm32g4, stm32l5))] impl From for WakeupPrescaler { fn from(val: crate::pac::rtc::vals::Wucksel) -> Self { use crate::pac::rtc::vals::Wucksel; @@ -348,7 +348,7 @@ impl Rtc { ) { use embassy_time::{Duration, TICK_HZ}; - #[cfg(any(rtc_v3, rtc_v3u5))] + #[cfg(any(rtc_v3, rtc_v3u5, rtc_v3l5))] use crate::pac::rtc::vals::Calrf; // Panic if the rcc mod knows we're not using low-power rtc @@ -375,7 +375,7 @@ impl Rtc { while !regs.isr().read().wutwf() {} } - #[cfg(any(rtc_v3, rtc_v3u5))] + #[cfg(any(rtc_v3, rtc_v3u5, rtc_v3l5))] { regs.scr().write(|w| w.set_cwutf(Calrf::CLEAR)); while !regs.icsr().read().wutwf() {} @@ -404,7 +404,7 @@ impl Rtc { /// was called, otherwise none pub(crate) fn stop_wakeup_alarm(&self, cs: critical_section::CriticalSection) -> Option { use crate::interrupt::typelevel::Interrupt; - #[cfg(any(rtc_v3, rtc_v3u5))] + #[cfg(any(rtc_v3, rtc_v3u5, rtc_v3l5))] use crate::pac::rtc::vals::Calrf; let instant = self.instant().unwrap(); @@ -420,13 +420,19 @@ impl Rtc { ))] regs.isr().modify(|w| w.set_wutf(false)); - #[cfg(any(rtc_v3, rtc_v3u5))] + #[cfg(any(rtc_v3, rtc_v3u5, rtc_v3l5))] regs.scr().write(|w| w.set_cwutf(Calrf::CLEAR)); + #[cfg(not(stm32l5))] crate::pac::EXTI .pr(0) .modify(|w| w.set_line(RTC::EXTI_WAKEUP_LINE, true)); + #[cfg(stm32l5)] + crate::pac::EXTI + .fpr(0) + .modify(|w| w.set_line(RTC::EXTI_WAKEUP_LINE, true)); + ::WakeupInterrupt::unpend(); }); } diff --git a/embassy-stm32/src/rtc/v3.rs b/embassy-stm32/src/rtc/v3.rs index 902776b0a..114141b64 100644 --- a/embassy-stm32/src/rtc/v3.rs +++ b/embassy-stm32/src/rtc/v3.rs @@ -135,6 +135,12 @@ impl sealed::Instance for crate::peripherals::RTC { #[cfg(all(feature = "low-power", stm32g4))] type WakeupInterrupt = crate::interrupt::typelevel::RTC_WKUP; + #[cfg(all(feature = "low-power", stm32l5))] + const EXTI_WAKEUP_LINE: usize = 17; + + #[cfg(all(feature = "low-power", stm32l5))] + type WakeupInterrupt = crate::interrupt::typelevel::RTC; + fn read_backup_register(_rtc: &Rtc, register: usize) -> Option { #[allow(clippy::if_same_then_else)] if register < Self::BACKUP_REGISTER_COUNT { From 7fa954c0273623a9ab5181800fe1bb1273bb7982 Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Tue, 26 Dec 2023 17:35:49 +0100 Subject: [PATCH 113/124] nrf/gpio: add toggle. --- embassy-nrf/src/gpio.rs | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/embassy-nrf/src/gpio.rs b/embassy-nrf/src/gpio.rs index a47fb8350..27c18383f 100644 --- a/embassy-nrf/src/gpio.rs +++ b/embassy-nrf/src/gpio.rs @@ -152,6 +152,12 @@ impl<'d, T: Pin> Output<'d, T> { self.pin.set_low() } + /// Toggle the output level. + #[inline] + pub fn toggle(&mut self) { + self.pin.toggle() + } + /// Set the output level. #[inline] pub fn set_level(&mut self, level: Level) { @@ -310,6 +316,16 @@ impl<'d, T: Pin> Flex<'d, T> { self.pin.set_low() } + /// Toggle the output level. + #[inline] + pub fn toggle(&mut self) { + if self.is_set_low() { + self.set_high() + } else { + self.set_low() + } + } + /// Set the output level. #[inline] pub fn set_level(&mut self, level: Level) { @@ -538,6 +554,15 @@ mod eh02 { } } + impl<'d, T: Pin> embedded_hal_02::digital::v2::ToggleableOutputPin for Output<'d, T> { + type Error = Infallible; + #[inline] + fn toggle(&mut self) -> Result<(), Self::Error> { + self.toggle(); + Ok(()) + } + } + /// Implement [`embedded_hal_02::digital::v2::InputPin`] for [`Flex`]; /// /// If the pin is not in input mode the result is unspecified. @@ -574,6 +599,15 @@ mod eh02 { Ok(self.ref_is_set_low()) } } + + impl<'d, T: Pin> embedded_hal_02::digital::v2::ToggleableOutputPin for Flex<'d, T> { + type Error = Infallible; + #[inline] + fn toggle(&mut self) -> Result<(), Self::Error> { + self.toggle(); + Ok(()) + } + } } impl<'d, T: Pin> embedded_hal_1::digital::ErrorType for Input<'d, T> { From 211f3357b7dcc3a3ff1c956f053917c3c69c5ec3 Mon Sep 17 00:00:00 2001 From: Ben Schattinger Date: Tue, 26 Dec 2023 18:22:54 -0500 Subject: [PATCH 114/124] stm32: USB IN endpoints use IN wakers fixes #2360 --- embassy-stm32/src/usb/usb.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/embassy-stm32/src/usb/usb.rs b/embassy-stm32/src/usb/usb.rs index a8aebfe1f..39538beb7 100644 --- a/embassy-stm32/src/usb/usb.rs +++ b/embassy-stm32/src/usb/usb.rs @@ -704,7 +704,7 @@ impl<'d, T: Instance> driver::Endpoint for Endpoint<'d, T, In> { trace!("wait_enabled OUT WAITING"); let index = self.info.addr.index(); poll_fn(|cx| { - EP_OUT_WAKERS[index].register(cx.waker()); + EP_IN_WAKERS[index].register(cx.waker()); let regs = T::regs(); if regs.epr(index).read().stat_tx() == Stat::DISABLED { Poll::Pending From 87b23f9037aedb4720ded089d481de1696d91e26 Mon Sep 17 00:00:00 2001 From: Ben Schattinger Date: Tue, 26 Dec 2023 18:26:01 -0500 Subject: [PATCH 115/124] stm32: fix USB wait_enabled IN messages --- embassy-stm32/src/usb/usb.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/embassy-stm32/src/usb/usb.rs b/embassy-stm32/src/usb/usb.rs index 39538beb7..04b1b35e8 100644 --- a/embassy-stm32/src/usb/usb.rs +++ b/embassy-stm32/src/usb/usb.rs @@ -701,7 +701,7 @@ impl<'d, T: Instance> driver::Endpoint for Endpoint<'d, T, In> { } async fn wait_enabled(&mut self) { - trace!("wait_enabled OUT WAITING"); + trace!("wait_enabled IN WAITING"); let index = self.info.addr.index(); poll_fn(|cx| { EP_IN_WAKERS[index].register(cx.waker()); @@ -713,7 +713,7 @@ impl<'d, T: Instance> driver::Endpoint for Endpoint<'d, T, In> { } }) .await; - trace!("wait_enabled OUT OK"); + trace!("wait_enabled IN OK"); } } From a142be8bb8f90ea9935d452bbac692e678f0c9e7 Mon Sep 17 00:00:00 2001 From: James Munns Date: Wed, 27 Dec 2023 19:12:44 +0100 Subject: [PATCH 116/124] Seems to help --- embassy-stm32/src/i2c/v1.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/embassy-stm32/src/i2c/v1.rs b/embassy-stm32/src/i2c/v1.rs index df5b44c2d..231d08f18 100644 --- a/embassy-stm32/src/i2c/v1.rs +++ b/embassy-stm32/src/i2c/v1.rs @@ -375,6 +375,9 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> { T::regs().sr2().read(); Poll::Ready(Ok(())) } else { + // If we need to go around, then re-enable the interrupts, otherwise nothing + // can wake us up and we'll hang. + Self::enable_interrupts(); Poll::Pending } } From da31aa44c0b9f1a9358e4ebf7e3a0b2a63828e8b Mon Sep 17 00:00:00 2001 From: Christian Enderle Date: Thu, 28 Dec 2023 10:52:23 +0100 Subject: [PATCH 117/124] dbgmcu: set bits to false when disabled --- embassy-stm32/src/lib.rs | 50 +++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 26 deletions(-) diff --git a/embassy-stm32/src/lib.rs b/embassy-stm32/src/lib.rs index 207f7ed8f..f10e9d50d 100644 --- a/embassy-stm32/src/lib.rs +++ b/embassy-stm32/src/lib.rs @@ -208,32 +208,30 @@ pub fn init(config: Config) -> Peripherals { let p = Peripherals::take_with_cs(cs); #[cfg(dbgmcu)] - if config.enable_debug_during_sleep { - crate::pac::DBGMCU.cr().modify(|cr| { - #[cfg(any(dbgmcu_f0, dbgmcu_c0, dbgmcu_g0, dbgmcu_u5, dbgmcu_wba))] - { - cr.set_dbg_stop(true); - cr.set_dbg_standby(true); - } - #[cfg(any( - dbgmcu_f1, dbgmcu_f2, dbgmcu_f3, dbgmcu_f4, dbgmcu_f7, dbgmcu_g4, dbgmcu_f7, dbgmcu_l0, dbgmcu_l1, - dbgmcu_l4, dbgmcu_wb, dbgmcu_wl - ))] - { - cr.set_dbg_sleep(true); - cr.set_dbg_stop(true); - cr.set_dbg_standby(true); - } - #[cfg(dbgmcu_h7)] - { - cr.set_d1dbgcken(true); - cr.set_d3dbgcken(true); - cr.set_dbgsleep_d1(true); - cr.set_dbgstby_d1(true); - cr.set_dbgstop_d1(true); - } - }); - } + crate::pac::DBGMCU.cr().modify(|cr| { + #[cfg(any(dbgmcu_f0, dbgmcu_c0, dbgmcu_g0, dbgmcu_u5, dbgmcu_wba))] + { + cr.set_dbg_stop(config.enable_debug_during_sleep); + cr.set_dbg_standby(config.enable_debug_during_sleep); + } + #[cfg(any( + dbgmcu_f1, dbgmcu_f2, dbgmcu_f3, dbgmcu_f4, dbgmcu_f7, dbgmcu_g4, dbgmcu_f7, dbgmcu_l0, dbgmcu_l1, + dbgmcu_l4, dbgmcu_wb, dbgmcu_wl + ))] + { + cr.set_dbg_sleep(config.enable_debug_during_sleep); + cr.set_dbg_stop(config.enable_debug_during_sleep); + cr.set_dbg_standby(config.enable_debug_during_sleep); + } + #[cfg(dbgmcu_h7)] + { + cr.set_d1dbgcken(config.enable_debug_during_sleep); + cr.set_d3dbgcken(config.enable_debug_during_sleep); + cr.set_dbgsleep_d1(config.enable_debug_during_sleep); + cr.set_dbgstby_d1(config.enable_debug_during_sleep); + cr.set_dbgstop_d1(config.enable_debug_during_sleep); + } + }); #[cfg(not(any(stm32f1, stm32wb, stm32wl)))] peripherals::SYSCFG::enable_and_reset_with_cs(cs); From 8d36fe388240b02ae5ef2f49b310e215fc9dffc3 Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Thu, 28 Dec 2023 18:14:55 +0100 Subject: [PATCH 118/124] ci: use stable 1.75. --- rust-toolchain.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust-toolchain.toml b/rust-toolchain.toml index e1af0b647..a6fe52ee2 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,5 +1,5 @@ [toolchain] -channel = "beta-2023-12-17" +channel = "1.75" components = [ "rust-src", "rustfmt", "llvm-tools" ] targets = [ "thumbv7em-none-eabi", From d32fe0ccdcfe7507accf28caaf2ce03b4b5713f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Damien?= Date: Thu, 28 Dec 2023 22:15:16 +0100 Subject: [PATCH 119/124] Add set_hop_limit to UDP sockets --- embassy-net/src/udp.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/embassy-net/src/udp.rs b/embassy-net/src/udp.rs index d9df5b29d..a22cd8827 100644 --- a/embassy-net/src/udp.rs +++ b/embassy-net/src/udp.rs @@ -222,6 +222,11 @@ impl<'a> UdpSocket<'a> { pub fn payload_send_capacity(&self) -> usize { self.with(|s, _| s.payload_send_capacity()) } + + /// Set the hop limit field in the IP header of sent packets. + pub fn set_hop_limit(&mut self, hop_limit: Option) { + self.with_mut(|s, _| s.set_hop_limit(hop_limit)) + } } impl Drop for UdpSocket<'_> { From 989901c09268cecc5aca558eaecd6ca3fc8bbb76 Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Thu, 28 Dec 2023 23:55:19 +0100 Subject: [PATCH 120/124] ci: disable rpi-pico/i2c test --- ci.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ci.sh b/ci.sh index 933e54a80..75640e384 100755 --- a/ci.sh +++ b/ci.sh @@ -207,6 +207,9 @@ cargo batch \ $BUILD_EXTRA +# failed, a wire must've come loose, will check asap. +rm out/tests/rpi-pico/i2c + rm out/tests/stm32wb55rg/wpan_mac rm out/tests/stm32wb55rg/wpan_ble From a780339103239890e52fea26172071ec222ee81b Mon Sep 17 00:00:00 2001 From: James Munns Date: Thu, 28 Dec 2023 23:57:10 +0100 Subject: [PATCH 121/124] stm32: Add breadcrumb to i2cv1 investigation Adds an in-code breadcrumb for https://github.com/embassy-rs/embassy/issues/2372 --- embassy-stm32/src/i2c/v1.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/embassy-stm32/src/i2c/v1.rs b/embassy-stm32/src/i2c/v1.rs index df5b44c2d..134593276 100644 --- a/embassy-stm32/src/i2c/v1.rs +++ b/embassy-stm32/src/i2c/v1.rs @@ -1,3 +1,9 @@ +//! # I2Cv1 +//! +//! This implementation is used for STM32F1, STM32F2, STM32F4, and STM32L1 devices. +//! +//! All other devices (as of 2023-12-28) use [`v2`](super::v2) instead. + use core::future::poll_fn; use core::task::Poll; @@ -10,6 +16,17 @@ use crate::dma::Transfer; use crate::pac::i2c; use crate::time::Hertz; +// /!\ /!\ +// /!\ Implementation note! /!\ +// /!\ /!\ +// +// It's somewhat unclear whether using interrupts here in a *strictly* one-shot style is actually +// what we want! If you are looking in this file because you are doing async I2C and your code is +// just totally hanging (sometimes), maybe swing by this issue: +// . +// +// There's some more details there, and we might have a fix for you. But please let us know if you +// hit a case like this! pub unsafe fn on_interrupt() { let regs = T::regs(); // i2c v2 only woke the task on transfer complete interrupts. v1 uses interrupts for a bunch of From 3916b26b258ae8216fedf0394257e39f23c53c19 Mon Sep 17 00:00:00 2001 From: ftilde Date: Fri, 29 Dec 2023 12:27:52 +0100 Subject: [PATCH 122/124] Reset rx_started state of nrf buffered_uarte on init This was likely forgotten as part of c46418f12. Without this, when creating a uarte instance, dropping it and then creating another instance, this instance would never receive any bytes. --- embassy-nrf/src/buffered_uarte.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/embassy-nrf/src/buffered_uarte.rs b/embassy-nrf/src/buffered_uarte.rs index 4ac622d34..2c620798d 100644 --- a/embassy-nrf/src/buffered_uarte.rs +++ b/embassy-nrf/src/buffered_uarte.rs @@ -342,6 +342,7 @@ impl<'d, U: UarteInstance, T: TimerInstance> BufferedUarte<'d, U, T> { s.tx_count.store(0, Ordering::Relaxed); s.rx_started_count.store(0, Ordering::Relaxed); s.rx_ended_count.store(0, Ordering::Relaxed); + s.rx_started.store(false, Ordering::Relaxed); let len = tx_buffer.len(); unsafe { s.tx_buf.init(tx_buffer.as_mut_ptr(), len) }; let len = rx_buffer.len(); From 93b64b90ce426e6d1aa91d473265ec5dfde97b71 Mon Sep 17 00:00:00 2001 From: Scott Mabin Date: Sun, 31 Dec 2023 14:14:32 +0000 Subject: [PATCH 123/124] Extend the task macro to allow cfging arguments away --- embassy-executor-macros/src/macros/task.rs | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/embassy-executor-macros/src/macros/task.rs b/embassy-executor-macros/src/macros/task.rs index 5161e1020..1efb2788b 100644 --- a/embassy-executor-macros/src/macros/task.rs +++ b/embassy-executor-macros/src/macros/task.rs @@ -49,7 +49,7 @@ pub fn run(args: &[NestedMeta], f: syn::ItemFn) -> Result Result match t.pat.as_mut() { syn::Pat::Ident(id) => { - arg_names.push(id.ident.clone()); id.mutability = None; + args.push((id.clone(), t.attrs.clone())); } _ => { ctxt.error_spanned_by(arg, "pattern matching in task arguments is not yet supported"); @@ -79,13 +79,24 @@ pub fn run(args: &[NestedMeta], f: syn::ItemFn) -> Result ::embassy_executor::SpawnToken { type Fut = impl ::core::future::Future + 'static; const POOL_SIZE: usize = #pool_size; static POOL: ::embassy_executor::raw::TaskPool = ::embassy_executor::raw::TaskPool::new(); - unsafe { POOL._spawn_async_fn(move || #task_inner_ident(#(#arg_names,)*)) } + unsafe { POOL._spawn_async_fn(move || #task_inner_ident(#(#full_args,)*)) } } }; #[cfg(not(feature = "nightly"))] @@ -93,7 +104,7 @@ pub fn run(args: &[NestedMeta], f: syn::ItemFn) -> Result ::embassy_executor::SpawnToken { const POOL_SIZE: usize = #pool_size; static POOL: ::embassy_executor::_export::TaskPoolRef = ::embassy_executor::_export::TaskPoolRef::new(); - unsafe { POOL.get::<_, POOL_SIZE>()._spawn_async_fn(move || #task_inner_ident(#(#arg_names,)*)) } + unsafe { POOL.get::<_, POOL_SIZE>()._spawn_async_fn(move || #task_inner_ident(#(#full_args,)*)) } } }; From 2efde24f333cdf1730f14c050460eb7e0c44f5b9 Mon Sep 17 00:00:00 2001 From: Scott Mabin Date: Sun, 31 Dec 2023 16:55:46 +0000 Subject: [PATCH 124/124] Add test case --- embassy-executor/tests/test.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/embassy-executor/tests/test.rs b/embassy-executor/tests/test.rs index 0dbd391e8..2c2441dd5 100644 --- a/embassy-executor/tests/test.rs +++ b/embassy-executor/tests/test.rs @@ -135,3 +135,17 @@ fn executor_task_self_wake_twice() { ] ) } + +#[test] +fn executor_task_cfg_args() { + // simulate cfg'ing away argument c + #[task] + async fn task1(a: u32, b: u32, #[cfg(any())] c: u32) { + let (_, _) = (a, b); + } + + #[task] + async fn task2(a: u32, b: u32, #[cfg(all())] c: u32) { + let (_, _, _) = (a, b, c); + } +}