diff options
| -rw-r--r-- | embassy-stm32/Cargo.toml | 2 | ||||
| -rw-r--r-- | embassy-stm32/src/lib.rs | 32 | ||||
| -rw-r--r-- | embassy-stm32/src/rcc/mod.rs | 4 | ||||
| -rw-r--r-- | examples/stm32h755cm4/memory.x | 1 | ||||
| -rw-r--r-- | examples/stm32h755cm4/src/bin/blinky.rs | 2 | ||||
| -rw-r--r-- | examples/stm32h755cm7/memory.x | 1 | ||||
| -rw-r--r-- | examples/stm32h755cm7/src/bin/blinky.rs | 2 |
7 files changed, 22 insertions, 22 deletions
diff --git a/embassy-stm32/Cargo.toml b/embassy-stm32/Cargo.toml index a72a1a667..30f486ccc 100644 --- a/embassy-stm32/Cargo.toml +++ b/embassy-stm32/Cargo.toml | |||
| @@ -80,7 +80,7 @@ stm32-fmc = "0.3.0" | |||
| 80 | cfg-if = "1.0.0" | 80 | cfg-if = "1.0.0" |
| 81 | embedded-io = { version = "0.6.0" } | 81 | embedded-io = { version = "0.6.0" } |
| 82 | embedded-io-async = { version = "0.6.1" } | 82 | embedded-io-async = { version = "0.6.1" } |
| 83 | chrono = { version = "^0.4", default-features = false, optional = true} | 83 | chrono = { version = "^0.4", default-features = false, optional = true } |
| 84 | bit_field = "0.10.2" | 84 | bit_field = "0.10.2" |
| 85 | document-features = "0.2.7" | 85 | document-features = "0.2.7" |
| 86 | 86 | ||
diff --git a/embassy-stm32/src/lib.rs b/embassy-stm32/src/lib.rs index 03c0eda1d..12ebbae2d 100644 --- a/embassy-stm32/src/lib.rs +++ b/embassy-stm32/src/lib.rs | |||
| @@ -280,6 +280,7 @@ pub fn init(config: Config) -> Peripherals { | |||
| 280 | 280 | ||
| 281 | #[cfg(feature = "_dual-core")] | 281 | #[cfg(feature = "_dual-core")] |
| 282 | mod dual_core { | 282 | mod dual_core { |
| 283 | use core::cell::UnsafeCell; | ||
| 283 | use core::mem::MaybeUninit; | 284 | use core::mem::MaybeUninit; |
| 284 | use core::sync::atomic::{AtomicUsize, Ordering}; | 285 | use core::sync::atomic::{AtomicUsize, Ordering}; |
| 285 | 286 | ||
| @@ -301,9 +302,11 @@ mod dual_core { | |||
| 301 | /// This static must be placed in the same position for both cores. How and where this is done is left to the user. | 302 | /// This static must be placed in the same position for both cores. How and where this is done is left to the user. |
| 302 | pub struct SharedData { | 303 | pub struct SharedData { |
| 303 | init_flag: AtomicUsize, | 304 | init_flag: AtomicUsize, |
| 304 | clocks: MaybeUninit<Clocks>, | 305 | clocks: UnsafeCell<MaybeUninit<Clocks>>, |
| 305 | } | 306 | } |
| 306 | 307 | ||
| 308 | unsafe impl Sync for SharedData {} | ||
| 309 | |||
| 307 | const INIT_DONE_FLAG: usize = 0xca11ab1e; | 310 | const INIT_DONE_FLAG: usize = 0xca11ab1e; |
| 308 | 311 | ||
| 309 | /// Initialize the `embassy-stm32` HAL with the provided configuration. | 312 | /// Initialize the `embassy-stm32` HAL with the provided configuration. |
| @@ -319,7 +322,7 @@ mod dual_core { | |||
| 319 | pub fn init_primary(config: Config, shared_data: &'static MaybeUninit<SharedData>) -> Peripherals { | 322 | pub fn init_primary(config: Config, shared_data: &'static MaybeUninit<SharedData>) -> Peripherals { |
| 320 | let shared_data = unsafe { shared_data.assume_init_ref() }; | 323 | let shared_data = unsafe { shared_data.assume_init_ref() }; |
| 321 | 324 | ||
| 322 | rcc::set_freqs_ptr(&shared_data.clocks); | 325 | rcc::set_freqs_ptr(shared_data.clocks.get()); |
| 323 | let p = init_hw(config); | 326 | let p = init_hw(config); |
| 324 | 327 | ||
| 325 | shared_data.init_flag.store(INIT_DONE_FLAG, Ordering::SeqCst); | 328 | shared_data.init_flag.store(INIT_DONE_FLAG, Ordering::SeqCst); |
| @@ -339,14 +342,13 @@ mod dual_core { | |||
| 339 | pub fn try_init_secondary(shared_data: &'static MaybeUninit<SharedData>) -> Option<Peripherals> { | 342 | pub fn try_init_secondary(shared_data: &'static MaybeUninit<SharedData>) -> Option<Peripherals> { |
| 340 | let shared_data = unsafe { shared_data.assume_init_ref() }; | 343 | let shared_data = unsafe { shared_data.assume_init_ref() }; |
| 341 | 344 | ||
| 342 | if shared_data | 345 | if shared_data.init_flag.load(Ordering::SeqCst) != INIT_DONE_FLAG { |
| 343 | .init_flag | ||
| 344 | .compare_exchange(INIT_DONE_FLAG, 0, Ordering::SeqCst, Ordering::SeqCst) | ||
| 345 | .is_err() | ||
| 346 | { | ||
| 347 | return None; | 346 | return None; |
| 348 | } | 347 | } |
| 349 | 348 | ||
| 349 | // Separate load and store to support the CM0 of the STM32WL | ||
| 350 | shared_data.init_flag.store(0, Ordering::SeqCst); | ||
| 351 | |||
| 350 | Some(init_secondary_hw(shared_data)) | 352 | Some(init_secondary_hw(shared_data)) |
| 351 | } | 353 | } |
| 352 | 354 | ||
| @@ -360,19 +362,15 @@ mod dual_core { | |||
| 360 | /// The `shared_data` is used to coordinate the init with the second core. Read the [SharedData] docs | 362 | /// The `shared_data` is used to coordinate the init with the second core. Read the [SharedData] docs |
| 361 | /// for more information on its requirements. | 363 | /// for more information on its requirements. |
| 362 | pub fn init_secondary(shared_data: &'static MaybeUninit<SharedData>) -> Peripherals { | 364 | pub fn init_secondary(shared_data: &'static MaybeUninit<SharedData>) -> Peripherals { |
| 363 | let shared_data = unsafe { shared_data.assume_init_ref() }; | 365 | loop { |
| 364 | 366 | if let Some(p) = try_init_secondary(shared_data) { | |
| 365 | while shared_data | 367 | return p; |
| 366 | .init_flag | 368 | } |
| 367 | .compare_exchange(INIT_DONE_FLAG, 0, Ordering::SeqCst, Ordering::SeqCst) | 369 | } |
| 368 | .is_err() | ||
| 369 | {} | ||
| 370 | |||
| 371 | init_secondary_hw(shared_data) | ||
| 372 | } | 370 | } |
| 373 | 371 | ||
| 374 | fn init_secondary_hw(shared_data: &'static SharedData) -> Peripherals { | 372 | fn init_secondary_hw(shared_data: &'static SharedData) -> Peripherals { |
| 375 | rcc::set_freqs_ptr(&shared_data.clocks); | 373 | rcc::set_freqs_ptr(shared_data.clocks.get()); |
| 376 | 374 | ||
| 377 | // We use different timers on the different cores, so we have to still initialize one here | 375 | // We use different timers on the different cores, so we have to still initialize one here |
| 378 | #[cfg(feature = "_time-driver")] | 376 | #[cfg(feature = "_time-driver")] |
diff --git a/embassy-stm32/src/rcc/mod.rs b/embassy-stm32/src/rcc/mod.rs index 0656619b1..8022a35a4 100644 --- a/embassy-stm32/src/rcc/mod.rs +++ b/embassy-stm32/src/rcc/mod.rs | |||
| @@ -59,8 +59,8 @@ static CLOCK_FREQS_PTR: core::sync::atomic::AtomicPtr<MaybeUninit<Clocks>> = | |||
| 59 | core::sync::atomic::AtomicPtr::new(core::ptr::null_mut()); | 59 | core::sync::atomic::AtomicPtr::new(core::ptr::null_mut()); |
| 60 | 60 | ||
| 61 | #[cfg(feature = "_dual-core")] | 61 | #[cfg(feature = "_dual-core")] |
| 62 | pub(crate) fn set_freqs_ptr(freqs: &'static MaybeUninit<Clocks>) { | 62 | pub(crate) fn set_freqs_ptr(freqs: *mut MaybeUninit<Clocks>) { |
| 63 | CLOCK_FREQS_PTR.store(freqs as *const _ as *mut _, core::sync::atomic::Ordering::SeqCst); | 63 | CLOCK_FREQS_PTR.store(freqs, core::sync::atomic::Ordering::SeqCst); |
| 64 | } | 64 | } |
| 65 | 65 | ||
| 66 | #[cfg(not(feature = "_dual-core"))] | 66 | #[cfg(not(feature = "_dual-core"))] |
diff --git a/examples/stm32h755cm4/memory.x b/examples/stm32h755cm4/memory.x index 538bac586..7d60354e3 100644 --- a/examples/stm32h755cm4/memory.x +++ b/examples/stm32h755cm4/memory.x | |||
| @@ -9,6 +9,7 @@ SECTIONS | |||
| 9 | { | 9 | { |
| 10 | .ram_d3 : | 10 | .ram_d3 : |
| 11 | { | 11 | { |
| 12 | *(.ram_d3.shared_data) | ||
| 12 | *(.ram_d3) | 13 | *(.ram_d3) |
| 13 | } > RAM_D3 | 14 | } > RAM_D3 |
| 14 | } \ No newline at end of file | 15 | } \ No newline at end of file |
diff --git a/examples/stm32h755cm4/src/bin/blinky.rs b/examples/stm32h755cm4/src/bin/blinky.rs index f750c5db6..b5c547839 100644 --- a/examples/stm32h755cm4/src/bin/blinky.rs +++ b/examples/stm32h755cm4/src/bin/blinky.rs | |||
| @@ -10,7 +10,7 @@ use embassy_stm32::SharedData; | |||
| 10 | use embassy_time::Timer; | 10 | use embassy_time::Timer; |
| 11 | use {defmt_rtt as _, panic_probe as _}; | 11 | use {defmt_rtt as _, panic_probe as _}; |
| 12 | 12 | ||
| 13 | #[link_section = ".ram_d3"] | 13 | #[link_section = ".ram_d3.shared_data"] |
| 14 | static SHARED_DATA: MaybeUninit<SharedData> = MaybeUninit::uninit(); | 14 | static SHARED_DATA: MaybeUninit<SharedData> = MaybeUninit::uninit(); |
| 15 | 15 | ||
| 16 | #[embassy_executor::main] | 16 | #[embassy_executor::main] |
diff --git a/examples/stm32h755cm7/memory.x b/examples/stm32h755cm7/memory.x index ab2afc216..ef884796a 100644 --- a/examples/stm32h755cm7/memory.x +++ b/examples/stm32h755cm7/memory.x | |||
| @@ -9,6 +9,7 @@ SECTIONS | |||
| 9 | { | 9 | { |
| 10 | .ram_d3 : | 10 | .ram_d3 : |
| 11 | { | 11 | { |
| 12 | *(.ram_d3.shared_data) | ||
| 12 | *(.ram_d3) | 13 | *(.ram_d3) |
| 13 | } > RAM_D3 | 14 | } > RAM_D3 |
| 14 | } \ No newline at end of file | 15 | } \ No newline at end of file |
diff --git a/examples/stm32h755cm7/src/bin/blinky.rs b/examples/stm32h755cm7/src/bin/blinky.rs index f76a136aa..94d2226c0 100644 --- a/examples/stm32h755cm7/src/bin/blinky.rs +++ b/examples/stm32h755cm7/src/bin/blinky.rs | |||
| @@ -10,7 +10,7 @@ use embassy_stm32::SharedData; | |||
| 10 | use embassy_time::Timer; | 10 | use embassy_time::Timer; |
| 11 | use {defmt_rtt as _, panic_probe as _}; | 11 | use {defmt_rtt as _, panic_probe as _}; |
| 12 | 12 | ||
| 13 | #[link_section = ".ram_d3"] | 13 | #[link_section = ".ram_d3.shared_data"] |
| 14 | static SHARED_DATA: MaybeUninit<SharedData> = MaybeUninit::uninit(); | 14 | static SHARED_DATA: MaybeUninit<SharedData> = MaybeUninit::uninit(); |
| 15 | 15 | ||
| 16 | #[embassy_executor::main] | 16 | #[embassy_executor::main] |
