From 823bd714fb6da94cf3b31c2066c398207228b4c6 Mon Sep 17 00:00:00 2001 From: Mathias Date: Wed, 28 Sep 2022 05:19:43 +0200 Subject: [PATCH 01/17] Add E-H1 uart blocking & nb implementation --- embassy-stm32/src/usart/mod.rs | 73 ++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/embassy-stm32/src/usart/mod.rs b/embassy-stm32/src/usart/mod.rs index 6c266874..5ee09934 100644 --- a/embassy-stm32/src/usart/mod.rs +++ b/embassy-stm32/src/usart/mod.rs @@ -359,6 +359,79 @@ mod eh1 { impl<'d, T: BasicInstance, RxDma> embedded_hal_1::serial::ErrorType for UartRx<'d, T, RxDma> { type Error = Error; } + + + impl<'d, T: BasicInstance, RxDma> embedded_hal_1::serial::nb::Read for UartRx<'d, T, RxDma> { + fn read(&mut self) -> nb::Result { + let r = T::regs(); + unsafe { + let sr = sr(r).read(); + if sr.pe() { + rdr(r).read_volatile(); + Err(nb::Error::Other(Error::Parity)) + } else if sr.fe() { + rdr(r).read_volatile(); + Err(nb::Error::Other(Error::Framing)) + } else if sr.ne() { + rdr(r).read_volatile(); + Err(nb::Error::Other(Error::Noise)) + } else if sr.ore() { + rdr(r).read_volatile(); + Err(nb::Error::Other(Error::Overrun)) + } else if sr.rxne() { + Ok(rdr(r).read_volatile()) + } else { + Err(nb::Error::WouldBlock) + } + } + } + } + + impl<'d, T: BasicInstance, TxDma> embedded_hal_1::serial::blocking::Write for UartTx<'d, T, TxDma> { + fn write(&mut self, buffer: &[u8]) -> Result<(), Self::Error> { + self.blocking_write(buffer) + } + + fn flush(&mut self) -> Result<(), Self::Error> { + self.blocking_flush() + } + } + + impl<'d, T: BasicInstance, TxDma> embedded_hal_1::serial::nb::Write for UartTx<'d, T, TxDma> { + fn write(&mut self, char: u8) -> nb::Result<(), Self::Error> { + self.blocking_write(&[char]).map_err(nb::Error::Other) + } + + fn flush(&mut self) -> nb::Result<(), Self::Error> { + self.blocking_flush().map_err(nb::Error::Other) + } + } + + impl<'d, T: BasicInstance, TxDma, RxDma> embedded_hal_1::serial::nb::Read for Uart<'d, T, TxDma, RxDma> { + fn read(&mut self) -> Result> { + embedded_hal_02::serial::Read::read(&mut self.rx) + } + } + + impl<'d, T: BasicInstance, TxDma, RxDma> embedded_hal_1::serial::blocking::Write for Uart<'d, T, TxDma, RxDma> { + fn write(&mut self, buffer: &[u8]) -> Result<(), Self::Error> { + self.blocking_write(buffer) + } + + fn flush(&mut self) -> Result<(), Self::Error> { + self.blocking_flush() + } + } + + impl<'d, T: BasicInstance, TxDma, RxDma> embedded_hal_1::serial::nb::Write for Uart<'d, T, TxDma, RxDma> { + fn write(&mut self, char: u8) -> nb::Result<(), Self::Error> { + self.blocking_write(&[char]).map_err(nb::Error::Other) + } + + fn flush(&mut self) -> nb::Result<(), Self::Error> { + self.blocking_flush().map_err(nb::Error::Other) + } + } } #[cfg(all( From dc90006982899a5b1be43123905dd65f7b161789 Mon Sep 17 00:00:00 2001 From: Mathias Date: Thu, 29 Sep 2022 07:58:11 +0200 Subject: [PATCH 02/17] Remove code duplication on nb_read --- embassy-stm32/src/usart/mod.rs | 77 ++++++++++++++-------------------- 1 file changed, 32 insertions(+), 45 deletions(-) diff --git a/embassy-stm32/src/usart/mod.rs b/embassy-stm32/src/usart/mod.rs index 5ee09934..4bf15729 100644 --- a/embassy-stm32/src/usart/mod.rs +++ b/embassy-stm32/src/usart/mod.rs @@ -160,6 +160,30 @@ impl<'d, T: BasicInstance, RxDma> UartRx<'d, T, RxDma> { Ok(()) } + pub fn nb_read(&mut self) -> Result> { + let r = T::regs(); + unsafe { + let sr = sr(r).read(); + if sr.pe() { + rdr(r).read_volatile(); + Err(nb::Error::Other(Error::Parity)) + } else if sr.fe() { + rdr(r).read_volatile(); + Err(nb::Error::Other(Error::Framing)) + } else if sr.ne() { + rdr(r).read_volatile(); + Err(nb::Error::Other(Error::Noise)) + } else if sr.ore() { + rdr(r).read_volatile(); + Err(nb::Error::Other(Error::Overrun)) + } else if sr.rxne() { + Ok(rdr(r).read_volatile()) + } else { + Err(nb::Error::WouldBlock) + } + } + } + pub fn blocking_read(&mut self, buffer: &mut [u8]) -> Result<(), Error> { unsafe { let r = T::regs(); @@ -263,6 +287,10 @@ impl<'d, T: BasicInstance, TxDma, RxDma> Uart<'d, T, TxDma, RxDma> { self.rx.read(buffer).await } + pub fn nb_read(&mut self) -> Result> { + self.rx.nb_read() + } + pub fn blocking_read(&mut self, buffer: &mut [u8]) -> Result<(), Error> { self.rx.blocking_read(buffer) } @@ -281,27 +309,7 @@ mod eh02 { impl<'d, T: BasicInstance, RxDma> embedded_hal_02::serial::Read for UartRx<'d, T, RxDma> { type Error = Error; fn read(&mut self) -> Result> { - let r = T::regs(); - unsafe { - let sr = sr(r).read(); - if sr.pe() { - rdr(r).read_volatile(); - Err(nb::Error::Other(Error::Parity)) - } else if sr.fe() { - rdr(r).read_volatile(); - Err(nb::Error::Other(Error::Framing)) - } else if sr.ne() { - rdr(r).read_volatile(); - Err(nb::Error::Other(Error::Noise)) - } else if sr.ore() { - rdr(r).read_volatile(); - Err(nb::Error::Other(Error::Overrun)) - } else if sr.rxne() { - Ok(rdr(r).read_volatile()) - } else { - Err(nb::Error::WouldBlock) - } - } + self.nb_read() } } @@ -318,7 +326,7 @@ mod eh02 { impl<'d, T: BasicInstance, TxDma, RxDma> embedded_hal_02::serial::Read for Uart<'d, T, TxDma, RxDma> { type Error = Error; fn read(&mut self) -> Result> { - embedded_hal_02::serial::Read::read(&mut self.rx) + self.nb_read() } } @@ -360,30 +368,9 @@ mod eh1 { type Error = Error; } - impl<'d, T: BasicInstance, RxDma> embedded_hal_1::serial::nb::Read for UartRx<'d, T, RxDma> { fn read(&mut self) -> nb::Result { - let r = T::regs(); - unsafe { - let sr = sr(r).read(); - if sr.pe() { - rdr(r).read_volatile(); - Err(nb::Error::Other(Error::Parity)) - } else if sr.fe() { - rdr(r).read_volatile(); - Err(nb::Error::Other(Error::Framing)) - } else if sr.ne() { - rdr(r).read_volatile(); - Err(nb::Error::Other(Error::Noise)) - } else if sr.ore() { - rdr(r).read_volatile(); - Err(nb::Error::Other(Error::Overrun)) - } else if sr.rxne() { - Ok(rdr(r).read_volatile()) - } else { - Err(nb::Error::WouldBlock) - } - } + self.nb_read() } } @@ -409,7 +396,7 @@ mod eh1 { impl<'d, T: BasicInstance, TxDma, RxDma> embedded_hal_1::serial::nb::Read for Uart<'d, T, TxDma, RxDma> { fn read(&mut self) -> Result> { - embedded_hal_02::serial::Read::read(&mut self.rx) + self.nb_read() } } From a7fdeac560b5e277afa80cd60f788a48df6069c9 Mon Sep 17 00:00:00 2001 From: Mathias Date: Fri, 30 Sep 2022 06:00:46 +0200 Subject: [PATCH 03/17] Remove flash lock/unlock public API from stm32 flash, and perform the unlocking and locking automatically on erase and write operations --- embassy-stm32/src/flash/mod.rs | 27 +++++++++---------- .../boot/application/stm32f3/src/bin/a.rs | 2 +- .../boot/application/stm32f7/src/bin/a.rs | 2 +- .../boot/application/stm32h7/src/bin/a.rs | 2 +- .../boot/application/stm32l0/src/bin/a.rs | 2 +- .../boot/application/stm32l1/src/bin/a.rs | 2 +- .../boot/application/stm32l4/src/bin/a.rs | 2 +- .../boot/application/stm32wl/src/bin/a.rs | 2 +- examples/boot/bootloader/stm32/src/main.rs | 2 +- examples/stm32f3/src/bin/flash.rs | 2 +- examples/stm32f4/src/bin/flash.rs | 2 +- examples/stm32f7/src/bin/flash.rs | 2 +- examples/stm32h7/src/bin/flash.rs | 2 +- examples/stm32l0/src/bin/flash.rs | 2 +- examples/stm32l1/src/bin/flash.rs | 2 +- examples/stm32wl/src/bin/flash.rs | 2 +- 16 files changed, 28 insertions(+), 29 deletions(-) diff --git a/embassy-stm32/src/flash/mod.rs b/embassy-stm32/src/flash/mod.rs index 5258c9b0..988cf9fa 100644 --- a/embassy-stm32/src/flash/mod.rs +++ b/embassy-stm32/src/flash/mod.rs @@ -23,17 +23,6 @@ impl<'d> Flash<'d> { Self { _inner: p } } - pub fn unlock(p: impl Peripheral

