cancel
Showing results for 
Search instead for 
Did you mean: 

Hi, I am using STM32L4R5ZG controller in one of my custom board. My application need to erase some flash area in controller. However when i ma trying to erase 100 pages in Bank2 of controller pages are not getting erased and there is no error

PKrish
Associate

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;

}

2 REPLIES 2

Fail to show calling parameters for your function.

Suggest you instrument, printing out values​ you call into HAL function, and provide that output also.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
PKrish
Associate

Hi,

Please find parameters as below:

FLASH_Erase_Size(0x08080000,409600);

the function is returning HAL_OK

Best Regards

Pankaj