Setup POSIX File system to be able to use an image on an SD Card

Description

I’m trying to put all my image .bin files in an sd card to lighten the program size, so I am trying to setup the filesystem. I was told that POSIX was the way to go but I’m running into problems where the SD card is detected but the f_open function is returning null. What am I doing wrong?

What MCU/Processor/Board and compiler are you using?

ESP 32 Devkit on Arduino IDE

What LVGL version are you using?

8.3

What do you want to achieve?

Setup POSIX File system to be able to use an image on an SD Card for LVGL widgets

What have you tried so far?

See below

Code to reproduce

Enabled POSIX file system in lv_conf.h

#define LV_USE_FS_POSIX 1
#if LV_USE_FS_POSIX
    #define LV_FS_POSIX_LETTER 'S'
    #define LV_FS_POSIX_PATH "/"
    #define LV_FS_POSIX_CACHE_SIZE 512
#endif

then in my .ino file I added the following:

  
#define SCK  18
#define MISO  19
#define MOSI  23
#define CS  5

   ...

   SPIClass spi = SPIClass(VSPI);
   spi.begin(SCK, MISO, MOSI, CS);

   if (!SD.begin(CS, spi)) {
    Serial.println("Card Mount Failed");
    return;
  }
  uint8_t cardType = SD.cardType();

  if (cardType == CARD_NONE) {
    Serial.println("No SD card attached");
    return;
  }

  Serial.print("SD Card Type: ");
  if (cardType == CARD_MMC) {
    Serial.println("MMC");
  } else if (cardType == CARD_SD) {
    Serial.println("SDSC");
  } else if (cardType == CARD_SDHC) {
    Serial.println("SDHC");
  } else {
    Serial.println("UNKNOWN");
  }

  uint64_t cardSize = SD.cardSize() / (1024 * 1024);
  Serial.printf("SD Card Size: %lluMB\n", cardSize);

  Serial.println("initialisation done.");

  ...

  lv_init();
  Serial.println("initializing posix init...");
  lv_fs_posix_init();
  Serial.println("posix init done...");

  ...
  
  lv_obj_t * img_bin = lv_img_create(lv_scr_act());
  lv_img_set_src(img_bin, "S:/Baboon40.bin");
  lv_obj_align(img_bin, LV_ALIGN_CENTER, 0, 0);
  lv_obj_set_size(img_bin, 320,480);

then inside the fs_open function of lv_fs_posix.c, I added logging in lines 119:

    int f = open(buf, flags);
    if(f < 0) {
        printf("open returned null :( \r\n");
        return NULL;
    }

Screenshot and/or video

my logs in the serial monitor is this:

rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0030,len:1344
load:0x40078000,len:13864
load:0x40080400,len:3608
entry 0x400805f0
Hello Arduino! V8.3.1
I am LVGL_Arduino
SD Card Type: SDHC
SD Card Size: 14910MB
initialisation done.
lv_fs_posix_init

initializing posix init...
lv_fs_posix_init

posix init done...
fs_open

open returned null :(