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.

CCS/MSP432P401R: How to Unlock Flash Information Memory sector (TLV)

Part Number: MSP432P401R

Tool/software: Code Composer Studio

Hello

I'm using custom board with MSP432 MCU on it.

As datasheet I've seen, It looks like that I'm able to program some data(variable) on Flash Information Memory.

I'm trying to write some data on it but it doesn't work.

Questions:

1. Is it possible to write some variable in the region of Flash Information Memory(0x0020_0000 ~ 0x0020_3FFF)?

2. If possible, does this piece of data are stored when the power off?

3. If it doesn't, is there anyway to store some data(variable) which can be changed but should be stored when the power off?

Here is my code of trying

----------------------------------------------------------------------------------------------------------------

//write flash
  FlashCtl_enableWordProgramming(FLASH_COLLATED_WRITE_MODE);
  FlashCtl_unprotectSector(FLASH_MAIN_MEMORY_SPACE_BANK0,0xFFFFFFFF);
  FlashCtl_unprotectSector(FLASH_MAIN_MEMORY_SPACE_BANK1,0xFFFFFFFF);
  FlashCtl_unprotectSector(FLASH_INFO_MEMORY_SPACE_BANK0,FLASH_SECTOR0 | FLASH_SECTOR1);
  FlashCtl_unprotectSector(FLASH_INFO_MEMORY_SPACE_BANK1,FLASH_SECTOR0 | FLASH_SECTOR1);
  uint32_t* flash_ptr;
  flash_ptr = (int*)0x0020102C;
  *flash_ptr = c_address[0];
  flash_ptr = (int*)0x0020102D;
  *flash_ptr = c_address[1];
  flash_ptr = (int*)0x0020102E;
  *flash_ptr = c_address[2];
  FlashCtl_protectSector(FLASH_MAIN_MEMORY_SPACE_BANK0,0xFFFFFFFF);
  FlashCtl_protectSector(FLASH_MAIN_MEMORY_SPACE_BANK1,0xFFFFFFFF);
  FlashCtl_protectSector(FLASH_INFO_MEMORY_SPACE_BANK0,FLASH_SECTOR0 | FLASH_SECTOR1);
  FlashCtl_protectSector(FLASH_INFO_MEMORY_SPACE_BANK1,FLASH_SECTOR0 | FLASH_SECTOR1);
  FlashCtl_disableWordProgramming();

 ----------------------------------------------------------------------------------------------------------------

//read flash

   tempp = (int*)0x0020102C;
   temp[0] = *tempp;
   tempp = (int*)0x0020102D;
   temp[1] = *tempp;
   tempp = (int*)0x0020102E;
   temp[2] = *tempp;
----------------------------------------------------------------------------------------------------------------
//Linker Command 
MEMORY
{
    MAIN       (RWX) : origin = 0x00000000, length = 0x00040000
    INFO       (RWX) : origin = 0x00200000, length = 0x00004000       //cheanged to RWX in order to write
    SRAM_CODE  (RWX): origin = 0x01000000, length = 0x00010000
    SRAM_DATA  (RW) : origin = 0x20000000, length = 0x00010000
}
/* The following command line options are set as part of the CCS project.    */
/* If you are building using the command line, or for some reason want to    */
/* define them here, you can uncomment and modify these lines as needed.     */
/* If you are using CCS for building, it is probably better to make any such */
/* modifications in your CCS project and leave this file alone.              */
/*                                                                           */
/* A heap size of 1024 bytes is recommended when you plan to use printf()    */
/* for debug output to the console window.                                   */
/*                                                                           */
/* --heap_size=1024                                                          */
/* --stack_size=512                                                          */
/* --library=rtsv7M4_T_le_eabi.lib                                           */
/* Section allocation in memory */
SECTIONS
{
    .intvecs    : > 0x00000000
    .text       : > MAIN
    .const      : > MAIN
    .constdata  : > MAIN
    .cinit      : > MAIN
    .pinit      : > MAIN
    .init_array : > MAIN
    *           : > MAIN
    .sysmem : > INFO
    .flashMailbox : > 0x00200000
    .vtable :   > 0x20000000
    .data   :   > SRAM_DATA
    .bss    :   > SRAM_DATA
    .sysmem :   > SRAM_DATA
    .stack  :   > SRAM_DATA (HIGH)
}
/* Symbolic definition of the WDTCTL register for RTS */
WDTCTL_SYM = 0x4000480C;
----------------------------------------------------------------------------------------------------------------

bests regards

