cancel
Showing results for 
Search instead for 
Did you mean: 

Erasing Internal Flash in NUCLEO-H533RE

BrucePB
Associate II

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.

1 ACCEPTED SOLUTION

Accepted Solutions
mƎALLEm
ST Employee

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.

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.

View solution in original post

2 REPLIES 2
mƎALLEm
ST Employee

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.

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.

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.