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.

MSP432P401R: flash erase hangs.

Part Number: MSP432P401R

I am using the msp432p401r bga in a custom design.  When I try to erase a 4K sector in the top part of the 1st bank the erase hangs.

I doing an erase of 0x0001e000, length 0x1000.  that is the 2nd to last sector of bank 0 for a size of 4096 (1 sector).

I am changing the protect bit in BANK0_MAIN_WEPROT to 0xbfffffff then calling MAP_FlashCtl_performMassErase() to do the erase.  But it hangs.  Note that the area being erased is already erased.  But it should still work.

Here is where it is hanging:

/* While the burst read hasn't finished */
while ((FLCTL->RDBRST_CTLSTAT & FLCTL_RDBRST_CTLSTAT_BRST_STAT_MASK)
!= FLCTL_RDBRST_CTLSTAT_BRST_STAT_3)
{
__no_operation();
}

this is from driverlib/flash.c

* -------------------------------------------
* MSP432 DriverLib - v3_21_00_05
* -------------------------------------------

here is the current settings (at the time the above loop is running):

POWER_STAT = 0x7c
RESERVED0 = {0x0, 0x0, 0x0}
BANK0_RDCTL = 0x43004
BANK1_RDCTL = 0x1000
RESERVED1 = {0x0, 0x0}
RDBRST_CTLSTAT = 0x30018
RDBRST_STARTADDR = 0x1e000
RDBRST_LEN = 0x1000
RESERVED2 = {0x0, 0x0, 0x0, 0x0}
RDBRST_FAILADDR = 0x0
RDBRST_FAILCNT = 0x0
RESERVED3 = {0x0, 0x0, 0x0}
PRG_CTLSTAT = 0xc
PRGBRST_CTLSTAT = 0xa0
PRGBRST_STARTADDR = 0x8fc0
RESERVED4 = 0x0
PRGBRST_DATA0_0 = 0xf1035380
PRGBRST_DATA0_1 = 0x681b030c
PRGBRST_DATA0_2 = 0xf5073301
PRGBRST_DATA0_3 = 0xf1025280
PRGBRST_DATA1_0 = 0x6013020c
PRGBRST_DATA1_1 = 0x5380f507
PRGBRST_DATA1_2 = 0x30cf103
PRGBRST_DATA1_3 = 0xf5b3681b
PRGBRST_DATA2_0 = 0xd3cb6f80
PRGBRST_DATA2_1 = 0x5780f507
PRGBRST_DATA2_2 = 0x46bd3710
PRGBRST_DATA2_3 = 0xbf00bd80
PRGBRST_DATA3_0 = 0xe000edf0
PRGBRST_DATA3_1 = 0xb084b580
PRGBRST_DATA3_2 = 0x6078af00
PRGBRST_DATA3_3 = 0x68786039
ERASE_CTLSTAT = 0x30002
ERASE_SECTADDR = 0x8000
RESERVED5 = {0x0, 0x0}
BANK0_INFO_WEPROT = 0x3
BANK0_MAIN_WEPROT = 0xbfffffff
RESERVED6 = {0x0, 0x0}
BANK1_INFO_WEPROT = 0x3
BANK1_MAIN_WEPROT = 0xffffffff
RESERVED7 = {0x0, 0x0}
BMRK_CTLSTAT = 0x0
BMRK_IFETCH = 0x0
BMRK_DREAD = 0x0
BMRK_CMP = 0x10000
RESERVED8 = {0x0, 0x0, 0x0, 0x0}
IFG = 0x21
IE = 0x0
CLRIFG = 0x0
SETIFG = 0x0
READ_TIMCTL = 0x64a037
READMARGIN_TIMCTL = 0x5a
PRGVER_TIMCTL = 0xa53f
ERSVER_TIMCTL = 0x32
LKGVER_TIMCTL = 0x5a
PROGRAM_TIMCTL = 0xa0002d0f
ERASE_TIMCTL = 0xa0afc80f
MASSERASE_TIMCTL = 0x1040
BURSTPRG_TIMCTL = 0x1e00

