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.

MSP432 - Trying to Erase the Sector 0 Bank 0 before Writing to it but CPU gets halted somewhere.

Hello,

Sorry for reposting this. In the last post I was told to use the library but unfortunately it is blocking resources so I cannot use that. 

I want to write some information on the Sector 0 of Bank 0 in the main memory. Before writing I am erasing the sector but some how the CPU gets halted somewhere in the erase method.

void FlashCtl::EraseSect()
{
    FLCTL->BANK0_MAIN_WEPROT    &= ~(FLCTL_BANK0_MAIN_WEPROT_PROT0);                                             // Write/Erase Unprotect
    FLCTL->ERASE_SECTADDR         = 0x00000000 ;                                                                                         // Sector Address
    FLCTL->ERASE_CTLSTAT        |= FLCTL_ERASE_CTLSTAT_START;                                                                    // Start Erase Operation
    while((FLCTL->ERASE_CTLSTAT & FLCTL_ERASE_CTLSTAT_STATUS_3) != FLCTL_ERASE_CTLSTAT_STATUS_3) // Erase Completion Status
    {
        __no_operation();
    }
    FLCTL->ERASE_CTLSTAT        |= FLCTL_ERASE_CTLSTAT_ADDR_ERR;
    FLCTL->BANK0_MAIN_WEPROT    |= FLCTL_BANK0_MAIN_WEPROT_PROT0;   
}

  • Do you know where in Flash the Linker puts your code?

    Do you know if Sector 0 of Bank 0 is not being used?
  • Hello Prem,

    The flash controller for MSP432 is somewhat complex in that it requires multiple pulses, changing read modes, and potential bit masking for each erase operation. There are also some restrictions of programming/erasing out of the same bank that you are executing which add to this complexity.

    Applying only one erase pulse as in the case of your code is no guarantee that the erase will occur successfully.  For this reason, it is highly recommended that you use the ROM_FlashCtl_eraseSector and ROM_FlashCtl_performMassErase functions which are included in ROM code in every device. These APIs have been verified, validated, and take care of all of the requirements set forth in the technical reference manual. Furthermore, as they are located in ROM, there is very little code space overhead that is introduced. The peripheral driver library can be found at the following URL:

    If you are still wanting to write your own flash driver, I would recommend taking a look at section 8.3 of the MSP432 Technical Reference Manual. This section describes in detail the programming flow of writing your own flash driver.

    Additionally the DriverLib code that I referenced is open source with a BSD license, so there are very little restrictions on taking the code underneath those examples and modifying them to fit your individual application needs.

    Best Regards,
    Tim

  • 1) From 0x00000000 to 0x00000FFF.
    2) Yes, it's not being used as I have assigned sector 0 for writing my data and rest of the memory for the code.
  • Hey,
    Thank You for the information on technical reference, I will go through it and let you know. For now I will try to make it work with my own driver as the library functions are blocking resources.

    Prem.
  • Hi Prem,

    Is this debug effort still ongoing? If not I will close out this thread.

    Please let us know.

    David

**Attention** This is a public forum