Keil Logo

C166: Changing the System Stack Size and Location

Information in this article applies to:

  • C166 Version 5 and later


How do I change the size and location of the system stack?


Configure the startup code START167.A66 (not required for XC16x devices) for no wrapping stack and define the location of the stack section using the L166 SECTIONS directive.

  1. Startup code START167.A66 configuration (Note: this is not required for XC16x devices since START_V2.A66 always configures a non-wrapping stack):

    ; STKSZ: Maximum System Stack Size selection  (SYSCON.13 .. SYSCON.15)
    ;  Defines the system stack space which is used by CALL/RET and PUSH/POP
    ;  instructions.  The system stack space must be adjusted according the
    ;  actual requirements of the application.
    $SET (STK_SIZE = 7)
    ;     System stack sizes:
    ;       0 = 256 words (Reset Value)
    ;       1 = 128 words
    ;       2 =  64 words
    ;       3 =  32 words
    ;       4 = 512 words
    ;       5 = not implemented
    ;       6 = not implemented
    ;       7 = no wrapping (entire internal RAM use as STACK, set size with SYSSZ)
    ; If you have selected 7 for STK_SIZE, you can set the actual system stack size
    ; with the following SSTSZ statement.
    SSTSZ  EQU  200H  ; set System Stack Size to 200H Bytes
  2. Enter the stack section setting in µVision under Project - Options - L166 Locate - User Sections:


    As alternative you may use the Linker SECTIONS directive at the command line. Note that the stack must be within IDATA RAM.


Last Reviewed: Thursday, February 25, 2021

Did this article provide the answer you needed?
Not Sure
  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.