Skip to content

Commit

Permalink
flash_stm32: don't unlock flash if already unlocked (#13841)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
xyzz authored Aug 2, 2021
1 parent 4b630c4 commit 720c676
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions tmk_core/common/chibios/flash_stm32.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,11 @@ FLASH_Status FLASH_ProgramHalfWord(uint32_t Address, uint16_t Data) {
* @retval None
*/
void FLASH_Unlock(void) {
/* Authorize the FPEC Access */
FLASH->KEYR = FLASH_KEY1;
FLASH->KEYR = FLASH_KEY2;
if (FLASH->CR & FLASH_CR_LOCK) {
/* Authorize the FPEC Access */
FLASH->KEYR = FLASH_KEY1;
FLASH->KEYR = FLASH_KEY2;
}
}

/**
Expand Down

0 comments on commit 720c676

Please sign in to comment.