我试图在STM32F103RB上擦除闪存中的一页,如下所示:
FLASH_Unlock();
FLASH_ClearFlag(FLASH_FLAG_BSY | FLASH_FLAG_EOP | FLASH_FLAG_PGERR | FLASH_FLAG_WRPRTERR | FLASH_FLAG_OPTERR);
FLASHStatus = FLASH_ErasePage(Page);
但是,FLASH_ErasePage无法生成FLASH_ERROR_WRP
在stm32-linker工具中手动启用/禁用写保护无法解决问题。
答案 0 :(得分:0)
基本上FLASH_ErasePage失败并出现WRP错误,如果状态寄存器中存在先前的WRP错误,则不会尝试执行任何操作。
你的FLASH_ClearFlag调用是什么,至少FLASH_FLAG_BSY会导致assert_param(IS_FLASH_CLEAR_FLAG(FLASH_FLAG));失败(虽然我不确定在这种情况下会发生什么)。
#define IS_FLASH_CLEAR_FLAG(FLAG) ((((FLAG) & (uint32_t)0xFFFFC0FD) == 0x00000000) && ((FLAG) != 0x00000000))
答案 1 :(得分:0)
您的网页地址是什么?您要访问哪个地址? 例如,此示例在STM32F100C8上进行测试,不仅包括擦除,还包括正确写入数据。 http://www.ozturkibrahim.com/TR/eeprom-emulation-on-stm32/
答案 2 :(得分:0)
如果使用HAL驱动程序,您的代码可能如下所示(从实际项目中删除' n)
static HAL_StatusTypeDef Erase_Main_Program ()
{
FLASH_EraseInitTypeDef ins;
uint32_t sectorerror;
ins.TypeErase = FLASH_TYPEERASE_SECTORS;
ins.Banks = FLASH_BANK_1; /* Do not care, used for mass-erase */
#warning We currently erase from sector 2 (only keep 64KB of flash for boot))
ins.Sector = FLASH_SECTOR_4;
ins.NbSectors = 4;
ins.VoltageRange = FLASH_VOLTAGE_RANGE_3; /* voltage-range defines how big blocks can be erased at the same time */
return HAL_FLASHEx_Erase (&ins, §orerror);
}
HAL驱动程序中实际执行工作的内部函数
void FLASH_Erase_Sector(uint32_t Sector, uint8_t VoltageRange)
{
uint32_t tmp_psize = 0U;
/* Check the parameters */
assert_param(IS_FLASH_SECTOR(Sector));
assert_param(IS_VOLTAGERANGE(VoltageRange));
if(VoltageRange == FLASH_VOLTAGE_RANGE_1)
{
tmp_psize = FLASH_PSIZE_BYTE;
}
else if(VoltageRange == FLASH_VOLTAGE_RANGE_2)
{
tmp_psize = FLASH_PSIZE_HALF_WORD;
}
else if(VoltageRange == FLASH_VOLTAGE_RANGE_3)
{
tmp_psize = FLASH_PSIZE_WORD;
}
else
{
tmp_psize = FLASH_PSIZE_DOUBLE_WORD;
}
/* If the previous operation is completed, proceed to erase the sector */
CLEAR_BIT(FLASH->CR, FLASH_CR_PSIZE);
FLASH->CR |= tmp_psize;
CLEAR_BIT(FLASH->CR, FLASH_CR_SNB);
FLASH->CR |= FLASH_CR_SER | (Sector << POSITION_VAL(FLASH_CR_SNB));
FLASH->CR |= FLASH_CR_STRT;
}
要检查的第二件事。是否启用了中断,解锁呼叫和擦除呼叫之间是否有任何硬件访问?
我希望这会有所帮助