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.

location of static char array

Other Parts Discussed in Thread: MSP430F4794

Using TI compiler v4.4.2 for MSP430 the following declaration causes the string "current_directory to be placed in flash rather than RAM:

void open_file(FATFS *my_fs, DIR *dir_struct, FIL *filp)
{
    uint32_t temp_time;
    static uint32_t file_time;
    static char current_directory[9];
    struct tm *ltime;
    char dir_name[9];
    char filename[22]; // 8 chars + . + 3 + \ + dir_name + NUL
   

This did not happen in earlier versions of the compiler, 4.3.x I believe. BTW, the other arrays are located properly.

How do I fix this?

  • Moving the declaration outside the function, locates the string in flash, but I still belive that this is a bug.
  • I cannot build the example you show.  But when I build a simple example that includes a static char array, I see that array is always placed in the input section named .bss.  What happens after that depends on what is in your linker command file.  For more background on this process, please see this wiki article.

    Thanks and regards,

    -George

  • Correction: This comment should have read:
    Moving the declaration outside the function, locates the string in RAM, but I still belive that this is a bug.
    Not:Moving the declaration outside the function, locates the string in flash, but I still belive that this is a bug.
  • Please attach the linker command file you use to your next post.

    Thanks and regards,

    -George

  • /******************************************************************************/
    /* lnk_msp430f4794.cmd - LINKER COMMAND FILE FOR LINKING MSP430F4794 PROGRAMS */
    /* */
    /* Usage: lnk430 <obj files...> -o <out file> -m <map file> lnk.cmd */
    /* cl430 <src files...> -z -o <out file> -m <map file> lnk.cmd */
    /* */
    /*----------------------------------------------------------------------------*/
    /* These linker options are for command line linking only. For IDE linking, */
    /* you should set your linker options in Project Properties */
    /* -c LINK USING C CONVENTIONS */
    /* -stack 0x0100 SOFTWARE STACK SIZE */
    /* -heap 0x0100 HEAP AREA SIZE */
    /* */
    /*----------------------------------------------------------------------------*/


    /****************************************************************************/
    /* SPECIFY THE SYSTEM MEMORY MAP */
    /****************************************************************************/

    MEMORY
    {
    SFR : origin = 0x0000, length = 0x0010
    PERIPHERALS_8BIT : origin = 0x0010, length = 0x00F0
    PERIPHERALS_16BIT : origin = 0x0100, length = 0x0100
    RAM : origin = 0x0200, length = 0x0A00
    INFOA : origin = 0x10C0, length = 0x0040
    INFOB : origin = 0x1080, length = 0x0040
    INFOC : origin = 0x1040, length = 0x0040
    INFOD : origin = 0x1000, length = 0x0040
    FLASH1 : origin = 0x1100, length = 0x1100
    FLASH2 : origin = 0x2200, length = 0xDDE0
    INT00 : origin = 0xFFE0, length = 0x0002
    INT01 : origin = 0xFFE2, length = 0x0002
    INT02 : origin = 0xFFE4, length = 0x0002
    INT03 : origin = 0xFFE6, length = 0x0002
    INT04 : origin = 0xFFE8, length = 0x0002
    INT05 : origin = 0xFFEA, length = 0x0002
    INT06 : origin = 0xFFEC, length = 0x0002
    INT07 : origin = 0xFFEE, length = 0x0002
    INT08 : origin = 0xFFF0, length = 0x0002
    INT09 : origin = 0xFFF2, length = 0x0002
    INT10 : origin = 0xFFF4, length = 0x0002
    INT11 : origin = 0xFFF6, length = 0x0002
    INT12 : origin = 0xFFF8, length = 0x0002
    INT13 : origin = 0xFFFA, length = 0x0002
    INT14 : origin = 0xFFFC, length = 0x0002
    RESET : origin = 0xFFFE, length = 0x0002
    }

    /****************************************************************************/
    /* SPECIFY THE SECTIONS ALLOCATION INTO MEMORY */
    /****************************************************************************/

    SECTIONS
    {

    /* .data : {} > RAM GLOBAL & STATIC VARS */
    .sysmem : {} > RAM fill = 0xDEAD /* DYNAMIC MEMORY ALLOCATION AREA */
    /* .bss : {} > RAM /* GLOBAL & STATIC VARS */
    /* .TI.noinit : {} > RAM*/
    /* .TI.persistent : {} >RAM */
    GROUP : {
    .data
    .bss
    .TI.noinit
    .TI.persistent
    .RECEIVE_BUF
    .SAMPLE_BUF
    } > RAM

    .stack : {} > RAM (HIGH) fill = 0xCAFE /* SOFTWARE SYSTEM STACK */
    .RX_ISR : {} load = 0x1100
    .BSL : {} > FLASH1
    //.boot : {-l rts430_eabi.lib<boot.obj>(.text)} > FLASH1
    //.pi : {-l rts430_eabi.lib<pre_init.obj>(.text)} > FLASH1
    //.ai : {-l rts430_eabi.lib<autoinit.obj>(.text)} > FLASH1
    //.dc : {-l rts430_eabi.lib<copy_decompress_rle.obj>(.text)} > FLASH1
    //.ep : {-l rts430_eabi.lib<epilog.obj>(.text)} > FLASH1
    .USR_RX : {} load = 0x2200
    .APPL_CFG : {} > FLASH2 palign = 0x200
    .XAPPL_CFG : {} > FLASH2 palign = 0x200
    .XAPPL_CFG_CPY : {} > FLASH2 palign = 0x200
    .CFG_B : {} > FLASH2 palign = 0x200
    .BATTERY_TYPE : {} > FLASH2
    .STATIC_CFG : {} > FLASH2
    .TC_TABLE : {} > FLASH2
    .STATIC_INFO : {} > FLASH2 (HIGH)
    .text : {} > FLASH2 /* CODE */
    .cinit : {} > FLASH2 /* INITIALIZATION TABLES */
    .const : {} > FLASH2 /* CONSTANT DATA */
    .cio : {} > RAM /* C I/O BUFFER */

    .pinit : {} > FLASH2 /* C++ CONSTRUCTOR TABLES */
    .init_array : {} > FLASH2 /* C++ CONSTRUCTOR TABLES */
    .mspabi.exidx : {} > FLASH2 /* C++ CONSTRUCTOR TABLES */
    .mspabi.extab : {} > FLASH2 /* C++ CONSTRUCTOR TABLES */

    .TI.bound : {} > INFOA /* MSP430 INFO FLASH MEMORY SEGMENTS */
    .infoB : {} > INFOB
    .infoC : {} > INFOC
    .infoD : {} > INFOD

    /* MSP430 INTERRUPT VECTORS */
    BASICTIMER : { * ( .int00 ) } > INT00 type = VECT_INIT
    PORT2 : { * ( .int01 ) } > INT01 type = VECT_INIT
    USCIAB1TX : { * ( .int02 ) } > INT02 type = VECT_INIT
    USCIAB1RX : { * ( .int03 ) } > INT03 type = VECT_INIT
    PORT1 : { * ( .int04 ) } > INT04 type = VECT_INIT
    TIMERA1 : { * ( .int05 ) } > INT05 type = VECT_INIT
    TIMERA0 : { * ( .int06 ) } > INT06 type = VECT_INIT
    SD16A : { * ( .int07 ) } > INT07 type = VECT_INIT
    USCIAB0TX : { * ( .int08 ) } > INT08 type = VECT_INIT
    USCIAB0RX : { * ( .int09 ) } > INT09 type = VECT_INIT
    WDT : { * ( .int10 ) } > INT10 type = VECT_INIT
    COMPARATORA : { * ( .int11 ) } > INT11 type = VECT_INIT
    TIMERB1 : { * ( .int12 ) } > INT12 type = VECT_INIT
    TIMERB0 : { * ( .int13 ) } > INT13 type = VECT_INIT
    NMI : { * ( .int14 ) } > INT14 type = VECT_INIT
    .reset : {} > RESET /* MSP430 RESET VECTOR */
    }

    /****************************************************************************/
    /* INCLUDE PERIPHERALS MEMORY MAP */
    /****************************************************************************/

    -l msp430f4794.cmd
  • The small test case I wrote always put the static char array in the .bss section.  These lines from your linker command file ...

    Corky Benson said:
    GROUP : {
    .data
    .bss
    .TI.noinit
    .TI.persistent
    .RECEIVE_BUF
    .SAMPLE_BUF
    } > RAM

    ... mean the static char array will become part of the .bss output section created here.  This output section, in turn, is part of that GROUP.  And the GROUP is allocated to the RAM memory range.  

    Please attach the linker map file (with the extension .map) from one of your problem builds.  Use drag-n-drop from your file browser on to the forum post.  I also need to know the name of the source file which defines the static char array.  I'll look at the map file to see where the .bss section from that file is placed.

    Thanks and regards,

    -George

  • Corky Benson said:
    Using TI compiler v4.4.2 for MSP430 the following declaration causes the string "current_directory to be placed in flash rather than RAM

    How did you determine that the current_directory was placed in flash?

    E.g. there have been compiler bugs where the compiler generated incorrect debug information for static variables, such that the CCS debugger reported that variables were in flash when they were actually in RAM. See CCS 5.5 debugger shows incorrect address for C++ class given static storage allocation in main. The work-around for that problem (SDSCM00049324) is to build with compiler switch --common=off

  • Chester,

    The symptom was that this line of code failed to write to the string "current_directory". Using the debugger showed the string in flash rather than ram.

                    memcpy(current_directory,dir_name,sizeof(current_directory));

  • Chester,

    This does seem to be the situation. The map files looks like this:

    .bss       0    00000272    0000037b     UNINITIALIZED

                     00000272    0000022e     (.common:Generic_Buffer)

                     000004a0    00000024     (.common:rec_status)

                     000004c4    00000020     (.common:converted_alarm_value)

                     000004e4    00000020     (.common:converted_deadband_value)

                     00000504    00000012     (.common:lcd_data)

                     00000516    00000010     (.common:chanval)

                     00000526    00000010     (.common:samp)

                     00000536    00000010     (.common:samphi)

                     00000546    00000010     (.common:samplo)

                     00000556    00000010     (.common:samptot)

                     00000566    0000000c     (.common:timrwkg)

                     00000572    0000000a     (.common:current_directory$2)

                     0000057c    00000008     (.common:Internal_Measure)

    But the debugger shows this : OOPS the copy and paste from the debugger did not work, but trust me it showed the location in flash.