2026-04-16 4:36 PM - last edited on 2026-04-17 3:11 AM by Andrew Neil
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.
Solved! Go to Solution.
2026-04-17 3:07 AM - edited 2026-04-17 3:20 AM
Hello,
PS - I am trying to learn STM32CubeIDE and the processor using only
code I write. i.e. no CubeMX or HAL drivers.
1- That's definitely not a CubeIDE question. So no need to post that thread in STM32CubeIDE forum board
2- Ok you need to learn and you don't use HAL ok.. but before going ahead with the direct access to the registers, try to use HAL and inspire from the examples provided in CubeHAL package: https://github.com/STMicroelectronics/STM32CubeH5/tree/main/Projects/NUCLEO-H533RE/Examples/FLASH/FLASH_EraseProgram
If all is ok inspire from the register access sequence in the HAL.
2026-04-17 3:07 AM - edited 2026-04-17 3:20 AM
Hello,
PS - I am trying to learn STM32CubeIDE and the processor using only
code I write. i.e. no CubeMX or HAL drivers.
1- That's definitely not a CubeIDE question. So no need to post that thread in STM32CubeIDE forum board
2- Ok you need to learn and you don't use HAL ok.. but before going ahead with the direct access to the registers, try to use HAL and inspire from the examples provided in CubeHAL package: https://github.com/STMicroelectronics/STM32CubeH5/tree/main/Projects/NUCLEO-H533RE/Examples/FLASH/FLASH_EraseProgram
If all is ok inspire from the register access sequence in the HAL.
2026-04-17 5:09 AM
1. I think the problem is my understanding of what CubeIDE is doing on startup. i.e. how and why erasing Flash is not useable when the default conditions says it should be working. I cannot find the source for SystemInit.
2. I have looked at HAL code to write my code and do not see why it does not work. Again, I think the problem is my understanding of what CubeIDE is doing on startup.