Memory and register map RM0016
32/449 Doc ID 14587 Rev 8
Customized stack model
STM8S and STM8A stack pointer handling allows a customized stack model to be
implemented. This permits a flexible stack size without restrictions due to the stack roll-over
limit. Implementing the customized stack also benefits portability of the software on products
with different memory configurations. Figure 5 shows the customized stack model.
Figure 5. Customized stack model
1. The stack roll-over limit is not implemented on all devices.
2. The guard cells are RAM locations that have to be continuously polled by the application program to detect
whether a stack overflow has taken place.
In this stack model, the initial stack pointer must be placed beyond the stack roll-over limit.
Consequently, the growing stack never reaches the stack roll-over limit. It is clear that in this
implementation the stack size is not limited by the roll-over mechanism. Nevertheless, the
user has to define the stack position and stack size in the link file, and he has to ensure that
the stack pointer does not exceed the defined stack area (stack overflow or under-run).
The RAM locations above and below the customized stack can be regularly used as RAM to
store variables or other information.
Guard cells can be implemented at the lower end of the stack to detect if the stack pointer
exceeds the defined limit. These cells are standard RAM locations, initialized with fixed
values that the stack overwrites if an overflow occurs. The user software can regularly poll
these cells, detect the overflow condition, and put the application in a fail safe state.
During the software validation phase hardware breakpoints can be set at both limits of the
stack to validate that neither a stack overflow nor an under-run happens.
ai15056
Customized stack model
End address
Stack roll-over limit
(1)
Stack pointer initialization value
Start address
RAM
Optional guard cells
(2)
Flexible stack size