Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 4 of 4

Thread: Is there and alignment directive to align data on a 16-byte boundary?

  1. #1

    Is there and alignment directive to align data on a 16-byte boundary?

    Hey guys...

    Is there and alignment directive to align data on a 16-byte boundary?

    I'm working with a Teensy LC.
    I've successfully used PROGMEM to store a 16-byte array in program flash memory.
    Here is the code snippet of static global variable;

    Code:
    static const uint8_t PROGMEM SYNC_Table[16] = {0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F};
    I can open the .hex file in a text editor and see the data.
    I can also access the data in program.
    So everything is working just fine.
    My question is...is there some way to have the compiler start this array on a 16-byte border in the Flash Memory.

    The reason is...I want to hold a GUID Type ID...like a MAC address...or IP address.
    I also want the user to be able to go into the .hex file and modify the bytes.
    Having the array on a single line of the .hex file makes it easier to deal with.
    Of course the checksum at the end of the line has to be adjusted.

    To make things more foolproof, I can even write a program that gives the user a 16-byte field to enter a random number.
    The program would then open the .hex file and scan for the 16 occurrences of 0x3F in the proper columns...plug in the new number...and fix up the checksum.

    But if I can't get 16-byte alignment...that makes the task more difficult...but not impossible.
    I'd just have to deal with plugging the proper fragments in two lines.

    Any thoughts?

    Thanks!!!

  2. #2
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    20,576
    const uint8_t myarray[16] __attribute__((aligned(16)))

  3. #3
    Senior Member
    Join Date
    Nov 2012
    Posts
    1,155
    Try:
    Code:
    static const uint8_t PROGMEM SYNC_Table[16] __attribute__ ((aligned (16))) =
    Pete
    Paul beat me to it.

  4. #4
    YEAH!!!!
    WORK'S LIKE A CHAMP!!!!!
    Code:
    static const uint8_t PROGMEM SYNC_Table[16]__attribute__((aligned(16))) = 
    {0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F};
    When I look at the .HEX file it's aligned on the 16-byte boundry...

    THANKS GUYS!!!!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •