[En-Nut-Discussion] gcc, large programs, corrupted variable or memory space? :( --> :)

Brett Abbott Brett.Abbott at digital-telemetry.com
Sat Apr 19 00:27:17 CEST 2003


  Hi

I have used the prog_char "macro" to shift char strings into Flash, away 
from precious sram (and using the _P functions) which works well except 
for char arrays.

Before I launch into finding either a fix to fprint_P or my misguided C 
programming, I humbly ask if this should even work or if there is a 
better way.

Examples: (from the httpserv.c demo)

// Works: 
static char *states[] = { "TRM", "<FONT COLOR=#CC0000>RUN</FONT>", "<FONT COLOR=#339966>RDY</FONT>", "SLP" };  fprintf(stream, "<TD>%s</TD>", states[tdp->td_state]); 

// Doesnt work: 
static prog_char *states[] = { "TRM", "<FONT COLOR=#CC0000>RUN</FONT>", "<FONT COLOR=#339966>RDY</FONT>", "SLP" };
fprintf_P(stream, "<TD>%s</TD>", states[tdp->td_state]);

The latter version seems to output some sort of corrupted string, the 
original using normal "char *" works fine as Harald intended.

Many Thanks
Brett

Igor V. Tchibirev wrote:

>Hi Brett,
>I faced the same problems a couple months ago. The reason is very simple.
>All the variables you have in program will be allocated by linker either in
>.data or in .bss section. Take a look at your *.map file. The trick is that
>total amount of memory is 4K bytes - it is internal data memory of
>processor. Good news:
>1. you can either allocate static initiated variables in program memory
>using prog_char instead of char and NutOs special functions to have access
>to these variables. For example NutProntString_P(...) instead of
>NutPrintString(...).
>2. Big peaces of data without initialization you can allocate in external
>data memory using NutOs hash functions. For example
>#define DATA_LEN 5000
>u_char* p_crypto_heap;
>.....
>// with "garbage" (random) init
> p_crypto_heap = NutHeapAlloc( DATA_LEN );
>// with zero initialisation
>p_crypto_heap = NutHeapAllocClear( DATA_LEN );
>
>After this string you can us
>e pointer p_crypto_heap the same way as any
>other pointer.
>
>Hope it helps.
>Regards
>
>Igor Tchibirev,
>System software developer
>Intech 21, Inc.
>50 Glen Street,
>Glen Cove, NY, 11542
>516 656 5581 x228
>http://www.intech21.com
>
>

-- 
-----------------------------------------------------------------
Brett Abbott, Managing Director, Digital Telemetry Limited
Email: Brett.Abbott at digital-telemetry.com
PO Box 24 036 Manners Street, Wellington, New Zealand
Phone +64 (4) 5666-860  Mobile +64 (21) 656-144
------------------- Commercial in confidence --------------------







More information about the En-Nut-Discussion mailing list