diff --git a/os/various/littlefs_bindings/lfs_hal.h b/os/various/littlefs_bindings/lfs_hal.h
index a8eb10750..c1b5c6a76 100644
--- a/os/various/littlefs_bindings/lfs_hal.h
+++ b/os/various/littlefs_bindings/lfs_hal.h
@@ -61,7 +61,6 @@
#ifdef __cplusplus
extern "C" {
#endif
- void lfsInit(void);
int __lfs_read(const struct lfs_config *c, lfs_block_t block,
lfs_off_t off, void *buffer, lfs_size_t size);
int __lfs_prog(const struct lfs_config *c, lfs_block_t block,
diff --git a/readme.txt b/readme.txt
index 01f828909..15c4e2bbc 100644
--- a/readme.txt
+++ b/readme.txt
@@ -74,6 +74,7 @@
*****************************************************************************
*** Next ***
+- NEW: Added integration of LittleFS on top of our flash infrastructure.
- NEW: Added a new MEM_IS_VALID_FUNCTION() macro to RT and NIL.
- NEW: Improved HAL flash interface with mutual exclusion methods, improved
EFL and SNOR drivers to use it.
diff --git a/testhal/STM32/multi/WSPI-LITTLEFS/.project b/testhal/STM32/multi/WSPI-LITTLEFS/.project
index dfe8c6817..0e0e9fb5d 100644
--- a/testhal/STM32/multi/WSPI-LITTLEFS/.project
+++ b/testhal/STM32/multi/WSPI-LITTLEFS/.project
@@ -76,6 +76,11 @@
org.eclipse.cdt.managedbuilder.core.ScannerConfigNature
+
+ littlefs
+ 2
+ CHIBIOS/ext/littlefs
+
os
2
diff --git a/testhal/STM32/multi/WSPI-LITTLEFS/main.c b/testhal/STM32/multi/WSPI-LITTLEFS/main.c
index fb81460c6..7773521be 100644
--- a/testhal/STM32/multi/WSPI-LITTLEFS/main.c
+++ b/testhal/STM32/multi/WSPI-LITTLEFS/main.c
@@ -18,17 +18,54 @@
#include "ch.h"
#include "hal.h"
+#include "lfs.h"
+#include "lfs_hal.h"
#include "hal_serial_nor.h"
#include "portab.h"
-const SNORConfig snorcfg1 = {
+static const SNORConfig snorcfg1 = {
.busp = &PORTAB_WSPI1,
.buscfg = &WSPIcfg1
};
-SNORDriver snor1;
+static SNORDriver snor1;
+
+static uint8_t __lfs_read_buffer[16];
+static uint8_t __lfs_prog_buffer[16];
+static uint8_t __lfs_lookahead_buffer[16];
+
+static const struct lfs_config lfscfg = {
+ /* Link to the flash device driver.*/
+ .context = &snor1,
+
+ /* Block device operations.*/
+ .read = __lfs_read,
+ .prog = __lfs_prog,
+ .erase = __lfs_erase,
+ .sync = __lfs_sync,
+ .lock = __lfs_lock,
+ .unlock = __lfs_unlock,
+
+ /* Block device configuration.*/
+ .read_size = 16,
+ .prog_size = 16,
+ .block_size = 4096,
+ .block_count = 128,
+ .block_cycles = 500,
+ .cache_size = 16,
+ .lookahead_size = 16,
+ .read_buffer = __lfs_read_buffer,
+ .prog_buffer = __lfs_prog_buffer,
+ .lookahead_buffer = __lfs_lookahead_buffer,
+ .name_max = 0,
+ .file_max = 0,
+ .attr_max = 0,
+ .metadata_max = 0
+};
+
+static lfs_t lfs;
/*
* LED blinker thread, times are in milliseconds.
@@ -50,6 +87,7 @@ static THD_FUNCTION(Thread1, arg) {
* Application entry point.
*/
int main(void) {
+ int err;
/*
* System initializations.
@@ -70,19 +108,23 @@ int main(void) {
/* Initializing and starting snor1 driver.*/
snorObjectInit(&snor1);
snorStart(&snor1, &snorcfg1);
-#if 1
- /* Testing memory mapped mode.*/
- {
- uint8_t *addr;
- snorMemoryMap(&snor1, &addr);
- chThdSleepMilliseconds(50);
- snorMemoryUnmap(&snor1);
- }
-#endif
/* Creates the blinker thread.*/
chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);
+ /* Mounting the file system, if it fails then formatting.*/
+ err = lfs_mount(&lfs, &lfscfg);
+ if (err < 0) {
+ err = lfs_format(&lfs, &lfscfg);
+ if (err < 0) {
+ chSysHalt("LFS format failed");
+ }
+ err = lfs_mount(&lfs, &lfscfg);
+ if (err < 0) {
+ chSysHalt("LFS mount failed");
+ }
+ }
+
/* Normal main() thread activity, in this demo it does nothing.*/
while (true) {
if (palReadLine(PORTAB_LINE_BUTTON) == PORTAB_BUTTON_PRESSED) {
diff --git a/testhal/STM32/multi/WSPI-LITTLEFS/make/stm32l4r9ai_discovery.make b/testhal/STM32/multi/WSPI-LITTLEFS/make/stm32l4r9ai_discovery.make
index bb6c290a6..8ba6eb21c 100644
--- a/testhal/STM32/multi/WSPI-LITTLEFS/make/stm32l4r9ai_discovery.make
+++ b/testhal/STM32/multi/WSPI-LITTLEFS/make/stm32l4r9ai_discovery.make
@@ -55,7 +55,7 @@ endif
# Stack size to be allocated to the Cortex-M process stack. This stack is
# the stack used by the main() thread.
ifeq ($(USE_PROCESS_STACKSIZE),)
- USE_PROCESS_STACKSIZE = 0x400
+ USE_PROCESS_STACKSIZE = 0x800
endif
# Stack size to the allocated to the Cortex-M main/exceptions stack. This