diff --git a/flight/pios/common/pios_flash_eeprom.c b/flight/pios/common/pios_flash_eeprom.c index 63d1c751b..2a31a81ef 100644 --- a/flight/pios/common/pios_flash_eeprom.c +++ b/flight/pios/common/pios_flash_eeprom.c @@ -389,8 +389,11 @@ static int32_t PIOS_Flash_EEPROM_EraseSector(uintptr_t flash_id, uint32_t addr) if (PIOS_Flash_EEPROM_Validate(flash_dev) != 0) { return -1; } - // Rewrite first block of bytes to invalidate the sector. - const uint8_t buf[16] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; + // Rewrite the whole page + const uint8_t buf[] = { + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + }; return PIOS_Flash_EEPROM_Write(flash_dev, addr, buf, sizeof(buf)); } diff --git a/flight/pios/common/pios_flashfs_objlist.c b/flight/pios/common/pios_flashfs_objlist.c index 727f1cbaa..8b8589dd0 100644 --- a/flight/pios/common/pios_flashfs_objlist.c +++ b/flight/pios/common/pios_flashfs_objlist.c @@ -194,10 +194,13 @@ int32_t PIOS_FLASHFS_Format(uintptr_t fs_id) */ static int32_t PIOS_FLASHFS_ClearObjectTableHeader(struct flashfs_dev *dev) { - for (int i = 0; i < 16; i++) { - if (dev->driver->erase_sector(dev->flash_id, 256 * i) != 0) { + uint32_t addr = dev->cfg->obj_table_start; + + while (addr < dev->cfg->obj_table_end) { + if (dev->driver->erase_sector(dev->flash_id, addr) != 0) { return -1; } + addr += dev->cfg->sector_size; } if (dev->driver->write_data(dev->flash_id, 0, (uint8_t *)&dev->cfg->table_magic, sizeof(dev->cfg->table_magic)) != 0) { diff --git a/flight/targets/boards/revonano/firmware/pios_board.c b/flight/targets/boards/revonano/firmware/pios_board.c index 8156d2a15..367175dd9 100644 --- a/flight/targets/boards/revonano/firmware/pios_board.c +++ b/flight/targets/boards/revonano/firmware/pios_board.c @@ -352,8 +352,7 @@ void PIOS_Board_Init(void) if (PIOS_IAP_ReadBootCmd(0) == PIOS_IAP_CLEAR_FLASH_CMD_0 && PIOS_IAP_ReadBootCmd(1) == PIOS_IAP_CLEAR_FLASH_CMD_1 && PIOS_IAP_ReadBootCmd(2) == PIOS_IAP_CLEAR_FLASH_CMD_2) { - // todo: EEprom ERASE - // PIOS_FLASHFS_Format(pios_uavo_settings_fs_id); + PIOS_FLASHFS_Format(pios_uavo_settings_fs_id); PIOS_IAP_WriteBootCmd(0, 0); PIOS_IAP_WriteBootCmd(1, 0); PIOS_IAP_WriteBootCmd(2, 0);