Part Number: MSPM0G3507
Other Parts Discussed in Thread: MSP432E401Y, , UNIFLASH
We take the driver lib code as reference to make our own MCAL library.
And we have a function to erase a flash sector.
This funcion works well for all other conditions.
But there is one case I saw sector erase fail:
Only the last 64 bits are valid data in this sector but all other data are 0xFFFFFFFF
The STATCMD register shows cmd pass and done, but data was not erased.
Then I tried to write some data at first 64 bits before erase it. It works.
But TRM did not mentioned this kind of operation needed when do sector erase.
Why sector erase failed in this condition? What should I do to prevent it?
Below is the reference code for us to erase the flash:
/*! Erase the next sector*/
FLASH_Unlock();
/* Set command type and size */
FLASHCTL->GEN.CMDTYPE = (FLASHCTL_CMDTYPE_SIZE_SECTOR | FLASHCTL_CMDTYPE_COMMAND_ERASE);
/*! Select the target erase base address in the CMDADDR registers*/
FLASHCTL->GEN.CMDADDR = pageAddress + FLASH_PHYSICAL_PAGE_SIZE;
/*! Execute and wait for the response*/
FLASHCTL->GEN.CMDEXEC = FLASHCTL_CMDEXEC_VAL_EXECUTE;
status = FLASH_WaitForCmdDone(FLASHCTL);
/*! Restore Configuration to noop command*/
FLASHCTL->GEN.CMDTYPE = FLASHCTL_CMDTYPE_COMMAND_NOOP;
__STATIC_INLINE bool FLASH_WaitForCmdDone(FLASHCTL_Regs *flashctl)
{
/* Wait for command to complete */
while ((flashctl->GEN.STATCMD & FLASHCTL_STATCMD_CMDDONE_MASK) !=
FLASHCTL_STATCMD_CMDDONE_STATDONE) {
;
}
return ((flashctl->GEN.STATCMD & FLASHCTL_STATCMD_CMDPASS_MASK) ==
FLASHCTL_STATCMD_CMDPASS_STATPASS);
}