cancel
Showing results for 
Search instead for 
Did you mean: 

stm32f767igt doesn't erase the flash

Glee.11
Associate II

Hi All.

I work with stm32f767igt for using flash.

The code below is erasing and writing flash.

I succeed writing the flash.

0693W000001sH6wQAE.png

But when i try to delete the flash with

HAL_FLASHEx_Erase(&EraseInitStruct, &SECTORError) ;

and

FLASH_Erase_Sector(FLASH_SECTOR_10 ,FLASH_VOLTAGE_RANGE_3);

it didn't work properly.

So i can't update data in flash because flash doesn't deleted.

What am i doing wrong?

------------------------------------code ---------------------------------------------------------------------------------------

#define FLASH_BASE_ADDR  ADDR_FLASH_SECTOR_10  /* Start @ of user Flash area */

#define FLASH_END_ADDR   (ADDR_FLASH_SECTOR_11-1)  /* End @ of user Flash area */

void flash_erase_write(void)

{

HAL_FLASH_Unlock();

// HAL_FLASH_OB_Unlock();

// HAL_FLASHEx_OBGetConfig(&OBInit);

// #if defined(DUAL_BANK)

// /* Turn on LED3 if FLASH is configured in Dual Bank mode */

// if((OBInit.USERConfig & OB_NDBANK_SINGLE_BANK) == OB_NDBANK_SINGLE_BANK)

// #else

// /* Turn on LED3 if FLASH is configured in Single Bank mode */

// if((OBInit.USERConfig & OB_NDBANK_SINGLE_BANK) == OB_NDBANK_DUAL_BANK)

// #endif

// {

// while(1);

// }

/* Get the 1st sector to erase */

FirstSector = GetSector(FLASH_BASE_ADDR);

/* Get the number of sector to erase from 1st sector*/

NbOfSectors = GetSector(FLASH_END_ADDR) - FirstSector + 1;

/* Fill EraseInit structure*/

EraseInitStruct.TypeErase   = FLASH_TYPEERASE_SECTORS;

EraseInitStruct.VoltageRange = FLASH_VOLTAGE_RANGE_3;

EraseInitStruct.Sector    = FirstSector;

EraseInitStruct.NbSectors   = NbOfSectors;//NbOfSectors;

//FLASH_Erase_Sector(FLASH_SECTOR_10 ,FLASH_VOLTAGE_RANGE_3);

 if (HAL_FLASHEx_Erase(&EraseInitStruct, &SECTORError) != HAL_OK)           

 {

printf("flash erase Error!!!\r\n");

  while (1)

  {

  }

 }

  

Address = FLASH_BASE_ADDR;

#define DATA_32 ((uint32_t)0x12345678)

if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD, Address, DATA_32) == HAL_OK)

{

 Address = Address + 4;

}

}

17 REPLIES 17
TDK
Guru

Does HAL_FLASHEx_Erase return HAL_OK or some other value?

Double check your arguments in EraseInitStruct. You haven't included enough code to check them here.

Ensure your DUAL_BANK define matches up with what you have configured in the option bytes.

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

thank you for your quick reply.

Yes. the HAL_FLASHEx_Erase returns HAL_OK otherwise it stuck in while(1).

i didn't set any option realted with DUAL_BANK.

how do i check the option bytes?

Piranha
Chief II

Say hello to high-performance Cortex-M7 with cache and idiot made HAL (non-)high-level library. By default FLASH region is configured as write-through. Because of that after write operations no cache management is necessary, but after erase cache invalidation must be executed on the respective region. Typically you need to use SCB_InvalidateDCache_by_Addr().

SCB_InvalidateDCache_by_Addr((uint32_t*)0x080C0000, 131072);

/* flash delete */

 if (HAL_FLASHEx_Erase(&EraseInitStruct, &SECTORError) != HAL_OK)

 {

  /*

   Error occurred while sector erase.

   User can add here some code to deal with this error.

   SECTORError will contain the faulty sector and then to know the code error on this sector,

   user can call function 'HAL_FLASH_GetError()'

  */

  /* Infinite loop */

printf("flash erase Error!!!\r\n");

  while (1)

  {

  }

 }

I program like this, but it didn't work.

How do i use this function correctly?

What do you think the word "after" means?

Glee.11
Associate II

Yes. . . I added after erase flash()​ ,,too

But , not working

Also​ i have tested on nucleo-144 stm32f767ZIboard, it works.​

Piranha
Chief II

"Not working" is not a description of the problem and with that noone can help. Have you looked at flash contents after power cycle? Have you debugged HAL bloatware?

Oh, that bloatware even has multiple copies of the same function... Because of sector number 12, this could also be your problem.

https://github.com/STMicroelectronics/STM32CubeF7/blob/08376dce1b404687e4a86b73077f396bccfc9cb5/Drivers/STM32F7xx_HAL_Driver/Src/stm32f7xx_hal_flash_ex.c#L488

https://github.com/STMicroelectronics/STM32CubeF7/blob/08376dce1b404687e4a86b73077f396bccfc9cb5/Drivers/STM32F7xx_HAL_Driver/Src/stm32f7xx_hal_flash_ex.c#L672

The first one seems to be the latest one with additional code for sector numbers. @Imen DAHMEN​​, how can such a crap get through all ST's year long "tests"?

i'm not familiar with english =)

anyway, thank you for the link.

very helpful!

regard

That's not related to the language but the fact that you have not done your homework of debugging and describing the situation.