Stack in lpc1114

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

Stack in lpc1114

460 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Dariusz on Wed Jun 16 16:36:24 MST 2010
Hello,
I have nxp xpresso lpc1114 with code-red. I want to see sizes of my stacks somewhere in files and I  don't know how to do it. I can see only top of stack. My second problem is this question: we have limits for stacks in cortex-m0 lpc1114(128B and 256B) and I want to know if we can change these limits. I don't know  also : these limits are fixed or linker can dynamic reduce stack space to our requirements. The last question is how to calculate stack space for out program? I have nested interrupt. I can paste my code later.
0 Kudos
6 Replies

427 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Dariusz on Thu Jun 17 14:00:40 MST 2010
void TIMER32_0_IRQHandler (void)
{
    LPC_TMR32B0->IR = 1;  
    LPC_ADC->CR|=(1<<24); 

    while((LPC_ADC->DR[5]&0x80000000)==0)   
      {
        napiecie=((LPC_ADC->DR[5]>>6)&0x3FF);
        napiecie=3300*napiecie/1024; 
        wyslijnap(napiecie);       
       }
    on=0;
    while(on==0);


}

//procedura obslugi przerwania od przycisku
void PIOINT2_IRQHandler ()
 {
    LPC_TMR32B1->TCR = 0x01; 
    while (LPC_TMR32B1->TCR & 0x01); 

    if(LPC_GPIO2->MIS == 4) 
    {
          napis("Przerwanie zagniezdzone"); 
          wyslij(10);
           wyslij(13);
          on=1;
          dioda=dioda+1;    
            if((dioda%2)==0)
             {
                LPC_GPIO3->DATA=0x0;
             }
            if((dioda%2)!=0)
             {
                LPC_GPIO3->DATA=0x4;
             }
     }

}

void wyslijnap(int wartosc)            
{
    int lokalna;
    int j=1000;
    int i=0;

    while (!(LPC_UART->LSR & 0x20));  
    napis("Napiecie wynosi [mV]: ");

      while(i<4)
      {
        lokalna=(int)(wartosc/j);    
        wyslij(lokalna+48);         
        wartosc=wartosc-(lokalna*j);
        j =j/10;
        i=i+1;
      }
       wyslij(10); 
       wyslij(13);
}

void wyslij(int liczba)
{
     while (!(LPC_UART->LSR & 0x20)); 
     LPC_UART->THR=liczba;
}


void napis(char *pisz)
{
     int i=0;

       while(pisz!='\0')         
       {
           while (!(LPC_UART->LSR & 0x20));
           LPC_UART->THR=(pisz);         
           i++;
       }

}




I'm sorry but I still don't know how to calculate my stack. When cpu goes to ISR it push 8 register(R0-R3,R12,LR,PC,xPSR)-stack frame onto stack. I have nested interrupts:  priority for timer0 is 2 , priority for PIOINT2 is 1. So min. 16 registers are pushed onto the stack. This is 8*2*4Byte=64Byte. But what else , I can't see how many registers are pushed when I call subroutine(or I don't know how to do it).The code above is half of my entire code.
0 Kudos

427 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by CodeRedSupport on Thu Jun 17 08:50:00 MST 2010
My reading of the text in the latest LPC11xx User manual (V0.15  - Jun 7, 2010)...

Quote:
[B]19.4.9 RAM used by IAP command handler[/B]
Flash programming commands use the top 32 bytes of on-chip RAM. The maximum stack usage in the user allocated stack space is 128 bytes and it grows downwards.

is that you are correct. To prevent corruption of the stack, you will need to use your own linker script to shift the stack pointer down by 32 bytes. Details of using your own linker scripts instead of the automatically created one can be found at:

http://lpcxpresso.code-red-tech.com/LPCXpresso/node/31
[login required].

You will also need to allow for the fact that your stack may extend by 128 bytes when IAP commands are being executed.

Regards,
CodeRedSupport
0 Kudos

427 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by mcu_programmer on Thu Jun 17 08:26:55 MST 2010
If one uses the IAP commands, do one have to manually change the stacktop 32 bytes lower in the liknker script? (since IAP uses the 32 top bytes of RAM)
0 Kudos

427 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by CodeRedSupport on Thu Jun 17 04:30:31 MST 2010
The stack can grow without limits. If it continues to grow, at some point, it will start to overwrite your applications data. And also, your application data can overwrite the stack. At which point things will go badly wrong, but there is no way to predict what...
0 Kudos

427 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Dariusz on Thu Jun 17 04:25:59 MST 2010
'ISP commands use on-chip RAM from 0x1000 017C to 0x1000 025B. The user could use this area, but the contents may be lost upon reset. Flash programming commands use the top 32 bytes of on-chip RAM. The stack is located at RAM top &#8722; 32. The maximum stack usage is 256 bytes and it grows downwards.'

'Flash programming commands use the top 32 bytes of on-chip RAM. The maximum stack usage in the user allocated stack space is 128 bytes and it grows downwards.'

Ok but how understand these sentences from manual? We don't have limits but if we will exceed them we can have problems?
0 Kudos

427 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by CodeRedSupport on Thu Jun 17 00:09:57 MST 2010
There is not a stack limit in a Cortex-M0. It can continue to grow forever...

The way the stacks are setup by default is to initialise the stack pointer to the top of RAM. Your data is put into the bottom of RAM, with the C heap (malloc space) immediately following your data - the heap grows 'up' the RAM and the stack grows 'down' the RAM.

As there is no hardware support for stack checking, this potentially means that the stack can grow and overwrite you heap/data.

To calculate your stack space you will need to do it the hard way:
- work out the maximum nesting depth (including functions called by you ISRs)
- examine the generated code for each function and sum them
0 Kudos