Skip to main content
Datome
Associate II
December 28, 2020
Question

How to read .bin file for Touchgfx

  • December 28, 2020
  • 19 replies
  • 4555 views

Normally I can display all projects of touchgfx (which can be stored in internal memory) on my touchscreen without any problem.

For a larger project I needed to use a SD card. For this purpose, I compiled all the images into a .bin file and then saved it to SD card. I try to use blockcopy function as shown below but all I get is just a black screen.

To sum up, I dont know how to call the images. it will be appreciated if someone correct the mistakes or shift me to the the correct way.

bool TouchGFXHAL::blockCopy(void* RESTRICT dest, const void* RESTRICT src, uint32_t numBytes)
{
	uint32_t dataOffset = (uint32_t)src;
	if (dataOffset >= 0x9A000000 && dataOffset < 0xA0000000)
	{
		int fd;
 
		if(f_mount(&myFatFs,SDPath,1) == FR_OK)
		 {
			 if (f_open(&myFile,"images.bin",FA_OPEN_EXISTING | FA_READ) == FR_OK)
			 {
				 fd = open("images.bin", O_RDONLY, 0);
				 dataOffset = dataOffset - 0x9A000000;
				 lseek(fd, dataOffset, SEEK_SET);
				 read(fd, (uint8_t *)dest, numBytes);
				 close(fd);
			 }
				 return true;
		 }
 
	 else { return false;}
	}
 
 else
 { return HAL::blockCopy(dest, src, numBytes); }
 
}

for initialization ;

void TouchGFXHAL::initialize()
 
{
 
 uint16_t* cacheStartAddr = (uint16_t *) malloc(0x3000000);
 
 uint32_t cacheSize = 0x3000000; 
 
 Bitmap::removeCache();
 
 Bitmap::setCache(cacheStartAddr,cacheSize,1024);
 
 Bitmap::cacheAll();
 
 
}

This topic has been closed for replies.

19 replies

MM..1
Super User
December 28, 2020

You debug your code fread?

Datome
DatomeAuthor
Associate II
December 29, 2020

I saw that it enters the Bitmap::cacheAll(); but does not pass it over and stays there.

and it doesnot enter the blockcopy function.

MM..1
Super User
December 29, 2020
void TouchGFXHAL::initialize()
{
 // Calling parent implementation of initialize().
 //
 // To overwrite the generated implementation, omit call to parent function
 // and implemented needed functionality here.
 // Please note, HAL::initialize() must be called to initialize the framework.
 
 TouchGFXGeneratedHAL::initialize();
}

Datome
DatomeAuthor
Associate II
December 29, 2020

Sorry I forgot to paste it (TouchGFXGeneratedHAL::initialize();) into the code section of the question. it is already there.

Datome
DatomeAuthor
Associate II
December 29, 2020
void TouchGFXHAL::initialize()
{
 
 TouchGFXGeneratedHAL::initialize();
 
 uint16_t* cacheStartAddr = (uint16_t *) malloc(0x1400000);
 uint32_t cacheSize = 0x1400000; //20 MB, as example
 
 Bitmap::removeCache();
 Bitmap::setCache(cacheStartAddr,cacheSize,1024);
 Bitmap::cacheAll();
 
}

MM..1
Super User
December 29, 2020

Maybe you dont understand cache please apply Caching Bitmaps | TouchGFX Documentation

or turn off caching and solve SDCARD first...

December 29, 2020

To clear the problem, which part have you stucked in?

Reading data from sd card?

Coping data from sd card to ram?

Display the image?

Match the image into touchgfx?

Datome
DatomeAuthor
Associate II
December 30, 2020

I think the problem is related to the initialization coz after executing the cacheAll() , it doesnot get out from the initialize function. so it seems I need to understand caching process or find a sample code.

MM..1
Super User
December 30, 2020

Realy your LD file and clibs can alloc this?

 uint16_t* cacheStartAddr = (uint16_t *) malloc(0x1400000);
 uint32_t cacheSize = 0x1400000; //20 MB, as example

Datome
DatomeAuthor
Associate II
December 30, 2020

I found out the problem after reading your suggestion and it was written as "you must allocate slightly more memory than actually needed for the raw pixel data". after increasing the allocated memory the black screen disappeared and I can display some texts of the GUI on a white screen without images. Now I try to figure out how to display the images as well.

MM..1
Super User
December 30, 2020

Check in debuger breakpoint at line 2 how address is in cacheStartAddr.?