diff options
| author | Dario Nieuwenhuis <[email protected]> | 2023-07-31 10:55:30 +0000 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-07-31 10:55:30 +0000 |
| commit | 71fcea159f2b17d9acdaa5b4a5bde9b525de4167 (patch) | |
| tree | ac63749a93f1b596b291b95cca4b65c111384644 | |
| parent | 958cace36dec6d0473c85a4129c871be9e563f2a (diff) | |
| parent | 036e00113e1525060e120394c718b5b5af09434a (diff) | |
Merge pull request #1725 from embassy-rs/flash-pointless-set-bits
stm32/flash: avoid pointless "if flag is set, set it".
| -rw-r--r-- | embassy-stm32/src/flash/f0.rs | 14 | ||||
| -rw-r--r-- | embassy-stm32/src/flash/f3.rs | 14 | ||||
| -rw-r--r-- | embassy-stm32/src/flash/f4.rs | 9 | ||||
| -rw-r--r-- | embassy-stm32/src/flash/f7.rs | 20 | ||||
| -rw-r--r-- | embassy-stm32/src/flash/g0.rs | 26 | ||||
| -rw-r--r-- | embassy-stm32/src/flash/h7.rs | 36 | ||||
| -rw-r--r-- | embassy-stm32/src/flash/l.rs | 38 |
7 files changed, 21 insertions, 136 deletions
diff --git a/embassy-stm32/src/flash/f0.rs b/embassy-stm32/src/flash/f0.rs index ec8343e7c..d011522be 100644 --- a/embassy-stm32/src/flash/f0.rs +++ b/embassy-stm32/src/flash/f0.rs | |||
| @@ -76,17 +76,9 @@ pub(crate) unsafe fn blocking_erase_sector(sector: &FlashSector) -> Result<(), E | |||
| 76 | } | 76 | } |
| 77 | 77 | ||
| 78 | pub(crate) unsafe fn clear_all_err() { | 78 | pub(crate) unsafe fn clear_all_err() { |
| 79 | pac::FLASH.sr().modify(|w| { | 79 | // read and write back the same value. |
| 80 | if w.pgerr() { | 80 | // This clears all "write 0 to clear" bits. |
| 81 | w.set_pgerr(true); | 81 | pac::FLASH.sr().modify(|_| {}); |
| 82 | } | ||
| 83 | if w.wrprt() { | ||
| 84 | w.set_wrprt(true) | ||
| 85 | }; | ||
| 86 | if w.eop() { | ||
| 87 | w.set_eop(true); | ||
| 88 | } | ||
| 89 | }); | ||
| 90 | } | 82 | } |
| 91 | 83 | ||
| 92 | unsafe fn wait_ready_blocking() -> Result<(), Error> { | 84 | unsafe fn wait_ready_blocking() -> Result<(), Error> { |
diff --git a/embassy-stm32/src/flash/f3.rs b/embassy-stm32/src/flash/f3.rs index 40335d643..065369f64 100644 --- a/embassy-stm32/src/flash/f3.rs +++ b/embassy-stm32/src/flash/f3.rs | |||
| @@ -76,17 +76,9 @@ pub(crate) unsafe fn blocking_erase_sector(sector: &FlashSector) -> Result<(), E | |||
| 76 | } | 76 | } |
| 77 | 77 | ||
| 78 | pub(crate) unsafe fn clear_all_err() { | 78 | pub(crate) unsafe fn clear_all_err() { |
| 79 | pac::FLASH.sr().modify(|w| { | 79 | // read and write back the same value. |
| 80 | if w.pgerr() { | 80 | // This clears all "write 0 to clear" bits. |
| 81 | w.set_pgerr(true); | 81 | pac::FLASH.sr().modify(|_| {}); |
| 82 | } | ||
| 83 | if w.wrprterr() { | ||
| 84 | w.set_wrprterr(true); | ||
| 85 | } | ||
| 86 | if w.eop() { | ||
| 87 | w.set_eop(true); | ||
| 88 | } | ||
| 89 | }); | ||
| 90 | } | 82 | } |
| 91 | 83 | ||
| 92 | unsafe fn wait_ready_blocking() -> Result<(), Error> { | 84 | unsafe fn wait_ready_blocking() -> Result<(), Error> { |
diff --git a/embassy-stm32/src/flash/f4.rs b/embassy-stm32/src/flash/f4.rs index 728f6d604..913950fe5 100644 --- a/embassy-stm32/src/flash/f4.rs +++ b/embassy-stm32/src/flash/f4.rs | |||
| @@ -336,12 +336,9 @@ pub(crate) unsafe fn blocking_erase_sector(sector: &FlashSector) -> Result<(), E | |||
| 336 | } | 336 | } |
| 337 | 337 | ||
| 338 | pub(crate) fn clear_all_err() { | 338 | pub(crate) fn clear_all_err() { |
| 339 | pac::FLASH.sr().write(|w| { | 339 | // read and write back the same value. |
| 340 | w.set_pgserr(true); | 340 | // This clears all "write 0 to clear" bits. |
| 341 | w.set_pgperr(true); | 341 | pac::FLASH.sr().modify(|_| {}); |
| 342 | w.set_pgaerr(true); | ||
| 343 | w.set_wrperr(true); | ||
| 344 | }); | ||
| 345 | } | 342 | } |
| 346 | 343 | ||
| 347 | pub(crate) async fn wait_ready() -> Result<(), Error> { | 344 | pub(crate) async fn wait_ready() -> Result<(), Error> { |
diff --git a/embassy-stm32/src/flash/f7.rs b/embassy-stm32/src/flash/f7.rs index 1a6d6bb03..3a5bdf9c5 100644 --- a/embassy-stm32/src/flash/f7.rs +++ b/embassy-stm32/src/flash/f7.rs | |||
| @@ -66,23 +66,9 @@ pub(crate) unsafe fn blocking_erase_sector(sector: &FlashSector) -> Result<(), E | |||
| 66 | } | 66 | } |
| 67 | 67 | ||
| 68 | pub(crate) unsafe fn clear_all_err() { | 68 | pub(crate) unsafe fn clear_all_err() { |
| 69 | pac::FLASH.sr().modify(|w| { | 69 | // read and write back the same value. |
| 70 | if w.erserr() { | 70 | // This clears all "write 0 to clear" bits. |
| 71 | w.set_erserr(true); | 71 | pac::FLASH.sr().modify(|_| {}); |
| 72 | } | ||
| 73 | if w.pgperr() { | ||
| 74 | w.set_pgperr(true); | ||
| 75 | } | ||
| 76 | if w.pgaerr() { | ||
| 77 | w.set_pgaerr(true); | ||
| 78 | } | ||
| 79 | if w.wrperr() { | ||
| 80 | w.set_wrperr(true); | ||
| 81 | } | ||
| 82 | if w.eop() { | ||
| 83 | w.set_eop(true); | ||
| 84 | } | ||
| 85 | }); | ||
| 86 | } | 72 | } |
| 87 | 73 | ||
| 88 | unsafe fn blocking_wait_ready() -> Result<(), Error> { | 74 | unsafe fn blocking_wait_ready() -> Result<(), Error> { |
diff --git a/embassy-stm32/src/flash/g0.rs b/embassy-stm32/src/flash/g0.rs index 60ff1abf1..3a4576016 100644 --- a/embassy-stm32/src/flash/g0.rs +++ b/embassy-stm32/src/flash/g0.rs | |||
| @@ -89,27 +89,7 @@ pub(crate) unsafe fn wait_ready_blocking() -> Result<(), Error> { | |||
| 89 | } | 89 | } |
| 90 | 90 | ||
| 91 | pub(crate) unsafe fn clear_all_err() { | 91 | pub(crate) unsafe fn clear_all_err() { |
| 92 | pac::FLASH.sr().modify(|w| { | 92 | // read and write back the same value. |
| 93 | if w.progerr() { | 93 | // This clears all "write 0 to clear" bits. |
| 94 | w.set_progerr(true); | 94 | pac::FLASH.sr().modify(|_| {}); |
| 95 | } | ||
| 96 | if w.pgserr() { | ||
| 97 | w.set_pgserr(true); | ||
| 98 | } | ||
| 99 | if w.rderr() { | ||
| 100 | w.set_rderr(true); | ||
| 101 | } | ||
| 102 | if w.optverr() { | ||
| 103 | w.set_optverr(true); | ||
| 104 | } | ||
| 105 | if w.sizerr() { | ||
| 106 | w.set_sizerr(true); | ||
| 107 | } | ||
| 108 | if w.pgaerr() { | ||
| 109 | w.set_pgaerr(true); | ||
| 110 | } | ||
| 111 | if w.wrperr() { | ||
| 112 | w.set_wrperr(true); | ||
| 113 | } | ||
| 114 | }); | ||
| 115 | } | 95 | } |
diff --git a/embassy-stm32/src/flash/h7.rs b/embassy-stm32/src/flash/h7.rs index bf17b5b18..bb429d773 100644 --- a/embassy-stm32/src/flash/h7.rs +++ b/embassy-stm32/src/flash/h7.rs | |||
| @@ -104,39 +104,9 @@ pub(crate) unsafe fn clear_all_err() { | |||
| 104 | } | 104 | } |
| 105 | 105 | ||
| 106 | unsafe fn bank_clear_all_err(bank: pac::flash::Bank) { | 106 | unsafe fn bank_clear_all_err(bank: pac::flash::Bank) { |
| 107 | bank.sr().modify(|w| { | 107 | // read and write back the same value. |
| 108 | if w.wrperr() { | 108 | // This clears all "write 0 to clear" bits. |
| 109 | w.set_wrperr(true); | 109 | bank.sr().modify(|_| {}); |
| 110 | } | ||
| 111 | if w.pgserr() { | ||
| 112 | w.set_pgserr(true); | ||
| 113 | } | ||
| 114 | if w.strberr() { | ||
| 115 | // single address was written multiple times, can be ignored | ||
| 116 | w.set_strberr(true); | ||
| 117 | } | ||
| 118 | if w.incerr() { | ||
| 119 | // writing to a different address when programming 256 bit word was not finished | ||
| 120 | w.set_incerr(true); | ||
| 121 | } | ||
| 122 | if w.operr() { | ||
| 123 | w.set_operr(true); | ||
| 124 | } | ||
| 125 | if w.sneccerr1() { | ||
| 126 | // single ECC error | ||
| 127 | w.set_sneccerr1(true); | ||
| 128 | } | ||
| 129 | if w.dbeccerr() { | ||
| 130 | // double ECC error | ||
| 131 | w.set_dbeccerr(true); | ||
| 132 | } | ||
| 133 | if w.rdperr() { | ||
| 134 | w.set_rdperr(true); | ||
| 135 | } | ||
| 136 | if w.rdserr() { | ||
| 137 | w.set_rdserr(true); | ||
| 138 | } | ||
| 139 | }); | ||
| 140 | } | 110 | } |
| 141 | 111 | ||
| 142 | unsafe fn blocking_wait_ready(bank: pac::flash::Bank) -> Result<(), Error> { | 112 | unsafe fn blocking_wait_ready(bank: pac::flash::Bank) -> Result<(), Error> { |
diff --git a/embassy-stm32/src/flash/l.rs b/embassy-stm32/src/flash/l.rs index 243c8b51d..24dcf99bc 100644 --- a/embassy-stm32/src/flash/l.rs +++ b/embassy-stm32/src/flash/l.rs | |||
| @@ -113,41 +113,9 @@ pub(crate) unsafe fn blocking_erase_sector(sector: &FlashSector) -> Result<(), E | |||
| 113 | } | 113 | } |
| 114 | 114 | ||
| 115 | pub(crate) unsafe fn clear_all_err() { | 115 | pub(crate) unsafe fn clear_all_err() { |
| 116 | pac::FLASH.sr().modify(|w| { | 116 | // read and write back the same value. |
| 117 | #[cfg(any(flash_wl, flash_wb, flash_l4, flash_l0))] | 117 | // This clears all "write 0 to clear" bits. |
| 118 | if w.rderr() { | 118 | pac::FLASH.sr().modify(|_| {}); |
| 119 | w.set_rderr(true); | ||
| 120 | } | ||
| 121 | #[cfg(any(flash_wl, flash_wb, flash_l4))] | ||
| 122 | if w.fasterr() { | ||
| 123 | w.set_fasterr(true); | ||
| 124 | } | ||
| 125 | #[cfg(any(flash_wl, flash_wb, flash_l4))] | ||
| 126 | if w.miserr() { | ||
| 127 | w.set_miserr(true); | ||
| 128 | } | ||
| 129 | #[cfg(any(flash_wl, flash_wb, flash_l4))] | ||
| 130 | if w.pgserr() { | ||
| 131 | w.set_pgserr(true); | ||
| 132 | } | ||
| 133 | if w.sizerr() { | ||
| 134 | w.set_sizerr(true); | ||
| 135 | } | ||
| 136 | if w.pgaerr() { | ||
| 137 | w.set_pgaerr(true); | ||
| 138 | } | ||
| 139 | if w.wrperr() { | ||
| 140 | w.set_wrperr(true); | ||
| 141 | } | ||
| 142 | #[cfg(any(flash_wl, flash_wb, flash_l4))] | ||
| 143 | if w.progerr() { | ||
| 144 | w.set_progerr(true); | ||
| 145 | } | ||
| 146 | #[cfg(any(flash_wl, flash_wb, flash_l4))] | ||
| 147 | if w.operr() { | ||
| 148 | w.set_operr(true); | ||
| 149 | } | ||
| 150 | }); | ||
| 151 | } | 119 | } |
| 152 | 120 | ||
| 153 | unsafe fn wait_ready_blocking() -> Result<(), Error> { | 121 | unsafe fn wait_ready_blocking() -> Result<(), Error> { |
