From 13b1ca1eb65ddf969526fd71841145ad9a0502f8 Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Wed, 17 Aug 2022 13:44:24 +0200 Subject: [PATCH 1/5] Update nightly. --- rust-toolchain.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust-toolchain.toml b/rust-toolchain.toml index c6d0f485f..f5e342edc 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,7 +1,7 @@ # Before upgrading check that everything is available on all tier1 targets here: # https://rust-lang.github.io/rustup-components-history [toolchain] -channel = "nightly-2022-07-13" +channel = "nightly-2022-08-16" components = [ "rust-src", "rustfmt" ] targets = [ "thumbv7em-none-eabi", From 72cd015c1ad107003e56ffcec3441b43066e4bda Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Wed, 17 Aug 2022 14:44:18 +0200 Subject: [PATCH 2/5] stm32/sdmmc: remove cast no longer allowed on latest nightly due to nonexhaustive enum. --- embassy-stm32/src/sdmmc/mod.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/embassy-stm32/src/sdmmc/mod.rs b/embassy-stm32/src/sdmmc/mod.rs index 1de4b2aa6..3ad31ec87 100644 --- a/embassy-stm32/src/sdmmc/mod.rs +++ b/embassy-stm32/src/sdmmc/mod.rs @@ -999,10 +999,17 @@ impl SdmmcInner { fn clkcr_set_clkdiv(&self, freq: u32, width: BusWidth, ker_ck: Hertz, clock: &mut Hertz) -> Result<(), Error> { let regs = self.0; + let width_u32 = match width { + BusWidth::One => 1u32, + BusWidth::Four => 4u32, + BusWidth::Eight => 8u32, + _ => panic!("Invalid Bus Width"), + }; + let (clkdiv, new_clock) = clk_div(ker_ck, freq)?; // Enforce AHB and SDMMC_CK clock relation. See RM0433 Rev 7 // Section 55.5.8 - let sdmmc_bus_bandwidth = new_clock.0 * (width as u32); + let sdmmc_bus_bandwidth = new_clock.0 * width_u32; assert!(ker_ck.0 > 3 * sdmmc_bus_bandwidth / 32); *clock = new_clock; From 2649f13dc7c0bff87752f4fbf0d3cab7b1468e12 Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Wed, 17 Aug 2022 15:01:07 +0200 Subject: [PATCH 3/5] stm32/rcc: fix unnecessary parentheses --- embassy-stm32/src/rcc/u5.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/embassy-stm32/src/rcc/u5.rs b/embassy-stm32/src/rcc/u5.rs index 1f7e39070..960c45322 100644 --- a/embassy-stm32/src/rcc/u5.rs +++ b/embassy-stm32/src/rcc/u5.rs @@ -63,7 +63,7 @@ seq_macro::seq!(N in 2..=128 { match self { PllClkDiv::NotDivided => 1, #( - PllClkDiv::Div~N => (N + 1), + PllClkDiv::Div~N => N + 1, )* } } @@ -81,7 +81,7 @@ seq_macro::seq!(N in 4..=512 { pub enum PllN { NotMultiplied, #( - Mul~N = (N-1), + Mul~N = N-1, )* } @@ -90,7 +90,7 @@ seq_macro::seq!(N in 4..=512 { match self { PllN::NotMultiplied => 1, #( - PllN::Mul~N => (N + 1), + PllN::Mul~N => N + 1, )* } } From ef9e373ec444c781a81a528b4215582b018b43d5 Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Wed, 17 Aug 2022 14:49:42 +0200 Subject: [PATCH 4/5] macros/interrupt_take: do not assume embassy-executor is a dependency of the user crate. --- embassy-cortex-m/src/interrupt.rs | 6 ++++++ embassy-macros/src/macros/cortex_m_interrupt_take.rs | 8 ++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/embassy-cortex-m/src/interrupt.rs b/embassy-cortex-m/src/interrupt.rs index 7358caa46..be11c5eba 100644 --- a/embassy-cortex-m/src/interrupt.rs +++ b/embassy-cortex-m/src/interrupt.rs @@ -6,6 +6,12 @@ use cortex_m::peripheral::NVIC; use embassy_hal_common::Peripheral; pub use embassy_macros::cortex_m_interrupt_take as take; +/// Do not use. Used for macros only. Not covered by semver guarantees. +#[doc(hidden)] +pub mod _export { + pub use atomic_polyfill as atomic; +} + /// Implementation detail, do not use outside embassy crates. #[doc(hidden)] pub struct Handler { diff --git a/embassy-macros/src/macros/cortex_m_interrupt_take.rs b/embassy-macros/src/macros/cortex_m_interrupt_take.rs index 133eb5c26..9e40a56f1 100644 --- a/embassy-macros/src/macros/cortex_m_interrupt_take.rs +++ b/embassy-macros/src/macros/cortex_m_interrupt_take.rs @@ -16,15 +16,15 @@ pub fn run(name: syn::Ident) -> Result { static HANDLER: interrupt::Handler; } - let func = HANDLER.func.load(::embassy_executor::export::atomic::Ordering::Relaxed); - let ctx = HANDLER.ctx.load(::embassy_executor::export::atomic::Ordering::Relaxed); + let func = HANDLER.func.load(interrupt::_export::atomic::Ordering::Relaxed); + let ctx = HANDLER.ctx.load(interrupt::_export::atomic::Ordering::Relaxed); let func: fn(*mut ()) = ::core::mem::transmute(func); func(ctx) } - static TAKEN: ::embassy_executor::export::atomic::AtomicBool = ::embassy_executor::export::atomic::AtomicBool::new(false); + static TAKEN: interrupt::_export::atomic::AtomicBool = interrupt::_export::atomic::AtomicBool::new(false); - if TAKEN.compare_exchange(false, true, ::embassy_executor::export::atomic::Ordering::AcqRel, ::embassy_executor::export::atomic::Ordering::Acquire).is_err() { + if TAKEN.compare_exchange(false, true, interrupt::_export::atomic::Ordering::AcqRel, interrupt::_export::atomic::Ordering::Acquire).is_err() { core::panic!("IRQ Already taken"); } From bd0aaec6242c86d126fdb3784ae603cbf329957b Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Wed, 17 Aug 2022 15:03:12 +0200 Subject: [PATCH 5/5] macros: remove embassy_prefix attr. This was used in the past for reexporting the macros from drogue-device, which is no longer using it. Also, it is a pain to support, so we don't want it. --- embassy-macros/src/macros/main.rs | 57 +++++++++++++------------------ embassy-macros/src/macros/task.rs | 10 ++---- embassy-macros/src/util/mod.rs | 1 - embassy-macros/src/util/path.rs | 41 ---------------------- 4 files changed, 26 insertions(+), 83 deletions(-) delete mode 100644 embassy-macros/src/util/path.rs diff --git a/embassy-macros/src/macros/main.rs b/embassy-macros/src/macros/main.rs index a8c8bb0d7..b040edc5a 100644 --- a/embassy-macros/src/macros/main.rs +++ b/embassy-macros/src/macros/main.rs @@ -3,28 +3,16 @@ use proc_macro2::TokenStream; use quote::quote; use crate::util::ctxt::Ctxt; -use crate::util::path::ModulePrefix; - -#[cfg(feature = "stm32")] -const HAL: Option<&str> = Some("embassy_stm32"); -#[cfg(feature = "nrf")] -const HAL: Option<&str> = Some("embassy_nrf"); -#[cfg(feature = "rp")] -const HAL: Option<&str> = Some("embassy_rp"); -#[cfg(not(any(feature = "stm32", feature = "nrf", feature = "rp")))] -const HAL: Option<&str> = None; #[derive(Debug, FromMeta)] struct Args { - #[darling(default)] - embassy_prefix: ModulePrefix, - #[allow(unused)] #[darling(default)] config: Option, } pub fn run(args: syn::AttributeArgs, f: syn::ItemFn) -> Result { + #[allow(unused_variables)] let args = Args::from_list(&args).map_err(|e| e.write_errors())?; let fargs = f.sig.inputs.clone(); @@ -38,26 +26,32 @@ pub fn run(args: syn::AttributeArgs, f: syn::ItemFn) -> Result = None; + + if hal.is_some() && fargs.len() != 2 { ctxt.error_spanned_by(&f.sig, "main function must have 2 arguments"); } - if HAL.is_none() && fargs.len() != 1 { + if hal.is_none() && fargs.len() != 1 { ctxt.error_spanned_by(&f.sig, "main function must have 1 argument"); } ctxt.check()?; - let embassy_prefix = args.embassy_prefix; - let embassy_prefix_lit = embassy_prefix.literal(); - let embassy_path = embassy_prefix.append("embassy_executor").path(); let f_body = f.block; #[cfg(feature = "wasm")] let main = quote! { #[wasm_bindgen::prelude::wasm_bindgen(start)] pub fn main() -> Result<(), wasm_bindgen::JsValue> { - static EXECUTOR: ::embassy_util::Forever<#embassy_path::executor::Executor> = ::embassy_util::Forever::new(); - let executor = EXECUTOR.put(#embassy_path::executor::Executor::new()); + static EXECUTOR: ::embassy_util::Forever<::embassy_executor::executor::Executor> = ::embassy_util::Forever::new(); + let executor = EXECUTOR.put(::embassy_executor::executor::Executor::new()); executor.start(|spawner| { spawner.spawn(__embassy_main(spawner)).unwrap(); @@ -70,7 +64,7 @@ pub fn run(args: syn::AttributeArgs, f: syn::ItemFn) -> Result ! { - let mut executor = #embassy_path::executor::Executor::new(); + let mut executor = ::embassy_executor::executor::Executor::new(); let executor = unsafe { __make_static(&mut executor) }; executor.run(|spawner| { @@ -87,16 +81,13 @@ pub fn run(args: syn::AttributeArgs, f: syn::ItemFn) -> Result { - let embassy_hal_path = embassy_prefix.append(hal).path(); - ( - quote!( - let p = #embassy_hal_path::init(#config); - ), - quote!(p), - ) - } + let (hal_setup, peris_arg) = match hal { + Some(hal) => ( + quote!( + let p = #hal::init(#config); + ), + quote!(p), + ), None => (quote!(), quote!()), }; @@ -105,7 +96,7 @@ pub fn run(args: syn::AttributeArgs, f: syn::ItemFn) -> Result ! { #hal_setup - let mut executor = #embassy_path::executor::Executor::new(); + let mut executor = ::embassy_executor::executor::Executor::new(); let executor = unsafe { __make_static(&mut executor) }; executor.run(|spawner| { @@ -116,7 +107,7 @@ pub fn run(args: syn::AttributeArgs, f: syn::ItemFn) -> Result, - #[darling(default)] - embassy_prefix: ModulePrefix, } pub fn run(args: syn::AttributeArgs, f: syn::ItemFn) -> Result { let args = Args::from_list(&args).map_err(|e| e.write_errors())?; - let embassy_prefix = args.embassy_prefix.append("embassy_executor"); - let embassy_path = embassy_prefix.path(); - let pool_size: usize = args.pool_size.unwrap_or(1); let ctxt = Ctxt::new(); @@ -70,9 +64,9 @@ pub fn run(args: syn::AttributeArgs, f: syn::ItemFn) -> Result #embassy_path::executor::SpawnToken { + #visibility fn #task_ident(#fargs) -> ::embassy_executor::executor::SpawnToken { type Fut = impl ::core::future::Future + 'static; - static POOL: #embassy_path::executor::raw::TaskPool = #embassy_path::executor::raw::TaskPool::new(); + static POOL: ::embassy_executor::executor::raw::TaskPool = ::embassy_executor::executor::raw::TaskPool::new(); unsafe { POOL._spawn_async_fn(move || #task_inner_ident(#(#arg_names,)*)) } } }; diff --git a/embassy-macros/src/util/mod.rs b/embassy-macros/src/util/mod.rs index c2f2dfd65..28702809e 100644 --- a/embassy-macros/src/util/mod.rs +++ b/embassy-macros/src/util/mod.rs @@ -1,2 +1 @@ pub mod ctxt; -pub mod path; diff --git a/embassy-macros/src/util/path.rs b/embassy-macros/src/util/path.rs deleted file mode 100644 index 00fca7bdb..000000000 --- a/embassy-macros/src/util/path.rs +++ /dev/null @@ -1,41 +0,0 @@ -use darling::{FromMeta, Result}; -use proc_macro2::Span; -use syn::{LitStr, Path}; - -#[derive(Debug)] -pub struct ModulePrefix { - literal: LitStr, -} - -impl ModulePrefix { - pub fn new(path: &str) -> Self { - let literal = LitStr::new(path, Span::call_site()); - Self { literal } - } - - pub fn append(&self, component: &str) -> ModulePrefix { - let mut lit = self.literal().value(); - lit.push_str(component); - Self::new(lit.as_str()) - } - - pub fn path(&self) -> Path { - self.literal.parse().unwrap() - } - - pub fn literal(&self) -> &LitStr { - &self.literal - } -} - -impl FromMeta for ModulePrefix { - fn from_string(value: &str) -> Result { - Ok(ModulePrefix::new(value)) - } -} - -impl Default for ModulePrefix { - fn default() -> ModulePrefix { - ModulePrefix::new("::") - } -}