diff options
| author | Dion Dokter <[email protected]> | 2025-05-01 13:37:12 +0200 |
|---|---|---|
| committer | Dion Dokter <[email protected]> | 2025-05-01 13:37:12 +0200 |
| commit | 59d839a2b8a488bf1e9056f46ba1dff61148642b (patch) | |
| tree | 7536a0e4ea4b8bb4c271371c0dc4afe4fec30723 | |
| parent | cff6eb9a81a34f7e7437f30470c0914177ca3a27 (diff) | |
Fix dual bank support for F7
| -rwxr-xr-x | .github/ci/test.sh | 8 | ||||
| -rw-r--r-- | embassy-stm32/src/flash/f7.rs | 57 |
2 files changed, 60 insertions, 5 deletions
diff --git a/.github/ci/test.sh b/.github/ci/test.sh index 88962a533..c9b332cf8 100755 --- a/.github/ci/test.sh +++ b/.github/ci/test.sh | |||
| @@ -29,8 +29,10 @@ cargo test --manifest-path ./embassy-nrf/Cargo.toml --no-default-features --feat | |||
| 29 | cargo test --manifest-path ./embassy-rp/Cargo.toml --no-default-features --features time-driver,rp2040,_test | 29 | cargo test --manifest-path ./embassy-rp/Cargo.toml --no-default-features --features time-driver,rp2040,_test |
| 30 | cargo test --manifest-path ./embassy-rp/Cargo.toml --no-default-features --features time-driver,rp235xa,_test | 30 | cargo test --manifest-path ./embassy-rp/Cargo.toml --no-default-features --features time-driver,rp235xa,_test |
| 31 | 31 | ||
| 32 | cargo test --manifest-path ./embassy-stm32/Cargo.toml --no-default-features --features stm32f429vg,exti,time-driver-any,exti,dual-bank | 32 | cargo test --manifest-path ./embassy-stm32/Cargo.toml --no-default-features --features stm32f429vg,time-driver-any,exti,single-bank |
| 33 | cargo test --manifest-path ./embassy-stm32/Cargo.toml --no-default-features --features stm32f732ze,exti,time-driver-any,exti | 33 | cargo test --manifest-path ./embassy-stm32/Cargo.toml --no-default-features --features stm32f429vg,time-driver-any,exti,dual-bank |
| 34 | cargo test --manifest-path ./embassy-stm32/Cargo.toml --no-default-features --features stm32f769ni,exti,time-driver-any,exti,single-bank | 34 | cargo test --manifest-path ./embassy-stm32/Cargo.toml --no-default-features --features stm32f732ze,time-driver-any,exti |
| 35 | cargo test --manifest-path ./embassy-stm32/Cargo.toml --no-default-features --features stm32f769ni,time-driver-any,exti,single-bank | ||
| 36 | cargo test --manifest-path ./embassy-stm32/Cargo.toml --no-default-features --features stm32f769ni,time-driver-any,exti,dual-bank | ||
| 35 | 37 | ||
| 36 | cargo test --manifest-path ./embassy-net-adin1110/Cargo.toml | 38 | cargo test --manifest-path ./embassy-net-adin1110/Cargo.toml |
diff --git a/embassy-stm32/src/flash/f7.rs b/embassy-stm32/src/flash/f7.rs index 043382590..27a7afadf 100644 --- a/embassy-stm32/src/flash/f7.rs +++ b/embassy-stm32/src/flash/f7.rs | |||
| @@ -5,6 +5,12 @@ use super::{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 | ||
| 8 | impl FlashSector { | ||
| 9 | const fn snb(&self) -> u8 { | ||
| 10 | ((self.bank as u8) << 4) + self.index_in_bank | ||
| 11 | } | ||
| 12 | } | ||
| 13 | |||
| 8 | pub(crate) const fn is_default_layout() -> bool { | 14 | pub(crate) const fn is_default_layout() -> bool { |
| 9 | true | 15 | true |
| 10 | } | 16 | } |
| @@ -53,7 +59,7 @@ pub(crate) unsafe fn blocking_write(start_address: u32, buf: &[u8; WRITE_SIZE]) | |||
| 53 | pub(crate) unsafe fn blocking_erase_sector(sector: &FlashSector) -> Result<(), Error> { | 59 | pub(crate) unsafe fn blocking_erase_sector(sector: &FlashSector) -> Result<(), Error> { |
| 54 | pac::FLASH.cr().modify(|w| { | 60 | pac::FLASH.cr().modify(|w| { |
| 55 | w.set_ser(true); | 61 | w.set_ser(true); |
| 56 | w.set_snb(sector.index_in_bank) | 62 | w.set_snb(sector.snb()) |
| 57 | }); | 63 | }); |
| 58 | 64 | ||
| 59 | pac::FLASH.cr().modify(|w| { | 65 | pac::FLASH.cr().modify(|w| { |
| @@ -137,7 +143,7 @@ mod tests { | |||
| 137 | } | 143 | } |
| 138 | 144 | ||
| 139 | #[test] | 145 | #[test] |
| 140 | #[cfg(stm32f769)] | 146 | #[cfg(all(stm32f769, feature = "single-bank"))] |
| 141 | fn can_get_sector() { | 147 | fn can_get_sector() { |
| 142 | const SMALL_SECTOR_SIZE: u32 = 32 * 1024; | 148 | const SMALL_SECTOR_SIZE: u32 = 32 * 1024; |
| 143 | const MEDIUM_SECTOR_SIZE: u32 = 128 * 1024; | 149 | const MEDIUM_SECTOR_SIZE: u32 = 128 * 1024; |
| @@ -168,6 +174,53 @@ mod tests { | |||
| 168 | assert_sector(7, 0x080C_0000, LARGE_SECTOR_SIZE, 0x080C_0000); | 174 | assert_sector(7, 0x080C_0000, LARGE_SECTOR_SIZE, 0x080C_0000); |
| 169 | assert_sector(7, 0x080C_0000, LARGE_SECTOR_SIZE, 0x080F_FFFF); | 175 | assert_sector(7, 0x080C_0000, LARGE_SECTOR_SIZE, 0x080F_FFFF); |
| 170 | } | 176 | } |
| 177 | |||
| 178 | #[test] | ||
| 179 | #[cfg(all(stm32f769, feature = "dual-bank"))] | ||
| 180 | fn can_get_sector() { | ||
| 181 | const SMALL_SECTOR_SIZE: u32 = 16 * 1024; | ||
| 182 | const MEDIUM_SECTOR_SIZE: u32 = 64 * 1024; | ||
| 183 | const LARGE_SECTOR_SIZE: u32 = 128 * 1024; | ||
| 184 | |||
| 185 | let assert_sector = |index_in_bank: u8, start: u32, size: u32, address: u32, snb: u8, bank: FlashBank| { | ||
| 186 | assert_eq!( | ||
| 187 | FlashSector { | ||
| 188 | bank: bank, | ||
| 189 | index_in_bank, | ||
| 190 | start, | ||
| 191 | size | ||
| 192 | }, | ||
| 193 | get_sector(address, &FLASH_REGIONS) | ||
| 194 | ); | ||
| 195 | assert_eq!(get_sector(address, &FLASH_REGIONS).snb(), snb); | ||
| 196 | }; | ||
| 197 | |||
| 198 | assert_sector(0, 0x0800_0000, SMALL_SECTOR_SIZE, 0x0800_0000, 0x00, FlashBank::Bank1); | ||
| 199 | assert_sector(0, 0x0800_0000, SMALL_SECTOR_SIZE, 0x0800_3FFF, 0x00, FlashBank::Bank1); | ||
| 200 | assert_sector(3, 0x0800_C000, SMALL_SECTOR_SIZE, 0x0800_C000, 0x03, FlashBank::Bank1); | ||
| 201 | assert_sector(3, 0x0800_C000, SMALL_SECTOR_SIZE, 0x0800_FFFF, 0x03, FlashBank::Bank1); | ||
| 202 | |||
| 203 | assert_sector(4, 0x0801_0000, MEDIUM_SECTOR_SIZE, 0x0801_0000, 0x04, FlashBank::Bank1); | ||
| 204 | assert_sector(4, 0x0801_0000, MEDIUM_SECTOR_SIZE, 0x0801_FFFF, 0x04, FlashBank::Bank1); | ||
| 205 | |||
| 206 | assert_sector(5, 0x0802_0000, LARGE_SECTOR_SIZE, 0x0802_0000, 0x05, FlashBank::Bank1); | ||
| 207 | assert_sector(5, 0x0802_0000, LARGE_SECTOR_SIZE, 0x0803_FFFF, 0x05, FlashBank::Bank1); | ||
| 208 | assert_sector(10, 0x080C_0000, LARGE_SECTOR_SIZE, 0x080C_0000, 0x0A, FlashBank::Bank1); | ||
| 209 | assert_sector(10, 0x080C_0000, LARGE_SECTOR_SIZE, 0x080D_FFFF, 0x0A, FlashBank::Bank1); | ||
| 210 | |||
| 211 | assert_sector(0, 0x0810_0000, SMALL_SECTOR_SIZE, 0x0810_0000, 0x10, FlashBank::Bank2); | ||
| 212 | assert_sector(0, 0x0810_0000, SMALL_SECTOR_SIZE, 0x0810_3FFF, 0x10, FlashBank::Bank2); | ||
| 213 | assert_sector(3, 0x0810_C000, SMALL_SECTOR_SIZE, 0x0810_C000, 0x13, FlashBank::Bank2); | ||
| 214 | assert_sector(3, 0x0810_C000, SMALL_SECTOR_SIZE, 0x0810_FFFF, 0x13, FlashBank::Bank2); | ||
| 215 | |||
| 216 | assert_sector(4, 0x0811_0000, MEDIUM_SECTOR_SIZE, 0x0811_0000, 0x14, FlashBank::Bank2); | ||
| 217 | assert_sector(4, 0x0811_0000, MEDIUM_SECTOR_SIZE, 0x0811_FFFF, 0x14, FlashBank::Bank2); | ||
| 218 | |||
| 219 | assert_sector(5, 0x0812_0000, LARGE_SECTOR_SIZE, 0x0812_0000, 0x15, FlashBank::Bank2); | ||
| 220 | assert_sector(5, 0x0812_0000, LARGE_SECTOR_SIZE, 0x0813_FFFF, 0x15, FlashBank::Bank2); | ||
| 221 | assert_sector(10, 0x081C_0000, LARGE_SECTOR_SIZE, 0x081C_0000, 0x1A, FlashBank::Bank2); | ||
| 222 | assert_sector(10, 0x081C_0000, LARGE_SECTOR_SIZE, 0x081D_FFFF, 0x1A, FlashBank::Bank2); | ||
| 223 | } | ||
| 171 | } | 224 | } |
| 172 | 225 | ||
| 173 | #[cfg(all(bank_setup_configurable))] | 226 | #[cfg(all(bank_setup_configurable))] |
