找到 uint16_t MEM_If_Init_FS(void) 函数
我们添加
HAL_FLASH_Unlock();
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP | FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR |
FLASH_FLAG_PGAERR | FLASH_FLAG_PGPERR | FLASH_FLAG_PGSERR);解锁flash和清除一些flash的异常状态标识
把 uint16_t MEM_If_DeInit_FS(void) 函数里面增加一个
HAL_FLASH_Lock();紧接着是flash 的写入操作
uint16_t MEM_If_Erase_FS(uint32_t Add)
{
/* USER CODE BEGIN 3 */
uint32_t UserStartSector;
uint32_t SectorError;
FLASH_EraseInitTypeDef pEraseInit;
/* Unlock the Flash to enable the flash control register access *************/
MEM_If_Init_FS();
/* Get the sector where start the user flash area */
UserStartSector = GetSector(Add);
pEraseInit.TypeErase = TYPEERASE_SECTORS;
pEraseInit.Sector = UserStartSector;
pEraseInit.NbSectors = 9;
pEraseInit.VoltageRange