stack overflow
Moderator: Benj
- Jan Lichtenbelt
- Posts: 797
- Joined: Tue Feb 17, 2009 8:35 pm
- Location: Haren GN, the Netherlands
- Has thanked: 128 times
- Been thanked: 264 times
- Contact:
stack overflow
I get a serious warming: stack usage exceeds 8. What to do? What can be the reason? And where do I have to check the programm?
-------------
Building CASM file
Serious Warning: Call stack usage exceeds:8!
Call Stack Usage Report
=======================
main and Task(s): hw used:8, exceeded by:0
interrupt: hw used:2, exceeded by:0
Memory Usage Report
===================
RAM available:368 bytes, used:229 bytes (62.3%), free:139 bytes (37.7%),
Heap size:139 bytes, Heap max single alloc:95 bytes
ROM available:8192 words, used:6831 words (83.4%), free:1361 words (16.6%)
-------------
Building CASM file
Serious Warning: Call stack usage exceeds:8!
Call Stack Usage Report
=======================
main and Task(s): hw used:8, exceeded by:0
interrupt: hw used:2, exceeded by:0
Memory Usage Report
===================
RAM available:368 bytes, used:229 bytes (62.3%), free:139 bytes (37.7%),
Heap size:139 bytes, Heap max single alloc:95 bytes
ROM available:8192 words, used:6831 words (83.4%), free:1361 words (16.6%)
-
medelec35
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
Re: stack overflow
Basically each macro is treated as a subroutine = a stack. So if you have a Marco, calling a macro, calling a delay which I would assume a delay would be more than a stack? the stacks soon add up. Also an interrupt macro with a delay or calling another macro is a BIG no no. The solution would be to restructure your program or use a different microcontroller which has more stack levels.
Martin
- Jan Lichtenbelt
- Posts: 797
- Joined: Tue Feb 17, 2009 8:35 pm
- Location: Haren GN, the Netherlands
- Has thanked: 128 times
- Been thanked: 264 times
- Contact:
Re: stack overflow
Do you know which parameter in the PIC specifications shows the amount of stack? Is that "architecture"?
I use now the PIC16F877A, but cannot find it anymore in the microchip list
http://www.microchip.com/ParamChartSear ... &pageId=74
Does that means this chip is not procuded anymore?
I use now the PIC16F877A, but cannot find it anymore in the microchip list
http://www.microchip.com/ParamChartSear ... &pageId=74
Does that means this chip is not procuded anymore?
-
medelec35
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
Re: stack overflow
First if you go into Matrix Multimedia/Flowcode V4/boostc/config directory
Then double click on the microcontroller you want to find out stack level for. Associate TDF extension with a text file editor (notepad will do) then read down the list and you will see Stack level. E.g for PIC16F877A shows:
I am looking on the net for a product selection list that includes stack levels.
If I can find it, will post link.
Mean while something for you to try.
Take a look here:
http://www.microchip.com/productselecto ... ector.html
then with 8Bit selected move left slider on RAM (KB) to 0.5
With the results look at the stack level in files with TDF extension as mention above.
E.G for 18F2610
You can the move other sliders E.g number of pins etc. To narrow down selection. Don't for get to have voltage slider on max 5.5.
Looking at the microchip range, you will need any microcontroller starting from 16F1000 and up! Which of course includes all 18F range,
as I believe they all have a stackdepth of at least 32
Hope this helps.
Then double click on the microcontroller you want to find out stack level for. Associate TDF extension with a text file editor (notepad will do) then read down the list and you will see Stack level. E.g for PIC16F877A shows:
Code: Select all
Configure Core
{
Type = PIC16F877A;
}
Configure ProgramMemory
{
AddressRange = 0000h -> 1FFFh;
}
Configure StackHardware
{
StackDepth = 8;
}
Configure EEPROM
{
// EEPROM size in bytes
// EEIF and EEIE bit must be correctly declared for interrupts
Size = 256;
}If I can find it, will post link.
Mean while something for you to try.
Take a look here:
http://www.microchip.com/productselecto ... ector.html
then with 8Bit selected move left slider on RAM (KB) to 0.5
With the results look at the stack level in files with TDF extension as mention above.
E.G for 18F2610
Code: Select all
Type = PIC18F2610;
}
Configure ProgramMemory
{
AddressRange = 000000h -> 00FFFFh;
}
Configure AccessBank
{
SplitAddr = 07Fh;
}
Configure StackHardware
{
StackDepth = 32;Looking at the microchip range, you will need any microcontroller starting from 16F1000 and up! Which of course includes all 18F range,
as I believe they all have a stackdepth of at least 32
Hope this helps.
Martin
- Jan Lichtenbelt
- Posts: 797
- Joined: Tue Feb 17, 2009 8:35 pm
- Location: Haren GN, the Netherlands
- Has thanked: 128 times
- Been thanked: 264 times
- Contact:
Re: stack overflow
Thanks a lot. It seems easier to buy an other microchip compared to reprogramm my flowcode.
-
medelec35
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
Re: stack overflow
Thanks Steve.
This issue is also covered here:
http://www.matrixmultimedia.com/mmforum ... 56&p=14010
Question. If you used a target chip with a higher hardware stack, does the software stack have the same higher limit as hardware stack?
Also is it not better to have a higher hardware stack if you want to increase sw stack, since it makes the running of the code more efficient?
Lastly do you know what the sw stack size could be increased to on the 16F877A for example?
This issue is also covered here:
http://www.matrixmultimedia.com/mmforum ... 56&p=14010
Question. If you used a target chip with a higher hardware stack, does the software stack have the same higher limit as hardware stack?
Also is it not better to have a higher hardware stack if you want to increase sw stack, since it makes the running of the code more efficient?
Lastly do you know what the sw stack size could be increased to on the 16F877A for example?
Martin
- Steve
- Matrix Staff
- Posts: 3434
- Joined: Tue Jan 03, 2006 3:59 pm
- Has thanked: 114 times
- Been thanked: 422 times
Re: stack overflow
This is from the boostc datasheet:
You are right - a larger hardware stack is more efficient, but if there is room in the RAM for a chip then there should be no problem. It looks like the software stack depth is as high as the available RAM. It also seems to handle the size of the software stack behind the scenes - i.e. you only specify the size of the hardware stack to use.-swcs s1 s2 s3
This command line option to the linker tells it to use a software call stack in
addition to the hardware call stack. This allows subroutine calls deeper than the
call hardware call stack of the PIC. A function call that is made on the software call
stack uses an extra byte of RAM to hold the return point number. This option must
be used when using Novo RTOS. Where possible the hardware stack is used for
efficiency. By specifying the depth of hardware stack to use for main (and Novo
tasks) s1, ISR (interrupt service routine) s2 and low priority ISR (PIC18 only) s3,
provides control over when the software call stack is used instead of the hardware
call stack. The software call stack is applied to functions higher up in the call tree,
so calls lower down the call tree still use the hardware call stack. If no hardware
stack depths are specified, then the software stack is only used in functions that
contain or call functions that contain a Novo RTOS Sys_Yield() function.
Example:
-swcs 6 2
Main routine will use hardware call stack up to a depth of 6 and then start using
software call stack. Interrupt routine will use hardware call stack up to a depth of 2
and start using software call stack. An ISR uses hardware call stack depth of 1 to
save the address of the point where the code was interrupted, so in this example it
only leaves a hardware call stack depth 1 for subsequent calls within the ISR.
-
medelec35
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times