aboutsummaryrefslogtreecommitdiff
path: root/embassy-nrf/src
diff options
context:
space:
mode:
authorMatteo Meluzzi <[email protected]>2025-10-24 15:48:34 +0200
committerMatteo Meluzzi <[email protected]>2025-10-24 15:48:34 +0200
commit7976f950b0de72c521f92efa350c67ccd197fab9 (patch)
tree8759312eb000de09b92a4921f476d5c16b7e7342 /embassy-nrf/src
parent828a8df18d04877df1f55f04354980b28ff2f2f8 (diff)
Merge branch 'main' into 17-add-support-for-boot-protocol
Diffstat (limited to 'embassy-nrf/src')
-rw-r--r--embassy-nrf/src/buffered_uarte.rs32
-rw-r--r--embassy-nrf/src/chips/nrf54l15_app.rs43
-rw-r--r--embassy-nrf/src/egu.rs2
-rw-r--r--embassy-nrf/src/embassy_net_802154_driver.rs4
-rw-r--r--embassy-nrf/src/gpio.rs4
-rw-r--r--embassy-nrf/src/gpiote.rs12
-rw-r--r--embassy-nrf/src/i2s.rs4
-rw-r--r--embassy-nrf/src/lib.rs70
-rw-r--r--embassy-nrf/src/nfct.rs6
-rw-r--r--embassy-nrf/src/nvmc.rs2
-rw-r--r--embassy-nrf/src/pdm.rs4
-rw-r--r--embassy-nrf/src/ppi/dppi.rs2
-rw-r--r--embassy-nrf/src/ppi/mod.rs4
-rw-r--r--embassy-nrf/src/ppi/ppi.rs2
-rw-r--r--embassy-nrf/src/pwm.rs4
-rwxr-xr-xembassy-nrf/src/qspi.rs2
-rw-r--r--embassy-nrf/src/radio/ieee802154.rs21
-rw-r--r--embassy-nrf/src/rramc.rs2
-rw-r--r--embassy-nrf/src/saadc.rs4
-rw-r--r--embassy-nrf/src/spim.rs6
-rw-r--r--embassy-nrf/src/spis.rs6
-rw-r--r--embassy-nrf/src/temp.rs2
-rw-r--r--embassy-nrf/src/time_driver.rs4
-rw-r--r--embassy-nrf/src/twim.rs2
-rw-r--r--embassy-nrf/src/twis.rs4
-rw-r--r--embassy-nrf/src/uarte.rs4
-rw-r--r--embassy-nrf/src/usb/mod.rs10
-rw-r--r--embassy-nrf/src/usb/vbus_detect.rs2
-rw-r--r--embassy-nrf/src/util.rs6
-rw-r--r--embassy-nrf/src/wdt.rs2
30 files changed, 192 insertions, 80 deletions
diff --git a/embassy-nrf/src/buffered_uarte.rs b/embassy-nrf/src/buffered_uarte.rs
index 40c679190..b1eb5c81a 100644
--- a/embassy-nrf/src/buffered_uarte.rs
+++ b/embassy-nrf/src/buffered_uarte.rs
@@ -9,27 +9,27 @@
9//! Please also see [crate::uarte] to understand when [BufferedUarte] should be used. 9//! Please also see [crate::uarte] to understand when [BufferedUarte] should be used.
10 10
11use core::cmp::min; 11use core::cmp::min;
12use core::future::{poll_fn, Future}; 12use core::future::{Future, poll_fn};
13use core::marker::PhantomData; 13use core::marker::PhantomData;
14use core::slice; 14use core::slice;
15use core::sync::atomic::{compiler_fence, AtomicBool, AtomicU8, AtomicUsize, Ordering}; 15use core::sync::atomic::{AtomicBool, AtomicU8, AtomicUsize, Ordering, compiler_fence};
16use core::task::Poll; 16use core::task::Poll;
17 17
18use embassy_hal_internal::atomic_ring_buffer::RingBuffer;
19use embassy_hal_internal::Peri; 18use embassy_hal_internal::Peri;
19use embassy_hal_internal::atomic_ring_buffer::RingBuffer;
20use pac::uarte::vals; 20use pac::uarte::vals;
21// Re-export SVD variants to allow user to directly set values 21// Re-export SVD variants to allow user to directly set values
22pub use pac::uarte::vals::{Baudrate, ConfigParity as Parity}; 22pub use pac::uarte::vals::{Baudrate, ConfigParity as Parity};
23 23
24use crate::gpio::{AnyPin, Pin as GpioPin}; 24use crate::gpio::{AnyPin, Pin as GpioPin};
25use crate::interrupt::typelevel::Interrupt;
26use crate::interrupt::InterruptExt; 25use crate::interrupt::InterruptExt;
26use crate::interrupt::typelevel::Interrupt;
27use crate::ppi::{ 27use crate::ppi::{
28 self, AnyConfigurableChannel, AnyGroup, Channel, ConfigurableChannel, Event, Group, Ppi, PpiGroup, Task, 28 self, AnyConfigurableChannel, AnyGroup, Channel, ConfigurableChannel, Event, Group, Ppi, PpiGroup, Task,
29}; 29};
30use crate::timer::{Instance as TimerInstance, Timer}; 30use crate::timer::{Instance as TimerInstance, Timer};
31use crate::uarte::{configure, configure_rx_pins, configure_tx_pins, drop_tx_rx, Config, Instance as UarteInstance}; 31use crate::uarte::{Config, Instance as UarteInstance, configure, configure_rx_pins, configure_tx_pins, drop_tx_rx};
32use crate::{interrupt, pac, EASY_DMA_SIZE}; 32use crate::{EASY_DMA_SIZE, interrupt, pac};
33 33
34pub(crate) struct State { 34pub(crate) struct State {
35 tx_buf: RingBuffer, 35 tx_buf: RingBuffer,
@@ -40,6 +40,7 @@ pub(crate) struct State {
40 rx_started_count: AtomicU8, 40 rx_started_count: AtomicU8,
41 rx_ended_count: AtomicU8, 41 rx_ended_count: AtomicU8,
42 rx_ppi_ch: AtomicU8, 42 rx_ppi_ch: AtomicU8,
43 rx_overrun: AtomicBool,
43} 44}
44 45
45/// UART error. 46/// UART error.
@@ -47,7 +48,8 @@ pub(crate) struct State {
47#[cfg_attr(feature = "defmt", derive(defmt::Format))] 48#[cfg_attr(feature = "defmt", derive(defmt::Format))]
48#[non_exhaustive] 49#[non_exhaustive]
49pub enum Error { 50pub enum Error {
50 // No errors for now 51 /// Buffer Overrun
52 Overrun,
51} 53}
52 54
53impl State { 55impl State {
@@ -61,6 +63,7 @@ impl State {
61 rx_started_count: AtomicU8::new(0), 63 rx_started_count: AtomicU8::new(0),
62 rx_ended_count: AtomicU8::new(0), 64 rx_ended_count: AtomicU8::new(0),
63 rx_ppi_ch: AtomicU8::new(0), 65 rx_ppi_ch: AtomicU8::new(0),
66 rx_overrun: AtomicBool::new(false),
64 } 67 }
65 } 68 }
66} 69}
@@ -87,7 +90,8 @@ impl<U: UarteInstance> interrupt::typelevel::Handler<U::Interrupt> for Interrupt
87 r.errorsrc().write_value(errs); 90 r.errorsrc().write_value(errs);
88 91
89 if errs.overrun() { 92 if errs.overrun() {
90 panic!("BufferedUarte overrun"); 93 s.rx_overrun.store(true, Ordering::Release);
94 ss.rx_waker.wake();
91 } 95 }
92 } 96 }
93 97
@@ -689,6 +693,7 @@ impl<'d> BufferedUarteRx<'d> {
689 buffered_state.rx_started_count.store(0, Ordering::Relaxed); 693 buffered_state.rx_started_count.store(0, Ordering::Relaxed);
690 buffered_state.rx_ended_count.store(0, Ordering::Relaxed); 694 buffered_state.rx_ended_count.store(0, Ordering::Relaxed);
691 buffered_state.rx_started.store(false, Ordering::Relaxed); 695 buffered_state.rx_started.store(false, Ordering::Relaxed);
696 buffered_state.rx_overrun.store(false, Ordering::Relaxed);
692 let rx_len = rx_buffer.len().min(EASY_DMA_SIZE * 2); 697 let rx_len = rx_buffer.len().min(EASY_DMA_SIZE * 2);
693 unsafe { buffered_state.rx_buf.init(rx_buffer.as_mut_ptr(), rx_len) }; 698 unsafe { buffered_state.rx_buf.init(rx_buffer.as_mut_ptr(), rx_len) };
694 699
@@ -762,6 +767,10 @@ impl<'d> BufferedUarteRx<'d> {
762 compiler_fence(Ordering::SeqCst); 767 compiler_fence(Ordering::SeqCst);
763 //trace!("poll_read"); 768 //trace!("poll_read");
764 769
770 if s.rx_overrun.swap(false, Ordering::Acquire) {
771 return Poll::Ready(Err(Error::Overrun));
772 }
773
765 // Read the RXDRDY counter. 774 // Read the RXDRDY counter.
766 timer.cc(0).capture(); 775 timer.cc(0).capture();
767 let mut end = timer.cc(0).read() as usize; 776 let mut end = timer.cc(0).read() as usize;
@@ -820,6 +829,9 @@ impl<'d> BufferedUarteRx<'d> {
820 /// we are ready to read if there is data in the buffer 829 /// we are ready to read if there is data in the buffer
821 fn read_ready(&self) -> Result<bool, Error> { 830 fn read_ready(&self) -> Result<bool, Error> {
822 let state = self.buffered_state; 831 let state = self.buffered_state;
832 if state.rx_overrun.swap(false, Ordering::Acquire) {
833 return Err(Error::Overrun);
834 }
823 Ok(!state.rx_buf.is_empty()) 835 Ok(!state.rx_buf.is_empty())
824 } 836 }
825} 837}
@@ -854,7 +866,9 @@ mod _embedded_io {
854 866
855 impl embedded_io_async::Error for Error { 867 impl embedded_io_async::Error for Error {
856 fn kind(&self) -> embedded_io_async::ErrorKind { 868 fn kind(&self) -> embedded_io_async::ErrorKind {
857 match *self {} 869 match *self {
870 Error::Overrun => embedded_io_async::ErrorKind::OutOfMemory,
871 }
858 } 872 }
859 } 873 }
860 874
diff --git a/embassy-nrf/src/chips/nrf54l15_app.rs b/embassy-nrf/src/chips/nrf54l15_app.rs
index ff05bbec0..901c5e7fc 100644
--- a/embassy-nrf/src/chips/nrf54l15_app.rs
+++ b/embassy-nrf/src/chips/nrf54l15_app.rs
@@ -94,6 +94,7 @@ pub mod pac {
94 #[cfg(feature = "_s")] 94 #[cfg(feature = "_s")]
95 #[doc(no_inline)] 95 #[doc(no_inline)]
96 pub use nrf_pac::{ 96 pub use nrf_pac::{
97 FICR_NS as FICR,
97 SICR_S as SICR, 98 SICR_S as SICR,
98 ICACHEDATA_S as ICACHEDATA, 99 ICACHEDATA_S as ICACHEDATA,
99 ICACHEINFO_S as ICACHEINFO, 100 ICACHEINFO_S as ICACHEINFO,
@@ -248,6 +249,45 @@ embassy_hal_internal::peripherals! {
248 P2_09, 249 P2_09,
249 P2_10, 250 P2_10,
250 251
252 // RTC
253 RTC10,
254 RTC30,
255
256 // SERIAL
257 SERIAL00,
258 SERIAL20,
259 SERIAL21,
260 SERIAL22,
261 SERIAL30,
262
263 // SAADC
264 SAADC,
265
266 // RADIO
267 RADIO,
268
269 // TIMER
270 TIMER00,
271 TIMER10,
272 TIMER20,
273
274 // PPI BRIDGE
275 PPIB00,
276 PPIB01,
277 PPIB10,
278 PPIB11,
279 PPIB20,
280 PPIB21,
281 PPIB22,
282 PPIB30,
283
284 // GPIOTE
285 GPIOTE20,
286 GPIOTE30,
287
288 // CRACEN
289 CRACEN,
290
251 #[cfg(feature = "_s")] 291 #[cfg(feature = "_s")]
252 // RRAMC 292 // RRAMC
253 RRAMC, 293 RRAMC,
@@ -302,6 +342,9 @@ impl_pin!(P2_08, 2, 8);
302impl_pin!(P2_09, 2, 9); 342impl_pin!(P2_09, 2, 9);
303impl_pin!(P2_10, 2, 10); 343impl_pin!(P2_10, 2, 10);
304 344
345impl_rtc!(RTC10, RTC10, RTC10);
346impl_rtc!(RTC30, RTC30, RTC30);
347
305#[cfg(feature = "_ns")] 348#[cfg(feature = "_ns")]
306impl_wdt!(WDT, WDT31, WDT31, 0); 349impl_wdt!(WDT, WDT31, WDT31, 0);
307#[cfg(feature = "_s")] 350#[cfg(feature = "_s")]
diff --git a/embassy-nrf/src/egu.rs b/embassy-nrf/src/egu.rs
index f7372fca1..666986115 100644
--- a/embassy-nrf/src/egu.rs
+++ b/embassy-nrf/src/egu.rs
@@ -10,7 +10,7 @@ use core::marker::PhantomData;
10use embassy_hal_internal::PeripheralType; 10use embassy_hal_internal::PeripheralType;
11 11
12use crate::ppi::{Event, Task}; 12use crate::ppi::{Event, Task};
13use crate::{interrupt, pac, Peri}; 13use crate::{Peri, interrupt, pac};
14 14
15/// An instance of the EGU. 15/// An instance of the EGU.
16pub struct Egu<'d> { 16pub struct Egu<'d> {
diff --git a/embassy-nrf/src/embassy_net_802154_driver.rs b/embassy-nrf/src/embassy_net_802154_driver.rs
index b3fc5df2c..4c47b7cbd 100644
--- a/embassy-nrf/src/embassy_net_802154_driver.rs
+++ b/embassy-nrf/src/embassy_net_802154_driver.rs
@@ -1,12 +1,12 @@
1//! embassy-net IEEE 802.15.4 driver 1//! embassy-net IEEE 802.15.4 driver
2 2
3use embassy_futures::select::{select3, Either3}; 3use embassy_futures::select::{Either3, select3};
4use embassy_net_driver_channel::driver::LinkState; 4use embassy_net_driver_channel::driver::LinkState;
5use embassy_net_driver_channel::{self as ch}; 5use embassy_net_driver_channel::{self as ch};
6use embassy_time::{Duration, Ticker}; 6use embassy_time::{Duration, Ticker};
7 7
8use crate::radio::ieee802154::{Packet, Radio};
9use crate::radio::InterruptHandler; 8use crate::radio::InterruptHandler;
9use crate::radio::ieee802154::{Packet, Radio};
10use crate::{self as nrf, interrupt}; 10use crate::{self as nrf, interrupt};
11 11
12/// MTU for the nrf radio. 12/// MTU for the nrf radio.
diff --git a/embassy-nrf/src/gpio.rs b/embassy-nrf/src/gpio.rs
index ab5e7ed4b..7ed3a7927 100644
--- a/embassy-nrf/src/gpio.rs
+++ b/embassy-nrf/src/gpio.rs
@@ -5,10 +5,10 @@ use core::convert::Infallible;
5use core::hint::unreachable_unchecked; 5use core::hint::unreachable_unchecked;
6 6
7use cfg_if::cfg_if; 7use cfg_if::cfg_if;
8use embassy_hal_internal::{impl_peripheral, Peri, PeripheralType}; 8use embassy_hal_internal::{Peri, PeripheralType, impl_peripheral};
9 9
10use crate::pac; 10use crate::pac;
11use crate::pac::common::{Reg, RW}; 11use crate::pac::common::{RW, Reg};
12use crate::pac::gpio; 12use crate::pac::gpio;
13use crate::pac::gpio::vals; 13use crate::pac::gpio::vals;
14#[cfg(not(feature = "_nrf51"))] 14#[cfg(not(feature = "_nrf51"))]
diff --git a/embassy-nrf/src/gpiote.rs b/embassy-nrf/src/gpiote.rs
index 43e43f0bf..3658657c0 100644
--- a/embassy-nrf/src/gpiote.rs
+++ b/embassy-nrf/src/gpiote.rs
@@ -1,10 +1,10 @@
1//! GPIO task/event (GPIOTE) driver. 1//! GPIO task/event (GPIOTE) driver.
2 2
3use core::convert::Infallible; 3use core::convert::Infallible;
4use core::future::{poll_fn, Future}; 4use core::future::{Future, poll_fn};
5use core::task::{Context, Poll}; 5use core::task::{Context, Poll};
6 6
7use embassy_hal_internal::{impl_peripheral, Peri, PeripheralType}; 7use embassy_hal_internal::{Peri, PeripheralType, impl_peripheral};
8use embassy_sync::waitqueue::AtomicWaker; 8use embassy_sync::waitqueue::AtomicWaker;
9 9
10use crate::gpio::{AnyPin, Flex, Input, Output, Pin as GpioPin, SealedPin as _}; 10use crate::gpio::{AnyPin, Flex, Input, Output, Pin as GpioPin, SealedPin as _};
@@ -77,6 +77,9 @@ pub(crate) fn init(irq_prio: crate::interrupt::Priority) {
77 77
78 for &p in ports { 78 for &p in ports {
79 // Enable latched detection 79 // Enable latched detection
80 #[cfg(feature = "_s")]
81 p.detectmode_sec().write(|w| w.set_detectmode(Detectmode::LDETECT));
82 #[cfg(not(feature = "_s"))]
80 p.detectmode().write(|w| w.set_detectmode(Detectmode::LDETECT)); 83 p.detectmode().write(|w| w.set_detectmode(Detectmode::LDETECT));
81 // Clear latch 84 // Clear latch
82 p.latch().write(|w| w.0 = 0xFFFFFFFF) 85 p.latch().write(|w| w.0 = 0xFFFFFFFF)
@@ -259,6 +262,11 @@ impl<'d> InputChannel<'d> {
259 .await; 262 .await;
260 } 263 }
261 264
265 /// Get the associated input pin.
266 pub fn pin(&self) -> &Input<'_> {
267 &self.pin
268 }
269
262 /// Returns the IN event, for use with PPI. 270 /// Returns the IN event, for use with PPI.
263 pub fn event_in(&self) -> Event<'d> { 271 pub fn event_in(&self) -> Event<'d> {
264 let g = regs(); 272 let g = regs();
diff --git a/embassy-nrf/src/i2s.rs b/embassy-nrf/src/i2s.rs
index 1bfa18491..9cce9f1e8 100644
--- a/embassy-nrf/src/i2s.rs
+++ b/embassy-nrf/src/i2s.rs
@@ -6,7 +6,7 @@ use core::future::poll_fn;
6use core::marker::PhantomData; 6use core::marker::PhantomData;
7use core::mem::size_of; 7use core::mem::size_of;
8use core::ops::{Deref, DerefMut}; 8use core::ops::{Deref, DerefMut};
9use core::sync::atomic::{compiler_fence, AtomicBool, Ordering}; 9use core::sync::atomic::{AtomicBool, Ordering, compiler_fence};
10use core::task::Poll; 10use core::task::Poll;
11 11
12use embassy_hal_internal::drop::OnDrop; 12use embassy_hal_internal::drop::OnDrop;
@@ -17,7 +17,7 @@ use crate::gpio::{AnyPin, Pin as GpioPin, PselBits};
17use crate::interrupt::typelevel::Interrupt; 17use crate::interrupt::typelevel::Interrupt;
18use crate::pac::i2s::vals; 18use crate::pac::i2s::vals;
19use crate::util::slice_in_ram_or; 19use crate::util::slice_in_ram_or;
20use crate::{interrupt, pac, EASY_DMA_SIZE}; 20use crate::{EASY_DMA_SIZE, interrupt, pac};
21 21
22/// Type alias for `MultiBuffering` with 2 buffers. 22/// Type alias for `MultiBuffering` with 2 buffers.
23pub type DoubleBuffering<S, const NS: usize> = MultiBuffering<S, 2, NS>; 23pub type DoubleBuffering<S, const NS: usize> = MultiBuffering<S, 2, NS>;
diff --git a/embassy-nrf/src/lib.rs b/embassy-nrf/src/lib.rs
index 7c26a6184..705c77453 100644
--- a/embassy-nrf/src/lib.rs
+++ b/embassy-nrf/src/lib.rs
@@ -1,5 +1,6 @@
1#![no_std] 1#![no_std]
2#![allow(async_fn_in_trait)] 2#![allow(async_fn_in_trait)]
3#![allow(unsafe_op_in_unsafe_fn)]
3#![cfg_attr( 4#![cfg_attr(
4 docsrs, 5 docsrs,
5 doc = "<div style='padding:30px;background:#810;color:#fff;text-align:center;'><p>You might want to <a href='https://docs.embassy.dev/embassy-nrf'>browse the `embassy-nrf` documentation on the Embassy website</a> instead.</p><p>The documentation here on `docs.rs` is built for a single chip only (nRF52840 in particular), while on the Embassy website you can pick your exact chip from the top menu. Available peripherals and their APIs change depending on the chip.</p></div>\n\n" 6 doc = "<div style='padding:30px;background:#810;color:#fff;text-align:center;'><p>You might want to <a href='https://docs.embassy.dev/embassy-nrf'>browse the `embassy-nrf` documentation on the Embassy website</a> instead.</p><p>The documentation here on `docs.rs` is built for a single chip only (nRF52840 in particular), while on the Embassy website you can pick your exact chip from the top menu. Available peripherals and their APIs change depending on the chip.</p></div>\n\n"
@@ -154,7 +155,6 @@ pub mod reset;
154#[cfg(not(feature = "_nrf54l"))] // TODO 155#[cfg(not(feature = "_nrf54l"))] // TODO
155#[cfg(not(any(feature = "_nrf5340-app", feature = "_nrf91")))] 156#[cfg(not(any(feature = "_nrf5340-app", feature = "_nrf91")))]
156pub mod rng; 157pub mod rng;
157#[cfg(not(feature = "_nrf54l"))] // TODO
158pub mod rtc; 158pub mod rtc;
159#[cfg(not(feature = "_nrf54l"))] // TODO 159#[cfg(not(feature = "_nrf54l"))] // TODO
160#[cfg(not(any(feature = "_nrf51", feature = "nrf52820", feature = "_nrf5340-net")))] 160#[cfg(not(any(feature = "_nrf51", feature = "nrf52820", feature = "_nrf5340-net")))]
@@ -252,7 +252,7 @@ macro_rules! bind_interrupts {
252 252
253 $( 253 $(
254 #[allow(non_snake_case)] 254 #[allow(non_snake_case)]
255 #[no_mangle] 255 #[unsafe(no_mangle)]
256 $(#[cfg($cond_irq)])? 256 $(#[cfg($cond_irq)])?
257 unsafe extern "C" fn $irq() { 257 unsafe extern "C" fn $irq() {
258 unsafe { 258 unsafe {
@@ -284,7 +284,7 @@ macro_rules! bind_interrupts {
284pub use chip::pac; 284pub use chip::pac;
285#[cfg(not(feature = "unstable-pac"))] 285#[cfg(not(feature = "unstable-pac"))]
286pub(crate) use chip::pac; 286pub(crate) use chip::pac;
287pub use chip::{peripherals, Peripherals, EASY_DMA_SIZE}; 287pub use chip::{EASY_DMA_SIZE, Peripherals, peripherals};
288pub use embassy_hal_internal::{Peri, PeripheralType}; 288pub use embassy_hal_internal::{Peri, PeripheralType};
289 289
290pub use crate::chip::interrupt; 290pub use crate::chip::interrupt;
@@ -406,9 +406,10 @@ pub mod config {
406 /// Settings for the internal capacitors. 406 /// Settings for the internal capacitors.
407 #[cfg(feature = "nrf5340-app-s")] 407 #[cfg(feature = "nrf5340-app-s")]
408 pub struct InternalCapacitors { 408 pub struct InternalCapacitors {
409 /// Config for the internal capacitors on pins XC1 and XC2. 409 /// Config for the internal capacitors on pins XC1 and XC2. Pass `None` to not touch it.
410 pub hfxo: Option<HfxoCapacitance>, 410 pub hfxo: Option<HfxoCapacitance>,
411 /// Config for the internal capacitors between pins XL1 and XL2. 411 /// Config for the internal capacitors between pins XL1 and XL2. Pass `None` to not touch
412 /// it.
412 pub lfxo: Option<LfxoCapacitance>, 413 pub lfxo: Option<LfxoCapacitance>,
413 } 414 }
414 415
@@ -416,6 +417,8 @@ pub mod config {
416 #[cfg(feature = "nrf5340-app-s")] 417 #[cfg(feature = "nrf5340-app-s")]
417 #[derive(Copy, Clone)] 418 #[derive(Copy, Clone)]
418 pub enum HfxoCapacitance { 419 pub enum HfxoCapacitance {
420 /// Use external capacitors
421 External,
419 /// 7.0 pF 422 /// 7.0 pF
420 _7_0pF, 423 _7_0pF,
421 /// 7.5 pF 424 /// 7.5 pF
@@ -475,8 +478,9 @@ pub mod config {
475 #[cfg(feature = "nrf5340-app-s")] 478 #[cfg(feature = "nrf5340-app-s")]
476 impl HfxoCapacitance { 479 impl HfxoCapacitance {
477 /// The capacitance value times two. 480 /// The capacitance value times two.
478 pub(crate) const fn value2(self) -> i32 { 481 pub(crate) fn value2(self) -> i32 {
479 match self { 482 match self {
483 HfxoCapacitance::External => unreachable!(),
480 HfxoCapacitance::_7_0pF => 14, 484 HfxoCapacitance::_7_0pF => 14,
481 HfxoCapacitance::_7_5pF => 15, 485 HfxoCapacitance::_7_5pF => 15,
482 HfxoCapacitance::_8_0pF => 16, 486 HfxoCapacitance::_8_0pF => 16,
@@ -506,11 +510,17 @@ pub mod config {
506 HfxoCapacitance::_20_0pF => 40, 510 HfxoCapacitance::_20_0pF => 40,
507 } 511 }
508 } 512 }
513
514 pub(crate) fn external(self) -> bool {
515 matches!(self, Self::External)
516 }
509 } 517 }
510 518
511 /// Internal capacitance value for the LFXO. 519 /// Internal capacitance value for the LFXO.
512 #[cfg(feature = "nrf5340-app-s")] 520 #[cfg(feature = "nrf5340-app-s")]
513 pub enum LfxoCapacitance { 521 pub enum LfxoCapacitance {
522 /// Use external capacitors
523 External = 0,
514 /// 6 pF 524 /// 6 pF
515 _6pF = 1, 525 _6pF = 1,
516 /// 7 pF 526 /// 7 pF
@@ -523,6 +533,7 @@ pub mod config {
523 impl From<LfxoCapacitance> for super::pac::oscillators::vals::Intcap { 533 impl From<LfxoCapacitance> for super::pac::oscillators::vals::Intcap {
524 fn from(t: LfxoCapacitance) -> Self { 534 fn from(t: LfxoCapacitance) -> Self {
525 match t { 535 match t {
536 LfxoCapacitance::External => Self::EXTERNAL,
526 LfxoCapacitance::_6pF => Self::C6PF, 537 LfxoCapacitance::_6pF => Self::C6PF,
527 LfxoCapacitance::_7pF => Self::C7PF, 538 LfxoCapacitance::_7pF => Self::C7PF,
528 LfxoCapacitance::_9pF => Self::C9PF, 539 LfxoCapacitance::_9pF => Self::C9PF,
@@ -720,6 +731,29 @@ pub fn init(config: config::Config) -> Peripherals {
720 } 731 }
721 } 732 }
722 733
734 // Apply trimming values from the FICR.
735 #[cfg(any(
736 all(feature = "_nrf5340-app", feature = "_s"),
737 all(feature = "_nrf54l", feature = "_s"),
738 feature = "_nrf5340-net",
739 ))]
740 {
741 #[cfg(feature = "_nrf5340")]
742 let n = 32;
743 #[cfg(feature = "_nrf54l")]
744 let n = 64;
745 for i in 0..n {
746 let info = pac::FICR.trimcnf(i);
747 let addr = info.addr().read();
748 if addr == 0 || addr == 0xFFFF_FFFF {
749 break;
750 }
751 unsafe {
752 (addr as *mut u32).write_volatile(info.data().read());
753 }
754 }
755 }
756
723 // GLITCHDET is only accessible for secure code 757 // GLITCHDET is only accessible for secure code
724 #[cfg(all(feature = "_nrf54l", feature = "_s"))] 758 #[cfg(all(feature = "_nrf54l", feature = "_s"))]
725 { 759 {
@@ -953,17 +987,21 @@ pub fn init(config: config::Config) -> Peripherals {
953 #[cfg(feature = "nrf5340-app-s")] 987 #[cfg(feature = "nrf5340-app-s")]
954 { 988 {
955 if let Some(cap) = config.internal_capacitors.hfxo { 989 if let Some(cap) = config.internal_capacitors.hfxo {
956 let mut slope = pac::FICR.xosc32mtrim().read().slope() as i32; 990 if cap.external() {
957 let offset = pac::FICR.xosc32mtrim().read().offset() as i32; 991 pac::OSCILLATORS.xosc32mcaps().write(|w| w.set_enable(false));
958 // slope is a signed 5-bit integer 992 } else {
959 if slope >= 16 { 993 let mut slope = pac::FICR.xosc32mtrim().read().slope() as i32;
960 slope -= 32; 994 let offset = pac::FICR.xosc32mtrim().read().offset() as i32;
995 // slope is a signed 5-bit integer
996 if slope >= 16 {
997 slope -= 32;
998 }
999 let capvalue = (((slope + 56) * (cap.value2() - 14)) + ((offset - 8) << 4) + 32) >> 6;
1000 pac::OSCILLATORS.xosc32mcaps().write(|w| {
1001 w.set_capvalue(capvalue as u8);
1002 w.set_enable(true);
1003 });
961 } 1004 }
962 let capvalue = (((slope + 56) * (cap.value2() - 14)) + ((offset - 8) << 4) + 32) >> 6;
963 pac::OSCILLATORS.xosc32mcaps().write(|w| {
964 w.set_capvalue(capvalue as u8);
965 w.set_enable(true);
966 });
967 } 1005 }
968 if let Some(cap) = config.internal_capacitors.lfxo { 1006 if let Some(cap) = config.internal_capacitors.lfxo {
969 pac::OSCILLATORS.xosc32ki().intcap().write(|w| w.set_intcap(cap.into())); 1007 pac::OSCILLATORS.xosc32ki().intcap().write(|w| w.set_intcap(cap.into()));
diff --git a/embassy-nrf/src/nfct.rs b/embassy-nrf/src/nfct.rs
index 8d70ec954..bfbdc2906 100644
--- a/embassy-nrf/src/nfct.rs
+++ b/embassy-nrf/src/nfct.rs
@@ -10,18 +10,18 @@
10#![macro_use] 10#![macro_use]
11 11
12use core::future::poll_fn; 12use core::future::poll_fn;
13use core::sync::atomic::{compiler_fence, Ordering}; 13use core::sync::atomic::{Ordering, compiler_fence};
14use core::task::Poll; 14use core::task::Poll;
15 15
16use embassy_sync::waitqueue::AtomicWaker; 16use embassy_sync::waitqueue::AtomicWaker;
17pub use vals::{Bitframesdd as SddPat, Discardmode as DiscardMode}; 17pub use vals::{Bitframesdd as SddPat, Discardmode as DiscardMode};
18 18
19use crate::interrupt::InterruptExt; 19use crate::interrupt::InterruptExt;
20use crate::pac::nfct::vals;
21use crate::pac::NFCT; 20use crate::pac::NFCT;
21use crate::pac::nfct::vals;
22use crate::peripherals::NFCT; 22use crate::peripherals::NFCT;
23use crate::util::slice_in_ram; 23use crate::util::slice_in_ram;
24use crate::{interrupt, pac, Peri}; 24use crate::{Peri, interrupt, pac};
25 25
26/// NFCID1 (aka UID) of different sizes. 26/// NFCID1 (aka UID) of different sizes.
27#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug)] 27#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug)]
diff --git a/embassy-nrf/src/nvmc.rs b/embassy-nrf/src/nvmc.rs
index c46af0b34..3f38cd0f5 100644
--- a/embassy-nrf/src/nvmc.rs
+++ b/embassy-nrf/src/nvmc.rs
@@ -8,7 +8,7 @@ use embedded_storage::nor_flash::{
8 8
9use crate::pac::nvmc::vals; 9use crate::pac::nvmc::vals;
10use crate::peripherals::NVMC; 10use crate::peripherals::NVMC;
11use crate::{pac, Peri}; 11use crate::{Peri, pac};
12 12
13#[cfg(not(feature = "_nrf5340-net"))] 13#[cfg(not(feature = "_nrf5340-net"))]
14/// Erase size of NVMC flash in bytes. 14/// Erase size of NVMC flash in bytes.
diff --git a/embassy-nrf/src/pdm.rs b/embassy-nrf/src/pdm.rs
index b6ee52850..bc28f5c8a 100644
--- a/embassy-nrf/src/pdm.rs
+++ b/embassy-nrf/src/pdm.rs
@@ -4,7 +4,7 @@
4 4
5use core::future::poll_fn; 5use core::future::poll_fn;
6use core::marker::PhantomData; 6use core::marker::PhantomData;
7use core::sync::atomic::{compiler_fence, Ordering}; 7use core::sync::atomic::{Ordering, compiler_fence};
8use core::task::Poll; 8use core::task::Poll;
9 9
10use embassy_hal_internal::drop::OnDrop; 10use embassy_hal_internal::drop::OnDrop;
@@ -13,7 +13,7 @@ use embassy_sync::waitqueue::AtomicWaker;
13use fixed::types::I7F1; 13use fixed::types::I7F1;
14 14
15use crate::chip::EASY_DMA_SIZE; 15use crate::chip::EASY_DMA_SIZE;
16use crate::gpio::{AnyPin, Pin as GpioPin, SealedPin, DISCONNECTED}; 16use crate::gpio::{AnyPin, DISCONNECTED, Pin as GpioPin, SealedPin};
17use crate::interrupt::typelevel::Interrupt; 17use crate::interrupt::typelevel::Interrupt;
18use crate::pac::gpio::vals as gpiovals; 18use crate::pac::gpio::vals as gpiovals;
19use crate::pac::pdm::vals; 19use crate::pac::pdm::vals;
diff --git a/embassy-nrf/src/ppi/dppi.rs b/embassy-nrf/src/ppi/dppi.rs
index 078d2fd1c..168647be3 100644
--- a/embassy-nrf/src/ppi/dppi.rs
+++ b/embassy-nrf/src/ppi/dppi.rs
@@ -1,5 +1,5 @@
1use super::{Channel, ConfigurableChannel, Event, Ppi, Task}; 1use super::{Channel, ConfigurableChannel, Event, Ppi, Task};
2use crate::{pac, Peri}; 2use crate::{Peri, pac};
3 3
4const DPPI_ENABLE_BIT: u32 = 0x8000_0000; 4const DPPI_ENABLE_BIT: u32 = 0x8000_0000;
5const DPPI_CHANNEL_MASK: u32 = 0x0000_00FF; 5const DPPI_CHANNEL_MASK: u32 = 0x0000_00FF;
diff --git a/embassy-nrf/src/ppi/mod.rs b/embassy-nrf/src/ppi/mod.rs
index 2bcf72e9c..f30c2218d 100644
--- a/embassy-nrf/src/ppi/mod.rs
+++ b/embassy-nrf/src/ppi/mod.rs
@@ -18,9 +18,9 @@
18use core::marker::PhantomData; 18use core::marker::PhantomData;
19use core::ptr::NonNull; 19use core::ptr::NonNull;
20 20
21use embassy_hal_internal::{impl_peripheral, Peri, PeripheralType}; 21use embassy_hal_internal::{Peri, PeripheralType, impl_peripheral};
22 22
23use crate::pac::common::{Reg, RW, W}; 23use crate::pac::common::{RW, Reg, W};
24use crate::peripherals; 24use crate::peripherals;
25 25
26#[cfg_attr(feature = "_dppi", path = "dppi.rs")] 26#[cfg_attr(feature = "_dppi", path = "dppi.rs")]
diff --git a/embassy-nrf/src/ppi/ppi.rs b/embassy-nrf/src/ppi/ppi.rs
index 531c25444..18bc8b8db 100644
--- a/embassy-nrf/src/ppi/ppi.rs
+++ b/embassy-nrf/src/ppi/ppi.rs
@@ -1,5 +1,5 @@
1use super::{Channel, ConfigurableChannel, Event, Ppi, Task}; 1use super::{Channel, ConfigurableChannel, Event, Ppi, Task};
2use crate::{pac, Peri}; 2use crate::{Peri, pac};
3 3
4impl<'d> Task<'d> { 4impl<'d> Task<'d> {
5 fn reg_val(&self) -> u32 { 5 fn reg_val(&self) -> u32 {
diff --git a/embassy-nrf/src/pwm.rs b/embassy-nrf/src/pwm.rs
index d67cb546b..e038f44b8 100644
--- a/embassy-nrf/src/pwm.rs
+++ b/embassy-nrf/src/pwm.rs
@@ -2,11 +2,11 @@
2 2
3#![macro_use] 3#![macro_use]
4 4
5use core::sync::atomic::{compiler_fence, Ordering}; 5use core::sync::atomic::{Ordering, compiler_fence};
6 6
7use embassy_hal_internal::{Peri, PeripheralType}; 7use embassy_hal_internal::{Peri, PeripheralType};
8 8
9use crate::gpio::{convert_drive, AnyPin, OutputDrive, Pin as GpioPin, PselBits, SealedPin as _, DISCONNECTED}; 9use crate::gpio::{AnyPin, DISCONNECTED, OutputDrive, Pin as GpioPin, PselBits, SealedPin as _, convert_drive};
10use crate::pac::gpio::vals as gpiovals; 10use crate::pac::gpio::vals as gpiovals;
11use crate::pac::pwm::vals; 11use crate::pac::pwm::vals;
12use crate::ppi::{Event, Task}; 12use crate::ppi::{Event, Task};
diff --git a/embassy-nrf/src/qspi.rs b/embassy-nrf/src/qspi.rs
index 6f4524716..6bb7c033e 100755
--- a/embassy-nrf/src/qspi.rs
+++ b/embassy-nrf/src/qspi.rs
@@ -2,7 +2,7 @@
2 2
3#![macro_use] 3#![macro_use]
4 4
5use core::future::{poll_fn, Future}; 5use core::future::{Future, poll_fn};
6use core::marker::PhantomData; 6use core::marker::PhantomData;
7use core::ptr; 7use core::ptr;
8use core::task::Poll; 8use core::task::Poll;
diff --git a/embassy-nrf/src/radio/ieee802154.rs b/embassy-nrf/src/radio/ieee802154.rs
index 62af03a5a..54b463343 100644
--- a/embassy-nrf/src/radio/ieee802154.rs
+++ b/embassy-nrf/src/radio/ieee802154.rs
@@ -1,18 +1,18 @@
1//! IEEE 802.15.4 radio driver 1//! IEEE 802.15.4 radio driver
2 2
3use core::marker::PhantomData; 3use core::marker::PhantomData;
4use core::sync::atomic::{compiler_fence, Ordering}; 4use core::sync::atomic::{Ordering, compiler_fence};
5use core::task::Poll; 5use core::task::Poll;
6 6
7use embassy_hal_internal::drop::OnDrop; 7use embassy_hal_internal::drop::OnDrop;
8 8
9use super::{Error, InterruptHandler, TxPower}; 9use super::{Error, InterruptHandler, TxPower};
10use crate::Peri;
10use crate::interrupt::typelevel::Interrupt; 11use crate::interrupt::typelevel::Interrupt;
11use crate::interrupt::{self}; 12use crate::interrupt::{self};
12use crate::pac::radio::vals; 13use crate::pac::radio::vals;
13pub use crate::pac::radio::vals::State as RadioState; 14pub use crate::pac::radio::vals::State as RadioState;
14use crate::radio::Instance; 15use crate::radio::Instance;
15use crate::Peri;
16 16
17/// Default (IEEE compliant) Start of Frame Delimiter 17/// Default (IEEE compliant) Start of Frame Delimiter
18pub const DEFAULT_SFD: u8 = 0xA7; 18pub const DEFAULT_SFD: u8 = 0xA7;
@@ -52,6 +52,7 @@ impl<'d> Radio<'d> {
52 // Disable and enable to reset peripheral 52 // Disable and enable to reset peripheral
53 r.power().write(|w| w.set_power(false)); 53 r.power().write(|w| w.set_power(false));
54 r.power().write(|w| w.set_power(true)); 54 r.power().write(|w| w.set_power(true));
55 errata::post_power();
55 56
56 // Enable 802.15.4 mode 57 // Enable 802.15.4 mode
57 r.mode().write(|w| w.set_mode(vals::Mode::IEEE802154_250KBIT)); 58 r.mode().write(|w| w.set_mode(vals::Mode::IEEE802154_250KBIT));
@@ -541,3 +542,19 @@ fn dma_start_fence() {
541fn dma_end_fence() { 542fn dma_end_fence() {
542 compiler_fence(Ordering::Acquire); 543 compiler_fence(Ordering::Acquire);
543} 544}
545
546mod errata {
547 pub fn post_power() {
548 // Workaround for anomaly 158
549 #[cfg(feature = "_nrf5340-net")]
550 for i in 0..32 {
551 let info = crate::pac::FICR.trimcnf(i);
552 let addr = info.addr().read();
553 if addr & 0xFFFF_F000 == crate::pac::RADIO.as_ptr() as u32 {
554 unsafe {
555 (addr as *mut u32).write_volatile(info.data().read());
556 }
557 }
558 }
559 }
560}
diff --git a/embassy-nrf/src/rramc.rs b/embassy-nrf/src/rramc.rs
index 7cb5660cb..521ac4ee7 100644
--- a/embassy-nrf/src/rramc.rs
+++ b/embassy-nrf/src/rramc.rs
@@ -7,7 +7,7 @@ use embedded_storage::nor_flash::{
7}; 7};
8 8
9use crate::peripherals::RRAMC; 9use crate::peripherals::RRAMC;
10use crate::{pac, Peri}; 10use crate::{Peri, pac};
11 11
12// 12//
13// Export Nvmc alias and page size for downstream compatibility 13// Export Nvmc alias and page size for downstream compatibility
diff --git a/embassy-nrf/src/saadc.rs b/embassy-nrf/src/saadc.rs
index fd48faabb..a199c1c4d 100644
--- a/embassy-nrf/src/saadc.rs
+++ b/embassy-nrf/src/saadc.rs
@@ -4,11 +4,11 @@
4 4
5use core::future::poll_fn; 5use core::future::poll_fn;
6use core::marker::PhantomData; 6use core::marker::PhantomData;
7use core::sync::atomic::{compiler_fence, Ordering}; 7use core::sync::atomic::{Ordering, compiler_fence};
8use core::task::Poll; 8use core::task::Poll;
9 9
10use embassy_hal_internal::drop::OnDrop; 10use embassy_hal_internal::drop::OnDrop;
11use embassy_hal_internal::{impl_peripheral, Peri}; 11use embassy_hal_internal::{Peri, impl_peripheral};
12use embassy_sync::waitqueue::AtomicWaker; 12use embassy_sync::waitqueue::AtomicWaker;
13pub(crate) use vals::Psel as InputChannel; 13pub(crate) use vals::Psel as InputChannel;
14 14
diff --git a/embassy-nrf/src/spim.rs b/embassy-nrf/src/spim.rs
index c410e49fd..ce994dbc9 100644
--- a/embassy-nrf/src/spim.rs
+++ b/embassy-nrf/src/spim.rs
@@ -6,17 +6,17 @@ use core::future::poll_fn;
6use core::marker::PhantomData; 6use core::marker::PhantomData;
7#[cfg(feature = "_nrf52832_anomaly_109")] 7#[cfg(feature = "_nrf52832_anomaly_109")]
8use core::sync::atomic::AtomicU8; 8use core::sync::atomic::AtomicU8;
9use core::sync::atomic::{compiler_fence, Ordering}; 9use core::sync::atomic::{Ordering, compiler_fence};
10use core::task::Poll; 10use core::task::Poll;
11 11
12use embassy_embedded_hal::SetConfig; 12use embassy_embedded_hal::SetConfig;
13use embassy_hal_internal::{Peri, PeripheralType}; 13use embassy_hal_internal::{Peri, PeripheralType};
14use embassy_sync::waitqueue::AtomicWaker; 14use embassy_sync::waitqueue::AtomicWaker;
15pub use embedded_hal_02::spi::{Mode, Phase, Polarity, MODE_0, MODE_1, MODE_2, MODE_3}; 15pub use embedded_hal_02::spi::{MODE_0, MODE_1, MODE_2, MODE_3, Mode, Phase, Polarity};
16pub use pac::spim::vals::{Frequency, Order as BitOrder}; 16pub use pac::spim::vals::{Frequency, Order as BitOrder};
17 17
18use crate::chip::{EASY_DMA_SIZE, FORCE_COPY_BUFFER_SIZE}; 18use crate::chip::{EASY_DMA_SIZE, FORCE_COPY_BUFFER_SIZE};
19use crate::gpio::{self, convert_drive, AnyPin, OutputDrive, Pin as GpioPin, PselBits, SealedPin as _}; 19use crate::gpio::{self, AnyPin, OutputDrive, Pin as GpioPin, PselBits, SealedPin as _, convert_drive};
20use crate::interrupt::typelevel::Interrupt; 20use crate::interrupt::typelevel::Interrupt;
21use crate::pac::gpio::vals as gpiovals; 21use crate::pac::gpio::vals as gpiovals;
22use crate::pac::spim::vals; 22use crate::pac::spim::vals;
diff --git a/embassy-nrf/src/spis.rs b/embassy-nrf/src/spis.rs
index 713163a55..885821146 100644
--- a/embassy-nrf/src/spis.rs
+++ b/embassy-nrf/src/spis.rs
@@ -3,17 +3,17 @@
3#![macro_use] 3#![macro_use]
4use core::future::poll_fn; 4use core::future::poll_fn;
5use core::marker::PhantomData; 5use core::marker::PhantomData;
6use core::sync::atomic::{compiler_fence, Ordering}; 6use core::sync::atomic::{Ordering, compiler_fence};
7use core::task::Poll; 7use core::task::Poll;
8 8
9use embassy_embedded_hal::SetConfig; 9use embassy_embedded_hal::SetConfig;
10use embassy_hal_internal::{Peri, PeripheralType}; 10use embassy_hal_internal::{Peri, PeripheralType};
11use embassy_sync::waitqueue::AtomicWaker; 11use embassy_sync::waitqueue::AtomicWaker;
12pub use embedded_hal_02::spi::{Mode, Phase, Polarity, MODE_0, MODE_1, MODE_2, MODE_3}; 12pub use embedded_hal_02::spi::{MODE_0, MODE_1, MODE_2, MODE_3, Mode, Phase, Polarity};
13pub use pac::spis::vals::Order as BitOrder; 13pub use pac::spis::vals::Order as BitOrder;
14 14
15use crate::chip::{EASY_DMA_SIZE, FORCE_COPY_BUFFER_SIZE}; 15use crate::chip::{EASY_DMA_SIZE, FORCE_COPY_BUFFER_SIZE};
16use crate::gpio::{self, convert_drive, AnyPin, OutputDrive, Pin as GpioPin, SealedPin as _}; 16use crate::gpio::{self, AnyPin, OutputDrive, Pin as GpioPin, SealedPin as _, convert_drive};
17use crate::interrupt::typelevel::Interrupt; 17use crate::interrupt::typelevel::Interrupt;
18use crate::pac::gpio::vals as gpiovals; 18use crate::pac::gpio::vals as gpiovals;
19use crate::pac::spis::vals; 19use crate::pac::spis::vals;
diff --git a/embassy-nrf/src/temp.rs b/embassy-nrf/src/temp.rs
index 44be0f6d1..a20e300b7 100644
--- a/embassy-nrf/src/temp.rs
+++ b/embassy-nrf/src/temp.rs
@@ -9,7 +9,7 @@ use fixed::types::I30F2;
9 9
10use crate::interrupt::InterruptExt; 10use crate::interrupt::InterruptExt;
11use crate::peripherals::TEMP; 11use crate::peripherals::TEMP;
12use crate::{interrupt, pac, Peri}; 12use crate::{Peri, interrupt, pac};
13 13
14/// Interrupt handler. 14/// Interrupt handler.
15pub struct InterruptHandler { 15pub struct InterruptHandler {
diff --git a/embassy-nrf/src/time_driver.rs b/embassy-nrf/src/time_driver.rs
index 03f4c2e2b..b723e2334 100644
--- a/embassy-nrf/src/time_driver.rs
+++ b/embassy-nrf/src/time_driver.rs
@@ -1,9 +1,9 @@
1use core::cell::{Cell, RefCell}; 1use core::cell::{Cell, RefCell};
2use core::sync::atomic::{compiler_fence, AtomicU32, Ordering}; 2use core::sync::atomic::{AtomicU32, Ordering, compiler_fence};
3 3
4use critical_section::CriticalSection; 4use critical_section::CriticalSection;
5use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex;
6use embassy_sync::blocking_mutex::CriticalSectionMutex as Mutex; 5use embassy_sync::blocking_mutex::CriticalSectionMutex as Mutex;
6use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex;
7use embassy_time_driver::Driver; 7use embassy_time_driver::Driver;
8use embassy_time_queue_utils::Queue; 8use embassy_time_queue_utils::Queue;
9 9
diff --git a/embassy-nrf/src/twim.rs b/embassy-nrf/src/twim.rs
index 943ea9d31..93255c832 100644
--- a/embassy-nrf/src/twim.rs
+++ b/embassy-nrf/src/twim.rs
@@ -4,8 +4,8 @@
4 4
5use core::future::poll_fn; 5use core::future::poll_fn;
6use core::marker::PhantomData; 6use core::marker::PhantomData;
7use core::sync::atomic::compiler_fence;
8use core::sync::atomic::Ordering::SeqCst; 7use core::sync::atomic::Ordering::SeqCst;
8use core::sync::atomic::compiler_fence;
9use core::task::Poll; 9use core::task::Poll;
10 10
11use embassy_embedded_hal::SetConfig; 11use embassy_embedded_hal::SetConfig;
diff --git a/embassy-nrf/src/twis.rs b/embassy-nrf/src/twis.rs
index dd4978b3e..2bc0a5c13 100644
--- a/embassy-nrf/src/twis.rs
+++ b/embassy-nrf/src/twis.rs
@@ -2,10 +2,10 @@
2 2
3#![macro_use] 3#![macro_use]
4 4
5use core::future::{poll_fn, Future}; 5use core::future::{Future, poll_fn};
6use core::marker::PhantomData; 6use core::marker::PhantomData;
7use core::sync::atomic::compiler_fence;
8use core::sync::atomic::Ordering::SeqCst; 7use core::sync::atomic::Ordering::SeqCst;
8use core::sync::atomic::compiler_fence;
9use core::task::Poll; 9use core::task::Poll;
10 10
11use embassy_hal_internal::{Peri, PeripheralType}; 11use embassy_hal_internal::{Peri, PeripheralType};
diff --git a/embassy-nrf/src/uarte.rs b/embassy-nrf/src/uarte.rs
index 66fb3b3f2..1ee452173 100644
--- a/embassy-nrf/src/uarte.rs
+++ b/embassy-nrf/src/uarte.rs
@@ -15,7 +15,7 @@
15 15
16use core::future::poll_fn; 16use core::future::poll_fn;
17use core::marker::PhantomData; 17use core::marker::PhantomData;
18use core::sync::atomic::{compiler_fence, AtomicU8, Ordering}; 18use core::sync::atomic::{AtomicU8, Ordering, compiler_fence};
19use core::task::Poll; 19use core::task::Poll;
20 20
21use embassy_hal_internal::drop::OnDrop; 21use embassy_hal_internal::drop::OnDrop;
@@ -25,7 +25,7 @@ use embassy_sync::waitqueue::AtomicWaker;
25pub use pac::uarte::vals::{Baudrate, ConfigParity as Parity}; 25pub use pac::uarte::vals::{Baudrate, ConfigParity as Parity};
26 26
27use crate::chip::{EASY_DMA_SIZE, FORCE_COPY_BUFFER_SIZE}; 27use crate::chip::{EASY_DMA_SIZE, FORCE_COPY_BUFFER_SIZE};
28use crate::gpio::{self, AnyPin, Pin as GpioPin, PselBits, SealedPin as _, DISCONNECTED}; 28use crate::gpio::{self, AnyPin, DISCONNECTED, Pin as GpioPin, PselBits, SealedPin as _};
29use crate::interrupt::typelevel::Interrupt; 29use crate::interrupt::typelevel::Interrupt;
30use crate::pac::gpio::vals as gpiovals; 30use crate::pac::gpio::vals as gpiovals;
31use crate::pac::uarte::vals; 31use crate::pac::uarte::vals;
diff --git a/embassy-nrf/src/usb/mod.rs b/embassy-nrf/src/usb/mod.rs
index 2a32fe922..07cf2578a 100644
--- a/embassy-nrf/src/usb/mod.rs
+++ b/embassy-nrf/src/usb/mod.rs
@@ -4,10 +4,10 @@
4 4
5pub mod vbus_detect; 5pub mod vbus_detect;
6 6
7use core::future::{poll_fn, Future}; 7use core::future::{Future, poll_fn};
8use core::marker::PhantomData; 8use core::marker::PhantomData;
9use core::mem::MaybeUninit; 9use core::mem::MaybeUninit;
10use core::sync::atomic::{compiler_fence, AtomicU32, Ordering}; 10use core::sync::atomic::{AtomicU32, Ordering, compiler_fence};
11use core::task::Poll; 11use core::task::Poll;
12 12
13use cortex_m::peripheral::NVIC; 13use cortex_m::peripheral::NVIC;
@@ -330,11 +330,7 @@ impl<'d, V: VbusDetect> driver::Bus for Bus<'d, V> {
330 let mut was_enabled = false; 330 let mut was_enabled = false;
331 regs.epinen().modify(|w| { 331 regs.epinen().modify(|w| {
332 was_enabled = (w.0 & mask) != 0; 332 was_enabled = (w.0 & mask) != 0;
333 if enabled { 333 if enabled { w.0 |= mask } else { w.0 &= !mask }
334 w.0 |= mask
335 } else {
336 w.0 &= !mask
337 }
338 }); 334 });
339 335
340 let ready_mask = In::mask(i); 336 let ready_mask = In::mask(i);
diff --git a/embassy-nrf/src/usb/vbus_detect.rs b/embassy-nrf/src/usb/vbus_detect.rs
index 33cf91ee2..f24a7bff5 100644
--- a/embassy-nrf/src/usb/vbus_detect.rs
+++ b/embassy-nrf/src/usb/vbus_detect.rs
@@ -1,6 +1,6 @@
1//! Trait and implementations for performing VBUS detection. 1//! Trait and implementations for performing VBUS detection.
2 2
3use core::future::{poll_fn, Future}; 3use core::future::{Future, poll_fn};
4use core::sync::atomic::{AtomicBool, Ordering}; 4use core::sync::atomic::{AtomicBool, Ordering};
5use core::task::Poll; 5use core::task::Poll;
6 6
diff --git a/embassy-nrf/src/util.rs b/embassy-nrf/src/util.rs
index 78f71719f..87118d347 100644
--- a/embassy-nrf/src/util.rs
+++ b/embassy-nrf/src/util.rs
@@ -15,9 +15,5 @@ pub(crate) fn slice_in_ram<T>(slice: *const [T]) -> bool {
15 15
16/// Return an error if slice is not in RAM. Skips check if slice is zero-length. 16/// Return an error if slice is not in RAM. Skips check if slice is zero-length.
17pub(crate) fn slice_in_ram_or<T, E>(slice: *const [T], err: E) -> Result<(), E> { 17pub(crate) fn slice_in_ram_or<T, E>(slice: *const [T], err: E) -> Result<(), E> {
18 if slice_in_ram(slice) { 18 if slice_in_ram(slice) { Ok(()) } else { Err(err) }
19 Ok(())
20 } else {
21 Err(err)
22 }
23} 19}
diff --git a/embassy-nrf/src/wdt.rs b/embassy-nrf/src/wdt.rs
index dc99a16f5..6afd73431 100644
--- a/embassy-nrf/src/wdt.rs
+++ b/embassy-nrf/src/wdt.rs
@@ -11,7 +11,7 @@ use embassy_hal_internal::PeripheralType;
11 11
12use crate::pac::wdt::vals; 12use crate::pac::wdt::vals;
13pub use crate::pac::wdt::vals::{Halt as HaltConfig, Sleep as SleepConfig}; 13pub use crate::pac::wdt::vals::{Halt as HaltConfig, Sleep as SleepConfig};
14use crate::{interrupt, pac, peripherals, Peri}; 14use crate::{Peri, interrupt, pac, peripherals};
15 15
16const MIN_TICKS: u32 = 15; 16const MIN_TICKS: u32 = 15;
17 17