cancel
Showing results for 
Search instead for 
Did you mean: 

How to read .bin file for Touchgfx

Datome
Associate II

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();
 
 
}

19 REPLIES 19
MM..1
Chief II

You debug your code fread?

Datome
Associate II

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
Chief II
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
Associate II

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

Datome
Associate II
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
Chief II

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

or turn off caching and solve SDCARD first...

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
Associate II

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
Chief II

Realy your LD file and clibs can alloc this?

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