aboutsummaryrefslogtreecommitdiffstats
path: root/libmaple/include/libmaple/flash.h
diff options
context:
space:
mode:
authorMarti Bolivar <mbolivar@leaflabs.com>2012-01-27 21:01:59 -0500
committerMarti Bolivar <mbolivar@leaflabs.com>2012-04-11 16:56:54 -0400
commitb5a8e0386d5134839bf23e82110d2f1926201202 (patch)
tree50b4a7a328bbc848d877ac9c6f77166403afe586 /libmaple/include/libmaple/flash.h
parent511a553334f36112bc2fd85f7c991840df727b60 (diff)
downloadlibrambutan-b5a8e0386d5134839bf23e82110d2f1926201202.tar.gz
librambutan-b5a8e0386d5134839bf23e82110d2f1926201202.zip
Clean up Flash interface; add flash_enable_features().
Make a single function, flash_enable_features(), to control the access characteristics of Flash memory (i.e. to write to the non-latency bits of ACR). In so doing, make everybody pretend to allow instruction and data caching. On STM32F1, trying to turn these on simply has no effect. This allows unconditionally trying to turn them on, which will simplify users' lives. This has the ancillary benefit of making the stm32f2- and stm32f1-specific flash.c files unnecessary; delete these. Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
Diffstat (limited to 'libmaple/include/libmaple/flash.h')
-rw-r--r--libmaple/include/libmaple/flash.h32
1 files changed, 27 insertions, 5 deletions
diff --git a/libmaple/include/libmaple/flash.h b/libmaple/include/libmaple/flash.h
index 97bfa26..bacbbda 100644
--- a/libmaple/include/libmaple/flash.h
+++ b/libmaple/include/libmaple/flash.h
@@ -47,18 +47,40 @@ extern "C"{
#define FLASH_WAIT_STATE_6 0x6
#define FLASH_WAIT_STATE_7 0x7
-/* The series header must define FLASH_SAFE_WAIT_STATES, the smallest
- * number of wait states that it is safe to use when the MCU clock is
- * at its fastest rate (not considering overclocking). */
+/* The series header must define:
+ *
+ * - FLASH_SAFE_WAIT_STATES, the smallest number of wait states that
+ * it is safe to use when SYSCLK is at its fastest documented rate
+ * and the MCU is powered at 3.3V (i.e. this doesn't consider
+ * overclocking or low voltage operation).
+ *
+ * - The following bit flags, for flash_enable_features():
+ *
+ * -- FLASH_PREFETCH: prefetcher
+ * -- FLASH_ICACHE: instruction cache
+ * -- FLASH_DCACHE: data cache
+ *
+ * If the target doesn't provide a feature (e.g. instruction and
+ * data caches on the STM32F1), the flag should be set to some no-op
+ * value. This allows using these flags unconditionally, with the
+ * desired effect taking place on series that support them.
+ */
#include <series/flash.h>
/*
- * Setup routines
+ * Flash routines
*/
-void flash_enable_prefetch(void);
void flash_set_latency(uint32 wait_states);
+static inline void flash_enable_features(uint32 feature_flags) {
+ FLASH_BASE->ACR |= feature_flags;
+}
+
+static inline void flash_enable_prefetch(void) {
+ flash_enable_features(FLASH_PREFETCH);
+}
+
#ifdef __cplusplus
}
#endif