2023-06-28 08:55 AM - edited 2023-06-28 09:18 AM
SOLVED: I didn't convert the flashErase_handle.PageAddress to hex, so I was passing in the integer 800_8000, which is much less than 0x800_8000
I'm using the Nucleo F303RE board and as part of a bootloader trying to erase pages of flash containing the user application. `HAL_FLASHEx_Erase()` retuns a OK status but when I reset the processor and jumped to the user application it still worked. I also stepped through HAL_FLASHEx_Erase() to confirm it was trying to erase the right addresses, which it seemed to be as it started at 0x0800_8000 and increase by 0x800 every iteration of FLASH_PageErase().
Then I tried `FLASH_PageErase()` manually to erase the first page containing the user application (0x0800_8000) and on reboot the user application did not work. I also tried manually deleting one of the last pages of flash to see that the user application still worked (0x800F7FF), which it did. I retested both steps multiple times by reflashing the user application, confirming it worked, then trying to manually delete pages.
So it would seem that HAL_FLASHEx_Erase(), which uses FLASH_PageErase(), does not work when the internal function FLASH_PageErase() seems to work ok.
Here's the code:
if (!verify_flash_address(initial_addr))
{
status = HAL_ERROR;
return status;
}
/* Read PRIMASK register, check interrupt status before you disable them */
/* Returns 0 if they are enabled, or non-zero if disabled */
uint32_t prim = __get_PRIMASK();
/* Disable interrupts */
__disable_irq();
// Erase flash
if(HAL_FLASH_Unlock() == HAL_OK)
{
printf("unlocked flash\n\r");
// FLASH_PageErase(0x8008000);
// FLASH_PageErase(0x800F7FF);
status = (uint8_t) HAL_FLASHEx_Erase(&flashErase_handle, &PageError);
printf("status: %d, PageError: 0x%08x\r\n", status, PageError);
HAL_FLASH_Lock();
}
else
{
printf("error unlocking flash\n\r");
}
/* Enable interrupts back */
if (!prim) {
__enable_irq();
}
}
Solved! Go to Solution.
2023-07-03 06:30 AM - edited 2023-08-07 06:09 AM
Hello @shane mattner ,
Glad to know that the issue is already fixed.
Thank you for your sharing the solution :) : " SOLVED: I didn't convert the flashErase_handle.PageAddress to hex, so I was passing in the integer 800_8000, which is much less than 0x800_8000"
Thank you.
Kaouthar
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.
2023-07-03 06:30 AM - edited 2023-08-07 06:09 AM
Hello @shane mattner ,
Glad to know that the issue is already fixed.
Thank you for your sharing the solution :) : " SOLVED: I didn't convert the flashErase_handle.PageAddress to hex, so I was passing in the integer 800_8000, which is much less than 0x800_8000"
Thank you.
Kaouthar
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.