Loading image (c array) from memory address

Intro

We are using LVGL with our ESP32-S3 (32MB flash memory). Since we have some large graphics and fonts (especially Chinese characters), we started storing the raw c-arrays of the images and fonts in fixed address spaces in the ESP32’s flash memory. Reason for not having the images/fonts compiled into the firmware is to keep the firmware.bin small to allow over-the-air updates and avoid storing those resources twice.

  • MCU: ESP32-S3-WROOM2-N32R8V (32MB flash memory)
  • LVGL Version: 8.3.6
  • Framework: Arduino (with TFT_eSPI)

Issue Description

When trying to access the image data at the respective memory address, the image area on the screen simply stays empty.

What did we try so far?

In the .c image file in /lib/ui/src/images we commented out the data array and saved this data in the EPS32’s memory address 0x1FD8000 instead.
The ui_img_myimage_160x160_png.data we replaced the reference to the data array into a pointer to the memory address (const uint8_t*)0x1FD8000.

#include “…/ui.h”

#ifndef LV_ATTRIBUTE_MEM_ALIGN
#define LV_ATTRIBUTE_MEM_ALIGN
#endif

// IMAGE DATA: assets/myimage_160x160.png
// const LV_ATTRIBUTE_MEM_ALIGN uint8_t ui_img_myimage_160x160_png_data = {0xFF,0xFF,0x00,0xFF, …};
const lv_img_dsc_t ui_img_fingerprint_160x160_png = {
.header.always_zero = 0,
.header.w = 160,
.header.h = 160,
.data_size = 1601603,
.header.cf = LV_IMG_CF_TRUE_COLOR_ALPHA,
.data = (const uint8_t*)0x1FD8000
};

When loading the image in the code we set the pointer to the memory address instead.

lv_img_set_src(ui_Screen8Icon, (const uint8_t*)0x1FD8000);

What are we trying to achieve?

How can we have LVGL load image data directly from a memory address?
We are not trying to have images stored as png or jpg files on SD-Cards (we saw a lot of documentation on this already). As we have the c-arrays stored in defined memory addresses, we would like to “simply” access them from there.

Thanks a lot for your support! :slight_smile:

Maybe try

lv_img_set_src(ui_Screen8Icon, &ui_img_fingerprint_160x160_png);

and your data_size seems be fail.

Thanks for your feedback! It brought us a step nearer, but seems to get more complex now.

Issue
The ESP32 crashes when trying to access the image data from flash. The image data is stored in memory address 0x016B6000 with a size of 76,800 bytes.
The log output of the ESP32 shows that the exception occurred when trying to access address 0x016B6002.

Guru Meditation Error: Core 1 panic’ed (LoadProhibited). Exception was unhandled.

Core 1 register dump:
PC : 0x4208d079 PS : 0x00060630 A0 : 0x821470b1 A1 : 0x3fccf8a0
A2 : 0x3d871d78 A3 : 0x00000000 A4 : 0x3fccfa28 A5 : 0x00000000
A6 : 0x000000a0 A7 : 0x00000140 A8 : 0x000001e0 A9 : 0x00000000
A10 : 0x000000a0 A11 : 0x00000002 A12 : 0x016b6000 A13 : 0x00000000
A14 : 0x016b6000 A15 : 0x3d81e970 SAR : 0x0000000a EXCCAUSE: 0x0000001c
EXCVADDR: 0x016b6002 LBEG : 0x42082f89 LEND : 0x42082fd0 LCOUNT : 0x0000000e

Backtrace: 0x4208d076:0x3fccf8a0 0x421470ae:0x3fccf960 0x4207a569:0x3fccf980 > 0x42086091:0x3fccf9e0 0x42147ee5:0x3fccfa70 0x420887d7:0x3fccfa90 > 0x4208898d:0x3fccfab0 0x42079104:0x3fccfaf0 0x420791ef:0x3fccfb40 0x4207916e:0x3fccfbc0 > 0x42079537:0x3fccfc10 0x4207959a:0x3fccfc90 0x4207971b:0x3fccfcc0 > 0x4207a31d:0x3fccfd90 0x42084128:0x3fccfde0 0x420599b9:0x3fccfe10

What we tried
We reviewed the lv_conf.h in the section of Memory Usage and added the attribute to align memory in blocks of 4-bytes.

#define LV_MEM_CUSTOM 1
#if LV_MEM_CUSTOM == 0
// Not used
#else /LV_MEM_CUSTOM/
#define LV_MEM_CUSTOM_INCLUDE <stdlib.h> /Header for the dynamic memory function/
//#define LV_MEM_CUSTOM_ALLOC malloc
//#define LV_MEM_CUSTOM_FREE free
//#define LV_MEM_CUSTOM_REALLOC realloc
#define LV_MEM_CUSTOM_INCLUDE <esp32-hal-psram.h> // For PSRAM allocation
#define LV_MEM_CUSTOM_ALLOC ps_malloc
#define LV_MEM_CUSTOM_FREE free
#define LV_MEM_CUSTOM_REALLOC ps_realloc
#endif /LV_MEM_CUSTOM/

#define LV_ATTRIBUTE_MEM_ALIGN attribute((aligned(4))) // Ensure 4-byte alignment

What we try to achieve
We would like to have the ESP32 accessing the images raw data from flash memory.
Is there anything we oversee or need to tell LVGL to properly access flash memory to obtain the image data? Are there any configurations we missed?

Thanks a lot for your support! :slight_smile:

Im not expert , but my tip you miss in idea your flash is memory mapped and accesible. In my idea bootloader ESP map only partitions in table and map it to code and data segments. Then for access any data outside this partitions your require add mappping. But this is non standart use.
Standart is partition flash and create filesystem for your data. Then simply use files in code …