2020-08-02 08:32 AM
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.
Solved! Go to Solution.
2020-08-02 08:46 AM
Flash sectors are numbered starting with 0. The third flash sector is FLASH_SECTOR_2 = 2.
2020-08-02 08:46 AM
Flash sectors are numbered starting with 0. The third flash sector is FLASH_SECTOR_2 = 2.
2020-08-02 09:01 AM
Thank you very much for finding my stupid mistake.