Content originally posted in LPCWare by elecia on Tue Apr 27 12:06:13 MST 2010
Thank you for your response. I agree that the bad stack pointer is tramping over the RAM. I put in the --gc-sections (I have version 3.3.4) and it reduced the size considerably:
text data bss dec hex filename
2324 4 24 2352 930 blinky.axf
However, when I breakpoint at the start of Reset_Handler, the SP is 0x10000fec. Because blinky is so small now, the bad stack pointer doesn't cause a problem, however, I don't think blinky's stack is over 0x1000 before the start of Reset_Handler.
Actaully, I don't see why the non-optimized version shouldn't work. It built to 0x1cc4, 7364 bytes. That leaves 0x334 (828) bytes for the stack which should be plenty. There is no heap.
So you said "your SP value is not being picked up", do you recommend that I force the SP to the _vStackTop (read from 0x10000000) at the start of Reset_Handler? Let's see what happens if I try that...
When I look at 0x10000000 (g_pfnVectors), the _vStackTop value is 0x10001FF0. So if I add some code to cr_startup_lpc13.c, blinky without --gc-sections builds to a whopping 8032 bytes but, more importantly, it works.
[B][COLOR=Black]
[/COLOR][/B][FONT=Courier New][COLOR=Black][SIZE=2][B]#include "LPC13xx.h" // for set stack pointer[/B]
void
//ResetISR(void)
Reset_Handler(void)
{
unsigned long *pulSrc, *pulDest;
[/SIZE][/COLOR][/FONT][FONT=Courier New][COLOR=Black][SIZE=2]
[B]// loading code in RAM means stack pointer is set before loading is complete[/B][/SIZE][/COLOR][/FONT][COLOR=Black][B][FONT=Courier New][SIZE=2], reset it now to the correct value:
__set_MSP((uint32_t)g_pfnVectors[0]); [/SIZE][/FONT][/B]
....[/COLOR]
(New code is in bold.)
Thanks! With this code, my bootloader is no longer having code stomped on by the stack pointer as it runs from ram.
I'd still be happy to take any advice about if this is a good solution or a horrible hack (and if there is a better way).