Skip to content

Commit 0474448

Browse files
bakatroublehallard
authored andcommitted
Support different STM32F7 flash configurations
1 parent 33732c3 commit 0474448

File tree

1 file changed

+33
-9
lines changed

1 file changed

+33
-9
lines changed

targets/TARGET_STM/TARGET_STM32F7/flash_api.c

+33-9
Original file line numberDiff line numberDiff line change
@@ -206,13 +206,37 @@ static uint32_t GetSector(uint32_t address)
206206
sector += 16 + (tmp >> 17);
207207
}
208208
#else // SINGLE BANK
209-
if (address < ADDR_FLASH_SECTOR_4) { // Sectors 0 to 3
210-
sector += tmp >> 15;
211-
} else if (address < ADDR_FLASH_SECTOR_5) { // Sector 4
212-
sector += FLASH_SECTOR_4;
213-
} else { // Sectors 5 to 11
214-
sector += 4 + (tmp >> 18);
209+
if (address < ADDR_FLASH_SECTOR_1) {
210+
sector = 0;
211+
} else if (address < ADDR_FLASH_SECTOR_2) {
212+
sector = 1;
213+
} else if (address < ADDR_FLASH_SECTOR_3) {
214+
sector = 2;
215+
} else if (address < ADDR_FLASH_SECTOR_4) {
216+
sector = 3;
217+
} else if (address < ADDR_FLASH_SECTOR_5) {
218+
sector = 4;
219+
} else if (address < ADDR_FLASH_SECTOR_6) {
220+
sector = 5;
221+
} else if (address < ADDR_FLASH_SECTOR_7) {
222+
sector = 6;
223+
#if defined (ADDR_FLASH_SECTOR_8)
224+
} else if (address < ADDR_FLASH_SECTOR_8) {
225+
sector = 7;
226+
} else if (address < ADDR_FLASH_SECTOR_9) {
227+
sector = 8;
228+
} else if (address < ADDR_FLASH_SECTOR_10) {
229+
sector = 9;
230+
} else if (address < ADDR_FLASH_SECTOR_11) {
231+
sector = 10;
232+
} else {
233+
sector = 11;
234+
}
235+
#else
236+
} else {
237+
sector = 7;
215238
}
239+
#endif
216240
#endif
217241
return sector;
218242
}
@@ -239,11 +263,11 @@ static uint32_t GetSectorSize(uint32_t Sector)
239263
#else // SINGLE BANK
240264
if ((Sector == FLASH_SECTOR_0) || (Sector == FLASH_SECTOR_1) || \
241265
(Sector == FLASH_SECTOR_2) || (Sector == FLASH_SECTOR_3)) {
242-
sectorsize = 32 * 1024;
266+
sectorsize = ADDR_FLASH_SECTOR_1 - ADDR_FLASH_SECTOR_0;
243267
} else if (Sector == FLASH_SECTOR_4) {
244-
sectorsize = 128 * 1024;
268+
sectorsize = ADDR_FLASH_SECTOR_5 - ADDR_FLASH_SECTOR_4;
245269
} else {
246-
sectorsize = 256 * 1024;
270+
sectorsize = ADDR_FLASH_SECTOR_7 - ADDR_FLASH_SECTOR_6;
247271
}
248272
#endif
249273
return sectorsize;

0 commit comments

Comments
 (0)