diff options
| author | Michael Kefeder <[email protected]> | 2025-09-28 18:32:40 +0200 |
|---|---|---|
| committer | Michael Kefeder <[email protected]> | 2025-09-29 21:24:34 +0200 |
| commit | 8fae6f5a3f7055dc8250cd8926624010b14db6dc (patch) | |
| tree | 8efee5340798565cf5a0e13293e1766f5156c6d9 /embassy-nrf/src | |
| parent | b29c7295e406045ec137b78ca5f220bf7909006b (diff) | |
Reset SAADC in Drop impl for nrf52, workaround for anomaly 241.
Diffstat (limited to 'embassy-nrf/src')
| -rw-r--r-- | embassy-nrf/src/saadc.rs | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/embassy-nrf/src/saadc.rs b/embassy-nrf/src/saadc.rs index 92b6fb01f..d84246572 100644 --- a/embassy-nrf/src/saadc.rs +++ b/embassy-nrf/src/saadc.rs | |||
| @@ -457,6 +457,19 @@ impl<'d> Saadc<'d, 1> { | |||
| 457 | 457 | ||
| 458 | impl<'d, const N: usize> Drop for Saadc<'d, N> { | 458 | impl<'d, const N: usize> Drop for Saadc<'d, N> { |
| 459 | fn drop(&mut self) { | 459 | fn drop(&mut self) { |
| 460 | // Reset of SAADC. | ||
| 461 | // | ||
| 462 | // This is needed when more than one pin is sampled to avoid needless power consumption. | ||
| 463 | // More information can be found in [nrf52 Anomaly 241](https://docs.nordicsemi.com/bundle/errata_nRF52810_Rev1/page/ERR/nRF52810/Rev1/latest/anomaly_810_241.html). | ||
| 464 | // The workaround seems like it copies the configuration before reset and reapplies it after. | ||
| 465 | // This method consumes the instance forcing a reconfiguration at compile time, hence we only | ||
| 466 | // call what is the reset portion of the workaround. | ||
| 467 | #[cfg(feature = "_nrf52")] | ||
| 468 | { | ||
| 469 | unsafe { core::ptr::write_volatile(0x40007FFC as *mut u32, 0) } | ||
| 470 | unsafe { core::ptr::read_volatile(0x40007FFC as *const ()) } | ||
| 471 | unsafe { core::ptr::write_volatile(0x40007FFC as *mut u32, 1) } | ||
| 472 | } | ||
| 460 | let r = Self::regs(); | 473 | let r = Self::regs(); |
| 461 | r.enable().write(|w| w.set_enable(false)); | 474 | r.enable().write(|w| w.set_enable(false)); |
| 462 | for i in 0..N { | 475 | for i in 0..N { |
