1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-19 14:25:20 +03:00

fix wrong flash sector on F4 targets.

This commit is contained in:
Hydra 2017-04-02 10:08:25 +01:00 committed by Dominic Clifton
parent 60cf02354f
commit 837f24f098

View file

@ -224,6 +224,58 @@ void writeEEPROM(void)
resumeRxSignal();
}
#else
#if defined(STM32F4)
/*
Sector 0 0x08000000 - 0x08003FFF 16 Kbytes
Sector 1 0x08004000 - 0x08007FFF 16 Kbytes
Sector 2 0x08008000 - 0x0800BFFF 16 Kbytes
Sector 3 0x0800C000 - 0x0800FFFF 16 Kbytes
Sector 4 0x08010000 - 0x0801FFFF 64 Kbytes
Sector 5 0x08020000 - 0x0803FFFF 128 Kbytes
Sector 6 0x08040000 - 0x0805FFFF 128 Kbytes
Sector 7 0x08060000 - 0x0807FFFF 128 Kbytes
Sector 8 0x08080000 - 0x0809FFFF 128 Kbytes
Sector 9 0x080A0000 - 0x080BFFFF 128 Kbytes
Sector 10 0x080C0000 - 0x080DFFFF 128 Kbytes
Sector 11 0x080E0000 - 0x080FFFFF 128 Kbytes
*/
static uint32_t getFLASHSectorForEEPROM(void)
{
if (CONFIG_START_FLASH_ADDRESS <= 0x08003FFF)
return FLASH_Sector_0;
if (CONFIG_START_FLASH_ADDRESS <= 0x08007FFF)
return FLASH_Sector_1;
if (CONFIG_START_FLASH_ADDRESS <= 0x0800BFFF)
return FLASH_Sector_2;
if (CONFIG_START_FLASH_ADDRESS <= 0x0800FFFF)
return FLASH_Sector_3;
if (CONFIG_START_FLASH_ADDRESS <= 0x0801FFFF)
return FLASH_Sector_4;
if (CONFIG_START_FLASH_ADDRESS <= 0x0803FFFF)
return FLASH_Sector_5;
if (CONFIG_START_FLASH_ADDRESS <= 0x0805FFFF)
return FLASH_Sector_6;
if (CONFIG_START_FLASH_ADDRESS <= 0x0807FFFF)
return FLASH_Sector_7;
if (CONFIG_START_FLASH_ADDRESS <= 0x0809FFFF)
return FLASH_Sector_8;
if (CONFIG_START_FLASH_ADDRESS <= 0x080DFFFF)
return FLASH_Sector_9;
if (CONFIG_START_FLASH_ADDRESS <= 0x080BFFFF)
return FLASH_Sector_10;
if (CONFIG_START_FLASH_ADDRESS <= 0x080FFFFF)
return FLASH_Sector_11;
// Not good
while (1) {
failureMode(FAILURE_FLASH_WRITE_FAILED);
}
}
#endif
void writeEEPROM(void)
{
// Generate compile time error if the config does not fit in the reserved area of flash.
@ -255,10 +307,8 @@ void writeEEPROM(void)
#endif
for (wordOffset = 0; wordOffset < sizeof(master_t); wordOffset += 4) {
if (wordOffset % FLASH_PAGE_SIZE == 0) {
#if defined(STM32F40_41xxx)
status = FLASH_EraseSector(FLASH_Sector_8, VoltageRange_3); //0x08080000 to 0x080A0000
#elif defined (STM32F411xE)
status = FLASH_EraseSector(FLASH_Sector_7, VoltageRange_3); //0x08060000 to 0x08080000
#if defined(STM32F4)
status = FLASH_EraseSector(getFLASHSectorForEEPROM(), VoltageRange_3); //0x08060000 to 0x08080000
#else
status = FLASH_ErasePage(CONFIG_START_FLASH_ADDRESS + wordOffset);
#endif