cancel
Showing results for 
Search instead for 
Did you mean: 

Flash memory erase

DivyaJayan
Associate III

I am using STM32L476RGT6. I am trying to read and write operation in the embedded flash memory. I am unable to erase the stored data in the embedded flash memory. 

I am following method to erase :

FLASH_EraseInitTypeDef EraseInitStruct;

 

HAL_FLASH_Unlock();

EraseInitStruct.TypeErase= FLASH_TYPEERASE_PAGES;

EraseInitStruct. Page = 0x0807F800;

EraseInitStruct. NbPages=1;

EraseInitStruct. Banks= 1;//

uint32_t  PAGE Error;

 

if (HAL_FLASHEx_Erase(&EraseInitStruct, &PAGEError) != HAL_OK) {

}

HAL_FLASH_Lock();

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Elatewendy
Associate III

hello,

 

 

 

EraseInitStruct. Page = 0x0807F800;

 

the page is the number of page,not the address.

 
 

The number of page numbers can be obtained by calculation.

For example:

 

unsigned int STMFLASH_GetFlashPage(unsigned int addr) { uint32_t page = 0; if (addr < (FLASH_BASE + FLASH_BANK_SIZE)) { /* Bank 1 */ page = (addr - FLASH_BASE) / FLASH_PAGE_SIZE; } else { /* Bank 2 */ page = (addr - (FLASH_BASE + FLASH_BANK_SIZE)) / FLASH_PAGE_SIZE; } return page; }

 

View solution in original post

1 REPLY 1
Elatewendy
Associate III

hello,

 

 

 

EraseInitStruct. Page = 0x0807F800;

 

the page is the number of page,not the address.

 
 

The number of page numbers can be obtained by calculation.

For example:

 

unsigned int STMFLASH_GetFlashPage(unsigned int addr) { uint32_t page = 0; if (addr < (FLASH_BASE + FLASH_BANK_SIZE)) { /* Bank 1 */ page = (addr - FLASH_BASE) / FLASH_PAGE_SIZE; } else { /* Bank 2 */ page = (addr - (FLASH_BASE + FLASH_BANK_SIZE)) / FLASH_PAGE_SIZE; } return page; }