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

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

[avr-gcc-list] program memory access question


From: Andrew Edgecombe
Subject: [avr-gcc-list] program memory access question
Date: Wed, 12 Jun 2002 16:15:37 +1000

Hello avr-gcc folk,

I'm attempting to get the avr-gcc (v3.0.4) compiler to access structures 
that I have stored in program memory.

However, I'm having some difficulty convincing the compiler.
Take the following code snippet:

typedef struct
        {
        char wasteOfSpace;
        } junkType __attribute__ ((progmem));

junkType thing1 = {0xff};
int main(void)
        {
        const junkType *tempPtr;
        char tempChar;
        tempPtr = &thing1;
        tempChar = tempPtr->wasteOfSpace;
        return 0;
        }

which generates the following map:
(snip)
000000d0 T main
0000008c T thing1
(putting "thing1" into program space)

However, the assembler generated is as follows:
(snip)
        tempPtr = &thing1;
  d8:   8c e8           ldi     r24, 0x8C       ; 140
  da:   90 e0           ldi     r25, 0x00       ; 0
  dc:   89 83           std     Y+1, r24        ; 0x01
  de:   9a 83           std     Y+2, r25        ; 0x02
        tempChar = tempPtr->wasteOfSpace;
  e0:   e9 81           ldd     r30, Y+1        ; 0x01
  e2:   fa 81           ldd     r31, Y+2        ; 0x02
  e4:   80 81           ld      r24, Z
  e6:   8b 83           std     Y+3, r24        ; 0x03
(snip)

tempPtr has the correct value stored in it, however the dereference is ignoring
the fact that the pointer is defined to be pointing to program memory (by 
virtue of
the junkType attribute).

Can I do what I'm trying to do without reverting to calls to _lpm_inline?
Is there something obvious that I'm missing?

thanks in advance,
Andrew Edgecombe

-- 
Andrew Edgecombe <address@hidden>

avr-gcc-list at http://avr1.org



reply via email to

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