我想从我的用户代码写入 STM32F407VGT 的闪存扇区 11 以存储一些数据。我用过stm32f4xx_hal_flash.c
图书馆。我首先使用以下代码擦除扇区:
void Flash_Init(void)
{
FLASH_EraseInitTypeDef pEraseInit;
pEraseInit.Banks = FLASH_BANK_1;
pEraseInit.NbSectors = 1;
pEraseInit.Sector = FLASH_SECTOR_10;
pEraseInit.VoltageRange = FLASH_VOLTAGE_RANGE_3;
pEraseInit.TypeErase = FLASH_TYPEERASE_SECTORS;
if(HAL_FLASH_Unlock() == HAL_OK)
{
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP | FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR | FLASH_FLAG_PGSERR );
HAL_FLASHEx_Erase(&pEraseInit,0);
HAL_FLASH_Lock();
}
}
程序在到达HAL_FLASHEx_Erase(&pEraseInit,0);
函数时挂起。我的分散文件如下所示:
LR_IROM1 0x08000000 0x01000000 { ; load region size_region
ER_IROM1 0x08000000 0x01000000 { ; load address = execution address
*.o (RESET, +First)
*(InRoot$$Sections)
.ANY (+RO)
}
RW_IRAM1 0x20000000 0x00020000 { ; RW data
.ANY (+RW +ZI)
}
RW_IRAM2 0x10000000 0x00010000 {
.ANY (+RW +ZI)
}
}
我必须先做些什么才能让这个功能起作用吗?