diff --git a/include/libopencm3/stm32/common/flash_common_all.h b/include/libopencm3/stm32/common/flash_common_all.h
index be1c5eeb..8771ccf5 100644
--- a/include/libopencm3/stm32/common/flash_common_all.h
+++ b/include/libopencm3/stm32/common/flash_common_all.h
@@ -45,4 +45,15 @@ void flash_prefetch_disable(void);
void flash_set_ws(uint32_t ws);
+/** Lock the Flash Program and Erase Controller
+ * Used to prevent spurious writes to FLASH.
+ */
+void flash_lock(void);
+
+/** Unlock the Flash Program and Erase Controller
+ * This enables write access to the Flash memory. It is locked by default on
+ * reset.
+ */
+void flash_unlock(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 d52b1feb..70410f6d 100644
--- a/include/libopencm3/stm32/common/flash_common_f01.h
+++ b/include/libopencm3/stm32/common/flash_common_f01.h
@@ -99,8 +99,6 @@
BEGIN_DECLS
-void flash_unlock(void);
-void flash_lock(void);
void flash_clear_pgerr_flag(void);
void flash_clear_eop_flag(void);
void flash_clear_wrprterr_flag(void);
diff --git a/include/libopencm3/stm32/common/flash_common_f234.h b/include/libopencm3/stm32/common/flash_common_f234.h
index 9f546f54..1c52c5bf 100644
--- a/include/libopencm3/stm32/common/flash_common_f234.h
+++ b/include/libopencm3/stm32/common/flash_common_f234.h
@@ -74,8 +74,6 @@
BEGIN_DECLS
-void flash_unlock(void);
-void flash_lock(void);
void flash_clear_pgperr_flag(void);
void flash_clear_eop_flag(void);
void flash_clear_status_flags(void);
diff --git a/include/libopencm3/stm32/common/flash_common_l01.h b/include/libopencm3/stm32/common/flash_common_l01.h
index 385e8475..82053ed4 100644
--- a/include/libopencm3/stm32/common/flash_common_l01.h
+++ b/include/libopencm3/stm32/common/flash_common_l01.h
@@ -118,8 +118,6 @@ void flash_unlock_progmem(void);
void flash_lock_progmem(void);
void flash_unlock_option_bytes(void);
void flash_lock_option_bytes(void);
-void flash_unlock(void);
-void flash_lock(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/include/libopencm3/stm32/f7/flash.h b/include/libopencm3/stm32/f7/flash.h
index c0827dc7..befd63d6 100644
--- a/include/libopencm3/stm32/f7/flash.h
+++ b/include/libopencm3/stm32/f7/flash.h
@@ -152,8 +152,6 @@
BEGIN_DECLS
-void flash_unlock(void);
-void flash_lock(void);
void flash_clear_pgperr_flag(void);
void flash_clear_eop_flag(void);
void flash_wait_for_last_operation(void);
diff --git a/include/libopencm3/stm32/l4/flash.h b/include/libopencm3/stm32/l4/flash.h
index 50c7859f..90286058 100644
--- a/include/libopencm3/stm32/l4/flash.h
+++ b/include/libopencm3/stm32/l4/flash.h
@@ -224,8 +224,6 @@
BEGIN_DECLS
-void flash_unlock(void);
-void flash_lock(void);
void flash_clear_pgperr_flag(void);
void flash_clear_eop_flag(void);
void flash_wait_for_last_operation(void);
diff --git a/lib/stm32/common/flash_common_f.c b/lib/stm32/common/flash_common_f.c
new file mode 100644
index 00000000..b6f0ce50
--- /dev/null
+++ b/lib/stm32/common/flash_common_f.c
@@ -0,0 +1,41 @@
+/** @addtogroup flash_file
+ *
+ */
+
+/*
+ * This file is part of the libopencm3 project.
+ *
+ * This library is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library. If not, see .
+ */
+
+/**@{*/
+
+#include
+
+
+void flash_unlock(void)
+{
+ /* Clear the unlock state. */
+ FLASH_CR |= FLASH_CR_LOCK;
+
+ /* Authorize the FPEC access. */
+ FLASH_KEYR = FLASH_KEYR_KEY1;
+ FLASH_KEYR = FLASH_KEYR_KEY2;
+}
+
+void flash_lock(void)
+{
+ FLASH_CR |= FLASH_CR_LOCK;
+}
+
diff --git a/lib/stm32/common/flash_common_f01.c b/lib/stm32/common/flash_common_f01.c
index 98ee1c6c..2d8917cc 100644
--- a/lib/stm32/common/flash_common_f01.c
+++ b/lib/stm32/common/flash_common_f01.c
@@ -48,26 +48,6 @@ This enables write access to the Flash memory. It is locked by default on
reset.
*/
-void flash_unlock(void)
-{
- /* Clear the unlock state. */
- FLASH_CR |= FLASH_CR_LOCK;
-
- /* Authorize the FPEC access. */
- FLASH_KEYR = FLASH_KEYR_KEY1;
- FLASH_KEYR = FLASH_KEYR_KEY2;
-}
-
-/*---------------------------------------------------------------------------*/
-/** @brief Lock the Flash Program and Erase Controller
-
-Used to prevent spurious writes to FLASH.
-*/
-
-void flash_lock(void)
-{
- FLASH_CR |= FLASH_CR_LOCK;
-}
/*---------------------------------------------------------------------------*/
/** @brief Clear the Programming Error Status Flag
diff --git a/lib/stm32/common/flash_common_f234.c b/lib/stm32/common/flash_common_f234.c
index a8ab2db7..e150ce79 100644
--- a/lib/stm32/common/flash_common_f234.c
+++ b/lib/stm32/common/flash_common_f234.c
@@ -44,33 +44,6 @@ void flash_set_ws(uint32_t ws)
FLASH_ACR = reg32;
}
-/*---------------------------------------------------------------------------*/
-/** @brief Unlock the Flash Program and Erase Controller
-
-This enables write access to the Flash memory. It is locked by default on
-reset.
-*/
-
-void flash_unlock(void)
-{
- /* Clear the unlock sequence state. */
- FLASH_CR |= FLASH_CR_LOCK;
-
- /* Authorize the FPEC access. */
- FLASH_KEYR = FLASH_KEYR_KEY1;
- FLASH_KEYR = FLASH_KEYR_KEY2;
-}
-
-/*---------------------------------------------------------------------------*/
-/** @brief Lock the Flash Program and Erase Controller
-
-Used to prevent spurious writes to FLASH.
-*/
-
-void flash_lock(void)
-{
- FLASH_CR |= FLASH_CR_LOCK;
-}
/*---------------------------------------------------------------------------*/
/** @brief Clear the Programming Error Status Flag
diff --git a/lib/stm32/f0/Makefile b/lib/stm32/f0/Makefile
index 5f45b7fc..a5883643 100644
--- a/lib/stm32/f0/Makefile
+++ b/lib/stm32/f0/Makefile
@@ -47,7 +47,7 @@ OBJS += gpio_common_all.o gpio_common_f0234.o crc_common_all.o crc_v2
OBJS += adc_common_v2.o
OBJS += crs_common_all.o
-OBJS += flash_common_all.o flash_common_f01.o
+OBJS += flash_common_all.o flash_common_f.o flash_common_f01.o
OBJS += usart_common_all.o usart_common_v2.o
OBJS += i2c_common_v2.o
OBJS += spi_common_all.o spi_common_v2.o
diff --git a/lib/stm32/f1/Makefile b/lib/stm32/f1/Makefile
index 7803a102..c61f737b 100755
--- a/lib/stm32/f1/Makefile
+++ b/lib/stm32/f1/Makefile
@@ -46,7 +46,7 @@ OBJS += crc_common_all.o dac_common_all.o dma_common_l1f013.o \
timer_common_all.o usart_common_all.o usart_common_f124.o \
rcc_common_all.o exti_common_all.o
-OBJS += flash_common_all.o flash_common_f01.o
+OBJS += flash_common_all.o flash_common_f.o flash_common_f01.o
OBJS += spi_common_all.o spi_common_v1.o
OBJS += usb.o usb_control.o usb_standard.o usb_msc.o
diff --git a/lib/stm32/f2/Makefile b/lib/stm32/f2/Makefile
index 97700b19..edb92278 100644
--- a/lib/stm32/f2/Makefile
+++ b/lib/stm32/f2/Makefile
@@ -45,7 +45,7 @@ OBJS += crc_common_all.o dac_common_all.o dma_common_f24.o \
timer_common_f24.o usart_common_all.o usart_common_f124.o \
hash_common_f24.o \
crypto_common_f24.o exti_common_all.o rcc_common_all.o
-OBJS += flash_common_all.o flash_common_f234.o flash_common_f24.o
+OBJS += flash_common_all.o flash_common_f.o flash_common_f234.o flash_common_f24.o
OBJS += rng_common_v1.o
OBJS += spi_common_all.o spi_common_v1.o spi_common_v1_frf.o
diff --git a/lib/stm32/f3/Makefile b/lib/stm32/f3/Makefile
index 9e347628..304d5a5c 100644
--- a/lib/stm32/f3/Makefile
+++ b/lib/stm32/f3/Makefile
@@ -45,7 +45,7 @@ OBJS += gpio_common_all.o gpio_common_f0234.o \
timer_common_all.o timer_common_f0234.o \
exti_common_all.o rcc_common_all.o
OBJS += adc_common_v2.o adc_common_v2_multi.o
-OBJS += flash_common_all.o flash_common_f234.o
+OBJS += flash_common_all.o flash_common_f.o flash_common_f234.o
OBJS += usart_common_v2.o usart_common_all.o
OBJS += i2c_common_v2.o
OBJS += spi_common_all.o spi_common_v2.o
diff --git a/lib/stm32/f4/Makefile b/lib/stm32/f4/Makefile
index d9f0ad4a..4c60d9c6 100644
--- a/lib/stm32/f4/Makefile
+++ b/lib/stm32/f4/Makefile
@@ -50,7 +50,7 @@ OBJS += crc_common_all.o dac_common_all.o dma_common_f24.o \
usart_common_f124.o \
hash_common_f24.o crypto_common_f24.o exti_common_all.o \
rcc_common_all.o
-OBJS += flash_common_all.o flash_common_f234.o flash_common_f24.o
+OBJS += flash_common_all.o flash_common_f.o flash_common_f234.o flash_common_f24.o
OBJS += rng_common_v1.o
OBJS += spi_common_all.o spi_common_v1.o spi_common_v1_frf.o
diff --git a/lib/stm32/f7/Makefile b/lib/stm32/f7/Makefile
index 1cb01162..f53194d5 100644
--- a/lib/stm32/f7/Makefile
+++ b/lib/stm32/f7/Makefile
@@ -42,7 +42,7 @@ TGT_CFLAGS += $(STANDARD_FLAGS)
ARFLAGS = rcs
-OBJS = flash_common_all.o flash.o pwr.o rcc.o
+OBJS = flash_common_all.o flash_common_f.o flash.o pwr.o rcc.o
OBJS += gpio.o gpio_common_all.o gpio_common_f0234.o
OBJS += rcc_common_all.o
diff --git a/lib/stm32/f7/flash.c b/lib/stm32/f7/flash.c
index c525f4f0..a78b4bf6 100644
--- a/lib/stm32/f7/flash.c
+++ b/lib/stm32/f7/flash.c
@@ -84,34 +84,6 @@ void flash_set_ws(uint32_t ws)
while ((FLASH_ACR & FLASH_ACR_LATENCY_MASK) != ws);
}
-/*---------------------------------------------------------------------------*/
-/** @brief Unlock the Flash Program and Erase Controller
-
-This enables write access to the Flash memory. It is locked by default on
-reset.
-*/
-
-void flash_unlock(void)
-{
- /* Clear the unlock sequence state. */
- FLASH_CR |= FLASH_CR_LOCK;
-
- /* Authorize the FPEC access. */
- FLASH_KEYR = FLASH_KEYR_KEY1;
- FLASH_KEYR = FLASH_KEYR_KEY2;
-}
-
-/*---------------------------------------------------------------------------*/
-/** @brief Lock the Flash Program and Erase Controller
-
-Used to prevent spurious writes to FLASH.
-*/
-
-void flash_lock(void)
-{
- FLASH_CR |= FLASH_CR_LOCK;
-}
-
/*---------------------------------------------------------------------------*/
/** @brief Clear the Programming Error Status Flag
diff --git a/lib/stm32/l4/Makefile b/lib/stm32/l4/Makefile
index da3283bd..99dfe791 100644
--- a/lib/stm32/l4/Makefile
+++ b/lib/stm32/l4/Makefile
@@ -47,7 +47,7 @@ OBJS += exti_common_all.o
OBJS += adc_common_v2.o adc_common_v2_multi.o
OBJS += crc_common_all.o crc_v2.o
OBJS += crs_common_all.o
-OBJS += flash_common_all.o
+OBJS += flash_common_all.o flash_common_f.o
OBJS += rng_common_v1.o
OBJS += timer_common_all.o
OBJS += i2c_common_v2.o
diff --git a/lib/stm32/l4/flash.c b/lib/stm32/l4/flash.c
index 27d8783a..d654ecc8 100644
--- a/lib/stm32/l4/flash.c
+++ b/lib/stm32/l4/flash.c
@@ -61,28 +61,6 @@ void flash_set_ws(uint32_t ws)
FLASH_ACR = reg32;
}
-/** @brief Unlock the Flash Program and Erase Controller
- * This enables write access to the Flash memory. It is locked by default on
- * reset.
- */
-void flash_unlock(void)
-{
- /* Clear the unlock sequence state. */
- FLASH_CR |= FLASH_CR_LOCK;
-
- /* Authorize the FPEC access. */
- FLASH_KEYR = FLASH_KEYR_KEY1;
- FLASH_KEYR = FLASH_KEYR_KEY2;
-}
-
-/** @brief Lock the Flash Program and Erase Controller
- * Used to prevent spurious writes to FLASH.
- */
-void flash_lock(void)
-{
- FLASH_CR |= FLASH_CR_LOCK;
-}
-
/** @brief Clear the Programming Error Status Flag
*/
void flash_clear_pgperr_flag(void)