Skip to content

Commit e20d35d

Browse files
LMESTMadbridge
authored andcommitted
STM32F4: Flash: fix 2MB GetSector computation
The computation of the sector number in GetSector for 2MB flash sizes consists in adding an extra constant for 2MB dual bank (12 as in ADDR_FLASH_SECTOR_12), then going through the same address check as if it was an address of the first sector. That means that we need to modify tmp and address as if it was a first bank address, which we're doing here by sub_stracting 0x100000 delta.
1 parent c2bba67 commit e20d35d

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

targets/TARGET_STM/TARGET_STM32F4/flash_api.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,10 @@ static uint32_t GetSector(uint32_t address)
180180
/* This function supports 1Mb and 2Mb flash sizes */
181181
#if defined(ADDR_FLASH_SECTOR_16)
182182
if (address & 0x100000) { // handle 2nd bank
183+
/* Sector will be at least 12 */
183184
sector = FLASH_SECTOR_12;
184-
tmp = address - ADDR_FLASH_SECTOR_12;
185+
tmp -= 0x100000;
186+
address -= 0x100000;
185187
}
186188
#endif
187189
if (address < ADDR_FLASH_SECTOR_4) { // 16k sectorsize

0 commit comments

Comments
 (0)