From 0c66636d003979c3aecff36c9e03e87f34147a94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1niel=20Buga?= Date: Sat, 2 Sep 2023 07:44:10 +0200 Subject: [PATCH 1/2] Use fmt::unwrap --- embassy-net/src/device.rs | 4 ++-- embassy-net/src/lib.rs | 14 +++++++------- embassy-net/src/tcp.rs | 4 ++-- embassy-sync/src/channel.rs | 2 +- embassy-sync/src/mutex.rs | 2 +- embassy-time/src/instant.rs | 2 +- 6 files changed, 14 insertions(+), 14 deletions(-) diff --git a/embassy-net/src/device.rs b/embassy-net/src/device.rs index d29ab8970..8c2b7d31a 100644 --- a/embassy-net/src/device.rs +++ b/embassy-net/src/device.rs @@ -22,13 +22,13 @@ where fn receive(&mut self, _timestamp: Instant) -> Option<(Self::RxToken<'_>, Self::TxToken<'_>)> { self.inner - .receive(self.cx.as_deref_mut().unwrap()) + .receive(unwrap!(self.cx.as_deref_mut())) .map(|(rx, tx)| (RxTokenAdapter(rx), TxTokenAdapter(tx))) } /// Construct a transmit token. fn transmit(&mut self, _timestamp: Instant) -> Option> { - self.inner.transmit(self.cx.as_deref_mut().unwrap()).map(TxTokenAdapter) + self.inner.transmit(unwrap!(self.cx.as_deref_mut())).map(TxTokenAdapter) } /// Get a description of device capabilities. diff --git a/embassy-net/src/lib.rs b/embassy-net/src/lib.rs index 3a385fad6..c2575267c 100644 --- a/embassy-net/src/lib.rs +++ b/embassy-net/src/lib.rs @@ -616,7 +616,7 @@ impl Inner { } // Configure it - let socket = _s.sockets.get_mut::(self.dhcp_socket.unwrap()); + let socket = _s.sockets.get_mut::(unwrap!(self.dhcp_socket)); socket.set_ignore_naks(c.ignore_naks); socket.set_max_lease_duration(c.max_lease_duration.map(crate::time::duration_to_smoltcp)); socket.set_ports(c.server_port, c.client_port); @@ -656,12 +656,12 @@ impl Inner { debug!(" IP address: {:?}", config.address); debug!(" Default gateway: {:?}", config.gateway); - addrs.push(IpCidr::Ipv4(config.address)).unwrap(); + unwrap!(addrs.push(IpCidr::Ipv4(config.address)).ok()); gateway_v4 = config.gateway.into(); #[cfg(feature = "dns")] for s in &config.dns_servers { debug!(" DNS server: {:?}", s); - dns_servers.push(s.clone().into()).unwrap(); + unwrap!(dns_servers.push(s.clone().into()).ok()); } } else { info!("IPv4: DOWN"); @@ -673,12 +673,12 @@ impl Inner { debug!(" IP address: {:?}", config.address); debug!(" Default gateway: {:?}", config.gateway); - addrs.push(IpCidr::Ipv6(config.address)).unwrap(); + unwrap!(addrs.push(IpCidr::Ipv6(config.address)).ok()); gateway_v6 = config.gateway.into(); #[cfg(feature = "dns")] for s in &config.dns_servers { debug!(" DNS server: {:?}", s); - dns_servers.push(s.clone().into()).unwrap(); + unwrap!(dns_servers.push(s.clone().into()).ok()); } } else { info!("IPv6: DOWN"); @@ -690,13 +690,13 @@ impl Inner { // Apply gateways #[cfg(feature = "proto-ipv4")] if let Some(gateway) = gateway_v4 { - s.iface.routes_mut().add_default_ipv4_route(gateway).unwrap(); + unwrap!(s.iface.routes_mut().add_default_ipv4_route(gateway)); } else { s.iface.routes_mut().remove_default_ipv4_route(); } #[cfg(feature = "proto-ipv6")] if let Some(gateway) = gateway_v6 { - s.iface.routes_mut().add_default_ipv6_route(gateway).unwrap(); + unwrap!(s.iface.routes_mut().add_default_ipv6_route(gateway)); } else { s.iface.routes_mut().remove_default_ipv6_route(); } diff --git a/embassy-net/src/tcp.rs b/embassy-net/src/tcp.rs index c92ad2d2e..a12fd382a 100644 --- a/embassy-net/src/tcp.rs +++ b/embassy-net/src/tcp.rs @@ -440,7 +440,7 @@ impl<'d> TcpIo<'d> { Poll::Ready(Err(Error::ConnectionReset)) } } else { - Poll::Ready(match s.send(f.take().unwrap()) { + Poll::Ready(match s.send(unwrap!(f.take())) { // Connection reset. TODO: this can also be timeouts etc, investigate. Err(tcp::SendError::InvalidState) => Err(Error::ConnectionReset), Ok(r) => Ok(r), @@ -468,7 +468,7 @@ impl<'d> TcpIo<'d> { Poll::Ready(Err(Error::ConnectionReset)) } } else { - Poll::Ready(match s.recv(f.take().unwrap()) { + Poll::Ready(match s.recv(unwrap!(f.take())) { // Connection reset. TODO: this can also be timeouts etc, investigate. Err(tcp::RecvError::Finished) | Err(tcp::RecvError::InvalidState) => { Err(Error::ConnectionReset) diff --git a/embassy-sync/src/channel.rs b/embassy-sync/src/channel.rs index 62ea1307d..a512e0c41 100644 --- a/embassy-sync/src/channel.rs +++ b/embassy-sync/src/channel.rs @@ -471,7 +471,7 @@ where } fn lock(&self, f: impl FnOnce(&mut ChannelState) -> R) -> R { - self.inner.lock(|rc| f(&mut *rc.borrow_mut())) + self.inner.lock(|rc| f(&mut *unwrap!(rc.try_borrow_mut()))) } fn try_receive_with_context(&self, cx: Option<&mut Context<'_>>) -> Result { diff --git a/embassy-sync/src/mutex.rs b/embassy-sync/src/mutex.rs index fcf056d36..72459d660 100644 --- a/embassy-sync/src/mutex.rs +++ b/embassy-sync/src/mutex.rs @@ -149,7 +149,7 @@ where { fn drop(&mut self) { self.mutex.state.lock(|s| { - let mut s = s.borrow_mut(); + let mut s = unwrap!(s.try_borrow_mut()); s.locked = false; s.waker.wake(); }) diff --git a/embassy-time/src/instant.rs b/embassy-time/src/instant.rs index 44f226f62..5571cdd15 100644 --- a/embassy-time/src/instant.rs +++ b/embassy-time/src/instant.rs @@ -71,7 +71,7 @@ impl Instant { /// Panics on over/underflow. pub fn duration_since(&self, earlier: Instant) -> Duration { Duration { - ticks: self.ticks.checked_sub(earlier.ticks).unwrap(), + ticks: unwrap!(self.ticks.checked_sub(earlier.ticks)), } } From 360286e67c355d23a355f83bbb6586b3fa3b3a7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1niel=20Buga?= Date: Sat, 2 Sep 2023 08:50:03 +0200 Subject: [PATCH 2/2] Fix bootloader application examples --- examples/boot/application/rp/Cargo.toml | 1 + examples/boot/application/stm32f3/Cargo.toml | 3 ++- examples/boot/application/stm32f7/Cargo.toml | 3 ++- examples/boot/application/stm32h7/Cargo.toml | 1 + examples/boot/application/stm32l0/Cargo.toml | 3 ++- examples/boot/application/stm32l1/Cargo.toml | 3 ++- examples/boot/application/stm32l4/Cargo.toml | 3 ++- examples/boot/application/stm32wl/Cargo.toml | 3 ++- examples/boot/bootloader/nrf/Cargo.toml | 2 +- examples/boot/bootloader/stm32/Cargo.toml | 2 +- 10 files changed, 16 insertions(+), 8 deletions(-) diff --git a/examples/boot/application/rp/Cargo.toml b/examples/boot/application/rp/Cargo.toml index be85f4437..23cce9593 100644 --- a/examples/boot/application/rp/Cargo.toml +++ b/examples/boot/application/rp/Cargo.toml @@ -27,6 +27,7 @@ default = ["panic-reset"] debug = [ "embassy-rp/defmt", "embassy-boot-rp/defmt", + "embassy-sync/defmt", "panic-probe" ] skip-include = [] diff --git a/examples/boot/application/stm32f3/Cargo.toml b/examples/boot/application/stm32f3/Cargo.toml index ea8789332..31ea46d9b 100644 --- a/examples/boot/application/stm32f3/Cargo.toml +++ b/examples/boot/application/stm32f3/Cargo.toml @@ -5,7 +5,7 @@ version = "0.1.0" license = "MIT OR Apache-2.0" [dependencies] -embassy-sync = { version = "0.2.0", path = "../../../../embassy-sync", features = ["defmt"] } +embassy-sync = { version = "0.2.0", path = "../../../../embassy-sync" } embassy-executor = { version = "0.3.0", path = "../../../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "nightly", "integrated-timers"] } embassy-time = { version = "0.1.2", path = "../../../../embassy-time", features = ["nightly", "tick-hz-32_768"] } embassy-stm32 = { version = "0.1.0", path = "../../../../embassy-stm32", features = ["unstable-traits", "nightly", "stm32f303re", "time-driver-any", "exti"] } @@ -25,5 +25,6 @@ defmt = [ "dep:defmt", "embassy-stm32/defmt", "embassy-boot-stm32/defmt", + "embassy-sync/defmt", ] skip-include = [] diff --git a/examples/boot/application/stm32f7/Cargo.toml b/examples/boot/application/stm32f7/Cargo.toml index b39bc2922..46f709cb8 100644 --- a/examples/boot/application/stm32f7/Cargo.toml +++ b/examples/boot/application/stm32f7/Cargo.toml @@ -5,7 +5,7 @@ version = "0.1.0" license = "MIT OR Apache-2.0" [dependencies] -embassy-sync = { version = "0.2.0", path = "../../../../embassy-sync", features = ["defmt"] } +embassy-sync = { version = "0.2.0", path = "../../../../embassy-sync" } embassy-executor = { version = "0.3.0", path = "../../../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "nightly", "integrated-timers"] } embassy-time = { version = "0.1.2", path = "../../../../embassy-time", features = ["nightly", "tick-hz-32_768"] } embassy-stm32 = { version = "0.1.0", path = "../../../../embassy-stm32", features = ["unstable-traits", "nightly", "stm32f767zi", "time-driver-any", "exti"] } @@ -26,5 +26,6 @@ defmt = [ "dep:defmt", "embassy-stm32/defmt", "embassy-boot-stm32/defmt", + "embassy-sync/defmt", ] skip-include = [] diff --git a/examples/boot/application/stm32h7/Cargo.toml b/examples/boot/application/stm32h7/Cargo.toml index f015b2cae..49743b9c3 100644 --- a/examples/boot/application/stm32h7/Cargo.toml +++ b/examples/boot/application/stm32h7/Cargo.toml @@ -26,5 +26,6 @@ defmt = [ "dep:defmt", "embassy-stm32/defmt", "embassy-boot-stm32/defmt", + "embassy-sync/defmt", ] skip-include = [] diff --git a/examples/boot/application/stm32l0/Cargo.toml b/examples/boot/application/stm32l0/Cargo.toml index f221e1de7..acc9e9e35 100644 --- a/examples/boot/application/stm32l0/Cargo.toml +++ b/examples/boot/application/stm32l0/Cargo.toml @@ -5,7 +5,7 @@ version = "0.1.0" license = "MIT OR Apache-2.0" [dependencies] -embassy-sync = { version = "0.2.0", path = "../../../../embassy-sync", features = ["defmt"] } +embassy-sync = { version = "0.2.0", path = "../../../../embassy-sync" } embassy-executor = { version = "0.3.0", path = "../../../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "nightly", "integrated-timers"] } embassy-time = { version = "0.1.2", path = "../../../../embassy-time", features = ["nightly", "tick-hz-32_768"] } embassy-stm32 = { version = "0.1.0", path = "../../../../embassy-stm32", features = ["unstable-traits", "nightly", "stm32l072cz", "time-driver-any", "exti", "memory-x"] } @@ -25,5 +25,6 @@ defmt = [ "dep:defmt", "embassy-stm32/defmt", "embassy-boot-stm32/defmt", + "embassy-sync/defmt", ] skip-include = [] diff --git a/examples/boot/application/stm32l1/Cargo.toml b/examples/boot/application/stm32l1/Cargo.toml index 2896afa3e..f2ff6ae0e 100644 --- a/examples/boot/application/stm32l1/Cargo.toml +++ b/examples/boot/application/stm32l1/Cargo.toml @@ -5,7 +5,7 @@ version = "0.1.0" license = "MIT OR Apache-2.0" [dependencies] -embassy-sync = { version = "0.2.0", path = "../../../../embassy-sync", features = ["defmt"] } +embassy-sync = { version = "0.2.0", path = "../../../../embassy-sync" } embassy-executor = { version = "0.3.0", path = "../../../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "nightly", "integrated-timers"] } embassy-time = { version = "0.1.2", path = "../../../../embassy-time", features = ["nightly", "tick-hz-32_768"] } embassy-stm32 = { version = "0.1.0", path = "../../../../embassy-stm32", features = ["unstable-traits", "nightly", "stm32l151cb-a", "time-driver-any", "exti"] } @@ -25,5 +25,6 @@ defmt = [ "dep:defmt", "embassy-stm32/defmt", "embassy-boot-stm32/defmt", + "embassy-sync/defmt", ] skip-include = [] diff --git a/examples/boot/application/stm32l4/Cargo.toml b/examples/boot/application/stm32l4/Cargo.toml index 50d8967a1..167f8f9e8 100644 --- a/examples/boot/application/stm32l4/Cargo.toml +++ b/examples/boot/application/stm32l4/Cargo.toml @@ -5,7 +5,7 @@ version = "0.1.0" license = "MIT OR Apache-2.0" [dependencies] -embassy-sync = { version = "0.2.0", path = "../../../../embassy-sync", features = ["defmt"] } +embassy-sync = { version = "0.2.0", path = "../../../../embassy-sync" } embassy-executor = { version = "0.3.0", path = "../../../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "nightly", "integrated-timers"] } embassy-time = { version = "0.1.2", path = "../../../../embassy-time", features = ["nightly", "tick-hz-32_768"] } embassy-stm32 = { version = "0.1.0", path = "../../../../embassy-stm32", features = ["unstable-traits", "nightly", "stm32l475vg", "time-driver-any", "exti"] } @@ -25,5 +25,6 @@ defmt = [ "dep:defmt", "embassy-stm32/defmt", "embassy-boot-stm32/defmt", + "embassy-sync/defmt", ] skip-include = [] diff --git a/examples/boot/application/stm32wl/Cargo.toml b/examples/boot/application/stm32wl/Cargo.toml index 275414391..066150dd3 100644 --- a/examples/boot/application/stm32wl/Cargo.toml +++ b/examples/boot/application/stm32wl/Cargo.toml @@ -5,7 +5,7 @@ version = "0.1.0" license = "MIT OR Apache-2.0" [dependencies] -embassy-sync = { version = "0.2.0", path = "../../../../embassy-sync", features = ["defmt"] } +embassy-sync = { version = "0.2.0", path = "../../../../embassy-sync" } embassy-executor = { version = "0.3.0", path = "../../../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "nightly", "integrated-timers"] } embassy-time = { version = "0.1.2", path = "../../../../embassy-time", features = ["nightly", "tick-hz-32_768"] } embassy-stm32 = { version = "0.1.0", path = "../../../../embassy-stm32", features = ["unstable-traits", "nightly", "stm32wl55jc-cm4", "time-driver-any", "exti"] } @@ -25,5 +25,6 @@ defmt = [ "dep:defmt", "embassy-stm32/defmt", "embassy-boot-stm32/defmt", + "embassy-sync/defmt", ] skip-include = [] diff --git a/examples/boot/bootloader/nrf/Cargo.toml b/examples/boot/bootloader/nrf/Cargo.toml index 40656f359..42391778d 100644 --- a/examples/boot/bootloader/nrf/Cargo.toml +++ b/examples/boot/bootloader/nrf/Cargo.toml @@ -25,7 +25,7 @@ defmt = [ softdevice = [ "embassy-boot-nrf/softdevice", ] -debug = ["defmt-rtt"] +debug = ["defmt-rtt", "defmt"] [profile.dev] debug = 2 diff --git a/examples/boot/bootloader/stm32/Cargo.toml b/examples/boot/bootloader/stm32/Cargo.toml index 6436f2fee..9175768d6 100644 --- a/examples/boot/bootloader/stm32/Cargo.toml +++ b/examples/boot/bootloader/stm32/Cargo.toml @@ -24,7 +24,7 @@ defmt = [ "embassy-boot-stm32/defmt", "embassy-stm32/defmt", ] -debug = ["defmt-rtt"] +debug = ["defmt-rtt", "defmt"] [profile.dev] debug = 2