XC8 - possible hardware stack overflow detected

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 7.

Moderator: Benj

Post Reply
User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

XC8 - possible hardware stack overflow detected

Post by Benj »

Hello,

I've just come across a stack related problem using the XC8 compiler and thought I would document my work around.

Here is the warning I receive when compiling.

Uart_Int (1).c: 1884: (1393) possible hardware stack overflow detected; estimated stack depth: 10 (warning)

I’ve been looking through the XC8 compiler manual and there is a way to switch on a software stack.

In the compiler options make a new compiler type for the PIC family with these compiler parameters.

Compiler Parameters
--chip=$(chip) "$(target).c" --MSGDISABLE=359,1273,1388 --RUNTIME=stackcall


The stack controls how many jumps away from main a program can make and be able to find it’s way back to where it was. E.g. macros and components macros each require a level of the stack. A macro that calls another macro uses two levels of stack. Interrupt macros will also use the stack.

I'm using a 16F88 device which I believe has a hardware stack of 8 jumps. The –RUNTIME=stackcall basically uses RAM to store the return addresses when you run out of hardware stack. Beware the software stack has the possibility of corrupting your RAM variables, especially if you are already low on RAM in your program. Maybe try optimising your program or moving to a bigger device.

Here is an exported version of the compiler options you can import using the compiler options import button. Remember to set the option you want to use to be the default option.
XC8_SWStack.FCS
(571 Bytes) Downloaded 372 times

Post Reply