2024-02-20 08:35 PM
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();
Solved! Go to Solution.
2024-02-20 10:23 PM
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;
}
2024-02-20 10:23 PM
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;
}