4 years, 5 months ago.

Nucleo L152RE: Flash page erase issue


I'm trying to write and erase data into/from internal Flash memory (range 0x0800000 - 0x0807FFFF) of STM32 L152RE. I'm only accessing the last page of Flash ( 0x0807FF00 - 0x0807FFFF) and then writing the data only on half page.

I'm erasing the page using following code: And erasing through following code:

include the mbed library with this snippet

FLASH_EraseInitTypeDef erase_pages;
uint32_t *error; 
HAL_FLASHEx_Erase(&erase_pages, error);

And then writing on the half page using following code below

include the mbed library with this snippet


(here 'data' is the pointer to the array of 128 bytes (32 words) which is the size of half page)

Both writing and erasing are working perfectly fine when placed in while(1). But when I reset the board (through button), it simply do nothing, as if whole Flash memory is erased and there is no code to execute. Is this normal?

I have checked through the keil uvision debugger, the code is in the first bank of flash (range 0x0800000 - 0x0803FFFF) and I'm only accessing the last page of the second bank. Even if I'm overwriting the code section then it should also not run in while(1) as well.

I have also checked that when I comment out the "page erase" code, the program start to work properly and on reset program re-start from the beginning (except it don't actual write anything on the flash because page need to be erased first).

I'm not sure whether the problem is in "page write" or "page erase" code or this is normal behavior (which is weird). I want to write some data in Flash memory (not EEPROM) and then read that data after reset of microcontroller board.

Kindly help


Comment on this question

2 Answers

3 years, 9 months ago.

-- uint32_t *error; 
++ uint32_t error; 

-- HAL_FLASHEx_Erase(&erase_pages, error);
++ HAL_FLASHEx_Erase(&erase_pages, &error);

4 years, 5 months ago.


For this kind of problems/questions more related to the STM32 device and not mbed API, it is better to ask directly in the ST forum. You will find I think more answers. Thanks.

Best regards

+1, Thanks bco for looking after this questions

posted by Martin Kojtal 18 Mar 2015

You need to log in to post a question