Running out of stack space

Technical questions regarding the XTC tools and programming with XMOS.
User avatar
jb007
Active Member
Posts: 33
Joined: Fri Jul 23, 2010 5:10 am
Contact:

Running out of stack space

Post by jb007 »

Hi all. I'm getting out of stack space compiling the sd_card software. Can anyone guide me in the right direction to resolve this. Be gentle, I'm a newbie!

Code: Select all

**** Build of configuration Debug for project SDCard ****

xmake CONFIG=Debug all 
Creating dependencies for SDCardHost4Bit.xc
Compiling SDCardHost4Bit.xc
Updating eclipse config
Using modules:
Creating SDCard_Debug.xe
Constraint check for "stdcore[0]" (node "0", core 0):
  Stack available:   0x000004f0,   used: 0x000006e0 .  FAILED
  Threads available:          8,   used:          1 .  OKAY
  Timers available:          10,   used:          1 .  OKAY
  Chanends available:        32,   used:          0 .  OKAY
Error: L00109 Constraints check FAILED for node 0, core 0.
xmake[1]: *** [bin/Debug/SDCard_Debug.xe] Error 1
xmake: *** [bin/Debug/SDCard_Debug.xe] Error 2
TIA, Jim


User avatar
XMatt
XCore Addict
Posts: 147
Joined: Tue Feb 23, 2010 6:55 pm

Post by XMatt »

Is this a project you have created or one of the examples?

Matt
User avatar
jb007
Active Member
Posts: 33
Joined: Fri Jul 23, 2010 5:10 am
Contact:

Post by jb007 »

XMatt wrote:Is this a project you have created or one of the examples?

Matt
Thanks XMatt. It is example code from here http://github.xcore.com/repo_index/sc_s ... eadme.html

I have uncommented the define (#define BUS_MODE_4BIT in diskio.h) to allow for 4bit access to the sdcard instead of using the SPI interface.

TIA, Jim
Redeye
XCore Addict
Posts: 131
Joined: Wed Aug 03, 2011 9:13 am

Post by Redeye »

Jim,

I feel your pain, the AVB code I've been working on is a constant battle with stack space.

Probably the easiest way to solve the problem is to set optimisation to -O3 (I'm assuming the Debug config you're using is currently set to -O0 ie. unoptimised).

Hope that helps,
Dan
User avatar
paul
XCore Addict
Posts: 169
Joined: Fri Jan 08, 2010 12:13 am
Contact:

Post by paul »

Redeye wrote: Probably the easiest way to solve the problem is to set optimisation to -O3 (I'm assuming the Debug config you're using is currently set to -O0 ie. unoptimised).
-O3 doesn't guarantee your code will be smaller versus -O0 - if your not careful it can actually cause your code to be larger because of loop unrolling etc.

If you're running out of memory you need to start considering reducing buffer sizes or how much functionality you are trying to squeeze on one core. Things like filesystem stacks get quite big.
User avatar
jb007
Active Member
Posts: 33
Joined: Fri Jul 23, 2010 5:10 am
Contact:

Post by jb007 »

Hi all, thanks for your replies. I changed the optimisation flag but it made no difference. I then changed some code (shouldn't have affected the stack) and then the out of stack message disappeared. Go figure! Not sure whats going on.

Thanks. Jim
User avatar
jb007
Active Member
Posts: 33
Joined: Fri Jul 23, 2010 5:10 am
Contact:

Post by jb007 »

jb007 wrote:Hi all, thanks for your replies. I changed the optimisation flag but it made no difference. I then changed some code (shouldn't have affected the stack) and then the out of stack message disappeared. Go figure! Not sure whats going on.

Thanks. Jim
Just tried it again,after doing a clean, and guess what it runs out of stack again. Bugger.

I'm going to try XDE under Linux, I'm using OS X Lion at the moment.

TIA. Jim.
Redeye
XCore Addict
Posts: 131
Joined: Wed Aug 03, 2011 9:13 am

Post by Redeye »

paul wrote:-O3 doesn't guarantee your code will be smaller versus -O0 - if your not careful it can actually cause your code to be larger because of loop unrolling etc.
Paul - yes, you're absolutely right. I think what I probably meant to put was the -Os compiler option which optimises for code space. I think some parts of the ethernet module use (need?) this.

Otherwise like Paul says, you might be able to reduce some static buffer sizes and check if there's any functionality in the code that you don't need and can easily/simply eliminate.
User avatar
segher
XCore Expert
Posts: 844
Joined: Sun Jul 11, 2010 1:31 am
Contact:

Post by segher »

"Running out of stack space" means running out of RAM. You should
figure out what is taking up all the space. One obvious glutton is the
25kB buffer the example app uses, but that's only half of the RAM;
where did the rest go?

Maybe there is some nice way in the IDE to find out, I have no idea,
but I can tell you how to do it from the command line (on your Linux
system):

Code: Select all

nm --size *.o
will tell you the size of the data objects in your files (this works with
any nm that has ELF support);

Code: Select all

xobjdump --size some-file.o
will tell you the overall size of code and data in that object file;

Code: Select all

readelf -S some-file.o
digs a bit deeper, showing size per section.
User avatar
jb007
Active Member
Posts: 33
Joined: Fri Jul 23, 2010 5:10 am
Contact:

Post by jb007 »

Nup. Linux no different!
Just noticed this warning though... can anyone enlighten me as to what its trying to say?

Code: Select all

Description	Resource	Path	Location	Type
Invalid project path: Duplicate path entries found (/SDCard [Include path] isSystemInclude:true includePath:/Applications/XMOS_11.11.0/target/include), path: [/SDCard].	SDCard		pathentry	Path Entry Problem
Post Reply