Browse files

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>
  • Loading branch information...
1 parent 9703511 commit 0284df54f75038039b1ced24fe9ecabaa6bd18b0 @mbolivar committed Jan 27, 2012
View
32 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
View
41 libmaple/stm32f1/flash.c
@@ -1,41 +0,0 @@
-/******************************************************************************
- * The MIT License
- *
- * Copyright (c) 2010 Perry Hung.
- * Copyright (c) 2011 LeafLabs, LLC.
- *
- * Permission is hereby granted, free of charge, to any person
- * obtaining a copy of this software and associated documentation
- * files (the "Software"), to deal in the Software without
- * restriction, including without limitation the rights to use, copy,
- * modify, merge, publish, distribute, sublicense, and/or sell copies
- * of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be
- * included in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
- * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
- * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- *****************************************************************************/
-
-/**
- * @file libmaple/stm32f1/flash.c
- * @brief Flash management functions
- */
-
-#include <libmaple/flash.h>
-#include <libmaple/bitband.h>
-
-/**
- * @brief Turn on the hardware prefetcher.
- */
-void flash_enable_prefetch(void) {
- *bb_perip(&FLASH_BASE->ACR, FLASH_ACR_PRFTBE_BIT) = 1;
-}
View
8 libmaple/stm32f1/include/series/flash.h
@@ -135,6 +135,14 @@ typedef struct flash_reg_map {
#define FLASH_SAFE_WAIT_STATES FLASH_WAIT_STATE_2
+/* Flash memory features available via ACR */
+enum {
+ FLASH_PREFETCH = 0x10,
+ FLASH_HALF_CYCLE = 0x8,
+ FLASH_ICACHE = 0x0, /* Not available on STM32F1 */
+ FLASH_DCACHE = 0x0, /* Not available on STM32F1 */
+};
+
#ifdef __cplusplus
}
#endif
View
1 libmaple/stm32f1/rules.mk
@@ -12,7 +12,6 @@ sSRCS_$(d) := isrs_performance.S \
vector_table_performance.S
cSRCS_$(d) := rcc.c
-cSRCS_$(d) += flash.c
cSRCS_$(d) += gpio.c
cSRCS_$(d) += bkp.c
View
39 libmaple/stm32f2/flash.c
@@ -1,39 +0,0 @@
-/******************************************************************************
- * The MIT License
- *
- * Copyright (c) 2011 LeafLabs, LLC.
- *
- * Permission is hereby granted, free of charge, to any person
- * obtaining a copy of this software and associated documentation
- * files (the "Software"), to deal in the Software without
- * restriction, including without limitation the rights to use, copy,
- * modify, merge, publish, distribute, sublicense, and/or sell copies
- * of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be
- * included in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
- * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
- * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- *****************************************************************************/
-
-/**
- * @file libmaple/stm32f2/flash.c
- * @brief Flash management functions
- */
-
-#include <libmaple/flash.h>
-
-/**
- * @brief Turn on the instruction prefetcher.
- */
-void flash_enable_prefetch(void) {
- FLASH_BASE->ACR |= FLASH_ACR_PRFTEN;
-}
View
7 libmaple/stm32f2/include/series/flash.h
@@ -189,6 +189,13 @@ typedef struct flash_reg_map {
/* Note that this value depends on a 2.7V--3.6V supply voltage */
#define FLASH_SAFE_WAIT_STATES FLASH_WAIT_STATE_3
+/* Flash memory features available via ACR. */
+enum {
+ FLASH_PREFETCH = 0x100,
+ FLASH_ICACHE = 0x200,
+ FLASH_DCACHE = 0x400,
+};
+
#ifdef __cplusplus
}
#endif
View
1 libmaple/stm32f2/rules.mk
@@ -11,7 +11,6 @@ CFLAGS_$(d) = -I$(d) $(LIBMAPLE_INCLUDES) $(LIBMAPLE_PRIVATE_INCLUDES) -Wall -We
sSRCS_$(d) := isrs.S vector_table.S
cSRCS_$(d) := rcc.c
cSRCS_$(d) += gpio.c
-cSRCS_$(d) += flash.c
sFILES_$(d) := $(sSRCS_$(d):%=$(d)/%)
cFILES_$(d) := $(cSRCS_$(d):%=$(d)/%)

0 comments on commit 0284df5

Please sign in to comment.