cancel
Showing results for 
Search instead for 
Did you mean: 

Can't Erase flash memory page

Radoslav Mar
Associate II
Posted on June 18, 2018 at 12:26

Hello All.

MCU: STM32F031G6U6

IDE: System Workbench

API: STM32F0 HAL and low-layer drivers

I am trying to erase page in the flash memory at address: 0x8002000.

Here is the code:

https://community.st.com/tags♯/?tags=code

‌

FLASH_EraseInitTypeDef EraseInitStruct;

uint32_t SECTORError = 0;;

bool result = true;

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

HAL_FLASH_Unlock();

//addr = 0x08007800 just for testing

/* Erase the user Flash area

(area defined by FLASH_USER_START_ADDR and FLASH_USER_END_ADDR) ***********/

/* Fill EraseInit structure*/

EraseInitStruct.TypeErase = FLASH_TYPEERASE_PAGES;

EraseInitStruct.PageAddress = Address; // start address = 

0x8002000.

EraseInitStruct.NbPages = 1;

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 */

while (1)

{

;// error, BALAGAN!!!

}

}

The program crashes at this line 

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

Nothing after this function call is executed.

Any Ideas?

#code
0 REPLIES 0