From 7afd86db3093044ecbd9d90ffafd4fd8da31f306 Mon Sep 17 00:00:00 2001 From: Guillaume Revaillot Date: Tue, 8 Jan 2019 14:26:38 +0100 Subject: [PATCH] stm32l[01]: flash common: add flash_unlock_acr, allowing to unlock FLASH_ACR RUN_PD bit. flash_unlock_acr allows to unlock RUN_PD bit from FLASH_ACR register. Relock is done automatically when writing 0 to RUN_PD, so no flash_lock_acr method. --- include/libopencm3/stm32/common/flash_common_l01.h | 1 + lib/stm32/common/flash_common_l01.c | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/include/libopencm3/stm32/common/flash_common_l01.h b/include/libopencm3/stm32/common/flash_common_l01.h index 64f2f6a5..442c000f 100644 --- a/include/libopencm3/stm32/common/flash_common_l01.h +++ b/include/libopencm3/stm32/common/flash_common_l01.h @@ -119,6 +119,7 @@ void flash_lock_pecr(void); void flash_unlock_progmem(void); void flash_lock_progmem(void); void flash_lock_option_bytes(void); +void flash_unlock_acr(void); void eeprom_program_word(uint32_t address, uint32_t data); void eeprom_program_words(uint32_t address, uint32_t *data, int length_in_words); diff --git a/lib/stm32/common/flash_common_l01.c b/lib/stm32/common/flash_common_l01.c index 9eceb45f..9fb1212b 100644 --- a/lib/stm32/common/flash_common_l01.c +++ b/lib/stm32/common/flash_common_l01.c @@ -89,6 +89,14 @@ void flash_lock(void) flash_lock_pecr(); } +/** @brief Unlock RUN_PD bit from FLASH_ACR register. + */ +void flash_unlock_acr(void) +{ + FLASH_PDKEYR = FLASH_PDKEYR_PDKEY1; + FLASH_PDKEYR = FLASH_PDKEYR_PDKEY2; +} + /** @brief Write a word to eeprom * * @param address assumed to be in the eeprom space, no checking