Merge pull request #2032 from andresv/stm32-check-flash-lock-before-unlocking

stm32 flash: check lock bit before unlocking
This commit is contained in:
Dario Nieuwenhuis 2023-10-10 10:12:55 +00:00 committed by GitHub
commit eff73d6dfa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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() {
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() {

View File

@ -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() {

View File

@ -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() {

View File

@ -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() {

View File

@ -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() {

View File

@ -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() {

View File

@ -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() {