My lvgl can not load a bin file from Fatfs.It said "No data".How can i fix it?

  • Be sure to update lvgl from the latest version from the master branch.


My lvgl cloud load an img from c array,and display it normal. But When i change to bin file ,and put it on my fatfs , display show “No data”. The flash and fatfs is work normal.
The bin file format is RGB565 with true color and alpha which is my succeed c array’ format.
I doubt the problem is on ‘lv_port_fs.c’ or i use the “lv_img_set_src” in worong way.
Unfortunately,my lvgl project is base on 7.0,i will update it when i free.

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

Complier:Keil 5.26

What do you want to achieve?

I want to make my lvgl show a img form fatfs normaly.

What have you tried so far?

I had changed bin’s format to true color & true color with alpha,but it does work.

Code to reproduce

The code block(s) should be between ```c and ``` tags:

Here is use the bin file:

lv_img_set_src(ui->Home_Background_img, "F:\\bg.bin");

Folowwing is the ‘lv_port_fs.c’ witch is connected lvgl and fatfs:

void lv_port_fs_init(void)
    lv_fs_drv_t fs_drv;

   fs_drv.letter = 'F';
    fs_drv.file_size = sizeof(file_t);
    fs_drv.ready_cb = NULL; 
    fs_drv.open_cb = fs_open;
    fs_drv.close_cb = fs_close;
    fs_drv.read_cb = fs_read;
    fs_drv.write_cb = fs_write;
    fs_drv.seek_cb = fs_seek;
    fs_drv.tell_cb = fs_tell;
    fs_drv.free_space_cb = fs_free;
    fs_drv.size_cb = fs_size;
    fs_drv.remove_cb = fs_remove;
    fs_drv.rename_cb = fs_rename;
    fs_drv.trunc_cb = fs_trunc;
//    fs_drv.rddir_size = sizeof(dir_t);
//    fs_drv.dir_close_cb = fs_dir_close;
//    fs_drv.dir_open_cb = fs_dir_open;
//    fs_drv.dir_read_cb = fs_dir_read;

static void fs_init(void)
		FileSteamInit(); //mount put on this function 
static lv_fs_res_t fs_open (lv_fs_drv_t * drv, void * file_p, const char * path, lv_fs_mode_t FSOperateMode)
	int8_t OperateMode = 0;
	char *path_buf = NULL;
	uint16_t path_len = strlen(path);
	path_buf = (char *)lv_mem_alloc(sizeof(char) * (path_len + 6));
	sprintf(path_buf, "0:/%s", path);
	if(FSOperateMode == LV_FS_MODE_WR) 
		OperateMode = FA_OPEN_ALWAYS | FA_WRITE;							
	else if(FSOperateMode == LV_FS_MODE_RD) 
		OperateMode = FA_OPEN_EXISTING | FA_READ;							
	else if(FSOperateMode == (LV_FS_MODE_WR | LV_FS_MODE_RD)) 
		OperateMode = FA_WRITE | FA_READ;											
	return lv_FSResult;
static lv_fs_res_t fs_close (lv_fs_drv_t * drv, void * file_p)
    return lv_FSResult;
static lv_fs_res_t fs_read (lv_fs_drv_t * drv, void * file_p, void * buf, uint32_t btr, uint32_t * br)
    return lv_FSResult;
static lv_fs_res_t fs_write(lv_fs_drv_t * drv, void * file_p, const void * buf, uint32_t btw, uint32_t * bw)
		return lv_FSResult;
static lv_fs_res_t fs_seek (lv_fs_drv_t * drv, void * file_p, uint32_t pos)
    return f_lseek(file_p,pos);
static lv_fs_res_t fs_size (lv_fs_drv_t * drv, void * file_p, uint32_t * size_p)
    *size_p = f_size((FIL *)file_p);
    return LV_FS_RES_OK;
static lv_fs_res_t fs_tell (lv_fs_drv_t * drv, void * file_p, uint32_t * pos_p)
		*pos_p=f_tell((FIL *)file_p);
		return LV_FS_RES_OK;
static lv_fs_res_t fs_remove (lv_fs_drv_t * drv, const char *path)
    return f_unlink(path);
static lv_fs_res_t fs_trunc (lv_fs_drv_t * drv, void * file_p)
    return f_truncate((FIL *)file_p);
static lv_fs_res_t fs_rename (lv_fs_drv_t * drv, const char * oldname, const char * newname)
    return f_rename(oldname,newname);
static lv_fs_res_t fs_free (lv_fs_drv_t * drv, uint32_t * total_p, uint32_t * free_p)
    lv_fs_res_t res;
    uint32_t fre_clust;
    uint32_t fre_sect;
    uint32_t tot_sect;
    FATFS *fs1 = &FileSystemObject;
    res = f_getfree((const TCHAR *)&drv->letter,&fre_clust,&fs1);
    if(res == 0)
        tot_sect = (fs1->n_fatent-2)*fs1->csize;
        fre_sect = fre_clust * fs1->csize;
        #if FF_MAX_SS != 512
        tot_sect *= 4096/512;
        tot_sect *= 4096/512;
				tot_sect *= 4096/512;
        tot_sect *= 4096/512;
        *total_p = tot_sect >> 1;
        *free_p = fre_sect >> 1;
    return res;

Screenshot and/or video

If possible, add screenshots and/or videos about the current state.

Please ,helo,save me.:sob:

Hi, try to remove F:\ from the path… The FatFS has drives numbered (0:) and this number is already added in your fs_open

Thanks your reply.
As your suggestion,i changed

lv_img_set_src(ui->Home_Background_img, "F:\\bg.bin");


ui->Home_Background_img = lv_img_create(lv_scr_act(),NULL);
lv_img_set_src(ui->Home_Background_img, "\bg.bin");

It still show “No data”.

Is there a possible problem with the bin file?
Looking forward to your reply,3Q.

3Q for your watching.
i solove this probelm today,it’s my bin files’ mistake.i send the flash bin file to the flash.

I have the same problem, I use sdsram ,The photo is no display or display half something display No date,Athought can adjust

lv_disp_buf_init(&disp_buf_1,buf_1, buf_2, LV_HOR_RES_MAX * 10);

but always display half or NO date