From 855361488a0e8a1a0262d205e04782fd36391d75 Mon Sep 17 00:00:00 2001 From: Alessio Morale Date: Fri, 10 Apr 2015 15:12:44 +0200 Subject: [PATCH] REVONANO - emulate bigger sector size for erase operations --- flight/pios/common/pios_flash_eeprom.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/flight/pios/common/pios_flash_eeprom.c b/flight/pios/common/pios_flash_eeprom.c index 2a31a81ef..69389cdb4 100644 --- a/flight/pios/common/pios_flash_eeprom.c +++ b/flight/pios/common/pios_flash_eeprom.c @@ -32,6 +32,10 @@ #ifdef PIOS_INCLUDE_FLASH_EEPROM +#ifndef PIOS_EEPROM_EMULATED_SECTOR_SIZE +#define PIOS_EEPROM_EMULATED_SECTOR_SIZE 256 +#endif + #include #include enum pios_eeprom_dev_magic { @@ -393,8 +397,24 @@ static int32_t PIOS_Flash_EEPROM_EraseSector(uintptr_t flash_id, uint32_t addr) 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, + 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, + 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, + 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)); + uint32_t current = addr; + while (current - addr < PIOS_EEPROM_EMULATED_SECTOR_SIZE) { + uint32_t erase_size = (MIN(sizeof(buf), flash_dev->cfg->page_len)); + erase_size = MIN(erase_size, (PIOS_EEPROM_EMULATED_SECTOR_SIZE - current + addr)); + int32_t res = PIOS_Flash_EEPROM_Write(flash_dev, current, buf, erase_size); + if (!res) { + return res; + } + current += erase_size; + } + return 0; } /** -- 2.11.4.GIT