Erasing Internal Flash in NUCLEO-H533RE
I am not able to erase a section of internal flash of the NUCLEO-H633RE.
Using the debugger I see the Flash is all 0x00 before I try to erase. I verify that Flash is not locked i.e.
if (*FLASH_NSCR && LOCK)
{
*FLASH_NSKEYR = 0x45670123;
*FLASH_NSKEYR = 0xcdef89ab;
}
then I try to erase a section of Flash i.e.
/* ************************************************************************* */
/* */
/* EraseFla - Erases 8K page of Flash, Waits for Flash not busy. */
/* Inputs: uint32_t page holds the page to erase. */
/* Outputs: None */
/* */
/* ************************************************************************* */
void EraseFla(int EraPage)
{ while (*FLASH_NSCR && BSY){};
n = *FLASH_PRIVCFGR; // just testing
n = EraPage >> 7;
if (n && 0x0800)
{ n &= 0x07C0;
n |= 0x80000004;} // BKSEL and SER
else
{ n &= 0x07C0;
n |= 0x00000004;}
*FLASH_NSCR |= n;
*FLASH_NSCR |= STRT;
while (*FLASH_NSCR && BSY){};
}With the debugger I read 0x00000000 at *FLASH_NSCR but when I write
0x80000684 to *FLASH_NSCR it still reads as 0x00000000.
I suspect there is another way Flash is disabled, if so why?
I am trying to erase Flash at start up before I run my application.
Why would the IDE environment disable the flash and how do I enable
the flash again?
PS - I am trying to learn STM32CubeIDE and the processor using only
code I write. i.e. no CubeMX or HAL drivers.
Edited to apply source code formatting - please see How to insert source code for future reference.
