aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarti Bolivar <mbolivar@leaflabs.com>2012-04-24 05:01:28 -0400
committerMarti Bolivar <mbolivar@leaflabs.com>2012-04-24 05:01:28 -0400
commit9c8b3225efd5ee816ad840ea97ba7bb92ff17941 (patch)
tree078925a675e51debaf2b2946660e858b9448d543
parent83f361c4bb9bed827b02df7aeae5f2cf9a14707a (diff)
downloadlibrambutan-9c8b3225efd5ee816ad840ea97ba7bb92ff17941.tar.gz
librambutan-9c8b3225efd5ee816ad840ea97ba7bb92ff17941.zip
stm32.h: Various updates, mostly to help STM32F1 line support.
Add STM32_HAVE_USB feature test macro requirement for <series/stm32.h>. This will let us test if we've got a USB peripheral. wirish/stm32f1/boards_setup.cpp is set up to use this when turning on USB CDC ACM support at init() time. Rework the STM32F1 <series/stm32.h> to make it easier to support the various lines that subdivide that series. We don't really support anything besides performance line yet, but there's been enough enthusiasm for value and connectivity line support in the past that these hooks seem worth adding. This means adding an STM32_F1_LINE macro and STM32_F1_LINE_[PERFORMANCE,VALUE,ACCESS,CONNECTIVITY] macros for values that STM32_F1_LINE can take, and generalizing the rest of the file to begin taking this into account. Some TODOs remain, but filling these in is the responsibility of future libmaple porting efforts. One pleasant consequence of the F1 stm32.h rework is that the build system no longer has to tell us what density of F103 we're building for, so remove that from the relevant support/make/board-includes/ files. Add some tweaks to <libmaple/stm32.h> and the STM32F2 stm32.h header to make sure this went through properly, and continues to go through properly in the future.
-rw-r--r--libmaple/include/libmaple/stm32.h12
-rw-r--r--libmaple/stm32f1/include/series/stm32.h100
-rw-r--r--libmaple/stm32f2/include/series/stm32.h1
-rw-r--r--support/make/board-includes/maple.mk2
-rw-r--r--support/make/board-includes/maple_RET6.mk2
-rw-r--r--support/make/board-includes/maple_mini.mk2
-rw-r--r--support/make/board-includes/maple_native.mk2
-rw-r--r--support/make/board-includes/olimex_stm32_h103.mk2
-rw-r--r--wirish/stm32f1/boards_setup.cpp2
9 files changed, 84 insertions, 41 deletions
diff --git a/libmaple/include/libmaple/stm32.h b/libmaple/include/libmaple/stm32.h
index d6f3304..d53af3a 100644
--- a/libmaple/include/libmaple/stm32.h
+++ b/libmaple/include/libmaple/stm32.h
@@ -58,9 +58,21 @@ extern "C" {
*
* - STM32_HAVE_FSMC: 1 if the MCU has the FSMC peripheral, and 0
* otherwise.
+ *
+ * - STM32_HAVE_USB: 1 if the MCU has a USB peripheral, and 0
+ * otherwise.
*/
#include <series/stm32.h>
+/* Ensure the series header isn't broken. */
+#if (!defined(STM32_PCLK1) || !defined(STM32_PCLK2) || \
+ !defined(STM32_MCU_SERIES) || !defined(STM32_NR_INTERRUPTS) || \
+ !defined(STM32_NR_GPIO_PORTS) || !defined(STM32_DELAY_US_MULT) || \
+ !defined(STM32_SRAM_END) || !defined(STM32_HAVE_FSMC) || \
+ !defined(STM32_HAVE_USB))
+#error "Bad STM32F1 configuration. Check <series/stm32.h> header for your MCU."
+#endif
+
#ifdef __DOXYGEN_PREDEFINED_HACK
/*
diff --git a/libmaple/stm32f1/include/series/stm32.h b/libmaple/stm32f1/include/series/stm32.h
index c122df0..eaf9287 100644
--- a/libmaple/stm32f1/include/series/stm32.h
+++ b/libmaple/stm32f1/include/series/stm32.h
@@ -38,6 +38,17 @@ extern "C" {
#define STM32_MCU_SERIES STM32_SERIES_F1
+/* The STM32F1 series is subdivided into "lines". libmaple currently
+ * officially supports STM32F103 performance line MCUs (see the
+ * MCU-specific value section below).
+ *
+ * You can use these F1 line defines if porting libmaple to support
+ * MCUs on other lines. */
+#define STM32_F1_LINE_PERFORMANCE 0
+#define STM32_F1_LINE_VALUE 1
+#define STM32_F1_LINE_ACCESS 2
+#define STM32_F1_LINE_CONNECTIVITY 3
+
/*
* MCU-specific values.
*
@@ -48,23 +59,31 @@ extern "C" {
*/
#if defined(MCU_STM32F103RB)
+# define STM32_F1_LINE STM32_F1_LINE_PERFORMANCE
# define STM32_NR_GPIO_PORTS 4
# define STM32_SRAM_END ((void*)0x20005000)
+# define STM32_MEDIUM_DENSITY
#elif defined(MCU_STM32F103ZE)
+# define STM32_F1_LINE STM32_F1_LINE_PERFORMANCE
# define STM32_NR_GPIO_PORTS 7
# define STM32_SRAM_END ((void*)0x20010000)
+# define STM32_HIGH_DENSITY
#elif defined(MCU_STM32F103CB)
+# define STM32_F1_LINE STM32_F1_LINE_PERFORMANCE
/* This STM32_NR_GPIO_PORTS is not strictly true, but only pins 0
* and exist, and they're used for OSC (e.g. on e.g. LeafLabs
* Maple Mini), so we'll live with this for now. */
# define STM32_NR_GPIO_PORTS 3
# define STM32_SRAM_END ((void*)0x20005000)
+# define STM32_MEDIUM_DENSITY
#elif defined(MCU_STM32F103RE)
+# define STM32_F1_LINE STM32_F1_LINE_PERFORMANCE
# define STM32_NR_GPIO_PORTS 4
# define STM32_SRAM_END ((void*)0x20010000)
+# define STM32_HIGH_DENSITY
#else
#error "Unrecognized STM32F1 MCU, or no MCU specified. Add something like " \
@@ -72,46 +91,65 @@ extern "C" {
#endif
/*
- * Clock configuration.
+ * Derived values.
*/
-#ifndef STM32_PCLK1
-#define STM32_PCLK1 36000000U
-#endif
+#if STM32_F1_LINE == STM32_F1_LINE_PERFORMANCE
+ /* All supported performance line MCUs have a USB peripheral */
+# define STM32_HAVE_USB 1
+
+# ifdef STM32_MEDIUM_DENSITY
+# define STM32_NR_INTERRUPTS 43
+# define STM32_HAVE_FSMC 0
+# elif defined(STM32_HIGH_DENSITY)
+# define STM32_NR_INTERRUPTS 60
+# define STM32_HAVE_FSMC 1
+# endif
+
+#elif STM32_F1_LINE == STM32_F1_LINE_VALUE
+ /* Value line MCUs don't have USB peripherals. */
+# define STM32_HAVE_USB 0
+
+# ifdef STM32_MEDIUM_DENSITY
+# define STM32_NR_INTERRUPTS 56
+# define STM32_HAVE_FSMC 0
+# elif defined(STM32_HIGH_DENSITY)
+ /* 61 interrupts here counts the possibility for a remapped
+ * DMA2 channel 5 IRQ occurring at NVIC index 60. */
+# define STM32_NR_INTERRUPTS 61
+# define STM32_HAVE_FSMC 1
+# endif
-#ifndef STM32_PCLK2
-#define STM32_PCLK2 72000000U
-#endif
-
-#ifndef STM32_DELAY_US_MULT
-#define STM32_DELAY_US_MULT 12 /* FIXME: value is incorrect. */
#endif
/*
- * Density-specific values.
+ * Clock configuration.
+ *
+ * We've currently got values for F103 MCUs operating at the fastest
+ * possible speeds.
+ *
+ * You can patch these for your line, MCU, clock configuration,
+ * etc. here or by setting cflags when compiling libmaple.
*/
-#ifdef STM32_MEDIUM_DENSITY
-# ifndef STM32_NR_INTERRUPTS
-# define STM32_NR_INTERRUPTS 43
-# endif
-
-# ifndef STM32_HAVE_FSMC
-# define STM32_HAVE_FSMC 0
-# endif
-
-#elif defined(STM32_HIGH_DENSITY)
-# ifndef STM32_NR_INTERRUPTS
-# define STM32_NR_INTERRUPTS 60
-# endif
-
-# ifndef STM32_HAVE_FSMC
-# define STM32_HAVE_FSMC 1
-# endif
+#if STM32_F1_LINE == STM32_F1_LINE_PERFORMANCE
+# ifndef STM32_PCLK1
+# define STM32_PCLK1 36000000U
+# endif
+# ifndef STM32_PCLK2
+# define STM32_PCLK2 72000000U
+# endif
+# ifndef STM32_DELAY_US_MULT
+# define STM32_DELAY_US_MULT 12 /* FIXME: value is incorrect. */
+# endif
+#elif STM32_F1_LINE == STM32_F1_LINE_VALUE /* TODO */
+#elif STM32_F1_LINE == STM32_F1_LINE_ACCESS /* TODO */
+#elif STM32_F1_LINE == STM32_F1_LINE_CONNECTIVITY /* TODO */
+#endif
-#else
-#error "Unsupported STM32F1 density, or no density specified. Add something " \
- "like -DSTM32_MEDIUM_DENSITY to your compiler arguments."
+/* Make sure we have the F1-specific defines we need. */
+#if !defined(STM32_F1_LINE)
+#error "Bad STM32F1 configuration. Check STM32F1 <series/stm32.h> header."
#endif
#ifdef __cplusplus
diff --git a/libmaple/stm32f2/include/series/stm32.h b/libmaple/stm32f2/include/series/stm32.h
index 222608d..5ab4c56 100644
--- a/libmaple/stm32f2/include/series/stm32.h
+++ b/libmaple/stm32f2/include/series/stm32.h
@@ -59,6 +59,7 @@ extern "C" {
#define STM32_MCU_SERIES STM32_SERIES_F2
#define STM32_NR_INTERRUPTS 81
#define STM32_HAVE_FSMC 1
+#define STM32_HAVE_USB 1
#if defined(MCU_STM32F207IC) || defined(MCU_STM32F207IG)
# define STM32_NR_GPIO_PORTS 9
diff --git a/support/make/board-includes/maple.mk b/support/make/board-includes/maple.mk
index a84f0ac..d31ad83 100644
--- a/support/make/board-includes/maple.mk
+++ b/support/make/board-includes/maple.mk
@@ -2,6 +2,4 @@ MCU := STM32F103RB
PRODUCT_ID := 0003
ERROR_LED_PORT := GPIOA
ERROR_LED_PIN := 5
-DENSITY := STM32_MEDIUM_DENSITY
-TARGET_FLAGS += -D$(DENSITY)
MCU_SERIES := stm32f1
diff --git a/support/make/board-includes/maple_RET6.mk b/support/make/board-includes/maple_RET6.mk
index 8bd9b90..d06f068 100644
--- a/support/make/board-includes/maple_RET6.mk
+++ b/support/make/board-includes/maple_RET6.mk
@@ -2,6 +2,4 @@ MCU := STM32F103RE
PRODUCT_ID := 0003
ERROR_LED_PORT := GPIOA
ERROR_LED_PIN := 5
-DENSITY := STM32_HIGH_DENSITY
-TARGET_FLAGS += -D$(DENSITY)
MCU_SERIES := stm32f1
diff --git a/support/make/board-includes/maple_mini.mk b/support/make/board-includes/maple_mini.mk
index 4a3e2ab..835adc3 100644
--- a/support/make/board-includes/maple_mini.mk
+++ b/support/make/board-includes/maple_mini.mk
@@ -2,6 +2,4 @@ MCU := STM32F103CB
PRODUCT_ID := 0003
ERROR_LED_PORT := GPIOB
ERROR_LED_PIN := 1
-DENSITY := STM32_MEDIUM_DENSITY
-TARGET_FLAGS += -D$(DENSITY)
MCU_SERIES := stm32f1
diff --git a/support/make/board-includes/maple_native.mk b/support/make/board-includes/maple_native.mk
index cd07c21..3e88e7b 100644
--- a/support/make/board-includes/maple_native.mk
+++ b/support/make/board-includes/maple_native.mk
@@ -2,6 +2,4 @@ MCU := STM32F103ZE
PRODUCT_ID := 0003
ERROR_LED_PORT := GPIOC
ERROR_LED_PIN := 15
-DENSITY := STM32_HIGH_DENSITY
-TARGET_FLAGS += -D$(DENSITY)
MCU_SERIES := stm32f1
diff --git a/support/make/board-includes/olimex_stm32_h103.mk b/support/make/board-includes/olimex_stm32_h103.mk
index 1d84cc2..96d6976 100644
--- a/support/make/board-includes/olimex_stm32_h103.mk
+++ b/support/make/board-includes/olimex_stm32_h103.mk
@@ -2,6 +2,4 @@ MCU := STM32F103RB
PRODUCT_ID := 0003
ERROR_LED_PORT := GPIOC
ERROR_LED_PIN := 12
-DENSITY := STM32_MEDIUM_DENSITY
-TARGET_FLAGS += -D$(DENSITY)
MCU_SERIES := stm32f1
diff --git a/wirish/stm32f1/boards_setup.cpp b/wirish/stm32f1/boards_setup.cpp
index 74c0e79..a71661d 100644
--- a/wirish/stm32f1/boards_setup.cpp
+++ b/wirish/stm32f1/boards_setup.cpp
@@ -87,7 +87,9 @@ namespace wirish {
void board_setup_usb(void) {
#if 0
+# if STM32_HAVE_USB
usb_cdcacm_enable(BOARD_USB_DISC_DEV, BOARD_USB_DISC_BIT);
+# endif
#endif
}