diff --git a/include/libopencm3/stm32/common/flash_common_all.h b/include/libopencm3/stm32/common/flash_common_all.h index 00232224..ad7b5560 100644 --- a/include/libopencm3/stm32/common/flash_common_all.h +++ b/include/libopencm3/stm32/common/flash_common_all.h @@ -65,4 +65,10 @@ void flash_lock(void); */ void flash_unlock(void); +/** Unlock the Option Byte Access. + * This enables write access to the option bytes. It is locked by default on + * reset. + */ +void flash_unlock_option_bytes(void); + END_DECLS \ No newline at end of file diff --git a/include/libopencm3/stm32/common/flash_common_f01.h b/include/libopencm3/stm32/common/flash_common_f01.h index e0d309e0..e4f7d60f 100644 --- a/include/libopencm3/stm32/common/flash_common_f01.h +++ b/include/libopencm3/stm32/common/flash_common_f01.h @@ -95,6 +95,9 @@ #define FLASH_KEYR_KEY1 ((uint32_t)0x45670123) #define FLASH_KEYR_KEY2 ((uint32_t)0xcdef89ab) +#define FLASH_OPTKEYR_KEY1 FLASH_KEYR_KEY1 +#define FLASH_OPTKEYR_KEY2 FLASH_KEYR_KEY2 + /* --- Function prototypes ------------------------------------------------- */ BEGIN_DECLS @@ -108,7 +111,6 @@ void flash_program_word(uint32_t address, uint32_t data); void flash_program_half_word(uint32_t address, uint16_t data); void flash_erase_page(uint32_t page_address); void flash_erase_all_pages(void); -void flash_unlock_option_bytes(void); void flash_erase_option_bytes(void); void flash_program_option_bytes(uint32_t address, uint16_t data); diff --git a/include/libopencm3/stm32/common/flash_common_f24.h b/include/libopencm3/stm32/common/flash_common_f24.h index 92494bfb..647f8413 100644 --- a/include/libopencm3/stm32/common/flash_common_f24.h +++ b/include/libopencm3/stm32/common/flash_common_f24.h @@ -112,7 +112,6 @@ BEGIN_DECLS -void flash_unlock_option_bytes(void); void flash_lock_option_bytes(void); void flash_clear_pgserr_flag(void); void flash_clear_wrperr_flag(void); diff --git a/include/libopencm3/stm32/common/flash_common_l01.h b/include/libopencm3/stm32/common/flash_common_l01.h index 8333df57..64f2f6a5 100644 --- a/include/libopencm3/stm32/common/flash_common_l01.h +++ b/include/libopencm3/stm32/common/flash_common_l01.h @@ -118,7 +118,6 @@ void flash_unlock_pecr(void); void flash_lock_pecr(void); void flash_unlock_progmem(void); void flash_lock_progmem(void); -void flash_unlock_option_bytes(void); void flash_lock_option_bytes(void); void eeprom_program_word(uint32_t address, uint32_t data); diff --git a/include/libopencm3/stm32/f3/flash.h b/include/libopencm3/stm32/f3/flash.h index f4024c50..d73d215a 100644 --- a/include/libopencm3/stm32/f3/flash.h +++ b/include/libopencm3/stm32/f3/flash.h @@ -72,6 +72,10 @@ #define FLASH_CR_PER (1 << 1) #define FLASH_CR_PG (1 << 0) +/* F3 uses the same keys for option bytes */ +#define FLASH_OPTKEYR_KEY1 FLASH_KEYR_KEY1 +#define FLASH_OPTKEYR_KEY2 FLASH_KEYR_KEY2 + BEGIN_DECLS diff --git a/include/libopencm3/stm32/f7/flash.h b/include/libopencm3/stm32/f7/flash.h index 93a8f7e8..9b9cb120 100644 --- a/include/libopencm3/stm32/f7/flash.h +++ b/include/libopencm3/stm32/f7/flash.h @@ -157,7 +157,6 @@ BEGIN_DECLS void flash_clear_pgperr_flag(void); void flash_wait_for_last_operation(void); -void flash_unlock_option_bytes(void); void flash_lock_option_bytes(void); void flash_clear_erserr_flag(void); void flash_clear_wrperr_flag(void); diff --git a/include/libopencm3/stm32/l4/flash.h b/include/libopencm3/stm32/l4/flash.h index c92e95cc..be790d7d 100644 --- a/include/libopencm3/stm32/l4/flash.h +++ b/include/libopencm3/stm32/l4/flash.h @@ -228,7 +228,6 @@ void flash_clear_pgserr_flag(void); void flash_clear_pgaerr_flag(void); void flash_clear_wrperr_flag(void); void flash_clear_status_flags(void); -void flash_unlock_option_bytes(void); void flash_lock_option_bytes(void); void flash_program_word(uint32_t address, uint32_t data); void flash_program(uint32_t address, uint8_t *data, uint32_t len); diff --git a/lib/stm32/common/flash_common_all.c b/lib/stm32/common/flash_common_all.c index f85fac1e..98821796 100644 --- a/lib/stm32/common/flash_common_all.c +++ b/lib/stm32/common/flash_common_all.c @@ -43,6 +43,10 @@ void flash_set_ws(uint32_t ws) FLASH_ACR = reg32; } - +void flash_unlock_option_bytes(void) +{ + FLASH_OPTKEYR = FLASH_OPTKEYR_KEY1; + FLASH_OPTKEYR = FLASH_OPTKEYR_KEY2; +} /*@}*/ diff --git a/lib/stm32/common/flash_common_f01.c b/lib/stm32/common/flash_common_f01.c index fc621388..2520a66c 100644 --- a/lib/stm32/common/flash_common_f01.c +++ b/lib/stm32/common/flash_common_f01.c @@ -85,20 +85,6 @@ void flash_program_word(uint32_t address, uint32_t data) flash_program_half_word(address+2, (uint16_t)(data>>16)); } -/*---------------------------------------------------------------------------*/ -/** @brief Unlock the Option Byte Access - -This enables write access to the option bytes. It is locked by default on -reset. -*/ - -void flash_unlock_option_bytes(void) -{ - /* F1 uses same keys for flash and option */ - FLASH_OPTKEYR = FLASH_KEYR_KEY1; - FLASH_OPTKEYR = FLASH_KEYR_KEY2; -} - /*---------------------------------------------------------------------------*/ /** @brief Erase All Option Bytes diff --git a/lib/stm32/common/flash_common_f24.c b/lib/stm32/common/flash_common_f24.c index db4ce4c5..096409c7 100644 --- a/lib/stm32/common/flash_common_f24.c +++ b/lib/stm32/common/flash_common_f24.c @@ -87,19 +87,6 @@ void flash_clear_status_flags(void) flash_clear_eop_flag(); } -/*---------------------------------------------------------------------------*/ -/** @brief Unlock the Option Byte Access - -This enables write access to the option bytes. It is locked by default on -reset. -*/ - -void flash_unlock_option_bytes(void) -{ - FLASH_OPTKEYR = FLASH_OPTKEYR_KEY1; - FLASH_OPTKEYR = FLASH_OPTKEYR_KEY2; -} - /*---------------------------------------------------------------------------*/ /** @brief Lock the Option Byte Access diff --git a/lib/stm32/common/flash_common_l01.c b/lib/stm32/common/flash_common_l01.c index 7ca1f48d..9eceb45f 100644 --- a/lib/stm32/common/flash_common_l01.c +++ b/lib/stm32/common/flash_common_l01.c @@ -64,18 +64,6 @@ void flash_lock_progmem(void) FLASH_PECR |= FLASH_PECR_PRGLOCK; } -/** - * Unlock option bytes. - * Writes the magic sequence to unlock the option bytes, - * you must have already unlocked access to this register! - * @sa flash_unlock_pecr - */ -void flash_unlock_option_bytes(void) -{ - FLASH_OPTKEYR = FLASH_OPTKEYR_KEY1; - FLASH_OPTKEYR = FLASH_OPTKEYR_KEY2; -} - void flash_lock_option_bytes(void) { FLASH_PECR |= FLASH_PECR_OPTLOCK; diff --git a/lib/stm32/f7/flash.c b/lib/stm32/f7/flash.c index 0dcf388b..a81815a9 100644 --- a/lib/stm32/f7/flash.c +++ b/lib/stm32/f7/flash.c @@ -82,19 +82,6 @@ void flash_wait_for_last_operation(void) while ((FLASH_SR & FLASH_SR_BSY) == FLASH_SR_BSY); } -/*---------------------------------------------------------------------------*/ -/** @brief Unlock the Option Byte Access - -This enables write access to the option bytes. It is locked by default on -reset. -*/ - -void flash_unlock_option_bytes(void) -{ - FLASH_OPTKEYR = FLASH_OPTKEYR_KEY1; - FLASH_OPTKEYR = FLASH_OPTKEYR_KEY2; -} - /*---------------------------------------------------------------------------*/ /** @brief Lock the Option Byte Access diff --git a/lib/stm32/l4/flash.c b/lib/stm32/l4/flash.c index fd3665aa..c3ec1f5e 100644 --- a/lib/stm32/l4/flash.c +++ b/lib/stm32/l4/flash.c @@ -92,16 +92,6 @@ void flash_clear_status_flags(void) flash_clear_eop_flag(); } -/** @brief Unlock the Option Byte Access - * This enables write access to the option bytes. It is locked by default on - * reset. - */ -void flash_unlock_option_bytes(void) -{ - FLASH_OPTKEYR = FLASH_OPTKEYR_KEY1; - FLASH_OPTKEYR = FLASH_OPTKEYR_KEY2; -} - /** @brief Lock the Option Byte Access * This disables write access to the option bytes. It is locked by default on * reset.