You can use a macro in your board.c
to create a mountpoint for littlefs2:
VFS_AUTO_MOUNT(littlefs2, VFS_MTD(my_mtd_dev), VFS_DEFAULT_NVM(0), 0);
This will use my_mtd_dev
for littlefs and mount it as /nvm0
(that’s what VFS_DEFAULT_NVM(0)
expands to, you can change that if you want a different mountpoint).
my_mtd_dev
is your MTD device, for SPI connected NOR flash you’d have
static mtd_spi_nor_t my_mtd_dev = {
.base = {
.driver = &mtd_spi_nor_driver,
.page_size = 256,
.pages_per_sector = 16, // 4k sectors
},
.params = &my_spi_nor_params,
};
my_spi_nor_params
contains the configuration (pins, timings) for your flash, e.g. :
static const mtd_spi_nor_params_t _same54_nor_params = {
.opcode = &mtd_spi_nor_opcode_default,
.wait_chip_erase = 240 * US_PER_SEC, // check with data sheet
.wait_64k_erase = 700 * US_PER_MS,
.wait_sector_erase = 250 * US_PER_MS,
.wait_chip_wake_up = 1 * US_PER_MS,
.clk = MHZ(54), // check with data sheet
.flag = SPI_NOR_F_SECT_4K | SPI_NOR_F_SECT_64K, // check with data sheet
.spi = SPI_DEV(…), // insert your SPI device index
.mode = SPI_MODE_0,
.cs = GPIO_PIN(…), // insert your pin
.wp = GPIO_PIN(…),
.hold = GPIO_PIN(…),
};
To enable the fs automatically, add
ifneq (,$(filter mtd,$(USEMODULE)))
USEMODULE += mtd_spi_nor
endif
ifneq (,$(filter vfs_default,$(USEMODULE)))
USEPKG += littlefs2
USEMODULE += mtd
endif
to your board’s Makefile.dep
To check if everything works correctly, you can run tests/sys/vfs_default