AnsweredAssumed Answered

FLASH_Erase_Sector

Question asked by Stefano Ugolini on Dec 22, 2017
Latest reply on Mar 19, 2018 by Malith Yapa

I'm trying to store some data using HAL library.

 

 

HAL_FLASH_Unlock();

 

__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP | FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR | FLASH_FLAG_PGSERR );

 

FLASH_Erase_Sector(ADDR_FLASH_SECTOR_10, VOLTAGE_RANGE_3);

 

uint64_t testVar = 0XFAFAFAFAFAFAFAFA;

 

HAL_FLASH_Program(TYPEPROGRAM_WORD, ADDR_FLASH_SECTOR_10, testVar);

 

HAL_FLASH_Lock();

 

 

Now FLASH_Erase_Sector does not erase the sector and that's why I can't program it. Am I missing something?

 

 

 

I tried the same function from STM32F4xx_StdPeriph_Driver library and it works fine. I can see that the two fuctions are different even if they should look the same. Few things I don't understand.

 

1.In the HAL version of the function FLASH_WaitForLastOperation() is not used. 

 

2.This part is missing

/* if the erase operation is completed, disable the SER Bit */
FLASH->CR &= (~FLASH_CR_SER);
FLASH->CR &= SECTOR_MASK;

 

3. This comment seems a bad copy and paste from the STM32F4xx_StdPeriph_Driver  version.

/* if the previous operation is completed, proceed to erase the sector */

 

 

4. I can't figure out where this come from, could someone point me to a datasheet?

 

/* Need to add offset of 4 when sector higher than FLASH_SECTOR_11 */
if(Sector > FLASH_SECTOR_11)
{
Sector += 4U;
}

Outcomes