Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
17 years ago

How to create and store data table in Flash

I want to create a few tables of data and store the tables and specific locations in off-chip Flash memory. The Linker would easily allow me to do this, but I am porting legacy code from long ago and it will be far easier for me if I can find a way to assign each table's starting address by doing so in my C code.

How can I do this?

Example tables:

char table_1[] = {0x11, 0x22, 0x33};

char table_2[] = {0xFF, 0xEE, 0xDD};

Now I want to assign the base address of table_1[] to 0x4B001000, and the base address of table_2[] to 0x4CD01000 (for example).

I know that I can get the base address of foo by using "base = &foo[0]", but how can I do the opposite (explicitly assign the base address)?

5 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Couldn't you just achieve the same thing by:

    char *table1 = 0x4B001000;
    char *table2 = 0x4CD01000;
    

    Jake
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    I thought I could use something like you suggest, but I get a "conflicting types" error:

    char table_1[] = {0x11, 0x22, 0x33};

    char *table_1 = 0x4B001000;

    >.....error: conflicting types for 'table_1'
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    You can have only one of those two lines. If you use the pointer with the address, you would have to program the values in the flash separately instead of defining the initial values in your code.

    You may be able to fix both the values and the addresses by using a custom linker script but it's not the easiest thing to do...
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Maybe it is simply not possible to do what I want to do in the way I was hoping.

    What is the "usual" way to assign memory addresses to data tables stored in flash? Is the Linker the "normal" way to do this?

    What I am ultimately after is to have one .c (or .h, or whatever) file that I can convert into on .hex file (or .srec, or whatever) that can then be programmed into a Flash device. I would like to assign specific address locations to specific constants in doing this.

    Is the Linker the only way to do this?

    Thanks for your help!
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Even if you specify to the compiler and linker that these tables reside in location corresponding to the flash, they're not going to automatically be programmed there for you. The best you could hope for is that the resulting ".flash" S-record file produced by the NIOS II tools would have this data in it.

    Program the flash locations separately. Then in your program, simply specify the address of the tables so that you can read them.

    Jake