This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

EEPROM emulation using FLASH - How to initialize variables

Expert 1570 points

Hi,

I followed successful the app note and the examples.

I have a struct with about ten fields of int, float etc for calibration data, which will be kept in flash.

I would like to have the possibility the initialize this struct when I first program the device using JTAG. This will be very helpful.

So I thought to use the CMD file, and somehow define the struct, the values and the location in that file, so the linker will recognize it and write it to flash when programing with JTAG.

Is that possible somehow ?

Thanks a lot

  • I don't see this being possible by only the linker command file.

    One possibility would be to write an assembly file with the data you want programmed in the specific locations. In our examples we do this with the Code Security Module Password (CSM) (the file is <device>_CSMPasswords.asm

    The code looks like this:

    .sect "csmpasswds"

    .int 0xFFFF ;PWL0 (LSW of 128-bit password)
    .int 0xFFFF ;PWL1
    .int 0xFFFF ;PWL2
    .int 0xFFFF ;PWL3
    .int 0xFFFF ;PWL4
    .int 0xFFFF ;PWL5
    .int 0xFFFF ;PWL6
    .int 0xFFFF ;PWL7 (MSW of 128-bit password)


    Then the csmpasswds section is mapped in the linker command file to the memory containing the password. In this case it would set them to all 0xFFFF which is the default password.

    The Compiler team may have other ideas on their E2E forum.

    Regards
    Lori
  • Hi Lori
    That's a good idea to place it in an .asm file.
    Is it possible to define a struct and then initialize it using this method ?
    Is it possible to use a ".float" ?

    Thanks
  • Yes. The assembly directives (.int, .float, etc...) are described in the Assembly Language Ref Guide for C2000.

    http://www.ti.com/lit/spru513

    Regards
    Lori
  • Hi Lori, (Sorry for the big picture above, I tried to insert it between the lines but was unsuccessful...)

    Ok, so this is what I tried to do:

    Defined a section in the cmd file:

    PAGE 1 :

    ....

    D_FLASHA    : origin = 0x3F6000, length = 0x001F7F

    SECTIONS
    {

    .....

    my_sec              : > D_FLASHA     PAGE = 1

    }


    Define an .asm file with the values:

        .sect "my_sec"

          .int    -1587        
          .uword  5342        
          .float  3.2567 

    Defined a .c file with the struct, with DATA_SECTION pragma:

    #pragma DATA_SECTION(struct1,"my_sec")

    typedef struct my_struct
    {
        int16    a;
        Uint16    c;
        float32    b;
    }my_struct;

    my_struct    struct1;

    So the Flash was initialized (I don't know why all the trailing zeros..maybe alignment issue...).

    And struct1 is of course not initialized correctly.

    But it's initialized with zeros... So something is happening there...

    Can you please advise what is wrong, and if this is the correct method to implement what I want ?

    Thanks a lot

  • The linker has allocated struct1 followed by your mysec data.  In order for them to overlap you need to use a UNION in the linker command file.

  • Hi Lori,
    Can you please post a code snippet of such a union definition?
    Thanks
  • There are some examples in www.ti.com/lit/spru513. Refer to 8.5.7.2 - Overlaying sections with the UNION statement .

    The compiler team may have other (better) suggestions for how to do this.
    e2e.ti.com/.../

    Regards
    Lori