aboutsummaryrefslogtreecommitdiffstats
path: root/libmaple/flash.c
diff options
context:
space:
mode:
Diffstat (limited to 'libmaple/flash.c')
-rw-r--r--libmaple/flash.c43
1 files changed, 27 insertions, 16 deletions
diff --git a/libmaple/flash.c b/libmaple/flash.c
index 9442c44..3fd35d6 100644
--- a/libmaple/flash.c
+++ b/libmaple/flash.c
@@ -25,29 +25,40 @@
#include "libmaple.h"
#include "flash.h"
-#define ACR_PRFTBE ((uint32)0xFFFFFFEF)
-#define ACR_PRFTBE_ENABLE ((uint32)0x00000010) /* FLASH Prefetch Buffer Enable */
-#define ACR_PRFTBE_DISABLE ((uint32)0x00000000) /* FLASH Prefetch Buffer Disable */
+#define FLASH_BASE 0x40022000
+#define FLASH_ACR FLASH_BASE
-#define ACR_LATENCY ((uint32)0x00000038)
-#define ACR_LATENCY_0 ((uint32)0x00000000) /* FLASH Zero Latency cycle */
-#define ACR_LATENCY_1 ((uint32)0x00000001) /* FLASH One Latency cycle */
-#define ACR_LATENCY_2 ((uint32)0x00000002) /* FLASH Two Latency cycles */
+#define ACR_PRFTBE BIT(4)
+#define ACR_PRFTBE_ENABLE BIT(4)
+/* flash wait states */
+#define ACR_LATENCY (0x7)
+
+#define FLASH_WRITE_ACR(val) __write(FLASH_ACR, val)
+#define FLASH_READ_ACR() __read(FLASH_ACR)
+
+
+/**
+ * @brief turn on the hardware prefetcher
+ */
void flash_enable_prefetch(void) {
- uint32 acr = __read(FLASH_ACR);
+ uint32 val = FLASH_READ_ACR();
- acr &= ACR_PRFTBE;
- acr |= ACR_PRFTBE_ENABLE;
+ val |= ACR_PRFTBE_ENABLE;
- __write(FLASH_ACR, acr);
+ FLASH_WRITE_ACR(val);
}
-void flash_set_latency(void) {
- uint32 acr = __read(FLASH_ACR);
- acr &= ACR_LATENCY;
- acr |= ACR_LATENCY_2;
+/**
+ * @brief set flash wait states
+ * @param number of wait states
+ */
+void flash_set_latency(uint32 wait_states) {
+ uint32 val = FLASH_READ_ACR();
+
+ val &= ~ACR_LATENCY;
+ val |= wait_states;
- __write(FLASH_ACR, acr);
+ FLASH_WRITE_ACR(val);
}