Hi, Mark.
So far as I can tell,
ucTopOfStack, defined as an
unsigned char in
fnInitialiseHeap(), is never actually used. Only its address is ever referenced, here in this
while (ucPattern <= &ucTopOfStack) { // this pattern is used later for Stack use monitoring
*ucPattern++ = UNUSED_STACK_PATTERN;
}
Apparently, the compiler never actually allocates a location for the variable. Indeed, it does not appear in
uTasker_full.elf.xMAP. The result is that the
while loop that is supposed to fill the heap with
UNUSED_STACK_PATTERN doesn't do anything.
Did I miss something?
I found this because, in my program,
pucTopOfHeap += ctOurHeap->need_this_amount;
causes
pucTopOfHeap to be set to
0x20008340. Since there is no memory there, calling
fnStackFree() fails with an access error exception on an operand read. If the
while loop in
fnInitialiseHeap() actually did anything, an access error would have occurred at that point, as the program was starting up.
My next question is this: can I safely reduce the value of
OUR_HEAP_SIZE below the 21K it is set to and by how much?
Since I'm using CodeWarrior and use only
uMalloc() and never
malloc(), it looks like I can change
HEAP_SIZE = 0x1000; to
HEAP_SIZE = 0; in
M52235EVB_FLASH.lcf. The note in the file is a little difficult to interpret: by "This can be left as zero..." do you mean that it can be reduced to zero? If so, it may be enough to save me without reducing OUR_HEAP_SIZE ... for now.
Thanks,
Richard
P.S. Thinking about your comment,
If the pattern is not being set it suggests that its address is below the top of heap (system variables plus OUR_HEAP_SIZE)
I've modified the code in
fnInitialiseHeap() to be
if (pucTopOfHeap <= &ucTopOfStack) {
while (ucPattern <= &ucTopOfStack) { // this pattern is used later for Stack use monitoring
*ucPattern++ = UNUSED_STACK_PATTERN;
}
}
else // not enough memory for heap!
while (1) {}; // hang here to make the problem obvious while debugging.