擦除STM32F205的扇区4,
板子开始可以,第二天就一直不行。
打印Flash-SR寄存器,值为0X10 (WRP错误)
但是芯片并没设置写保护:
读取OB区内容如下:
OptionType :0x0f; FLASH_OB_GetRDP:0xaa; FLASH_OB_GetWRP:0x00
代码如下:
HAL_StatusTypeDef flash_erase_4sectors()
{
uint32_t SectorError = 0;
HAL_StatusTypeDef status = HAL_ERROR ;
FLASH_EraseInitTypeDef pEraseInit;
if(uID_sector<FLASH_SECTOR_4 || uID_sector>= FLASH_SECTOR_5 || voltage >VOLTAGE_ERASE_WW)
return HAL_ERROR;
pEraseInit.TypeErase = FLASH_TYPEERASE_SECTORS;
pEraseInit.VoltageRange = FLASH_PSIZE_HALF_WORD;
pEraseInit.Sector = FLASH_SECTOR_4;
pEraseInit.NbSectors = 1;
HAL_FLASH_Unlock();
__disable_irq(); //
__HAL_FLASH_CLEAR_FLAG((FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR | \
FLASH_FLAG_PGPERR | FLASH_FLAG_PGSERR));
status = HAL_FLASHEx_Erase(&pEraseInit, &SectorError);
__enable_irq();
HAL_FLASH_Lock();
return status;
} |