+ 'd) -> Self { - let flash = Self::new(p); - - unsafe { family::unlock() }; - flash - } - - pub fn lock(&mut self) { - unsafe { family::lock() }; - } - pub fn blocking_read(&mut self, offset: u32, bytes: &mut [u8]) -> Result<(), Error> { let offset = FLASH_BASE as u32 + offset; if offset as usize >= FLASH_END || offset as usize + bytes.len() > FLASH_END { @@ -57,7 +46,12 @@ impl<'d> Flash<'d> { self.clear_all_err(); - unsafe { family::blocking_write(offset, buf) } + unsafe { + family::unlock(); + let res = family::blocking_write(offset, buf); + family::lock(); + res + } } pub fn blocking_erase(&mut self, from: u32, to: u32) -> Result<(), Error> { @@ -72,7 +66,12 @@ impl<'d> Flash<'d> { self.clear_all_err(); - unsafe { family::blocking_erase(from, to) } + unsafe { + family::unlock(); + let res = family::blocking_erase(from, to); + family::lock(); + res + } } fn clear_all_err(&mut self) { @@ -82,7 +81,7 @@ impl<'d> Flash<'d> { impl Drop for Flash<'_> { fn drop(&mut self) { - self.lock(); + unsafe { family::lock() }; } } diff --git a/examples/boot/application/stm32f3/src/bin/a.rs b/examples/boot/application/stm32f3/src/bin/a.rs index fdbd5ab9..d92d59b2 100644 --- a/examples/boot/application/stm32f3/src/bin/a.rs +++ b/examples/boot/application/stm32f3/src/bin/a.rs @@ -17,7 +17,7 @@ static APP_B: &[u8] = include_bytes!("../../b.bin"); #[embassy_executor::main] async fn main(_spawner: Spawner) { let p = embassy_stm32::init(Default::default()); - let flash = Flash::unlock(p.FLASH); + let flash = Flash::new(p.FLASH); let mut flash = BlockingAsync::new(flash); let button = Input::new(p.PC13, Pull::Up); diff --git a/examples/boot/application/stm32f7/src/bin/a.rs b/examples/boot/application/stm32f7/src/bin/a.rs index 77b897b0..79ab80e0 100644 --- a/examples/boot/application/stm32f7/src/bin/a.rs +++ b/examples/boot/application/stm32f7/src/bin/a.rs @@ -16,7 +16,7 @@ static APP_B: &[u8] = include_bytes!("../../b.bin"); #[embassy_executor::main] async fn main(_spawner: Spawner) { let p = embassy_stm32::init(Default::default()); - let mut flash = Flash::unlock(p.FLASH); + let mut flash = Flash::new(p.FLASH); let button = Input::new(p.PC13, Pull::Down); let mut button = ExtiInput::new(button, p.EXTI13); diff --git a/examples/boot/application/stm32h7/src/bin/a.rs b/examples/boot/application/stm32h7/src/bin/a.rs index 0fe598a5..8b452be3 100644 --- a/examples/boot/application/stm32h7/src/bin/a.rs +++ b/examples/boot/application/stm32h7/src/bin/a.rs @@ -16,7 +16,7 @@ static APP_B: &[u8] = include_bytes!("../../b.bin"); #[embassy_executor::main] async fn main(_spawner: Spawner) { let p = embassy_stm32::init(Default::default()); - let mut flash = Flash::unlock(p.FLASH); + let mut flash = Flash::new(p.FLASH); let button = Input::new(p.PC13, Pull::Down); let mut button = ExtiInput::new(button, p.EXTI13); diff --git a/examples/boot/application/stm32l0/src/bin/a.rs b/examples/boot/application/stm32l0/src/bin/a.rs index f0b0b80e..59ca3438 100644 --- a/examples/boot/application/stm32l0/src/bin/a.rs +++ b/examples/boot/application/stm32l0/src/bin/a.rs @@ -18,7 +18,7 @@ static APP_B: &[u8] = include_bytes!("../../b.bin"); #[embassy_executor::main] async fn main(_spawner: Spawner) { let p = embassy_stm32::init(Default::default()); - let flash = Flash::unlock(p.FLASH); + let flash = Flash::new(p.FLASH); let mut flash = BlockingAsync::new(flash); let button = Input::new(p.PB2, Pull::Up); diff --git a/examples/boot/application/stm32l1/src/bin/a.rs b/examples/boot/application/stm32l1/src/bin/a.rs index f0b0b80e..59ca3438 100644 --- a/examples/boot/application/stm32l1/src/bin/a.rs +++ b/examples/boot/application/stm32l1/src/bin/a.rs @@ -18,7 +18,7 @@ static APP_B: &[u8] = include_bytes!("../../b.bin"); #[embassy_executor::main] async fn main(_spawner: Spawner) { let p = embassy_stm32::init(Default::default()); - let flash = Flash::unlock(p.FLASH); + let flash = Flash::new(p.FLASH); let mut flash = BlockingAsync::new(flash); let button = Input::new(p.PB2, Pull::Up); diff --git a/examples/boot/application/stm32l4/src/bin/a.rs b/examples/boot/application/stm32l4/src/bin/a.rs index 5119bad2..6cddc6cc 100644 --- a/examples/boot/application/stm32l4/src/bin/a.rs +++ b/examples/boot/application/stm32l4/src/bin/a.rs @@ -17,7 +17,7 @@ static APP_B: &[u8] = include_bytes!("../../b.bin"); #[embassy_executor::main] async fn main(_spawner: Spawner) { let p = embassy_stm32::init(Default::default()); - let flash = Flash::unlock(p.FLASH); + let flash = Flash::new(p.FLASH); let mut flash = BlockingAsync::new(flash); let button = Input::new(p.PC13, Pull::Up); diff --git a/examples/boot/application/stm32wl/src/bin/a.rs b/examples/boot/application/stm32wl/src/bin/a.rs index faa65077..1ff47edd 100644 --- a/examples/boot/application/stm32wl/src/bin/a.rs +++ b/examples/boot/application/stm32wl/src/bin/a.rs @@ -17,7 +17,7 @@ static APP_B: &[u8] = include_bytes!("../../b.bin"); #[embassy_executor::main] async fn main(_spawner: Spawner) { let p = embassy_stm32::init(Default::default()); - let flash = Flash::unlock(p.FLASH); + let flash = Flash::new(p.FLASH); let mut flash = BlockingAsync::new(flash); let button = Input::new(p.PA0, Pull::Up); diff --git a/examples/boot/bootloader/stm32/src/main.rs b/examples/boot/bootloader/stm32/src/main.rs index 294464d1..4b17cd79 100644 --- a/examples/boot/bootloader/stm32/src/main.rs +++ b/examples/boot/bootloader/stm32/src/main.rs @@ -20,7 +20,7 @@ fn main() -> ! { */ let mut bl: BootLoader = BootLoader::default(); - let flash = Flash::unlock(p.FLASH); + let flash = Flash::new(p.FLASH); let mut flash = BootFlash::<_, ERASE_SIZE, ERASE_VALUE>::new(flash); let start = bl.prepare(&mut SingleFlashConfig::new(&mut flash)); core::mem::drop(flash); diff --git a/examples/stm32f3/src/bin/flash.rs b/examples/stm32f3/src/bin/flash.rs index 2cf24dbd..baa7484d 100644 --- a/examples/stm32f3/src/bin/flash.rs +++ b/examples/stm32f3/src/bin/flash.rs @@ -15,7 +15,7 @@ async fn main(_spawner: Spawner) { const ADDR: u32 = 0x26000; - let mut f = Flash::unlock(p.FLASH); + let mut f = Flash::new(p.FLASH); info!("Reading..."); let mut buf = [0u8; 8]; diff --git a/examples/stm32f4/src/bin/flash.rs b/examples/stm32f4/src/bin/flash.rs index 393d61e8..7ea068a4 100644 --- a/examples/stm32f4/src/bin/flash.rs +++ b/examples/stm32f4/src/bin/flash.rs @@ -13,7 +13,7 @@ async fn main(_spawner: Spawner) { let p = embassy_stm32::init(Default::default()); info!("Hello Flash!"); - let mut f = Flash::unlock(p.FLASH); + let mut f = Flash::new(p.FLASH); // Sector 5 test_flash(&mut f, 128 * 1024, 128 * 1024); diff --git a/examples/stm32f7/src/bin/flash.rs b/examples/stm32f7/src/bin/flash.rs index c10781d0..4a7bca1f 100644 --- a/examples/stm32f7/src/bin/flash.rs +++ b/examples/stm32f7/src/bin/flash.rs @@ -19,7 +19,7 @@ async fn main(_spawner: Spawner) { // wait a bit before accessing the flash Timer::after(Duration::from_millis(300)).await; - let mut f = Flash::unlock(p.FLASH); + let mut f = Flash::new(p.FLASH); info!("Reading..."); let mut buf = [0u8; 32]; diff --git a/examples/stm32h7/src/bin/flash.rs b/examples/stm32h7/src/bin/flash.rs index 6682c64d..ee86bdbf 100644 --- a/examples/stm32h7/src/bin/flash.rs +++ b/examples/stm32h7/src/bin/flash.rs @@ -19,7 +19,7 @@ async fn main(_spawner: Spawner) { // wait a bit before accessing the flash Timer::after(Duration::from_millis(300)).await; - let mut f = Flash::unlock(p.FLASH); + let mut f = Flash::new(p.FLASH); info!("Reading..."); let mut buf = [0u8; 32]; diff --git a/examples/stm32l0/src/bin/flash.rs b/examples/stm32l0/src/bin/flash.rs index 867cb4d3..ffe4fb10 100644 --- a/examples/stm32l0/src/bin/flash.rs +++ b/examples/stm32l0/src/bin/flash.rs @@ -15,7 +15,7 @@ async fn main(_spawner: Spawner) { const ADDR: u32 = 0x26000; - let mut f = Flash::unlock(p.FLASH); + let mut f = Flash::new(p.FLASH); info!("Reading..."); let mut buf = [0u8; 8]; diff --git a/examples/stm32l1/src/bin/flash.rs b/examples/stm32l1/src/bin/flash.rs index a76b9879..476ed51a 100644 --- a/examples/stm32l1/src/bin/flash.rs +++ b/examples/stm32l1/src/bin/flash.rs @@ -15,7 +15,7 @@ async fn main(_spawner: Spawner) { const ADDR: u32 = 0x26000; - let mut f = Flash::unlock(p.FLASH); + let mut f = Flash::new(p.FLASH); info!("Reading..."); let mut buf = [0u8; 8]; diff --git a/examples/stm32wl/src/bin/flash.rs b/examples/stm32wl/src/bin/flash.rs index eb748976..2a888062 100644 --- a/examples/stm32wl/src/bin/flash.rs +++ b/examples/stm32wl/src/bin/flash.rs @@ -15,7 +15,7 @@ async fn main(_spawner: Spawner) { const ADDR: u32 = 0x36000; - let mut f = Flash::unlock(p.FLASH); + let mut f = Flash::new(p.FLASH); info!("Reading..."); let mut buf = [0u8; 8]; From a283c47557ee6a0c0e54bcb7f27b6c85813ae0e3 Mon Sep 17 00:00:00 2001 From: Mathias Date: Fri, 30 Sep 2022 05:35:46 +0200 Subject: [PATCH 04/17] Implement embedded-hal-nb for uart --- embassy-stm32/Cargo.toml | 3 ++- embassy-stm32/src/usart/mod.rs | 12 ++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/embassy-stm32/Cargo.toml b/embassy-stm32/Cargo.toml index 9566dbca..fbe37fe3 100644 --- a/embassy-stm32/Cargo.toml +++ b/embassy-stm32/Cargo.toml @@ -44,6 +44,7 @@ embassy-usb-driver = {version = "0.1.0", path = "../embassy-usb-driver", optiona embedded-hal-02 = { package = "embedded-hal", version = "0.2.6", features = ["unproven"] } embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-alpha.9", optional = true} embedded-hal-async = { version = "=0.1.0-alpha.2", optional = true} +embedded-hal-nb = { version = "=1.0.0-alpha.1", optional = true} embedded-storage = "0.3.0" embedded-storage-async = { version = "0.3.0", optional = true } @@ -102,7 +103,7 @@ unstable-pac = [] # Implement embedded-hal 1.0 alpha traits. # Implement embedded-hal-async traits if `nightly` is set as well. -unstable-traits = ["embedded-hal-1"] +unstable-traits = ["embedded-hal-1", "dep:embedded-hal-nb"] # BEGIN GENERATED FEATURES # Generated by stm32-gen-features. DO NOT EDIT. diff --git a/embassy-stm32/src/usart/mod.rs b/embassy-stm32/src/usart/mod.rs index 4bf15729..a152a0c1 100644 --- a/embassy-stm32/src/usart/mod.rs +++ b/embassy-stm32/src/usart/mod.rs @@ -368,13 +368,13 @@ mod eh1 { type Error = Error; } - impl<'d, T: BasicInstance, RxDma> embedded_hal_1::serial::nb::Read for UartRx<'d, T, RxDma> { + impl<'d, T: BasicInstance, RxDma> embedded_hal_nb::serial::Read for UartRx<'d, T, RxDma> { fn read(&mut self) -> nb::Result { self.nb_read() } } - impl<'d, T: BasicInstance, TxDma> embedded_hal_1::serial::blocking::Write for UartTx<'d, T, TxDma> { + impl<'d, T: BasicInstance, TxDma> embedded_hal_1::serial::Write for UartTx<'d, T, TxDma> { fn write(&mut self, buffer: &[u8]) -> Result<(), Self::Error> { self.blocking_write(buffer) } @@ -384,7 +384,7 @@ mod eh1 { } } - impl<'d, T: BasicInstance, TxDma> embedded_hal_1::serial::nb::Write for UartTx<'d, T, TxDma> { + impl<'d, T: BasicInstance, TxDma> embedded_hal_nb::serial::Write for UartTx<'d, T, TxDma> { fn write(&mut self, char: u8) -> nb::Result<(), Self::Error> { self.blocking_write(&[char]).map_err(nb::Error::Other) } @@ -394,13 +394,13 @@ mod eh1 { } } - impl<'d, T: BasicInstance, TxDma, RxDma> embedded_hal_1::serial::nb::Read for Uart<'d, T, TxDma, RxDma> { + impl<'d, T: BasicInstance, TxDma, RxDma> embedded_hal_nb::serial::Read for Uart<'d, T, TxDma, RxDma> { fn read(&mut self) -> Result> { self.nb_read() } } - impl<'d, T: BasicInstance, TxDma, RxDma> embedded_hal_1::serial::blocking::Write for Uart<'d, T, TxDma, RxDma> { + impl<'d, T: BasicInstance, TxDma, RxDma> embedded_hal_1::serial::Write for Uart<'d, T, TxDma, RxDma> { fn write(&mut self, buffer: &[u8]) -> Result<(), Self::Error> { self.blocking_write(buffer) } @@ -410,7 +410,7 @@ mod eh1 { } } - impl<'d, T: BasicInstance, TxDma, RxDma> embedded_hal_1::serial::nb::Write for Uart<'d, T, TxDma, RxDma> { + impl<'d, T: BasicInstance, TxDma, RxDma> embedded_hal_nb::serial::Write for Uart<'d, T, TxDma, RxDma> { fn write(&mut self, char: u8) -> nb::Result<(), Self::Error> { self.blocking_write(&[char]).map_err(nb::Error::Other) } From 9f77dbf5ae442c1cac0c652b4ef25bf1c82ed9d4 Mon Sep 17 00:00:00 2001 From: Jeremy Fitzhardinge Date: Thu, 29 Sep 2022 02:01:58 -0700 Subject: [PATCH 05/17] rp i2c: blocking example i2c example talking to mcp23017 i2c gpio expander. --- examples/rp/src/bin/i2c.rs | 70 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 examples/rp/src/bin/i2c.rs diff --git a/examples/rp/src/bin/i2c.rs b/examples/rp/src/bin/i2c.rs new file mode 100644 index 00000000..a5991d0d --- /dev/null +++ b/examples/rp/src/bin/i2c.rs @@ -0,0 +1,70 @@ +#![no_std] +#![no_main] +#![feature(type_alias_impl_trait)] + +use defmt::*; +use embassy_executor::Spawner; +use embassy_rp::i2c::{self, Config}; +use embassy_time::{Duration, Timer}; +use embedded_hal_1::i2c::blocking::I2c; +use {defmt_rtt as _, panic_probe as _}; + +#[allow(dead_code)] +mod mcp23017 { + pub const ADDR: u8 = 0x20; // default addr + + pub const IODIRA: u8 = 0x00; + pub const IPOLA: u8 = 0x02; + pub const GPINTENA: u8 = 0x04; + pub const DEFVALA: u8 = 0x06; + pub const INTCONA: u8 = 0x08; + pub const IOCONA: u8 = 0x0A; + pub const GPPUA: u8 = 0x0C; + pub const INTFA: u8 = 0x0E; + pub const INTCAPA: u8 = 0x10; + pub const GPIOA: u8 = 0x12; + pub const OLATA: u8 = 0x14; + pub const IODIRB: u8 = 0x01; + pub const IPOLB: u8 = 0x03; + pub const GPINTENB: u8 = 0x05; + pub const DEFVALB: u8 = 0x07; + pub const INTCONB: u8 = 0x09; + pub const IOCONB: u8 = 0x0B; + pub const GPPUB: u8 = 0x0D; + pub const INTFB: u8 = 0x0F; + pub const INTCAPB: u8 = 0x11; + pub const GPIOB: u8 = 0x13; + pub const OLATB: u8 = 0x15; +} + +#[embassy_executor::main] +async fn main(_spawner: Spawner) { + let p = embassy_rp::init(Default::default()); + + let sda = p.PIN_14; + let scl = p.PIN_15; + + info!("set up i2c "); + let mut i2c = i2c::I2c::new_blocking(p.I2C1, scl, sda, Config::default()); + + use mcp23017::*; + + info!("init mcp23017 config for IxpandO"); + // init - a outputs, b inputs + i2c.write(ADDR, &[IODIRA, 0x00]).unwrap(); + i2c.write(ADDR, &[IODIRB, 0xff]).unwrap(); + i2c.write(ADDR, &[GPPUB, 0xff]).unwrap(); // pullups + + let mut val = 0xaa; + loop { + let mut portb = [0]; + + i2c.write(mcp23017::ADDR, &[GPIOA, val]).unwrap(); + i2c.write_read(mcp23017::ADDR, &[GPIOB], &mut portb).unwrap(); + + info!("portb = {:02x}", portb[0]); + val = !val; + + Timer::after(Duration::from_secs(1)).await; + } +} From d5abd32da21998178216693a4d549a0f2683a4bb Mon Sep 17 00:00:00 2001 From: Jeremy Fitzhardinge Date: Sat, 1 Oct 2022 01:09:40 -0700 Subject: [PATCH 06/17] rename to i2c_blocking --- examples/rp/src/bin/{i2c.rs => i2c_blocking.rs} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename examples/rp/src/bin/{i2c.rs => i2c_blocking.rs} (100%) diff --git a/examples/rp/src/bin/i2c.rs b/examples/rp/src/bin/i2c_blocking.rs similarity index 100% rename from examples/rp/src/bin/i2c.rs rename to examples/rp/src/bin/i2c_blocking.rs From c96581879cf054d9e4fec9272e5cecb165844cbb Mon Sep 17 00:00:00 2001 From: Jeremy Fitzhardinge Date: Sat, 1 Oct 2022 01:33:36 -0700 Subject: [PATCH 07/17] update embedded-hal api Also pin to alpha.9 since its a breaking change --- examples/rp/Cargo.toml | 2 +- examples/rp/src/bin/i2c_blocking.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/rp/Cargo.toml b/examples/rp/Cargo.toml index 3c8f923e..1bb6432e 100644 --- a/examples/rp/Cargo.toml +++ b/examples/rp/Cargo.toml @@ -26,7 +26,7 @@ st7789 = "0.6.1" display-interface = "0.4.1" byte-slice-cast = { version = "1.2.0", default-features = false } -embedded-hal-1 = { package = "embedded-hal", version = "1.0.0-alpha.8" } +embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-alpha.9" } embedded-hal-async = { version = "0.1.0-alpha.1" } embedded-io = { version = "0.3.0", features = ["async", "defmt"] } static_cell = "1.0.0" diff --git a/examples/rp/src/bin/i2c_blocking.rs b/examples/rp/src/bin/i2c_blocking.rs index a5991d0d..7623e33c 100644 --- a/examples/rp/src/bin/i2c_blocking.rs +++ b/examples/rp/src/bin/i2c_blocking.rs @@ -6,7 +6,7 @@ use defmt::*; use embassy_executor::Spawner; use embassy_rp::i2c::{self, Config}; use embassy_time::{Duration, Timer}; -use embedded_hal_1::i2c::blocking::I2c; +use embedded_hal_1::i2c::I2c; use {defmt_rtt as _, panic_probe as _}; #[allow(dead_code)] From 753781a2639c3505ab046cb48acb6473b84b214b Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Sun, 2 Oct 2022 22:24:59 +0200 Subject: [PATCH 08/17] Build docs in CI --- .github/workflows/doc.yml | 85 +++++++++++++++++++++++++++++++++ .github/workflows/rust.yml | 2 +- embassy-embedded-hal/Cargo.toml | 2 +- embassy-executor/Cargo.toml | 2 +- embassy-usb/Cargo.toml | 2 +- 5 files changed, 89 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/doc.yml diff --git a/.github/workflows/doc.yml b/.github/workflows/doc.yml new file mode 100644 index 00000000..349ca404 --- /dev/null +++ b/.github/workflows/doc.yml @@ -0,0 +1,85 @@ +name: Docs + +on: + push: + branches: [master] + +env: + BUILDER_THREADS: '2' + +jobs: + doc: + runs-on: ubuntu-latest + + # Since stm32 crates take SO LONG to build, we split them + # into a separate job. This way it doesn't slow down updating + # the rest. + strategy: + matrix: + crates: + - stm32 + - rest + + # This will ensure at most one doc build job is running at a time + # (for stm32 and non-stm32 independently). + # If another job is already running, the new job will wait. + # If another job is already waiting, it'll be canceled. + # This means some commits will be skipped, but that's fine because + # we only care that the latest gets built. + concurrency: doc-${{ matrix.crates }} + + steps: + - uses: actions/checkout@v2 + with: + submodules: true + - name: Install Rust targets + run: | + rustup target add x86_64-unknown-linux-gnu + rustup target add wasm32-unknown-unknown + rustup target add thumbv6m-none-eabi + rustup target add thumbv7m-none-eabi + rustup target add thumbv7em-none-eabi + rustup target add thumbv7em-none-eabihf + rustup target add thumbv8m.base-none-eabi + rustup target add thumbv8m.main-none-eabi + rustup target add thumbv8m.main-none-eabihf + + - name: Install docserver + run: | + wget -q -O /usr/local/bin/builder "https://github.com/embassy-rs/docserver/releases/download/v0.3/builder" + chmod +x /usr/local/bin/builder + + - name: build-stm32 + if: ${{ matrix.crates=='stm32' }} + run: | + mkdir crates + builder ./embassy-stm32 crates/embassy-stm32/git.zup + builder ./stm32-metapac crates/stm32-metapac/git.zup + + - name: build-rest + if: ${{ matrix.crates=='rest' }} + run: | + mkdir crates + builder ./embassy-boot/boot crates/embassy-boot/git.zup + builder ./embassy-boot/nrf crates/embassy-boot-nrf/git.zup + builder ./embassy-boot/stm32 crates/embassy-boot-stm32/git.zup + builder ./embassy-cortex-m crates/embassy-cortex-m/git.zup + builder ./embassy-embedded-hal crates/embassy-embedded-hal/git.zup + builder ./embassy-executor crates/embassy-executor/git.zup + builder ./embassy-futures crates/embassy-futures/git.zup + builder ./embassy-lora crates/embassy-lora/git.zup + builder ./embassy-net crates/embassy-net/git.zup + builder ./embassy-nrf crates/embassy-nrf/git.zup + builder ./embassy-rp crates/embassy-rp/git.zup + builder ./embassy-sync crates/embassy-sync/git.zup + builder ./embassy-usb crates/embassy-usb/git.zup + builder ./embassy-usb-driver crates/embassy-usb-driver/git.zup + + - name: upload + run: | + mkdir -p ~/.kube + echo "${{secrets.KUBECONFIG}}" > ~/.kube/config + POD=$(kubectl -n embassy get po -l app=docserver -o jsonpath={.items[0].metadata.name}) + kubectl cp crates $POD:/data + + \ No newline at end of file diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index d2e8e316..b93c8783 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -11,7 +11,7 @@ env: jobs: all: - runs-on: ubuntu-20.04 + runs-on: ubuntu-latest needs: [build-nightly, build-stable, test] steps: - name: Done diff --git a/embassy-embedded-hal/Cargo.toml b/embassy-embedded-hal/Cargo.toml index fe8fac7c..845f742e 100644 --- a/embassy-embedded-hal/Cargo.toml +++ b/embassy-embedded-hal/Cargo.toml @@ -8,7 +8,7 @@ edition = "2021" src_base = "https://github.com/embassy-rs/embassy/blob/embassy-embedded-hal-v$VERSION/embassy-embedded-hal/src/" src_base_git = "https://github.com/embassy-rs/embassy/blob/$COMMIT/embassy-embedded-hal/src/" features = ["nightly", "std"] -target = "thumbv7em-none-eabi" +target = "x86_64-unknown-linux-gnu" [features] std = [] diff --git a/embassy-executor/Cargo.toml b/embassy-executor/Cargo.toml index fa3d0b2b..3b1c4ab4 100644 --- a/embassy-executor/Cargo.toml +++ b/embassy-executor/Cargo.toml @@ -7,7 +7,7 @@ edition = "2021" [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", "unstable-traits"] +features = ["nightly", "defmt"] flavors = [ { name = "std", target = "x86_64-unknown-linux-gnu", features = ["std"] }, { name = "wasm", target = "wasm32-unknown-unknown", features = ["wasm"] }, diff --git a/embassy-usb/Cargo.toml b/embassy-usb/Cargo.toml index aad54dba..1f705e9f 100644 --- a/embassy-usb/Cargo.toml +++ b/embassy-usb/Cargo.toml @@ -6,7 +6,7 @@ edition = "2021" [package.metadata.embassy_docs] src_base = "https://github.com/embassy-rs/embassy/blob/embassy-usb-v$VERSION/embassy-usb/src/" src_base_git = "https://github.com/embassy-rs/embassy/blob/$COMMIT/embassy-usb/src/" -features = ["defmt"] +features = ["defmt", "usbd-hid"] target = "thumbv7em-none-eabi" [features] From f075e624440af121da7a27a145e2acee0730c542 Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Mon, 3 Oct 2022 01:59:44 +0200 Subject: [PATCH 09/17] Use 1 thread in ci doc building. --- .github/workflows/doc.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/doc.yml b/.github/workflows/doc.yml index 349ca404..49e1cf71 100644 --- a/.github/workflows/doc.yml +++ b/.github/workflows/doc.yml @@ -5,7 +5,7 @@ on: branches: [master] env: - BUILDER_THREADS: '2' + BUILDER_THREADS: '1' jobs: doc: From 59765590e0339e8f4294719b6e99a6ab110266d8 Mon Sep 17 00:00:00 2001 From: Ulf Lilleengen Date: Tue, 4 Oct 2022 16:38:11 +0200 Subject: [PATCH 10/17] Add required info to embassy-sync package Updates the README.md based on embassy-futures structure. --- embassy-sync/Cargo.toml | 10 ++++++++++ embassy-sync/README.md | 24 ++++++++++++++++++++++-- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/embassy-sync/Cargo.toml b/embassy-sync/Cargo.toml index 14ab1d00..584d5ba9 100644 --- a/embassy-sync/Cargo.toml +++ b/embassy-sync/Cargo.toml @@ -2,6 +2,16 @@ name = "embassy-sync" version = "0.1.0" edition = "2021" +description = "no-std, no-alloc synchronization primitives with async support" +repository = "https://github.com/embassy-rs/embassy" +readme = "README.md" +license = "MIT OR Apache-2.0" +categories = [ + "embedded", + "no-std", + "concurrency", + "asynchronous", +] [package.metadata.embassy_docs] src_base = "https://github.com/embassy-rs/embassy/blob/embassy-sync-v$VERSION/embassy-sync/src/" diff --git a/embassy-sync/README.md b/embassy-sync/README.md index 106295c0..cc65cf6e 100644 --- a/embassy-sync/README.md +++ b/embassy-sync/README.md @@ -1,12 +1,32 @@ # embassy-sync -Synchronization primitives and data structures with an async API: +An [Embassy](https://embassy.dev) project. + +Synchronization primitives and data structures with async support: - [`Channel`](channel::Channel) - A Multiple Producer Multiple Consumer (MPMC) channel. Each message is only received by a single consumer. - [`PubSubChannel`](pubsub::PubSubChannel) - A broadcast channel (publish-subscribe) channel. Each message is received by all consumers. - [`Signal`](signal::Signal) - Signalling latest value to a single consumer. -- [`Mutex`](mutex::Mutex) - A Mutex for synchronizing state between asynchronous tasks. +- [`Mutex`](mutex::Mutex) - Mutex for synchronizing state between asynchronous tasks. - [`Pipe`](pipe::Pipe) - Byte stream implementing `embedded_io` traits. - [`WakerRegistration`](waitqueue::WakerRegistration) - Utility to register and wake a `Waker`. - [`AtomicWaker`](waitqueue::AtomicWaker) - A variant of `WakerRegistration` accessible using a non-mut API. - [`MultiWakerRegistration`](waitqueue::MultiWakerRegistration) - Utility registering and waking multiple `Waker`'s. + +## Interoperability + +Futures from this crate can run on any executor. + +## 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 530182d6683531f7c259448e6c54c866f35837c7 Mon Sep 17 00:00:00 2001 From: Dion Dokter Date: Wed, 5 Oct 2022 15:15:03 +0200 Subject: [PATCH 11/17] Forgot to add space function to immediate publisher --- embassy-sync/src/pubsub/publisher.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/embassy-sync/src/pubsub/publisher.rs b/embassy-sync/src/pubsub/publisher.rs index faa67d94..e1edc9eb 100644 --- a/embassy-sync/src/pubsub/publisher.rs +++ b/embassy-sync/src/pubsub/publisher.rs @@ -123,6 +123,14 @@ impl<'a, PSB: PubSubBehavior + ?Sized, T: Clone> ImmediatePub<'a, PSB, T> { pub fn try_publish(&self, message: T) -> Result<(), T> { self.channel.publish_with_context(message, None) } + + /// The amount of messages that can still be published without having to wait or without having to lag the subscribers + /// + /// *Note: In the time between checking this and a publish action, other publishers may have had time to publish something. + /// So checking doesn't give any guarantees.* + pub fn space(&self) -> usize { + self.channel.space() + } } /// An immediate publisher that holds a dynamic reference to the channel From d49d1b6b1cf6de9577816397db3c41f6e93aa4e6 Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Wed, 5 Oct 2022 17:08:02 +0200 Subject: [PATCH 12/17] ci/doc: build embassy-time too. --- .github/workflows/doc.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/doc.yml b/.github/workflows/doc.yml index 49e1cf71..eb460e73 100644 --- a/.github/workflows/doc.yml +++ b/.github/workflows/doc.yml @@ -72,6 +72,7 @@ jobs: builder ./embassy-nrf crates/embassy-nrf/git.zup builder ./embassy-rp crates/embassy-rp/git.zup builder ./embassy-sync crates/embassy-sync/git.zup + builder ./embassy-time crates/embassy-time/git.zup builder ./embassy-usb crates/embassy-usb/git.zup builder ./embassy-usb-driver crates/embassy-usb-driver/git.zup From 9dca368c3dd1a8f00295b21c87d4fbb94afb60a5 Mon Sep 17 00:00:00 2001 From: chemicstry Date: Fri, 7 Oct 2022 13:29:56 +0300 Subject: [PATCH 13/17] Use RccPeripheral for adc_v2 --- embassy-stm32/src/adc/mod.rs | 4 ++-- embassy-stm32/src/adc/v2.rs | 26 +++++++++----------------- 2 files changed, 11 insertions(+), 19 deletions(-) diff --git a/embassy-stm32/src/adc/mod.rs b/embassy-stm32/src/adc/mod.rs index 8da13073..fba016a7 100644 --- a/embassy-stm32/src/adc/mod.rs +++ b/embassy-stm32/src/adc/mod.rs @@ -30,9 +30,9 @@ pub(crate) mod sealed { } } -#[cfg(not(adc_f1))] +#[cfg(not(any(adc_f1, adc_v2)))] pub trait Instance: sealed::Instance + 'static {} -#[cfg(adc_f1)] +#[cfg(any(adc_f1, adc_v2))] pub trait Instance: sealed::Instance + crate::rcc::RccPeripheral + 'static {} #[cfg(all(not(adc_f1), not(adc_v1)))] pub trait Common: sealed::Common + 'static {} diff --git a/embassy-stm32/src/adc/v2.rs b/embassy-stm32/src/adc/v2.rs index 25b7ba96..70e3b73b 100644 --- a/embassy-stm32/src/adc/v2.rs +++ b/embassy-stm32/src/adc/v2.rs @@ -12,21 +12,6 @@ pub const VREF_DEFAULT_MV: u32 = 3300; /// VREF voltage used for factory calibration of VREFINTCAL register. pub const VREF_CALIB_MV: u32 = 3300; -#[cfg(not(any(rcc_f4, rcc_f7)))] -fn enable() { - todo!() -} - -#[cfg(any(rcc_f4, rcc_f7))] -fn enable() { - critical_section::with(|_| unsafe { - // TODO do not enable all adc clocks if not needed - crate::pac::RCC.apb2enr().modify(|w| w.set_adc1en(true)); - crate::pac::RCC.apb2enr().modify(|w| w.set_adc2en(true)); - crate::pac::RCC.apb2enr().modify(|w| w.set_adc3en(true)); - }); -} - pub enum Resolution { TwelveBit, TenBit, @@ -164,9 +149,10 @@ where { pub fn new(_peri: impl Peripheral

