avr-gcc-list
[Top][All Lists]
Advanced

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

Re: [avr-gcc-list] PROGMEM with boot loader


From: Wolfgang Quack
Subject: Re: [avr-gcc-list] PROGMEM with boot loader
Date: Mon, 22 Nov 2004 13:43:57 +0100 (CET)

Hi Yannick,

fprintf_P sets __SPGM in the stream->flags and calls vfprintf.
And vfprintf reads the format string via PRG_RDB macro.

There's no support in fprintf_P to print PROGMEM strings from vars,
therefore you must use something like this:

const char essai[] PROGMEM = {"essai\n"};
fputs_P(essai, OutPc);

But this didn't solve your problems, because the library use the PRG_RDB
macro which reads near memory (lower 64kB of the AVR) with the LPM
assembler instruction instead of the ELPM. But you need to call ELPM in
case of bootloader address spaces (> 64kByte).
And this is the reason why your format string must be located in the
lower progmem.
The va_list must be located in data space (RAM) in every version of
fprintf.

In formatted output the ..printf_P() reads the format-string from PROGMEM.
In direct output the fputs_P() reads the string from PROGMEM.
In both cases the string in PROGMEM must be located in addresses lower
0x10000 !

To see more details look in the avr-libc-users-manual and/or the
pgmspace.h include file.

To get a version of avr-libc with far support you have to edit
pgmspace.h and redefine the macro PRG_RDB
#define PRG_RDB(addr)   pgm_read_byte_far(addr)
and then don't forget to make and install it.

Wolfgang

On Mon, 22 Nov 2004, Yannick PODGORSKI wrote:

> Hi Wolfgang,
> thanks again but it doesn't work again.
> I use :
>         const char essai[] PROGMEM = {"essai"};
> and
>         fprintf_P(OutPc, "%s", pgm_read_byte_far(essai));
>
> You talked about PRG_RDB but I don't use it.
> I try to use PSRT :
>         fprintf_P(OutPc, PSTR("PSTR")); and it doesn't work.
> You say that's fprint_P() supports only near progmem but
> I don't see that in libc.
> Sorry for my questions.
>
> Yannick.
>
> > On Fri, 19 Nov 2004, Wolfgang Quack wrote:
>
> > Hi Yannick,
> >
> > uups, sorry.
> >
> > The fprintf_P() in avr-libc-1.0.4 supports only near progmem.
> >
> > Look at avr-libc-1.0.4/libc/stdio/vfprintf.c line 141:
> > The old style macro PRG_RDB() is used there.
> > This is defined as the near version of pgm_read_byte() instead of the
> > far version you need to access the upper memory.
> >
> > Wolfgang
> >
> >
> > On Fri, 19 Nov 2004, Yannick PODGORSKI wrote:
> >
> >> Hi Wolfgang,
> >> thanks for your answer but it doesn't work
> >> with "RAMPZ = 1" or "RAMPZ = 0".
> >> I try this before but nothing.
> >> I try again to put the section .text at the address 0x0
> >> and it works with "RAMPZ = 1" AND "RAMPZ = 0".
> >> It's strange because this bit allow me to access to upper
> >> or lower flash and I can access whatever the RAMPZ is.
> >> Thanks.
> >>
> >> Yannick
> >>
> >>
> >> > On Fri, 19 Nov 2004, Wolfgang Quack wrote
> >>
> >>
> >> > Hi Yannick,
> >> >
> >> > Just put "RAMPZ = 1;" in front of fprintf_P(...)
> >> >
> >> > You need this, because the const's are now in the upper space or flash.
> >> >
> >> > Wolfgang
> >>
>


reply via email to

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