diff options
| author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2022-10-19 07:29:12 +0000 |
|---|---|---|
| committer | GitHub <[email protected]> | 2022-10-19 07:29:12 +0000 |
| commit | d9c773f47598666c322a5e25c1f3d2681c3d3c01 (patch) | |
| tree | 01c3a1a35dc8624f661c1bf9843f3df0de82536a | |
| parent | a669f4cfd8b178e924482cf008d5eaec7889e415 (diff) | |
| parent | 6c5d81ada52bfac1592c7be025038a3eea3acc42 (diff) | |
Merge #1014
1014: Add memory barriers to H7 flash driver to mitigate PGSERR errors r=lulf a=matoushybl
The stm32h7xx-hal uses only the ordering barrier, while the CubeMX uses the DSB and ISB instructions, to be on the safe side, both are used here.
Without the barrier, the PG bit is not set, when the writes are being done, resulting in an error.
Co-authored-by: Matous Hybl <[email protected]>
| -rw-r--r-- | embassy-stm32/src/flash/h7.rs | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/embassy-stm32/src/flash/h7.rs b/embassy-stm32/src/flash/h7.rs index 7ce0ac776..3f2129de8 100644 --- a/embassy-stm32/src/flash/h7.rs +++ b/embassy-stm32/src/flash/h7.rs | |||
| @@ -39,6 +39,10 @@ pub(crate) unsafe fn blocking_write(offset: u32, buf: &[u8]) -> Result<(), Error | |||
| 39 | w.set_psize(2); // 32 bits at once | 39 | w.set_psize(2); // 32 bits at once |
| 40 | }); | 40 | }); |
| 41 | 41 | ||
| 42 | cortex_m::asm::isb(); | ||
| 43 | cortex_m::asm::dsb(); | ||
| 44 | atomic_polyfill::fence(atomic_polyfill::Ordering::SeqCst); | ||
| 45 | |||
| 42 | let ret = { | 46 | let ret = { |
| 43 | let mut ret: Result<(), Error> = Ok(()); | 47 | let mut ret: Result<(), Error> = Ok(()); |
| 44 | let mut offset = offset; | 48 | let mut offset = offset; |
| @@ -64,6 +68,10 @@ pub(crate) unsafe fn blocking_write(offset: u32, buf: &[u8]) -> Result<(), Error | |||
| 64 | 68 | ||
| 65 | bank.cr().write(|w| w.set_pg(false)); | 69 | bank.cr().write(|w| w.set_pg(false)); |
| 66 | 70 | ||
| 71 | cortex_m::asm::isb(); | ||
| 72 | cortex_m::asm::dsb(); | ||
| 73 | atomic_polyfill::fence(atomic_polyfill::Ordering::SeqCst); | ||
| 74 | |||
| 67 | ret | 75 | ret |
| 68 | } | 76 | } |
| 69 | 77 | ||
