Skip to content

Commit e9534ac

Browse files
Liamoluckojannic
andcommitted
Add a fence after writing the arguments to the stack
Co-authored-by: Jan Niehusmann <[email protected]>
1 parent 9848f84 commit e9534ac

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

rp2040-hal/src/multicore.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
//! For a detailed example, see [examples/multicore_fifo_blink.rs](https://github.com/rp-rs/rp-hal/tree/main/rp2040-hal/examples/multicore_fifo_blink.rs)
3636
3737
use core::mem::ManuallyDrop;
38+
use core::sync::atomic::compiler_fence;
39+
use core::sync::atomic::Ordering;
3840

3941
use crate::pac;
4042
use crate::Sio;
@@ -194,6 +196,15 @@ impl<'p> Core<'p> {
194196
stack_ptr.cast::<&mut ManuallyDrop<F>>().write(&mut entry);
195197
}
196198

199+
// Make sure the compiler does not reorder the stack writes after to after the
200+
// below FIFO writes, which would result in them not being seen by the second
201+
// core.
202+
//
203+
// From the compiler perspective, this doesn't guarantee that the second core
204+
// actually sees those writes. However, we know that the RP2040 doesn't have
205+
// memory caches, and writes happen in-order.
206+
compiler_fence(Ordering::Release);
207+
197208
let vector_table = ppb.vtor.read().bits();
198209

199210
// After reset, core 1 is waiting to receive commands over FIFO.

0 commit comments

Comments
 (0)