add filesystem format()

This commit is contained in:
hathach committed 2018-10-25 17:21:23 +07:00
1 parent d97818faed
commit 70305da5e7
9 files changed
+156 -13

No files matched your search

+7
View File
@@ -228,6 +228,13 @@ bool fal_qspi_erase (uint32_t addr)
return true;
}
bool flash_qspi_chiperase (void)
{
VERIFY(_flash_dev);
VERIFY(NRFX_SUCCESS == nrfx_qspi_erase(NRF_QSPI_ERASE_LEN_ALL, 0));
return true;
}
static uint32_t fal_qspi_program (uint32_t dst, void const * src, uint32_t len)
{
VERIFY(_flash_dev, 0);
+2 -1
View File
@@ -46,9 +46,10 @@
#endif
void flash_qspi_init (void);
uint32_t flash_qspi_size (void);
void flash_qspi_flush (void);
bool flash_qspi_erase (uint32_t addr);
uint32_t flash_qspi_size (void);
bool flash_qspi_chiperase (void);
uint32_t flash_qspi_write (uint32_t dst, void const * src, uint32_t len);
uint32_t flash_qspi_read (void* dst, uint32_t src, uint32_t len);
@@ -0,0 +1,53 @@
/*********************************************************************
This is an example for our nRF52 based Bluefruit LE modules
Pick one up today in the adafruit shop!
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
MIT license, check LICENSE for more information
All text above, and the splash screen below must be included in
any redistribution
*********************************************************************/
#include <FileIO.h>
// the setup function runs once when you press reset or power the board
void setup()
{
Serial.begin(115200);
while ( !Serial ) delay(10); // for nrf52840 with native usb
Serial.println("ExternalFS Format Example");
Serial.println();
// Wait for user input to run.
Serial.println("This sketch will destroy all of your data in External Flash!");
Serial.print("Enter any keys to continue:");
while ( !Serial.available() )
{
delay(1);
}
Serial.println();
Serial.println();
// Initialize Internal File System
ExternalFS.begin();
Serial.print("Formating ...");
delay(1);
// Format without erase
ExternalFS.format(true);
Serial.println("Done");
delay(1);
}
// the loop function runs over and over again forever
void loop()
{
// nothing to do
}
@@ -0,0 +1,53 @@
/*********************************************************************
This is an example for our nRF52 based Bluefruit LE modules
Pick one up today in the adafruit shop!
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
MIT license, check LICENSE for more information
All text above, and the splash screen below must be included in
any redistribution
*********************************************************************/
#include <FileIO.h>
// the setup function runs once when you press reset or power the board
void setup()
{
Serial.begin(115200);
while ( !Serial ) delay(10); // for nrf52840 with native usb
Serial.println("InternalFS Format Example");
Serial.println();
// Wait for user input to run.
Serial.println("This sketch will destroy all of your data in External Flash!");
Serial.print("Enter any keys to continue:");
while ( !Serial.available() )
{
delay(1);
}
Serial.println();
Serial.println();
// Initialize Internal File System
InternalFS.begin();
Serial.print("Formating ...");
delay(1);
// Format without erase
InternalFS.format(true);
Serial.println("Done");
delay(1);
}
// the loop function runs over and over again forever
void loop()
{
// nothing to do
}
+14 -5
View File
@@ -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);
+1
View File
@@ -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);
+3
View File
@@ -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
//--------------------------------------------------------------------+
+22 -7
View File
@@ -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);
+1
View File
@@ -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);