Should LittleFS work on bare metal (without RTOS)? I tried to compile a program using LittleFS on SPIF with { "requires": ["bare-metal"] }
, but the compiler was unable to find the header file.
It worked for us on a uBlox Nina B3 ( Nordic chip ). Here’s our mbed app json:
{
"requires": [ "bare-metal", "nordic" ],
"target_overrides": {
"NRF52840_DK": {
"target.features_remove": [ "CRYPTOCELL310" ]
}
And here’s the littleFS instantiation:
#include "SPIFBlockDevice.h"
using namespace mbed;
SPIFBlockDevice flash_bd(MBED_CONF_SPIF_DRIVER_SPI_MOSI,
MBED_CONF_SPIF_DRIVER_SPI_MISO,
MBED_CONF_SPIF_DRIVER_SPI_CLK,
MBED_CONF_SPIF_DRIVER_SPI_CS,
MBED_CONF_SPIF_DRIVER_SPI_FREQ);
#include "lfs.h"
#include "FlashIAP.h"
// variables used by the filesystem
lfs_t lfs;
lfs_file_t file;
FlashIAP internal_flash;
//function prototypes
static void lfs_bd_init(lfs_config* cfg);
static int lfs_bd_read(const struct lfs_config *c, lfs_block_t block,
lfs_off_t off, void *buffer, lfs_size_t size);
static int lfs_bd_prog(const struct lfs_config *c, lfs_block_t block,
lfs_off_t off, const void *buffer, lfs_size_t size);
static int lfs_bd_erase(const struct lfs_config *c, lfs_block_t block);
static int lfs_bd_sync(const struct lfs_config *c);
// configuration of the filesystem is provided by this struct
struct lfs_config cfg = {
// block device operations
.context = &flash_bd,
.read = lfs_bd_read,
.prog = lfs_bd_prog,
.erase = lfs_bd_erase,
.sync = lfs_bd_sync,
};
}
}
I also found this file compiled in ( I didn’t write the code )
#include "lfs.h"
#include "lfs_util.h"
#include "MbedCRC.h"
namespace mbed {
//Copied from LittleFileSystem.cpp. Couldn't use the default version since it is
//gaurded by preprocessors #ifndef that are needed for other processes, and
//including the LittleFileSystem.h and LittleFileSystem.cpp would require a
//large amount of overhead just for this function. As per ARM mbed documentation
//this function is intended to be replaced by custom code if desired, so this
//makes it more reasonable to copy from known source.
extern "C" void lfs_crc(uint32_t *crc, const void *buffer, size_t size)
{
uint32_t initial_xor = *crc;
MbedCRC<POLY_32BIT_REV_ANSI, 32> ct(initial_xor, 0x0, true, false);
ct.compute((void *)buffer, size, (uint32_t *) crc);
}
} //namespace mbed