2024-12-05 11:23 AM
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.
Solved! Go to Solution.
2024-12-09 06:22 AM
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;
}
2024-12-09 06:22 AM
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;
}
2024-12-09 07:32 AM
Thank you...Yes I found this over the weekend.