lvgl: FatFS doesn't work
Perform all steps below and tick them with [x]
- Read the FAQ
- Check the related part of the Documentation
- Update lvgl to the latest version
- Reproduce the issue in a Simulator
Describe the bug
Compile fails after enabling the FatFS usage in lv_conf.h
and try to use it:
/.../Arduino/libraries/lvgl/src/extra/libs/fsdrv/lv_fs_fatfs.c: In function 'fs_dir_open':
/.../Arduino/libraries/lvgl/src/extra/libs/fsdrv/lv_fs_fatfs.c:228:5: error: unknown type name 'DIR'; did you mean 'DDR'?
DIR * d = lv_mem_alloc(sizeof(DIR));
^~~
To Reproduce
enable FatsFS usage:
/*API for FATFS (needs to be added separately). Uses f_open, f_read, etc*/
#define LV_USE_FS_FATFS 1
#if LV_USE_FS_FATFS
#define LV_FS_FATFS_LETTER 'S' /*Set an upper cased letter on which the drive will accessible (e.g. 'A')*/
#define LV_FS_FATFS_CACHE_SIZE 0 /*>0 to cache this number of bytes in lv_fs_read()*/
#endif
Try to use it for instance with image upload:
LV_IMG_DECLARE(mountain);
lv_obj_t * backgroung = lv_img_create(lv_scr_act());
lv_img_set_src(backgroung, "S:mountain.bin");
lv_obj_align(backgroung, LV_ALIGN_CENTER, 0, -20);
lv_obj_set_size(backgroung, 800, 520);
Expected behavior
The compilation goes fine and FatFS can be used.
Screenshots or video
/.../Arduino/libraries/lvgl/src/extra/libs/fsdrv/lv_fs_fatfs.c: In function 'fs_dir_open':
/.../Arduino/libraries/lvgl/src/extra/libs/fsdrv/lv_fs_fatfs.c:228:5: error: unknown type name 'DIR'; did you mean 'DDR'?
DIR * d = lv_mem_alloc(sizeof(DIR));
^~~
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 24 (9 by maintainers)
Without gate crashing this issue, I am happy to raise a separate one but believe this is the same issue as @shur1k with LVGL FatFS, ie image not rendering. It doesn’t show the data element of the image but you can tell it is reading part of the file as it renders the pixel size correctly but displays a white box with
No Data
.I’ve posted about it in the LVGL forum LVGL is not loading image file with FatFS - no data and found a slight workaround but it is not perfect: I’m wondering whether it could be a bug with how the built-in File System utilises FatFs and
lv_img_set_src
as I’ve proven the file is being read manually and loaded via LVGL:lv_fs_res_t res = LV_FS_RES_OK;
lv_fs_file_t f;
res = lv_fs_open(&f, "A:image.bin", LV_FS_MODE_RD);
res = lv_fs_seek(&f, 0, LV_FS_SEEK_END);
res = lv_fs_tell(&f, &fSize);
res = lv_fs_read(&f, buf, fSize, &rd);
But it just doesnt render the image if I call
lv_img_set_src(img, "A:image.bin")
, I have to instead call my custom function to pre-loadlv_img_set_src(img, lv_img_dsc_load_src("A:image.bin"));
lv_img_dsc_load_src
I’ve not had a chance to debug but will hopefully look in to it this week.
If I set the log level to
LV_LOG_LEVEL_TRACE
it crashes on me just before it loads the image using the standard method as per the docs for loading a .bin image, below is part of the full logs captured up to the point it crashes.TRACE Log - Click Me to open
Trace Log
If I set the log level to
LV_LOG_LEVEL_WARN
it doesn’t crash but as previously it only shows a box withNo data
with the pixel size rendered correctly, below is the[Warn]
logs captured:If I use
lv_img_dsc_load_src
instead the image loads fine and no error logs. I do run out of allocated memory to buffer the image if my .bin file is over 40kB which I could increaseLV_MEM_SIZE
but not sure if that is the most efficient way of doing it compared to letting LVGL handle it all?