aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.travis.yml8
-rw-r--r--Makefile10
-rw-r--r--docs/source/bootloader.rst2
-rw-r--r--docs/source/conf.py2
-rw-r--r--docs/source/unix-toolchain.rst2
-rw-r--r--libmaple/include/libmaple/i2c.h15
-rw-r--r--libmaple/include/libmaple/nvic.h8
-rw-r--r--libmaple/include/libmaple/stm32.h2
-rw-r--r--libmaple/include/libmaple/systick.h1
-rw-r--r--libmaple/include/libmaple/usb_cdcacm.h2
-rw-r--r--libmaple/stm32f1/include/series/i2c.h13
-rw-r--r--libmaple/stm32f1/include/series/spi.h14
-rw-r--r--libmaple/stm32f2-f4/adc.c (renamed from libmaple/stm32f2/adc.c)0
-rw-r--r--libmaple/stm32f2-f4/dma.c (renamed from libmaple/stm32f2/dma.c)0
-rw-r--r--libmaple/stm32f2-f4/exti.c (renamed from libmaple/stm32f2/exti.c)0
-rw-r--r--libmaple/stm32f2-f4/fsmc.c (renamed from libmaple/stm32f2/fsmc.c)6
-rw-r--r--libmaple/stm32f2-f4/gpio.c (renamed from libmaple/stm32f2/gpio.c)0
-rw-r--r--libmaple/stm32f2-f4/i2c.c99
-rw-r--r--libmaple/stm32f2-f4/include/series/adc.h (renamed from libmaple/stm32f2/include/series/adc.h)0
-rw-r--r--libmaple/stm32f2-f4/include/series/dac.h (renamed from libmaple/stm32f2/include/series/dac.h)0
-rw-r--r--libmaple/stm32f2-f4/include/series/dma.h (renamed from libmaple/stm32f2/include/series/dma.h)0
-rw-r--r--libmaple/stm32f2-f4/include/series/exti.h (renamed from libmaple/stm32f2/include/series/exti.h)0
-rw-r--r--libmaple/stm32f2-f4/include/series/flash.h (renamed from libmaple/stm32f2/include/series/flash.h)4
-rw-r--r--libmaple/stm32f2-f4/include/series/gpio.h (renamed from libmaple/stm32f2/include/series/gpio.h)0
-rw-r--r--libmaple/stm32f2-f4/include/series/i2c.h80
-rw-r--r--libmaple/stm32f2-f4/include/series/nvic.h (renamed from libmaple/stm32f2/include/series/nvic.h)0
-rw-r--r--libmaple/stm32f2-f4/include/series/pwr.h (renamed from libmaple/stm32f2/include/series/pwr.h)0
-rw-r--r--libmaple/stm32f2-f4/include/series/rcc.h (renamed from libmaple/stm32f2/include/series/rcc.h)6
-rw-r--r--libmaple/stm32f2-f4/include/series/spi.h (renamed from libmaple/stm32f2/include/series/spi.h)0
-rw-r--r--libmaple/stm32f2-f4/include/series/stm32.h (renamed from libmaple/stm32f2/include/series/stm32.h)72
-rw-r--r--libmaple/stm32f2-f4/include/series/timer.h (renamed from libmaple/stm32f2/include/series/timer.h)0
-rw-r--r--libmaple/stm32f2-f4/include/series/usart.h (renamed from libmaple/stm32f2/include/series/usart.h)0
-rw-r--r--libmaple/stm32f2-f4/isrs.S (renamed from libmaple/stm32f2/isrs.S)7
-rw-r--r--libmaple/stm32f2-f4/rcc.c (renamed from libmaple/stm32f2/rcc.c)0
-rw-r--r--libmaple/stm32f2-f4/rules.mk (renamed from libmaple/stm32f2/rules.mk)0
-rw-r--r--libmaple/stm32f2-f4/spi.c (renamed from libmaple/stm32f2/spi.c)0
-rw-r--r--libmaple/stm32f2-f4/syscfg.c (renamed from libmaple/stm32f2/syscfg.c)0
-rw-r--r--libmaple/stm32f2-f4/timer.c (renamed from libmaple/stm32f2/timer.c)23
-rw-r--r--libmaple/stm32f2-f4/usart.c (renamed from libmaple/stm32f2/usart.c)6
-rw-r--r--libmaple/stm32f2-f4/vector_table.S (renamed from libmaple/stm32f2/vector_table.S)3
-rw-r--r--notes/boards/st_stm32vldiscovery.txt10
-rw-r--r--notes/usb.txt5
-rw-r--r--support/ld/stm32/mem/sram_64k_flash_128k/mem-jtag.inc5
-rw-r--r--support/ld/stm32/mem/sram_64k_flash_256k/mem-jtag.inc5
-rw-r--r--support/ld/stm32/series/stm32f2-f4/dynamic_efficiency/vector_symbols.inc100
-rw-r--r--support/ld/stm32/series/stm32f2-f4/stm32f2/vector_symbols.inc (renamed from support/ld/stm32/series/stm32f2/vector_symbols.inc)0
-rw-r--r--support/make/board-includes/robotis_cm900.mk (renamed from support/make/board-includes/cm900.mk)0
-rw-r--r--support/make/board-includes/robotis_opencm904.mk (renamed from support/make/board-includes/opencm904.mk)0
-rw-r--r--support/make/board-includes/st_nucleo_f103rb.mk (renamed from support/make/board-includes/nucleo.mk)0
-rw-r--r--support/make/board-includes/st_stm32f401cdiscovery.mk7
-rw-r--r--support/make/board-includes/st_stm32vldiscovery.mk (renamed from support/make/board-includes/VLDiscovery.mk)0
-rw-r--r--support/make/target-config.mk29
-rw-r--r--tests/test-bkp.cpp (renamed from examples/test-bkp.cpp)0
-rw-r--r--tests/test-dac.cpp (renamed from examples/test-dac.cpp)0
-rw-r--r--tests/test-fsmc.cpp (renamed from examples/test-fsmc.cpp)0
-rw-r--r--tests/test-print.cpp (renamed from examples/test-print.cpp)0
-rw-r--r--tests/test-ring-buffer-insertion.cpp (renamed from examples/test-ring-buffer-insertion.cpp)0
-rw-r--r--tests/test-serial-flush.cpp (renamed from examples/test-serial-flush.cpp)0
-rw-r--r--tests/test-serialusb.cpp (renamed from examples/test-serialusb.cpp)0
-rw-r--r--tests/test-servo.cpp (renamed from examples/test-servo.cpp)0
-rw-r--r--tests/test-session.cpp (renamed from examples/test-session.cpp)8
-rw-r--r--tests/test-spi-roundtrip.cpp (renamed from examples/test-spi-roundtrip.cpp)0
-rw-r--r--tests/test-systick.cpp (renamed from examples/test-systick.cpp)0
-rw-r--r--tests/test-timers.cpp (renamed from examples/test-timers.cpp)0
-rw-r--r--tests/test-usart-dma.cpp (renamed from examples/test-usart-dma.cpp)2
-rw-r--r--wirish/HardwareSPI.cpp38
-rw-r--r--wirish/HardwareTimer.cpp18
-rw-r--r--wirish/Print.cpp12
-rw-r--r--wirish/boards.cpp110
-rw-r--r--wirish/boards/robotis_cm900/board.cpp (renamed from wirish/boards/cm900/board.cpp)8
-rw-r--r--wirish/boards/robotis_cm900/include/board/board.h (renamed from wirish/boards/cm900/include/board/board.h)2
-rw-r--r--wirish/boards/robotis_opencm904/board.cpp (renamed from wirish/boards/opencm904/board.cpp)5
-rw-r--r--wirish/boards/robotis_opencm904/include/board/board.h (renamed from wirish/boards/opencm904/include/board/board.h)0
-rw-r--r--wirish/boards/st_nucleo_f103rb/board.cpp (renamed from wirish/boards/nucleo/board.cpp)4
-rw-r--r--wirish/boards/st_nucleo_f103rb/include/board/board.h (renamed from wirish/boards/nucleo/include/board/board.h)6
-rw-r--r--wirish/boards/st_stm32f401cdiscovery/board.cpp177
-rw-r--r--wirish/boards/st_stm32f401cdiscovery/include/board/board.h127
-rw-r--r--wirish/boards/st_stm32vldiscovery/board.cpp (renamed from wirish/boards/VLDiscovery/board.cpp)4
-rw-r--r--wirish/boards/st_stm32vldiscovery/include/board/board.h (renamed from wirish/boards/VLDiscovery/include/board/board.h)4
-rw-r--r--wirish/boards_private.h13
-rw-r--r--wirish/include/wirish/ext_interrupts.h4
-rw-r--r--wirish/include/wirish/wirish.h9
-rw-r--r--wirish/include/wirish/wirish_math.h3
-rw-r--r--wirish/rules.mk33
-rw-r--r--wirish/stm32f2-f4/boards_setup.cpp (renamed from wirish/stm32f2/boards_setup.cpp)69
-rw-r--r--wirish/stm32f2-f4/util_hooks.c (renamed from wirish/stm32f2/util_hooks.c)36
-rw-r--r--wirish/stm32f2-f4/wirish_debug.cpp (renamed from wirish/stm32f2/wirish_debug.cpp)0
-rw-r--r--wirish/stm32f2-f4/wirish_digital.cpp (renamed from wirish/stm32f2/wirish_digital.cpp)0
88 files changed, 1041 insertions, 197 deletions
diff --git a/.travis.yml b/.travis.yml
index 41bd110..35d1e5d 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -6,13 +6,17 @@ before_install:
install:
- sudo apt-get install gcc-arm-none-eabi
before_script:
- - cp examples/test-session.cpp main.cpp
+ - cp tests/test-session.cpp main.cpp
script:
- - make
+ - make jtag
env:
+ - BOARD=maple
- BOARD=maple_mini
+ - BOARD=olimex_stm32_h103
- BOARD=maple_native
- BOARD=st_stm3220g_eval
+ - BOARD=st_stm32f401cdiscovery
matrix:
allow_failures:
- env: BOARD=st_stm3220g_eval
+ - env: BOARD=st_stm32f401cdiscovery
diff --git a/Makefile b/Makefile
index 82ba456..092ebb4 100644
--- a/Makefile
+++ b/Makefile
@@ -20,7 +20,7 @@ LIBRARIES_PATH := $(SRCROOT)/libraries
LDDIR := $(SUPPORT_PATH)/ld
# Support files for this Makefile
MAKEDIR := $(SUPPORT_PATH)/make
-BOARD_INCLUDE_DIR := $(MAKEDIR)/board-includes
+BOARD_INCLUDE_DIR ?= $(MAKEDIR)/board-includes
##
## Target-specific configuration. This determines some compiler and
@@ -66,10 +66,10 @@ GLOBAL_CFLAGS := -Os -g3 -gdwarf-2 -nostdlib \
-DBOOTLOADER_$(BOOTLOADER)
GLOBAL_CXXFLAGS := -fno-rtti -fno-exceptions -Wall $(TARGET_FLAGS)
GLOBAL_ASFLAGS := -x assembler-with-cpp $(TARGET_FLAGS)
-LDFLAGS = $(TARGET_LDFLAGS) $(TOOLCHAIN_LDFLAGS) -mcpu=cortex-m3 -mthumb \
- -Xlinker --gc-sections \
- -Xassembler --march=armv7-m -Wall
-# -Xlinker --print-gc-sections \
+LDFLAGS = $(TARGET_LDFLAGS) $(TOOLCHAIN_LDFLAGS)
+LDFLAGS += -Xlinker --gc-sections
+#LDFLAGS += -Xlinker --print-gc-sections
+LDFLAGS += -Xassembler -Wall
##
## Set all submodules here
diff --git a/docs/source/bootloader.rst b/docs/source/bootloader.rst
index 0896ce3..bff9bb7 100644
--- a/docs/source/bootloader.rst
+++ b/docs/source/bootloader.rst
@@ -695,7 +695,7 @@ port.
could be ``/dev/ttyUSB1``, ``/dev/ttyUSB2``, etc.).
* On **OS X**, ``ser-port`` will probably look like
- ``/dev/tty.usbserialXXXX``, where ``XXXX`` is some random string of
+ ``/dev/tty.usbserialXYZ``, where ``XYZ`` is some random string of
characters.
* On **Windows**, ``ser-port`` will be something like ``COM1``, ``COM2``, etc.
diff --git a/docs/source/conf.py b/docs/source/conf.py
index dc01672..247edbf 100644
--- a/docs/source/conf.py
+++ b/docs/source/conf.py
@@ -61,7 +61,7 @@ copyright = u'2010, 2011, LeafLabs, LLC. 2014 Various Contributors'
version = '0.0'
# The full version, including alpha/beta/rc tags.
# FIXME [RELEASE] update this for the release
-release = 'legacy'
+release = 'prerelease'
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
diff --git a/docs/source/unix-toolchain.rst b/docs/source/unix-toolchain.rst
index 6e20218..2aab7fa 100644
--- a/docs/source/unix-toolchain.rst
+++ b/docs/source/unix-toolchain.rst
@@ -223,7 +223,7 @@ Try using one of these to find out which it is::
To open up a session on Linux or OS X, run ::
- $ screen /dev/ttyXXX
+ $ screen /dev/ttyXYZ
(On Windows, you will need to use a separate program, such as `PuTTY
<http://www.chiark.greenend.org.uk/~sgtatham/putty/>`_.)
diff --git a/libmaple/include/libmaple/i2c.h b/libmaple/include/libmaple/i2c.h
index ff1c313..b198bfa 100644
--- a/libmaple/include/libmaple/i2c.h
+++ b/libmaple/include/libmaple/i2c.h
@@ -47,6 +47,8 @@ extern "C" {
/*
* Series header must provide:
*
+ * - struct i2c_reg_map
+ *
* - uint32 _i2c_bus_clk(i2c_dev*): Clock frequency of dev's bus, in
* MHz. (This is for internal use only).
*
@@ -72,19 +74,6 @@ extern "C" {
#include <libmaple/nvic.h>
#include <libmaple/gpio.h>
-/** I2C register map type */
-typedef struct i2c_reg_map {
- __io uint32 CR1; /**< Control register 1 */
- __io uint32 CR2; /**< Control register 2 */
- __io uint32 OAR1; /**< Own address register 1 */
- __io uint32 OAR2; /**< Own address register 2 */
- __io uint32 DR; /**< Data register */
- __io uint32 SR1; /**< Status register 1 */
- __io uint32 SR2; /**< Status register 2 */
- __io uint32 CCR; /**< Clock control register */
- __io uint32 TRISE; /**< TRISE (rise time) register */
-} i2c_reg_map;
-
/**
* @brief I2C message type
*/
diff --git a/libmaple/include/libmaple/nvic.h b/libmaple/include/libmaple/nvic.h
index ffe385d..3e29f9e 100644
--- a/libmaple/include/libmaple/nvic.h
+++ b/libmaple/include/libmaple/nvic.h
@@ -107,16 +107,12 @@ void nvic_sys_reset();
/**
* Enables interrupts and configurable fault handlers (clear PRIMASK).
*/
-static __always_inline void nvic_globalirq_enable() {
- asm volatile("cpsie i");
-}
+#define nvic_globalirq_enable() do { asm volatile("cpsie i"); } while (0)
/**
* Disable interrupts and configurable fault handlers (set PRIMASK).
*/
-static __always_inline void nvic_globalirq_disable() {
- asm volatile("cpsid i");
-}
+#define nvic_globalirq_disable() do { asm volatile("cpsid i"); } while (0)
/**
* @brief Enable interrupt irq_num
diff --git a/libmaple/include/libmaple/stm32.h b/libmaple/include/libmaple/stm32.h
index 3845cab..5fef820 100644
--- a/libmaple/include/libmaple/stm32.h
+++ b/libmaple/include/libmaple/stm32.h
@@ -69,6 +69,8 @@ extern "C" {
*/
#include <series/stm32.h>
+/* FIXME: need an STM32_USART_MASK to parallel STM32_TIMER_MASK */
+
/* Ensure the series header isn't broken. */
#if (!defined(STM32_PCLK1) || \
!defined(STM32_PCLK2) || \
diff --git a/libmaple/include/libmaple/systick.h b/libmaple/include/libmaple/systick.h
index 551f800..bd8b18f 100644
--- a/libmaple/include/libmaple/systick.h
+++ b/libmaple/include/libmaple/systick.h
@@ -87,6 +87,7 @@ static inline uint32 systick_uptime(void) {
void systick_init(uint32 reload_val);
void systick_disable();
void systick_enable();
+void systick_attach_callback(void (*)(void));
/**
* @brief Returns the current value of the SysTick counter.
diff --git a/libmaple/include/libmaple/usb_cdcacm.h b/libmaple/include/libmaple/usb_cdcacm.h
index 5fe832c..b925883 100644
--- a/libmaple/include/libmaple/usb_cdcacm.h
+++ b/libmaple/include/libmaple/usb_cdcacm.h
@@ -168,7 +168,7 @@ int usb_cdcacm_get_n_data_bits(void); /* bDataBits */
void usb_cdcacm_set_hooks(unsigned hook_flags, void (*hook)(unsigned, void*));
-static __always_inline void usb_cdcacm_remove_hooks(unsigned hook_flags) {
+static inline void usb_cdcacm_remove_hooks(unsigned hook_flags) {
usb_cdcacm_set_hooks(hook_flags, 0);
}
diff --git a/libmaple/stm32f1/include/series/i2c.h b/libmaple/stm32f1/include/series/i2c.h
index f407955..ae05377 100644
--- a/libmaple/stm32f1/include/series/i2c.h
+++ b/libmaple/stm32f1/include/series/i2c.h
@@ -41,7 +41,18 @@
* Register maps
*/
-struct i2c_reg_map;
+/** I2C register map type */
+typedef struct i2c_reg_map {
+ __io uint32 CR1; /**< Control register 1 */
+ __io uint32 CR2; /**< Control register 2 */
+ __io uint32 OAR1; /**< Own address register 1 */
+ __io uint32 OAR2; /**< Own address register 2 */
+ __io uint32 DR; /**< Data register */
+ __io uint32 SR1; /**< Status register 1 */
+ __io uint32 SR2; /**< Status register 2 */
+ __io uint32 CCR; /**< Clock control register */
+ __io uint32 TRISE; /**< TRISE (rise time) register */
+} i2c_reg_map;
/** STM32F1 I2C1 register map base pointer */
#define I2C1_BASE ((struct i2c_reg_map*)0x40005400)
diff --git a/libmaple/stm32f1/include/series/spi.h b/libmaple/stm32f1/include/series/spi.h
index d288a0c..b65111b 100644
--- a/libmaple/stm32f1/include/series/spi.h
+++ b/libmaple/stm32f1/include/series/spi.h
@@ -75,13 +75,13 @@ extern void spi_config_gpios(struct spi_dev*, uint8,
* @brief Deprecated. Use spi_config_gpios() instead.
* @see spi_config_gpios()
*/
-static __always_inline void spi_gpio_cfg(uint8 as_master,
- struct gpio_dev *nss_dev,
- uint8 nss_bit,
- struct gpio_dev *comm_dev,
- uint8 sck_bit,
- uint8 miso_bit,
- uint8 mosi_bit) {
+static inline void spi_gpio_cfg(uint8 as_master,
+ struct gpio_dev *nss_dev,
+ uint8 nss_bit,
+ struct gpio_dev *comm_dev,
+ uint8 sck_bit,
+ uint8 miso_bit,
+ uint8 mosi_bit) {
/* We switched style globally to foo_config_gpios() and always
* taking a foo_dev* argument (that last bit is the important
* part) after this function was written.
diff --git a/libmaple/stm32f2/adc.c b/libmaple/stm32f2-f4/adc.c
index a400d7b..a400d7b 100644
--- a/libmaple/stm32f2/adc.c
+++ b/libmaple/stm32f2-f4/adc.c
diff --git a/libmaple/stm32f2/dma.c b/libmaple/stm32f2-f4/dma.c
index 26e87b9..26e87b9 100644
--- a/libmaple/stm32f2/dma.c
+++ b/libmaple/stm32f2-f4/dma.c
diff --git a/libmaple/stm32f2/exti.c b/libmaple/stm32f2-f4/exti.c
index 208415f..208415f 100644
--- a/libmaple/stm32f2/exti.c
+++ b/libmaple/stm32f2-f4/exti.c
diff --git a/libmaple/stm32f2/fsmc.c b/libmaple/stm32f2-f4/fsmc.c
index ec41720..4ee23fa 100644
--- a/libmaple/stm32f2/fsmc.c
+++ b/libmaple/stm32f2-f4/fsmc.c
@@ -30,6 +30,10 @@
* @brief STM32F2 FSMC support.
*/
+#include <libmaple/stm32.h>
+
+#if STM32_HAVE_FSMC /* Don't try building the rest for MCUs without FSMC */
+
#include <libmaple/fsmc.h>
#include <libmaple/gpio.h>
@@ -88,3 +92,5 @@ void fsmc_sram_init_gpios(void) {
CONFIG_GPIO(GPIOE, 0);
CONFIG_GPIO(GPIOE, 1);
}
+
+#endif /* STM32_HAVE_FSMC */
diff --git a/libmaple/stm32f2/gpio.c b/libmaple/stm32f2-f4/gpio.c
index a26edaa..a26edaa 100644
--- a/libmaple/stm32f2/gpio.c
+++ b/libmaple/stm32f2-f4/gpio.c
diff --git a/libmaple/stm32f2-f4/i2c.c b/libmaple/stm32f2-f4/i2c.c
new file mode 100644
index 0000000..42fd427
--- /dev/null
+++ b/libmaple/stm32f2-f4/i2c.c
@@ -0,0 +1,99 @@
+/******************************************************************************
+ * The MIT License
+ *
+ * Copyright (c) 2012 LeafLabs, LLC.
+ * Copyright (c) 2014 Google, Inc.
+ *
+ * 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.
+ *****************************************************************************/
+
+#include "i2c_private.h"
+#include <libmaple/i2c.h>
+
+/*
+ * Devices
+ */
+
+static i2c_dev i2c1 = I2C_DEV_NEW(1, &gpiob, 7, &gpiob, 6);
+static i2c_dev i2c2 = I2C_DEV_NEW(1, &gpioh, 5, &gpioh, 4);
+static i2c_dev i2c3 = I2C_DEV_NEW(1, &gpioh, 8, &gpioh, 7);
+
+/** I2C1 device */
+i2c_dev* const I2C1 = &i2c1;
+/** I2C2 device */
+i2c_dev* const I2C2 = &i2c2;
+/** I2C3 device */
+i2c_dev* const I2C3 = &i2c3;
+
+/*
+ * libmaple routines
+ */
+
+#define I2C_MODEF_FLAGS (GPIO_MODEF_TYPE_OD | GPIO_MODEF_SPEED_HIGH | \
+ GPIO_MODEF_PUPD_PU)
+
+void i2c_config_gpios(const i2c_dev *dev) {
+ /* Untested... */
+ gpio_set_modef(sda_port(dev), dev->sda_pin, GPIO_MODE_AF, I2C_MODEF_FLAGS);
+ gpio_set_modef(scl_port(dev), dev->scl_pin, GPIO_MODE_AF, I2C_MODEF_FLAGS);
+ gpio_set_af(sda_port(dev), dev->sda_pin, GPIO_AF_I2C);
+ gpio_set_af(scl_port(dev), dev->scl_pin, GPIO_AF_I2C);
+}
+
+void i2c_master_release_bus(const i2c_dev *dev) {
+ /* Untested... */
+ unsigned flags = (GPIO_MODEF_TYPE_OD | GPIO_MODEF_SPEED_HIGH |
+ GPIO_MODEF_PUPD_PU);
+ gpio_write_bit(scl_port(dev), dev->scl_pin, 1);
+ gpio_write_bit(sda_port(dev), dev->sda_pin, 1);
+ gpio_set_modef(scl_port(dev), dev->scl_pin, GPIO_MODE_OUTPUT,
+ I2C_MODEF_FLAGS);
+ gpio_set_modef(sda_port(dev), dev->sda_pin, GPIO_MODE_OUTPUT,
+ I2C_MODEF_FLAGS);
+}
+
+/*
+ * IRQ Handlers
+ */
+
+void __irq_i2c1_ev(void) {
+ _i2c_irq_handler(I2C1);
+}
+
+void __irq_i2c2_ev(void) {
+ _i2c_irq_handler(I2C2);
+}
+
+void __irq_i2c3_ev(void) {
+ _i2c_irq_handler(I2C3);
+}
+
+void __irq_i2c1_er(void) {
+ _i2c_irq_error_handler(I2C1);
+}
+
+void __irq_i2c2_er(void) {
+ _i2c_irq_error_handler(I2C2);
+}
+
+void __irq_i2c3_er(void) {
+ _i2c_irq_error_handler(I2C3);
+}
diff --git a/libmaple/stm32f2/include/series/adc.h b/libmaple/stm32f2-f4/include/series/adc.h
index 175fe11..175fe11 100644
--- a/libmaple/stm32f2/include/series/adc.h
+++ b/libmaple/stm32f2-f4/include/series/adc.h
diff --git a/libmaple/stm32f2/include/series/dac.h b/libmaple/stm32f2-f4/include/series/dac.h
index 0a578ca..0a578ca 100644
--- a/libmaple/stm32f2/include/series/dac.h
+++ b/libmaple/stm32f2-f4/include/series/dac.h
diff --git a/libmaple/stm32f2/include/series/dma.h b/libmaple/stm32f2-f4/include/series/dma.h
index 43bd1a2..43bd1a2 100644
--- a/libmaple/stm32f2/include/series/dma.h
+++ b/libmaple/stm32f2-f4/include/series/dma.h
diff --git a/libmaple/stm32f2/include/series/exti.h b/libmaple/stm32f2-f4/include/series/exti.h
index 4643fcf..4643fcf 100644
--- a/libmaple/stm32f2/include/series/exti.h
+++ b/libmaple/stm32f2-f4/include/series/exti.h
diff --git a/libmaple/stm32f2/include/series/flash.h b/libmaple/stm32f2-f4/include/series/flash.h
index a3c3933..1da55cd 100644
--- a/libmaple/stm32f2/include/series/flash.h
+++ b/libmaple/stm32f2-f4/include/series/flash.h
@@ -186,7 +186,11 @@ typedef struct flash_reg_map {
*/
/* Note that this value depends on a 2.7V--3.6V supply voltage */
+#if STM32_MCU_SERIES == STM32_SERIES_F4
+#define FLASH_SAFE_WAIT_STATES FLASH_WAIT_STATE_2
+#else
#define FLASH_SAFE_WAIT_STATES FLASH_WAIT_STATE_3
+#endif
/* Flash memory features available via ACR. */
enum {
diff --git a/libmaple/stm32f2/include/series/gpio.h b/libmaple/stm32f2-f4/include/series/gpio.h
index 4d0d98c..4d0d98c 100644
--- a/libmaple/stm32f2/include/series/gpio.h
+++ b/libmaple/stm32f2-f4/include/series/gpio.h
diff --git a/libmaple/stm32f2-f4/include/series/i2c.h b/libmaple/stm32f2-f4/include/series/i2c.h
new file mode 100644
index 0000000..b231256
--- /dev/null
+++ b/libmaple/stm32f2-f4/include/series/i2c.h
@@ -0,0 +1,80 @@
+/******************************************************************************
+ * The MIT License
+ *
+ * Copyright (c) 2010 Perry Hung (from <libmaple/i2c.h>).
+ * Copyright (c) 2012 LeafLabs, LLC.
+ * Copyright (c) 2014 Google, Inc.
+ *
+ * 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.
+ *****************************************************************************/
+
+#ifndef _LIBMAPLE_STM32F2_I2C_H_
+#define _LIBMAPLE_STM32F2_I2C_H_
+
+#include <libmaple/i2c_common.h>
+#include <libmaple/stm32.h>
+
+/*
+ * Register maps
+ */
+
+/** I2C register map type */
+typedef struct i2c_reg_map {
+ __io uint32 CR1; /**< Control register 1 */
+ __io uint32 CR2; /**< Control register 2 */
+ __io uint32 OAR1; /**< Own address register 1 */
+ __io uint32 OAR2; /**< Own address register 2 */
+ __io uint32 DR; /**< Data register */
+ __io uint32 SR1; /**< Status register 1 */
+ __io uint32 SR2; /**< Status register 2 */
+ __io uint32 CCR; /**< Clock control register */
+ __io uint32 TRISE; /**< TRISE (rise time) register */
+ __io uint32 FLTR; /**< Noise filter register */
+} i2c_reg_map;
+
+/** I2C1 register map base pointer */
+#define I2C1_BASE ((struct i2c_reg_map*)0x40005400)
+/** I2C2 register map base pointer */
+#define I2C2_BASE ((struct i2c_reg_map*)0x40005800)
+/** I2C3 register map base pointer */
+#define I2C3_BASE ((struct i2c_reg_map*)0x40005C00)
+
+/*
+ * Devices
+ */
+
+extern i2c_dev* const I2C1;
+extern i2c_dev* const I2C2;
+extern i2c_dev* const I2C3;
+
+/*
+ * For internal use
+ */
+
+static inline uint32 _i2c_bus_clk(i2c_dev *dev) {
+ /* All the I2C peripherals are on APB1 */
+ return STM32_PCLK1 / (1000 * 1000);
+}
+
+#undef _I2C_HAVE_IRQ_FIXUP
+#undef _I2C_HAVE_DEPRECATED_I2C_REMAP
+
+#endif /* _LIBMAPLE_STM32F1_I2C_H_ */
diff --git a/libmaple/stm32f2/include/series/nvic.h b/libmaple/stm32f2-f4/include/series/nvic.h
index dc03806..dc03806 100644
--- a/libmaple/stm32f2/include/series/nvic.h
+++ b/libmaple/stm32f2-f4/include/series/nvic.h
diff --git a/libmaple/stm32f2/include/series/pwr.h b/libmaple/stm32f2-f4/include/series/pwr.h
index 96353a4..96353a4 100644
--- a/libmaple/stm32f2/include/series/pwr.h
+++ b/libmaple/stm32f2-f4/include/series/pwr.h
diff --git a/libmaple/stm32f2/include/series/rcc.h b/libmaple/stm32f2-f4/include/series/rcc.h
index 441a5a8..7cb7df1 100644
--- a/libmaple/stm32f2/include/series/rcc.h
+++ b/libmaple/stm32f2-f4/include/series/rcc.h
@@ -128,7 +128,11 @@ typedef struct rcc_reg_map {
#define RCC_PLLCFGR_PLLSRC_HSE (0x1 << RCC_PLLCFGR_PLLSRC_BIT)
#define RCC_PLLCFGR_PLLP (0x3 << 16)
#define RCC_PLLCFGR_PLLN (0x1FF << 6)
-#define RCC_PLLCFGR_PLLM 0x1F
+#if STM32_MCU_SERIES == STM32_SERIES_F4
+# define RCC_PLLCFGR_PLLM 0x3F
+#else
+# define RCC_PLLCFGR_PLLM 0x1F
+#endif
/* Clock configuration register */
diff --git a/libmaple/stm32f2/include/series/spi.h b/libmaple/stm32f2-f4/include/series/spi.h
index 7b9f94a..7b9f94a 100644
--- a/libmaple/stm32f2/include/series/spi.h
+++ b/libmaple/stm32f2-f4/include/series/spi.h
diff --git a/libmaple/stm32f2/include/series/stm32.h b/libmaple/stm32f2-f4/include/series/stm32.h
index 180ab30..c2ad2f2 100644
--- a/libmaple/stm32f2/include/series/stm32.h
+++ b/libmaple/stm32f2-f4/include/series/stm32.h
@@ -37,37 +37,69 @@ extern "C" {
#endif
/*
- * Chip configuration
+ * MCU-specific values
*/
+#if defined(MCU_STM32F207IC) || defined(MCU_STM32F207IG)
+# define STM32_MCU_SERIES STM32_SERIES_F2
+# define STM32_NR_GPIO_PORTS 9
+# define STM32_TIMER_MASK 0x7FFE /* TIMER1-TIMER14. */
+# define STM32_SRAM_END ((void*)0x20020000)
+#elif defined(MCU_STM32F401VC)
+# define STM32_MCU_SERIES STM32_SERIES_F4
+# define STM32_NR_GPIO_PORTS 5
+# define STM32_TIMER_MASK 0x3E
+/* TODO: This value for STM32_SRAM_END is very generous */
+# define STM32_SRAM_END ((void*)0x20020000)
+#elif defined(MCU_STM32F401CC)
+# define STM32_MCU_SERIES STM32_SERIES_F4
+# define STM32_NR_GPIO_PORTS 3
+# define STM32_TIMER_MASK 0x3E
+# define STM32_SRAM_END ((void*)0x20010000)
+#else
+#warning "Unsupported or unspecified STM32F2 MCU."
+#endif
+
+/*
+ * Series-specific values
+ */
+
+#if STM32_MCU_SERIES == STM32_SERIES_F2
+# define STM32_NR_INTERRUPTS 81
+# define STM32_HAVE_FSMC 1
+# define STM32_HAVE_USB 1
+# define STM32_HAVE_DAC 1
+
+# ifndef STM32_PCLK1
+# define STM32_PCLK1 30000000U
+# endif
+
+# ifndef STM32_PCLK2
+# define STM32_PCLK2 60000000U
+# endif
+
+# ifndef STM32_DELAY_US_MULT
+# define STM32_DELAY_US_MULT 20 /* FIXME: dummy value. */
+# endif
+#elif STM32_MCU_SERIES == STM32_SERIES_F4
+# define STM32_NR_INTERRUPTS 84
+# define STM32_HAVE_FSMC 0
+# define STM32_HAVE_USB 0
+# define STM32_HAVE_DAC 0
+
#ifndef STM32_PCLK1
-#define STM32_PCLK1 30000000U
+#define STM32_PCLK1 42000000U
#endif
#ifndef STM32_PCLK2
-#define STM32_PCLK2 60000000U
+#define STM32_PCLK2 84000000U
#endif
#ifndef STM32_DELAY_US_MULT
-#define STM32_DELAY_US_MULT 20 /* FIXME: dummy value. */
+#define STM32_DELAY_US_MULT 28 /* CYCLES_PER_MICROSECOND/3 */
#endif
-
-/*
- * Series- and MCU-specific values
- */
-
-#define STM32_MCU_SERIES STM32_SERIES_F2
-#define STM32_NR_INTERRUPTS 81
-#define STM32_HAVE_FSMC 1
-#define STM32_HAVE_USB 1
-#define STM32_HAVE_DAC 1
-
-#if defined(MCU_STM32F207IC) || defined(MCU_STM32F207IG)
-# define STM32_NR_GPIO_PORTS 9
-# define STM32_TIMER_MASK 0x7FFE /* TIMER1-TIMER14. */
-# define STM32_SRAM_END ((void*)0x20020000)
#else
-#warning "Unsupported or unspecified STM32F2 MCU."
+# error "Invalid STM32 series for this header"
#endif
#ifdef __cplusplus
diff --git a/libmaple/stm32f2/include/series/timer.h b/libmaple/stm32f2-f4/include/series/timer.h
index a7ac276..a7ac276 100644
--- a/libmaple/stm32f2/include/series/timer.h
+++ b/libmaple/stm32f2-f4/include/series/timer.h
diff --git a/libmaple/stm32f2/include/series/usart.h b/libmaple/stm32f2-f4/include/series/usart.h
index 8936efa..8936efa 100644
--- a/libmaple/stm32f2/include/series/usart.h
+++ b/libmaple/stm32f2-f4/include/series/usart.h
diff --git a/libmaple/stm32f2/isrs.S b/libmaple/stm32f2-f4/isrs.S
index 5baaf8b..cda627a 100644
--- a/libmaple/stm32f2/isrs.S
+++ b/libmaple/stm32f2-f4/isrs.S
@@ -320,3 +320,10 @@ __default_handler:
.weak __irq_hash_rng
.globl __irq_hash_rng
.set __irq_hash_rng, __default_handler
+/* STM32F4 Specific */
+ .weak __irq_fpu
+ .globl __irq_fpu
+ .set __irq_fpu, __default_handler
+ .weak __irq_spi4
+ .globl __irq_spi4
+ .set __irq_spi4, __default_handler
diff --git a/libmaple/stm32f2/rcc.c b/libmaple/stm32f2-f4/rcc.c
index 7fc7eb0..7fc7eb0 100644
--- a/libmaple/stm32f2/rcc.c
+++ b/libmaple/stm32f2-f4/rcc.c
diff --git a/libmaple/stm32f2/rules.mk b/libmaple/stm32f2-f4/rules.mk
index 4c62cc2..4c62cc2 100644
--- a/libmaple/stm32f2/rules.mk
+++ b/libmaple/stm32f2-f4/rules.mk
diff --git a/libmaple/stm32f2/spi.c b/libmaple/stm32f2-f4/spi.c
index cfd9995..cfd9995 100644
--- a/libmaple/stm32f2/spi.c
+++ b/libmaple/stm32f2-f4/spi.c
diff --git a/libmaple/stm32f2/syscfg.c b/libmaple/stm32f2-f4/syscfg.c
index 19e932e..19e932e 100644
--- a/libmaple/stm32f2/syscfg.c
+++ b/libmaple/stm32f2-f4/syscfg.c
diff --git a/libmaple/stm32f2/timer.c b/libmaple/stm32f2-f4/timer.c
index a85bea0..4ef466a 100644
--- a/libmaple/stm32f2/timer.c
+++ b/libmaple/stm32f2-f4/timer.c
@@ -31,6 +31,7 @@
*/
#include <libmaple/timer.h>
+#include <libmaple/stm32.h>
#include "timer_private.h"
/*
@@ -85,17 +86,23 @@ gpio_af timer_get_af(timer_dev *dev) {
void __irq_tim1_brk_tim9(void) {
dispatch_adv_brk(TIMER1);
+#if STM32_HAVE_TIMER(9)
dispatch_tim_9_12(TIMER9);
+#endif
}
void __irq_tim1_up_tim10(void) {
dispatch_adv_up(TIMER1);
+#if STM32_HAVE_TIMER(10)
dispatch_tim_10_11_13_14(TIMER10);
+#endif
}
void __irq_tim1_trg_com_tim11(void) {
dispatch_adv_trg_com(TIMER1);
+#if STM32_HAVE_TIMER(11)
dispatch_tim_10_11_13_14(TIMER11);
+#endif
}
void __irq_tim1_cc(void) {
@@ -125,24 +132,40 @@ void __irq_tim6(void) {
}
void __irq_tim7(void) {
+#if STM32_HAVE_TIMER(7)
dispatch_basic(TIMER7);
+#endif
}
void __irq_tim8_brk_tim12(void) {
+#if STM32_HAVE_TIMER(8)
dispatch_adv_brk(TIMER8);
+#endif
+#if STM32_HAVE_TIMER(12)
dispatch_tim_9_12(TIMER12);
+#endif
}
void __irq_tim8_up_tim13(void) {
+#if STM32_HAVE_TIMER(8)
dispatch_adv_up(TIMER8);
+#endif
+#if STM32_HAVE_TIMER(13)
dispatch_tim_10_11_13_14(TIMER13);
+#endif
}
void __irq_tim8_trg_com_tim14(void) {
+#if STM32_HAVE_TIMER(8)
dispatch_adv_trg_com(TIMER8);
+#endif
+#if STM32_HAVE_TIMER(14)
dispatch_tim_10_11_13_14(TIMER14);
+#endif
}
void __irq_tim8_cc(void) {
+#if STM32_HAVE_TIMER(8)
dispatch_adv_cc(TIMER8);
+#endif
}
diff --git a/libmaple/stm32f2/usart.c b/libmaple/stm32f2-f4/usart.c
index 1472d13..fce122f 100644
--- a/libmaple/stm32f2/usart.c
+++ b/libmaple/stm32f2-f4/usart.c
@@ -42,7 +42,7 @@ static ring_buffer usart1_rb;
static usart_dev usart1 = {
.regs = USART1_BASE,
.rb = &usart1_rb,
- .max_baud = 4500000UL, /* TODO: are these correct? */
+ .max_baud = 4500000UL, /* TODO: are these correct? 5250000UL for STM32F4? */
.clk_id = RCC_USART1,
.irq_num = NVIC_USART1,
};
@@ -53,7 +53,7 @@ static ring_buffer usart2_rb;
static usart_dev usart2 = {
.regs = USART2_BASE,
.rb = &usart2_rb,
- .max_baud = 2250000UL, /* TODO: are these correct? */
+ .max_baud = 2250000UL, /* TODO: are these correct? 2620000UL for STM32F4? */
.clk_id = RCC_USART2,
.irq_num = NVIC_USART2,
};
@@ -97,7 +97,7 @@ static ring_buffer usart6_rb;
static usart_dev usart6 = {
.regs = USART6_BASE,
.rb = &usart6_rb,
- .max_baud = 4500000UL, /* TODO: are these correct? */
+ .max_baud = 4500000UL, /* TODO: are these correct? 5250000UL for STM32F4? */
.clk_id = RCC_USART6,
.irq_num = NVIC_USART6,
};
diff --git a/libmaple/stm32f2/vector_table.S b/libmaple/stm32f2-f4/vector_table.S
index 147e516..752503b 100644
--- a/libmaple/stm32f2/vector_table.S
+++ b/libmaple/stm32f2-f4/vector_table.S
@@ -131,5 +131,8 @@ __stm32_vector_table:
.long __irq_dcmi
.long __irq_cryp
.long __irq_hash_rng
+/* STM32F4-specific */
+ .long __irq_fpu
+ .long __irq_spi4
.size __stm32_vector_table, . - __stm32_vector_table
diff --git a/notes/boards/st_stm32vldiscovery.txt b/notes/boards/st_stm32vldiscovery.txt
new file mode 100644
index 0000000..3aa849d
--- /dev/null
+++ b/notes/boards/st_stm32vldiscovery.txt
@@ -0,0 +1,10 @@
+
+STM32VLDISCOVERY: STM32 value line Discovery
+
+User Manual:
+http://www.st.com/st-web-ui/static/active/en/resource/technical/document/user_manual/CD00267113.pdf
+
+STM32F100RBT6B microcontroller, 128 KB Flash, 8 KB RAM in 64-pin LQFP
+ST-LINK
+
+Two buttons (reset and user), two LEDs, that's it.
diff --git a/notes/usb.txt b/notes/usb.txt
index 9552b9f..c97c9b5 100644
--- a/notes/usb.txt
+++ b/notes/usb.txt
@@ -1,6 +1,5 @@
-XXX
-XXX This file may be out of date!
-XXX
+
+WARNING: This file may be out of date!
[NOTE: this is a long term proposal. The current implementation just does a
2ms TIMEOUT]
diff --git a/support/ld/stm32/mem/sram_64k_flash_128k/mem-jtag.inc b/support/ld/stm32/mem/sram_64k_flash_128k/mem-jtag.inc
new file mode 100644
index 0000000..e5a30cb
--- /dev/null
+++ b/support/ld/stm32/mem/sram_64k_flash_128k/mem-jtag.inc
@@ -0,0 +1,5 @@
+MEMORY
+{
+ ram (rwx) : ORIGIN = 0x20000000, LENGTH = 64K
+ rom (rx) : ORIGIN = 0x08000000, LENGTH = 128K
+}
diff --git a/support/ld/stm32/mem/sram_64k_flash_256k/mem-jtag.inc b/support/ld/stm32/mem/sram_64k_flash_256k/mem-jtag.inc
new file mode 100644
index 0000000..1e82e56
--- /dev/null
+++ b/support/ld/stm32/mem/sram_64k_flash_256k/mem-jtag.inc
@@ -0,0 +1,5 @@
+MEMORY
+{
+ ram (rwx) : ORIGIN = 0x20000000, LENGTH = 64K
+ rom (rx) : ORIGIN = 0x08000000, LENGTH = 256K
+}
diff --git a/support/ld/stm32/series/stm32f2-f4/dynamic_efficiency/vector_symbols.inc b/support/ld/stm32/series/stm32f2-f4/dynamic_efficiency/vector_symbols.inc
new file mode 100644
index 0000000..c013784
--- /dev/null
+++ b/support/ld/stm32/series/stm32f2-f4/dynamic_efficiency/vector_symbols.inc
@@ -0,0 +1,100 @@
+EXTERN(__msp_init)
+EXTERN(__exc_reset)
+EXTERN(__exc_nmi)
+EXTERN(__exc_hardfault)
+EXTERN(__exc_memmanage)
+EXTERN(__exc_busfault)
+EXTERN(__exc_usagefault)
+EXTERN(__stm32reservedexception7)
+EXTERN(__stm32reservedexception8)
+EXTERN(__stm32reservedexception9)
+EXTERN(__stm32reservedexception10)
+EXTERN(__exc_svc)
+EXTERN(__exc_debug_monitor)
+EXTERN(__stm32reservedexception13)
+EXTERN(__exc_pendsv)
+EXTERN(__exc_systick)
+
+EXTERN(__irq_wwdg)
+EXTERN(__irq_pvd)
+EXTERN(__irq_tamp_stamp)
+EXTERN(__irq_rtc_wkup)
+EXTERN(__irq_flash)
+EXTERN(__irq_rcc)
+EXTERN(__irq_exti0)
+EXTERN(__irq_exti1)
+EXTERN(__irq_exti2)
+EXTERN(__irq_exti3)
+EXTERN(__irq_exti4)
+EXTERN(__irq_dma1_stream0)
+EXTERN(__irq_dma1_stream1)
+EXTERN(__irq_dma1_stream2)
+EXTERN(__irq_dma1_stream3)
+EXTERN(__irq_dma1_stream4)
+EXTERN(__irq_dma1_stream5)
+EXTERN(__irq_dma1_stream6)
+EXTERN(__irq_adc)
+EXTERN(__irq_can1_tx)
+EXTERN(__irq_can1_rx0)
+EXTERN(__irq_can1_rx1)
+EXTERN(__irq_can1_sce)
+EXTERN(__irq_exti9_5)
+EXTERN(__irq_tim1_brk_tim9)
+EXTERN(__irq_tim1_up_tim10)
+EXTERN(__irq_tim1_trg_com_tim11)
+EXTERN(__irq_tim1_cc)
+EXTERN(__irq_tim2)
+EXTERN(__irq_tim3)
+EXTERN(__irq_tim4)
+EXTERN(__irq_i2c1_ev)
+EXTERN(__irq_i2c1_er)
+EXTERN(__irq_i2c2_ev)
+EXTERN(__irq_i2c2_er)
+EXTERN(__irq_spi1)
+EXTERN(__irq_spi2)
+EXTERN(__irq_usart1)
+EXTERN(__irq_usart2)
+EXTERN(__irq_usart3)
+EXTERN(__irq_exti15_10)
+EXTERN(__irq_rtc_alarm)
+EXTERN(__irq_otg_fs_wkup)
+EXTERN(__irq_tim8_brk_tim12)
+EXTERN(__irq_tim8_up_tim13)
+EXTERN(__irq_tim8_trg_com_tim14)
+EXTERN(__irq_tim8_cc)
+EXTERN(__irq_dma1_stream7)
+EXTERN(__irq_fsmc)
+EXTERN(__irq_sdio)
+EXTERN(__irq_tim5)
+EXTERN(__irq_spi3)
+EXTERN(__irq_uart4)
+EXTERN(__irq_uart5)
+EXTERN(__irq_tim6_dac)
+EXTERN(__irq_tim7)
+EXTERN(__irq_dma2_stream0)
+EXTERN(__irq_dma2_stream1)
+EXTERN(__irq_dma2_stream2)
+EXTERN(__irq_dma2_stream3)
+EXTERN(__irq_dma2_stream4)
+EXTERN(__irq_eth)
+EXTERN(__irq_eth_wkup)
+EXTERN(__irq_can2_tx)
+EXTERN(__irq_can2_rx0)
+EXTERN(__irq_can2_rx1)
+EXTERN(__irq_can2_sce)
+EXTERN(__irq_otg_fs)
+EXTERN(__irq_dma2_stream5)
+EXTERN(__irq_dma2_stream6)
+EXTERN(__irq_dma2_stream7)
+EXTERN(__irq_usart6)
+EXTERN(__irq_i2c3_ev)
+EXTERN(__irq_i2c3_er)
+EXTERN(__irq_otg_hs_ep1_out)
+EXTERN(__irq_otg_hs_ep1_in)
+EXTERN(__irq_otg_hs_wkup)
+EXTERN(__irq_otg_hs)
+EXTERN(__irq_dcmi)
+EXTERN(__irq_cryp)
+EXTERN(__irq_hash_rng)
+EXTERN(__irq_fpu)
+EXTERN(__irq_spi4)
diff --git a/support/ld/stm32/series/stm32f2/vector_symbols.inc b/support/ld/stm32/series/stm32f2-f4/stm32f2/vector_symbols.inc
index d275ec3..d275ec3 100644
--- a/support/ld/stm32/series/stm32f2/vector_symbols.inc
+++ b/support/ld/stm32/series/stm32f2-f4/stm32f2/vector_symbols.inc
diff --git a/support/make/board-includes/cm900.mk b/support/make/board-includes/robotis_cm900.mk
index 9f70a1b..9f70a1b 100644
--- a/support/make/board-includes/cm900.mk
+++ b/support/make/board-includes/robotis_cm900.mk
diff --git a/support/make/board-includes/opencm904.mk b/support/make/board-includes/robotis_opencm904.mk
index 64d3351..64d3351 100644
--- a/support/make/board-includes/opencm904.mk
+++ b/support/make/board-includes/robotis_opencm904.mk
diff --git a/support/make/board-includes/nucleo.mk b/support/make/board-includes/st_nucleo_f103rb.mk
index a2943ce..a2943ce 100644
--- a/support/make/board-includes/nucleo.mk
+++ b/support/make/board-includes/st_nucleo_f103rb.mk
diff --git a/support/make/board-includes/st_stm32f401cdiscovery.mk b/support/make/board-includes/st_stm32f401cdiscovery.mk
new file mode 100644
index 0000000..6eb584f
--- /dev/null
+++ b/support/make/board-includes/st_stm32f401cdiscovery.mk
@@ -0,0 +1,7 @@
+MCU := STM32F401VC
+PRODUCT_ID := 0003
+ERROR_LED_PORT := GPIOD
+ERROR_LED_PIN := 12
+MCU_SERIES := stm32f4
+MCU_F4_LINE := dynamic_efficiency
+LD_MEM_DIR := sram_64k_flash_256k
diff --git a/support/make/board-includes/VLDiscovery.mk b/support/make/board-includes/st_stm32vldiscovery.mk
index 76cd85a..76cd85a 100644
--- a/support/make/board-includes/VLDiscovery.mk
+++ b/support/make/board-includes/st_stm32vldiscovery.mk
diff --git a/support/make/target-config.mk b/support/make/target-config.mk
index 0e3a2c2..68cddbf 100644
--- a/support/make/target-config.mk
+++ b/support/make/target-config.mk
@@ -24,31 +24,42 @@ include $(BOARD_INCLUDE_DIR)/$(BOARD).mk
# Configuration derived from $(BOARD).mk
-LD_SERIES_PATH := $(LDDIR)/stm32/series/$(MCU_SERIES)
+TARGET_SERIES_MODULE := $(MCU_SERIES)
+
+# Override TARGET_SERIES_MODULE for STM32F2 and STM32F4, which are
+# basically the same and thus share a module.
+ifeq ($(MCU_SERIES), stm32f2)
+TARGET_SERIES_MODULE := stm32f2-f4
+endif
+ifeq ($(MCU_SERIES), stm32f4)
+TARGET_SERIES_MODULE := stm32f2-f4
+endif
+
+LIBMAPLE_MODULE_SERIES := $(LIBMAPLE_PATH)/$(TARGET_SERIES_MODULE)
+LD_SERIES_PATH := $(LDDIR)/stm32/series/$(TARGET_SERIES_MODULE)
LD_MEM_PATH := $(LDDIR)/stm32/mem/$(LD_MEM_DIR)
+
ifeq ($(MCU_SERIES), stm32f1)
+TARGET_FLAGS += -mcpu=cortex-m3 -march=armv7-m
# Due to the Balkanization on F1, we need to specify the line when
# making linker decisions.
LD_SERIES_PATH := $(LD_SERIES_PATH)/$(MCU_F1_LINE)
endif
-
-ifeq ($(MCU_SERIES), stm32f1)
-TARGET_FLAGS += -mcpu=cortex-m3 -march=armv7-m
-endif
ifeq ($(MCU_SERIES), stm32f2)
+LD_SERIES_PATH := $(LD_SERIES_PATH)/stm32f2
TARGET_FLAGS += -mcpu=cortex-m3 -march=armv7-m
endif
ifeq ($(MCU_SERIES), stm32f4)
-TARGET_FLAGS += -mcpu=cortex-m4 -march=armv7e-m -mfloat-abi=hard -mfpu=fpv4-sp-d16
+LD_SERIES_PATH := $(LD_SERIES_PATH)/$(MCU_F4_LINE)
+TARGET_FLAGS += -mcpu=cortex-m4 -march=armv7e-m -mfloat-abi=hard \
+ -mfpu=fpv4-sp-d16 -fsingle-precision-constant -Wdouble-promotion
endif
TARGET_LDFLAGS += -Xlinker -T$(LD_SCRIPT_PATH) \
-L $(LD_SERIES_PATH) \
-L $(LD_MEM_PATH) \
- -L $(LDDIR)
+ -L $(LDDIR) $(TARGET_FLAGS) -mthumb
TARGET_FLAGS += -mthumb -DBOARD_$(BOARD) -DMCU_$(MCU) \
-DERROR_LED_PORT=$(ERROR_LED_PORT) \
-DERROR_LED_PIN=$(ERROR_LED_PIN) \
-D$(VECT_BASE_ADDR)
-
-LIBMAPLE_MODULE_SERIES := $(LIBMAPLE_PATH)/$(MCU_SERIES)
diff --git a/examples/test-bkp.cpp b/tests/test-bkp.cpp
index 719cac7..719cac7 100644
--- a/examples/test-bkp.cpp
+++ b/tests/test-bkp.cpp
diff --git a/examples/test-dac.cpp b/tests/test-dac.cpp
index af188cc..af188cc 100644
--- a/examples/test-dac.cpp
+++ b/tests/test-dac.cpp
diff --git a/examples/test-fsmc.cpp b/tests/test-fsmc.cpp
index 1621317..1621317 100644
--- a/examples/test-fsmc.cpp
+++ b/tests/test-fsmc.cpp
diff --git a/examples/test-print.cpp b/tests/test-print.cpp
index bdc1894..bdc1894 100644
--- a/examples/test-print.cpp
+++ b/tests/test-print.cpp
diff --git a/examples/test-ring-buffer-insertion.cpp b/tests/test-ring-buffer-insertion.cpp
index 2188b03..2188b03 100644
--- a/examples/test-ring-buffer-insertion.cpp
+++ b/tests/test-ring-buffer-insertion.cpp
diff --git a/examples/test-serial-flush.cpp b/tests/test-serial-flush.cpp
index 409d1f9..409d1f9 100644
--- a/examples/test-serial-flush.cpp
+++ b/tests/test-serial-flush.cpp
diff --git a/examples/test-serialusb.cpp b/tests/test-serialusb.cpp
index 098e445..098e445 100644
--- a/examples/test-serialusb.cpp
+++ b/tests/test-serialusb.cpp
diff --git a/examples/test-servo.cpp b/tests/test-servo.cpp
index 6f6e3ba..6f6e3ba 100644
--- a/examples/test-servo.cpp
+++ b/tests/test-servo.cpp
diff --git a/examples/test-session.cpp b/tests/test-session.cpp
index 284b4b0..2cc000f 100644
--- a/examples/test-session.cpp
+++ b/tests/test-session.cpp
@@ -891,8 +891,10 @@ void enable_usarts(void) {
Serial1.begin(BAUD);
Serial2.begin(BAUD);
Serial3.begin(BAUD);
-#if defined(STM32_HIGH_DENSITY) && !defined(BOARD_maple_RET6)
+#if defined(BOARD_HAVE_USART4)
Serial4.begin(BAUD);
+#endif
+#if defined(BOARD_HAVE_USART5)
Serial5.begin(BAUD);
#endif
}
@@ -901,8 +903,10 @@ void disable_usarts(void) {
Serial1.end();
Serial2.end();
Serial3.end();
-#if defined(STM32_HIGH_DENSITY) && !defined(BOARD_maple_RET6)
+#if defined(BOARD_HAVE_USART4)
Serial4.end();
+#endif
+#if defined(BOARD_HAVE_USART5)
Serial5.end();
#endif
}
diff --git a/examples/test-spi-roundtrip.cpp b/tests/test-spi-roundtrip.cpp
index ddc9875..ddc9875 100644
--- a/examples/test-spi-roundtrip.cpp
+++ b/tests/test-spi-roundtrip.cpp
diff --git a/examples/test-systick.cpp b/tests/test-systick.cpp
index 356f302..356f302 100644
--- a/examples/test-systick.cpp
+++ b/tests/test-systick.cpp
diff --git a/examples/test-timers.cpp b/tests/test-timers.cpp
index e646916..e646916 100644
--- a/examples/test-timers.cpp
+++ b/tests/test-timers.cpp
diff --git a/examples/test-usart-dma.cpp b/tests/test-usart-dma.cpp
index d10dc68..7d6d8b9 100644
--- a/examples/test-usart-dma.cpp
+++ b/tests/test-usart-dma.cpp
@@ -1,5 +1,5 @@
/**
- * @file examples/test-usart-dma.cpp
+ * @file tests/test-usart-dma.cpp
* @author Marti Bolivar <mbolivar@leaflabs.com>
*
* Simple test of DMA used with a USART receiver.
diff --git a/wirish/HardwareSPI.cpp b/wirish/HardwareSPI.cpp
index 94985eb..1acba76 100644
--- a/wirish/HardwareSPI.cpp
+++ b/wirish/HardwareSPI.cpp
@@ -2,6 +2,7 @@
* The MIT License
*
* Copyright (c) 2010 Perry Hung.
+ * Copyright 2014 Google, Inc.
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
@@ -59,23 +60,32 @@ static void enable_device(spi_dev *dev,
spi_mode mode);
static const spi_pins board_spi_pins[] __FLASH__ = {
+#if BOARD_HAVE_SPI1
{BOARD_SPI1_NSS_PIN,
BOARD_SPI1_SCK_PIN,
BOARD_SPI1_MISO_PIN,
BOARD_SPI1_MOSI_PIN},
+#else
+ {0, 0, 0, 0},
+#endif
+#if BOARD_HAVE_SPI2
{BOARD_SPI2_NSS_PIN,
BOARD_SPI2_SCK_PIN,
BOARD_SPI2_MISO_PIN,
BOARD_SPI2_MOSI_PIN},
-#ifdef STM32_HIGH_DENSITY
+#else
+ {0, 0, 0, 0},
+#endif
+#if BOARD_HAVE_SPI3
{BOARD_SPI3_NSS_PIN,
BOARD_SPI3_SCK_PIN,
BOARD_SPI3_MISO_PIN,
BOARD_SPI3_MOSI_PIN},
+#else
+ {0, 0, 0, 0},
#endif
};
-
/*
* Constructor
*/
@@ -235,12 +245,26 @@ static spi_baud_rate determine_baud_rate(spi_dev *dev, SPIFrequency freq);
static const spi_pins* dev_to_spi_pins(spi_dev *dev) {
switch (dev->clk_id) {
- case RCC_SPI1: return board_spi_pins;
- case RCC_SPI2: return board_spi_pins + 1;
-#ifdef STM32_HIGH_DENSITY
- case RCC_SPI3: return board_spi_pins + 2;
+ case RCC_SPI1:
+#if BOARD_HAVE_SPI1
+ return board_spi_pins;
+#else
+ return NULL;
+#endif
+ case RCC_SPI2:
+#if BOARD_HAVE_SPI2
+ return board_spi_pins + 1;
+#else
+ return NULL;
#endif
- default: return NULL;
+ case RCC_SPI3:
+#if BOARD_HAVE_SPI3
+ return board_spi_pins + 2;
+#else
+ return NULL;
+#endif
+ default:
+ return NULL;
}
}
diff --git a/wirish/HardwareTimer.cpp b/wirish/HardwareTimer.cpp
index 4f68ad7..1d9fe61 100644
--- a/wirish/HardwareTimer.cpp
+++ b/wirish/HardwareTimer.cpp
@@ -2,6 +2,7 @@
* The MIT License
*
* Copyright (c) 2010 Bryan Newbold.
+ * Copyright 2014 Google, Inc.
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
@@ -26,6 +27,7 @@
#include <wirish/HardwareTimer.h>
+#include <libmaple/stm32.h>
#include <libmaple/rcc.h>
#include <wirish/ext_interrupts.h> // for noInterrupts(), interrupts()
#include <wirish/wirish_math.h>
@@ -144,13 +146,27 @@ void HardwareTimer::refresh(void) {
/* -- Deprecated predefined instances -------------------------------------- */
+#if STM32_TIMER_MASK & (1 << 1)
HardwareTimer Timer1(1);
+#endif
+#if STM32_TIMER_MASK & (1 << 2)
HardwareTimer Timer2(2);
+#endif
+#if STM32_TIMER_MASK & (1 << 3)
HardwareTimer Timer3(3);
+#endif
+#if STM32_TIMER_MASK & (1 << 4)
HardwareTimer Timer4(4);
-#ifdef STM32_HIGH_DENSITY
+#endif
+#if STM32_TIMER_MASK & (1 << 5)
HardwareTimer Timer5(5);
+#endif
+#if STM32_TIMER_MASK & (1 << 6)
HardwareTimer Timer6(6);
+#endif
+#if STM32_TIMER_MASK & (1 << 7)
HardwareTimer Timer7(7);
+#endif
+#if STM32_TIMER_MASK & (1 << 8)
HardwareTimer Timer8(8);
#endif
diff --git a/wirish/Print.cpp b/wirish/Print.cpp
index f6bc0c6..cf0f74b 100644
--- a/wirish/Print.cpp
+++ b/wirish/Print.cpp
@@ -196,7 +196,7 @@ void Print::printNumber(unsigned long long n, uint8 base) {
* nextafter((double)numeric_limits<long long>::max(), 0.0) ~= 9.22337e+18
*
* This slightly smaller value was picked semi-arbitrarily. */
-#define LARGE_DOUBLE_TRESHOLD (9.1e18)
+#define LARGE_DOUBLE_TRESHOLD ((double)9.1e18)
/* THIS FUNCTION SHOULDN'T BE USED IF YOU NEED ACCURATE RESULTS.
*
@@ -211,7 +211,7 @@ void Print::printNumber(unsigned long long n, uint8 base) {
void Print::printFloat(double number, uint8 digits) {
// Hackish fail-fast behavior for large-magnitude doubles
if (abs(number) >= LARGE_DOUBLE_TRESHOLD) {
- if (number < 0.0) {
+ if (number < (double)0.0) {
print('-');
}
print("<large double>");
@@ -219,16 +219,16 @@ void Print::printFloat(double number, uint8 digits) {
}
// Handle negative numbers
- if (number < 0.0) {
+ if (number < (double)0.0) {
print('-');
number = -number;
}
// Simplistic rounding strategy so that e.g. print(1.999, 2)
// prints as "2.00"
- double rounding = 0.5;
+ double rounding = (double)0.5;
for (uint8 i = 0; i < digits; i++) {
- rounding /= 10.0;
+ rounding /= (double)10.0;
}
number += rounding;
@@ -244,7 +244,7 @@ void Print::printFloat(double number, uint8 digits) {
// Extract digits from the remainder one at a time
while (digits-- > 0) {
- remainder *= 10.0;
+ remainder *= (double)10.0;
int to_print = (int)remainder;
print(to_print);
remainder -= to_print;
diff --git a/wirish/boards.cpp b/wirish/boards.cpp
index 77a05de..6b0c74b 100644
--- a/wirish/boards.cpp
+++ b/wirish/boards.cpp
@@ -3,6 +3,7 @@
*
* Copyright (c) 2010 Perry Hung.
* Copyright (c) 2011, 2012 LeafLabs, LLC.
+ * Copyright 2014 Google, Inc.
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
@@ -45,6 +46,8 @@
* notice.
*/
+#pragma GCC diagnostic ignored "-Wunused-function"
+
#include <wirish/boards.h>
#include <libmaple/libmaple_types.h>
#include <libmaple/flash.h>
@@ -52,24 +55,16 @@
#include <libmaple/systick.h>
#include "boards_private.h"
-static void setup_flash(void);
-static void setup_clocks(void);
static void setup_nvic(void);
-static void setup_adcs(void);
-static void setup_timers(void);
-
-/*
- * Exported functions
- */
void init(void) {
- setup_flash();
- setup_clocks();
+ wirish::priv::board_setup_flash();
+ wirish::priv::board_setup_clocks();
setup_nvic();
systick_init(SYSTICK_RELOAD_VAL);
wirish::priv::board_setup_gpio();
- setup_adcs();
- setup_timers();
+ wirish::priv::board_setup_adcs();
+ wirish::priv::board_setup_timers();
wirish::priv::board_setup_usb();
wirish::priv::series_init();
boardInit();
@@ -91,20 +86,54 @@ bool boardUsesPin(uint8 pin) {
}
/*
- * Auxiliary routines
+ * These addresses are where usercode starts when a bootloader is
+ * present. If no bootloader is present, the user NVIC usually starts
+ * at the Flash base address, 0x08000000.
*/
+#if defined(BOOTLOADER_maple)
+#define USER_ADDR_ROM 0x08005000
+#elif defined(BOOTLOADER_robotis)
+#define USER_ADDR_ROM 0x08003000
+#endif
+#define USER_ADDR_RAM 0x20000C00
+extern char __text_start__;
+
+static void setup_nvic(void) {
+#ifdef VECT_TAB_FLASH
+ nvic_init(USER_ADDR_ROM, 0);
+#elif defined VECT_TAB_RAM
+ nvic_init(USER_ADDR_RAM, 0);
+#elif defined VECT_TAB_BASE
+ nvic_init((uint32)0x08000000, 0);
+#elif defined VECT_TAB_ADDR
+ // A numerically supplied value
+ nvic_init((uint32)VECT_TAB_ADDR, 0);
+#else
+ // Use the __text_start__ value from the linker script; this
+ // should be the start of the vector table.
+ nvic_init((uint32)&__text_start__, 0);
+#endif
+}
+
+/*
+ * Default implementations for some board-specific routines.
+ */
+
+namespace wirish {
+namespace priv {
-static void setup_flash(void) {
+__weak rcc_clk w_board_pll_in_clk = RCC_CLK_HSE;
+
+__weak void board_setup_flash(void) {
// Turn on as many Flash "go faster" features as
// possible. flash_enable_features() just ignores any flags it
// can't support.
flash_enable_features(FLASH_PREFETCH | FLASH_ICACHE | FLASH_DCACHE);
- // Configure the wait states, assuming we're operating at "close
- // enough" to 3.3V.
+ // FLASH_SAFE_WAIT_STATES is a hack that needs to go away.
flash_set_latency(FLASH_SAFE_WAIT_STATES);
}
-static void setup_clocks(void) {
+__weak void board_setup_clocks(void) {
// Turn on HSI. We'll switch to and run off of this while we're
// setting up the main PLL.
rcc_turn_on_clk(RCC_CLK_HSI);
@@ -115,15 +144,17 @@ static void setup_clocks(void) {
RCC_BASE->CFGR = 0x00000000;
rcc_disable_css();
rcc_turn_off_clk(RCC_CLK_PLL);
- rcc_turn_off_clk(RCC_CLK_HSE);
+ if (w_board_pll_in_clk != RCC_CLK_HSI) {
+ rcc_turn_off_clk(w_board_pll_in_clk);
+ }
wirish::priv::board_reset_pll();
// Clear clock readiness interrupt flags and turn off clock
// readiness interrupts.
RCC_BASE->CIR = 0x00000000;
- // Enable HSE, and wait until it's ready.
- rcc_turn_on_clk(RCC_CLK_HSE);
- while (!rcc_is_clk_ready(RCC_CLK_HSE))
+ // Enable the PLL input clock, and wait until it's ready.
+ rcc_turn_on_clk(w_board_pll_in_clk);
+ while (!rcc_is_clk_ready(w_board_pll_in_clk))
;
// Configure AHBx, APBx, etc. prescalers and the main PLL.
@@ -139,42 +170,12 @@ static void setup_clocks(void) {
rcc_switch_sysclk(RCC_CLKSRC_PLL);
}
-/*
- * These addresses are where usercode starts when a bootloader is
- * present. If no bootloader is present, the user NVIC usually starts
- * at the Flash base address, 0x08000000.
- */
-#if defined(BOOTLOADER_maple)
-#define USER_ADDR_ROM 0x08005000
-#elif defined(BOOTLOADER_robotis)
-#define USER_ADDR_ROM 0x08003000
-#endif
-#define USER_ADDR_RAM 0x20000C00
-extern char __text_start__;
-
-static void setup_nvic(void) {
-#ifdef VECT_TAB_FLASH
- nvic_init(USER_ADDR_ROM, 0);
-#elif defined VECT_TAB_RAM
- nvic_init(USER_ADDR_RAM, 0);
-#elif defined VECT_TAB_BASE
- nvic_init((uint32)0x08000000, 0);
-#elif defined VECT_TAB_ADDR
- // A numerically supplied value
- nvic_init((uint32)VECT_TAB_ADDR, 0);
-#else
- // Use the __text_start__ value from the linker script; this
- // should be the start of the vector table.
- nvic_init((uint32)&__text_start__, 0);
-#endif
-}
-
static void adc_default_config(const adc_dev *dev) {
adc_enable_single_swstart(dev);
adc_set_sample_rate(dev, wirish::priv::w_adc_smp);
}
-static void setup_adcs(void) {
+__weak void board_setup_adcs(void) {
adc_set_prescaler(wirish::priv::w_adc_pre);
adc_foreach(adc_default_config);
}
@@ -214,6 +215,9 @@ static void timer_default_config(timer_dev *dev) {
timer_resume(dev);
}
-static void setup_timers(void) {
+__weak void board_setup_timers(void) {
timer_foreach(timer_default_config);
}
+
+}
+}
diff --git a/wirish/boards/cm900/board.cpp b/wirish/boards/robotis_cm900/board.cpp
index ec747b3..735bf33 100644
--- a/wirish/boards/cm900/board.cpp
+++ b/wirish/boards/robotis_cm900/board.cpp
@@ -1,5 +1,5 @@
/*
- * cm900.cpp
+ * robotis_cm900.cpp
*
* Created on: 2012. 10. 14.
* Author: in2storm
@@ -31,12 +31,6 @@
* SOFTWARE.
*****************************************************************************/
-/**
- * @file maple.cpp
- * @author Marti Bolivar <mbolivar@leaflabs.com>
- * @brief Maple PIN_MAP and boardInit().
- */
-
#include <board/board.h> // For this board's header file
#include <wirish/wirish_types.h> // For stm32_pin_info and its contents
diff --git a/wirish/boards/cm900/include/board/board.h b/wirish/boards/robotis_cm900/include/board/board.h
index fed1a1b..7eab980 100644
--- a/wirish/boards/cm900/include/board/board.h
+++ b/wirish/boards/robotis_cm900/include/board/board.h
@@ -27,7 +27,7 @@
/*
- * CM900.h
+ * robotis_cm900.h
*
* Created on: 2012. 10. 14.
* Author: ROBOTIS[sm6787@robotis.com]
diff --git a/wirish/boards/opencm904/board.cpp b/wirish/boards/robotis_opencm904/board.cpp
index b3c600b..19220fb 100644
--- a/wirish/boards/opencm904/board.cpp
+++ b/wirish/boards/robotis_opencm904/board.cpp
@@ -24,11 +24,6 @@
* SOFTWARE.
*****************************************************************************/
-/**
- * @file maple.cpp
- * @author Marti Bolivar <mbolivar@leaflabs.com>
- * @brief Maple PIN_MAP and boardInit().
- */
/*
* CM904.cpp ported from CM900.cpp
*
diff --git a/wirish/boards/opencm904/include/board/board.h b/wirish/boards/robotis_opencm904/include/board/board.h
index 274a2a7..274a2a7 100644
--- a/wirish/boards/opencm904/include/board/board.h
+++ b/wirish/boards/robotis_opencm904/include/board/board.h
diff --git a/wirish/boards/nucleo/board.cpp b/wirish/boards/st_nucleo_f103rb/board.cpp
index 641f542..ea2f5c6 100644
--- a/wirish/boards/nucleo/board.cpp
+++ b/wirish/boards/st_nucleo_f103rb/board.cpp
@@ -25,9 +25,9 @@
*****************************************************************************/
/**
- * @file wirish/boards/nucleo/board.cpp
+ * @file wirish/boards/st_nucleo_f103rb/board.cpp
* @author Grégoire Passault <g.passault@gmail.com>
- * @brief Nucleo board file
+ * @brief st_nucleo_f103rb board file
*
* This mapping was done using the NUCLEO documentation and may be incomplete
* or contains error
diff --git a/wirish/boards/nucleo/include/board/board.h b/wirish/boards/st_nucleo_f103rb/include/board/board.h
index f7e3a38..7788cd8 100644
--- a/wirish/boards/nucleo/include/board/board.h
+++ b/wirish/boards/st_nucleo_f103rb/include/board/board.h
@@ -25,9 +25,9 @@
*****************************************************************************/
/**
- * @file wirish/boards/maple/include/board/board.h
- * @author Marti Bolivar <mbolivar@leaflabs.com>
- * @brief Maple board header.
+ * @file wirish/boards/st_nucleo_f103rb/include/board/board.h
+ * @author Grégoire Passault <g.passault@gmail.com>
+ * @brief st_nucleo_f103rb board header.
*/
#ifndef _BOARD_MAPLE_H_
diff --git a/wirish/boards/st_stm32f401cdiscovery/board.cpp b/wirish/boards/st_stm32f401cdiscovery/board.cpp
new file mode 100644
index 0000000..7f89ab6
--- /dev/null
+++ b/wirish/boards/st_stm32f401cdiscovery/board.cpp
@@ -0,0 +1,177 @@
+/******************************************************************************
+ * 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 wirish/boards/maple/board.cpp
+ * @author Perry Huang <iperry@leaflabs.com>, Bryan Newbold <bnewbold@robocracy.org
+ * @brief STM32F401C Discovery board file.
+ */
+
+#include <board/board.h> // For this board's header file
+
+#include <wirish/wirish_types.h> // For stm32_pin_info and its contents
+ // (these go into PIN_MAP).
+
+#include "boards_private.h" // For PMAP_ROW(), which makes
+ // PIN_MAP easier to read.
+
+// boardInit(): nothing special to do for Maple.
+//
+// When defining your own board.cpp, you can put extra code in this
+// function if you have anything you want done on reset, before main()
+// or setup() are called.
+//
+// If there's nothing special you need done, feel free to leave this
+// function out.
+void boardInit(void) {
+ // Disable on-board MEMS Gycroscope by pulling PE3 high (nCS line).
+ // If this isn't done, use of SPI peripheral 1 will fail mysteriously due
+ // to the Gyro writing to MISO.
+ // To re-enable and use the gyro, pull PE3 (D67) low in setup().
+ gpio_set_mode(GPIOE, 3, GPIO_MODE_OUTPUT);
+ gpio_write_bit(GPIOE, 3, 1);
+}
+
+// Pin map: this lets the basic I/O functions (digitalWrite(),
+// analogRead(), pwmWrite()) translate from pin numbers to STM32
+// peripherals.
+//
+// PMAP_ROW() lets us specify a row (really a struct stm32_pin_info)
+// in the pin map. Its arguments are:
+//
+// - GPIO device for the pin (GPIOA, etc.)
+// - GPIO bit for the pin (0 through 15)
+// - Timer device, or NULL if none
+// - Timer channel (1 to 4, for PWM), or 0 if none
+// - ADC device, or NULL if none
+// - ADC channel, or ADCx if none
+//
+// TODO: This table is definately not complete for the STM32F401C!!
+extern const stm32_pin_info PIN_MAP[BOARD_NR_GPIO_PINS] = {
+ PMAP_ROW(GPIOA, 0, NULL, 0, NULL, ADCx), /* D0/PA0 */
+ PMAP_ROW(GPIOA, 1, NULL, 0, NULL, ADCx), /* D1/PA1 */
+ PMAP_ROW(GPIOA, 2, NULL, 0, NULL, ADCx), /* D2/PA2 */
+ PMAP_ROW(GPIOA, 3, NULL, 0, NULL, ADCx), /* D3/PA3 */
+ PMAP_ROW(GPIOA, 4, NULL, 0, NULL, ADCx), /* D4/PA4 */
+ PMAP_ROW(GPIOA, 5, NULL, 0, NULL, ADCx), /* D5/PA5 */
+ PMAP_ROW(GPIOA, 6, NULL, 0, NULL, ADCx), /* D6/PA6 */
+ PMAP_ROW(GPIOA, 7, NULL, 0, NULL, ADCx), /* D7/PA7 */
+ PMAP_ROW(GPIOA, 8, NULL, 0, NULL, ADCx), /* D8/PA8 */
+ PMAP_ROW(GPIOA, 9, NULL, 0, NULL, ADCx), /* D9/PA9 */
+ PMAP_ROW(GPIOA, 10, NULL, 0, NULL, ADCx), /* D10/PA10 */
+ PMAP_ROW(GPIOA, 11, NULL, 0, NULL, ADCx), /* D11/PA11 */
+ PMAP_ROW(GPIOA, 12, NULL, 0, NULL, ADCx), /* D12/PA12 */
+ PMAP_ROW(GPIOA, 13, NULL, 0, NULL, ADCx), /* D13/PA13 */
+ PMAP_ROW(GPIOA, 14, NULL, 0, NULL, ADCx), /* D14/PA14 */
+ PMAP_ROW(GPIOA, 15, NULL, 0, NULL, ADCx), /* D15/PA15 */
+
+ PMAP_ROW(GPIOB, 0, NULL, 0, NULL, ADCx), /* D16/PB0 */
+ PMAP_ROW(GPIOB, 1, NULL, 0, NULL, ADCx), /* D17/PB1 */
+ PMAP_ROW(GPIOB, 2, NULL, 0, NULL, ADCx), /* D18/PB2 */
+ PMAP_ROW(GPIOB, 3, NULL, 0, NULL, ADCx), /* D19/PB3 */
+ PMAP_ROW(GPIOB, 4, NULL, 0, NULL, ADCx), /* D20/PB4 */
+ PMAP_ROW(GPIOB, 5, NULL, 0, NULL, ADCx), /* D21/PB5 */
+ PMAP_ROW(GPIOB, 6, NULL, 0, NULL, ADCx), /* D22/PB6 */
+ PMAP_ROW(GPIOB, 7, NULL, 0, NULL, ADCx), /* D23/PB7 */
+ PMAP_ROW(GPIOB, 8, NULL, 0, NULL, ADCx), /* D24/PB8 */
+ PMAP_ROW(GPIOB, 9, NULL, 0, NULL, ADCx), /* D25/PB9 */
+ PMAP_ROW(GPIOB, 10, NULL, 0, NULL, ADCx), /* D26/PB10 */
+ PMAP_ROW(GPIOB, 11, NULL, 0, NULL, ADCx), /* D27/PB11 */
+ PMAP_ROW(GPIOB, 12, NULL, 0, NULL, ADCx), /* D28/PB12 */
+ PMAP_ROW(GPIOB, 13, NULL, 0, NULL, ADCx), /* D29/PB13 */
+ PMAP_ROW(GPIOB, 14, NULL, 0, NULL, ADCx), /* D30/PB14 */
+ PMAP_ROW(GPIOB, 15, NULL, 0, NULL, ADCx), /* D31/PB15 */
+
+ PMAP_ROW(GPIOC, 0, NULL, 0, NULL, ADCx), /* D32/PC0 */
+ PMAP_ROW(GPIOC, 1, NULL, 0, NULL, ADCx), /* D33/PC1 */
+ PMAP_ROW(GPIOC, 2, NULL, 0, NULL, ADCx), /* D34/PC2 */
+ PMAP_ROW(GPIOC, 3, NULL, 0, NULL, ADCx), /* D35/PC3 */
+ PMAP_ROW(GPIOC, 4, NULL, 0, NULL, ADCx), /* D36/PC4 */
+ PMAP_ROW(GPIOC, 5, NULL, 0, NULL, ADCx), /* D37/PC5 */
+ PMAP_ROW(GPIOC, 6, NULL, 0, NULL, ADCx), /* D38/PC6 */
+ PMAP_ROW(GPIOC, 7, NULL, 0, NULL, ADCx), /* D39/PC7 */
+ PMAP_ROW(GPIOC, 8, NULL, 0, NULL, ADCx), /* D40/PC8 */
+ PMAP_ROW(GPIOC, 9, NULL, 0, NULL, ADCx), /* D41/PC9 */
+ PMAP_ROW(GPIOC, 10, NULL, 0, NULL, ADCx), /* D42/PC10 */
+ PMAP_ROW(GPIOC, 11, NULL, 0, NULL, ADCx), /* D43/PC11 */
+ PMAP_ROW(GPIOC, 12, NULL, 0, NULL, ADCx), /* D44/PC12 */
+ PMAP_ROW(GPIOC, 13, NULL, 0, NULL, ADCx), /* D45/PC13 */
+ PMAP_ROW(GPIOC, 14, NULL, 0, NULL, ADCx), /* D46/PC14 */
+ PMAP_ROW(GPIOC, 15, NULL, 0, NULL, ADCx), /* D47/PC15 */
+
+ PMAP_ROW(GPIOD, 0, NULL, 0, NULL, ADCx), /* D48/PD0 */
+ PMAP_ROW(GPIOD, 1, NULL, 0, NULL, ADCx), /* D49/PD1 */
+ PMAP_ROW(GPIOD, 2, NULL, 0, NULL, ADCx), /* D50/PD2 */
+ PMAP_ROW(GPIOD, 3, NULL, 0, NULL, ADCx), /* D51/PD3 */
+ PMAP_ROW(GPIOD, 4, NULL, 0, NULL, ADCx), /* D52/PD4 */
+ PMAP_ROW(GPIOD, 5, NULL, 0, NULL, ADCx), /* D53/PD5 */
+ PMAP_ROW(GPIOD, 6, NULL, 0, NULL, ADCx), /* D54/PD6 */
+ PMAP_ROW(GPIOD, 7, NULL, 0, NULL, ADCx), /* D55/PD7 */
+ PMAP_ROW(GPIOD, 8, NULL, 0, NULL, ADCx), /* D56/PD8 */
+ PMAP_ROW(GPIOD, 9, NULL, 0, NULL, ADCx), /* D57/PD9 */
+ PMAP_ROW(GPIOD, 10, NULL, 0, NULL, ADCx), /* D58/PD10 */
+ PMAP_ROW(GPIOD, 11, NULL, 0, NULL, ADCx), /* D59/PD11 */
+ PMAP_ROW(GPIOD, 12, NULL, 0, NULL, ADCx), /* D60/PD12 */
+ PMAP_ROW(GPIOD, 13, NULL, 0, NULL, ADCx), /* D61/PD13 */
+ PMAP_ROW(GPIOD, 14, NULL, 0, NULL, ADCx), /* D62/PD14 */
+ PMAP_ROW(GPIOD, 15, NULL, 0, NULL, ADCx), /* D63/PD15 */
+
+ PMAP_ROW(GPIOE, 0, NULL, 0, NULL, ADCx), /* D64/PE0 */
+ PMAP_ROW(GPIOE, 1, NULL, 0, NULL, ADCx), /* D65/PE1 */
+ PMAP_ROW(GPIOE, 2, NULL, 0, NULL, ADCx), /* D66/PE2 */
+ PMAP_ROW(GPIOE, 3, NULL, 0, NULL, ADCx), /* D67/PE3 */
+ PMAP_ROW(GPIOE, 4, NULL, 0, NULL, ADCx), /* D68/PE4 */
+ PMAP_ROW(GPIOE, 5, NULL, 0, NULL, ADCx), /* D69/PE5 */
+ PMAP_ROW(GPIOE, 6, NULL, 0, NULL, ADCx), /* D70/PE6 */
+ PMAP_ROW(GPIOE, 7, NULL, 0, NULL, ADCx), /* D71/PE7 */
+ PMAP_ROW(GPIOE, 8, NULL, 0, NULL, ADCx), /* D72/PE8 */
+ PMAP_ROW(GPIOE, 9, NULL, 0, NULL, ADCx), /* D73/PE9 */
+ PMAP_ROW(GPIOE, 10, NULL, 0, NULL, ADCx), /* D74/PE10 */
+ PMAP_ROW(GPIOE, 11, NULL, 0, NULL, ADCx), /* D75/PE11 */
+ PMAP_ROW(GPIOE, 12, NULL, 0, NULL, ADCx), /* D76/PE12 */
+ PMAP_ROW(GPIOE, 13, NULL, 0, NULL, ADCx), /* D77/PE13 */
+ PMAP_ROW(GPIOE, 14, NULL, 0, NULL, ADCx), /* D78/PE14 */
+ PMAP_ROW(GPIOE, 15, NULL, 0, NULL, ADCx), /* D79/PE15 */
+};
+
+// Array of pins you can use for pwmWrite(). Keep it in Flash because
+// it doesn't change, and so we don't waste RAM.
+extern const uint8 boardPWMPins[] __FLASH__ = {
+ 0, 1, 2, 3, 5, 6, 7, 8, 9, 11, 12, 14, 24, 27, 28
+};
+
+// Array of pins you can use for analogRead().
+extern const uint8 boardADCPins[] __FLASH__ = {
+ 0,
+};
+
+// Array of pins that the board uses for something special. Other than
+// the button and the LED, it's usually best to leave these pins alone
+// unless you know what you're doing.
+extern const uint8 boardUsedPins[] __FLASH__ = {
+ BOARD_LED_PIN, BOARD_BUTTON_PIN, BOARD_JTMS_SWDIO_PIN,
+ BOARD_JTCK_SWCLK_PIN, BOARD_JTDI_PIN, BOARD_JTDO_PIN, BOARD_NJTRST_PIN
+};
diff --git a/wirish/boards/st_stm32f401cdiscovery/include/board/board.h b/wirish/boards/st_stm32f401cdiscovery/include/board/board.h
new file mode 100644
index 0000000..d93bc30
--- /dev/null
+++ b/wirish/boards/st_stm32f401cdiscovery/include/board/board.h
@@ -0,0 +1,127 @@
+/******************************************************************************
+ * 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 wirish/boards/maple/include/board/board.h
+ * @author Perry Huang <iperry@leaflabs.com>, Bryan Newbold <bnewbold@robocracy.org
+ * @brief STM32F401C Discovery board file.
+ */
+
+#ifndef _BOARD_STM32F401_DISCOVERY_H_
+#define _BOARD_STM32F401_DISCOVERY_H_
+
+/* 84 MHz -> 84 cycles per microsecond. */
+#define CYCLES_PER_MICROSECOND 84
+
+// PLL config for 8 MHz external crystal
+// --> 84 MHz SYSCLK, with 48 MHz PLL48CK.
+//
+// Additional constraints:
+// ASSERT_FAULT((data->pllq >= 4) && (data->pllq <= 15));
+// ASSERT_FAULT((data->pllp >= 2) && (data->pllp <= 8));
+// ASSERT_FAULT(!(data->pllp & 1));
+// ASSERT_FAULT((data->plln >= 192) && (data->plln <= 432));
+// ASSERT_FAULT((data->pllm >= 2) && (data->pllm <= 63));
+//
+// f_VCO = (INPUT) X (PLL_N / PLL_M)
+#define BOARD_PLL_N 336
+#define BOARD_PLL_M 8
+// SYSCLK = f_PLL = f_VCO / PLL_P; PLL_P = {2, 4, 6, 8}
+#define BOARD_PLL_P 4
+// PLL48CK = f_USBETC = f_VCO / PLL_Q; 2 <= PLL_Q <= 15
+#define BOARD_PLL_Q 7 // should be 2?
+
+/* Pin number for the built-in button (USER button on STM32F401DISCOVERY) */
+#define BOARD_BUTTON_PIN PA0
+
+/* Pin number for the built-in LED (blue LED on STM32F401DISCOVERY) */
+#define BOARD_LED_PIN PD15
+
+/* Number of USARTs/UARTs whose pins are broken out to headers. */
+#define BOARD_NR_USARTS 3
+
+/* USART pin numbers. */
+#define BOARD_USART1_TX_PIN PA9
+#define BOARD_USART1_RX_PIN PA10
+#define BOARD_USART2_TX_PIN PA2
+#define BOARD_USART2_RX_PIN PA3
+#define BOARD_USART3_TX_PIN PB10
+#define BOARD_USART3_RX_PIN PB11
+
+/* Number of SPI ports broken out to headers. */
+#define BOARD_NR_SPI 2
+
+/* SPI pin numbers. */
+#define BOARD_SPI1_NSS_PIN PA4
+#define BOARD_SPI1_MOSI_PIN PA7
+#define BOARD_SPI1_MISO_PIN PA6
+#define BOARD_SPI1_SCK_PIN PA5
+
+#define BOARD_SPI2_NSS_PIN 28
+#define BOARD_SPI2_MOSI_PIN 31
+#define BOARD_SPI2_MISO_PIN 30
+#define BOARD_SPI2_SCK_PIN 29
+
+/* Total number of GPIO pins that are broken out to headers and
+ * intended for use. This includes pins like the LED, button, and
+ * debug port (JTAG/SWD) pins. */
+#define BOARD_NR_GPIO_PINS 80
+
+/* Number of pins capable of PWM output. */
+#define BOARD_NR_PWM_PINS 5
+
+/* Number of pins capable of ADC conversion. */
+#define BOARD_NR_ADC_PINS 1
+
+/* Number of pins already connected to external hardware. For Maple,
+ * these are just BOARD_LED_PIN, BOARD_BUTTON_PIN, and the debug port
+ * pins (see below). */
+#define BOARD_NR_USED_PINS 7
+
+/* Debug port pins. */
+#define BOARD_JTMS_SWDIO_PIN 39
+#define BOARD_JTCK_SWCLK_PIN 40
+#define BOARD_JTDI_PIN 41
+#define BOARD_JTDO_PIN 42
+#define BOARD_NJTRST_PIN 43
+
+/* USB configuration. BOARD_USB_DISC_DEV is the GPIO port containing
+ * the USB_DISC pin, and BOARD_USB_DISC_BIT is that pin's bit. */
+#define BOARD_USB_DISC_DEV GPIOC
+#define BOARD_USB_DISC_BIT 12
+
+/* Pin aliases: these give the GPIO port/bit for each pin as an
+ * enum. These are optional, but recommended. They make it easier to
+ * write code using low-level GPIO functionality. */
+enum {
+ PA0, PA1, PA2, PA3, PA4, PA5, PA6, PA7, PA8, PA9, PA10, PA11, PA12, PA13, PA14, PA15,
+ PB0, PB1, PB2, PB3, PB4, PB5, PB6, PB7, PB8, PB9, PB10, PB11, PB12, PB13, PB14, PB15,
+ PC0, PC1, PC2, PC3, PC4, PC5, PC6, PC7, PC8, PC9, PC10, PC11, PC12, PC13, PC14, PC15,
+ PD0, PD1, PD2, PD3, PD4, PD5, PD6, PD7, PD8, PD9, PD10, PD11, PD12, PD13, PD14, PD15,
+ PE0, PE1, PE2, PE3, PE4, PE5, PE6, PE7, PE8, PE9, PE10, PE11, PE12, PE13, PE14, PE15,
+};
+
+#endif
diff --git a/wirish/boards/VLDiscovery/board.cpp b/wirish/boards/st_stm32vldiscovery/board.cpp
index c86204d..a787472 100644
--- a/wirish/boards/VLDiscovery/board.cpp
+++ b/wirish/boards/st_stm32vldiscovery/board.cpp
@@ -25,9 +25,9 @@
*****************************************************************************/
/**
- * @file wirish/boards/VLDiscovery/board.cpp
+ * @file wirish/boards/st_stm32vldiscovery/board.cpp
* @author Anton Eltchaninov <anton.eltchaninov@gmail.com>
- * @brief VLDiscovery board file.
+ * @brief st_stm32vldiscovery board file.
*/
#include <board/board.h>
diff --git a/wirish/boards/VLDiscovery/include/board/board.h b/wirish/boards/st_stm32vldiscovery/include/board/board.h
index 04d21c7..e976add 100644
--- a/wirish/boards/VLDiscovery/include/board/board.h
+++ b/wirish/boards/st_stm32vldiscovery/include/board/board.h
@@ -25,9 +25,9 @@
*****************************************************************************/
/**
- * @file wirish/boards/VLDiscovery/include/board/board.h
+ * @file wirish/boards/st_stm32vldiscovery/include/board/board.h
* @author Anton Eltchaninov <anton.eltchaninov@gmail.com>
- * @brief VLDiscovery board header.
+ * @brief st_stm32vldiscovery board header.
*/
#ifndef _BOARD_VLDISCOVERY_H_
diff --git a/wirish/boards_private.h b/wirish/boards_private.h
index 49867ca..642a9ee 100644
--- a/wirish/boards_private.h
+++ b/wirish/boards_private.h
@@ -48,21 +48,30 @@ namespace wirish {
namespace priv {
/*
- * Chip-specific initialization data
+ * Chip- and board-specific initialization data
*/
extern rcc_pll_cfg w_board_pll_cfg;
+ extern rcc_clk w_board_pll_in_clk;
extern adc_prescaler w_adc_pre;
extern adc_smp_rate w_adc_smp;
/*
- * Chip-specific initialization routines and helper functions.
+ * Chip- and board-specific initialization routines and helper
+ * functions.
+ *
+ * Some of these have default (weak) implementations in
+ * boards.cpp; define them in your board file to override.
*/
void board_reset_pll(void);
void board_setup_clock_prescalers(void);
void board_setup_gpio(void);
void board_setup_usb(void);
+ void board_setup_flash(void);
+ void board_setup_adcs(void);
+ void board_setup_timers(void);
+ void board_setup_clocks(void);
void series_init(void);
}
diff --git a/wirish/include/wirish/ext_interrupts.h b/wirish/include/wirish/ext_interrupts.h
index ce1ca03..7b82c40 100644
--- a/wirish/include/wirish/ext_interrupts.h
+++ b/wirish/include/wirish/ext_interrupts.h
@@ -106,7 +106,7 @@ void detachInterrupt(uint8 pin);
*
* @see noInterrupts()
*/
-static __always_inline void interrupts() {
+static inline void interrupts() {
nvic_globalirq_enable();
}
@@ -120,7 +120,7 @@ static __always_inline void interrupts() {
*
* @see interrupts()
*/
-static __always_inline void noInterrupts() {
+static inline void noInterrupts() {
nvic_globalirq_disable();
}
diff --git a/wirish/include/wirish/wirish.h b/wirish/include/wirish/wirish.h
index 610aa3f..606aac0 100644
--- a/wirish/include/wirish/wirish.h
+++ b/wirish/include/wirish/wirish.h
@@ -58,8 +58,13 @@
/* Wiring macros and bit defines */
-#define true 0x1
-#define false 0x0
+// These may have been defined if stdbool.h was included
+#ifndef true
+# define true 0x1
+#endif
+#ifndef false
+# define false 0x0
+#endif
#define LSBFIRST 0
#define MSBFIRST 1
diff --git a/wirish/include/wirish/wirish_math.h b/wirish/include/wirish/wirish_math.h
index 39f16a0..ff264dc 100644
--- a/wirish/include/wirish/wirish_math.h
+++ b/wirish/include/wirish/wirish_math.h
@@ -93,7 +93,8 @@ static inline long map(long value, long fromStart, long fromEnd,
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt)))
-#define round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5))
+#define round(x) ((x)>=0?(long)((x)+(double)0.5):(long)((x)-(double)0.5))
+#define roundf(x) ((x)>=0?(long)((x)+(float)0.5):(long)((x)-(float)0.5))
#define radians(deg) ((deg)*DEG_TO_RAD)
#define degrees(rad) ((rad)*RAD_TO_DEG)
#define sq(x) ((x)*(x))
diff --git a/wirish/rules.mk b/wirish/rules.mk
index 1cac74a..13da229 100644
--- a/wirish/rules.mk
+++ b/wirish/rules.mk
@@ -4,15 +4,25 @@ dirstack_$(sp) := $(d)
d := $(dir)
BUILDDIRS += $(BUILD_PATH)/$(d)
-# Add board directory and MCU-specific directory to BUILDDIRS. These
-# are in subdirectories, but they're logically part of the Wirish
-# submodule.
+# Add board directory and target-specific directory to
+# BUILDDIRS. These are in subdirectories, but they're logically part
+# of the Wirish submodule. That's a bit inconsistent with libmaple
+# proper, and should be fixed.
+# Optionally support out-of-tree board files if WIRISH_BOARD_PATH was exported
+ifeq ($(WIRISH_BOARD_PATH),)
WIRISH_BOARD_PATH := boards/$(BOARD)
+WIRISH_BOARD_INCLUDE := $(d)/$(WIRISH_BOARD_PATH)/include
+WIRISH_BOARD_CPP_FILE := $(d)/$(WIRISH_BOARD_PATH)/board.cpp
BUILDDIRS += $(BUILD_PATH)/$(d)/$(WIRISH_BOARD_PATH)
-BUILDDIRS += $(BUILD_PATH)/$(d)/$(MCU_SERIES)
+else
+WIRISH_BOARD_INCLUDE := $(WIRISH_BOARD_PATH)/include
+WIRISH_BOARD_CPP_FILE := $(WIRISH_BOARD_PATH)/board.cpp
+BUILDDIRS += $(BUILD_PATH)/$(WIRISH_BOARD_PATH)
+endif
+BUILDDIRS += $(BUILD_PATH)/$(d)/$(TARGET_SERIES_MODULE)
# Safe includes for Wirish.
-WIRISH_INCLUDES := -I$(d)/include -I$(d)/$(WIRISH_BOARD_PATH)/include
+WIRISH_INCLUDES := -I$(d)/include -I$(WIRISH_BOARD_INCLUDE)
# Local flags. Add -I$(d) to allow for private includes.
CFLAGS_$(d) := $(LIBMAPLE_INCLUDES) $(WIRISH_INCLUDES) -I$(d)
@@ -21,7 +31,7 @@ CFLAGS_$(d) := $(LIBMAPLE_INCLUDES) $(WIRISH_INCLUDES) -I$(d)
sSRCS_$(d) := start.S
cSRCS_$(d) := start_c.c
cSRCS_$(d) += syscalls.c
-cSRCS_$(d) += $(MCU_SERIES)/util_hooks.c
+cSRCS_$(d) += $(TARGET_SERIES_MODULE)/util_hooks.c
cppSRCS_$(d) := boards.cpp
cppSRCS_$(d) += cxxabi-compat.cpp
cppSRCS_$(d) += ext_interrupts.cpp
@@ -38,15 +48,18 @@ cppSRCS_$(d) += wirish_digital.cpp
cppSRCS_$(d) += wirish_math.cpp
cppSRCS_$(d) += wirish_shift.cpp
cppSRCS_$(d) += wirish_time.cpp
-cppSRCS_$(d) += $(MCU_SERIES)/boards_setup.cpp
-cppSRCS_$(d) += $(MCU_SERIES)/wirish_digital.cpp
-cppSRCS_$(d) += $(MCU_SERIES)/wirish_debug.cpp
-cppSRCS_$(d) += $(WIRISH_BOARD_PATH)/board.cpp
+cppSRCS_$(d) += $(TARGET_SERIES_MODULE)/boards_setup.cpp
+cppSRCS_$(d) += $(TARGET_SERIES_MODULE)/wirish_digital.cpp
+cppSRCS_$(d) += $(TARGET_SERIES_MODULE)/wirish_debug.cpp
sFILES_$(d) := $(sSRCS_$(d):%=$(d)/%)
cFILES_$(d) := $(cSRCS_$(d):%=$(d)/%)
cppFILES_$(d) := $(cppSRCS_$(d):%=$(d)/%)
+# board.cpp is a special case, because it may be out of tree
+cppSRCS_$(d) += $(WIRISH_BOARD_PATH)/board.cpp
+cppFILES_$(d) += $(WIRISH_BOARD_CPP_FILE)
+
OBJS_$(d) := $(sFILES_$(d):%.S=$(BUILD_PATH)/%.o) \
$(cFILES_$(d):%.c=$(BUILD_PATH)/%.o) \
$(cppFILES_$(d):%.cpp=$(BUILD_PATH)/%.o)
diff --git a/wirish/stm32f2/boards_setup.cpp b/wirish/stm32f2-f4/boards_setup.cpp
index 5764dd0..aa44a11 100644
--- a/wirish/stm32f2/boards_setup.cpp
+++ b/wirish/stm32f2-f4/boards_setup.cpp
@@ -42,19 +42,43 @@
#include <wirish/wirish_types.h>
#include <board/board.h>
-// PLL config for 25 MHz external crystal --> 120 MHz SYSCLK, with
-// 48 MHz PLL48CK.
-#ifndef BOARD_PLL_Q
-#define BOARD_PLL_Q 5
-#endif
-#ifndef BOARD_PLL_P
-#define BOARD_PLL_P 2
-#endif
-#ifndef BOARD_PLL_N
-#define BOARD_PLL_N 240
-#endif
-#ifndef BOARD_PLL_M
-#define BOARD_PLL_M 25
+// Not used by STM32F2
+#define FPU_CPACR 0xE000ED88
+
+/* See libmaple/stm32f2-f4/rcc.c for constraints on these values, or the vendor
+ * user manual */
+#if STM32_MCU_SERIES == STM32_SERIES_F2
+ // PLL config for 25 MHz external crystal --> 120 MHz SYSCLK, with
+ // 48 MHz PLL48CK.
+# ifndef BOARD_PLL_Q
+# define BOARD_PLL_Q 5
+# endif
+# ifndef BOARD_PLL_P
+# define BOARD_PLL_P 2
+# endif
+# ifndef BOARD_PLL_N
+# define BOARD_PLL_N 240
+# endif
+# ifndef BOARD_PLL_M
+# define BOARD_PLL_M 25
+# endif
+#elif STM32_MCU_SERIES == STM32_SERIES_F4
+ // PLL config for 8 MHz external crystal --> 84 MHz SYSCLK, with
+ // 48 MHz PLL48CK.
+# ifndef BOARD_PLL_Q
+# define BOARD_PLL_Q 7
+# endif
+# ifndef BOARD_PLL_P
+# define BOARD_PLL_P 4
+# endif
+# ifndef BOARD_PLL_N
+# define BOARD_PLL_N 336
+# endif
+# ifndef BOARD_PLL_M
+# define BOARD_PLL_M 8
+# endif
+#else
+# error "Unsupported STM32_MCU_SERIES"
#endif
static stm32f2_rcc_pll_data pll_data = {BOARD_PLL_Q,
@@ -89,6 +113,7 @@ namespace wirish {
}
__weak void board_setup_clock_prescalers(void) {
+#if STM32_MCU_SERIES == STM32_SERIES_F2
// On F2, with f_SYSCLK = 120 MHz (as determined by
// board_pll_cfg),
//
@@ -98,6 +123,19 @@ namespace wirish {
rcc_set_prescaler(RCC_PRESCALER_AHB, RCC_AHB_SYSCLK_DIV_1);
rcc_set_prescaler(RCC_PRESCALER_APB1, RCC_APB1_HCLK_DIV_4);
rcc_set_prescaler(RCC_PRESCALER_APB2, RCC_APB2_HCLK_DIV_2);
+#elif STM32_MCU_SERIES == STM32_SERIES_F4
+ // On F2, with f_SYSCLK = 84 MHz (as determined by
+ // board_pll_cfg),
+ //
+ // f_AHB = f_SYSCLK / 1 = 84 MHz
+ // f_APB1 = f_AHB / 2 = 42 MHz
+ // f_APB2 = f_AHB / 1 = 84 MHz
+ rcc_set_prescaler(RCC_PRESCALER_AHB, RCC_AHB_SYSCLK_DIV_1);
+ rcc_set_prescaler(RCC_PRESCALER_APB1, RCC_APB1_HCLK_DIV_2);
+ rcc_set_prescaler(RCC_PRESCALER_APB2, RCC_APB2_HCLK_DIV_1);
+#else
+# error "Unsupported STM32_MCU_SERIES"
+#endif
}
__weak void board_setup_gpio(void) {
@@ -114,6 +152,11 @@ namespace wirish {
// Turn on the I/O compensation cell, since we drive the
// GPIOs quickly by default.
syscfg_enable_io_compensation();
+
+#if STM32_MCU_SERIES == STM32_SERIES_F4
+ /* enable fpu with full access */
+ *(volatile unsigned int*)FPU_CPACR |= 0xF << 20;
+#endif
}
}
diff --git a/wirish/stm32f2/util_hooks.c b/wirish/stm32f2-f4/util_hooks.c
index 1b519ab..a18dfe8 100644
--- a/wirish/stm32f2/util_hooks.c
+++ b/wirish/stm32f2-f4/util_hooks.c
@@ -30,16 +30,50 @@
*/
#include <libmaple/nvic.h>
+#include <libmaple/gpio.h>
+#include <libmaple/stm32.h>
+#include <libmaple/timer.h>
+#include <libmaple/adc.h>
+#include <libmaple/usart.h>
+
+/* Failed ASSERT()s send out a message using this USART config. */
+#ifndef ERROR_USART
+#define ERROR_USART USART1
+#define ERROR_USART_BAUD 115200
+#define ERROR_TX_PORT GPIOA
+#define ERROR_TX_PIN 9
+#endif
/*
* Disables all peripheral interrupts. Called by __error() with global
* interrupts disabled.
*/
void __lm_error(void) {
+ /* Turn off peripheral interrupts */
nvic_irq_disable_all();
+
+ /* Turn off timers */
+ timer_disable_all();
+
+ /* Turn off ADC */
+ adc_disable_all();
+
+ /* Turn off all USARTs */
+ usart_disable_all();
+
+#if STM32_HAVE_USB
+ /* Turn the USB interrupt back on so the bootloader keeps on functioning */
+ nvic_irq_enable(NVIC_USB_HP_CAN_TX);
+ nvic_irq_enable(NVIC_USB_LP_CAN_RX0);
+#endif
}
/*
* Enable the error USART for writing.
*/
-/* usart_dev* __lm_enable_error_usart(void) { (TODO) } */
+usart_dev* __lm_enable_error_usart() {
+ // FIXME: gpio_set_mode(ERROR_TX_PORT, ERROR_TX_PIN, GPIO_AF_OUTPUT_PP);
+ usart_init(ERROR_USART);
+ usart_set_baud_rate(ERROR_USART, USART_USE_PCLK, ERROR_USART_BAUD);
+ return ERROR_USART;
+}
diff --git a/wirish/stm32f2/wirish_debug.cpp b/wirish/stm32f2-f4/wirish_debug.cpp
index af6c78b..af6c78b 100644
--- a/wirish/stm32f2/wirish_debug.cpp
+++ b/wirish/stm32f2-f4/wirish_debug.cpp
diff --git a/wirish/stm32f2/wirish_digital.cpp b/wirish/stm32f2-f4/wirish_digital.cpp
index 4d46f1c..4d46f1c 100644
--- a/wirish/stm32f2/wirish_digital.cpp
+++ b/wirish/stm32f2-f4/wirish_digital.cpp