Skip to content

Commit 4c4e6b8

Browse files
ficetoficeto
ficeto
authored and
ficeto
committed
spiffs fixes
1 parent b6c196a commit 4c4e6b8

File tree

3 files changed

+19
-17
lines changed

3 files changed

+19
-17
lines changed

cores/esp8266/FileSystem.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
class String;
2727

2828
#define FSFILE_READ SPIFFS_RDONLY
29-
#define FSFILE_WRITE (SPIFFS_RDONLY | SPIFFS_WRONLY | SPIFFS_CREAT | SPIFFS_APPEND | SPIFFS_DIRECT)
30-
#define FSFILE_OVERWRITE (SPIFFS_RDONLY | SPIFFS_WRONLY | SPIFFS_CREAT | SPIFFS_APPEND | SPIFFS_TRUNC | SPIFFS_DIRECT)
29+
#define FSFILE_WRITE (SPIFFS_RDONLY | SPIFFS_WRONLY | SPIFFS_CREAT | SPIFFS_APPEND )
30+
#define FSFILE_OVERWRITE (SPIFFS_RDONLY | SPIFFS_WRONLY | SPIFFS_CREAT | SPIFFS_APPEND | SPIFFS_TRUNC )
3131

3232
class FSFile : public Stream {
3333
private:

cores/esp8266/spiffs/spiffs.c

+8-6
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ static s32_t api_spiffs_write(u32_t addr, u32_t size, u8_t *src){
2121
static s32_t api_spiffs_erase(u32_t addr, u32_t size){
2222
debugf("api_spiffs_erase");
2323
u32_t sect_first = flashmem_get_sector_of_address(addr);
24-
u32_t sect_last = sect_first;
24+
u32_t sect_last = flashmem_get_sector_of_address(addr+size);
2525
while( sect_first <= sect_last )
2626
if( !flashmem_erase_sector( sect_first ++ ) )
2727
return SPIFFS_ERR_INTERNAL;
@@ -68,7 +68,7 @@ bool spiffs_format_internal(){
6868
return true;
6969
}
7070

71-
bool spiffs_mount(){
71+
bool spiffs_mount_internal(bool wipe){
7272
spiffs_config cfg = spiffs_get_storage_config();
7373
if (cfg.phys_addr == 0){
7474
SYSTEM_ERROR("Can't start file system, wrong address");
@@ -85,7 +85,7 @@ bool spiffs_mount(){
8585
bool writeFirst = false;
8686
flashmem_read(&dat, cfg.phys_addr, 4);
8787

88-
if (dat == UINT32_MAX){
88+
if (dat == UINT32_MAX || wipe){
8989
debugf("First init file system");
9090
if(!spiffs_format_internal()){
9191
SYSTEM_ERROR("Can't format file system");
@@ -115,15 +115,17 @@ bool spiffs_mount(){
115115
return true;
116116
}
117117

118+
bool spiffs_mount(){
119+
return spiffs_mount_internal(false);
120+
}
121+
118122
void spiffs_unmount(){
119123
SPIFFS_unmount(&_filesystemStorageHandle);
120124
}
121125

122126
bool spiffs_format(){
123127
spiffs_unmount();
124-
if(!spiffs_format_internal()) return false;
125-
spiffs_mount();
126-
return true;
128+
return spiffs_mount_internal(true);
127129
}
128130

129131
void test_spiffs(){

cores/esp8266/spiffs/spiffs_flashmem.c

+9-9
Original file line numberDiff line numberDiff line change
@@ -96,15 +96,6 @@ uint32_t flashmem_read( void *to, uint32_t fromaddr, uint32_t size )
9696
return ssize;
9797
}
9898

99-
bool flashmem_erase_sector( uint32_t sector_id )
100-
{
101-
WDT_RESET();
102-
noInterrupts();
103-
bool erased = spi_flash_erase_sector( sector_id ) == SPI_FLASH_RESULT_OK;
104-
interrupts();
105-
return erased;
106-
}
107-
10899
SPIFlashInfo flashmem_get_info()
109100
{
110101
volatile SPIFlashInfo spi_flash_info STORE_ATTR;
@@ -177,6 +168,15 @@ uint32_t flashmem_get_sector_of_address( uint32_t addr )
177168

178169
/////////////////////////////////////////////////////
179170

171+
bool flashmem_erase_sector( uint32_t sector_id )
172+
{
173+
WDT_RESET();
174+
noInterrupts();
175+
bool erased = spi_flash_erase_sector( sector_id ) == SPI_FLASH_RESULT_OK;
176+
interrupts();
177+
return erased;
178+
}
179+
180180
uint32_t flashmem_write_internal( const void *from, uint32_t toaddr, uint32_t size )
181181
{
182182
toaddr -= INTERNAL_FLASH_START_ADDRESS;

0 commit comments

Comments
 (0)