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.

MSPM0G1506: When writing data to the internal Flash ROM, if the data is set as a global variable, a HardFault interrupt occurs.

Part Number: MSPM0G1506
Other Parts Discussed in Thread: MSPM0G3507

Tool/software:

Hello. My name is Mori.

I am checking the writing of the internal Flash ROM, and a HardFault interrupt is occurring at "DL_FlashCTL_programMemoryFromRAM64WithECCGenerated".

However, if the storage destination for the write data of the third argument is set to a global variable,
a HardFault interrupt occurs, but if I set it to a local variable,
it does not occur and I am able to write the data.
Why does this happen?
I have attached the source code and the execution results.
Please check.

  • Hi,

    Your image is not clear, can you upload a new one?

  • Hi

    I have pasted the text as the source code.
    I have pasted the image as the execution result.
    Please check it.

    【SourceCode】

    #if __DEBUG_FLASH_WT
    static ErrLog_t stDmyLog; //←Global Variables
    #endif
    #if DEVELOP_MSP430_TO_MSPM0
    __attribute__((optnone))
    int main(void)
    #else
    void main(void)
    #endif
    {

    #if DEVELOP_MSP430_TO_MSPM0
    uchar bSysRequest;
    uchar bTskRequest;
    uchar bCnt;


    #if __DEBUG_FLASH_WT
    ErrLog_t atDmyLog; //←Local variables
    uint32_t qDistAdr = 0x00000800;
    uint32_t qSize = sizeof(ErrLog_t);

    uint32_t qWrtCnt;
    uint32_t qWrtAdr;
    uint32_t qSctAdr;
    volatile DL_FLASHCTL_COMMAND_STATUS stsCmdStatus;
    uint32_t *pqSrc;

    bArray_fill( (uchar*)&atDmyLog, 0xAA, (uchar)sizeof(ErrLog_t) );
    pqSrc = (uint32_t*)&atDmyLog; //←When writing data to a local variable

    bArray_fill( (uchar*)&stDmyLog, 0xAA, (uchar)sizeof(ErrLog_t) );
    pqSrc = (uint32_t*)&stDmyLog; //←When writing data to a global variable

    //erase
    qSctAdr = 0x00000800;
    CPUSS->CTL &= ~CPUSS_CTL_ICACHE_ENABLE;
    DL_FlashCTL_unprotectSector(FLASHCTL, qSctAdr, DL_FLASHCTL_REGION_SELECT_MAIN);
    stsCmdStatus = DL_FlashCTL_eraseMemoryFromRAM(FLASHCTL, qSctAdr, DL_FLASHCTL_COMMAND_SIZE_SECTOR);
    if (stsCmdStatus == DL_FLASHCTL_COMMAND_STATUS_FAILED)
    {
    ;;;
    }
    DL_FlashCTL_waitForCmdDone(FLASHCTL);
    CPUSS->CTL |= CPUSS_CTL_ICACHE_ENABLE;

    //program
    CPUSS->CTL &= ~CPUSS_CTL_ICACHE_ENABLE;
    for(qWrtCnt = 0; qWrtCnt < qSize; qWrtCnt+=8)
    {
    qWrtAdr = qDistAdr + qWrtCnt;
    DL_FlashCTL_unprotectSector(FLASHCTL, qSctAdr, DL_FLASHCTL_REGION_SELECT_MAIN);
    stsCmdStatus = DL_FlashCTL_programMemoryFromRAM64WithECCGenerated(FLASHCTL, qWrtAdr, (uint32_t*)pqSrc); //Addressing the write data (pqSrc)
    if (stsCmdStatus == DL_FLASHCTL_COMMAND_STATUS_FAILED)
    {
    ;;;
    }
    pqSrc += 2;
    }
    CPUSS->CTL |= CPUSS_CTL_ICACHE_ENABLE;
    while(1);
    #endif

  • Hi,

    Thanks for your detailed information.

    It seems interesting, I will do the test from my side tomorrow and give your feedback as soon as possible.

    Regards,

    Zoey

  • Hi,

    I have verified from my side. Both global variable and function internal variable can support to write into Flash.

    #include "ti_msp_dl_config.h"
    
    /* Address in main memory to write to */
    #define MAIN_BASE_ADDRESS (0x00000800)
    
    
    
    /* 32-bit data to write to flash */
    //uint32_t gData32 = 0x33333333;
    volatile DL_FLASHCTL_COMMAND_STATUS gCmdStatus;
    
    
    int main(void)
    {
        SYSCFG_DL_init();
        uint32_t gData32 = 0x33333333;
        uint32_t *pqSrc;
    
        pqSrc = (uint32_t*)&gData32;
    
        /* 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);
    
        DL_FlashCTL_unprotectSector(FLASHCTL, MAIN_BASE_ADDRESS, DL_FLASHCTL_REGION_SELECT_MAIN);
        gCmdStatus = DL_FlashCTL_programMemoryFromRAM32WithECCGenerated(FLASHCTL, (MAIN_BASE_ADDRESS), (uint32_t*)pqSrc);
        while(1);
    
    }

    Can you double check from your side according to my demo code

    Regards,

    Zoey

  • Or you can upload your simplified version of the project so that I can help you debug it quickly.

  • Hi

    Thank you for your reply.
    The model number of the microcontroller I checked was "MSPM0G3506T".
    I'm sorry.
    I'm sorry to trouble you, but could you please check it here as well?

  • Hi,

    It is the same, and my test MCU number is MSPM0G3507.

  • Hi

    I'm sorry. I was told that this issue does not occur there, so I investigated it again here.
    Currently, optimization is set to "-z",
    but I found that if I set it to "-0", the HardFault does not occur.
    I tried adding the volatile modifier to the global variable that stores the write data,
    but a HardFault occurred.
    When creating source code with optimization "-z",
    can you tell me if there is anything I should be careful of or if you know of any causes for the issue?

  • Hi,

    It seems strange, but I can not reproduce your phenomena from my side.

    Can you give a simplified code that can reproduce this?

    Regards,

    Zoey