aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPriit Laes <[email protected]>2023-09-22 17:30:09 +0300
committerNils Fitinghoff <[email protected]>2023-09-22 17:02:21 +0200
commit6f83acc010786d89400426c3395f871ac7199d32 (patch)
treef18184c7417140e8466e72d78609348ca44d447e
parent2b7b7a917d0fc5917cb968c52bd19d710675f540 (diff)
Add separate work-around specific flag for DMA errata on NRF52832
-rw-r--r--embassy-nrf/Cargo.toml5
-rw-r--r--embassy-nrf/src/spim.rs21
2 files changed, 14 insertions, 12 deletions
diff --git a/embassy-nrf/Cargo.toml b/embassy-nrf/Cargo.toml
index eee927211..3c706b473 100644
--- a/embassy-nrf/Cargo.toml
+++ b/embassy-nrf/Cargo.toml
@@ -51,7 +51,7 @@ nrf52805 = ["nrf52805-pac", "_nrf52"]
51nrf52810 = ["nrf52810-pac", "_nrf52"] 51nrf52810 = ["nrf52810-pac", "_nrf52"]
52nrf52811 = ["nrf52811-pac", "_nrf52"] 52nrf52811 = ["nrf52811-pac", "_nrf52"]
53nrf52820 = ["nrf52820-pac", "_nrf52"] 53nrf52820 = ["nrf52820-pac", "_nrf52"]
54nrf52832 = ["nrf52832-pac", "_nrf52"] 54nrf52832 = ["nrf52832-pac", "_nrf52", "_nrf52832_anomaly_109"]
55nrf52833 = ["nrf52833-pac", "_nrf52", "_gpio-p1"] 55nrf52833 = ["nrf52833-pac", "_nrf52", "_gpio-p1"]
56nrf52840 = ["nrf52840-pac", "_nrf52", "_gpio-p1"] 56nrf52840 = ["nrf52840-pac", "_nrf52", "_gpio-p1"]
57nrf5340-app-s = ["_nrf5340-app", "_s"] 57nrf5340-app-s = ["_nrf5340-app", "_s"]
@@ -90,6 +90,9 @@ _ppi = []
90_dppi = [] 90_dppi = []
91_gpio-p1 = [] 91_gpio-p1 = []
92 92
93# Errata workarounds
94_nrf52832_anomaly_109 = []
95
93[dependencies] 96[dependencies]
94embassy-time = { version = "0.1.3", path = "../embassy-time", optional = true } 97embassy-time = { version = "0.1.3", path = "../embassy-time", optional = true }
95embassy-sync = { version = "0.3.0", path = "../embassy-sync" } 98embassy-sync = { version = "0.3.0", path = "../embassy-sync" }
diff --git a/embassy-nrf/src/spim.rs b/embassy-nrf/src/spim.rs
index a0d2c8eb1..4828af43e 100644
--- a/embassy-nrf/src/spim.rs
+++ b/embassy-nrf/src/spim.rs
@@ -68,7 +68,7 @@ impl<T: Instance> interrupt::typelevel::Handler<T::Interrupt> for InterruptHandl
68 let r = T::regs(); 68 let r = T::regs();
69 let s = T::state(); 69 let s = T::state();
70 70
71 #[cfg(feature = "nrf52832")] 71 #[cfg(feature = "_nrf52832_anomaly_109")]
72 if r.events_started.read().bits() != 0 { 72 if r.events_started.read().bits() != 0 {
73 s.waker.wake(); 73 s.waker.wake();
74 r.intenclr.write(|w| w.started().clear()); 74 r.intenclr.write(|w| w.started().clear());
@@ -206,8 +206,7 @@ impl<'d, T: Instance> Spim<'d, T> {
206 r.rxd.ptr.write(|w| unsafe { w.ptr().bits(ptr as _) }); 206 r.rxd.ptr.write(|w| unsafe { w.ptr().bits(ptr as _) });
207 r.rxd.maxcnt.write(|w| unsafe { w.maxcnt().bits(rx_len as _) }); 207 r.rxd.maxcnt.write(|w| unsafe { w.maxcnt().bits(rx_len as _) });
208 208
209 // ANOMALY 109 workaround 209 #[cfg(feature = "_nrf52832_anomaly_109")]
210 #[cfg(feature = "nrf52832")]
211 { 210 {
212 let s = T::state(); 211 let s = T::state();
213 212
@@ -238,7 +237,7 @@ impl<'d, T: Instance> Spim<'d, T> {
238 fn blocking_inner_from_ram(&mut self, rx: *mut [u8], tx: *const [u8]) -> Result<(), Error> { 237 fn blocking_inner_from_ram(&mut self, rx: *mut [u8], tx: *const [u8]) -> Result<(), Error> {
239 self.prepare(rx, tx)?; 238 self.prepare(rx, tx)?;
240 239
241 #[cfg(feature = "nrf52832")] 240 #[cfg(feature = "_nrf52832_anomaly_109")]
242 while let Poll::Pending = self.nrf52832_dma_workaround_status() {} 241 while let Poll::Pending = self.nrf52832_dma_workaround_status() {}
243 242
244 // Wait for 'end' event. 243 // Wait for 'end' event.
@@ -265,7 +264,7 @@ impl<'d, T: Instance> Spim<'d, T> {
265 async fn async_inner_from_ram(&mut self, rx: *mut [u8], tx: *const [u8]) -> Result<(), Error> { 264 async fn async_inner_from_ram(&mut self, rx: *mut [u8], tx: *const [u8]) -> Result<(), Error> {
266 self.prepare(rx, tx)?; 265 self.prepare(rx, tx)?;
267 266
268 #[cfg(feature = "nrf52832")] 267 #[cfg(feature = "_nrf52832_anomaly_109")]
269 poll_fn(|cx| { 268 poll_fn(|cx| {
270 let s = T::state(); 269 let s = T::state();
271 270
@@ -369,7 +368,7 @@ impl<'d, T: Instance> Spim<'d, T> {
369 self.async_inner_from_ram(&mut [], data).await 368 self.async_inner_from_ram(&mut [], data).await
370 } 369 }
371 370
372 #[cfg(feature = "nrf52832")] 371 #[cfg(feature = "_nrf52832_anomaly_109")]
373 fn nrf52832_dma_workaround_status(&mut self) -> Poll<()> { 372 fn nrf52832_dma_workaround_status(&mut self) -> Poll<()> {
374 let r = T::regs(); 373 let r = T::regs();
375 if r.events_started.read().bits() != 0 { 374 if r.events_started.read().bits() != 0 {
@@ -418,7 +417,7 @@ impl<'d, T: Instance> Drop for Spim<'d, T> {
418} 417}
419 418
420pub(crate) mod sealed { 419pub(crate) mod sealed {
421 #[cfg(feature = "nrf52832")] 420 #[cfg(feature = "_nrf52832_anomaly_109")]
422 use core::sync::atomic::AtomicU8; 421 use core::sync::atomic::AtomicU8;
423 422
424 use embassy_sync::waitqueue::AtomicWaker; 423 use embassy_sync::waitqueue::AtomicWaker;
@@ -427,9 +426,9 @@ pub(crate) mod sealed {
427 426
428 pub struct State { 427 pub struct State {
429 pub waker: AtomicWaker, 428 pub waker: AtomicWaker,
430 #[cfg(feature = "nrf52832")] 429 #[cfg(feature = "_nrf52832_anomaly_109")]
431 pub rx: AtomicU8, 430 pub rx: AtomicU8,
432 #[cfg(feature = "nrf52832")] 431 #[cfg(feature = "_nrf52832_anomaly_109")]
433 pub tx: AtomicU8, 432 pub tx: AtomicU8,
434 } 433 }
435 434
@@ -437,9 +436,9 @@ pub(crate) mod sealed {
437 pub const fn new() -> Self { 436 pub const fn new() -> Self {
438 Self { 437 Self {
439 waker: AtomicWaker::new(), 438 waker: AtomicWaker::new(),
440 #[cfg(feature = "nrf52832")] 439 #[cfg(feature = "_nrf52832_anomaly_109")]
441 rx: AtomicU8::new(0), 440 rx: AtomicU8::new(0),
442 #[cfg(feature = "nrf52832")] 441 #[cfg(feature = "_nrf52832_anomaly_109")]
443 tx: AtomicU8::new(0), 442 tx: AtomicU8::new(0),
444 } 443 }
445 } 444 }