10 years, 9 months ago.

Storing Large Arrays in Flash Question

/media/uploads/ScubaBoy/splashscreen.h HI,

I'm encountering a strange problem, I'm trying to store an array in flash that defines a 16bit 300x200 bmp as follows:

SplashScreen.h

SplashScreen

 extern const unsigned char splashScreenEasyWeigh[];

SplashScreen.cpp (some of the file not all)

SplashScreen

// size 300x200
extern const unsigned char splashScreenEasyWeigh[] = {
    0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 
    0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 
    0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF ..............
}

When I compile the code I can see that the array has been allocated to flash all good. However when I try and run the following my mbed stops responding.

Main

#include "SplashScreen.h"

int main() 
{
   unsinged const char* = &splashScreenEasyWeigh[0];
}

Does the above cause the c runtime to try and copy the array into the RAM? If so can this be avoided? I'm trying to assign a pointer to the start of the array in flash so I can access the values.

Any suggestions welcome.

Thanks

Robin

Hello,

does that even compile? You are missing an identifier, and one a spelling error is there:

unsinged const char* = &splashScreenEasyWeigh[0];

Small edit

const unsigned char* pointer = &splashScreenEasyWeigh[0];

It does not copy entire array, only defines a pointer to const unsigned char which designates the address of the first element in the array.

Regards, 0xc0170

posted by Martin Kojtal 25 Jul 2013

1 Answer

Rob Cawsey
poster
10 years, 9 months ago.

Thanks for the correction and yes the pointer to the first location in the splashscreen array was being stored, however taking things a bit further I have the following which does seem to break the mbed.

BMP

struct BMP
{
    const unsigned char* bmp;
    int width;
    int height;
};

Got a method with the following definition

BMPRender

void BMPRender (BMP* bmpToRender)
{

}

In Main I have the following

Main

int main() 
{
    BMP splashScreen;

    splashScreen.bmp = &splashScreenEasyWeigh[0];
    splashScreen.width = 300;
    splashScreen.height =200;

   BMPRender (&splashScreen);

}

As soon as the BMPRender is called the mbed stops responding.

Sorry meant to post this as a comment.

posted by Rob Cawsey 25 Jul 2013

Maybe it helps if you publish the simple program where it goes wrong, or if it is compact enough just post the entire code here. The following code for example runs fine for me:

#include "mbed.h"

DigitalOut led(LED1);
const unsigned char splashScreenEasyWeigh[300*200]={0xFF};

struct BMP
{
    const unsigned char* bmp;
    int width;
    int height;
};

void BMPRender (BMP* bmpToRender)
{
    printf("Data 0 = %X\n", bmpToRender->bmp[0]);
    printf("Data 1000 = %X\n", bmpToRender->bmp[1000]);
}


int main() 
{
    printf("Started!\n");
    wait(0.1);
    BMP splashScreen;
    wait(0.1);
    printf("Made BMP\n");
    
    splashScreen.bmp = &splashScreenEasyWeigh[0];
    splashScreen.width = 300;
    splashScreen.height =200;
    wait(0.1);
    printf("Defined splashscreen!\n");

   BMPRender (&splashScreen);
   wait(0.1);
   printf("Called function\n");
   while(1) {
    led = !led;
    wait(0.2);
   }
}
posted by Erik - 25 Jul 2013

Thanks for that I made an assumption that it was my mbed because it wasn't working on my prototype board I built using the reference design, when infact it works fine on mbed I'm using to program the board with flash magic. I wonder if the bin2hex tool I'm using is the problem.

posted by Rob Cawsey 25 Jul 2013

No bin2hex tool doesn't seem to be the problem have tried both 32 and 64 bit windows version of this tool with the same result when run on the prototype board.

posted by Rob Cawsey 25 Jul 2013

MCU on prototype board is an LPC1768

Device ID: 26013F37 Bootloader version 4.2

posted by Rob Cawsey 25 Jul 2013

Sorry I've wasted everyones time I forgot to set the switch so that the bin2hex tool could convert a file > 64KB

posted by Rob Cawsey 25 Jul 2013