Setting STACK_OFFSET automatically?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Setting STACK_OFFSET automatically?

406 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by micrio on Fri Feb 22 11:00:02 MST 2013
Some time ago I fought a weird problem because I didn't know that
you had to reserve 32 bytes at the top of RAM for the IAP routines.
With help from this group I reserved the 32 bytes and all was well.

That was a few versions of LPCXpresso ago.   With the periodic upgrades
I lost the setting.   It is pretty obscure and burried down in many layers of
menus.   There has to be a better way.

If it is not possible for the environment to determine automatically if you
are using IAP then there should be some #define that you can put in your
code to cause the 32 bytes to be reserved.   I suggest something like:

#define   USING_IAP
or
#define   IAP_RESERVED    32

If there is already something like this I would be happy to learn about it.

Thanks,
Pete.
0 Kudos
Reply
3 Replies

380 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by micrio on Sat Feb 23 07:05:36 MST 2013
I love it!   That is great, thanks.

Pete.
0 Kudos
Reply

380 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Sat Feb 23 04:57:53 MST 2013

Quote:

It would be much better if the code just crashed when you used IAP without setting the stack offset. Since it is so easy to miss, and that the bugs produced are so subtle, this issue is a real killer.

Then add a reminder

extern uint32_t _vStackTop;
extern uint32_t __top_RamLoc8;

int main(void)
{
 uint32_t offset = (uint32_t)&__top_RamLoc8 - (uint32_t)&_vStackTop;
 printf("Top of RAM(%X) - Top of Stack(%X)\n",&__top_RamLoc8,&_vStackTop);
 printf("Offset = %d\n",offset);
 if(offset <32)
 {
  while(1)printf("[COLOR=Red]I have forgotten to set my OFFSET[/COLOR] >=32!\n");
 }
 ...
0 Kudos
Reply

380 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by CodeRedSupport on Fri Feb 22 15:15:07 MST 2013
The option you need to set is in the Linker settings in Project Properties. The FAQ "Reserving RAM for IAP Flash Programming"  describes exactly how to do this.

http://support.code-red-tech.com/CodeRedWiki/ReserveIAPRam

Using a define here wouldn't help, the value needs passing to the linker script, which doesn't use the C preprocessor.

Regards,
CodeRedSupport
0 Kudos
Reply