Keil™, An ARM® Company

Discussion Forum

How to know stack overflow

Next Thread | Thread List | Previous Thread Start a Thread | Settings

DetailsMessage
Read-Only
Author
Jacky C
Posted
7-Feb-2006 02:50 GMT
Toolset
C51
New! How to know stack overflow
I have a question.
How to know maximum stack of my program and stack overflow?
beacause my program can lock when power have unstatable.
Read-Only
Author
Shail PAtel
Posted
7-Feb-2006 05:15 GMT
Toolset
C51
New! RE: How to know stack overflow
Hi,
The stack behaviour 8051 based core is little bit different from others. Here stack is used for:

1. Storing return address from function as well as ISR

2. Saving and Restoring Registers used in interrupt, if no register bank is defined for storing default register bank

3. Saving and restoring intermideate results

All local and global variables as well as function arguments will be stored on seperate memory (RAM). Stack will be allocated from idata which is 255 byte long, so there is a very little chance to have overflow in stack. But one can find out manually the stack usage by filling idata with 0xFF and observe the max. usage. There is not way to detect overflow runtime.

-SP
Read-Only
Author
Jacky C
Posted
7-Feb-2006 06:09 GMT
Toolset
C51
New! RE: How to know stack overflow
Thank you very much. I will try it.
If I assume that stack pointer point to wrong address in unstable power, how to know stack pointer be right or wrong?
Read-Only
Author
Reinhard Keil
Posted
7-Feb-2006 06:57 GMT
Toolset
C51
New! RE: How to know stack overflow
See also:
http://www.keil.com/support/docs/192.htm
Read-Only
Author
Hans-Bernhard Broeker
Posted
7-Feb-2006 15:10 GMT
Toolset
C51
New! RE: How to know stack overflow
If I assume that stack pointer point to wrong address in unstable power, how to know stack pointer be right or wrong?

That assumption is unfounded. If you have unstable power, a wandering stack pointer is the very least of your problems. Once the power becomes unstable (i.e. drops below the minimum allowed by the datasheet of your micro), anything can happen. You don't want to go there.

You're asking the wrong question. You should be asking yourself how to stabilize your power source, or how to survive any remaining instability. Forget the stack pointer, learn about power watchdogs and proper reset generation instead.
Read-Only
Author
Andy Neil
Posted
7-Feb-2006 06:57 GMT
Toolset
C51
New! Not the stack?
"my program can lock when power have unstatable"

That's very likely nothing to do with stack overflow, then.

Are you using a proper supervisor and reset generator chip?

Using a simple RC reset circuit will give you problems if you have "unstable" power!
Read-Only
Author
Drew Davis
Posted
7-Feb-2006 19:46 GMT
Toolset
C51
New! RE: Not the stack?
Once the power becomes unstable, anything can happen

A point worth emphasizing. For example, the SP could still be correct, but the memory to which is points changes values due to lack of power. Or the ALU gets the correct SP, and mangles the value while processing the instruction. There's just no way to guarantee that the chip will work correctly in this situation, or even that it will fail the same way every time.

If you have external devices on the board, you don't even know whether or not they have valid power, either; even if the processor core works, the rest of the board might not.

If handling loss of power is a design requirement, then the power supply has to deliver a power-fail signal to the CPU before falling below the minimum Vcc, and also guarantee enough capacitance in the supply to keep that voltage above the minimum for long enough for the CPU to shut down cleanly. Trying to detect power failure by having the CPU monitor itself for improper behavior won't work.
Read-Only
Author
erik malund
Posted
7-Feb-2006 20:30 GMT
Toolset
C51
New! RE: Not the stack?
If I assume that stack pointer point to wrong address in unstable power, how to know stack pointer be right or wrong

rephrasing the question
"how can I fix hardware in software"
answer
"you can't"

Erik
Read-Only
Author
Andy Neil
Posted
7-Feb-2006 21:30 GMT
Toolset
C51
New! It's worse than that, Jim!
"having the CPU monitor itself for improper behavior won't work"

Not only are you trying to have the CPU monitor itself for improper behaviour, but you are trying to have the CPU monitor itself for improper behaviour whilst behaving improperly!!! :-0

The word "Doomed!" springs to mind...

Next Thread | Thread List | Previous Thread Start a Thread | Settings