Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Скачиваний:
84
Добавлен:
01.03.2016
Размер:
3.56 Mб
Скачать

RM0016

Memory and register map

 

 

3.1.2Stack handling

Default stack model

The stack of the STM8S and STM8AF microcontrollers is implemented in the user RAM area. The default stack model is shown in Figure 4.

Figure 4. Default stack model

2!-

3TARTTADDRESS

3TACKKROLL OVER LIMIT

%NDNADDRESS 3TACKKPOINTERIINITIALIZATION VALUE

$EFAULTASTACKKMODEL

AI

1. The stack roll-over limit is not implemented on all devices. Refer to the datasheets for detailed information.

Stack pointer initialization value

This is the default value of the stack pointer. The user must take care to initialize this pointer. Correct loading of this pointer is usually performed by the initialization code generated by the development tools (linker file). In the default stack model this pointer is initialized to the RAM end address.

Stack roll-over limit

In some devices, a stack roll-over limit is implemented at a fixed address. If the stack pointer is decreased below the stack roll-over limit, using a push operation or during context saving for subroutines or interrupt routines, it is reset to the RAM end address. The stack pointer does not roll over if stack pointer arithmetic is used.

Such behavior of the stack pointer is of particular importance when developing software on a device with a different memory configuration than the target device.

Doc ID 14587 Rev 9

31/454

Memory and register map

RM0016

 

 

Customized stack model

STM8S and STM8AF 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

2!-

3TARTTADDRESS

/PTIONAL GUARD CELLS

&LEXIBLE STACKKSIZE

3TACKKPOINTERIINITIALIZATION VALUE

3TACKKROLL OVER LIMIT

%NDNADDRESS

#USTOMIZED STACKKMODEL

AI

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.

32/454

Doc ID 14587 Rev 9

Соседние файлы в папке Минимум документации STM8