EmbeddedRelated.com
Forums
The 2024 Embedded Online Conference

Stack Issue with FreeRTOS,GNUARM

Started by prab...@yahoo.co.in August 31, 2009
Hi all,

Setup:
FreeRTOS.org V5.2.0
GNUARM 4.1.1
LPC2103

I am developing one application using serial port.
I am facing one weired Issue.

In my function,

I am using two stack(local) variables(pointers).
One of this variable is changed unexpected.For example, i am assigning
NULL into local stack variable and go to while loop and check that
Local variable.But that pointer variable is not NULL;

Example,
ptr localptr1 = Valid address,localptr2= NULL;

while(localptr1)
{
dbgprintf("Output is:%d\n,localptr1);
/* Here localptr2 equal to NULL;
localptr1=localptr2;
}
Here i am expecting,to print debugprintf message is only one time.
But it is printing two times which means while loop is
executed two times.
The free rtos API uxTaskGetStackHighWaterMark( NULL )) returns 71.
which means there is no stack overflow.

But If i change, local variable is static or change optomization from Os to O0
or increase task's stack size from 128 variable to 256 variable
problem is not there.

I have also checked map file and confirmed code,ram size are not exceeded.

I used printf GCC lib(printf-stdarg.c) for debug printf.

Anybody face this Issue already,please share ur knowledge??

An Engineer's Guide to the LPC2100 Series

> I am using two stack(local) variables(pointers).
> One of this variable is changed unexpected.For example, i am assigning
> NULL into local stack variable and go to while loop and check that
> Local variable.But that pointer variable is not NULL;
>
> Example,
> ptr localptr1 = Valid address,localptr2= NULL;
>
> while(localptr1)
> {
> dbgprintf("Output is:%d\n,localptr1);
> /* Here localptr2 equal to NULL;
> localptr1=localptr2;
> }
> Here i am expecting,to print debugprintf message is only one time.
> But it is printing two times which means while loop is
> executed two times.
> The free rtos API uxTaskGetStackHighWaterMark( NULL )) returns 71.
> which means there is no stack overflow.
Try turning on the automatic stack checking as described here:
http://www.freertos.org/Stacks-and-stack-overflow-checking.html

>
> But If i change, local variable is static or change optomization from
> Os to O0
> or increase task's stack size from 128 variable to 256 variable
> problem is not there.
Could potentially be something to do with the optimization, especially the
optimization of interrupt handlers.

> I used printf GCC lib(printf-stdarg.c) for debug printf.
Is this the prtinf_stdarg.c that comes in the FreeRTOS download? If so that
implementation uses very little stack. If by chance you were using the
standard implementation that comes with GCC then that will use a lot of
stack and is probably the cause of your problem.

Regards,
Richard.

+ http://www.FreeRTOS.org
Designed for Microcontrollers. More than 7000 downloads per month.

+ http://www.SafeRTOS.com
Certified by T as meeting the requirements for safety related systems.

Thanks.See my comments below.

--- On Mon, 31/8/09, FreeRTOS Info wrote:
From: FreeRTOS Info
Subject: RE: [lpc2000] Stack Issue with FreeRTOS,GNUARM
To: l...
Date: Monday, 31 August, 2009, 8:46 PM


> I am using two stack(local) variables(pointers) .
> One of this variable is changed unexpected.For example, i am assigning
> NULL into local stack variable and go to while loop and check that
> Local variable.But that pointer variable is not NULL;
>
> Example,
> ptr localptr1 = Valid address,localptr2= NULL;
>
> while(localptr1)
> {
> dbgprintf("Output is:%d\n,localptr1) ;
> /* Here localptr2 equal to NULL;
> localptr1=localptr2 ;
> }
> Here i am expecting,to print debugprintf message is only one time.
> But it is printing two times which means while loop is
> executed two times.
> The free rtos API uxTaskGetStackHighW aterMark( NULL )) returns 71.
> which means there is no stack overflow.

Try turning on the automatic stack checking as described here:
http://www.freertos .org/Stacks- and-stack- overflow- checking. html
[Comment]: I will test and let u know.
The following API returns( uxTaskGetStackHighW aterMark( NULL )))
71 which means no stack overflow,corruption??Is it correct?

>
> But If i change, local variable is static or change optomization from
> Os to O0
> or increase task's stack size from 128 variable to 256 variable
> problem is not there.

Could potentially be something to do with the optimization, especially the
optimization of interrupt handlers.
[comment]: This issue is in normal function..

> I used printf GCC lib(printf-stdarg. c) for debug printf.

Is this the prtinf_stdarg. c that comes in the FreeRTOS download? If so that
implementation uses very little stack. If by chance you were using the
standard implementation that comes with GCC then that will use a lot of
stack and is probably the cause of your problem.

[Comment]: using prtinf_stdarg. c that comes in the FreeRTOS download.....

Regards,
Richard.

+ http://www.FreeRTOS .org
Designed for Microcontrollers. More than 7000 downloads per month.

+ http://www.SafeRTOS .com
Certified by T as meeting the requirements for safety related systems.
Find top restaurants in your city only on Yahoo! India Local http://in.local.yahoo.com/



> Thanks.See my comments below.
>
> --- On Mon, 31/8/09, FreeRTOS Info > > wrote:
>
> From: FreeRTOS Info
> >
> Subject: RE: [lpc2000] Stack Issue with FreeRTOS,GNUARM
> To: l...
> Date: Monday, 31 August, 2009, 8:46 PM
>
>
>
> > I am using two stack(local) variables(pointers) .
> > One of this variable is changed unexpected.For example, i am
> assigning
> > NULL into local stack variable and go to while loop and check that
> > Local variable.But that pointer variable is not NULL;
> >
> > Example,
> > ptr localptr1 = Valid address,localptr2= NULL;
> >
> > while(localptr1)
> > {
> > dbgprintf("Output is:%d\n,localptr1) ;
> > /* Here localptr2 equal to NULL;
> > localptr1=localptr2 ;
> > }
> > Here i am expecting,to print debugprintf message is only one time.
> > But it is printing two times which means while loop is
> > executed two times.
> > The free rtos API uxTaskGetStackHighW aterMark( NULL )) returns 71.
> > which means there is no stack overflow.
>
> Try turning on the automatic stack checking as described here:
> http://www.freertos .org/Stacks- and-stack- overflow- checking. html
> [Comment]: I will test and let u know.
> The following API returns( uxTaskGetStackHighW aterMark( NULL )) )
> 71 which means no stack overflow,corruption??Is it correct?
That is correct at the point where you call the function, but something bad
could potentially happen after that. I agree it seems unlikely though.
Regards,
Richard.

+ http://www.FreeRTOS.org
Designed for Microcontrollers. More than 7000 downloads per month.

+ http://www.SafeRTOS.com
Certified by T as meeting the requirements for safety related systems.

Please give idea about how to debug this issue??
Somebody should have faced this issue already.Please share ur knowledge?
Is there may be any problem in GCC code generation because ofmy code..
or I dont know how to debug this issue.

Additional information.
Ram size is : 8KB

In that,Heap = 5KB for heap2.c(In freeRTOS)

IRQ_STACK = 1kB

SVC_STACK = 1KB
(In that,i have set task stack is 128 variable..which menas 128*4=512 bytes.

remainingare data segment and bss segment..

I dont have JTAG to debug this Issue???

Thanks,

--- On Tue, 1/9/09, FreeRTOS Info wrote:
From: FreeRTOS Info
Subject: RE: [lpc2000] Stack Issue with FreeRTOS,GNUARM
To: l...
Date: Tuesday, 1 September, 2009, 12:09 PM


> Thanks.See my comments below.
>
> --- On Mon, 31/8/09, FreeRTOS Info > > wrote:
>
> From: FreeRTOS Info
> >
> Subject: RE: [lpc2000] Stack Issue with FreeRTOS,GNUARM
> To: lpc2000@yahoogroups .com
> Date: Monday, 31 August, 2009, 8:46 PM
>
>
>
> > I am using two stack(local) variables(pointers) .
> > One of this variable is changed unexpected.For example, i am
> assigning
> > NULL into local stack variable and go to while loop and check that
> > Local variable.But that pointer variable is not NULL;
> >
> > Example,
> > ptr localptr1 = Valid address,localptr2= NULL;
> >
> > while(localptr1)
> > {
> > dbgprintf("Output is:%d\n,localptr1) ;
> > /* Here localptr2 equal to NULL;
> > localptr1=localptr2 ;
> > }
> > Here i am expecting,to print debugprintf message is only one time.
> > But it is printing two times which means while loop is
> > executed two times.
> > The free rtos API uxTaskGetStackHighW aterMark( NULL )) returns 71.
> > which means there is no stack overflow.
>
> Try turning on the automatic stack checking as described here:
> http://www.freertos .org/Stacks- and-stack- overflow- checking. html
> [Comment]: I will test and let u know.
> The following API returns( uxTaskGetStackHighW aterMark( NULL )) )
> 71 which means no stack overflow,corruption ??Is it correct?

That is correct at the point where you call the function, but something bad
could potentially happen after that. I agree it seems unlikely though.

Regards,
Richard.

+ http://www.FreeRTOS .org
Designed for Microcontrollers. More than 7000 downloads per month.

+ http://www.SafeRTOS .com
Certified by T as meeting the requirements for safety related systems.
Love Cricket? Check out live scores, photos, video highlights and more. Click here http://cricket.yahoo.com



pra bu wrote:
> Please give idea about how to debug this issue??
>

If you think the optimization level makes a difference, which might well
be as GCC is known to optimize awaystuff once in a while,
then simply look at the assembler code for your function and compare them.

This does not sound like a stack problem to me.

Harald


The 2024 Embedded Online Conference