stm32 flash: check lock bit before unlocking

It hardfaults if already unlocked flash is unlocked again.
This commit is contained in:
Andres Vahter
2023-10-10 12:48:21 +03:00
parent 904f1cfc7a
commit 3616d68aaa
7 changed files with 40 additions and 20 deletions

View File

@ -19,8 +19,10 @@ pub(crate) unsafe fn lock() {
}
pub(crate) unsafe fn unlock() {
pac::FLASH.keyr().write(|w| w.set_fkeyr(0x4567_0123));
pac::FLASH.keyr().write(|w| w.set_fkeyr(0xCDEF_89AB));
if pac::FLASH.cr().read().lock() {
pac::FLASH.keyr().write(|w| w.set_fkeyr(0x4567_0123));
pac::FLASH.keyr().write(|w| w.set_fkeyr(0xCDEF_89AB));
}
}
pub(crate) unsafe fn enable_blocking_write() {