cancel
Showing results for 
Search instead for 
Did you mean: 

Nucleo-WB55RG / CubeMX / Flash Erase Hard Fault Interrupt??

SWenn.1
Senior III

I am using the above subject Nucleo.  I create a project and let STM32CubeIDE V 1.16.1 create a default project.  I make NO changes to this.  I close the .ioc and open main and add the following code (seen by Red Bars).  I build and load to target.  I place a breakpoint on the HAL_FLASHEx_ERASE function and when I go to step over this function I get a hard fault interrupt.  I step into code and the following line

  MODIFY_REG(FLASH->CR, FLASH_CR_PNB, ((Page << FLASH_CR_PNB_Pos) | FLASH_CR_PER | FLASH_CR_STRT));

creates the hard fault.  Can someone please tell me what I am doing wrong here?....The target address has been verified to be readable via STM32CubeProgrammer so I know that it is not out of memory space.

SWenn1_0-1733426589451.png

 

1 ACCEPTED SOLUTION

Accepted Solutions
Lubos KOUDELKA
ST Employee

Hello,
In FLASH_EraseInitTypeDef versionFlash Page field you're passing the absolute flash address, while page number is expected.

FLASH_EraseProgram example project is using GetPage function for page calculation to pass into Page

static uint32_t GetPage(uint32_t Addr)
{
  return (Addr - FLASH_BASE) / FLASH_PAGE_SIZE;
}

 

View solution in original post

2 REPLIES 2
Lubos KOUDELKA
ST Employee

Hello,
In FLASH_EraseInitTypeDef versionFlash Page field you're passing the absolute flash address, while page number is expected.

FLASH_EraseProgram example project is using GetPage function for page calculation to pass into Page

static uint32_t GetPage(uint32_t Addr)
{
  return (Addr - FLASH_BASE) / FLASH_PAGE_SIZE;
}

 

SWenn.1
Senior III

Thank you...Yes I found this over the weekend.