Report
4 years, 1 month ago.

Nucleo L152RE: Flash page erase issue

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:

include the mbed library with this snippet

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

include the mbed library with this snippet

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

Thankyou

Comment on this question

2 Answers

3 years, 5 months ago.

-- uint32_t *error; 
++ uint32_t error; 

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

4 years, 1 month ago.

Hi,

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.

https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/AllItems.aspx

Best regards

+1, Thanks bco for looking after this questions

posted by Martin Kojtal 18 Mar 2015

To post an answer, please log in.