Merge pull request #2032 from andresv/stm32-check-flash-lock-before-unlocking
stm32 flash: check lock bit before unlocking
This commit is contained in:
commit
eff73d6dfa
@ -19,8 +19,10 @@ pub(crate) unsafe fn lock() {
|
||||
}
|
||||
|
||||
pub(crate) unsafe fn unlock() {
|
||||
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() {
|
||||
|
@ -19,8 +19,10 @@ pub(crate) unsafe fn lock() {
|
||||
}
|
||||
|
||||
pub(crate) unsafe fn unlock() {
|
||||
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() {
|
||||
|
@ -228,8 +228,10 @@ pub(crate) unsafe fn lock() {
|
||||
}
|
||||
|
||||
pub(crate) unsafe fn unlock() {
|
||||
if pac::FLASH.cr().read().lock() {
|
||||
pac::FLASH.keyr().write(|w| w.set_key(0x45670123));
|
||||
pac::FLASH.keyr().write(|w| w.set_key(0xCDEF89AB));
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) unsafe fn enable_write() {
|
||||
|
@ -19,8 +19,10 @@ pub(crate) unsafe fn lock() {
|
||||
}
|
||||
|
||||
pub(crate) unsafe fn unlock() {
|
||||
if pac::FLASH.cr().read().lock() {
|
||||
pac::FLASH.keyr().write(|w| w.set_key(0x4567_0123));
|
||||
pac::FLASH.keyr().write(|w| w.set_key(0xCDEF_89AB));
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) unsafe fn enable_blocking_write() {
|
||||
|
@ -24,8 +24,10 @@ pub(crate) unsafe fn unlock() {
|
||||
while pac::FLASH.sr().read().bsy() {}
|
||||
|
||||
// Unlock flash
|
||||
if pac::FLASH.cr().read().lock() {
|
||||
pac::FLASH.keyr().write(|w| w.set_keyr(0x4567_0123));
|
||||
pac::FLASH.keyr().write(|w| w.set_keyr(0xCDEF_89AB));
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) unsafe fn enable_blocking_write() {
|
||||
|
@ -26,12 +26,16 @@ pub(crate) unsafe fn lock() {
|
||||
}
|
||||
|
||||
pub(crate) unsafe fn unlock() {
|
||||
if pac::FLASH.bank(0).cr().read().lock() {
|
||||
pac::FLASH.bank(0).keyr().write(|w| w.set_keyr(0x4567_0123));
|
||||
pac::FLASH.bank(0).keyr().write(|w| w.set_keyr(0xCDEF_89AB));
|
||||
}
|
||||
if is_dual_bank() {
|
||||
if pac::FLASH.bank(1).cr().read().lock() {
|
||||
pac::FLASH.bank(1).keyr().write(|w| w.set_keyr(0x4567_0123));
|
||||
pac::FLASH.bank(1).keyr().write(|w| w.set_keyr(0xCDEF_89AB));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) unsafe fn enable_blocking_write() {
|
||||
|
@ -28,18 +28,24 @@ pub(crate) unsafe fn lock() {
|
||||
pub(crate) unsafe fn unlock() {
|
||||
#[cfg(any(flash_wl, flash_wb, flash_l4))]
|
||||
{
|
||||
if pac::FLASH.cr().read().lock() {
|
||||
pac::FLASH.keyr().write(|w| w.set_keyr(0x4567_0123));
|
||||
pac::FLASH.keyr().write(|w| w.set_keyr(0xCDEF_89AB));
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(any(flash_l0, flash_l1))]
|
||||
{
|
||||
if pac::FLASH.pecr().read().pelock() {
|
||||
pac::FLASH.pekeyr().write(|w| w.set_pekeyr(0x89ABCDEF));
|
||||
pac::FLASH.pekeyr().write(|w| w.set_pekeyr(0x02030405));
|
||||
}
|
||||
|
||||
if pac::FLASH.pecr().read().prglock() {
|
||||
pac::FLASH.prgkeyr().write(|w| w.set_prgkeyr(0x8C9DAEBF));
|
||||
pac::FLASH.prgkeyr().write(|w| w.set_prgkeyr(0x13141516));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) unsafe fn enable_blocking_write() {
|
||||
|
Loading…
Reference in New Issue
Block a user