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.

How to write a variable to a specific flash address while programming

Other Parts Discussed in Thread: MSP430F2370

Hi

It should be an easy task to write a variable to a specific address in the flash area while programming in CCS. However it has caused me some problems - maybe some can point out what i'm doing wrong. In the main code I have written the following code just after the other variable declarations:

#pragma DATA_SECTION(TestVAR, ".infoC")
const unsigned char TestVAR = 0x41;

Before programming the MSP430F2370, the contents of infoC area (0x1040) is 0xFFFF. After programming where the program counter is waiting at the first line in the main rutine, the content of 0x1040 remain unchanged, which means the value it still 0xFFFF. Shoudn't the value have changed?

I'm using Code Composer Version: 5.5.0.00077 (16kb free edition)

Regards Henrik

 

  • Henrik,

    i think you need to explicitly enable the access to the INFO memory in the debug option. Go to "Project" -> "Properties" -> "Debug" -> "MSP430 Properties" as shown below.

  • Hi Leo

    Thanks for your answer - unfortunately it didn't help.

    I tried to follow your advise and change the setting to "Erase main and information memory", and programmed the MCU once again. But it didn't make any difference. The content at address us unchanged and has a value of 0xFFFF.

    /Henrik

  • Henrik Zimmermann said:
    Thanks for your answer - unfortunately it didn't help

    Did you check the symbol map to make sure that the variable really got placed in the correct segment by the linker tool?

  • Hi Brian

    Thanks for you reply to me problem.

    Yes, I have checked the linker file, which are defining the following memory areas of the flash:

    INFOA : origin = 0x10C0, length = 0x0040
    INFOB : origin = 0x1080, length = 0x0040
    INFOC : origin = 0x1040, length = 0x0040
    INFOD : origin = 0x1000, length = 0x0040

    So, it should be correct. Please let me know, if you have other suggestions.

    /Henrik

  • Henrik,

    have you referred to this wiki?

    http://processors.wiki.ti.com/index.php/Placing_Variables_in_Specific_Memory_Location_-_MSP430

    without any detail information such as project source code and linker command file, it is difficult to say where the problem is.

  • Hi Leo

    I would be happy to copy the entire source code, but it is long, and not related to the problem. In one of my previous replies, I copied the memory map of the MCU, and as you can see, the area of the flash called .infoC has the origin 0x1040 and length 0x0040.

    When I write the following code in the main.c file in the top during initialization of variables, I would expect the variable TestVAR would be placed in the flash at the position of infoC, and the value stored in the flash would be 0x41 (capital 'A' in ascii), when I program the MCU and afterwards look in the memory map.

    #pragma DATA_SECTION(TestVAR, ".infoC")
    const unsigned char TestVAR = 0x41;

    According to other forums, this should be the correct way of storing a value in flash at a specific location when you are using Code Composer Studio. But when I look at the memory map, the values of infoC is 0xFFFF, which indicates that the flash should be ready for writing values (all cells have the value of one), but no values are written.

    I have also tried a similar code for IAR even though I use CCS:

    #pragma location=0x1040
    const unsigned char TestVar = 0x41;

    How the #pragma is interpreted depends on the compiler, so I would not expect that the code for IAR would work in CCS, however it didn't give any compilation error either.

    Please let me know, if I can provide any information, that will shed some light on this problem.

    /Henrik

  • Hi Henrik,

    which device are you actually using? I might test it with a very simple program and let you know if it works.

    Anyway pragma location is also supported by CCS MSP430 compiler starting v4.x. For example refer to the latest User's Guide : http://www.ti.com/lit/ug/slau132h/slau132h.pdf - chapter 5.10.17

  • Have you tried having the tools output a TI-TXT format file (an ASCII hex style format) and looking at it in the code editor? You should see some lines with:

    @1040
    41 .. .. .. <- whatever other hex characters you have at that start address

    That will tell you if the tool is putting the data in the output file correctly. At least then you know it's either a code-generation problem (if the data isn't there) or a programming tool problem (if the data is there).

  • Hi Leo

    The device I'm using is a MSP430F2370. I would be very happy if you would try to make a simple program to see if it works:-)

    I have looked at the user guide you are referring to, and it seems that I'm following the explanation for "C" code...

    /Henrik

  • Hi Brian

    Thanks for your advice. I was not aware that you could get a TXT file in addition to the .out file.

    I have made the TXT file as you suggested, and now it starts to get interesting...

    The first line in the TXT file is starting with:

    @8000
    F2 F0 F0 00 29 00 F2 D0 0E 00 2A 00 3C 40 FA 00
    0D 43 B0 12 54 84 E2 D3 29 00 3C 40 E8 03 0D 43...

    If I understand this right, this means that nothing is written to the memory addresses below 0x8000, and this also explains why I don't see any change at the memory addresses in the flash (0x1040).

    Next question is, why is the compiler ignoring the "#pragma"?

    /Henrik

  • Henrik,

    i am getting a bit confused here. Are you writing the code in assembly or C?

    Anyway, have you tried to use the RETAIN pragma?

    http://processors.wiki.ti.com/index.php/Placing_Variables_in_Specific_Memory_Location_-_MSP430#Generating_JTAG_Lock

    If the variable is not used anywhere in the code, the compiler might not compile it in. Using RETAIN pragma will overcome this problem.

  • Leo Hendrawan TI said:
    If the variable is not used anywhere in the code, the compiler might not compile it in.

    And that is exactly where my suggestion to get a TI-TXT output file and look if the data is there comes into play....

    EDIT: Posted this before seeing Henrik's reply that he checked this already. Apologies.

  • Henrik Zimmermann said:

    @8000
    F2 F0 F0 00 29 00 F2 D0 0E 00 2A 00 3C 40 FA 00
    0D 43 B0 12 54 84 E2 D3 29 00 3C 40 E8 03 0D 43...

    If I understand this right, this means that nothing is written to the memory addresses below 0x8000, and this also explains why I don't see any change at the memory addresses in the flash (0x1040).

    Is the @8000 the only "@" directive in the TI-TXT file? If so then you are correct.

    I ask this only because I don't know if CCS requires programming segments to be in ascending order.

  • There is several "@" directives, but they are in ascending order, which means that the next directive is:

    @ffe0

    So nothing is written or changed at any addresses before 0x8000.

    /Henrik

  • Hopefully Leo can help you from here on out... I don't use CCS so I don't know the compiler-specific directives.

    However, for completeness, here is an example for those using IAR:

    #pragma segment="MyFlashSegment" __data16 2
    
    __root const unsigned int myFlashVar1 @ "MyFlashSegment" = 0x1234;
    __root const unsigned int myFlashVar2 @ "MyFlashSegment" = 0xCAFE;
    

  • Thanks to Leo and Brian I have now solved the problem.

    The correct code for writing to a specific memory address in flash using Code Composer Studio is:

    #pragma DATA_SECTION(TestVAR, ".infoC")
    const unsigned char TestVAR = 0x41;

    But as Brian pointed out, if it is not possible to see the a section starting with @1040 in TI-TXT outfile, it is a problem related to the compilation of the program. Here Leo came with the last clue:

    If the variable is not used anywhere in the code, the compiler might not compile it in.

    I had expected that the compiler would include the variable no matter what, if it was a part of a #pragma. But this turned out not to be the case (maybe due to the settings of the compiler).

    When using what is written above, and setting the erase options to: "Erase main and information memory" it works. Problem solved.

  • Glad to hear, it works for you now, Henrik.

**Attention** This is a public forum