+ 'd, delay: &mut impl DelayUs) -> Self { into_ref!(_peri); - enable(); + T::enable(); + T::reset(); - let presc = unsafe { Prescaler::from_pclk2(crate::rcc::get_freqs().apb2) }; + let presc = unsafe { Prescaler::from_pclk2(T::frequency()) }; unsafe { T::common_regs().ccr().modify(|w| w.set_adcpre(presc.adcpre())); } @@ -288,3 +274,9 @@ where } } } + +impl<'d, T: Instance> Drop for Adc<'d, T> { + fn drop(&mut self) { + T::disable(); + } +} From 6718ca3a9412c9fbd5f1161b1123664024ffbe37 Mon Sep 17 00:00:00 2001 From: chrysn Date: Fri, 7 Oct 2022 12:41:56 +0200 Subject: [PATCH 14/17] all Cargo.toml: Add license to all crate Cargo.toml files Closes: https://github.com/embassy-rs/embassy/issues/1002 --- docs/modules/ROOT/examples/basic/Cargo.toml | 1 + .../ROOT/examples/layer-by-layer/blinky-async/Cargo.toml | 1 + .../modules/ROOT/examples/layer-by-layer/blinky-hal/Cargo.toml | 1 + .../modules/ROOT/examples/layer-by-layer/blinky-irq/Cargo.toml | 1 + .../modules/ROOT/examples/layer-by-layer/blinky-pac/Cargo.toml | 1 + embassy-boot/boot/Cargo.toml | 1 + embassy-boot/nrf/Cargo.toml | 1 + embassy-boot/stm32/Cargo.toml | 1 + embassy-cortex-m/Cargo.toml | 1 + embassy-embedded-hal/Cargo.toml | 1 + embassy-executor/Cargo.toml | 1 + embassy-hal-common/Cargo.toml | 1 + embassy-lora/Cargo.toml | 1 + embassy-macros/Cargo.toml | 1 + embassy-net/Cargo.toml | 1 + embassy-nrf/Cargo.toml | 1 + embassy-rp/Cargo.toml | 1 + embassy-stm32/Cargo.toml | 1 + embassy-time/Cargo.toml | 1 + embassy-usb-driver/Cargo.toml | 3 ++- embassy-usb/Cargo.toml | 1 + examples/boot/application/nrf/Cargo.toml | 1 + examples/boot/application/stm32f3/Cargo.toml | 1 + examples/boot/application/stm32f7/Cargo.toml | 1 + examples/boot/application/stm32h7/Cargo.toml | 1 + examples/boot/application/stm32l0/Cargo.toml | 1 + examples/boot/application/stm32l1/Cargo.toml | 1 + examples/boot/application/stm32l4/Cargo.toml | 1 + examples/boot/application/stm32wl/Cargo.toml | 1 + examples/boot/bootloader/nrf/Cargo.toml | 1 + examples/boot/bootloader/stm32/Cargo.toml | 1 + examples/nrf-rtos-trace/Cargo.toml | 1 + examples/nrf/Cargo.toml | 1 + examples/rp/Cargo.toml | 1 + examples/std/Cargo.toml | 1 + examples/stm32f0/Cargo.toml | 1 + examples/stm32f1/Cargo.toml | 1 + examples/stm32f2/Cargo.toml | 1 + examples/stm32f3/Cargo.toml | 1 + examples/stm32f4/Cargo.toml | 1 + examples/stm32f7/Cargo.toml | 1 + examples/stm32g0/Cargo.toml | 1 + examples/stm32g4/Cargo.toml | 1 + examples/stm32h7/Cargo.toml | 1 + examples/stm32l0/Cargo.toml | 1 + examples/stm32l1/Cargo.toml | 1 + examples/stm32l4/Cargo.toml | 1 + examples/stm32l5/Cargo.toml | 1 + examples/stm32u5/Cargo.toml | 1 + examples/stm32wb/Cargo.toml | 1 + examples/stm32wl/Cargo.toml | 1 + examples/wasm/Cargo.toml | 1 + stm32-gen-features/Cargo.toml | 1 + stm32-metapac-gen/Cargo.toml | 1 + tests/rp/Cargo.toml | 1 + tests/stm32/Cargo.toml | 1 + xtask/Cargo.toml | 1 + 57 files changed, 58 insertions(+), 1 deletion(-) diff --git a/docs/modules/ROOT/examples/basic/Cargo.toml b/docs/modules/ROOT/examples/basic/Cargo.toml index ae124a87..c13f546e 100644 --- a/docs/modules/ROOT/examples/basic/Cargo.toml +++ b/docs/modules/ROOT/examples/basic/Cargo.toml @@ -3,6 +3,7 @@ authors = ["Dario Nieuwenhuis "] edition = "2018" name = "embassy-basic-example" version = "0.1.0" +license = "MIT OR Apache-2.0" [dependencies] embassy-executor = { version = "0.1.0", path = "../../../../../embassy-executor", features = ["defmt", "nightly"] } 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 e2933076..c9a963d4 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 @@ -2,6 +2,7 @@ name = "blinky-async" version = "0.1.0" edition = "2021" +license = "MIT OR Apache-2.0" [dependencies] cortex-m = "0.7" diff --git a/docs/modules/ROOT/examples/layer-by-layer/blinky-hal/Cargo.toml b/docs/modules/ROOT/examples/layer-by-layer/blinky-hal/Cargo.toml index dbd3aba8..f86361dd 100644 --- a/docs/modules/ROOT/examples/layer-by-layer/blinky-hal/Cargo.toml +++ b/docs/modules/ROOT/examples/layer-by-layer/blinky-hal/Cargo.toml @@ -2,6 +2,7 @@ name = "blinky-hal" version = "0.1.0" edition = "2021" +license = "MIT OR Apache-2.0" [dependencies] cortex-m = "0.7" diff --git a/docs/modules/ROOT/examples/layer-by-layer/blinky-irq/Cargo.toml b/docs/modules/ROOT/examples/layer-by-layer/blinky-irq/Cargo.toml index 0dd32601..9733658b 100644 --- a/docs/modules/ROOT/examples/layer-by-layer/blinky-irq/Cargo.toml +++ b/docs/modules/ROOT/examples/layer-by-layer/blinky-irq/Cargo.toml @@ -2,6 +2,7 @@ name = "blinky-irq" version = "0.1.0" edition = "2021" +license = "MIT OR Apache-2.0" [dependencies] cortex-m = "0.7" diff --git a/docs/modules/ROOT/examples/layer-by-layer/blinky-pac/Cargo.toml b/docs/modules/ROOT/examples/layer-by-layer/blinky-pac/Cargo.toml index e7f4f5d1..a077f182 100644 --- a/docs/modules/ROOT/examples/layer-by-layer/blinky-pac/Cargo.toml +++ b/docs/modules/ROOT/examples/layer-by-layer/blinky-pac/Cargo.toml @@ -2,6 +2,7 @@ name = "blinky-pac" version = "0.1.0" edition = "2021" +license = "MIT OR Apache-2.0" [dependencies] cortex-m = "0.7" diff --git a/embassy-boot/boot/Cargo.toml b/embassy-boot/boot/Cargo.toml index a42f8868..54c67a37 100644 --- a/embassy-boot/boot/Cargo.toml +++ b/embassy-boot/boot/Cargo.toml @@ -3,6 +3,7 @@ edition = "2021" name = "embassy-boot" version = "0.1.0" description = "Bootloader using Embassy" +license = "MIT OR Apache-2.0" [package.metadata.embassy_docs] src_base = "https://github.com/embassy-rs/embassy/blob/embassy-boot-v$VERSION/embassy-boot/boot/src/" diff --git a/embassy-boot/nrf/Cargo.toml b/embassy-boot/nrf/Cargo.toml index 234393e7..c6af7014 100644 --- a/embassy-boot/nrf/Cargo.toml +++ b/embassy-boot/nrf/Cargo.toml @@ -3,6 +3,7 @@ edition = "2021" name = "embassy-boot-nrf" version = "0.1.0" description = "Bootloader lib for nRF chips" +license = "MIT OR Apache-2.0" [package.metadata.embassy_docs] src_base = "https://github.com/embassy-rs/embassy/blob/embassy-boot-nrf-v$VERSION/embassy-boot/nrf/src/" diff --git a/embassy-boot/stm32/Cargo.toml b/embassy-boot/stm32/Cargo.toml index ad4657e0..9d12c6cf 100644 --- a/embassy-boot/stm32/Cargo.toml +++ b/embassy-boot/stm32/Cargo.toml @@ -3,6 +3,7 @@ edition = "2021" name = "embassy-boot-stm32" version = "0.1.0" description = "Bootloader lib for STM32 chips" +license = "MIT OR Apache-2.0" [package.metadata.embassy_docs] src_base = "https://github.com/embassy-rs/embassy/blob/embassy-boot-nrf-v$VERSION/embassy-boot/stm32/src/" diff --git a/embassy-cortex-m/Cargo.toml b/embassy-cortex-m/Cargo.toml index 7efced66..5c5718d5 100644 --- a/embassy-cortex-m/Cargo.toml +++ b/embassy-cortex-m/Cargo.toml @@ -2,6 +2,7 @@ name = "embassy-cortex-m" version = "0.1.0" edition = "2021" +license = "MIT OR Apache-2.0" [package.metadata.embassy_docs] src_base = "https://github.com/embassy-rs/embassy/blob/embassy-cortex-m-v$VERSION/embassy-cortex-m/src/" diff --git a/embassy-embedded-hal/Cargo.toml b/embassy-embedded-hal/Cargo.toml index 845f742e..d0be6d19 100644 --- a/embassy-embedded-hal/Cargo.toml +++ b/embassy-embedded-hal/Cargo.toml @@ -2,6 +2,7 @@ name = "embassy-embedded-hal" version = "0.1.0" edition = "2021" +license = "MIT OR Apache-2.0" [package.metadata.embassy_docs] diff --git a/embassy-executor/Cargo.toml b/embassy-executor/Cargo.toml index 3b1c4ab4..d0f51646 100644 --- a/embassy-executor/Cargo.toml +++ b/embassy-executor/Cargo.toml @@ -2,6 +2,7 @@ name = "embassy-executor" version = "0.1.0" edition = "2021" +license = "MIT OR Apache-2.0" [package.metadata.embassy_docs] diff --git a/embassy-hal-common/Cargo.toml b/embassy-hal-common/Cargo.toml index 58f0af6a..e8617c02 100644 --- a/embassy-hal-common/Cargo.toml +++ b/embassy-hal-common/Cargo.toml @@ -2,6 +2,7 @@ name = "embassy-hal-common" version = "0.1.0" edition = "2021" +license = "MIT OR Apache-2.0" [features] diff --git a/embassy-lora/Cargo.toml b/embassy-lora/Cargo.toml index dcb0d824..0e7a982a 100644 --- a/embassy-lora/Cargo.toml +++ b/embassy-lora/Cargo.toml @@ -2,6 +2,7 @@ name = "embassy-lora" version = "0.1.0" edition = "2021" +license = "MIT OR Apache-2.0" [package.metadata.embassy_docs] src_base = "https://github.com/embassy-rs/embassy/blob/embassy-lora-v$VERSION/embassy-lora/src/" diff --git a/embassy-macros/Cargo.toml b/embassy-macros/Cargo.toml index 03fa79dd..91d5ec8a 100644 --- a/embassy-macros/Cargo.toml +++ b/embassy-macros/Cargo.toml @@ -2,6 +2,7 @@ name = "embassy-macros" version = "0.1.0" edition = "2021" +license = "MIT OR Apache-2.0" [dependencies] syn = { version = "1.0.76", features = ["full", "extra-traits"] } diff --git a/embassy-net/Cargo.toml b/embassy-net/Cargo.toml index d5b13204..967ef26a 100644 --- a/embassy-net/Cargo.toml +++ b/embassy-net/Cargo.toml @@ -2,6 +2,7 @@ name = "embassy-net" version = "0.1.0" edition = "2021" +license = "MIT OR Apache-2.0" [package.metadata.embassy_docs] diff --git a/embassy-nrf/Cargo.toml b/embassy-nrf/Cargo.toml index 58b82024..5459bc90 100644 --- a/embassy-nrf/Cargo.toml +++ b/embassy-nrf/Cargo.toml @@ -2,6 +2,7 @@ name = "embassy-nrf" version = "0.1.0" edition = "2021" +license = "MIT OR Apache-2.0" [package.metadata.embassy_docs] src_base = "https://github.com/embassy-rs/embassy/blob/embassy-nrf-v$VERSION/embassy-nrf/src/" diff --git a/embassy-rp/Cargo.toml b/embassy-rp/Cargo.toml index 3aca5dbb..c5685841 100644 --- a/embassy-rp/Cargo.toml +++ b/embassy-rp/Cargo.toml @@ -2,6 +2,7 @@ name = "embassy-rp" version = "0.1.0" edition = "2021" +license = "MIT OR Apache-2.0" [package.metadata.embassy_docs] src_base = "https://github.com/embassy-rs/embassy/blob/embassy-rp-v$VERSION/embassy-rp/src/" diff --git a/embassy-stm32/Cargo.toml b/embassy-stm32/Cargo.toml index fbe37fe3..2610e568 100644 --- a/embassy-stm32/Cargo.toml +++ b/embassy-stm32/Cargo.toml @@ -2,6 +2,7 @@ name = "embassy-stm32" version = "0.1.0" edition = "2021" +license = "MIT OR Apache-2.0" [package.metadata.embassy_docs] src_base = "https://github.com/embassy-rs/embassy/blob/embassy-stm32-v$VERSION/embassy-stm32/src/" diff --git a/embassy-time/Cargo.toml b/embassy-time/Cargo.toml index c3b361b8..c51a71d0 100644 --- a/embassy-time/Cargo.toml +++ b/embassy-time/Cargo.toml @@ -2,6 +2,7 @@ name = "embassy-time" version = "0.1.0" edition = "2021" +license = "MIT OR Apache-2.0" [package.metadata.embassy_docs] diff --git a/embassy-usb-driver/Cargo.toml b/embassy-usb-driver/Cargo.toml index b525df33..d22bf7d7 100644 --- a/embassy-usb-driver/Cargo.toml +++ b/embassy-usb-driver/Cargo.toml @@ -2,6 +2,7 @@ name = "embassy-usb-driver" version = "0.1.0" edition = "2021" +license = "MIT OR Apache-2.0" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html @@ -13,4 +14,4 @@ target = "thumbv7em-none-eabi" [dependencies] defmt = { version = "0.3", optional = true } -log = { version = "0.4.14", optional = true } \ No newline at end of file +log = { version = "0.4.14", optional = true } diff --git a/embassy-usb/Cargo.toml b/embassy-usb/Cargo.toml index 1f705e9f..b59ba8a2 100644 --- a/embassy-usb/Cargo.toml +++ b/embassy-usb/Cargo.toml @@ -2,6 +2,7 @@ name = "embassy-usb" version = "0.1.0" edition = "2021" +license = "MIT OR Apache-2.0" [package.metadata.embassy_docs] src_base = "https://github.com/embassy-rs/embassy/blob/embassy-usb-v$VERSION/embassy-usb/src/" diff --git a/examples/boot/application/nrf/Cargo.toml b/examples/boot/application/nrf/Cargo.toml index b9ff9257..a5d82b60 100644 --- a/examples/boot/application/nrf/Cargo.toml +++ b/examples/boot/application/nrf/Cargo.toml @@ -2,6 +2,7 @@ edition = "2021" name = "embassy-boot-nrf-examples" version = "0.1.0" +license = "MIT OR Apache-2.0" [dependencies] embassy-sync = { version = "0.1.0", path = "../../../../embassy-sync" } diff --git a/examples/boot/application/stm32f3/Cargo.toml b/examples/boot/application/stm32f3/Cargo.toml index ce1e6fe4..3a184356 100644 --- a/examples/boot/application/stm32f3/Cargo.toml +++ b/examples/boot/application/stm32f3/Cargo.toml @@ -2,6 +2,7 @@ edition = "2021" name = "embassy-boot-stm32f3-examples" version = "0.1.0" +license = "MIT OR Apache-2.0" [dependencies] embassy-sync = { version = "0.1.0", path = "../../../../embassy-sync", features = ["defmt"] } diff --git a/examples/boot/application/stm32f7/Cargo.toml b/examples/boot/application/stm32f7/Cargo.toml index 2fc7ae83..8d9c4490 100644 --- a/examples/boot/application/stm32f7/Cargo.toml +++ b/examples/boot/application/stm32f7/Cargo.toml @@ -2,6 +2,7 @@ edition = "2021" name = "embassy-boot-stm32f7-examples" version = "0.1.0" +license = "MIT OR Apache-2.0" [dependencies] embassy-sync = { version = "0.1.0", path = "../../../../embassy-sync", features = ["defmt"] } diff --git a/examples/boot/application/stm32h7/Cargo.toml b/examples/boot/application/stm32h7/Cargo.toml index fd809714..b4314aa7 100644 --- a/examples/boot/application/stm32h7/Cargo.toml +++ b/examples/boot/application/stm32h7/Cargo.toml @@ -2,6 +2,7 @@ edition = "2021" name = "embassy-boot-stm32h7-examples" version = "0.1.0" +license = "MIT OR Apache-2.0" [dependencies] embassy-sync = { version = "0.1.0", path = "../../../../embassy-sync" } diff --git a/examples/boot/application/stm32l0/Cargo.toml b/examples/boot/application/stm32l0/Cargo.toml index 470eca52..a17d336a 100644 --- a/examples/boot/application/stm32l0/Cargo.toml +++ b/examples/boot/application/stm32l0/Cargo.toml @@ -2,6 +2,7 @@ edition = "2021" name = "embassy-boot-stm32l0-examples" version = "0.1.0" +license = "MIT OR Apache-2.0" [dependencies] embassy-sync = { version = "0.1.0", path = "../../../../embassy-sync", features = ["defmt"] } diff --git a/examples/boot/application/stm32l1/Cargo.toml b/examples/boot/application/stm32l1/Cargo.toml index 2b4b2935..683f2c86 100644 --- a/examples/boot/application/stm32l1/Cargo.toml +++ b/examples/boot/application/stm32l1/Cargo.toml @@ -2,6 +2,7 @@ edition = "2021" name = "embassy-boot-stm32l1-examples" version = "0.1.0" +license = "MIT OR Apache-2.0" [dependencies] embassy-sync = { version = "0.1.0", path = "../../../../embassy-sync", features = ["defmt"] } diff --git a/examples/boot/application/stm32l4/Cargo.toml b/examples/boot/application/stm32l4/Cargo.toml index 40bddd19..b879c0d7 100644 --- a/examples/boot/application/stm32l4/Cargo.toml +++ b/examples/boot/application/stm32l4/Cargo.toml @@ -2,6 +2,7 @@ edition = "2021" name = "embassy-boot-stm32l4-examples" version = "0.1.0" +license = "MIT OR Apache-2.0" [dependencies] embassy-sync = { version = "0.1.0", path = "../../../../embassy-sync", features = ["defmt"] } diff --git a/examples/boot/application/stm32wl/Cargo.toml b/examples/boot/application/stm32wl/Cargo.toml index 5b4a61e8..e3bc0e49 100644 --- a/examples/boot/application/stm32wl/Cargo.toml +++ b/examples/boot/application/stm32wl/Cargo.toml @@ -2,6 +2,7 @@ edition = "2021" name = "embassy-boot-stm32wl-examples" version = "0.1.0" +license = "MIT OR Apache-2.0" [dependencies] embassy-sync = { version = "0.1.0", path = "../../../../embassy-sync", features = ["defmt"] } diff --git a/examples/boot/bootloader/nrf/Cargo.toml b/examples/boot/bootloader/nrf/Cargo.toml index aa2a13ec..b417a40d 100644 --- a/examples/boot/bootloader/nrf/Cargo.toml +++ b/examples/boot/bootloader/nrf/Cargo.toml @@ -3,6 +3,7 @@ edition = "2021" name = "nrf-bootloader-example" version = "0.1.0" description = "Bootloader for nRF chips" +license = "MIT OR Apache-2.0" [dependencies] defmt = { version = "0.3", optional = true } diff --git a/examples/boot/bootloader/stm32/Cargo.toml b/examples/boot/bootloader/stm32/Cargo.toml index 49177710..4ddd1c99 100644 --- a/examples/boot/bootloader/stm32/Cargo.toml +++ b/examples/boot/bootloader/stm32/Cargo.toml @@ -3,6 +3,7 @@ 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 } diff --git a/examples/nrf-rtos-trace/Cargo.toml b/examples/nrf-rtos-trace/Cargo.toml index 87c9f33f..d8c24dfa 100644 --- a/examples/nrf-rtos-trace/Cargo.toml +++ b/examples/nrf-rtos-trace/Cargo.toml @@ -2,6 +2,7 @@ edition = "2021" name = "embassy-nrf-rtos-trace-examples" version = "0.1.0" +license = "MIT OR Apache-2.0" [features] default = ["log", "nightly"] diff --git a/examples/nrf/Cargo.toml b/examples/nrf/Cargo.toml index a5d340c6..9ebd0484 100644 --- a/examples/nrf/Cargo.toml +++ b/examples/nrf/Cargo.toml @@ -2,6 +2,7 @@ edition = "2021" name = "embassy-nrf-examples" version = "0.1.0" +license = "MIT OR Apache-2.0" [features] default = ["nightly"] diff --git a/examples/rp/Cargo.toml b/examples/rp/Cargo.toml index 1bb6432e..a5af8b2f 100644 --- a/examples/rp/Cargo.toml +++ b/examples/rp/Cargo.toml @@ -2,6 +2,7 @@ edition = "2021" name = "embassy-rp-examples" version = "0.1.0" +license = "MIT OR Apache-2.0" [dependencies] diff --git a/examples/std/Cargo.toml b/examples/std/Cargo.toml index dbfd9d62..b9bd1e71 100644 --- a/examples/std/Cargo.toml +++ b/examples/std/Cargo.toml @@ -2,6 +2,7 @@ edition = "2021" name = "embassy-std-examples" version = "0.1.0" +license = "MIT OR Apache-2.0" [dependencies] embassy-sync = { version = "0.1.0", path = "../../embassy-sync", features = ["log"] } diff --git a/examples/stm32f0/Cargo.toml b/examples/stm32f0/Cargo.toml index c82b79c8..a56c546e 100644 --- a/examples/stm32f0/Cargo.toml +++ b/examples/stm32f0/Cargo.toml @@ -2,6 +2,7 @@ name = "embassy-stm32f0-examples" version = "0.1.0" edition = "2021" +license = "MIT OR Apache-2.0" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/examples/stm32f1/Cargo.toml b/examples/stm32f1/Cargo.toml index e6553789..6be131f3 100644 --- a/examples/stm32f1/Cargo.toml +++ b/examples/stm32f1/Cargo.toml @@ -2,6 +2,7 @@ edition = "2021" name = "embassy-stm32f1-examples" version = "0.1.0" +license = "MIT OR Apache-2.0" [dependencies] embassy-sync = { version = "0.1.0", path = "../../embassy-sync", features = ["defmt"] } diff --git a/examples/stm32f2/Cargo.toml b/examples/stm32f2/Cargo.toml index 60cd54bd..f6adda2a 100644 --- a/examples/stm32f2/Cargo.toml +++ b/examples/stm32f2/Cargo.toml @@ -2,6 +2,7 @@ edition = "2021" name = "embassy-stm32f2-examples" version = "0.1.0" +license = "MIT OR Apache-2.0" [dependencies] embassy-sync = { version = "0.1.0", path = "../../embassy-sync", features = ["defmt"] } diff --git a/examples/stm32f3/Cargo.toml b/examples/stm32f3/Cargo.toml index f5b0b880..27188dd1 100644 --- a/examples/stm32f3/Cargo.toml +++ b/examples/stm32f3/Cargo.toml @@ -2,6 +2,7 @@ edition = "2021" name = "embassy-stm32f3-examples" version = "0.1.0" +license = "MIT OR Apache-2.0" [dependencies] embassy-sync = { version = "0.1.0", path = "../../embassy-sync", features = ["defmt"] } diff --git a/examples/stm32f4/Cargo.toml b/examples/stm32f4/Cargo.toml index ea5c47a4..6d4f09fb 100644 --- a/examples/stm32f4/Cargo.toml +++ b/examples/stm32f4/Cargo.toml @@ -2,6 +2,7 @@ edition = "2021" name = "embassy-stm32f4-examples" version = "0.1.0" +license = "MIT OR Apache-2.0" [dependencies] diff --git a/examples/stm32f7/Cargo.toml b/examples/stm32f7/Cargo.toml index 6c2f846f..dad92c0f 100644 --- a/examples/stm32f7/Cargo.toml +++ b/examples/stm32f7/Cargo.toml @@ -2,6 +2,7 @@ edition = "2021" name = "embassy-stm32f7-examples" version = "0.1.0" +license = "MIT OR Apache-2.0" [dependencies] embassy-sync = { version = "0.1.0", path = "../../embassy-sync", features = ["defmt"] } diff --git a/examples/stm32g0/Cargo.toml b/examples/stm32g0/Cargo.toml index 6baf17f3..f5673718 100644 --- a/examples/stm32g0/Cargo.toml +++ b/examples/stm32g0/Cargo.toml @@ -2,6 +2,7 @@ edition = "2021" name = "embassy-stm32g0-examples" version = "0.1.0" +license = "MIT OR Apache-2.0" [dependencies] embassy-sync = { version = "0.1.0", path = "../../embassy-sync", features = ["defmt"] } diff --git a/examples/stm32g4/Cargo.toml b/examples/stm32g4/Cargo.toml index d8c05a97..ecda2880 100644 --- a/examples/stm32g4/Cargo.toml +++ b/examples/stm32g4/Cargo.toml @@ -2,6 +2,7 @@ edition = "2021" name = "embassy-stm32g4-examples" version = "0.1.0" +license = "MIT OR Apache-2.0" [dependencies] embassy-sync = { version = "0.1.0", path = "../../embassy-sync", features = ["defmt"] } diff --git a/examples/stm32h7/Cargo.toml b/examples/stm32h7/Cargo.toml index e725e03c..1a05b9ec 100644 --- a/examples/stm32h7/Cargo.toml +++ b/examples/stm32h7/Cargo.toml @@ -2,6 +2,7 @@ edition = "2021" name = "embassy-stm32h7-examples" version = "0.1.0" +license = "MIT OR Apache-2.0" [dependencies] embassy-sync = { version = "0.1.0", path = "../../embassy-sync", features = ["defmt"] } diff --git a/examples/stm32l0/Cargo.toml b/examples/stm32l0/Cargo.toml index 7e61f0c1..7e1120f4 100644 --- a/examples/stm32l0/Cargo.toml +++ b/examples/stm32l0/Cargo.toml @@ -2,6 +2,7 @@ edition = "2021" name = "embassy-stm32l0-examples" version = "0.1.0" +license = "MIT OR Apache-2.0" [features] default = ["nightly"] diff --git a/examples/stm32l1/Cargo.toml b/examples/stm32l1/Cargo.toml index a943c73d..9460febf 100644 --- a/examples/stm32l1/Cargo.toml +++ b/examples/stm32l1/Cargo.toml @@ -2,6 +2,7 @@ edition = "2021" name = "embassy-stm32l1-examples" version = "0.1.0" +license = "MIT OR Apache-2.0" [dependencies] embassy-sync = { version = "0.1.0", path = "../../embassy-sync", features = ["defmt"] } diff --git a/examples/stm32l4/Cargo.toml b/examples/stm32l4/Cargo.toml index 2e2d07dc..657605eb 100644 --- a/examples/stm32l4/Cargo.toml +++ b/examples/stm32l4/Cargo.toml @@ -2,6 +2,7 @@ edition = "2021" name = "embassy-stm32l4-examples" version = "0.1.0" +license = "MIT OR Apache-2.0" [features] diff --git a/examples/stm32l5/Cargo.toml b/examples/stm32l5/Cargo.toml index 9ebab647..63eac3ed 100644 --- a/examples/stm32l5/Cargo.toml +++ b/examples/stm32l5/Cargo.toml @@ -2,6 +2,7 @@ edition = "2021" name = "embassy-stm32l5-examples" version = "0.1.0" +license = "MIT OR Apache-2.0" [features] diff --git a/examples/stm32u5/Cargo.toml b/examples/stm32u5/Cargo.toml index 16494058..3d704011 100644 --- a/examples/stm32u5/Cargo.toml +++ b/examples/stm32u5/Cargo.toml @@ -2,6 +2,7 @@ edition = "2021" name = "embassy-stm32u5-examples" version = "0.1.0" +license = "MIT OR Apache-2.0" [dependencies] embassy-sync = { version = "0.1.0", path = "../../embassy-sync", features = ["defmt"] } diff --git a/examples/stm32wb/Cargo.toml b/examples/stm32wb/Cargo.toml index 923833e4..5b96fa19 100644 --- a/examples/stm32wb/Cargo.toml +++ b/examples/stm32wb/Cargo.toml @@ -2,6 +2,7 @@ edition = "2021" name = "embassy-stm32wb-examples" version = "0.1.0" +license = "MIT OR Apache-2.0" [dependencies] embassy-sync = { version = "0.1.0", path = "../../embassy-sync", features = ["defmt"] } diff --git a/examples/stm32wl/Cargo.toml b/examples/stm32wl/Cargo.toml index 94e0fb83..c827d2b7 100644 --- a/examples/stm32wl/Cargo.toml +++ b/examples/stm32wl/Cargo.toml @@ -2,6 +2,7 @@ edition = "2021" name = "embassy-stm32wl-examples" version = "0.1.0" +license = "MIT OR Apache-2.0" [dependencies] embassy-sync = { version = "0.1.0", path = "../../embassy-sync", features = ["defmt"] } diff --git a/examples/wasm/Cargo.toml b/examples/wasm/Cargo.toml index ea61fb92..e0e799a3 100644 --- a/examples/wasm/Cargo.toml +++ b/examples/wasm/Cargo.toml @@ -2,6 +2,7 @@ edition = "2021" name = "embassy-wasm-example" version = "0.1.0" +license = "MIT OR Apache-2.0" [lib] crate-type = ["cdylib"] diff --git a/stm32-gen-features/Cargo.toml b/stm32-gen-features/Cargo.toml index f92d127e..f4aa08eb 100644 --- a/stm32-gen-features/Cargo.toml +++ b/stm32-gen-features/Cargo.toml @@ -2,6 +2,7 @@ name = "gen_features" version = "0.1.0" edition = "2021" +license = "MIT OR Apache-2.0" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/stm32-metapac-gen/Cargo.toml b/stm32-metapac-gen/Cargo.toml index 0ec2075f..3c1dab57 100644 --- a/stm32-metapac-gen/Cargo.toml +++ b/stm32-metapac-gen/Cargo.toml @@ -2,6 +2,7 @@ name = "stm32-metapac-gen" version = "0.1.0" edition = "2021" +license = "MIT OR Apache-2.0" [dependencies] diff --git a/tests/rp/Cargo.toml b/tests/rp/Cargo.toml index 2745aef0..d6770d6e 100644 --- a/tests/rp/Cargo.toml +++ b/tests/rp/Cargo.toml @@ -2,6 +2,7 @@ edition = "2021" name = "embassy-rp-tests" version = "0.1.0" +license = "MIT OR Apache-2.0" [dependencies] embassy-sync = { version = "0.1.0", path = "../../embassy-sync", features = ["defmt"] } diff --git a/tests/stm32/Cargo.toml b/tests/stm32/Cargo.toml index daae3d46..bebbf557 100644 --- a/tests/stm32/Cargo.toml +++ b/tests/stm32/Cargo.toml @@ -2,6 +2,7 @@ edition = "2021" name = "embassy-stm32-tests" version = "0.1.0" +license = "MIT OR Apache-2.0" [features] stm32f103c8 = ["embassy-stm32/stm32f103c8"] # Blue Pill diff --git a/xtask/Cargo.toml b/xtask/Cargo.toml index d9d6c9b2..696cfdaf 100644 --- a/xtask/Cargo.toml +++ b/xtask/Cargo.toml @@ -2,6 +2,7 @@ edition = "2021" name = "xtask" version = "0.1.0" +license = "MIT OR Apache-2.0" [dependencies] anyhow = "1.0.43" From df7174ecb03f466d4b97f2ce1a11e687317bd93a Mon Sep 17 00:00:00 2001 From: chemicstry Date: Fri, 7 Oct 2022 14:31:55 +0300 Subject: [PATCH 15/17] Fix internal channel reading on adc_v2 --- embassy-stm32/src/adc/mod.rs | 5 ++ embassy-stm32/src/adc/v2.rs | 149 ++++++++++++++++++++++---------- embassy-stm32/src/adc/v4.rs | 8 -- examples/stm32f4/src/bin/adc.rs | 25 +++++- 4 files changed, 130 insertions(+), 57 deletions(-) diff --git a/embassy-stm32/src/adc/mod.rs b/embassy-stm32/src/adc/mod.rs index fba016a7..0eb4eba7 100644 --- a/embassy-stm32/src/adc/mod.rs +++ b/embassy-stm32/src/adc/mod.rs @@ -28,6 +28,10 @@ pub(crate) mod sealed { pub trait AdcPin { fn channel(&self) -> u8; } + + pub trait InternalChannel { + fn channel(&self) -> u8; + } } #[cfg(not(any(adc_f1, adc_v2)))] @@ -37,6 +41,7 @@ pub trait Instance: sealed::Instance + crate::rcc::RccPeripheral + 'static {} #[cfg(all(not(adc_f1), not(adc_v1)))] pub trait Common: sealed::Common + 'static {} pub trait AdcPin: sealed::AdcPin {} +pub trait InternalChannel: sealed::InternalChannel {} #[cfg(not(stm32h7))] foreach_peripheral!( diff --git a/embassy-stm32/src/adc/v2.rs b/embassy-stm32/src/adc/v2.rs index 70e3b73b..4fe4ad1f 100644 --- a/embassy-stm32/src/adc/v2.rs +++ b/embassy-stm32/src/adc/v2.rs @@ -3,7 +3,9 @@ use core::marker::PhantomData; use embassy_hal_common::into_ref; use embedded_hal_02::blocking::delay::DelayUs; +use super::InternalChannel; use crate::adc::{AdcPin, Instance}; +use crate::peripherals::ADC1; use crate::time::Hertz; use crate::Peripheral; @@ -12,6 +14,9 @@ pub const VREF_DEFAULT_MV: u32 = 3300; /// VREF voltage used for factory calibration of VREFINTCAL register. pub const VREF_CALIB_MV: u32 = 3300; +/// ADC turn-on time +pub const ADC_POWERUP_TIME_US: u32 = 3; + pub enum Resolution { TwelveBit, TenBit, @@ -46,24 +51,53 @@ impl Resolution { } pub struct VrefInt; -impl AdcPin for VrefInt {} -impl super::sealed::AdcPin for VrefInt { +impl InternalChannel for VrefInt {} +impl super::sealed::InternalChannel for VrefInt { fn channel(&self) -> u8 { 17 } } +impl VrefInt { + /// Time needed for internal voltage reference to stabilize + pub fn start_time_us() -> u32 { + 10 + } +} + pub struct Temperature; -impl AdcPin for Temperature {} -impl super::sealed::AdcPin for Temperature { +impl InternalChannel for Temperature {} +impl super::sealed::InternalChannel for Temperature { fn channel(&self) -> u8 { - 16 + cfg_if::cfg_if! { + if #[cfg(any(stm32f40, stm32f41))] { + 16 + } else { + 18 + } + } + } +} + +impl Temperature { + /// Converts temperature sensor reading in millivolts to degrees celcius + pub fn to_celcius(sample_mv: u16) -> f32 { + // From 6.3.22 Temperature sensor characteristics + const V25: i32 = 760; // mV + const AVG_SLOPE: f32 = 2.5; // mV/C + + (sample_mv as i32 - V25) as f32 / AVG_SLOPE + 25.0 + } + + /// Time needed for temperature sensor readings to stabilize + pub fn start_time_us() -> u32 { + 10 } } pub struct Vbat; -impl AdcPin for Vbat {} -impl super::sealed::AdcPin for Vbat { +impl InternalChannel for Vbat {} +impl super::sealed::InternalChannel for Vbat { fn channel(&self) -> u8 { 18 } @@ -152,19 +186,16 @@ where T::enable(); T::reset(); - let presc = unsafe { Prescaler::from_pclk2(T::frequency()) }; + let presc = Prescaler::from_pclk2(T::frequency()); unsafe { T::common_regs().ccr().modify(|w| w.set_adcpre(presc.adcpre())); - } - unsafe { - // disable before config is set T::regs().cr2().modify(|reg| { - reg.set_adon(crate::pac::adc::vals::Adon::DISABLED); + reg.set_adon(crate::pac::adc::vals::Adon::ENABLED); }); } - delay.delay_us(20); // TODO? + delay.delay_us(ADC_POWERUP_TIME_US); Self { sample_time: Default::default(), @@ -194,6 +225,45 @@ where ((u32::from(sample) * self.vref_mv) / self.resolution.to_max_count()) as u16 } + /// Enables internal voltage reference and returns [VrefInt], which can be used in + /// [Adc::read_internal()] to perform conversion. + pub fn enable_vrefint(&self) -> VrefInt { + unsafe { + T::common_regs().ccr().modify(|reg| { + reg.set_tsvrefe(crate::pac::adccommon::vals::Tsvrefe::ENABLED); + }); + } + + VrefInt {} + } + + /// Enables internal temperature sensor and returns [Temperature], which can be used in + /// [Adc::read_internal()] to perform conversion. + /// + /// On STM32F42 and STM32F43 this can not be used together with [Vbat]. If both are enabled, + /// temperature sensor will return vbat value. + pub fn enable_temperature(&self) -> Temperature { + unsafe { + T::common_regs().ccr().modify(|reg| { + reg.set_tsvrefe(crate::pac::adccommon::vals::Tsvrefe::ENABLED); + }); + } + + Temperature {} + } + + /// Enables vbat input and returns [Vbat], which can be used in + /// [Adc::read_internal()] to perform conversion. + pub fn enable_vbat(&self) -> Vbat { + unsafe { + T::common_regs().ccr().modify(|reg| { + reg.set_vbate(crate::pac::adccommon::vals::Vbate::ENABLED); + }); + } + + Vbat {} + } + /// Perform a single conversion. fn convert(&mut self) -> u16 { unsafe { @@ -224,44 +294,31 @@ where P: crate::gpio::sealed::Pin, { unsafe { - // dissable ADC - T::regs().cr2().modify(|reg| { - reg.set_swstart(false); - }); - T::regs().cr2().modify(|reg| { - reg.set_adon(crate::pac::adc::vals::Adon::DISABLED); - }); - pin.set_as_analog(); - // Configure ADC - T::regs().cr1().modify(|reg| reg.set_res(self.resolution.res())); - - // Select channel - T::regs().sqr3().write(|reg| reg.set_sq(0, pin.channel())); - - // Configure channel - Self::set_channel_sample_time(pin.channel(), self.sample_time); - - // enable adc - T::regs().cr2().modify(|reg| { - reg.set_adon(crate::pac::adc::vals::Adon::ENABLED); - }); - - let val = self.convert(); - - // dissable ADC - T::regs().cr2().modify(|reg| { - reg.set_swstart(false); - }); - T::regs().cr2().modify(|reg| { - reg.set_adon(crate::pac::adc::vals::Adon::DISABLED); - }); - - val + self.read_channel(pin.channel()) } } + pub fn read_internal(&mut self, channel: &mut impl InternalChannel) -> u16 { + unsafe { self.read_channel(channel.channel()) } + } + + unsafe fn read_channel(&mut self, channel: u8) -> u16 { + // Configure ADC + T::regs().cr1().modify(|reg| reg.set_res(self.resolution.res())); + + // Select channel + T::regs().sqr3().write(|reg| reg.set_sq(0, channel)); + + // Configure channel + Self::set_channel_sample_time(channel, self.sample_time); + + let val = self.convert(); + + val + } + unsafe fn set_channel_sample_time(ch: u8, sample_time: SampleTime) { if ch <= 9 { T::regs() diff --git a/embassy-stm32/src/adc/v4.rs b/embassy-stm32/src/adc/v4.rs index d356d7b6..7e6a219e 100644 --- a/embassy-stm32/src/adc/v4.rs +++ b/embassy-stm32/src/adc/v4.rs @@ -50,14 +50,6 @@ impl Resolution { } } -pub trait InternalChannel: sealed::InternalChannel {} - -mod sealed { - pub trait InternalChannel { - fn channel(&self) -> u8; - } -} - // NOTE: Vrefint/Temperature/Vbat are only available on ADC3 on H7, this currently cannot be modeled with stm32-data, so these are available from the software on all ADCs pub struct VrefInt; impl InternalChannel for VrefInt {} diff --git a/examples/stm32f4/src/bin/adc.rs b/examples/stm32f4/src/bin/adc.rs index 87118507..6f80c1ef 100644 --- a/examples/stm32f4/src/bin/adc.rs +++ b/examples/stm32f4/src/bin/adc.rs @@ -2,9 +2,10 @@ #![no_main] #![feature(type_alias_impl_trait)] +use cortex_m::prelude::_embedded_hal_blocking_delay_DelayUs; use defmt::*; use embassy_executor::Spawner; -use embassy_stm32::adc::Adc; +use embassy_stm32::adc::{Adc, SampleTime, Temperature, VrefInt}; use embassy_time::{Delay, Duration, Timer}; use {defmt_rtt as _, panic_probe as _}; @@ -13,12 +14,30 @@ async fn main(_spawner: Spawner) { let p = embassy_stm32::init(Default::default()); info!("Hello World!"); - let mut adc = Adc::new(p.ADC1, &mut Delay); + let mut delay = Delay; + let mut adc = Adc::new(p.ADC1, &mut delay); let mut pin = p.PC1; + let mut vrefint = adc.enable_vrefint(); + let mut temp = adc.enable_temperature(); + + // Startup delay can be combined to the maximum of either + delay.delay_us(Temperature::start_time_us().max(VrefInt::start_time_us())); + loop { + // Read pin let v = adc.read(&mut pin); - info!("--> {} - {} mV", v, adc.to_millivolts(v)); + info!("PC1: {} ({} mV)", v, adc.to_millivolts(v)); + + // Read internal temperature + let v = adc.read_internal(&mut temp); + let celcius = Temperature::to_celcius(adc.to_millivolts(v)); + info!("Internal temp: {} ({} C)", v, celcius); + + // Read internal voltage reference + let v = adc.read_internal(&mut vrefint); + info!("VrefInt: {} ({} mV)", v, adc.to_millivolts(v)); + Timer::after(Duration::from_millis(100)).await; } } From 322cfafed353ddfbe62121238ef97c56dd7a6eed Mon Sep 17 00:00:00 2001 From: chemicstry Date: Fri, 7 Oct 2022 14:53:03 +0300 Subject: [PATCH 16/17] Fix adc_v4 compilation --- embassy-stm32/src/adc/v4.rs | 8 ++++---- examples/stm32f4/src/bin/adc.rs | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/embassy-stm32/src/adc/v4.rs b/embassy-stm32/src/adc/v4.rs index 7e6a219e..eda2b2a7 100644 --- a/embassy-stm32/src/adc/v4.rs +++ b/embassy-stm32/src/adc/v4.rs @@ -5,7 +5,7 @@ use embedded_hal_02::blocking::delay::DelayUs; use pac::adc::vals::{Adcaldif, Boost, Difsel, Exten, Pcsel}; use pac::adccommon::vals::Presc; -use super::{AdcPin, Instance}; +use super::{AdcPin, Instance, InternalChannel}; use crate::time::Hertz; use crate::{pac, Peripheral}; @@ -53,7 +53,7 @@ impl Resolution { // NOTE: Vrefint/Temperature/Vbat are only available on ADC3 on H7, this currently cannot be modeled with stm32-data, so these are available from the software on all ADCs pub struct VrefInt; impl InternalChannel for VrefInt {} -impl sealed::InternalChannel for VrefInt { +impl super::sealed::InternalChannel for VrefInt { fn channel(&self) -> u8 { 19 } @@ -61,7 +61,7 @@ impl sealed::InternalChannel for VrefInt { pub struct Temperature; impl InternalChannel for Temperature {} -impl sealed::InternalChannel for Temperature { +impl super::sealed::InternalChannel for Temperature { fn channel(&self) -> u8 { 18 } @@ -69,7 +69,7 @@ impl sealed::InternalChannel for Temperature { pub struct Vbat; impl InternalChannel for Vbat {} -impl sealed::InternalChannel for Vbat { +impl super::sealed::InternalChannel for Vbat { fn channel(&self) -> u8 { // TODO this should be 14 for H7a/b/35 17 diff --git a/examples/stm32f4/src/bin/adc.rs b/examples/stm32f4/src/bin/adc.rs index 6f80c1ef..1d030f7d 100644 --- a/examples/stm32f4/src/bin/adc.rs +++ b/examples/stm32f4/src/bin/adc.rs @@ -5,7 +5,7 @@ use cortex_m::prelude::_embedded_hal_blocking_delay_DelayUs; use defmt::*; use embassy_executor::Spawner; -use embassy_stm32::adc::{Adc, SampleTime, Temperature, VrefInt}; +use embassy_stm32::adc::{Adc, Temperature, VrefInt}; use embassy_time::{Delay, Duration, Timer}; use {defmt_rtt as _, panic_probe as _}; From aa8ba2115c4606b53dedce1af2da5de2fd59f563 Mon Sep 17 00:00:00 2001 From: Matt Johnston Date: Sat, 8 Oct 2022 11:35:11 +0800 Subject: [PATCH 17/17] Expose Pin::pin() and Pin::bank() as public --- embassy-rp/src/gpio.rs | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/embassy-rp/src/gpio.rs b/embassy-rp/src/gpio.rs index a28bae96..f79f592b 100644 --- a/embassy-rp/src/gpio.rs +++ b/embassy-rp/src/gpio.rs @@ -599,12 +599,12 @@ pub(crate) mod sealed { fn pin_bank(&self) -> u8; #[inline] - fn pin(&self) -> u8 { + fn _pin(&self) -> u8 { self.pin_bank() & 0x1f } #[inline] - fn bank(&self) -> Bank { + fn _bank(&self) -> Bank { if self.pin_bank() & 0x20 == 0 { Bank::Bank0 } else { @@ -613,35 +613,35 @@ pub(crate) mod sealed { } fn io(&self) -> pac::io::Gpio { - let block = match self.bank() { + let block = match self._bank() { Bank::Bank0 => crate::pac::IO_BANK0, Bank::Qspi => crate::pac::IO_QSPI, }; - block.gpio(self.pin() as _) + block.gpio(self._pin() as _) } fn pad_ctrl(&self) -> Reg { - let block = match self.bank() { + let block = match self._bank() { Bank::Bank0 => crate::pac::PADS_BANK0, Bank::Qspi => crate::pac::PADS_QSPI, }; - block.gpio(self.pin() as _) + block.gpio(self._pin() as _) } fn sio_out(&self) -> pac::sio::Gpio { - SIO.gpio_out(self.bank() as _) + SIO.gpio_out(self._bank() as _) } fn sio_oe(&self) -> pac::sio::Gpio { - SIO.gpio_oe(self.bank() as _) + SIO.gpio_oe(self._bank() as _) } fn sio_in(&self) -> Reg { - SIO.gpio_in(self.bank() as _) + SIO.gpio_in(self._bank() as _) } fn int_proc(&self) -> pac::io::Int { - let io_block = match self.bank() { + let io_block = match self._bank() { Bank::Bank0 => crate::pac::IO_BANK0, Bank::Qspi => crate::pac::IO_QSPI, }; @@ -658,6 +658,18 @@ pub trait Pin: Peripheral

+ Into + sealed::Pin + Sized + 'stat pin_bank: self.pin_bank(), } } + + /// Returns the pin number within a bank + #[inline] + fn pin(&self) -> u8 { + self._pin() + } + + /// Returns the bank of this pin + #[inline] + fn bank(&self) -> Bank { + self._bank() + } } pub struct AnyPin {