any idea why this is hanging?

  • when I single step the code. it works. So some kind of timing problem.
  • Eric,
    I do not see any obvious issues. Thank you for the additional information and I will see if I can recreate with a launchpad and the 80-pin package.

    Chris
  • thanks Chris,

    My main DCOCLK is 16MiHz (16777216 Hz). I suspect this may have something to do with it.

    how do you use a launchpad with the 80pin package? I thought the launchpad was 100pin only.

    Also I will try my code at 48MHz later tonight.

  • i have a launchpad and a separate custom board with the 80-pin package and will test each.

  • /* --COPYRIGHT--,BSD
     * Copyright (c) 2017, 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 - Mass Erase
     *
     * Description: This example shows the functionality of the mass erase API in
     * DriverLib. At the start of the example, flash bank 1 sectors 30 and 31 are
     * unprotected (0x3E000 - 0x3FFFF) and then programmed with filler data. Sector
     * 31 is then protected and a mass erase is performed. Since the mass erase
     * will only erase unprotected sectors, after the mass erase finishes only
     * the data in sector 30 will be erased (as can be observed through the memory
     * browser in the debugger).
     *
     *
     *
     * I am using the msp432p401r bga in a custom design.  When I try to erase a 4K
     * sector in the top part of the 1st bank the erase hangs. I doing an erase of
     * 0x0001e000, length 0x1000.  that is the 2nd to last sector of bank 0 for a
     * size of 4096 (1 sector). I am changing the protect bit in BANK0_MAIN_WEPROT
     *  to 0xbfffffff then calling MAP_FlashCtl_performMassErase() to do the erase.
     *  But it hangs.  Note that the area being erased is already erased.
     *  But it should still work.
     *
     * Here is where it is hanging:
     *
     * While the burst read hasn't finished
     *   while ((FLCTL->RDBRST_CTLSTAT & FLCTL_RDBRST_CTLSTAT_BRST_STAT_MASK)
     *   != FLCTL_RDBRST_CTLSTAT_BRST_STAT_3)
     *   {
     *       __no_operation();
     *   }
     *
     *   this is from driverlib/flash.c
     *
     *                MSP432P401
     *             ------------------
     *         /|\|                  |
     *          | |                  |
     *          --|RST               |
     *            |                  |
     *            |                  |
     *            |                  |
     *            |                  |
     *            |                  |
     *
     ******************************************************************************/
    /* DriverLib Includes */
    #include <ti/devices/msp432p4xx/driverlib/driverlib.h>
    
    /* Standard Includes */
    #include <stdint.h>
    #include <stdbool.h>
    #include <string.h>
    
    /*
     * Main Memory
     * 0x0000_0000 - 0x0004_0000
     *
     * The flash main memory on MSP432P401x MCUs can be up to 256KB. Flash main
     * memory consists of up to 64 sectors of 4KB each, with a minimum erase
     * granularity of 4KB (1 sector). The main memory can be viewed as two
     * independent identical banks of up to 128KB each, allowing simultaneous read
     * or execute from one bank while the other bank is undergoing a program or
     * erase operation.
     *
     * Block 0
     * 0x0000_0000 0x0001_FFFF
     *
     * Sector 30    1E000 - 1EFFF
     * Sector 31    1F000 - 1FFFF
     *
     * Block 1
     * 0x0002_0000 0x0003_FFFF
     *
     * Sector 30    3E000 - 3EFFF
     * Sector 31    3F000 - 3FFFF
     *
     */
    
    #define BANK1_S30 0x3E000
    #define BANK0_S30 0x1E000
    
    /* Statics */
    uint8_t patternArray[4096];
    
    int main(void)
    {
        /*
         * 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);
        MAP_FlashCtl_setWaitState(FLASH_BANK0, 1);
        MAP_FlashCtl_setWaitState(FLASH_BANK1, 1);
    //    MAP_CS_setDCOCenteredFrequency(CS_DCO_FREQUENCY_48);
    
        /*
         * Setting up clocks
         * MCLK = MCLK = 48MHz
         * SMCLK = MCLK/2 = 24Mhz
         * ACLK = REFO = 32Khz
         */
        MAP_CS_setDCOFrequency(16000000);
        MAP_CS_initClockSignal(CS_ACLK, CS_REFOCLK_SELECT, CS_CLOCK_DIVIDER_1);
        MAP_CS_initClockSignal(CS_SMCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_2);
        MAP_CS_initClockSignal(CS_MCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_1);
    
        /* Initializing our buffer to a pattern of 0xA5 */
        memset(patternArray, 0xA5, 4096);
        
        //![Simple Flash Config]
        //
        //
        /* Unprotecting User Bank 0, Sectors 30  */
        MAP_FlashCtl_unprotectSector(FLASH_MAIN_MEMORY_SPACE_BANK0,
                FLASH_SECTOR30);
    
        /*
         * I am changing the protect bit in BANK0_MAIN_WEPROT to 0xbfffffff then
         * calling MAP_FlashCtl_performMassErase() to do the erase.
         * 1011b ...... PROT30 is cleared
         */
    
        /* Trying a mass erase. Since we unprotected User Bank 0,
         * sector 30, this should erase these sectors. If it fails, we
         * trap inside an infinite loop.
         */
        if(!MAP_FlashCtl_performMassErase())
            while(1);
        //![Simple Flash Config]
        
        /* Trying to program the filler data. If it fails, trap inside an infinite
           loop */
        if(!MAP_FlashCtl_programMemory (patternArray, (void*) BANK0_S30, 4096))
            while(1);
    
        /* Setting  sector 31 back to protected  */
    //    MAP_FlashCtl_protectSector(FLASH_MAIN_MEMORY_SPACE_BANK1,FLASH_SECTOR31);
    
        /* Performing the mass erase again. Now, since we protected Sector31, only
         * Sector 30 (0x3E000 - 0x3EFFF) should be erased. Set a breakpoint
         * after this call to observe the memory in the debugger.
         */
    //    if(!MAP_FlashCtl_performMassErase())
    //        while(1);
    
        /* Deep Sleeping when not in use */
        while (1);
    //    {
    //        MAP_PCM_gotoLPM3();
    //    }
    }
    
    Eric,

    I still need to go through all of the register settings above, but I was able to run the attached code on both the 80-pin and 100-pin packages.  Please let me know if this is not representative of what you are doing, or if you are seeing different behavior with this code.

    Chris

  • are you running with driverlib in rom or in flash?

    my program when it hangs is using the driverlib api in flash. when I recompile to use driverlib in ROM it works correctly and doesn't hang.

    Here is where I found the reference that helped me figure out this issue...

    From the DriverLib manual.. (DriverLib User's Guide 4.10.01.00, Thu Aug 3 14:34:39 GMT+5 2017)

    Section 8.2, Flash Controller Limitations

    Furthermore, when using the FlashCtl APIs, the user must take special consideration of where the API is being executed. For the critical APIs (such as erase and program), the DriverLib APIs are required to be executed from either SRAM or ROM (using the ROM_ prefix). Due to the verification requirements of the flash controller, running these APIs out of Flash is not currently supported.


    This is the kind of warning that really should be in the Technical Reference Manual or in the device data sheet. In fact in the Technical Reference Manual it states:

    Section 8.2 Common Operations Using the Flash Controller

    Using MSP432 Driver Library for Flash Operations
    The MSP432 Driver Library allow the flash Module to be accessed through a simple and easy-to-use interface for a number of commonly used flash operations such as read, write and erase. TI recommends incorporating MSP432 Driver Library APIs for all flash operations to ensure safe execution of flash routines as per the required specification.
    A full listing of MSP432 Driver Library APIs is available in the MSP432 Driver Library MSP432P4xx User's Guide (see Chapter 8, Flash Memory Controller).



    So I've been using the published API and the published TI code. And it hangs when run from flash.

    I would recommend that you

    o update the TRM
    o put comments in the SDK code that at least warns you about running it out of FLASH.

    please.


    Yes I should have caught this but the warning is buryied deep in the DriverLib which I didn't go over in detail because I thought the TRM was the essential manual.

    It cost me a number of days trying to figure out what was going on.

    thanks,

**Attention** This is a public forum