diff options
| author | Rasmus Melchior Jacobsen <[email protected]> | 2023-04-01 18:10:20 +0200 |
|---|---|---|
| committer | Rasmus Melchior Jacobsen <[email protected]> | 2023-04-01 18:10:20 +0200 |
| commit | dd88775871d2946df6e7e06bf2b536e94973dbaa (patch) | |
| tree | da149271d94c55a216a07c3728601bc456e0873f /embassy-stm32 | |
| parent | e11eebfa577b143b8a19fcf6d9d5398c3058c3eb (diff) | |
Ensure that flash locking is defered to after write
Diffstat (limited to 'embassy-stm32')
| -rw-r--r-- | embassy-stm32/src/flash/common.rs | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/embassy-stm32/src/flash/common.rs b/embassy-stm32/src/flash/common.rs index 287c54f55..41c28c561 100644 --- a/embassy-stm32/src/flash/common.rs +++ b/embassy-stm32/src/flash/common.rs | |||
| @@ -1,3 +1,4 @@ | |||
| 1 | use atomic_polyfill::{fence, Ordering}; | ||
| 1 | use embassy_hal_common::drop::OnDrop; | 2 | use embassy_hal_common::drop::OnDrop; |
| 2 | use embassy_hal_common::{into_ref, PeripheralRef}; | 3 | use embassy_hal_common::{into_ref, PeripheralRef}; |
| 3 | 4 | ||
| @@ -74,12 +75,18 @@ unsafe fn blocking_write(base: u32, size: u32, offset: u32, bytes: &[u8]) -> Res | |||
| 74 | for chunk in bytes.chunks(WRITE_SIZE) { | 75 | for chunk in bytes.chunks(WRITE_SIZE) { |
| 75 | critical_section::with(|_| { | 76 | critical_section::with(|_| { |
| 76 | family::clear_all_err(); | 77 | family::clear_all_err(); |
| 78 | fence(Ordering::SeqCst); | ||
| 77 | family::unlock(); | 79 | family::unlock(); |
| 80 | fence(Ordering::SeqCst); | ||
| 78 | family::begin_write(); | 81 | family::begin_write(); |
| 79 | let _ = OnDrop::new(|| { | 82 | fence(Ordering::SeqCst); |
| 83 | |||
| 84 | let _on_drop = OnDrop::new(|| { | ||
| 80 | family::end_write(); | 85 | family::end_write(); |
| 86 | fence(Ordering::SeqCst); | ||
| 81 | family::lock(); | 87 | family::lock(); |
| 82 | }); | 88 | }); |
| 89 | |||
| 83 | family::blocking_write(address, chunk.try_into().unwrap()) | 90 | family::blocking_write(address, chunk.try_into().unwrap()) |
| 84 | })?; | 91 | })?; |
| 85 | address += WRITE_SIZE as u32; | 92 | address += WRITE_SIZE as u32; |
| @@ -114,10 +121,14 @@ unsafe fn blocking_erase(base: u32, from: u32, to: u32) -> Result<(), Error> { | |||
| 114 | 121 | ||
| 115 | critical_section::with(|_| { | 122 | critical_section::with(|_| { |
| 116 | family::clear_all_err(); | 123 | family::clear_all_err(); |
| 124 | fence(Ordering::SeqCst); | ||
| 117 | family::unlock(); | 125 | family::unlock(); |
| 118 | let _ = OnDrop::new(|| { | 126 | fence(Ordering::SeqCst); |
| 127 | |||
| 128 | let _on_drop = OnDrop::new(|| { | ||
| 119 | family::lock(); | 129 | family::lock(); |
| 120 | }); | 130 | }); |
| 131 | |||
| 121 | family::blocking_erase_sector(§or) | 132 | family::blocking_erase_sector(§or) |
| 122 | })?; | 133 | })?; |
| 123 | address += sector.size; | 134 | address += sector.size; |
