Error working with FatFS

Dear Friends,

I’m desperately trying to get the internal filesystem of an ESP32 working inside the LVGL framework. I am using LVGL 9.1.0. The first issue was that it couldn’t compile because of an “unknown type name ‘DIR’; did you mean ‘DDR’” error. After a lot of searching, I finally found following fix: FIX, which for whatever reason hasn’t been implemented in version 9.1. This solved the error preventing a successful compilation. However, I could find nowhere a good, working example code of the Usage of FatFS in LVGL. Before the question arises: the filesystem works great, when I utilize the traditional “FFat.h” to access it.

lv_conf.h has been modified as follows:

#define LV_USE_FS_FATFS 1
#if LV_USE_FS_FATFS
    #define LV_FS_FATFS_LETTER 'A'     /*Set an upper cased letter on which the drive will accessible (e.g. 'A')*/
    #define LV_FS_FATFS_CACHE_SIZE 460800    /*>0 to cache this number of bytes in lv_fs_read()*/
#endif

The small sample code is as follows:

#include <lvgl.h>

void setup() {
  Serial.begin(115200);
  Serial.println("Small FatFS Test!");

  lv_init();
  //_lv_fs_init();
  char buf;
  Serial.println(lv_fs_is_ready('A'));
  lv_fs_get_letters(&buf);
  Serial.println(buf);
  lv_fs_file_t f;
  lv_fs_res_t res;
  res = lv_fs_open(&f, "A:picture.png", LV_FS_MODE_RD);
  Serial.println(res);

  lv_fs_close(&f);

  Serial.println("Finish Setup!");
}

The code returns:

Small FatFS Test!
1 (<- Filesystem should be ready - CORRECT)
A (<- Should be mounted to the letter 'A' - CORRECT)
12 (<- I'm assuming this indicates an 'LV_FS_RES_UNKNOWN' Error.)
Finish Setup!

What am I missing? What do I need to do in order to access the filesystem correctly? Am I missing some initialization? Of course, the file exists. If I try to open a directory with lv_fs_dir_open the same LV_FS_RES_UNKNOWN Error is thrown - even when I try to access the root with A: or A:/

Hey Banjo,

I’m trying to do exactly the same thing.

It’s not very clear on my side how to use the FAT memory.

I have found this function lv_fs_fatfs_init(); . Not quite sure how it works or even if it’s usefull.

Let me know if you fix your problem.

Thomas.

Thanks for your input, Thomas. Unfortunately, lv_fs_fatfs_init(); is not applicable for LVGL version >= 9. But I think, I finally got the solution. I’m pretty certain that I tried this before without success… but it could be that some other thing didn’t work at that time. The solution is to:
1.) include "FFat.h"
2.) call FFat.begin() at the beginning of your code

Got it while analyzing the code and finding this part here from lv_fs_fatfs.c:

static void fs_init(void)
{
    /*Initialize the SD card and FatFS itself.
     *Better to do it in your code to keep this library untouched for easy updating*/
}

However, now I have the next problem getting a core dump when loading files after initializing my touchscreen with Wire.begin - which for now doesn’t make any sense…

Finally! I can’t believe it… but I got it running. It seems that the TAMC_GT911 library is faulty and causes really weird behaviour. So better don’t use it. After switching to bb_captouch, it is working now.

Hey Banjo,

Nice to hear you finally got it working :slight_smile:

It’s working also on my side thanks to your code snippet.

Have you tried to load some img and display it to the screen ?

I’m facing new issue about no enought memory to display img.

I’m using bin file so I need to enable decoder in lv_conf.h :

/*Decode bin images to RAM*/
#define LV_BIN_DECODER_RAM_LOAD 1

But i’m very limited in number of IMG.
I will create another post about this topic, but if you have any hints, feel free to share.

Thomas.