flash_stm32: don't unlock flash if already unlocked

On stm32f4 after reboot from DFU it was observed that the flash is
already unlocked. In that case, attempting to unlock it again causes a
data abort.
This commit is contained in:
Ilya Zhuravlev 2021-08-01 16:25:27 -04:00
parent 99bd9aeb3f
commit 7d932b88f8

View file

@ -175,9 +175,11 @@ FLASH_Status FLASH_ProgramHalfWord(uint32_t Address, uint16_t Data) {
* @retval None * @retval None
*/ */
void FLASH_Unlock(void) { void FLASH_Unlock(void) {
/* Authorize the FPEC Access */ if (FLASH->CR & FLASH_CR_LOCK) {
FLASH->KEYR = FLASH_KEY1; /* Authorize the FPEC Access */
FLASH->KEYR = FLASH_KEY2; FLASH->KEYR = FLASH_KEY1;
FLASH->KEYR = FLASH_KEY2;
}
} }
/** /**