diff --git a/include/libopencm3/stm32/common/flash_common_all.h b/include/libopencm3/stm32/common/flash_common_all.h
index 8771ccf5..00232224 100644
--- a/include/libopencm3/stm32/common/flash_common_all.h
+++ b/include/libopencm3/stm32/common/flash_common_all.h
@@ -43,6 +43,15 @@ void flash_prefetch_enable(void);
void flash_prefetch_disable(void);
+/** Set the Number of Wait States.
+
+Used to match the system clock to the FLASH memory access time. See the
+programming manual for more information on clock speed ranges. The latency must
+be changed to the appropriate value before any increase in clock
+speed, or after any decrease in clock speed.
+
+@param[in] ws values from @ref flash_latency.
+*/
void flash_set_ws(uint32_t ws);
/** Lock the Flash Program and Erase Controller
diff --git a/include/libopencm3/stm32/common/flash_common_f01.h b/include/libopencm3/stm32/common/flash_common_f01.h
index 33b02edd..e0d309e0 100644
--- a/include/libopencm3/stm32/common/flash_common_f01.h
+++ b/include/libopencm3/stm32/common/flash_common_f01.h
@@ -58,7 +58,7 @@
/* --- FLASH_ACR values ---------------------------------------------------- */
#define FLASH_ACR_LATENCY_SHIFT 0
-#define FLASH_ACR_LATENCY 7
+#define FLASH_ACR_LATENCY_MASK 7
#define FLASH_ACR_PRFTBS (1 << 5)
#define FLASH_ACR_PRFTBE (1 << 4)
diff --git a/include/libopencm3/stm32/common/flash_common_f234.h b/include/libopencm3/stm32/common/flash_common_f234.h
index 0842607b..50390c38 100644
--- a/include/libopencm3/stm32/common/flash_common_f234.h
+++ b/include/libopencm3/stm32/common/flash_common_f234.h
@@ -50,6 +50,7 @@
/* --- FLASH_ACR values ---------------------------------------------------- */
+#define FLASH_ACR_LATENCY_SHIFT 0
#define FLASH_ACR_LATENCY_MASK 0x0f
#define FLASH_ACR_LATENCY(w) ((w) & FLASH_ACR_LATENCY_MASK)
#define FLASH_ACR_LATENCY_0WS 0x00
diff --git a/include/libopencm3/stm32/common/flash_common_l01.h b/include/libopencm3/stm32/common/flash_common_l01.h
index 82053ed4..39a031cd 100644
--- a/include/libopencm3/stm32/common/flash_common_l01.h
+++ b/include/libopencm3/stm32/common/flash_common_l01.h
@@ -48,6 +48,8 @@
#define FLASH_ACR_RUNPD (1 << 4)
#define FLASH_ACR_SLEEPPD (1 << 3)
#define FLASH_ACR_PRFTEN (1 << 1)
+#define FLASH_ACR_LATENCY_SHIFT 0
+#define FLASH_ACR_LATENCY_MASK 1
/** @defgroup flash_latency FLASH Wait States
@ingroup flash_defines
@{*/
diff --git a/include/libopencm3/stm32/f7/flash.h b/include/libopencm3/stm32/f7/flash.h
index ef3d141b..93a8f7e8 100644
--- a/include/libopencm3/stm32/f7/flash.h
+++ b/include/libopencm3/stm32/f7/flash.h
@@ -80,6 +80,7 @@
#define FLASH_ACR_ARTEN (1 << 9)
#define FLASH_ACR_PRFTEN (1 << 8)
+#define FLASH_ACR_LATENCY_SHIFT 0
#define FLASH_ACR_LATENCY_MASK 0x0f
/* --- FLASH_SR values ----------------------------------------------------- */
diff --git a/lib/stm32/common/flash_common_all.c b/lib/stm32/common/flash_common_all.c
index 71210008..f85fac1e 100644
--- a/lib/stm32/common/flash_common_all.c
+++ b/lib/stm32/common/flash_common_all.c
@@ -33,5 +33,16 @@ void flash_prefetch_disable(void)
FLASH_ACR &= ~FLASH_ACR_PRFTEN;
}
+void flash_set_ws(uint32_t ws)
+{
+ uint32_t reg32;
+
+ reg32 = FLASH_ACR;
+ reg32 &= ~(FLASH_ACR_LATENCY_MASK << FLASH_ACR_LATENCY_SHIFT);
+ reg32 |= (ws << FLASH_ACR_LATENCY_SHIFT);
+ FLASH_ACR = reg32;
+}
+
+
/*@}*/
diff --git a/lib/stm32/common/flash_common_f01.c b/lib/stm32/common/flash_common_f01.c
index fe1c1709..fc621388 100644
--- a/lib/stm32/common/flash_common_f01.c
+++ b/lib/stm32/common/flash_common_f01.c
@@ -25,21 +25,6 @@
#include
-/*---------------------------------------------------------------------------*/
-/** @brief Set the Number of Wait States
-
-Used to match the system clock to the FLASH memory access time. See the
-reference manual for more information on clock speed ranges for each wait state.
-The latency must be changed to the appropriate value before any increase
-in clock speed, or after any decrease in clock speed.
-
-@param[in] ws values from @ref flash_latency.
-*/
-
-void flash_set_ws(uint32_t ws)
-{
- FLASH_ACR = (FLASH_ACR & ~FLASH_ACR_LATENCY) | ws;
-}
/*---------------------------------------------------------------------------*/
/** @brief Unlock the Flash Program and Erase Controller
diff --git a/lib/stm32/common/flash_common_f234.c b/lib/stm32/common/flash_common_f234.c
index 0e01f811..3f111444 100644
--- a/lib/stm32/common/flash_common_f234.c
+++ b/lib/stm32/common/flash_common_f234.c
@@ -26,25 +26,6 @@
#include
-/*---------------------------------------------------------------------------*/
-/** @brief Set the Number of Wait States
-
-Used to match the system clock to the FLASH memory access time. See the
-programming manual for more information on clock speed ranges. The latency must
-be changed to the appropriate value before any increase in clock
-speed, or after any decrease in clock speed.
-
-@param[in] ws values from @ref flash_latency.
-*/
-void flash_set_ws(uint32_t ws)
-{
- uint32_t reg32;
- reg32 = FLASH_ACR & ~(FLASH_ACR_LATENCY_MASK);
- reg32 |= ws & FLASH_ACR_LATENCY_MASK;
- FLASH_ACR = reg32;
-}
-
-
/*---------------------------------------------------------------------------*/
/** @brief Clear the Programming Error Status Flag
diff --git a/lib/stm32/common/flash_common_l01.c b/lib/stm32/common/flash_common_l01.c
index 53a8a19c..86ec743a 100644
--- a/lib/stm32/common/flash_common_l01.c
+++ b/lib/stm32/common/flash_common_l01.c
@@ -29,27 +29,6 @@
#include
-/*---------------------------------------------------------------------------*/
-/** @brief Set the Number of Wait States
-
-Used to match the system clock to the FLASH memory access time. See the
-programming manual for more information on clock speed and voltage ranges. The
-latency must be changed to the appropriate value before any increase in
-clock speed, or after any decrease in clock speed. A latency setting of
-zero only applies if 64-bit mode is not used.
-
-@param[in] ws values from @ref flash_latency.
-*/
-
-void flash_set_ws(uint32_t ws)
-{
- uint32_t reg32;
-
- reg32 = FLASH_ACR;
- reg32 &= ~(1 << 0);
- reg32 |= ws;
- FLASH_ACR = reg32;
-}
/**
* Unlock primary access to the flash control/erase block
diff --git a/lib/stm32/f7/flash.c b/lib/stm32/f7/flash.c
index 846aa042..314343b4 100644
--- a/lib/stm32/f7/flash.c
+++ b/lib/stm32/f7/flash.c
@@ -58,32 +58,6 @@ static inline void flash_pipeline_stall(void)
__asm__ volatile("dsb":::"memory");
}
-/*---------------------------------------------------------------------------*/
-/** @brief Set the Number of Wait States
-
-Used to match the system clock to the FLASH memory access time. See the
-programming manual for more information on clock speed ranges. The latency must
-be changed to the appropriate value before any increase in clock
-speed, or after any decrease in clock speed.
-
-@param[in] ws values from @ref flash_latency.
-*/
-void flash_set_ws(uint32_t ws)
-{
- uint32_t reg32;
-
- reg32 = FLASH_ACR;
- reg32 &= ~(FLASH_ACR_LATENCY_MASK);
- reg32 |= ws;
- FLASH_ACR = reg32;
-
- /* Wait until the new wait states take effect.
- * RM0385: Check that the new number of wait states is taken into
- * account to access the Flash memory by reading the FLASH_ACR register.
- */
- while ((FLASH_ACR & FLASH_ACR_LATENCY_MASK) != ws);
-}
-
/*---------------------------------------------------------------------------*/
/** @brief Clear the Programming Error Status Flag
diff --git a/lib/stm32/l4/flash.c b/lib/stm32/l4/flash.c
index 488017f0..71ebffeb 100644
--- a/lib/stm32/l4/flash.c
+++ b/lib/stm32/l4/flash.c
@@ -42,25 +42,6 @@
#include
-/** @brief Set the Number of Wait States
-
-Used to match the system clock to the FLASH memory access time. See the
-programming manual for more information on clock speed ranges. The latency must
-be changed to the appropriate value before any increase in clock
-speed, or after any decrease in clock speed.
-
-@param[in] ws values from @ref flash_latency.
-*/
-void flash_set_ws(uint32_t ws)
-{
- uint32_t reg32;
-
- reg32 = FLASH_ACR;
- reg32 &= ~(FLASH_ACR_LATENCY_MASK << FLASH_ACR_LATENCY_SHIFT);
- reg32 |= (ws << FLASH_ACR_LATENCY_SHIFT);
- FLASH_ACR = reg32;
-}
-
/** @brief Clear the Programming Error Status Flag
*/
void flash_clear_pgperr_flag(void)