-
My goal is:
Correctly use lfs functions to save files in a external SPI Flash memory. -
My actions are:
Using Fstab to mount the Flash in initialization:config_schema:
[“spi.enable”, true]
[“devtab.dev0.name”, “spif0”]
[“devtab.dev0.type”, “spi_flash”]
[“devtab.dev0.opts”, ‘{“cs”: 0, “freq”: 10000000}’]
[“fstab.fs0.dev”, “spif0”]
[“fstab.fs0.type”, “LFS”]
[“fstab.fs0.opts”, ‘{“bs”: 4096}’]
[“fstab.fs0.path”, “/data”]
[“fstab.fs0.create”, true]
Initialization ok and returns on Log:
[Aug 16 13:36:01.999] bcn 100 [Aug 16 13:36:01.999] esp_wifi.c:344 WiFi AP IP: 192.168.4.1/255.255.255.0 gw 192.168.4.1, DHCP range 192.168.4.2 - 192.168.4.100 [Aug 16 13:36:02.011] mgos_http_server.c:282 HTTP server started on [80] [Aug 16 13:36:02.022] mgos_spi_gpio.c:72 SPI GPIO init ok (MISO: 12, MOSI: 13, SCLK: 14; CS0/1/2: 15/0/0) [Aug 16 13:36:02.032] mgos_vfs_dev.c:73 spif0: spi_flash ({"cs": 0, "freq": 10000000}), size 2097152 [Aug 16 13:36:02.038] mgos_vfs.c:147 /data: LFS @ spif0, opts {"bs": 4096} [Aug 16 13:36:02.062] mgos_vfs.c:320 /data: size 2097152, used: 8192, free: 2088960 [Aug 16 13:36:02.068] mgos_provision_btn.c:75 Factory reset button: pin 0, pull up, hold_ms 0 (hold on boot) [Aug 16 13:36:02.088] mgos_provision_stat:119 Max state: 0 [Aug 16 13:36:02.088] mgos_rpc_channel_mq:203 0x3fff1f04 esp8266_249943/rpc [Aug 16 13:36:02.099] mgos_rpc_channel_ua:313 0x3fff254c UART0
My C function is the simplest as possible:
#include "mgos.h"
#include "lfs.h"
#include "lfs_util.h"
// variables used by the filesystem
lfs_t lfs;
lfs_file_t file;
enum mgos_app_init_result mgos_app_init(void) {
lfs_file_open(&lfs, &file, "/data/test.txt", LFS_O_RDWR | LFS_O_CREAT);
lfs_file_close(&lfs, &file);
return MGOS_APP_INIT_SUCCESS;
}
- The result I see is:
> [Aug 16 13:36:02.011] mgos_http_server.c:282 HTTP server started on [80] > [Aug 16 13:36:02.022] mgos_spi_gpio.c:72 SPI GPIO init ok (MISO: 12, MOSI: 13, SCLK: 14; CS0/1/2: 15/0/0) > [Aug 16 13:36:02.032] mgos_vfs_dev.c:73 spif0: spi_flash ({"cs": 0, "freq": 10000000}), size 2097152 > [Aug 16 13:36:02.038] mgos_vfs.c:147 /data: LFS @ spif0, opts {"bs": 4096} > [Aug 16 13:36:02.062] mgos_vfs.c:320 /data: size 2097152, used: 8192, free: 2088960 > [Aug 16 13:36:02.068] mgos_provision_btn.c:75 Factory reset button: pin 0, pull up, hold_ms 0 (hold on boot) > [Aug 16 13:36:02.088] mgos_provision_stat:119 Max state: 0 > [Aug 16 13:36:02.088] mgos_rpc_channel_mq:203 0x3fff1f04 esp8266_249943/rpc > [Aug 16 13:36:02.099] mgos_rpc_channel_ua:313 0x3fff254c UART0 > [Aug 16 13:36:02.099] > [Aug 16 13:36:02.099] Exception 28 @ 0x40299b9b, vaddr 0x0000001c > [Aug 16 13:36:02.105] A0: 0x4029ac64 A1: 0x3ffff8f0 A2: 0x00000004 A3: 0x00000000 > [Aug 16 13:36:02.110] A4: 0x3ffeeff0 A5: 0x00000004 A6: 0x00000000 A7: 0x00000000 > [Aug 16 13:36:02.129] A8: 0x00000000 A9: 0x00000090 A10: 0x3ffee95c A11: 0xffff8000 > [Aug 16 13:36:02.134] A12: 0x00000000 A13: 0x00000004 A14: 0x3ffeeff0 A15: 0x00000000 > [Aug 16 13:36:02.134] > [Aug 16 13:36:02.134] (exc SP: 0x3ffff750) > [Aug 16 13:36:02.134] > [Aug 16 13:36:02.134] --- BEGIN CORE DUMP --- > [Aug 16 13:36:02.137] mos: catching core dump > [Aug 16 13:36:04.975] .... > [Aug 16 13:36:13.681] ---- END CORE DUMP ---- > [Aug 16 13:36:13.684] mos: wrote to C:\mos\MyMemmoryPlayer\core-MyMemmoryPlayer-esp8266-20190816-133613.948335361 (133119 bytes) > [Aug 16 13:36:13.708] mos: analyzing core dump
- My expectation & question is:
How or what do I need to do to save files correctly using lfs functions do the partition /data created?