diff options
| author | Matous Hybl <[email protected]> | 2022-10-18 22:42:02 +0200 |
|---|---|---|
| committer | Matous Hybl <[email protected]> | 2022-10-18 22:42:02 +0200 |
| commit | 6c5d81ada52bfac1592c7be025038a3eea3acc42 (patch) | |
| tree | 7f41b9583e614bc036f29605e1c15478968dcf8d | |
| parent | 18453ee64c7d1b397aa96cb322cedee6166b4602 (diff) | |
Add memory barriers to H7 flash driver to mitigate PGSERR errors
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.
| -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 | ||
