avr-libc-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [avr-libc-dev] Missing vprintf_P in avr-libc


From: Stu Bell
Subject: RE: [avr-libc-dev] Missing vprintf_P in avr-libc
Date: Fri, 19 Feb 2010 10:59:56 -0700

> I recognized that for mostly all print functions a _P version 
> exists, besides of vprintf. In a current project I need this 
> one and I wondered why it is not in th avr-libc.

The AVR is a "Harvard" architecture, with separate data and instruction
memorie spaces.  The instructions are kept in flash, while the data is
kept in RAM.

Because the string functions (of which vprintf is a part) expects all
data pointers to reference RAM, the GCC compiler stores constant strings
in Flash but copies them to RAM during the system initialization.  If
you have a lot of strings, this can take up a lot of space.

To help with this, there are routines that allow you to store your
string in flash and bring them into RAM only when you need them  You
store these constants by giving them a PROGMEM attribute.  In addition,
routines are provided to duplicate the more interesting string functions
when calling up these stored constants.  These routines have a _P
suffixed to them, such as your vprintf_P.

Read the tutorial at
http://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&t=38003
and all will be made clear.

In fact, you might also want to hit the thread
http://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&t=70673
which all sorts of good pointers for AVR newbies.


Best regards, 

Stu Bell 
DataPlay (DPHI, Inc.) 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]