aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--embassy-stm32/build.rs20
1 files changed, 8 insertions, 12 deletions
diff --git a/embassy-stm32/build.rs b/embassy-stm32/build.rs
index cee2d7e92..f88843896 100644
--- a/embassy-stm32/build.rs
+++ b/embassy-stm32/build.rs
@@ -595,20 +595,16 @@ fn main() {
595 #start_rst 595 #start_rst
596 596
597 crate::pac::RCC.#en_reg().modify(|w| w.#set_en_field(true)); 597 crate::pac::RCC.#en_reg().modify(|w| w.#set_en_field(true));
598 // dummy read to ensure write is completed 598
599 // we must wait two peripheral clock cycles before the clock is active
600 // this seems to work, but might be incorrect
601 // see http://efton.sk/STM32/gotcha/g183.html
602
603 // dummy read (like in the ST HALs)
599 let _ = crate::pac::RCC.#en_reg().read(); 604 let _ = crate::pac::RCC.#en_reg().read();
600 605
601 // wait two peripheral clock cycles before the clock is active 606 // DSB for good measure
602 // accomplish this with two dummy reads from the peripheral. this shouldn't 607 cortex_m::asm::dsb();
603 // cause any side effects since the peripheral is in reset
604 unsafe {
605 //apparently volatile accesses to ZST like () can be optimized out. lol
606 let ptr = crate::pac::#pname.as_ptr() as *const usize;
607 let _ = ::core::ptr::read_volatile(ptr);
608 let _ = ::core::ptr::read_volatile(ptr);
609 // wait for memory accesses to finish
610 cortex_m::asm::dsb();
611 }
612 608
613 #end_rst 609 #end_rst
614 } 610 }