Skip to content

Commit a188560

Browse files
pabigotcarlescufi
authored andcommitted
samples: littlefs: use DT-defined mount information
Extend the nrf52840dk_nrf52840 sample overlay with a fstab entry for a littlefs file system on the storage partition. This eliminates the need for application configuration of the file system parameters and mount data. Signed-off-by: Peter Bigot <[email protected]>
1 parent 5b544e1 commit a188560

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

samples/subsys/fs/littlefs/boards/nrf52840dk_nrf52840.overlay

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,30 @@
66

77
/delete-node/ &storage_partition;
88

9+
/ {
10+
fstab {
11+
compatible = "zephyr,fstab";
12+
lfs1: lfs1 {
13+
compatible = "zephyr,fstab,littlefs";
14+
mount-point = "/lfs1";
15+
partition = <&lfs1_part>;
16+
automount;
17+
read-size = <16>;
18+
prog-size = <16>;
19+
cache-size = <64>;
20+
lookahead-size = <32>;
21+
block-cycles = <512>;
22+
};
23+
};
24+
};
25+
926
&mx25r64 {
1027
partitions {
1128
compatible = "fixed-partitions";
1229
#address-cells = <1>;
1330
#size-cells = <1>;
1431

15-
partition@0 {
32+
lfs1_part: partition@0 {
1633
label = "storage";
1734
reg = <0x00000000 0x00010000>;
1835
};

samples/subsys/fs/littlefs/src/main.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,29 @@
1717
/* Matches LFS_NAME_MAX */
1818
#define MAX_PATH_LEN 255
1919

20+
#define PARTITION_NODE DT_NODELABEL(lfs1)
21+
22+
#if DT_NODE_EXISTS(PARTITION_NODE)
23+
FS_FSTAB_DECLARE_ENTRY(PARTITION_NODE);
24+
#else /* PARTITION_NODE */
2025
FS_LITTLEFS_DECLARE_DEFAULT_CONFIG(storage);
2126
static struct fs_mount_t lfs_storage_mnt = {
2227
.type = FS_LITTLEFS,
2328
.fs_data = &storage,
2429
.storage_dev = (void *)FLASH_AREA_ID(storage),
2530
.mnt_point = "/lfs",
2631
};
32+
#endif /* PARTITION_NODE */
2733

2834
void main(void)
2935
{
30-
struct fs_mount_t *mp = &lfs_storage_mnt;
36+
struct fs_mount_t *mp =
37+
#if DT_NODE_EXISTS(PARTITION_NODE)
38+
&FS_FSTAB_ENTRY(PARTITION_NODE)
39+
#else
40+
&lfs_storage_mnt
41+
#endif
42+
;
3143
unsigned int id = (uintptr_t)mp->storage_dev;
3244
char fname[MAX_PATH_LEN];
3345
struct fs_statvfs sbuf;

0 commit comments

Comments
 (0)