flash_stm32: don't unlock flash if already unlocked (#13841)

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.
master
xyzz 2021-08-02 00:27:57 -04:00 committed by GitHub
parent 4b630c46fe
commit 720c676403
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 3 deletions

View File

@ -161,9 +161,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;
}
} }
/** /**