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

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.

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

Datome
Associate II

I couldn't achieve to display the images and I attached the result.

I can navigate through the pages of GUI coz it displays the buttons like a shadow. I couldn't find out the missing point.

0693W000006HKvFQAW.jpg

can you reply for question

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

Datome
Associate II

I changed it as;

uint16_t* cacheStartAddr = (uint16_t*)0xD1000000;

This is next chaos information please explain your full config, how SDRAM, where mapped, STM32xxxx usw ????

Adress 0xD1000000 is FYI 16M in SDRAM then your SDRAM when is mapped on 0xD0000000 must be 32M or more. ?

How big is your bin graphics file ?

?

?

Datome
Associate II

sorry for the missing information. yes my sdram is 32M and it is mapped to 0xD. I used 0xD0000000 and 0xD00D2F00 as double buffers of touchgfx. This demo version graphics occupies 4.7 MB.

    uint16_t* cacheStartAddr = (uint16_t*)0xD1000000;
    uint32_t cacheSize = 0x500000;

Then you read Using Non-Memory Mapped Flash for Storing Images | TouchGFX Documentation

and apply last part link in RAM, when your 16M is free and dont plan bigger bin file.

Remove all caching...

Datome
Associate II

the GUI size will be bigger than the ram size so I cannot store them as you suggested.

Then all you need is  Using Non-Memory Mapped Flash for Storing Images | TouchGFX Documentation

except last part link. But i mean your idea cacheall when your image is over ram size isnt logic.

You need apply one screen graphics must have size under ram size for cache and too empty your cache on change screens.

Normal use

void Screen1View::setupScreen()
{
    //ensure background is cached
    Bitmap::cache(BITMAP_SCREEN2_ID);
    //cache some icons
    Bitmap::cache(BITMAP_ICON10_ID);
    Bitmap::cache(BITMAP_ICON11_ID);
    Bitmap::cache(BITMAP_ICON12_ID);
}
 
void Screen1View::tearDownScreen()
{
    //Remove all bitmaps from the cache
    Bitmap::clearCache();
}