• AVR Freaks

Hot!Is there a way in XC8 to align const data to a page/row?

Author
JPortici
Super Member
  • Total Posts : 1202
  • Reward points : 0
  • Joined: 2012/11/17 06:27:45
  • Location: Grappaland
  • Status: offline
2020/10/29 06:16:37 (permalink)
0

Is there a way in XC8 to align const data to a page/row?

i have non-volatile data that i want to be aligned to a page or row boundary, so i can read/write it with less hassle.
(It's a bunch of structures conveniently the same size of a row)
 
the data is declared as such
#define FLASHROWSIZE 32
 
typedef union {
  struct {
    uint8_t map0[FLASHROWSIZE];
    uint8_t map1[FLASHROWSIZE];
    uint8_t map2[FLASHROWSIZE];
    uint8_t map3[FLASHROWSIZE];
    uint8_t map4[FLASHROWSIZE];
    uint8_t map5[FLASHROWSIZE];
    uint8_t map6[FLASHROWSIZE];
    uint8_t map7[FLASHROWSIZE];
    uint8_t map8[FLASHROWSIZE];
    uint8_t map9[FLASHROWSIZE];
  } maps;
  uint8_t map[10][FLASHROWSIZE];
} mapArray_t;
 
const mapArray_t mapArray

 
of course, it's placed at an odd address.
 
In order for it to be aligned, the only way i found is to place it at a specific address using the __at/address attribute, or by placing it in a section and defining the section address in the linker options.
However, i don't like using absolute addresses. The XC8 linker start doing funny stuff in program placement and if there is not A LOT of memory available, compilation fail due to internal limitation of the linker is around the corner (see my previous threads about trying and failing to use the SAF in a bootloader)
 
even if not documented, the compiler recognizes the alignment(n) attribute, complains if the argument is not a power of two but it will not align data in flash.
 
So automatic allocation would be best, but with alignment. Is there another solution? Like, can i define a section and specify its alignment?
#1

10 Replies Related Threads

    1and0
    Access is Denied
    • Total Posts : 11501
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: Is there a way in XC8 to align const data to a page/row? 2020/10/29 09:28:44 (permalink)
    0
    Jack_M
    i have non-volatile data that i want to be aligned to a page or row boundary, so i can read/write it with less hassle.
    (It's a bunch of structures conveniently the same size of a row)
     
    the data is declared as such
    #define FLASHROWSIZE 32
     
    typedef union {
      struct {
        uint8_t map0[FLASHROWSIZE];
        uint8_t map1[FLASHROWSIZE];
        uint8_t map2[FLASHROWSIZE];
        uint8_t map3[FLASHROWSIZE];
        uint8_t map4[FLASHROWSIZE];
        uint8_t map5[FLASHROWSIZE];
        uint8_t map6[FLASHROWSIZE];
        uint8_t map7[FLASHROWSIZE];
        uint8_t map8[FLASHROWSIZE];
        uint8_t map9[FLASHROWSIZE];
      } maps;
      uint8_t map[10][FLASHROWSIZE];
    } mapArray_t;
     
    const mapArray_t mapArray

    ...
    So automatic allocation would be best, but with alignment. Is there another solution? Like, can i define a section and specify its alignment?

    Give this a try:

    asm("psect MyMap,reloc="___mkstr(FLASHROWSIZE));
    const mapArray_t __section("MyMap") mapArray;

    #2
    NKurzman
    A Guy on the Net
    • Total Posts : 19023
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: offline
    Re: Is there a way in XC8 to align const data to a page/row? 2020/10/29 11:15:07 (permalink)
    +1 (1)
    In the Compiler manual
     
    2.5.8 Alignment of Objects
     
    Assuming they implemented it.  
    #3
    1and0
    Access is Denied
    • Total Posts : 11501
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: Is there a way in XC8 to align const data to a page/row? 2020/10/29 19:47:50 (permalink)
    -1 (1)
    NKurzman
    In the Compiler manual
     
    2.5.8 Alignment of Objects
     
    Assuming they implemented it.  

    2.5.8.4 CAVEATS

    This feature is not yet implemented on MPLAB XC8.
    #4
    NKurzman
    A Guy on the Net
    • Total Posts : 19023
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: offline
    Re: Is there a way in XC8 to align const data to a page/row? 2020/10/29 19:50:15 (permalink)
    0
    I was not sure if they added I do not have a 2.XX version installed.
    They have been putting it off for a while now.
    #5
    1and0
    Access is Denied
    • Total Posts : 11501
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: Is there a way in XC8 to align const data to a page/row? 2020/10/29 20:09:00 (permalink)
    0
    NKurzman
    I was not sure if they added I do not have a 2.XX version installed.
    They have been putting it off for a while now.

    That was quoted from the XC8 v2.30 Legacy User's Guide, which also states "An alignment feature has never been implemented on 8-bit compilers."
     
    There is NO "Alignment of Objects" section in the regular XC8 User's Guide.
     
    Just now tested it with v2.30 and got this
    warning: unsupported: the __align() attribute is not used by this compiler

    #6
    JPortici
    Super Member
    • Total Posts : 1202
    • Reward points : 0
    • Joined: 2012/11/17 06:27:45
    • Location: Grappaland
    • Status: offline
    Re: Is there a way in XC8 to align const data to a page/row? 2020/10/30 02:23:51 (permalink)
    -1 (1)
    1and0
    There is NO "Alignment of Objects" section in the regular XC8 User's Guide.



    And no index, and partial "Table of content" and a bunch of stuff missing since 2.20 user guides
    But at least pretty new graphics :)
     

    Just now tested it with v2.30 and got this
    warning: unsupported: the __align() attribute is not used by this compiler


    weird, didn't happen to me. I get a lot of new obvious warning that i can't suppress (should i really cast all assignments to 8 bit variables?) but i didn't see that.
    In any case, it confirms that __align is not implemented.
    Will test your proposed solution and report back
    #7
    ric
    Super Member
    • Total Posts : 28941
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: offline
    Re: Is there a way in XC8 to align const data to a page/row? 2020/10/30 02:33:48 (permalink)
    0
    You're probably on C99 mode, and he was using C90

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #8
    1and0
    Access is Denied
    • Total Posts : 11501
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: Is there a way in XC8 to align const data to a page/row? 2020/10/30 03:36:40 (permalink)
    +1 (1)
    The __align() attribute is not supported in both C90 and C99 modes.  I don't understand why they put XC16 and XC32 stuffs in the XC8 User's Guide. :(
     
    #9
    mad_c
    Super Member
    • Total Posts : 1266
    • Reward points : 0
    • Joined: 2010/12/12 17:48:27
    • Location: Brisbane, Australia
    • Status: offline
    Re: Is there a way in XC8 to align const data to a page/row? 2020/11/01 13:59:07 (permalink)
    0
    1and0
    The __align() attribute is not supported in both C90 and C99 modes.  I don't understand why they put XC16 and XC32 stuffs in the XC8 User's Guide. :(

    Hi,
     
    __align() in only mentioned in the CCI section of the legacy guide. CCI is like a language extension that makes code more portable across all XC compilers (hence why XC16/32 stuff is in that guide). It's just that for this particular keyword, XC8 will accept the syntax but it will have no effect.
     
    There is no easy way to have objects aligned. You could try placing each C object in a user-defined section and then override the reloc (alignment) flag of that section, as described here, or simply link the section at an aligned address. Alternatively, the objects could be defined in assembly code (see the ALIGN directive), but that is generally not advisable for C programs.
     
    Jeff.
    #10
    oliverb
    Super Member
    • Total Posts : 342
    • Reward points : 0
    • Joined: 2009/02/16 13:12:38
    • Location: 0
    • Status: offline
    Re: Is there a way in XC8 to align const data to a page/row? 2020/11/02 05:04:03 (permalink)
    -1 (1)
    FWIW XC8 doesn't even word-align. I had some sample code that produced a binary that started on an odd address!
    This breaks programming tools that assume PIC hex files will only ever contain even addresses.
    #11
    Jump to:
    © 2020 APG vNext Commercial Version 4.5