cancel
Showing results for 
Search instead for 
Did you mean: 

Nucleo L152RE: Flash page erase issue

hunarame
Associate
Posted on March 07, 2015 at 13:04

Hi,

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:

FLASH_EraseInitTypeDef erase_pages;
erase_pages.PageAddress=0x0807FF00;
erase_pages.NbPages=1;
erase_pages.TypeErase=TYPEERASE_PAGES;
uint32_t *error; 
HAL_FLASH_Unlock(); 
HAL_FLASHEx_Erase(&erase_pages, error);
HAL_FLASH_Lock();

And then writing on the half page using following code below

HAL_FLASH_Unlock(); 
status=HAL_FLASHEx_HalfPageProgram(0x0807FF00,data);
HAL_FLASH_Lock();

( 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 want to write some data in Flash memory (not EEPROM) and then read that data after reset of microcontroller board.

Kindly help

Thankyou

#stm32l152 #flash
0 REPLIES 0