Hello,
I’m using lvgl 8.3.8 with STM32H750.
With code below (see “Driver-Test Code”) I can confirm that my SD-Card driver is working properly (I’ve no error ouput).
Now I try to connect LVGL with this driver, but without success.I enabled LV_USE_FATFS and LV_USE_BMP in lv.conf file.
I use following code, see “LVGL Code”. I do not get any log warning from LVGL.
What am I doing wrong here?
LVGL Code:
MX_SDMMC1_SD_Init();
MX_FATFS_Init();
lv_fs_fatfs_init();
static lv_style_t style;
lv_style_init(&style);
lv_style_set_bg_color(&style, lv_color_make(0xFF,0x00,0xFF));
lv_style_set_bg_opa(&style, LV_OPA_COVER);
img1 = lv_img_create(lv_scr_act());
lv_obj_set_size(img1, 320, 320);
lv_img_set_src(img1, "S:color.bmp");
lv_obj_set_pos(img1, 0, 0);
lv_obj_add_style(img1, &style, 0);
/*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
/*PNG decoder library*/
#define LV_USE_PNG 0
/*BMP decoder library*/
#define LV_USE_BMP 1
Driver-Test Code:
MX_SDMMC1_SD_Init();
MX_FATFS_Init();
#if 0
FATFS fs;
FRESULT res;
UART_Printf("Ready!\r\n");
// mount the default drive
res = f_mount(&fs, "", 0);
if(res != FR_OK) {
UART_Printf("f_mount() failed, res = %d\r\n", res);
return;
}
UART_Printf("f_mount() done!\r\n");
uint32_t freeClust;
FATFS* fs_ptr = &fs;
res = f_getfree("", &freeClust, &fs_ptr); // Warning! This fills fs.n_fatent and fs.csize!
if(res != FR_OK) {
UART_Printf("f_getfree() failed, res = %d\r\n", res);
return;
}
UART_Printf("f_getfree() done!\r\n");
uint32_t totalBlocks = (fs.n_fatent - 2) * fs.csize;
uint32_t freeBlocks = freeClust * fs.csize;
UART_Printf("Total blocks: %lu (%lu Mb)\r\n", totalBlocks, totalBlocks / 2000);
UART_Printf("Free blocks: %lu (%lu Mb)\r\n", freeBlocks, freeBlocks / 2000);
DIR dir;
res = f_opendir(&dir, "/");
if(res != FR_OK) {
UART_Printf("f_opendir() failed, res = %d\r\n", res);
return;
}
FILINFO fileInfo;
uint32_t totalFiles = 0;
uint32_t totalDirs = 0;
UART_Printf("--------\r\nRoot directory:\r\n");
for(;;) {
res = f_readdir(&dir, &fileInfo);
if((res != FR_OK) || (fileInfo.fname[0] == '\0')) {
break;
}
if(fileInfo.fattrib & AM_DIR) {
UART_Printf(" DIR %s\r\n", fileInfo.fname);
totalDirs++;
} else {
UART_Printf(" FILE %s\r\n", fileInfo.fname);
totalFiles++;
}
}
UART_Printf("(total: %lu dirs, %lu files)\r\n--------\r\n", totalDirs, totalFiles);
res = f_closedir(&dir);
if(res != FR_OK) {
UART_Printf("f_closedir() failed, res = %d\r\n", res);
return;
}
UART_Printf("Writing to log.txt...\r\n");
char writeBuff[128];
snprintf(writeBuff, sizeof(writeBuff), "Total blocks: %lu (%lu Mb); Free blocks: %lu (%lu Mb)\r\n",
totalBlocks, totalBlocks / 2000,
freeBlocks, freeBlocks / 2000);
FIL logFile;
res = f_open(&logFile, "log.txt", FA_OPEN_APPEND | FA_WRITE);
if(res != FR_OK) {
UART_Printf("f_open() failed, res = %d\r\n", res);
return;
}
unsigned int bytesToWrite = strlen(writeBuff);
unsigned int bytesWritten;
res = f_write(&logFile, writeBuff, bytesToWrite, &bytesWritten);
if(res != FR_OK) {
UART_Printf("f_write() failed, res = %d\r\n", res);
return;
}
if(bytesWritten < bytesToWrite) {
UART_Printf("WARNING! Disk is full, bytesToWrite = %lu, bytesWritten = %lu\r\n", bytesToWrite, bytesWritten);
}
res = f_close(&logFile);
if(res != FR_OK) {
UART_Printf("f_close() failed, res = %d\r\n", res);
return;
}
UART_Printf("Reading file...\r\n");
FIL msgFile;
res = f_open(&msgFile, "log.txt", FA_READ);
if(res != FR_OK) {
UART_Printf("f_open() failed, res = %d\r\n", res);
return;
}
char readBuff[128];
unsigned int bytesRead;
res = f_read(&msgFile, readBuff, sizeof(readBuff)-1, &bytesRead);
if(res != FR_OK) {
UART_Printf("f_read() failed, res = %d\r\n", res);
return;
}
readBuff[bytesRead] = '\0';
UART_Printf("```\r\n%s\r\n```\r\n", readBuff);
res = f_close(&msgFile);
if(res != FR_OK) {
UART_Printf("f_close() failed, res = %d\r\n", res);
return;
}
// Unmount
res = f_mount(NULL, "", 0);
if(res != FR_OK) {
UART_Printf("Unmount failed, res = %d\r\n", res);
return;
}
UART_Printf("Done!\r\n");
#endif