cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F429 Flash erase not working on specific sectors.

NYulz.1
Associate II

Hey,

I'm adding a bootloader to my project that sits in the first 2 sectors of internal flash.

while trying to preform the update it seems that i can't erase sector 3 all other sectors that follow this sector are erased properly.

this is the code I'm using to erase the specified sectors:

    uint32_t                SectorError     = 0;
    FLASH_EraseInitTypeDef  EraseInitStruct;
    HAL_StatusTypeDef       flashStatus     = HAL_OK;
 
    /* Fill EraseInit structure*/
    EraseInitStruct.TypeErase       = FLASH_TYPEERASE_SECTORS;
    EraseInitStruct.VoltageRange    = FLASH_VOLTAGE_RANGE_3;
    EraseInitStruct.NbSectors       = 8;
    EraseInitStruct.Sector          = FLASH_SECTOR_3;
 
    /* Perform Erase Sector */
    do
    {
        flashStatus = HAL_FLASHEx_Erase(&EraseInitStruct, &SectorError);
     } while(flashStatus != HAL_OK);

I also tried disabling write protection with:

    FLASH_OBProgramInitTypeDef OBStruct= {0};
    HAL_StatusTypeDef status = HAL_OK;
    HAL_FLASH_Unlock();
    HAL_FLASH_OB_Unlock();
    
    /* Bank 1 */
    OBStruct.Banks = FLASH_BANK_1;
    OBStruct.WRPSector = OB_WRP_SECTOR_All;
    OBStruct.OptionType = OPTIONBYTE_WRP;
    OBStruct.WRPState = OB_WRPSTATE_DISABLE;
    
    status = HAL_FLASHEx_OBProgram(&OBStruct);
    
    HAL_FLASH_OB_Lock();
    HAL_FLASH_Lock();
   

All help will be appreciated.

1 ACCEPTED SOLUTION

Accepted Solutions
TDK
Guru

Flash sectors are numbered starting with 0. The third flash sector is FLASH_SECTOR_2 = 2.

If you feel a post has answered your question, please click "Accept as Solution".

View solution in original post

2 REPLIES 2
TDK
Guru

Flash sectors are numbered starting with 0. The third flash sector is FLASH_SECTOR_2 = 2.

If you feel a post has answered your question, please click "Accept as Solution".
NYulz.1
Associate II

Thank you very much for finding my stupid mistake.