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.

MSP-EXP432E401Y: #pragma DATA_SECTION(symbol, "section name") makes program execution hanged

Part Number: MSP-EXP432E401Y
Other Parts Discussed in Thread: SYSBIOS

Hi,

I import uartecho project into CCS and add some codes to test how to save data into flash area.

So I changed .cmd file as follows:

--stack_size=8192   /* C stack is also used for ISR stack */

HEAPSIZE = 0x20000;  /* Size of heap buffer used by HeapMem */

MEMORY
{
    FLASH (RX)  : origin = 0x00000000, length = 0x000FF000
    MYDATA (RW) : origin = 0x000FF000, length = 0x00001000
    SRAM (RWX)  : origin = 0x20000000, length = 0x00040000
}

/* Section allocation in memory */

SECTIONS
{
    .text   :   > FLASH
    .const  :   > FLASH
    .rodata :   > FLASH
    .cinit  :   > FLASH
    .init_array : > FLASH
    myvars      : {} > MYDATA

    .TI.ramfunc : {} load=FLASH, run=SRAM, table(BINIT)
    .data   :   > SRAM
    .bss    :   > SRAM
    .sysmem :   > SRAM

    /* Heap buffer used by HeapMem */
    .priheap   : {
        __primary_heap_start__ = .;
        . += HEAPSIZE;
        __primary_heap_end__ = .;
    } > SRAM align 8

    .stack  :   > SRAM (HIGH)
}

 Please note MYDATA and myvars.

I put following code snippet into uartecho.c:

/* pragmas to define the variables in flash */
#pragma DATA_SECTION(var1, "myvars");
#pragma RETAIN(var1)
uint32_t var1 = 125;
#pragma DATA_SECTION(var2, "myvars");
#pragma RETAIN(var2)
uint32_t var2 = 300;
 

I compiled the project and started debugging. Then I got following debugging session screen shot immediately.
Program run got into exit status and then hanged.

For testing purpose, I modified the attribute of variable var1 and var2 by adding const.

  const uint32_t var1 = 125;
  const uint32_t var2 = 300;

Then uartecho program runs well.

That means I can not change/modifiy the contents of specific location in flash.

How can I change contents of var1 and var2 defined in flash dynamically ?

Any tips/advises are appreciated in advance.

HaeSeung

  • Hi HasSeung,

    I think you need enable Flash Operation Function if you wolud like to write flash.

    You push some vars into flash, thus you have to enable flash write function before chaneg those vars.

    Thanks!

    Best Regards

    Johnson

  • Hi Johnson,

    I would like to ask 3 questions:
      1. if I define a variable, such as var1, with #pragma DATA_SECTION(var1, "myvars");,
          then do I HAVE TO define var1 as constant variable such as const uint32_t var1 = 100; ?
          If it is true, then why ?

      2. if I want to write some data in flash memory area, do I have to use FlashProgram() function?
          I want to write some data in flash, simply by assigning value to the variable var1. 

      3. Or following scheme is illegal mode ?:
           #pragma DATA_SECTION(var1, "myvars");
           uint32_t var1 = 100;

           then I change the contents of var1 using FlashProgram() function.
           If this is allowed, I can simply access the contents of flash with variable name, var1. 
           Is this procedure is not allowed ?

    Many thanks in advance and any tips appreciated.

    HaeSeung


           

  • Hi HaeSeung,

      1. if I define a variable, such as var1, with #pragma DATA_SECTION(var1, "myvars");,
          then do I HAVE TO define var1 as constant variable such as const uint32_t var1 = 100; ?
          If it is true, then why ?

    For Q1, you can define var1 to normal variable in flash, like uint32_t var1 = 100; this is OK, and if you define this variable into flash, this value ccan keep even if power cycle.

      2. if I want to write some data in flash memory area, do I have to use FlashProgram() function?
          I want to write some data in flash, simply by assigning value to the variable var1. 

    For Q2, yes, yo have to use FlashProgram() function to write some this variable if this var define in flash, beacuse the flash write default is disable.

    3. Or following scheme is illegal mode ?:
           #pragma DATA_SECTION(var1, "myvars");
           uint32_t var1 = 100;

           then I change the contents of var1 using FlashProgram() function.
           If this is allowed, I can simply access the contents of flash with variable name, var1. 
           Is this procedure is not allowed ?

    For Q3, contants variable is can't be changed.

    Thanks!

    Best Regards

    Johnson

  • Hi Johnson,

    I appreciate your answer about Q2 and Q3. Now I understand.

    About Q1, I followed your advice, but still have problem. My setups are as follows:

    In MSP_EXP432E401Y_TIRTOS.cmd:
      --stack_size=8192 /* C stack is also used for ISR stack */

      HEAPSIZE = 0x20000; /* Size of heap buffer used by HeapMem */

      MEMORY
      {
          FLASH (RX) : origin = 0x00000000, length = 0x000FF000
          MYDATA (RWX) : origin = 0x000FF000, length = 0x00001000
          SRAM (RWX) : origin = 0x20000000, length = 0x00040000
      }

      /* Section allocation in memory */

      SECTIONS
      {
          .text : > FLASH
          .const : > FLASH
          .rodata : > FLASH
          .cinit : > FLASH
          .pinit  :  > FLASH

          .init_array : > FLASH
          myvars : {} > MYDATA

          .TI.ramfunc : {} load=FLASH, run=SRAM, table(BINIT)
          .data : > SRAM
          .bss : > SRAM
          .sysmem : > SRAM

          /* Heap buffer used by HeapMem */
          .priheap : {
              __primary_heap_start__ = .;
              . += HEAPSIZE;
              __primary_heap_end__ = .;
      } > SRAM align 8

          .stack : > SRAM (HIGH)
      }

     In uartecho.c, I put following codes below the  #include file statements:
      #pragma DATA_SECTION(var1, "myvars");
      uint32_t var1 = 100;
      #pragma DATA_SECTION(var2, "myvars");
      uint32_t var2 = 200; 

    Compilation is OK.

    Start its debugging, then immediately program execution goes into exit(). 

    I attach its screenshot:

    Debug view:

    Console view:
      

    Source view:


    Its operation is very unexpectable.

    Error message in Console view said: 
         ti.sysbios.family.arm.m3.Hwi: line 1259: E_busFault: PRECISERR: Immediate Bus Fault, exact addr known, address: 000ff000
         Exception occurred in background thread at PC = 0x00007ab6.

    Is there anything that I miss in setting up the configuration or in C program ?

    Thank you very much

    HaeSeung

  • You might like to look at the nvsinternal_MSP_EXP432E401Y sample project.

    The NVS section in the config file lets you define the address and size of a block on FLASH to use as mon volatile storage, then the code shows how to use access functions to read and write it. It takes care of the cmd file/ linker settings.

    I wrapped all my config in a struct and put that in another struct with a checksum (see the CRC sample). I then read or write a copy of my config between the FLASH storage and a local RAM copy. Edit RAM copy and save to FLASH with access fn when required.

     NVS_write(nvsHandle, 0, (void *) &TheProtectedConfigData, sizeof(protectedConfigData), NVS_WRITE_ERASE | NVS_WRITE_POST_VERIFY);
    Display_printf(display, 0, 0, "Default config data written with crc %x.", TheProtectedConfigData.TheChecksum);