2021-10-29 01:05 AM
I am attaching my code for reference.
int FLASH_Erase_Size(uint32_t uStart, uint32_t uLength)
{
uint32_t page_error = 0U;
FLASH_EraseInitTypeDef x_erase_init;
uint32_t e_ret_status = HAL_ERROR;
uint32_t first_page = 0U, nb_of_pages = 0U, bank_number = 0U;
/* Initialize Flash */
e_ret_status = FLASH_Init();
if (e_ret_status == HAL_OK)
{
/* Unlock the Flash to enable the flash control register access *************/
if (HAL_FLASH_Unlock() == HAL_OK)
{
/* Get the 1st page to erase */
first_page = FLASH_get_pageInBank(uStart);
/* Get the number of pages to erase from 1st page */
nb_of_pages = FLASH_get_pageInBank(uStart + uLength - 1U) - first_page + 1U;
/* Get the bank */
bank_number = FLASH_get_bank(uStart);
/* Fill EraseInit structure*/
x_erase_init.TypeErase = FLASH_TYPEERASE_PAGES;
x_erase_init.Banks = bank_number;
x_erase_init.Page = first_page;
x_erase_init.NbPages = nb_of_pages;
if (HAL_FLASHEx_Erase(&x_erase_init, &page_error) != HAL_OK)
{
/* Error occurred while page erase */
HAL_FLASH_GetError();
printf("ERROR flash erase\n");
e_ret_status = HAL_ERROR;
}
HAL_FLASH_Lock();
}
else
{
}
}
else
{
}
return e_ret_status;
}
2021-10-29 02:36 AM
Fail to show calling parameters for your function.
Suggest you instrument, printing out values you call into HAL function, and provide that output also.
2021-10-29 03:46 AM
Hi,
Please find parameters as below:
FLASH_Erase_Size(0x08080000,409600);
the function is returning HAL_OK
Best Regards
Pankaj