diff options
| author | Dario Nieuwenhuis <[email protected]> | 2025-02-05 00:48:35 +0100 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2025-02-05 00:57:43 +0100 |
| commit | 9da04cc38ea5cc17740bd9921f9f5cbb1c689a31 (patch) | |
| tree | 2c4c507f2beb9293abc4e01262a3d1dcfa507175 /embassy-rp | |
| parent | bb2d9ec7f81bbf0d83e873d53eb37f9d0b359f3b (diff) | |
rp: make atomics work properly between cores in rp235x.
Diffstat (limited to 'embassy-rp')
| -rw-r--r-- | embassy-rp/src/lib.rs | 18 | ||||
| -rw-r--r-- | embassy-rp/src/multicore.rs | 4 |
2 files changed, 22 insertions, 0 deletions
diff --git a/embassy-rp/src/lib.rs b/embassy-rp/src/lib.rs index 8b0023ea5..80ee47802 100644 --- a/embassy-rp/src/lib.rs +++ b/embassy-rp/src/lib.rs | |||
| @@ -656,9 +656,27 @@ unsafe fn pre_init() { | |||
| 656 | // We can still use PSM to reset PROC1 since it comes after PROC0 in the state machine. | 656 | // We can still use PSM to reset PROC1 since it comes after PROC0 in the state machine. |
| 657 | pac::PSM.frce_off().write_and_wait(|w| w.set_proc1(true)); | 657 | pac::PSM.frce_off().write_and_wait(|w| w.set_proc1(true)); |
| 658 | pac::PSM.frce_off().write_and_wait(|_| {}); | 658 | pac::PSM.frce_off().write_and_wait(|_| {}); |
| 659 | |||
| 660 | // Make atomics work between cores. | ||
| 661 | enable_actlr_extexclall(); | ||
| 659 | } | 662 | } |
| 660 | } | 663 | } |
| 661 | 664 | ||
| 665 | /// Set the EXTEXCLALL bit in ACTLR. | ||
| 666 | /// | ||
| 667 | /// The default MPU memory map marks all memory as non-shareable, so atomics don't | ||
| 668 | /// synchronize memory accesses between cores at all. This bit forces all memory to be | ||
| 669 | /// considered shareable regardless of what the MPU says. | ||
| 670 | /// | ||
| 671 | /// TODO: does this interfere somehow if the user wants to use a custom MPU configuration? | ||
| 672 | /// maybe we need to add a way to disable this? | ||
| 673 | /// | ||
| 674 | /// This must be done FOR EACH CORE. | ||
| 675 | #[cfg(feature = "_rp235x")] | ||
| 676 | unsafe fn enable_actlr_extexclall() { | ||
| 677 | (&*cortex_m::peripheral::ICB::PTR).actlr.modify(|w| w | (1 << 29)); | ||
| 678 | } | ||
| 679 | |||
| 662 | /// Extension trait for PAC regs, adding atomic xor/bitset/bitclear writes. | 680 | /// Extension trait for PAC regs, adding atomic xor/bitset/bitclear writes. |
| 663 | #[allow(unused)] | 681 | #[allow(unused)] |
| 664 | trait RegExt<T: Copy> { | 682 | trait RegExt<T: Copy> { |
diff --git a/embassy-rp/src/multicore.rs b/embassy-rp/src/multicore.rs index ea0a29a36..1450505b9 100644 --- a/embassy-rp/src/multicore.rs +++ b/embassy-rp/src/multicore.rs | |||
| @@ -65,6 +65,10 @@ unsafe fn core1_setup(stack_bottom: *mut usize) { | |||
| 65 | // embassy, somehow. trap if so since we can't deal with that. | 65 | // embassy, somehow. trap if so since we can't deal with that. |
| 66 | cortex_m::asm::udf(); | 66 | cortex_m::asm::udf(); |
| 67 | } | 67 | } |
| 68 | |||
| 69 | #[cfg(feature = "_rp235x")] | ||
| 70 | crate::enable_actlr_extexclall(); | ||
| 71 | |||
| 68 | unsafe { | 72 | unsafe { |
| 69 | gpio::init(); | 73 | gpio::init(); |
| 70 | } | 74 | } |
