cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with Flash_Write after a reset

Moughit
Associate III

Hi,

I'm using the FLASH_Write function in order to save a table in a specific address. Once it is saved correctly I reset the board and try to change another address with the same function.

The problem is that the flash_write function works at the first try but once the reset is done, the flush_write crushes and give me this error "FLASHIF_WRITING_ERROR".

Does anyone know why it crushes in the second time after a reset ?

You may find the flash_write file attached to this post.

2 REPLIES 2
TDK
Guru

What chip?

Programming double words may not be supported on your chip for the voltage you have.

If you feel a post has answered your question, please click "Accept as Solution".
Moughit
Associate III

I'm using the STM32L476VG

I found out that the problem is actually coming from the Flash_Erase

uint32_t FLASH_If_Erase(uint32_t start)

{

 uint32_t NbrOfPages = 0;

 uint32_t PageError = 0;

 FLASH_EraseInitTypeDef pEraseInit;

 HAL_StatusTypeDef status = HAL_OK;

 /* Unlock the Flash to enable the flash control register access *************/

 HAL_FLASH_Unlock();

 /* Get the number of page to erase */

 NbrOfPages = (FLASH_START_ADRESS + FLASH_SIZE);

 NbrOfPages = (NbrOfPages - start) / FLASH_PAGE_SIZE;

 if(NbrOfPages > FLASH_PAGE_NBPERBANK)

 {

   pEraseInit.Banks = FLASH_BANK_1;

   //pEraseInit.NbPages = NbrOfPages % FLASH_PAGE_NBPERBANK;

      pEraseInit.NbPages = 32;

   pEraseInit.Page = FLASH_PAGE_NBPERBANK - pEraseInit.NbPages;

   pEraseInit.TypeErase = FLASH_TYPEERASE_PAGES;

   status = HAL_FLASHEx_Erase(&pEraseInit, &PageError);

   NbrOfPages = FLASH_PAGE_NBPERBANK;

 }

 if(status == HAL_OK)

 {

   pEraseInit.Banks = FLASH_BANK_2;

   pEraseInit.NbPages = NbrOfPages;

   pEraseInit.Page = FLASH_PAGE_NBPERBANK - pEraseInit.NbPages;

   pEraseInit.TypeErase = FLASH_TYPEERASE_PAGES;

   status = HAL_FLASHEx_Erase(&pEraseInit, &PageError);

 }

 /* Lock the Flash to disable the flash control register access (recommended

    to protect the FLASH memory against possible unwanted operation) *********/

 HAL_FLASH_Lock();

 if (status != HAL_OK)

 {

   /* Error occurred while page erase */

   return FLASHIF_ERASEKO;

 }

 return FLASHIF_OK;

}

When I use pEraseInit.NbPages = NbrOfPages % FLASH_PAGE_NBPERBANK; the Flash_Erase works fine, but it also erase the rest of the ship where I have stored other parameters. I only want to erase 32 pages so I have tried pEraseInit.NbPages = 32K; but it doesn't work