2015-08-01 08:10 AM
I'm using 32L0538DISCOVERY board and STM32Cube L0 V1.1.0.
Firstly, why are the pictures declared as ''static''??? It produces more code and use a lot of data RAM. Just replace all the occurrences of ''static'' in ''menu_res.c'' to ''const'': replacestatic uint8_t Background_pic[] = {toconst uint8_t Background_pic[] = {
and so on. It frees about 3k of your RAM. Simple magic, isn't it? Next look in the ''gde021a1.c'', function ''gde021a1_DrawImage'':301 uint8_t pixels_4_grey[4];
...
327 pixels_4_grey[j] &= 0xFC;
There is no initialization between these lines of pixels_4_grey array. It placed in stack and may contain any garbage from its previous incarnations. It would be not so bad if it does not form the data_res variable later in code with logic summing (face palm here). I strongly recommend to create standalone function with name like ''Convert4pixels_bw_to_gray'' and place there this code:uint8_t Convert4pixels_bw_to_gray( uint8_t pixels_4 )
{
int i;
uint8_t pixels_4_grey;
// We do not need to initialize pixels_4_grey because of it has 8-bit length and
// shifts 2x4=8 bits during process
for ( i=0; i<4; i++ ){
pixels_4_grey <<= 2; // Left shift fills 2 LSBs with zeros
if ( (pixels_4 & 0x01) == 0 ){ // White bit in picture
pixels_4_grey |= 0x03; // Fill 2 LSBs with maximal intensity level
}
pixels_4 >>= 1; // Go to the next picture bit
}
return( pixels_4_grey ); // Now we have 4 grey pixels
}
Result: - lower code; - lower data (1 byte for pixels_4_grey instead of 4 and so on); - bug with uninitialised pixels_4_grey eliminated. #bug #l0 #stm32cube
2015-08-03 07:03 AM
> Firstly, why are the pictures declared as ''static''??? It produces more code and use a lot of data RAM. Just replace all the occurrences of ''static'' in ''menu_res.c'' to ''const'':
Well, static and const aren't exclusive to each other, in this case ''static const'' is better than just ''const'' because these variables are being used only in that particular C source file, so adding ''static'' is good coding to limit the variable's scope.