diff options
| author | Badr Bouslikhin <[email protected]> | 2024-09-06 18:56:11 +0200 |
|---|---|---|
| committer | GitHub <[email protected]> | 2024-09-06 18:56:11 +0200 |
| commit | 94f109aec117699f86aa9915e72c0b275cf3cc4a (patch) | |
| tree | 58c78f13440beb85fa37fcecc5f26be7a43ce369 | |
| parent | 0e477a4df506981e770e41edec31e2bc0cd6b6c6 (diff) | |
| parent | 1cf778904d597a5bc01a4b7862f965681636faf1 (diff) | |
Merge branch 'embassy-rs:main' into buffered-uart-rx-fix
| -rwxr-xr-x | .github/ci/test.sh | 4 | ||||
| -rwxr-xr-x | ci.sh | 1 | ||||
| -rw-r--r-- | embassy-boot/Cargo.toml | 4 | ||||
| -rw-r--r-- | embassy-executor/Cargo.toml | 2 | ||||
| -rw-r--r-- | embassy-executor/src/lib.rs | 1 | ||||
| -rw-r--r-- | embassy-executor/src/raw/waker.rs | 3 | ||||
| -rw-r--r-- | embassy-usb-logger/src/lib.rs | 53 | ||||
| -rw-r--r-- | examples/nrf52840/src/bin/channel.rs | 4 | ||||
| -rw-r--r-- | examples/nrf52840/src/bin/channel_sender_receiver.rs | 4 | ||||
| -rw-r--r-- | examples/wasm/Cargo.toml | 1 | ||||
| -rw-r--r-- | rust-toolchain-nightly.toml | 2 |
11 files changed, 64 insertions, 15 deletions
diff --git a/.github/ci/test.sh b/.github/ci/test.sh index da0021684..0de265049 100755 --- a/.github/ci/test.sh +++ b/.github/ci/test.sh | |||
| @@ -8,6 +8,10 @@ export RUSTUP_HOME=/ci/cache/rustup | |||
| 8 | export CARGO_HOME=/ci/cache/cargo | 8 | export CARGO_HOME=/ci/cache/cargo |
| 9 | export CARGO_TARGET_DIR=/ci/cache/target | 9 | export CARGO_TARGET_DIR=/ci/cache/target |
| 10 | 10 | ||
| 11 | # needed for "dumb HTTP" transport support | ||
| 12 | # used when pointing stm32-metapac to a CI-built one. | ||
| 13 | export CARGO_NET_GIT_FETCH_WITH_CLI=true | ||
| 14 | |||
| 11 | cargo test --manifest-path ./embassy-futures/Cargo.toml | 15 | cargo test --manifest-path ./embassy-futures/Cargo.toml |
| 12 | cargo test --manifest-path ./embassy-sync/Cargo.toml | 16 | cargo test --manifest-path ./embassy-sync/Cargo.toml |
| 13 | cargo test --manifest-path ./embassy-embedded-hal/Cargo.toml | 17 | cargo test --manifest-path ./embassy-embedded-hal/Cargo.toml |
| @@ -305,6 +305,7 @@ rm out/tests/stm32u5a5zj/usart | |||
| 305 | # flaky, probably due to bad ringbuffered dma code. | 305 | # flaky, probably due to bad ringbuffered dma code. |
| 306 | rm out/tests/stm32l152re/usart_rx_ringbuffered | 306 | rm out/tests/stm32l152re/usart_rx_ringbuffered |
| 307 | rm out/tests/stm32f207zg/usart_rx_ringbuffered | 307 | rm out/tests/stm32f207zg/usart_rx_ringbuffered |
| 308 | rm out/tests/stm32wl55jc/usart_rx_ringbuffered | ||
| 308 | 309 | ||
| 309 | if [[ -z "${TELEPROBE_TOKEN-}" ]]; then | 310 | if [[ -z "${TELEPROBE_TOKEN-}" ]]; then |
| 310 | echo No teleprobe token found, skipping running HIL tests | 311 | echo No teleprobe token found, skipping running HIL tests |
diff --git a/embassy-boot/Cargo.toml b/embassy-boot/Cargo.toml index 85b3695a1..d27fe763e 100644 --- a/embassy-boot/Cargo.toml +++ b/embassy-boot/Cargo.toml | |||
| @@ -27,7 +27,7 @@ features = ["defmt"] | |||
| 27 | defmt = { version = "0.3", optional = true } | 27 | defmt = { version = "0.3", optional = true } |
| 28 | digest = "0.10" | 28 | digest = "0.10" |
| 29 | log = { version = "0.4", optional = true } | 29 | log = { version = "0.4", optional = true } |
| 30 | ed25519-dalek = { version = "2", default_features = false, features = ["digest"], optional = true } | 30 | ed25519-dalek = { version = "2", default-features = false, features = ["digest"], optional = true } |
| 31 | embassy-embedded-hal = { version = "0.2.0", path = "../embassy-embedded-hal" } | 31 | embassy-embedded-hal = { version = "0.2.0", path = "../embassy-embedded-hal" } |
| 32 | embassy-sync = { version = "0.6.0", path = "../embassy-sync" } | 32 | embassy-sync = { version = "0.6.0", path = "../embassy-sync" } |
| 33 | embedded-storage = "0.3.1" | 33 | embedded-storage = "0.3.1" |
| @@ -42,7 +42,7 @@ rand = "0.8" | |||
| 42 | futures = { version = "0.3", features = ["executor"] } | 42 | futures = { version = "0.3", features = ["executor"] } |
| 43 | sha1 = "0.10.5" | 43 | sha1 = "0.10.5" |
| 44 | critical-section = { version = "1.1.1", features = ["std"] } | 44 | critical-section = { version = "1.1.1", features = ["std"] } |
| 45 | ed25519-dalek = { version = "2", default_features = false, features = ["std", "rand_core", "digest"] } | 45 | ed25519-dalek = { version = "2", default-features = false, features = ["std", "rand_core", "digest"] } |
| 46 | 46 | ||
| 47 | [features] | 47 | [features] |
| 48 | ed25519-dalek = ["dep:ed25519-dalek", "_verify"] | 48 | ed25519-dalek = ["dep:ed25519-dalek", "_verify"] |
diff --git a/embassy-executor/Cargo.toml b/embassy-executor/Cargo.toml index 5984cc49c..01fa28b88 100644 --- a/embassy-executor/Cargo.toml +++ b/embassy-executor/Cargo.toml | |||
| @@ -79,7 +79,7 @@ arch-cortex-m = ["_arch", "dep:cortex-m"] | |||
| 79 | ## RISC-V 32 | 79 | ## RISC-V 32 |
| 80 | arch-riscv32 = ["_arch"] | 80 | arch-riscv32 = ["_arch"] |
| 81 | ## WASM | 81 | ## WASM |
| 82 | arch-wasm = ["_arch", "dep:wasm-bindgen", "dep:js-sys"] | 82 | arch-wasm = ["_arch", "dep:wasm-bindgen", "dep:js-sys", "critical-section/std"] |
| 83 | ## AVR | 83 | ## AVR |
| 84 | arch-avr = ["_arch", "dep:portable-atomic", "dep:avr-device"] | 84 | arch-avr = ["_arch", "dep:portable-atomic", "dep:avr-device"] |
| 85 | 85 | ||
diff --git a/embassy-executor/src/lib.rs b/embassy-executor/src/lib.rs index 553ed76d3..6a2e493a2 100644 --- a/embassy-executor/src/lib.rs +++ b/embassy-executor/src/lib.rs | |||
| @@ -1,5 +1,4 @@ | |||
| 1 | #![cfg_attr(not(any(feature = "arch-std", feature = "arch-wasm")), no_std)] | 1 | #![cfg_attr(not(any(feature = "arch-std", feature = "arch-wasm")), no_std)] |
| 2 | #![cfg_attr(feature = "nightly", feature(waker_getters))] | ||
| 3 | #![allow(clippy::new_without_default)] | 2 | #![allow(clippy::new_without_default)] |
| 4 | #![doc = include_str!("../README.md")] | 3 | #![doc = include_str!("../README.md")] |
| 5 | #![warn(missing_docs)] | 4 | #![warn(missing_docs)] |
diff --git a/embassy-executor/src/raw/waker.rs b/embassy-executor/src/raw/waker.rs index 8d3910a25..8bb2cfd05 100644 --- a/embassy-executor/src/raw/waker.rs +++ b/embassy-executor/src/raw/waker.rs | |||
| @@ -50,8 +50,7 @@ pub fn task_from_waker(waker: &Waker) -> TaskRef { | |||
| 50 | 50 | ||
| 51 | #[cfg(feature = "nightly")] | 51 | #[cfg(feature = "nightly")] |
| 52 | { | 52 | { |
| 53 | let raw_waker = waker.as_raw(); | 53 | (waker.vtable(), waker.data()) |
| 54 | (raw_waker.vtable(), raw_waker.data()) | ||
| 55 | } | 54 | } |
| 56 | }; | 55 | }; |
| 57 | 56 | ||
diff --git a/embassy-usb-logger/src/lib.rs b/embassy-usb-logger/src/lib.rs index 34d1ca663..11188b4ef 100644 --- a/embassy-usb-logger/src/lib.rs +++ b/embassy-usb-logger/src/lib.rs | |||
| @@ -41,12 +41,24 @@ pub const MAX_PACKET_SIZE: u8 = 64; | |||
| 41 | /// The logger handle, which contains a pipe with configurable size for buffering log messages. | 41 | /// The logger handle, which contains a pipe with configurable size for buffering log messages. |
| 42 | pub struct UsbLogger<const N: usize> { | 42 | pub struct UsbLogger<const N: usize> { |
| 43 | buffer: Pipe<CS, N>, | 43 | buffer: Pipe<CS, N>, |
| 44 | custom_style: Option<fn(&Record, &mut Writer<'_, N>) -> ()>, | ||
| 44 | } | 45 | } |
| 45 | 46 | ||
| 46 | impl<const N: usize> UsbLogger<N> { | 47 | impl<const N: usize> UsbLogger<N> { |
| 47 | /// Create a new logger instance. | 48 | /// Create a new logger instance. |
| 48 | pub const fn new() -> Self { | 49 | pub const fn new() -> Self { |
| 49 | Self { buffer: Pipe::new() } | 50 | Self { |
| 51 | buffer: Pipe::new(), | ||
| 52 | custom_style: None, | ||
| 53 | } | ||
| 54 | } | ||
| 55 | |||
| 56 | /// Create a new logger instance with a custom formatter. | ||
| 57 | pub const fn with_custom_style(custom_style: fn(&Record, &mut Writer<'_, N>) -> ()) -> Self { | ||
| 58 | Self { | ||
| 59 | buffer: Pipe::new(), | ||
| 60 | custom_style: Some(custom_style), | ||
| 61 | } | ||
| 50 | } | 62 | } |
| 51 | 63 | ||
| 52 | /// Run the USB logger using the state and USB driver. Never returns. | 64 | /// Run the USB logger using the state and USB driver. Never returns. |
| @@ -137,14 +149,19 @@ impl<const N: usize> log::Log for UsbLogger<N> { | |||
| 137 | 149 | ||
| 138 | fn log(&self, record: &Record) { | 150 | fn log(&self, record: &Record) { |
| 139 | if self.enabled(record.metadata()) { | 151 | if self.enabled(record.metadata()) { |
| 140 | let _ = write!(Writer(&self.buffer), "{}\r\n", record.args()); | 152 | if let Some(custom_style) = self.custom_style { |
| 153 | custom_style(record, &mut Writer(&self.buffer)); | ||
| 154 | } else { | ||
| 155 | let _ = write!(Writer(&self.buffer), "{}\r\n", record.args()); | ||
| 156 | } | ||
| 141 | } | 157 | } |
| 142 | } | 158 | } |
| 143 | 159 | ||
| 144 | fn flush(&self) {} | 160 | fn flush(&self) {} |
| 145 | } | 161 | } |
| 146 | 162 | ||
| 147 | struct Writer<'d, const N: usize>(&'d Pipe<CS, N>); | 163 | /// A writer that writes to the USB logger buffer. |
| 164 | pub struct Writer<'d, const N: usize>(&'d Pipe<CS, N>); | ||
| 148 | 165 | ||
| 149 | impl<'d, const N: usize> core::fmt::Write for Writer<'d, N> { | 166 | impl<'d, const N: usize> core::fmt::Write for Writer<'d, N> { |
| 150 | fn write_str(&mut self, s: &str) -> Result<(), core::fmt::Error> { | 167 | fn write_str(&mut self, s: &str) -> Result<(), core::fmt::Error> { |
| @@ -210,3 +227,33 @@ macro_rules! with_class { | |||
| 210 | LOGGER.create_future_from_class($p) | 227 | LOGGER.create_future_from_class($p) |
| 211 | }}; | 228 | }}; |
| 212 | } | 229 | } |
| 230 | |||
| 231 | /// Initialize the USB serial logger from a serial class and return the future to run it. | ||
| 232 | /// This version of the macro allows for a custom style function to be passed in. | ||
| 233 | /// The custom style function will be called for each log record and is responsible for writing the log message to the buffer. | ||
| 234 | /// | ||
| 235 | /// Arguments specify the buffer size, log level, the serial class and the custom style function, respectively. | ||
| 236 | /// | ||
| 237 | /// # Usage | ||
| 238 | /// | ||
| 239 | /// ``` | ||
| 240 | /// let log_fut = embassy_usb_logger::with_custom_style!(1024, log::LevelFilter::Info, logger_class, |record, writer| { | ||
| 241 | /// use core::fmt::Write; | ||
| 242 | /// let level = record.level().as_str(); | ||
| 243 | /// write!(writer, "[{level}] {}\r\n", record.args()).unwrap(); | ||
| 244 | /// }); | ||
| 245 | /// ``` | ||
| 246 | /// | ||
| 247 | /// # Safety | ||
| 248 | /// | ||
| 249 | /// This macro should only be invoked only once since it is setting the global logging state of the application. | ||
| 250 | #[macro_export] | ||
| 251 | macro_rules! with_custom_style { | ||
| 252 | ( $x:expr, $l:expr, $p:ident, $s:expr ) => {{ | ||
| 253 | static LOGGER: ::embassy_usb_logger::UsbLogger<$x> = ::embassy_usb_logger::UsbLogger::with_custom_style($s); | ||
| 254 | unsafe { | ||
| 255 | let _ = ::log::set_logger_racy(&LOGGER).map(|()| log::set_max_level_racy($l)); | ||
| 256 | } | ||
| 257 | LOGGER.create_future_from_class($p) | ||
| 258 | }}; | ||
| 259 | } | ||
diff --git a/examples/nrf52840/src/bin/channel.rs b/examples/nrf52840/src/bin/channel.rs index 7fcea9dbd..e06ba1c73 100644 --- a/examples/nrf52840/src/bin/channel.rs +++ b/examples/nrf52840/src/bin/channel.rs | |||
| @@ -35,8 +35,8 @@ async fn main(spawner: Spawner) { | |||
| 35 | 35 | ||
| 36 | loop { | 36 | loop { |
| 37 | match CHANNEL.receive().await { | 37 | match CHANNEL.receive().await { |
| 38 | LedState::On => led.set_high(), | 38 | LedState::On => led.set_low(), |
| 39 | LedState::Off => led.set_low(), | 39 | LedState::Off => led.set_high(), |
| 40 | } | 40 | } |
| 41 | } | 41 | } |
| 42 | } | 42 | } |
diff --git a/examples/nrf52840/src/bin/channel_sender_receiver.rs b/examples/nrf52840/src/bin/channel_sender_receiver.rs index 3095a04ec..29f70f91c 100644 --- a/examples/nrf52840/src/bin/channel_sender_receiver.rs +++ b/examples/nrf52840/src/bin/channel_sender_receiver.rs | |||
| @@ -33,8 +33,8 @@ async fn recv_task(led: AnyPin, receiver: Receiver<'static, NoopRawMutex, LedSta | |||
| 33 | 33 | ||
| 34 | loop { | 34 | loop { |
| 35 | match receiver.receive().await { | 35 | match receiver.receive().await { |
| 36 | LedState::On => led.set_high(), | 36 | LedState::On => led.set_low(), |
| 37 | LedState::Off => led.set_low(), | 37 | LedState::Off => led.set_high(), |
| 38 | } | 38 | } |
| 39 | } | 39 | } |
| 40 | } | 40 | } |
diff --git a/examples/wasm/Cargo.toml b/examples/wasm/Cargo.toml index 9bd37550c..75de079b7 100644 --- a/examples/wasm/Cargo.toml +++ b/examples/wasm/Cargo.toml | |||
| @@ -16,7 +16,6 @@ wasm-logger = "0.2.0" | |||
| 16 | wasm-bindgen = "0.2" | 16 | wasm-bindgen = "0.2" |
| 17 | web-sys = { version = "0.3", features = ["Document", "Element", "HtmlElement", "Node", "Window" ] } | 17 | web-sys = { version = "0.3", features = ["Document", "Element", "HtmlElement", "Node", "Window" ] } |
| 18 | log = "0.4.11" | 18 | log = "0.4.11" |
| 19 | critical-section = { version = "1.1", features = ["std"] } | ||
| 20 | 19 | ||
| 21 | [profile.release] | 20 | [profile.release] |
| 22 | debug = 2 | 21 | debug = 2 |
diff --git a/rust-toolchain-nightly.toml b/rust-toolchain-nightly.toml index dfa231344..0b10d7194 100644 --- a/rust-toolchain-nightly.toml +++ b/rust-toolchain-nightly.toml | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | [toolchain] | 1 | [toolchain] |
| 2 | channel = "nightly-2024-07-16" | 2 | channel = "nightly-2024-09-06" |
| 3 | components = [ "rust-src", "rustfmt", "llvm-tools", "miri" ] | 3 | components = [ "rust-src", "rustfmt", "llvm-tools", "miri" ] |
| 4 | targets = [ | 4 | targets = [ |
| 5 | "thumbv7em-none-eabi", | 5 | "thumbv7em-none-eabi", |