Sae Won Park

  • Hello,

    I'm going to start looking into this, but it might take me a couple of days to give a response.  You should expect to hear back from me be Friday, though.

  • Hello Sae Won Park,

      Let me try to answer your questions:

    Park Sae Won said:
    1. Is it possible to write some variable in the region of Flash Information Memory(0x0020_0000 ~ 0x0020_3FFF)?

    Yes it is possible (except for the TLV sector), but I would not recommended. This region consist of four sectors and it contains pre-programmed data.

    So please use a different section of flash (MAIN flash) and let us know if you need any help setting this up.

    Park Sae Won said:
    2. If possible, does this piece of data are stored when the power off?

    All the data that was stored in flash will be preserved after a power off.

    Hopefully this helps.

      David

  • Thank you for the answer.

    I need more help.

    As I wrote code after my question, it doesn't work when I'm writing on it.

    When I write some data on it, it doesn't change.

    How can I get it changed?

    And also could you suggest me where (the address) to write?

    Thanks.

    Sae Won Park
  • Additionally, when I write anywhere in SRAM_DATA (RW) : origin = 0x20000000, length = 0x00010000, it changes but is gone when power off.
  • Sae Won Park,

    Will you take a look at this post?  I modified some code using it as a learning base and it worked pretty well for me.

    I recommend using the MAIN MEMORY for this.

    The code I modified basically adds one to var1 stored in MAIN BANK 1, SECTOR 31 every time the device is reset. I will place the code below.  Entering debug on CCS erases MAIN MEMORY, so you should go to project properties->debug->MSP432 Settings.  Then change erase configurations to "Erase and download necessary segments only" if you intend to use the debugger memory browser as verification that you are storing and keeping the values in flash.  I started with this example.  I changed both the .cmd and .c files to make this work.

    Modified .cmd file:

    /******************************************************************************

    *

    * Copyright (C) 2012 - 2016 Texas Instruments Incorporated - http://www.ti.com/

    *

    * Redistribution and use in source and binary forms, with or without

    * modification, are permitted provided that the following conditions

    * are met:

    *

    * Redistributions of source code must retain the above copyright

    * notice, this list of conditions and the following disclaimer.

    *

    * Redistributions in binary form must reproduce the above copyright

    * notice, this list of conditions and the following disclaimer in the

    * documentation and/or other materials provided with the

    * distribution.

    *

    * Neither the name of Texas Instruments Incorporated nor the names of

    * its contributors may be used to endorse or promote products derived

    * from this software without specific prior written permission.

    *

    * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS

    * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT

    * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR

    * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT

    * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,

    * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT

    * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,

    * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY

    * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT

    * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE

    * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

    *

    * Default linker command file for Texas Instruments MSP432P401R

    *

    * File creation date: 2016-06-29

    *

    *****************************************************************************/

    --retain=flashMailbox

    MEMORY

    {

    MAIN (RX) : origin = 0x00000000, length = 0x0003F000

    MYDATA (RX) : origin = 0x0003F000, length = 0x00001000

    INFO (RX) : origin = 0x00200000, length = 0x00004000

    #ifdef __TI_COMPILER_VERSION__

    #if __TI_COMPILER_VERSION__ >= 15009000

    ALIAS

    {

    SRAM_CODE (RWX): origin = 0x01000000

    SRAM_DATA (RW) : origin = 0x20000000

    } length = 0x00010000

    #else

    /* Hint: If the user wants to use ram functions, please observe that SRAM_CODE */

    /* and SRAM_DATA memory areas are overlapping. You need to take measures to separate */

    /* data from code in RAM. This is only valid for Compiler version earlier than 15.09.0.STS.*/

    SRAM_CODE (RWX): origin = 0x01000000, length = 0x00010000

    SRAM_DATA (RW) : origin = 0x20000000, length = 0x00010000

    #endif

    #endif

    }

    /* The following command line options are set as part of the CCS project. */

    /* If you are building using the command line, or for some reason want to */

    /* define them here, you can uncomment and modify these lines as needed. */

    /* If you are using CCS for building, it is probably better to make any such */

    /* modifications in your CCS project and leave this file alone. */

    /* */

    /* A heap size of 1024 bytes is recommended when you plan to use printf() */

    /* for debug output to the console window. */

    /* */

    /* --heap_size=1024 */

    /* --stack_size=512 */

    /* --library=rtsv7M4_T_le_eabi.lib */

    /* Section allocation in memory */

    SECTIONS

    {

    .intvecs: > 0x00000000

    .text : > MAIN

    .const : > MAIN

    .cinit : > MAIN

    .pinit : > MAIN

    .init_array : > MAIN

    .mydata : {} > MYDATA

    .binit : {} > MAIN

    /* The following sections show the usage of the INFO flash memory */

    /* INFO flash memory is intended to be used for the following */

    /* device specific purposes: */

    /* Flash mailbox for device security operations */

    .flashMailbox : > 0x00200000

    /* TLV table for device identification and characterization */

    .tlvTable : > 0x00201000

    /* BSL area for device bootstrap loader */

    .bslArea : > 0x00202000

    .vtable : > 0x20000000

    .data : > SRAM_DATA

    .bss : > SRAM_DATA

    .sysmem : > SRAM_DATA

    .stack : > SRAM_DATA (HIGH)

    #ifdef __TI_COMPILER_VERSION__

    #if __TI_COMPILER_VERSION__ >= 15009000

    .TI.ramfunc : {} load=MAIN, run=SRAM_CODE, table(BINIT)

    #endif

    #endif

    }

    /* Symbolic definition of the WDTCTL register for RTS */

    WDTCTL_SYM = 0x4000480C;

    Modified .c file:

    /*
     * -------------------------------------------
     *    MSP432 DriverLib - v3_50_00_02 
     * -------------------------------------------
     *
     * --COPYRIGHT--,BSD,BSD
     * Copyright (c) 2016, Texas Instruments Incorporated
     * All rights reserved.
     *
     * Redistribution and use in source and binary forms, with or without
     * modification, are permitted provided that the following conditions
     * are met:
     *
     * *  Redistributions of source code must retain the above copyright
     *    notice, this list of conditions and the following disclaimer.
     *
     * *  Redistributions in binary form must reproduce the above copyright
     *    notice, this list of conditions and the following disclaimer in the
     *    documentation and/or other materials provided with the distribution.
     *
     * *  Neither the name of Texas Instruments Incorporated nor the names of
     *    its contributors may be used to endorse or promote products derived
     *    from this software without specific prior written permission.
     *
     * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
     * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
     * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
     * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
     * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
     * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
     * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     * --/COPYRIGHT--*/
    /*******************************************************************************
     * MSP432 Flash Controller - Programming Calibration Data
     *
     * Description: This example shows the use of the the Flash Controller APIs
     * to erase and program simulated calibration data to a specific area in memory.
     * Data in this example is programmed to user area of memory. The "fake"
     * calibration data is stored in a RAM array and set using the memset function,
     * however in a real application this buffer would be filled out using a serial
     * interface such as I2C.
     *
     *                MSP432P401
     *             ------------------
     *         /|\|                  |
     *          | |                  |
     *          --|RST               |
     *            |                  |
     *            |                  |
     *            |                  |
     *            |                  |
     *            |                  |
     *
     * Author: Timothy Logan (Modified by John Morrison for this E2E post)
     ******************************************************************************/
    /* DriverLib Includes */
    #include <ti/devices/msp432p4xx/driverlib/driverlib.h>
    
    /* Standard Includes */
    #include <stdint.h>
    
    #include <stdbool.h>
    #include <string.h>
    
    #define CALIBRATION_START 0x0003F000
    
    /* Statics */
    uint16_t simulatedCalibrationData[2048];
    
    /* pragmas to define the variables in flash */
    #pragma DATA_SECTION(var1, ".mydata");
    #pragma DATA_ALIGN(var1, 2);
    uint16_t var1, var1LOCAL = 0;
    
    int main(void)
    {
        var1LOCAL = var1;
        var1LOCAL++;
        /* Since this program has a huge buffer that simulates the calibration data,
         * halting the watch dog is done in the reset ISR to avoid a watchdog 
         * timeout during the zero 
         */
    
        /* Setting our MCLK to 48MHz for faster programming */
        MAP_PCM_setCoreVoltageLevel(PCM_VCORE1);
        FlashCtl_setWaitState(FLASH_BANK0, 2);
        FlashCtl_setWaitState(FLASH_BANK1, 2);
        MAP_CS_setDCOCenteredFrequency(CS_DCO_FREQUENCY_48);
    
        /* Initializing our buffer to a pattern of 0xA5 */
        memset(simulatedCalibrationData, 0xA5, 4096);
        simulatedCalibrationData[0] = var1LOCAL;
        
        /* Unprotecting Info Bank 0, Sector 0  */
        MAP_FlashCtl_unprotectSector(FLASH_MAIN_MEMORY_SPACE_BANK1,FLASH_SECTOR31);
    
        /* Trying to erase the sector. Within this function, the API will
            automatically try to erase the maximum number of tries. If it fails,
             trap in an infinite loop */
        if(!MAP_FlashCtl_eraseSector(CALIBRATION_START))
            while(1);
    
        /* Trying to program the memory. Within this function, the API will 
            automatically try to program the maximum number of tries. If it fails,
            trap inside an infinite loop */
        if(!MAP_FlashCtl_programMemory(simulatedCalibrationData,
                (void*) CALIBRATION_START, 4096))
                    while(1);
    
        /* Setting the sector back to protected  */
        MAP_FlashCtl_protectSector(FLASH_MAIN_MEMORY_SPACE_BANK1,FLASH_SECTOR31);
    
        /* Going to LPM3 when not in use */
        while (1)
        {
            MAP_PCM_gotoLPM3();
        }
    }
    

    Please let me know if this is helpful or if you need any further explanation of anything here.

  • Thank you so much.

    This works perfectly.

**Attention** This is a public forum