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.

LP-MSPM0G3507: How can I over-write the flash memory data on the same address

Part Number: LP-MSPM0G3507

#include "ti_msp_dl_config.h"

/* Address in main memory to write to */
#define MAIN_BASE_ADDRESS (0x00010000)

/* 16-bit data to write to flash */
uint16_t gData16 = 0x2222;
uint16_t gData160 = 0x4444;

/* 32-bit data to write to flash */
uint32_t gData32 = 0x33333333;

/* Array to write 64-bits to flash */
uint32_t gDataArray64[] = {0xABCDEF00, 0x12345678};

/* 32-bit data array to write to flash */
uint32_t gDataArray32[] = {0x00000000, 0x11111111, 0x22222222, 0x33333333,
    0x4444, 0x55555, 0x66, 0x77, 0x8, 0x9};

/* 8-bit data to write to flash */
uint8_t gData80 = 0x11;
uint8_t gData81 = 0x03;
uint8_t gData82 = 0xFF;

volatile DL_FLASHCTL_COMMAND_STATUS gCmdStatus;

int main(void)
{
    SYSCFG_DL_init();
    /* Unprotect sector in main memory with ECC generated by hardware */
    DL_FlashCTL_unprotectSector(
        FLASHCTL, MAIN_BASE_ADDRESS, DL_FLASHCTL_REGION_SELECT_MAIN);
    /* Erase sector in main memory */
    gCmdStatus = DL_FlashCTL_eraseMemoryFromRAM(
        FLASHCTL, MAIN_BASE_ADDRESS, DL_FLASHCTL_COMMAND_SIZE_SECTOR);
    if (gCmdStatus == DL_FLASHCTL_COMMAND_STATUS_FAILED) {
        /* If command was not successful, set a breakpoint */
        __BKPT(0);
    }

    /* 8-bit write to flash in main memory */
    DL_FlashCTL_unprotectSector(
        FLASHCTL, MAIN_BASE_ADDRESS, DL_FLASHCTL_REGION_SELECT_MAIN);
    gCmdStatus = DL_FlashCTL_programMemoryFromRAM8WithECCGenerated(
        FLASHCTL, MAIN_BASE_ADDRESS, &gData80);
    if (gCmdStatus == DL_FLASHCTL_COMMAND_STATUS_FAILED) {
        /* If command was not successful, set a breakpoint */
        __BKPT(0);
    }

    DL_FlashCTL_unprotectSector(
        FLASHCTL, MAIN_BASE_ADDRESS, DL_FLASHCTL_REGION_SELECT_MAIN);
    gCmdStatus = DL_FlashCTL_programMemoryFromRAM8WithECCGenerated(
        FLASHCTL, MAIN_BASE_ADDRESS, &gData81);
    if (gCmdStatus == DL_FLASHCTL_COMMAND_STATUS_FAILED) {
        /* If command was not successful, set a breakpoint */
        __BKPT(0);
    }

    DL_FlashCTL_unprotectSector(
        FLASHCTL, MAIN_BASE_ADDRESS, DL_FLASHCTL_REGION_SELECT_MAIN);
    gCmdStatus = DL_FlashCTL_programMemoryFromRAM8WithECCGenerated(
        FLASHCTL, MAIN_BASE_ADDRESS, &gData82);
    if (gCmdStatus == DL_FLASHCTL_COMMAND_STATUS_FAILED) {
        /* If command was not successful, set a breakpoint */
        __BKPT(0);
    }

Hi, Gentleman.

I want to make program to  write data on the flash memory.

I refer the sample program in mspm0_sdk "flashctl_multiple_size_write", and add the "over-write different data program" on the same flash memory address.

This program shall write 8bit data 0x11, 0x03, 0xff on the flash memory 0x00010000, but it doesn't change after 1st byte '0x11' is written. (I expected memory data will change 11->03->ff)

How can I write program that I want. Please advice me.

  • Hi  shotaro,

    I am expected to update on next Monday. Thanks for your patience.

    B.R.

    Sal

  • Hi Shotaro,

    If you do NOT erase the flash area before you writing a data to a memory which already has data, then the final data will be wrong with the data you write. It will result that the data can NOT pass ECC, so the data will be overwriting.

    By the way, M0 device should erase at least one sector, which is shown in the code example.

    B.R.

    Sal

  • Hi, Sal-san

    Thank you for your advice. I want to change each 8 byte at random timing in one all sector area.

    As you mentioned, if M0 device should erase at least one sector, 

    1. save 1sector data to RAM

    2. unprotect 1sector flash

    3. erase 1sector flash

    4. change 8 byte data in RAM

    5. unprotect 1sector flash

    6. write 1sector data from RAM to flash

    7. repeat 1~6

    This is very boring.

    Isn't  there any scheme to "erase only 8byte flash word area"?

    Please advice.

     

  • Hi Shotaro,

    Sorry, there is no method to "erase only 8byte flash word area", it is the hardware limit.

    I will recommend you use EEPROM emulation for this application, which is included in SDK. It can modify 8-byte flash word, and used like EEPROM. If you go through it in code, it will automatically move to next flash area to update new data.

    The details can refer to following: https://www.ti.com/lit/pdf/slaaeb4

    B.R.

    Sal

  • Hi, Sal-san

    Thank you for good idea. I'll try this method.

    Kind regards

    shota