cancel
Showing results for 
Search instead for 
Did you mean: 

BMP reading stop in the loop ?

antonius
Senior

Dear Members,

I have question related with BMP reading from SDcard then display to LCD ?

It stopped in one file,

Is it related with internal SRAM of my STM32F103, and I'm running out of internal SRAM memory,

I read some bmp files, and freeze.

Regards,

Code :

//Function reading 256 file
  void LCD_BMP_reading_256(char filename[120])
  {
    char temp_buffer[100],line[512];
	int count,z,bmpData,bmpAddr;
	int x = 0;
	int i,y = 0;
	int xx, yy;
    uint8_t hdr[0x28];
	UINT bytesread;
 
	
    uint8_t hdr_256[0x36];
    static uint16_t w[256];
    uint32_t off;
 
	 	delay_ms(1500);
						  res = f_open(&fsrc, filename, FA_READ);
  
						  f_read(&fsrc, hdr_256, sizeof(hdr_256), &bytesread); // Read header
						  
						  off = *((uint32_t *)&hdr_256[0x0A]); // offset to rasters
						 
						  xx = *((uint32_t *)&hdr_256[0x12]); // X pixels
						  
						  yy = *((uint32_t *)&hdr_256[0x16]); // Y pixels
						   
						  for(i=0; i<256; i++) // Build palette conversion (+0x46 count?)
						  {
						    uint32_t pal;
						   
						    f_read(&fsrc, &pal, 4, &bytesread); // Read palette B G R
						 
						// RRRRRRRRGGGGGGGGBBBBBBBB 8:8:8
						//         BBBBBGGGGGGRRRRR 5:6:5
						 
						    //pal = ((pal & 0x00FC00) >> 5) | ((pal & 0xF80000) >> 19) | ((pal & 0x0000F8) << 8);
							pal = ((pal & 0xF80000) >> 8) | ((pal & 0x00FC00) >> 5) | ((pal & 0x0000F8) >> 3);
							//pal = ((pal & 0x1F0000) >> 8) | ((pal & 0x007E00) >> 5) | ((pal & 0x0000F8) >> 3);
						    	 
						    w[i] = (uint16_t)pal;      
						  }
						     
						  f_lseek(&fsrc, off); // Seek to the data
						   
						  for(y=0; y<yy; y++)
						  {
						    for(x=0; x<xx; x++)
						    {
						      uint8_t b;
						   
						      f_read(&fsrc, &b, 1, &bytesread); // Read byte
						   
						      LCD_SetPoint(y, x, w[b]); // Colour Map
						    } // x
						  } // y
						   
						  f_close(&fsrc);
 
 
 
  }

I repeated that function many times in main()

5 REPLIES 5

"It stopped in one file"

What, exactly, does that mean? What debugging have you done to find out what's going on?

"Is it related with internal SRAM of my STM32F103, and I'm running out of internal SRAM memory,"

Doesn't your IDE give you information on that?

eg, STM32CubeIDE:

0693W00000Nph0cQAB.png 

"I read some bmp files"

So how big are those files? How does that compare to the amount of available RAM?

antonius
Senior

Hi Andrew,

Thanks for the reply,

The bmp file size is 320x240x16K colors,

Compiling result :

0693W00000NphKrQAJ.pngany clues ?

Regards,

Rixtronix

Again, what debugging have you done to find out what's going on?

"The bmp file size is 320x240x16K colors"

So have you done the basic maths?

320x240 = 76800 pixels.

For 16K colours, that must be at least 14 bits per pixel; presumably, you use 2 bytes?

So that's a total of 76800 x 2 = 153600 bytes = 150 K bytes for each file.

Are you trying to store all the files in memory at the same time?

Hi Andrew,

Thanks for the reply,

I read the file like this :

======

 LCD_BMP_reading_256("test10.bmp");

         delay_ms(2000);

=======

and next files,

The function is reading from sdcard and display to LCD,

Is the file being copied to RAM then displayed ?

I'm not sure yet,

Regards,

Rixtronix

It's your code - do you not know what it does?