Strange Error (Possibly Relating to Memory)

16 Mar 2010 . Edited: 16 Mar 2010

For my Science Fair, I'm using the mbed NXP LPC1768 to receive images from two cameras (the Nintendo Game Boy Cameras from the 90s; the Mitsubishi M64282FP Artificial Retina) to determine the blobs in both images using the MSER Algorithm (Maximally Stable Extremal Regions).  The program can be found here.  So far, I've been able to receive images at ~7fps and determine pixel brightness using a dynamic threshold.  The only problem now, is getting the MSER Algorithm working.  Even though I've developed it seemingly good enough, I'm having trouble compiling.  The bugs I'm getting are as follows:

  1. "<startPosition.0> may be used before being set" in file "/BinocularCamera/main.cpp"
  2. " No space in execution regions with .ANY selector matching Section .bss(main.cpp.cpp.LPC1768.o). (EL6406W)" in file "/"
  3. " Sections of aggregate size 0xdaa4 bytes could not fit into .ANY selector(s). (EL6407W)" in file "/"
  4. "Unable to download. Fix the reported errors..." in file "/"

Of course, I not quite worried about the first one and the last, but the "No space..." and "Sections of aggregate size..." is kind of worrying me.  At first, I assumed it was the part of my code meant for dynamic RAM allocation that included "realloc()", but just taking that part out didn't satisfy this bug's thirst.  Only after taking out practically all of my latest work did I finally make the problem go away.  Even Google didn't come up with much that helped (mostly KeilVision stuff).  Though this might help, I really don't want to go back to the less memory and processing consuming Edge Tracing Algorithm.

Sincerely,

Dylan Dalrymple

2010 Intel ISEF Entrant

16 Mar 2010

Hi Dylan,

Yes, this is certainly related to memory; it is the linker saying "I haven't got any room left in RAM to put your data structures". The main culprits are:

// Image Arrays
char imageArray1[62][64]; // [resizedHeight][resizedWidth];
char imageArray2[62][64]; // [resizedHeight][resizedWidth];

char blobArray1a[62][64];
char blobArray1b[62][64];
char blobArray1c[62][64];
char blobArray1d[62][64];
char blobArray1e[62][64];
char blobArray1f[62][64];

char blobArray2a[62][64];
char blobArray2b[62][64];
char blobArray2c[62][64];
char blobArray2d[62][64];
char blobArray2e[62][64];
char blobArray2f[62][64];
In total, this is 62*64*14 = ~56k. On the LPC1768 the main RAM section is 32k; this is where the R/W data, Stack and Heap live. So that doesn't go. There are 2 additional 16k blocks for the USB and Ethernet which should also be usable. If you look at our scatter file, you can see we've given these sections a name, so you can tell the linker where to try and allocate these blocks using the section attribute. In this case, i'll allocate 4 of your arrays to each of the sections:

// Image Arrays
char imageArray1[62][64]; // [resizedHeight][resizedWidth];
char imageArray2[62][64]; // [resizedHeight][resizedWidth];

char blobArray1a[62][64];
char blobArray1b[62][64];
char blobArray1c[62][64];
char blobArray1d[62][64];
char blobArray1e[62][64] __attribute__((section("AHBSRAM1")));
char blobArray1f[62][64] __attribute__((section("AHBSRAM1")));

char blobArray2a[62][64] __attribute__((section("AHBSRAM1")));
char blobArray2b[62][64] __attribute__((section("AHBSRAM1")));
char blobArray2c[62][64] __attribute__((section("AHBSRAM0")));
char blobArray2d[62][64] __attribute__((section("AHBSRAM0")));
char blobArray2e[62][64] __attribute__((section("AHBSRAM0")));
char blobArray2f[62][64] __attribute__((section("AHBSRAM0")));

This obviously is specific to the LPC1768 so is not ideal. It may be you can optimise your algorithm to use less RAM (perhaps by reusing buffers, or tiling somehow).

btw. you can also avoid the use-before-initialisation warning by initialising your struct as you define it, so:

    point startPosition;
    startPosition.x = NULL;
    startPosition.y = NULL;
becomes:

    point startPosition = {NULL, NULL};
With these changes, your program compiles without error (that is not to say it will work! but hopefully a step closer)

Simon

16 Mar 2010

...or even

point startPosition = {0};
This zeroes any structure of any layout.

16 Mar 2010

Thank you all so much!  I didn't realize that only 32kb of RAM was available for program use instead of the full 64kb available on the board.  So, I believe that I'll just use run through a single threshold at a time using a single blobArray[62][64], and then take out the essential blob data and reassign all of the array value to start again using a different threshold.  Also, I'll make sure to initialize all of my structs beforehand.  Hopefully, this will all fix the problem.

With Many Thanks,

Dylan Dalrymple

2010 Intel ISEF Entrant