2015-11-11 08:59 AM
I have the following code:
FLASH_EraseInitTypeDef EraseInitStruct;
__HAL_FLASH_INSTRUCTION_CACHE_RESET
();
__HAL_FLASH_INSTRUCTION_CACHE_ENABLE
();
HAL_FLASH_Unlock
();
/* Get the 1st sector to erase */ // FirstSector = GetSector (Start_Addr); /* Get the number of sector to erase from 1st sector*/ // NbOfSectors = GetSector (End_Addr) - FirstSector + 1; uint32_t SectorError; /* Fill EraseInit structure*/ EraseInitStruct.TypeErase = TYPEERASE_SECTORS; EraseInitStruct.VoltageRange = VOLTAGE_RANGE_3; EraseInitStruct.Sector = FLASH_SECTOR_1; EraseInitStruct.NbSectors = 1;__HAL_FLASH_CLEAR_FLAG
(FLASH_FLAG_EOP | FLASH_FLAG_OPERR |
FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR | FLASH_FLAG_PGSERR); if (HAL_FLASHEx_Erase
(&EraseInitStruct, &SectorError) != HAL_OK)
{ return false; }FLASH_WaitForLastOperation
(10000);
uint32_t* ptr = (uint32_t*)0x8004000; uint32_t value = *ptr; if (value == 0xFFFFFFFF) { return true; } else { return false; }I expect this to make the value at address 0x08004000 read 0xFFFFFFFF but it doesn't.
Any ideas why not? I'm running this and stepping through to verify. Any help is much appreciated. D2015-11-11 01:14 PM
Do you have any of the locks set?
What is at that address? JW2015-11-11 03:32 PM
[DEAD LINK /public/STe2ecommunities/mcu/Lists/STM32Java/Flat.aspx?RootFolder=/public/STe2ecommunities/mcu/Lists/STM32Java/Unable%20to%20erase%20Flash%20sector%20-%20STM32F4Discovery&FolderCTID=0x01200200770978C69A1141439FE559EB459D758000F9A0E3A95BA69146A17C2E80209ADC21&TopicsView=https://my.st.com/public/STe2ecommunities/mcu/Lists/STM32Java/AllItems.aspx¤tviews=6]Dupe
2015-11-12 01:20 AM
''Do you have any of the locks set?''
I assume ''
HAL_FLASH_Unlock
();'' should have cleared any locks?
''What is at that address?'' Nothing at the moment... Perhaps its not erasing the address range I think it is... Are sectors defined in hardware or by the HAL library? Dan2015-11-12 10:18 AM