diff options
| author | Dario Nieuwenhuis <[email protected]> | 2024-11-28 14:15:30 +0000 |
|---|---|---|
| committer | GitHub <[email protected]> | 2024-11-28 14:15:30 +0000 |
| commit | 8954c053fbb0ce83d4bcdec4bf84a26874421696 (patch) | |
| tree | 14e6ae0f6cbc343dec738a6aa5ecd591aac7c6e7 | |
| parent | 0349a8d3731527ed5deb869fb4fe172b838cef86 (diff) | |
| parent | b035ff114502b0e63f578441250b6ff94c5efda1 (diff) | |
Merge pull request #3583 from williams-one/add-flash-bank-selection-for-erase
STM32U5: Add flash bank selection when erasing a sector
| -rw-r--r-- | embassy-stm32/Cargo.toml | 4 | ||||
| -rw-r--r-- | embassy-stm32/src/flash/u5.rs | 16 |
2 files changed, 15 insertions, 5 deletions
diff --git a/embassy-stm32/Cargo.toml b/embassy-stm32/Cargo.toml index f6ffa29fa..09b7f805a 100644 --- a/embassy-stm32/Cargo.toml +++ b/embassy-stm32/Cargo.toml | |||
| @@ -72,7 +72,7 @@ rand_core = "0.6.3" | |||
| 72 | sdio-host = "0.5.0" | 72 | sdio-host = "0.5.0" |
| 73 | critical-section = "1.1" | 73 | critical-section = "1.1" |
| 74 | #stm32-metapac = { version = "15" } | 74 | #stm32-metapac = { version = "15" } |
| 75 | stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-04833817666290047257c65c6547d28e1bd10dc9" } | 75 | stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-ab0ec4c19f81854189bab8215544ccd1256e1045" } |
| 76 | 76 | ||
| 77 | vcell = "0.1.3" | 77 | vcell = "0.1.3" |
| 78 | nb = "1.0.0" | 78 | nb = "1.0.0" |
| @@ -101,7 +101,7 @@ proc-macro2 = "1.0.36" | |||
| 101 | quote = "1.0.15" | 101 | quote = "1.0.15" |
| 102 | 102 | ||
| 103 | #stm32-metapac = { version = "15", default-features = false, features = ["metadata"]} | 103 | #stm32-metapac = { version = "15", default-features = false, features = ["metadata"]} |
| 104 | stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-04833817666290047257c65c6547d28e1bd10dc9", default-features = false, features = ["metadata"] } | 104 | stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-ab0ec4c19f81854189bab8215544ccd1256e1045", default-features = false, features = ["metadata"] } |
| 105 | 105 | ||
| 106 | [features] | 106 | [features] |
| 107 | default = ["rt"] | 107 | default = ["rt"] |
diff --git a/embassy-stm32/src/flash/u5.rs b/embassy-stm32/src/flash/u5.rs index 0601017ce..e5af4f1f7 100644 --- a/embassy-stm32/src/flash/u5.rs +++ b/embassy-stm32/src/flash/u5.rs | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | use core::ptr::write_volatile; | 1 | use core::ptr::write_volatile; |
| 2 | use core::sync::atomic::{fence, Ordering}; | 2 | use core::sync::atomic::{fence, Ordering}; |
| 3 | 3 | ||
| 4 | use super::{FlashRegion, FlashSector, FLASH_REGIONS, WRITE_SIZE}; | 4 | use super::{FlashBank, FlashRegion, FlashSector, FLASH_REGIONS, WRITE_SIZE}; |
| 5 | use crate::flash::Error; | 5 | use crate::flash::Error; |
| 6 | use crate::pac; | 6 | use crate::pac; |
| 7 | 7 | ||
| @@ -70,12 +70,22 @@ pub(crate) unsafe fn blocking_erase_sector(sector: &FlashSector) -> Result<(), E | |||
| 70 | #[cfg(feature = "trustzone-secure")] | 70 | #[cfg(feature = "trustzone-secure")] |
| 71 | pac::FLASH.seccr().modify(|w| { | 71 | pac::FLASH.seccr().modify(|w| { |
| 72 | w.set_per(pac::flash::vals::SeccrPer::B_0X1); | 72 | w.set_per(pac::flash::vals::SeccrPer::B_0X1); |
| 73 | w.set_pnb(sector.index_in_bank) | 73 | w.set_pnb(sector.index_in_bank); |
| 74 | // TODO: add check for bank swap | ||
| 75 | w.set_bker(match sector.bank { | ||
| 76 | FlashBank::Bank1 => pac::flash::vals::SeccrBker::B_0X0, | ||
| 77 | FlashBank::Bank2 => pac::flash::vals::SeccrBker::B_0X1, | ||
| 78 | }); | ||
| 74 | }); | 79 | }); |
| 75 | #[cfg(not(feature = "trustzone-secure"))] | 80 | #[cfg(not(feature = "trustzone-secure"))] |
| 76 | pac::FLASH.nscr().modify(|w| { | 81 | pac::FLASH.nscr().modify(|w| { |
| 77 | w.set_per(pac::flash::vals::NscrPer::B_0X1); | 82 | w.set_per(pac::flash::vals::NscrPer::B_0X1); |
| 78 | w.set_pnb(sector.index_in_bank) | 83 | w.set_pnb(sector.index_in_bank); |
| 84 | // TODO: add check for bank swap | ||
| 85 | w.set_bker(match sector.bank { | ||
| 86 | FlashBank::Bank1 => pac::flash::vals::NscrBker::B_0X0, | ||
| 87 | FlashBank::Bank2 => pac::flash::vals::NscrBker::B_0X1, | ||
| 88 | }); | ||
| 79 | }); | 89 | }); |
| 80 | 90 | ||
| 81 | #[cfg(feature = "trustzone-secure")] | 91 | #[cfg(feature = "trustzone-secure")] |
