Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
11 years, 1 month 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
1 Answer
11 years, 1 month 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.
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); } }
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 25 Jul 2013No 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 25 Jul 2013
Hello,
does that even compile? You are missing an identifier, and one a spelling error is there:
Small edit
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