Skip to main content
RComa.1
Associate II
April 13, 2022
Solved

FLASH Memory erase sector

Hello folk, i hope you fine, i am using the STM32L072, i need erase FLASH memory from 0x08008000 up to the end, i read in the datasheet that every sector has 4Kb and every page has 128 bytes, i have the following:

 FLASH_EraseInitTypeDef borrat;
 
 borrat.NbPages = 1;
 borrat.PageAddress = 0x8008000; //flashAddr;
 borrat.TypeErase = FLASH_TYPEERASE_PAGES;
 
 uint32_t pagE;
 HAL_FLASH_Unlock();
// HAL_FLASHEx_Erase(&borrat, &pagE);
 HAL_FLASH_Lock();

In this code it erase just a page from 0x8008000, is that true? so i don't understand how to erase all pages from start position up to the end, can someone helps me?¿

Thanks a lot!

This topic has been closed for replies.
Peter BENSCH
Peter BENSCHBest answer
ST Technical Moderator
April 13, 2022

Well, if you specify only one page to delete, only one page will be deleted.

So you should calculate the number of pages to be deleted and then specify that at NbPages.

Does it answer your question?

Regards

/Peter

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

2 replies

KnarfB
Super User
April 13, 2022

NbPages is the number of pages to erase. Set a higher value here.

hth

KnarfB

Peter BENSCH
Peter BENSCHBest answer
ST Technical Moderator
April 13, 2022

Well, if you specify only one page to delete, only one page will be deleted.

So you should calculate the number of pages to be deleted and then specify that at NbPages.

Does it answer your question?

Regards

/Peter

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.