Use of SSTACK_AREA

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

Use of SSTACK_AREA

1,962 Views
PabloA
Contributor II
Hi again...
 
I'm using 96 Bytes of SSTACK_AREA for sprintf() and it let me without enough Z_RAM for the rest of functions. But if in the mostly of my code I use non "statics" variables whay this variables use Z_RAM space? How can I make that CodeWarrior use the SSTACK_AREA for non "statics" variables?
If it is posible I can use non statics variables while sprintf() is not used.
 
P.D:
I'm using    #pragma DATA_SEG __SHORT_SEG _DATA_ZEROPAGE1 for statics variables and the non statics are define in each function.
 
 
Thank you once again...
 
Pablo
Labels (1)
0 Kudos
6 Replies

405 Views
CompilerGuru
NXP Employee
NXP Employee
I'm not sure I understand what you refer to with "non statics".
CW is using the stack for normal local/automatic variables,
can you provide a small sample of your setup?

Also, one way would be not to use ssprintf but to use instead other functions for that purpose, I think that was proposed already on another thread.
Alternatively if you want to use sprintf, but if you do not use floats (%f, %g,..) or longs (%l), then the printf.c can be recompiled with the long support disabled. I think that helps also quite a bit to reduce the stack needs of sprintf.

Daniel
0 Kudos

405 Views
PabloA
Contributor II
Dear Daniel:
 
About sprintf already I solved the problem using a simple code that convert Binary to BCD and then convert to ASCII so it let me free a lot of RAM memory.
 
With "non statics" I refer to variables declared in the same function that only are used when this function is working and then this espace of RAM is free for another variables.
When I need to keep the data in variables declared as local, I use "static" so I understand tha the space for this variable has to be in My_zero_page like Global variables. But I don't know why CW use My_zero_page to locate local/automatic variables.
 
I declare my variables like this:
 
 
For Global I use the same Header included in all my code files with the diference that I define Global in the Main and Extern in the other ones.
 
#if VariableGlobal

        // --------- Global Variable Define ---------- //
 
      #pragma DATA_SEG __SHORT_SEG _DATA_ZEROPAGE
  
     unsigned char Output_SCI_Buffer [5] = 0;
     unsigned char Input_SCI_Buffer [5] = 0;
     unsigned char Input_Buffer = 0;
     unsigned char Time_Base_Div1 = 5;
    // and so on... 
      #pragma DATA_SEG DEFAULT
     
#endif
 
 
#if VariableExtern

        // --------- Extern Variable Define ---------- //
 
      #pragma DATA_SEG __SHORT_SEG _DATA_ZEROPAGE
    
     extern unsigned char Output_SCI_Buffer [5];
     extern unsigned char Input_SCI_Buffer [5];
     extern unsigned char Input_Buffer;
     extern unsigned char Time_Base_Div1;
   
    // and so on... 
     #pragma DATA_SEG DEFAULT

#endif
 
 
 
For local variables:
 
static unsigned char My_Static_Variable = 0;
unsigned char My_Local_Variable = 1;
 
void My_Function (void)
{
       My_Static_Variable = 1;
       My_Local_Variable = 2;
}
 
This is my third program using CW and I had to learn about it for my self so maybe I'm wrong whit some thing.
 
Thank you for your interest in my problem.
 
Pablo
0 Kudos

405 Views
Alban
Senior Contributor II
Hello Daniel, The Orange suits you well :smileywink:

I was wondering if there was a Technical Note giving tips about code size.
In one of the last Newsletter for DevTech, I think there was a trick for the library to take less space.

As far as I remember, using a #define __NO_FLOAT__ was reducing greatly the size of code.

Would you know of any document or defines we can add when we only work on INT, like 99% of HC08, S08 and also most of S12 and S12X ?

Cheers,
Alban.
0 Kudos

405 Views
CompilerGuru
NXP Employee
NXP Employee
Good question, the tn105.pdf covers the general library building.

In old releases recompiling printf.c with -D__NO_FLOAT__ did help a lot, but we do now provide a library actually built with this switch, the one which gets linked when choosing no floating point support. As this switch is the default, I expect most users to already have this optimization.
There is no prebuilt library with a sprintf with no long support, the steps to build one is the same as for the -D__NO_FLOAT__, just the option is -dLIBDEF_PRINTF_LONG=0 instead. No long support only works with no float, as that part needs the long support internally. The size reduction is not that extrem like when dropping the floating point part, but still a few hunders bytes.
I saw that sprintf(buf, "Hello %i", i); needs 75 bytes on the stack with IEEE64 support, 67 bytes with just IEEE32, 58 bytes with no floating point support and 40 bytes when the long support is disabled too.

The numbers will be different for the HC12 (or HCS12X, HC08, XGATE, RS08, ...) but the setup is the same.
0 Kudos

405 Views
CrasyCat
Specialist III
Alban
 
There is no Technical Note, but a FAQ on this topic :smileywink:.
Look for FAQ-27453 on Freescale Web page.
 
CrasyCat
0 Kudos

405 Views
Alban
Senior Contributor II
Hello Pablo,

When it linked (before including the fprintf()), you can look at the MAP file in the output directory.
You may have to enable the map file creation in your target options, output, create map file.

With this file, you can see how your memory is used and where variables and others are placed.

If you use global constants, start their declaration with "const" to make sure they are placed in flash to save your RAM space.
Also, the Z_RAM is the Page Zero. By putting the #pragma, you force them in page zero.
If you don't put a #pragma DATA_SEG DEFAULT after, it will keep putting them in page zero.

Alban.
0 Kudos