diff options
| author | Dario Nieuwenhuis <[email protected]> | 2025-03-02 21:12:30 +0000 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-03-02 21:12:30 +0000 |
| commit | 75c1ca2fa41dcc9362a71473274cc7d6bcaeba74 (patch) | |
| tree | c2d0aaf63e5f262cf50e9c1fbc12240a115ada3d /embassy-nrf | |
| parent | 207dbcc7aefb82b03bbd0f8bc25496eb32cd52e6 (diff) | |
| parent | 26c689db3e62d6c72063ee34e6fc3b7f7f6d310f (diff) | |
Merge pull request #3937 from 0e4ef622/nrf53-vreghvout
nrf5340: add regh_voltage config
Diffstat (limited to 'embassy-nrf')
| -rw-r--r-- | embassy-nrf/src/lib.rs | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/embassy-nrf/src/lib.rs b/embassy-nrf/src/lib.rs index 23888b390..dad975470 100644 --- a/embassy-nrf/src/lib.rs +++ b/embassy-nrf/src/lib.rs | |||
| @@ -347,12 +347,33 @@ pub mod config { | |||
| 347 | pub struct DcdcConfig { | 347 | pub struct DcdcConfig { |
| 348 | /// Config for the high voltage stage, if disabled LDO will be used. | 348 | /// Config for the high voltage stage, if disabled LDO will be used. |
| 349 | pub regh: bool, | 349 | pub regh: bool, |
| 350 | /// Configure the voltage of the high voltage stage. It is stored in non-volatile memory (UICR.VREGHVOUT register); pass None to not touch it. | ||
| 351 | #[cfg(feature = "nrf5340-app-s")] | ||
| 352 | pub regh_voltage: Option<ReghVoltage>, | ||
| 350 | /// Config for the main rail, if disabled LDO will be used. | 353 | /// Config for the main rail, if disabled LDO will be used. |
| 351 | pub regmain: bool, | 354 | pub regmain: bool, |
| 352 | /// Config for the radio rail, if disabled LDO will be used. | 355 | /// Config for the radio rail, if disabled LDO will be used. |
| 353 | pub regradio: bool, | 356 | pub regradio: bool, |
| 354 | } | 357 | } |
| 355 | 358 | ||
| 359 | /// Output voltage setting for VREGH regulator stage. | ||
| 360 | #[cfg(feature = "nrf5340-app-s")] | ||
| 361 | pub enum ReghVoltage { | ||
| 362 | /// 1.8 V | ||
| 363 | _1V8 = 0, | ||
| 364 | /// 2.1 V | ||
| 365 | _2V1 = 1, | ||
| 366 | /// 2.4 V | ||
| 367 | _2V4 = 2, | ||
| 368 | /// 2.7 V | ||
| 369 | _2V7 = 3, | ||
| 370 | /// 3.0 V | ||
| 371 | _3V0 = 4, | ||
| 372 | /// 3.3 V | ||
| 373 | _3v3 = 5, | ||
| 374 | //ERASED = 7, means 1.8V | ||
| 375 | } | ||
| 376 | |||
| 356 | /// Settings for enabling the built in DCDC converter. | 377 | /// Settings for enabling the built in DCDC converter. |
| 357 | #[cfg(feature = "_nrf91")] | 378 | #[cfg(feature = "_nrf91")] |
| 358 | pub struct DcdcConfig { | 379 | pub struct DcdcConfig { |
| @@ -399,6 +420,8 @@ pub mod config { | |||
| 399 | #[cfg(feature = "_nrf5340-app")] | 420 | #[cfg(feature = "_nrf5340-app")] |
| 400 | dcdc: DcdcConfig { | 421 | dcdc: DcdcConfig { |
| 401 | regh: false, | 422 | regh: false, |
| 423 | #[cfg(feature = "nrf5340-app-s")] | ||
| 424 | regh_voltage: None, | ||
| 402 | regmain: false, | 425 | regmain: false, |
| 403 | regradio: false, | 426 | regradio: false, |
| 404 | }, | 427 | }, |
| @@ -431,6 +454,7 @@ mod consts { | |||
| 431 | #[allow(unused)] | 454 | #[allow(unused)] |
| 432 | mod consts { | 455 | mod consts { |
| 433 | pub const UICR_APPROTECT: *mut u32 = 0x00FF8000 as *mut u32; | 456 | pub const UICR_APPROTECT: *mut u32 = 0x00FF8000 as *mut u32; |
| 457 | pub const UICR_VREGHVOUT: *mut u32 = 0x00FF8010 as *mut u32; | ||
| 434 | pub const UICR_SECUREAPPROTECT: *mut u32 = 0x00FF801C as *mut u32; | 458 | pub const UICR_SECUREAPPROTECT: *mut u32 = 0x00FF801C as *mut u32; |
| 435 | pub const UICR_NFCPINS: *mut u32 = 0x00FF8028 as *mut u32; | 459 | pub const UICR_NFCPINS: *mut u32 = 0x00FF8028 as *mut u32; |
| 436 | pub const APPROTECT_ENABLED: u32 = 0x0000_0000; | 460 | pub const APPROTECT_ENABLED: u32 = 0x0000_0000; |
| @@ -683,6 +707,21 @@ pub fn init(config: config::Config) -> Peripherals { | |||
| 683 | } | 707 | } |
| 684 | } | 708 | } |
| 685 | 709 | ||
| 710 | #[cfg(feature = "nrf5340-app-s")] | ||
| 711 | unsafe { | ||
| 712 | if let Some(value) = config.dcdc.regh_voltage { | ||
| 713 | let value = value as u32; | ||
| 714 | let res = uicr_write_masked(consts::UICR_VREGHVOUT, value, 0b00000000_00000000_00000000_00000111); | ||
| 715 | needs_reset |= res == WriteResult::Written; | ||
| 716 | if res == WriteResult::Failed { | ||
| 717 | warn!( | ||
| 718 | "Failed to set regulator voltage, as UICR is already programmed to some other setting, and can't be changed without erasing it.\n\ | ||
| 719 | To fix this, erase UICR manually, for example using `probe-rs erase` or `nrfjprog --eraseuicr`." | ||
| 720 | ); | ||
| 721 | } | ||
| 722 | } | ||
| 723 | } | ||
| 724 | |||
| 686 | if needs_reset { | 725 | if needs_reset { |
| 687 | cortex_m::peripheral::SCB::sys_reset(); | 726 | cortex_m::peripheral::SCB::sys_reset(); |
| 688 | } | 727 | } |
