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.
pull/5455/head
Laurent MEUNIER 2017-11-08 09:02:21 +01:00
parent 38488623c8
commit d9bda2800d
1 changed files with 3 additions and 1 deletions

View File

@ -180,8 +180,10 @@ static uint32_t GetSector(uint32_t address)
/* This function supports 1Mb and 2Mb flash sizes */
#if defined(ADDR_FLASH_SECTOR_16)
if (address & 0x100000) { // handle 2nd bank
/* Sector will be at least 12 */
sector = FLASH_SECTOR_12;
tmp = address - ADDR_FLASH_SECTOR_12;
tmp -= 0x100000;
address -= 0x100000;
}
#endif
if (address < ADDR_FLASH_SECTOR_4) { // 16k sectorsize