@@ -21,7 +21,7 @@ static s32_t api_spiffs_write(u32_t addr, u32_t size, u8_t *src){
21
21
static s32_t api_spiffs_erase (u32_t addr , u32_t size ){
22
22
debugf ("api_spiffs_erase" );
23
23
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 ) ;
25
25
while ( sect_first <= sect_last )
26
26
if ( !flashmem_erase_sector ( sect_first ++ ) )
27
27
return SPIFFS_ERR_INTERNAL ;
@@ -68,7 +68,7 @@ bool spiffs_format_internal(){
68
68
return true;
69
69
}
70
70
71
- bool spiffs_mount ( ){
71
+ bool spiffs_mount_internal ( bool wipe ){
72
72
spiffs_config cfg = spiffs_get_storage_config ();
73
73
if (cfg .phys_addr == 0 ){
74
74
SYSTEM_ERROR ("Can't start file system, wrong address" );
@@ -85,7 +85,7 @@ bool spiffs_mount(){
85
85
bool writeFirst = false;
86
86
flashmem_read (& dat , cfg .phys_addr , 4 );
87
87
88
- if (dat == UINT32_MAX ){
88
+ if (dat == UINT32_MAX || wipe ){
89
89
debugf ("First init file system" );
90
90
if (!spiffs_format_internal ()){
91
91
SYSTEM_ERROR ("Can't format file system" );
@@ -115,15 +115,17 @@ bool spiffs_mount(){
115
115
return true;
116
116
}
117
117
118
+ bool spiffs_mount (){
119
+ return spiffs_mount_internal (false);
120
+ }
121
+
118
122
void spiffs_unmount (){
119
123
SPIFFS_unmount (& _filesystemStorageHandle );
120
124
}
121
125
122
126
bool spiffs_format (){
123
127
spiffs_unmount ();
124
- if (!spiffs_format_internal ()) return false;
125
- spiffs_mount ();
126
- return true;
128
+ return spiffs_mount_internal (true);
127
129
}
128
130
129
131
void test_spiffs (){
0 commit comments