[Top][All Lists]

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

Re: [avr-gcc-list] String in flash

From: Russell Shaw
Subject: Re: [avr-gcc-list] String in flash
Date: Wed, 15 Oct 2003 01:49:11 +1000
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.2.1) Gecko/20030311 Debian/1.2.1-10

E.Weddington wrote:
I've read all the manual and header files. I've tried:

  static const char* hex="0123456789abcdef";
  static PGM_P hex="0123456789abcdef";
  static PGM_P hex=(prog_int8_t*)"0123456789abcdef";

but the "0123456789abcdef" string seems to go in the .data

These give an error:

  static PGM_P hex =  PSTR("0123456789abcdef");
error: braced-group within expression allowed only inside a function

Yes, unfortunately the PSTR() macro can only be used within a function.

This is the way you would declare it outside a function:

#include <avr/pgmspace.h>
#include <inttypes.h>

static uint8_t hex[] PROGMEM = "0123456789abcdef";

Use the pgm_read_byte() macro to read a data value that is placed in flash such as:

val = pgm_read_byte(&(hex[3]));   // val == '3'

Sorry if the docs are confusing about this.

I tried PROGMEM and found these both give the same result:

static uint8_t hex[] PROGMEM = "0123456789abcdef";
static uint8_t PROGMEM hex[] = "0123456789abcdef";

 217                            .section        .progmem.data,"a",@progbits
 218                            .type   hex, @object
 219                            .size   hex, 17
 220                    hex:
 221 0000 3031 3233             .string "0123456789abcdef"
 221      3435 3637
 221      3839 6162
 221      6364 6566
 221      00
 222                            .text

nm confirms that "hex" is in the text section. However, isn't this wrong?
I've been trying to get the "hex" pointer variable into the .data section
(normal ram variables), but have it initialized to be pointing to the start
of "0123456789abcdef" in the .text section in flash rom. The above lines
look like "hex" is a non-variable pointer frozen in flash, pointing to
the start of "0123456789abcdef" also in flash.

reply via email to

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