• AVR Freaks

[FAQ]Inappropriate program address when using space(prog) pointer?

Page: 12 > Showing page 1 of 2
Author
JesperW
Starting Member
  • Total Posts : 80
  • Reward points : 0
  • Joined: 2009/04/27 10:49:24
  • Location: Sweden
  • Status: offline
2010/03/29 10:04:56 (permalink)
0

Inappropriate program address when using space(prog) pointer?

I read this post: http://www.microchip.com/forums/tm.aspx?m=422442

... and I have the same issue now with C30 3.23 ?

config.c:54: error: Inappropriate program address 'config_Data'
config.c:54: error: Inappropriate program address 'config_Data'

Line 54 is:

const unsigned char __attribute__((space(prog),aligned(_FLASH_PAGE*2))) config_Data[_FLASH_PAGE*2];

...but it seems the error is reported against the declaration when in effect it is somewhere else in the code.

The file is quite long and has many accesses to this variable, so I am a little at loss as to why I get 2 copies of the error.
I have removed all accesses to config_Data[<something>] and replaced them with pointer arithmetic, but I still get the error.

#1

25 Replies Related Threads

    cawilkie
    Administrator
    • Total Posts : 1977
    • Reward points : 0
    • Joined: 2003/11/07 12:49:11
    • Status: offline
    RE: Inappropriate program address when using space(prog) pointer? 2010/03/29 10:13:49 (permalink)
    0
    Perhaps the error message is important?

    The compiler is trying to be helpful by giving you the location of the bad definition... This means that you are tyring to access something in space(prog) which isn't accessible in the current form. If it was in space(auto_psv) you could; or space(psv) and you set the PSVPAG up, you could; or if you use __prog__ qualifier instead of the 'const', you could.

    The error message is likely repeated because it has been attempted on more than one occasion.

    Regards
    Calum
    #2
    JesperW
    Starting Member
    • Total Posts : 80
    • Reward points : 0
    • Joined: 2009/04/27 10:49:24
    • Location: Sweden
    • Status: offline
    RE: Inappropriate program address when using space(prog) pointer? 2010/03/29 10:21:56 (permalink)
    0
    Eh... of course it is important???

    My problem is I have many accesses, and apparently two are wrong, but how do I know which, when the compiler always points to the same line number?

    They all look like "*(config_Data+n)" where n is an integer.

    #3
    cawilkie
    Administrator
    • Total Posts : 1977
    • Reward points : 0
    • Joined: 2003/11/07 12:49:11
    • Status: offline
    RE: Inappropriate program address when using space(prog) pointer? 2010/03/29 10:34:08 (permalink)
    +1 (1)
    The compiler is pointing you at the definition because the definition is incompatible with the access request. You cannot access anything in space(prog) using 'C' unless it is qualified with __prog__. Understand what it means to qualify it with __prog__ (it may be more efficient to manually access it using __builtin_tblrdl for example).

    Regards
    Calum
    #4
    threedog
    Super Member
    • Total Posts : 998
    • Reward points : 0
    • Joined: 2009/12/04 12:28:11
    • Location: Boise
    • Status: offline
    RE: Inappropriate program address when using space(prog) pointer? 2010/03/29 10:43:27 (permalink)
    0
    ORIGINAL: JesperW
    const unsigned char __attribute__((space(prog),aligned(_FLASH_PAGE*2))) config_Data[_FLASH_PAGE*2];

     
    "const" is enough to place config_Data in flash rather than RAM. 
     
    const unsigned char __attribute__((aligned(_FLASH_PAGE*2))) config_Data[_FLASH_PAGE*2];

    #5
    JesperW
    Starting Member
    • Total Posts : 80
    • Reward points : 0
    • Joined: 2009/04/27 10:49:24
    • Location: Sweden
    • Status: offline
    RE: Inappropriate program address when using space(prog) pointer? 2010/03/29 10:51:31 (permalink)
    0
    ORIGINAL: cawilkie
    Understand what it means to qualify it with __prog__

    I'm trying wink !

    Two things:

    1. After some trial and error: With a declaration as per the original post, accessing config_Data with a statement like:


    unsigned char c = *config_Data; // triggers "Inapproproate program address", but
    unsigned char c = *(config_Data+1); // does not.


    2. You said: "cannot access anything in space(prog) using 'C'". OK, so I misunderstood __prog__. So what I want is space(auto_psv) ? Does it still work to _erase_flash and _write_flash16 in this case? What I'd like to accomplish if possible is make the flash data readable byte for byte but writeable using _write_flash16)
    #6
    aschen0866
    Super Member
    • Total Posts : 4496
    • Reward points : 0
    • Joined: 2006/01/08 22:18:32
    • Location: San Diego
    • Status: offline
    RE: Inappropriate program address when using space(prog) pointer? 2010/03/29 10:53:41 (permalink)
    0
    What you want is:

    const __prog__ unsigned char __attribute__((space(prog),aligned(_FLASH_PAGE*2))) config_Data[_FLASH_PAGE*2];
    #7
    JesperW
    Starting Member
    • Total Posts : 80
    • Reward points : 0
    • Joined: 2009/04/27 10:49:24
    • Location: Sweden
    • Status: offline
    RE: Inappropriate program address when using space(prog) pointer? 2010/03/29 11:07:50 (permalink)
    0
    Ah. I see. Thank you sir, most appreciated.

    :-D BTW this makes it my personal record for "longest declaration of a 1k byte array"!
    #8
    cawilkie
    Administrator
    • Total Posts : 1977
    • Reward points : 0
    • Joined: 2003/11/07 12:49:11
    • Status: offline
    RE: Inappropriate program address when using space(prog) pointer? 2010/03/29 11:15:29 (permalink)
    0

    ORIGINAL: JesperW

    ORIGINAL: cawilkie
    Understand what it means to qualify it with __prog__

    I'm trying wink !

    Two things:

    1. After some trial and error: With a declaration as per the original post, accessing config_Data with a statement like:


    unsigned char c = *config_Data; // triggers "Inapproproate program address", but
    unsigned char c = *(config_Data+1); // does not.


    2. You said: "cannot access anything in space(prog) using 'C'". OK, so I misunderstood __prog__. So what I want is space(auto_psv) ? Does it still work to _erase_flash and _write_flash16 in this case? What I'd like to accomplish if possible is make the flash data readable byte for byte but writeable using _write_flash16)



    I know that you are trying and I wasn't trying to slight you here. I was just pointing out that there are different methods of placing and accessing memory in FLASH and they all have their cost/benefit. It is important for you to choose the right one for you. aschen said 'what you want is ...' but I'm not convinced it is that easy. Chapter 6, which talks about the different access methods, may give you some idea of the costs/ benefits of different approaches.

    By far the easiest is to use space(auto_psv), but it depends upon how much psv you are using... You are obviously re-writing flash since you have properly aligned it and so on. If you only have a few access points then __prog__ might be good enough (even though it can be expensive in terms of code size). If you need it to be fast, then one of the library routines that copies memory out of FLASH might be best - did you know that there are library routines to read/ write FLASH? - just in case you are re-inventing wheels.

    The documentation isn't the most coherent here - its all there, just not always all in one place. Perhaps I'll write a FAQ sometime and summarize all of the different methods in one place. I think I have some time in 2012... :)

    *sigh*

    Regards
    Calum
    #9
    JesperW
    Starting Member
    • Total Posts : 80
    • Reward points : 0
    • Joined: 2009/04/27 10:49:24
    • Location: Sweden
    • Status: offline
    RE: Inappropriate program address when using space(prog) pointer? 2010/03/29 11:30:31 (permalink)
    0
    ORIGINAL: cawilkie
     If you need it to be fast, then one of the library routines that copies memory out of FLASH might be best - did you know that there are library routines to read/ write FLASH? - just in case you are re-inventing wheels.


    Yes I do. However at the moment I am RAM constrained. Reading the Flash page out to RAM means I need three 1kByte areas, two in RAM and one in Flash, for the same info. (One RAM area for the current version that is used, one for the newly downloaded version to be written to Flash).

    I am trying to get rid of the current version in RAM, since it is read only.

    Thanks for your clarifications about the performance implications!
    #10
    JesperW
    Starting Member
    • Total Posts : 80
    • Reward points : 0
    • Joined: 2009/04/27 10:49:24
    • Location: Sweden
    • Status: offline
    RE: Inappropriate program address when using space(prog) pointer? 2010/03/29 12:36:03 (permalink)
    0
    ORIGINAL: cawilkie
    The documentation isn't the most coherent here

    Once we are on this subject, the 16 bit Language Tool Libraries manual, example code at the end of section 4.7:

    The row

    p.next += (_FLASH_ROW * 2);  /* advance to next row */

    ...seems to be incorrect. There is no p.next.
    #11
    threedog
    Super Member
    • Total Posts : 998
    • Reward points : 0
    • Joined: 2009/12/04 12:28:11
    • Location: Boise
    • Status: offline
    RE: Inappropriate program address when using space(prog) pointer? 2010/03/29 13:40:04 (permalink)
    0
    ORIGINAL: aschen0866

    What you want is:

    const __prog__ unsigned char __attribute__((space(prog),aligned(_FLASH_PAGE*2))) config_Data[_FLASH_PAGE*2];


     
    I don't think so.  The extra attribute "__prog__" is not needed nor wanted since config_Data MUST be PSV visable.  I don't think the OP wants config_Data to crosses a PSV boundary.
     
     
    • __psv__ for accessing objects that do not cross a PSV boundary, such as those
    allocated in space(auto_psv) or space(psv)
    • __prog__ for accessing objects that may cross a PSV boundary, specifically
    those allocated in space(prog), but it may be applied to any object in Flash
    Typically there is no need to specify __psv__ or __prog__ for an object placed in

    space(auto_psv), though there is no reason why it could be not done.
     
    #12
    aschen0866
    Super Member
    • Total Posts : 4496
    • Reward points : 0
    • Joined: 2006/01/08 22:18:32
    • Location: San Diego
    • Status: offline
    RE: Inappropriate program address when using space(prog) pointer? 2010/03/29 14:41:47 (permalink)
    0

    ORIGINAL: cawilkie
    ...
    The documentation isn't the most coherent here - its all there, just not always all in one place. Perhaps I'll write a FAQ sometime and summarize all of the different methods in one place. I think I have some time in 2012... :)

    *sigh*

    Regards
    Calum

    Calum,
    Why don't you post those two articles you and Guy wrote for the MASTERs last year? They have "everything you always want to know about flash but were afraid to ask". :-)
    #13
    cawilkie
    Administrator
    • Total Posts : 1977
    • Reward points : 0
    • Joined: 2003/11/07 12:49:11
    • Status: offline
    RE: Inappropriate program address when using space(prog) pointer? 2010/03/29 15:17:46 (permalink)
    +3 (2)
    This old thing? I had forgotten about it...

    Regards
    Calum
    #14
    kalpak
    Super Member
    • Total Posts : 3265
    • Reward points : 0
    • Joined: 2004/03/12 23:01:40
    • Location: India
    • Status: offline
    RE: Inappropriate program address when using space(prog) pointer? 2010/03/29 18:08:04 (permalink)
    0
    pl make it a sticky post.
    #15
    JesperW
    Starting Member
    • Total Posts : 80
    • Reward points : 0
    • Joined: 2009/04/27 10:49:24
    • Location: Sweden
    • Status: offline
    RE: Inappropriate program address when using space(prog) pointer? 2010/03/29 23:02:54 (permalink)
    0
    ORIGINAL: cawilkie
    This old thing? I had forgotten about it...


    That was a gem of understandability compared to the manuals. Thanks for sharing!
    #16
    threedog
    Super Member
    • Total Posts : 998
    • Reward points : 0
    • Joined: 2009/12/04 12:28:11
    • Location: Boise
    • Status: offline
    RE: Inappropriate program address when using space(prog) pointer? 2010/03/30 08:30:59 (permalink)
    0
    ORIGINAL: JesperW

    unsigned char c = *config_Data; // triggers "Inapproproate program address", but
    unsigned char c = *(config_Data+1); // does not.



    This code just gives me shivers for some reason.  It's like an address trap just waiting to happen.
    why not create a structure of all your config data and just reference the structure members with polite C code.

    struct _Config_t {
    unsigned int member_int;  // automaticaly 16 bit aligned to prevent address traps, be carefull of type/member order to reduce sizeof()
    unsigned char member_char;
    };

    const struct _Config_t __attribute__((aligned(_FLASH_PAGE))) ConfigData;
    //the size = sizeof(struct _Config_t), so to force the size, use a union, left as an excersize for the reader

    unsigned int ia = ConfigData->member_int;
    unsigned char ca = ConfigData->member_char;
    ...
    post edited by threedog - 2010/03/30 08:45:07
    #17
    JesperW
    Starting Member
    • Total Posts : 80
    • Reward points : 0
    • Joined: 2009/04/27 10:49:24
    • Location: Sweden
    • Status: offline
    RE: Inappropriate program address when using space(prog) pointer? 2010/03/31 13:18:31 (permalink)
    0
    ORIGINAL: threedog
    why not create a structure of all your config data?


    Because the data is not structured?

    (it is a byte stream of unknown length but max 1kB)
    #18
    threedog
    Super Member
    • Total Posts : 998
    • Reward points : 0
    • Joined: 2009/12/04 12:28:11
    • Location: Boise
    • Status: offline
    RE: Inappropriate program address when using space(prog) pointer? 2010/03/31 16:51:40 (permalink)
    0
    Well, that finishes that.wink
     
    #19
    reinartm
    New Member
    • Total Posts : 21
    • Reward points : 0
    • Joined: 2010/04/30 03:42:03
    • Location: 0
    • Status: offline
    Re:Inappropriate program address when using space(prog) pointer? 2010/11/16 13:59:13 (permalink)
    0
    Hi All
     
    OK, I think O solved the problem!
     
    First, I had to work with an array instead of a matrix. This is declared as follows:
     
    int __prog__ Block11[] __attribute__ ((space(prog))) = {1,2,3,4........,5,6};
     
    It is a bit tricky to get you indexing right, as you have to keep in mind that every (in my case) 90 integers, will be new row!
     
    Then to access the data, you cannot acces it as a normal matrix, instead you have to use pointers.
     
    F11=*(Block11+index);
     
    Thanks for all your help! I now have the world magnetic model 2010 programmed into my PIC24FJ256GB106. This model filled my pic to 94%!!!
     
    kind regards
    #20
    Page: 12 > Showing page 1 of 2
    Jump to:
    © 2019 APG vNext Commercial Version 4.5