How to change stack size for S12ZVML

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to change stack size for S12ZVML

1,042 Views
pratibhasurabhi
Contributor V

I want to change stack size for S12ZVML MCU.

I am using codewarrior V10.7.

is there any setting in codewarrior for changing stack size?

How to access the stack pointer in watch window at runtime?

Please provide me solution for the same.

0 Kudos
3 Replies

664 Views
lama
NXP TechSupport
NXP TechSupport

Hi,

There are commands STACKSIZE and STACKTOP you can use in the prm linker command file. Can be found in the project tree Project Setings->Linker_Files

pastedImage_2.png

Usually STACKSIZE is default.

STACKSIZE 0x100

Changing its value, you change size of allocated space for stack.

 

Usage of the stack is not possible to be done by any CW feature. The possibilities are either to use FILL command with defined value in prm linker file or fill the memory with given pattern in the debugger. Then you can check how large part of your stack was used by your code.

 

So finally, suitable combination of STACKSIZE or STACKTOP with the FILL command or filling the memory with given pater in the debugger provides you possibility to check stack usage.

 

******************

Some info copied from CW help (searched by index)

 

Defining a Fill Pattern

 

You can associate a fill pattern with each segment in the application. This can be useful for automatically initializing uninitialized variables in the segments with a predefined pattern.

 

Specify a fill pattern as follows:

 

FILL <HexByte> {<HexByte>}

 

 

 

NOTE 

Any segment defined with the FILL command in the SEGMENTS portion of the prm file fills only if the segment is also used in the PLACEMENT section of the prm file. If necessary, add a dummy entry to the PLACEMENT section.

 

 

The following listing shows an example.

 SEGMENTS

      RAM_1  = READ_WRITE 0x800 TO 0x8FF

               FILL 0xAA 0x55;

  END

  PLACEMENT

      DUMMY  INTO RAM_1

  END

 

This example initializes uninitialized objects and filling bytes with the pattern 0xAA55.

 

If the size of an object to initialize is greater than the size of the specified pattern, the pattern repeats as many time as necessary to fill the objects. In this example, an object with a size of 4 bytes initializes with 0xAA55AA55.

 

If the size of an object to initialize is less than the size of the specified pattern, the pattern truncates to match the size of the object. In this example, an object with a size of 1 byte initializes with 0xAA.

 

When the value specified in an element of a fill pattern does not fit into a byte, it truncates to a byte value.

 

The following listing shows as example.

 SEGMENTS

      RAM_1  = READ_WRITE 0x800 TO 0x8FF

               FILL 0xAA55;

  END

 

This example initializes uninitialized objects and filling bytes with the pattern 0x55. The specified fill pattern truncates to a 1-byte value.

 

Fill patterns are useful for assigning an initial value to the padding bytes inserted between two objects during object allocation. This allows marking from the unused position with a specific marker and detecting them inside of the application.

 

For example, you can initialize an unused position inside a section of code with the hexadecimal code for the NOP instruction.

 

******************

STACKTOP: Define Stack Pointer Initial Value

 

Syntax

 

STACKTOP Number

 

Description

 

The optional STACKTOP command cannot be specified more than once in a prm file. Additionally, you cannot specify both STACKTOP and STACKSIZE (see STACKSIZE: Define Stack Size) in a prm file.

 

The STACKTOP command defines the initial value for the stack pointer.

 

Example

 

Define STACKTOP as:

 

STACKTOP 0xBFF

 

This initializes the stack pointer with 0xBFF at application startup.

 

Defining the stack using a STACKTOP command alone affects the default stack size. Stack size depends on the processor and is big enough to store the target processor PC.

 

Defining the stack using a STACKTOP command associated with the placement of the .stack section starts the stack at the specified address, and includes the start address of the segment where .stack is placed.

 

Example

 

SEGMENTS

 

MY_STK = NO_INIT 0xB00 TO 0xBFF;

 

MY_RAM = READ_WRITE 0xA00 TO 0xAFF;

 

MY_ROM = READ_ONLY 0x800 TO 0x9FF;

 

END

 

PLACEMENT

 

DEFAULT_ROM INTO MY_ROM;

 

DEFAULT_RAM INTO MY_RAM;

 

SSTACK INTO MY_STK;

 

END

 

STACKTOP 0xB7E

 

This example defines the stack pointer from address 0xB7E to address 0xB00.

******************

STACKSIZE: Define Stack Size

 

Syntax

 

STACKSIZE Number

 

Description

 

The STACKSIZE command is optional in a prm file and it cannot be specified more than once. Additionally, you cannot specify both STACKTOP and STACKSIZE commands in the same prm file (see STACKTOP: Define Stack Pointer Initial Value).

 

The STACKSIZE command defines the size requested for the stack. We recommend using this command if you do not care where the stack is allocated but only how large it is.

 

When the stack is defined using a STACKSIZE command alone, the stack is placed next to the section .data.

 

 

 

NOTE 

In the Freescale object file format allows the synonym STACK instead of STACKSIZE. This is for compatibility only, and may be removed in a future version.

 

 

Example

 

SECTIONS

 

MY_RAM = READ_WRITE 0xA00 TO 0xAFF;

 

MY_ROM = READ_ONLY 0x800 TO 0x9FF;

 

PLACEMENT

 

DEFAULT_ROM INTO MY_ROM;

 

DEFAULT_RAM INTO MY_RAM;

 

END

 

STACKSIZE 0x60

 

In this example, if the section .data is 4 bytes wide (from address 0xA00 to 0xA03), the section .stack is allocated next to it, from address 0xA63 down to address 0xA04. The stack initial value is set to 0xA62.

 

When the stack is defined through a STACKSIZE command associated with the placement of the .stack section, the stack is supposed to start at the segment start address incremented by the specified value and is defined down to the start address of the segment, where .stack has been placed.

 

Example

 

SECTIONS

 

MY_STK = NO_INIT 0xB00 TO 0xBFF;

 

MY_RAM = READ_WRITE 0xA00 TO 0xAFF;

 

MY_ROM = READ_ONLY 0x800 TO 0x9FF;

 

PLACEMENT

 

DEFAULT_ROM INTO MY_ROM;

 

DEFAULT_RAM INTO MY_RAM;

 

SSTACK INTO MY_STK;

 

END

 

STACKSIZE 0x60

 

This example allocates the SSTACK section from address 0xB5F down to address 0xB00. The initial stack value is set to 0xB5E.

Best regards,

Ladislav

664 Views
pratibhasurabhi
Contributor V

Thanks!

I got the prm file,thanks for quick reply.

0 Kudos

664 Views
pratibhasurabhi
Contributor V

In my workspace,in the project tree ,Project setting->Linker Files is not present as below

pastedImage_1.png

0 Kudos