• AVR Freaks

Does C30 optimisation break __prog__ pointers?

Author
Barefoot Andrew
New Member
  • Total Posts : 18
  • Reward points : 0
  • Status: offline
2012/03/07 12:40:50 (permalink)
0

Does C30 optimisation break __prog__ pointers?

Hello All. We have a snippet of code that goes something like this:-
 #define CONFIG_START 0x2800  static const __prog__ Byte *rulePointer;  Byte getFirstRule() {      if (getAreaLength())      {          rulePointer = (const __prog__ Byte *)CONFIG_START;          return *rulePointer;      }       return 0; } 
In other words, there is some data stored in flash memory at 0x2800 onwards, and this bit of code reads the first byte. Debug builds consistently work correctly. Most release builds do not, and the 'return *rulePointer' statement resolves to machine instructions that fetch a byte from 0x2800 in *ram* not *flash*. I say most, because we can occasionally get release builds to work, if we include/exclude other blocks of data stored in flash memory. As yet, we haven't spotted a pattern in terms of what makes it work and what makes it fail. The MPU is the PIC24FJ128GB110. Current compiler version in v3.23, although the latest v3.31 behaves in the same way for us. Any suggestions would be welcome... Regards, A.
post edited by Barefoot Andrew - 2012/03/07 12:53:37
#1

7 Replies Related Threads

    Barefoot Andrew
    New Member
    • Total Posts : 18
    • Reward points : 0
    • Status: offline
    Re:Does C30 optimisation break __prog__ pointers? 2012/03/07 12:44:10 (permalink)
    0
    Ooh - all my paragraphs have gorn missing. Not sure why. Apologies to all for unfriendly block of text. A.
    #2
    Neiwiertz
    Super Member
    • Total Posts : 2094
    • Reward points : 0
    • Joined: 2004/09/01 02:58:52
    • Status: offline
    Re:Does C30 optimisation break __prog__ pointers? 2012/03/07 15:05:08 (permalink)
    0
    Try reserve space for "flash memory at 0x2800 onwards" only by a section at gld, like this or manual edit gld
    post edited by Neiwiertz - 2012/03/07 15:08:18

    Flying With --|Explorer 16|HardWare|SoftWare|-- Fav(s) Gallery Lists
    #3
    Barefoot Andrew
    New Member
    • Total Posts : 18
    • Reward points : 0
    • Status: offline
    Re:Does C30 optimisation break __prog__ pointers? 2012/03/07 15:46:30 (permalink)
    0
    Thanks for the suggestion - I'll give it a whirl. I'd be interested to know why this is problematic unless optimisations are -O0, if anyone knows. Regards, A.
    #4
    Barefoot Andrew
    New Member
    • Total Posts : 18
    • Reward points : 0
    • Status: offline
    Re:Does C30 optimisation break __prog__ pointers? 2012/03/08 05:06:49 (permalink)
    0
    That works a treat - thanks. A.
    #5
    flubydust
    Super Member
    • Total Posts : 1286
    • Reward points : 0
    • Joined: 2005/05/19 13:44:42
    • Status: offline
    Re:Does C30 optimisation break __prog__ pointers? 2012/03/09 14:33:51 (permalink)
    0
    "That works a treat - thanks. A." Works a treat because you allocated space in FLASH or because you took the address of a variable rather than casting an int? I suspect C30 is currently (3.31) dubious if not bugged in this area. The introduction of processors with EDS means __prog__ pointers become a subset of __eds__ pointers and __eds__ pointers can point at FLASH or RAM (encoded in high order pointer bits). The compiler seems to mess up treating __prog__ pointers as __eds__ pointers to RAM under some circumstances. Don't know if targeting a processor with EDS or not makes a difference.
    #6
    cawilkie
    Administrator
    • Total Posts : 1977
    • Reward points : 0
    • Joined: 2003/11/07 12:49:11
    • Status: offline
    Re:Does C30 optimisation break __prog__ pointers? 2012/03/12 19:32:27 (permalink)
    0
    You can't use an integer for a pointer; sorry.  Take the address of a symbol.

    It is never guaranteed in C that a literal value represents a value of a memory location and it almost never does for pointers that are __eds__, __prog__, __psv__, __pmp__ or __external__ since there needs to be alot more information carried in the pointer than an offset from 0.

    Regards
    Calum
    #7
    Neiwiertz
    Super Member
    • Total Posts : 2094
    • Reward points : 0
    • Joined: 2004/09/01 02:58:52
    • Status: offline
    Re:Does C30 optimisation break __prog__ pointers? 2012/03/13 13:55:10 (permalink)
    0
    Hello Cawilkie Good for heads up about the pointers i understand roughly what you mean
    for OP question "my" reply will do the job i think
    post edited by Neiwiertz - 2012/03/13 13:57:26

    Flying With --|Explorer 16|HardWare|SoftWare|-- Fav(s) Gallery Lists
    #8
    Jump to:
    © 2019 APG vNext Commercial Version 4.5