diff --git a/samples/subsys/fs/littlefs/Kconfig b/samples/subsys/fs/littlefs/Kconfig index d98d95ca62b..3ba067fb0fd 100644 --- a/samples/subsys/fs/littlefs/Kconfig +++ b/samples/subsys/fs/littlefs/Kconfig @@ -17,6 +17,8 @@ choice config APP_LITTLEFS_STORAGE_FLASH bool "Use flash memory backend" +config APP_LITTLEFS_STORAGE_BLK_SDMMC + bool "Use block device (e.g. SD MMC) backend" endchoice source "Kconfig.zephyr" diff --git a/samples/subsys/fs/littlefs/README.rst b/samples/subsys/fs/littlefs/README.rst index b2918eeca20..a4ff2b7b224 100644 --- a/samples/subsys/fs/littlefs/README.rst +++ b/samples/subsys/fs/littlefs/README.rst @@ -19,6 +19,9 @@ Other information about the file system is also displayed. Requirements ************ +Flash memory device +------------------- + The partition labeled "storage" will be used for the file system; see :ref:`flash_map_api`. If that area does not already have a compatible littlefs file system its contents will be replaced by an @@ -38,15 +41,57 @@ After the file system is mounted you'll also see:: This error is also normal for Zephyr not finding a file (the boot count, in this case). +Block device (e.g. SD card) +--------------------------- + +One needs to prepare the SD card with littlefs file system on +the host machine with the `lfs`_ program. + +.. _lfs: + https://www.thevtool.com/mounting-littlefs-on-linux-machine/ + +.. code-block:: console + + sudo chmod a+rw /dev/sda + lfs -d -s -f --read_size=512 --prog_size=512 --block_size=512 --cache_size=512 --lookahead_size=8192 --format /dev/sda + lfs -d -s -f --read_size=512 --prog_size=512 --block_size=512 --cache_size=512 --lookahead_size=8192 /dev/sda ./mnt_littlefs + cd ./mnt_littlefs + echo -en '\x01' > foo.txt + cd - + fusermount -u ./mnt_littlefs + + Building and Running ******************** +Flash memory device +------------------- + This example should work on any board that provides a "storage" partition. Two tested board targets are described below. You can set ``CONFIG_APP_WIPE_STORAGE`` to force the file system to be recreated. +Block device (e.g. SD card) +--------------------------- + +This example has been devised and initially tested on :ref:`Nucleo H743ZI ` +board. It can be also run on any other board with SD card connected to it. + +To build the test: + +.. zephyr-app-commands:: + :zephyr-app: samples/subsys/fs/littlefs + :board: nucleo_h743zi + :goals: build flash + :gen-args: -DCONF_FILE=prj_blk.conf + :compact: + +One can also set ``CONFIG_SDMMC_VOLUME_NAME`` to provide the mount point name +for `littlefs` file system block device. + + NRF52840 Development Kit ======================== diff --git a/samples/subsys/fs/littlefs/boards/nucleo_h743zi.overlay b/samples/subsys/fs/littlefs/boards/nucleo_h743zi.overlay index 338dc605747..43be6063c67 100644 --- a/samples/subsys/fs/littlefs/boards/nucleo_h743zi.overlay +++ b/samples/subsys/fs/littlefs/boards/nucleo_h743zi.overlay @@ -1,10 +1,19 @@ /* - * Copyright (c) 2021 Lukasz Majewski, DENX Software Engineering GmbH + * Copyright (c) 2022 Lukasz Majewski, DENX Software Engineering GmbH * * SPDX-License-Identifier: Apache-2.0 */ /delete-node/ &storage_partition; +&sdmmc1 { + status = "okay"; + pinctrl-0 = <&sdmmc1_d0_pc8 + &sdmmc1_ck_pc12 + &sdmmc1_cmd_pd2>; + + pinctrl-names = "default"; +}; + &quadspi { pinctrl-0 = <&quadspi_clk_pf10 &quadspi_bk2_ncs_pc11 &quadspi_bk2_io0_pe7 &quadspi_bk2_io1_pe8 diff --git a/samples/subsys/fs/littlefs/boards/nucleo_h743zi_blk.conf b/samples/subsys/fs/littlefs/boards/nucleo_h743zi_blk.conf new file mode 100644 index 00000000000..f6a5fde1757 --- /dev/null +++ b/samples/subsys/fs/littlefs/boards/nucleo_h743zi_blk.conf @@ -0,0 +1,9 @@ +# +# Copyright (c) 2022 Lukasz Majewski, DENX Software Engineering GmbH +# +# SPDX-License-Identifier: Apache-2.0 +# +CONFIG_MAIN_STACK_SIZE=2048 +CONFIG_MINIMAL_LIBC_MALLOC_ARENA_SIZE=8192 + +CONFIG_FS_LITTLEFS_FC_HEAP_SIZE=8192 diff --git a/samples/subsys/fs/littlefs/prj_blk.conf b/samples/subsys/fs/littlefs/prj_blk.conf new file mode 100644 index 00000000000..50fdcdf9a94 --- /dev/null +++ b/samples/subsys/fs/littlefs/prj_blk.conf @@ -0,0 +1,26 @@ +# +# Copyright (c) 2022 Lukasz Majewski, DENX Software Engineering GmbH +# +# SPDX-License-Identifier: Apache-2.0 +# + +CONFIG_DISK_ACCESS=y +CONFIG_DISK_DRIVERS=y +CONFIG_DISK_DRIVER_SDMMC=y + +CONFIG_DEBUG=y +CONFIG_LOG=y +CONFIG_LOG_MODE_MINIMAL=y + +CONFIG_FLASH=y +CONFIG_FLASH_MAP=y +CONFIG_FLASH_PAGE_LAYOUT=y + +CONFIG_FILE_SYSTEM=y +CONFIG_FILE_SYSTEM_LITTLEFS=y + +CONFIG_FS_LITTLEFS_BLK_DEV=y +CONFIG_APP_LITTLEFS_STORAGE_BLK_SDMMC=y + +CONFIG_NOCACHE_MEMORY=y +CONFIG_SDMMC_STM32_HWFC=y diff --git a/samples/subsys/fs/littlefs/src/main.c b/samples/subsys/fs/littlefs/src/main.c index 7f0e71d8072..714f21ef868 100644 --- a/samples/subsys/fs/littlefs/src/main.c +++ b/samples/subsys/fs/littlefs/src/main.c @@ -308,6 +308,27 @@ static int littlefs_mount(struct fs_mount_t *mp) } #endif /* CONFIG_APP_LITTLEFS_STORAGE_FLASH */ +#ifdef CONFIG_APP_LITTLEFS_STORAGE_BLK_SDMMC +struct fs_littlefs lfsfs; +static struct fs_mount_t __mp = { + .type = FS_LITTLEFS, + .fs_data = &lfsfs, + .flags = FS_MOUNT_FLAG_USE_DISK_ACCESS, +}; +struct fs_mount_t *mp = &__mp; + +static int littlefs_mount(struct fs_mount_t *mp) +{ + static const char *disk_mount_pt = "/"CONFIG_SDMMC_VOLUME_NAME":"; + static const char *disk_pdrv = CONFIG_SDMMC_VOLUME_NAME; + + mp->storage_dev = (void *)disk_pdrv; + mp->mnt_point = disk_mount_pt; + + return fs_mount(mp); +} +#endif /* CONFIG_APP_LITTLEFS_STORAGE_BLK_SDMMC */ + void main(void) { char fname1[MAX_PATH_LEN];