1.. _lfs:
2
3==============
4littlefs
5==============
6
7littlefs is a little fail-safe filesystem designed for microcontrollers.
8
9Detailed introduction: https://github.com/littlefs-project/littlefs
10
11
12Usage
13-----
14
15Enable :c:macro:`LV_USE_FS_LITTLEFS` and define a :c:macro:`LV_FS_LITTLEFS_LETTER` in ``lv_conf.h``.
16
17When enabled :c:macro:`lv_littlefs_set_handler` can be used to set up a mount point.
18
19Example
20-------
21
22.. code-block:: c
23
24    #include "lfs.h"
25
26    // configuration of the filesystem is provided by this struct
27    const struct lfs_config cfg = {
28        // block device operations
29        .read  = user_provided_block_device_read,
30        .prog  = user_provided_block_device_prog,
31        .erase = user_provided_block_device_erase,
32        .sync  = user_provided_block_device_sync,
33
34        // block device configuration
35        .read_size = 16,
36        .prog_size = 16,
37        .block_size = 4096,
38        .block_count = 128,
39        .cache_size = 16,
40        .lookahead_size = 16,
41        .block_cycles = 500,
42    };
43
44    // mount the filesystem
45    int err = lfs_mount(&lfs, &cfg);
46
47    // reformat if we can't mount the filesystem
48    // this should only happen on the first boot
49    if (err) {
50        lfs_format(&lfs, &cfg);
51        lfs_mount(&lfs, &cfg);
52    }
53
54    lv_littlefs_set_handler(&lfs);
55
56
57API
58---
59
60
61