diff --git a/hardware/esp8266com/esp8266/cores/esp8266/FileSystem.h b/hardware/esp8266com/esp8266/cores/esp8266/FileSystem.h index 012bdc45b..9d3a52eac 100755 --- a/hardware/esp8266com/esp8266/cores/esp8266/FileSystem.h +++ b/hardware/esp8266com/esp8266/cores/esp8266/FileSystem.h @@ -26,8 +26,8 @@ class String; #define FSFILE_READ SPIFFS_RDONLY -#define FSFILE_WRITE (SPIFFS_RDONLY | SPIFFS_WRONLY | SPIFFS_CREAT | SPIFFS_APPEND | SPIFFS_DIRECT) -#define FSFILE_OVERWRITE (SPIFFS_RDONLY | SPIFFS_WRONLY | SPIFFS_CREAT | SPIFFS_APPEND | SPIFFS_TRUNC | SPIFFS_DIRECT) +#define FSFILE_WRITE (SPIFFS_RDONLY | SPIFFS_WRONLY | SPIFFS_CREAT | SPIFFS_APPEND ) +#define FSFILE_OVERWRITE (SPIFFS_RDONLY | SPIFFS_WRONLY | SPIFFS_CREAT | SPIFFS_APPEND | SPIFFS_TRUNC ) class FSFile : public Stream { private: diff --git a/hardware/esp8266com/esp8266/cores/esp8266/spiffs/spiffs.c b/hardware/esp8266com/esp8266/cores/esp8266/spiffs/spiffs.c index 71d00905c..74a65e05d 100755 --- a/hardware/esp8266com/esp8266/cores/esp8266/spiffs/spiffs.c +++ b/hardware/esp8266com/esp8266/cores/esp8266/spiffs/spiffs.c @@ -21,7 +21,7 @@ static s32_t api_spiffs_write(u32_t addr, u32_t size, u8_t *src){ static s32_t api_spiffs_erase(u32_t addr, u32_t size){ debugf("api_spiffs_erase"); u32_t sect_first = flashmem_get_sector_of_address(addr); - u32_t sect_last = sect_first; + u32_t sect_last = flashmem_get_sector_of_address(addr+size); while( sect_first <= sect_last ) if( !flashmem_erase_sector( sect_first ++ ) ) return SPIFFS_ERR_INTERNAL; @@ -68,7 +68,7 @@ bool spiffs_format_internal(){ return true; } -bool spiffs_mount(){ +bool spiffs_mount_internal(bool wipe){ spiffs_config cfg = spiffs_get_storage_config(); if (cfg.phys_addr == 0){ SYSTEM_ERROR("Can't start file system, wrong address"); @@ -85,7 +85,7 @@ bool spiffs_mount(){ bool writeFirst = false; flashmem_read(&dat, cfg.phys_addr, 4); - if (dat == UINT32_MAX){ + if (dat == UINT32_MAX || wipe){ debugf("First init file system"); if(!spiffs_format_internal()){ SYSTEM_ERROR("Can't format file system"); @@ -115,15 +115,17 @@ bool spiffs_mount(){ return true; } +bool spiffs_mount(){ + return spiffs_mount_internal(false); +} + void spiffs_unmount(){ SPIFFS_unmount(&_filesystemStorageHandle); } bool spiffs_format(){ spiffs_unmount(); - if(!spiffs_format_internal()) return false; - spiffs_mount(); - return true; + return spiffs_mount_internal(true); } void test_spiffs(){ diff --git a/hardware/esp8266com/esp8266/cores/esp8266/spiffs/spiffs_flashmem.c b/hardware/esp8266com/esp8266/cores/esp8266/spiffs/spiffs_flashmem.c index d7f182ee0..dc875ff12 100755 --- a/hardware/esp8266com/esp8266/cores/esp8266/spiffs/spiffs_flashmem.c +++ b/hardware/esp8266com/esp8266/cores/esp8266/spiffs/spiffs_flashmem.c @@ -96,15 +96,6 @@ uint32_t flashmem_read( void *to, uint32_t fromaddr, uint32_t size ) return ssize; } -bool flashmem_erase_sector( uint32_t sector_id ) -{ - WDT_RESET(); - noInterrupts(); - bool erased = spi_flash_erase_sector( sector_id ) == SPI_FLASH_RESULT_OK; - interrupts(); - return erased; -} - SPIFlashInfo flashmem_get_info() { volatile SPIFlashInfo spi_flash_info STORE_ATTR; @@ -177,6 +168,15 @@ uint32_t flashmem_get_sector_of_address( uint32_t addr ) ///////////////////////////////////////////////////// +bool flashmem_erase_sector( uint32_t sector_id ) +{ + WDT_RESET(); + noInterrupts(); + bool erased = spi_flash_erase_sector( sector_id ) == SPI_FLASH_RESULT_OK; + interrupts(); + return erased; +} + uint32_t flashmem_write_internal( const void *from, uint32_t toaddr, uint32_t size ) { toaddr -= INTERNAL_FLASH_START_ADDRESS;