mirror of
https://github.com/esp8266/Arduino.git
synced 2025-06-16 11:21:18 +03:00
spiffs fixes
This commit is contained in:
@ -26,8 +26,8 @@
|
|||||||
class String;
|
class String;
|
||||||
|
|
||||||
#define FSFILE_READ SPIFFS_RDONLY
|
#define FSFILE_READ SPIFFS_RDONLY
|
||||||
#define FSFILE_WRITE (SPIFFS_RDONLY | SPIFFS_WRONLY | SPIFFS_CREAT | SPIFFS_APPEND | 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 | SPIFFS_DIRECT)
|
#define FSFILE_OVERWRITE (SPIFFS_RDONLY | SPIFFS_WRONLY | SPIFFS_CREAT | SPIFFS_APPEND | SPIFFS_TRUNC )
|
||||||
|
|
||||||
class FSFile : public Stream {
|
class FSFile : public Stream {
|
||||||
private:
|
private:
|
||||||
|
@ -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){
|
static s32_t api_spiffs_erase(u32_t addr, u32_t size){
|
||||||
debugf("api_spiffs_erase");
|
debugf("api_spiffs_erase");
|
||||||
u32_t sect_first = flashmem_get_sector_of_address(addr);
|
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 )
|
while( sect_first <= sect_last )
|
||||||
if( !flashmem_erase_sector( sect_first ++ ) )
|
if( !flashmem_erase_sector( sect_first ++ ) )
|
||||||
return SPIFFS_ERR_INTERNAL;
|
return SPIFFS_ERR_INTERNAL;
|
||||||
@ -68,7 +68,7 @@ bool spiffs_format_internal(){
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool spiffs_mount(){
|
bool spiffs_mount_internal(bool wipe){
|
||||||
spiffs_config cfg = spiffs_get_storage_config();
|
spiffs_config cfg = spiffs_get_storage_config();
|
||||||
if (cfg.phys_addr == 0){
|
if (cfg.phys_addr == 0){
|
||||||
SYSTEM_ERROR("Can't start file system, wrong address");
|
SYSTEM_ERROR("Can't start file system, wrong address");
|
||||||
@ -85,7 +85,7 @@ bool spiffs_mount(){
|
|||||||
bool writeFirst = false;
|
bool writeFirst = false;
|
||||||
flashmem_read(&dat, cfg.phys_addr, 4);
|
flashmem_read(&dat, cfg.phys_addr, 4);
|
||||||
|
|
||||||
if (dat == UINT32_MAX){
|
if (dat == UINT32_MAX || wipe){
|
||||||
debugf("First init file system");
|
debugf("First init file system");
|
||||||
if(!spiffs_format_internal()){
|
if(!spiffs_format_internal()){
|
||||||
SYSTEM_ERROR("Can't format file system");
|
SYSTEM_ERROR("Can't format file system");
|
||||||
@ -115,15 +115,17 @@ bool spiffs_mount(){
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool spiffs_mount(){
|
||||||
|
return spiffs_mount_internal(false);
|
||||||
|
}
|
||||||
|
|
||||||
void spiffs_unmount(){
|
void spiffs_unmount(){
|
||||||
SPIFFS_unmount(&_filesystemStorageHandle);
|
SPIFFS_unmount(&_filesystemStorageHandle);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool spiffs_format(){
|
bool spiffs_format(){
|
||||||
spiffs_unmount();
|
spiffs_unmount();
|
||||||
if(!spiffs_format_internal()) return false;
|
return spiffs_mount_internal(true);
|
||||||
spiffs_mount();
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_spiffs(){
|
void test_spiffs(){
|
||||||
|
@ -96,15 +96,6 @@ uint32_t flashmem_read( void *to, uint32_t fromaddr, uint32_t size )
|
|||||||
return ssize;
|
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()
|
SPIFlashInfo flashmem_get_info()
|
||||||
{
|
{
|
||||||
volatile SPIFlashInfo spi_flash_info STORE_ATTR;
|
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 )
|
uint32_t flashmem_write_internal( const void *from, uint32_t toaddr, uint32_t size )
|
||||||
{
|
{
|
||||||
toaddr -= INTERNAL_FLASH_START_ADDRESS;
|
toaddr -= INTERNAL_FLASH_START_ADDRESS;
|
||||||
|
Reference in New Issue
Block a user