it seems, that because of some HAL bug, you can recieve PGSERR and PGPERR on STM32F4. To fix this you need to add ```c __HAL_FLASH_CLEAR_FLAG(0xFF); ``` before ```c HAL_FLASH_UNLOCK(); ```