cancel
Showing results for 
Search instead for 
Did you mean: 

How touchGFX read the image from image.bin stored in SD card?

Junde
Senior II

Hi all,

According to the document, I already store my image data to SD card and I can read the image data correctly by below function:

 

FRESULT read_bin_file(char *name, uint32_t offset, uint32_t numBytesToRead, uint8_t* dest)
{
	fresult = f_stat (name, &fno);
	if (fresult != FR_OK) {
		SD_ERR("\"%s\" does not exists\n", name);
	  return fresult;
	}
	
	fresult = f_open(&fil, name, FA_READ);
	if(fresult != FR_OK) {
		SD_ERR("opening file \"%s\" err[%d]\n", name, fresult);
		return fresult;
	}
	
	uint32_t numBytesRead = 0;
	f_lseek(&fil, offset);
	f_read(&fil, dest, numBytesToRead, &numBytesRead);
	if (fresult != FR_OK || numBytesRead != numBytesToRead) {
		memset(dest, 0, numBytesToRead);
		SD_ERR("read bin file \"%s\" err[%d]\n", name, fresult);
		f_close(&fil);
		return fresult;
	}
	
	fresult = f_close(&fil);
	if (fresult != FR_OK) {
		SD_ERR("close file[%s] err[%d]\n", name, fresult);
	}
	return fresult;
}

 

 I rewrite the TouchGFXHAL::blockCopy() function as below:

 

bool TouchGFXHAL::blockCopy(void* RESTRICT dest, const void* RESTRICT src, uint32_t numBytes)
{
	if ((uint32_t)src >= 0x70000000 && (uint32_t)src < 0x78000000)
  {
		LOG_DBG((char*)"read %d bytes at 0x%08x ", numBytes, (uint32_t)src);
    uint32_t offset = (uint32_t)src - 0x70000000;
		Mount_SD("");
		FRESULT res =  read_bin_file((char*)"IMAGE/images.bin", offset, numBytes, (uint8_t*)dest);
		Unmount_SD("");
		if(res == FR_OK) {
			LOG_DBG((char*)"OK\n");
			return true;
		} else {
			LOG_DBG((char*)"err[%d]\n", res);
			return false;
		}
  } else {
		LOG_DBG((char*)"read %d bytes at 0x%08x", numBytes, (uint32_t)src);
    return TouchGFXGeneratedHAL::blockCopy(dest, src, numBytes);
	}
}

 

 After compiler and flash the program, however, the display can NOT show the screen, and there is nothing LOG output.

Does the blockCopy() NOT be called normally?

Can anyone give me some ideas, Thanks! 

1 ACCEPTED SOLUTION

Accepted Solutions
Junde
Senior II

Not only should we store the image on the SD card, but we also need to get the image from the SD card actively.

Refer to the Document Here and the Video Here.

View solution in original post

4 REPLIES 4
Junde
Senior II

The map file info:

Junde_0-1716542411255.png

the read_bin_file() test result:

Junde_1-1716543300211.png

Junde
Senior II

Not only should we store the image on the SD card, but we also need to get the image from the SD card actively.

Refer to the Document Here and the Video Here.

Arisha
Associate II

If you you use SDRAM it's better to replace your image to the address of your pervious image. 

Just read the image file then set the address 

At the start of image address in the SDRAM

For example,  0xD0789000

This is work for PNG format and same size images 

Hi @Arisha 

My board has an external SDRAM, and I think the SD card is just for storing the image data for non-volatile.

Each time the system power on, the touchGFX will read the image data to SDRAM, and keep it for later access.

This is finished by "void Bitmap::cacheAll()"(if the SDRAM is enough), or "bool Bitmap::cache(BitmapId id)"(if the SDRAM is not enough for all the images).