add filesystem format()
This commit is contained in:
1 parent
d97818faed
commit
70305da5e7
9 files changed
+156
-13
No files matched your search
@@ -39,6 +39,7 @@
|
||||
#include <Arduino.h>
|
||||
#include <string.h>
|
||||
#include "ExternalFS.h"
|
||||
#include "flash/flash_qspi.h"
|
||||
|
||||
// up to 11 characters
|
||||
#define VOLUME_LABEL "BLUEFRUIT"
|
||||
@@ -135,11 +136,7 @@ bool FatFS::begin (void)
|
||||
if ( FR_NO_FILESYSTEM == err )
|
||||
{
|
||||
LOG_LV1("FATFS", "No file system, format it");
|
||||
|
||||
uint8_t workbuf[FF_MAX_SS];
|
||||
VERIFY_FAT(f_mkfs("", FM_FAT | FM_SFD, 4096, workbuf, FF_MAX_SS), false);
|
||||
|
||||
VERIFY_FAT(f_setlabel(VOLUME_LABEL), false);
|
||||
this->format(false);
|
||||
|
||||
// FatFile readme;
|
||||
// readme.open("readme.txt", FAT_FILE_WRITE | FAT_FILE_CREATE_ALWAYS);
|
||||
@@ -156,6 +153,18 @@ bool FatFS::begin (void)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool FatFS::format (bool eraseall)
|
||||
{
|
||||
if ( eraseall ) VERIFY(flash_qspi_chiperase());
|
||||
|
||||
uint8_t workbuf[FF_MAX_SS];
|
||||
VERIFY_FAT(f_mkfs("", FM_FAT | FM_SFD, 4096, workbuf, FF_MAX_SS), false);
|
||||
VERIFY_FAT(f_setlabel(VOLUME_LABEL), false);
|
||||
VERIFY_FAT(f_mount(_fs, "", 1), false);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
File FatFS::_open_file (char const *filepath, uint8_t mode)
|
||||
{
|
||||
BluefuritLib::File file(*this);
|
||||
|
||||
@@ -56,6 +56,7 @@ class FatFS: public BluefuritLib::FileSystemClass
|
||||
bool remove (char const *filepath);
|
||||
bool rmdir (char const *filepath);
|
||||
bool rmdir_r (char const *filepath);
|
||||
bool format (bool eraseall);
|
||||
|
||||
virtual size_t _f_write (void* fhdl, uint8_t const *buf, size_t size);
|
||||
virtual int _f_read (void* fhdl, void *buf, uint16_t nbyte);
|
||||
|
||||
@@ -118,6 +118,9 @@ class FileSystemClass
|
||||
// Delete a folder (recursively)
|
||||
virtual bool rmdir_r (char const *filepath) = 0;
|
||||
|
||||
// format whole file system
|
||||
virtual bool format (bool eraseall);
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Internal API, shouldn't call directly
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
@@ -40,13 +40,13 @@
|
||||
#include "flash/flash_nrf5x.h"
|
||||
|
||||
#ifdef NRF52840_XXAA
|
||||
#define LFS_FLASH_ADDR 0xED000
|
||||
#define LFS_FLASH_ADDR 0xED000
|
||||
#else
|
||||
#define LFS_FLASH_ADDR 0x6D000
|
||||
#define LFS_FLASH_ADDR 0x6D000
|
||||
#endif
|
||||
|
||||
#define LFS_FLASH_SIZE (7*FLASH_NRF52_PAGE_SIZE)
|
||||
#define LFS_BLOCK_SIZE 128
|
||||
#define LFS_FLASH_TOTAL_SIZE (7*FLASH_NRF52_PAGE_SIZE)
|
||||
#define LFS_BLOCK_SIZE 128
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// LFS Disk IO
|
||||
@@ -182,7 +182,7 @@ LittleFS::LittleFS (void)
|
||||
_lfs_cfg.read_size = LFS_BLOCK_SIZE;
|
||||
_lfs_cfg.prog_size = LFS_BLOCK_SIZE;
|
||||
_lfs_cfg.block_size = LFS_BLOCK_SIZE;
|
||||
_lfs_cfg.block_count = LFS_FLASH_SIZE / LFS_BLOCK_SIZE;
|
||||
_lfs_cfg.block_count = LFS_FLASH_TOTAL_SIZE / LFS_BLOCK_SIZE;
|
||||
_lfs_cfg.lookahead = 128;
|
||||
|
||||
_begun = false;
|
||||
@@ -204,13 +204,28 @@ bool LittleFS::begin (void)
|
||||
if ( LFS_ERR_CORRUPT == err )
|
||||
{
|
||||
LOG_LV1("IFLASH", "Format internal file system");
|
||||
VERIFY_LFS(lfs_format(&_lfs, &_lfs_cfg), false);
|
||||
VERIFY_LFS(lfs_mount(&_lfs, &_lfs_cfg), false);
|
||||
this->format(false);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool LittleFS::format (bool eraseall)
|
||||
{
|
||||
if ( eraseall )
|
||||
{
|
||||
for ( uint32_t addr = LFS_FLASH_ADDR; addr < LFS_FLASH_ADDR + LFS_FLASH_TOTAL_SIZE; addr += FLASH_NRF52_PAGE_SIZE )
|
||||
{
|
||||
flash_nrf5x_erase(addr);
|
||||
}
|
||||
}
|
||||
|
||||
VERIFY_LFS(lfs_format(&_lfs, &_lfs_cfg), false);
|
||||
VERIFY_LFS(lfs_mount(&_lfs, &_lfs_cfg), false);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
BluefuritLib::File LittleFS::_open_file (char const *filepath, uint8_t mode)
|
||||
{
|
||||
BluefuritLib::File file(*this);
|
||||
|
||||
@@ -56,6 +56,7 @@ class LittleFS: public BluefuritLib::FileSystemClass
|
||||
bool remove (char const *filepath);
|
||||
bool rmdir (char const *filepath);
|
||||
bool rmdir_r (char const *filepath);
|
||||
bool format (bool eraseall);
|
||||
|
||||
virtual size_t _f_write (void* fhdl, uint8_t const *buf, size_t size);
|
||||
virtual int _f_read (void* fhdl, void *buf, uint16_t nbyte);
|
||||
|
||||
Reference in new issue
Block a user