This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Placing array tables in ARM flash?

I have some Const array tables that i want place in the flash/code memory of ARM controller. we can place array in code memory of C51 using "code" keyword. but how to place const array in ARM?

Parents
  • do i have to give address to all the arrays individually? Is there any way in which the compiler picks the address automatically?

    I have no idea why Tamir gave you this example. You didn't say that you wanted to place your data at a particular address, so it's safe to assume that you don't need the at attribute.
    All you need to do is declare your variables as const. This will put them in ROM. Compiler/linker will take care of assigning addresses, as usual.

Reply
  • do i have to give address to all the arrays individually? Is there any way in which the compiler picks the address automatically?

    I have no idea why Tamir gave you this example. You didn't say that you wanted to place your data at a particular address, so it's safe to assume that you don't need the at attribute.
    All you need to do is declare your variables as const. This will put them in ROM. Compiler/linker will take care of assigning addresses, as usual.

Children
  • Whew. I read the response and was wondering whether I was missing some important knowledge.

    Putting const puts the tables into a code segment. If the code is in flash, then so are the tables.

  • I wrote a small program to Test the keywords, here the results are

    with

    const unsigned char a[3] __attribute__( (at(0x0010) ) )={'1','2','3'};
    

    Result is:
    Program Size: Code=5126 RO-data=66 RW-data=16 ZI-data=560

    with

    const unsigned char a[3]={'1','2','3'};
    

    Result is:
    Program Size: Code=5130 RO-data=66 RW-data=16 ZI-data=560

    with

    unsigned char a[3]={'1','2','3'};
    

    Result:
    Program Size: Code=5130 RO-data=62 RW-data=20 ZI-data=556

    if both attribute keyword and const keyword do the same thing, then why there is the variation in Code size?

  • Because they do not "do the same thing"!

    They achieve the same end, but by doing different things!

    Look again at those numbers, carefully: it's not just the code size that changes, is it...?