summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2018-02-09 18:40:13 +1100
committerDamien George <damien.p.george@gmail.com>2018-02-09 18:40:13 +1100
commit2d5bab46be2175ff0d8db02a74afc34f0c8d287f (patch)
tree7be55d0e8cd24129ce830885287cc15738d3363e
parentbbb08431f3c45d94c1e6aa0762b8f13ccce1fe8e (diff)
stm32: Add mpconfigboard_common.h with common/default board settings.
This file mirrors py/mpconfig.h but for board-level config options. It provides a default configuration, to be overridden by a specific mpconfigboard.h file, as well as setting up certain macros to automatically configure a board.
-rw-r--r--ports/stm32/mpconfigboard_common.h116
-rw-r--r--ports/stm32/mpconfigport.h36
2 files changed, 120 insertions, 32 deletions
diff --git a/ports/stm32/mpconfigboard_common.h b/ports/stm32/mpconfigboard_common.h
new file mode 100644
index 000000000..1e3d6913b
--- /dev/null
+++ b/ports/stm32/mpconfigboard_common.h
@@ -0,0 +1,116 @@
+/*
+ * This file is part of the MicroPython project, http://micropython.org/
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2018 Damien P. George
+ *
+ * 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.
+ */
+
+// Common settings and defaults for board configuration.
+// The defaults here should be overridden in mpconfigboard.h.
+
+/*****************************************************************************/
+// Feature settings with defaults
+
+// Whether to enable the RTC, exposed as pyb.RTC
+#ifndef MICROPY_HW_ENABLE_RTC
+#define MICROPY_HW_ENABLE_RTC (0)
+#endif
+
+// Whether to enable the hardware RNG peripheral, exposed as pyb.rng()
+#ifndef MICROPY_HW_ENABLE_RNG
+#define MICROPY_HW_ENABLE_RNG (0)
+#endif
+
+// Whether to enable the DAC peripheral, exposed as pyb.DAC
+#ifndef MICROPY_HW_ENABLE_DAC
+#define MICROPY_HW_ENABLE_DAC (0)
+#endif
+
+// Whether to enable the CAN peripheral, exposed as pyb.CAN
+#ifndef MICROPY_HW_ENABLE_CAN
+#define MICROPY_HW_ENABLE_CAN (0)
+#endif
+
+// Whether to enable the PA0-PA3 servo driver, exposed as pyb.Servo
+#ifndef MICROPY_HW_ENABLE_SERVO
+#define MICROPY_HW_ENABLE_SERVO (0)
+#endif
+
+// Whether to enable a USR switch, exposed as pyb.Switch
+#ifndef MICROPY_HW_HAS_SWITCH
+#define MICROPY_HW_HAS_SWITCH (0)
+#endif
+
+// Whether to expose internal flash storage as pyb.Flash
+#ifndef MICROPY_HW_HAS_FLASH
+#define MICROPY_HW_HAS_FLASH (0)
+#endif
+
+// Whether to enable the SD card interface, exposed as pyb.SDCard
+#ifndef MICROPY_HW_HAS_SDCARD
+#define MICROPY_HW_HAS_SDCARD (0)
+#endif
+
+// Whether to enable the MMA7660 driver, exposed as pyb.Accel
+#ifndef MICROPY_HW_HAS_MMA7660
+#define MICROPY_HW_HAS_MMA7660 (0)
+#endif
+
+// Whether to enable the LCD32MK driver, exposed as pyb.LCD
+#ifndef MICROPY_HW_HAS_LCD
+#define MICROPY_HW_HAS_LCD (0)
+#endif
+
+/*****************************************************************************/
+// General configuration
+
+// Define the maximum number of peripherals that the MCU supports
+#if defined(MCU_SERIES_F7)
+#define PYB_EXTI_NUM_VECTORS (24)
+#define MICROPY_HW_MAX_TIMER (17)
+#define MICROPY_HW_MAX_UART (8)
+#elif defined(MCU_SERIES_L4)
+#define PYB_EXTI_NUM_VECTORS (23)
+#define MICROPY_HW_MAX_TIMER (17)
+#define MICROPY_HW_MAX_UART (6)
+#else
+#define PYB_EXTI_NUM_VECTORS (23)
+#define MICROPY_HW_MAX_TIMER (14)
+#define MICROPY_HW_MAX_UART (6)
+#endif
+
+// Enable hardware I2C if there are any peripherals defined
+#if defined(MICROPY_HW_I2C1_SCL) || defined(MICROPY_HW_I2C2_SCL) \
+ || defined(MICROPY_HW_I2C3_SCL) || defined(MICROPY_HW_I2C4_SCL)
+#define MICROPY_HW_ENABLE_HW_I2C (1)
+#else
+#define MICROPY_HW_ENABLE_HW_I2C (0)
+#endif
+
+// USB configuration
+// see stm32f4XX_hal_conf.h USE_USB_FS & USE_USB_HS
+// at the moment only USB_FS is supported
+#define USE_DEVICE_MODE
+//#define USE_HOST_MODE
+
+// Pin definition header file
+#define MICROPY_PIN_DEFS_PORT_H "pin_defs_stm32.h"
diff --git a/ports/stm32/mpconfigport.h b/ports/stm32/mpconfigport.h
index 6fa286b26..0ade01d15 100644
--- a/ports/stm32/mpconfigport.h
+++ b/ports/stm32/mpconfigport.h
@@ -29,6 +29,7 @@
// board specific definitions
#include "mpconfigboard.h"
+#include "mpconfigboard_common.h"
// memory allocation policies
#define MICROPY_ALLOC_PATH_MAX (128)
@@ -131,6 +132,9 @@
#define MICROPY_PY_MACHINE_PULSE (1)
#define MICROPY_PY_MACHINE_PIN_MAKE_NEW mp_pin_make_new
#define MICROPY_PY_MACHINE_I2C (1)
+#if MICROPY_HW_ENABLE_HW_I2C
+#define MICROPY_PY_MACHINE_I2C_MAKE_NEW machine_hard_i2c_make_new
+#endif
#define MICROPY_PY_MACHINE_SPI (1)
#define MICROPY_PY_MACHINE_SPI_MSB (SPI_FIRSTBIT_MSB)
#define MICROPY_PY_MACHINE_SPI_LSB (SPI_FIRSTBIT_LSB)
@@ -230,31 +234,6 @@ extern const struct _mp_obj_module_t mp_module_onewire;
{ MP_ROM_QSTR(MP_QSTR_pyb), MP_ROM_PTR(&pyb_module) }, \
{ MP_ROM_QSTR(MP_QSTR_stm), MP_ROM_PTR(&stm_module) }, \
-#if defined(MCU_SERIES_F7)
-#define PYB_EXTI_NUM_VECTORS (24)
-#define MICROPY_HW_MAX_TIMER (17)
-#define MICROPY_HW_MAX_UART (8)
-#elif defined(MCU_SERIES_L4)
-#define PYB_EXTI_NUM_VECTORS (23)
-#define MICROPY_HW_MAX_TIMER (17)
-#define MICROPY_HW_MAX_UART (6)
-#else
-#define PYB_EXTI_NUM_VECTORS (23)
-#define MICROPY_HW_MAX_TIMER (14)
-#define MICROPY_HW_MAX_UART (6)
-#endif
-
-// enable hardware I2C if there are any peripherals defined
-#define MICROPY_HW_ENABLE_HW_I2C ( \
- defined(MICROPY_HW_I2C1_SCL) \
- || defined(MICROPY_HW_I2C2_SCL) \
- || defined(MICROPY_HW_I2C3_SCL) \
- || defined(MICROPY_HW_I2C4_SCL) \
-)
-#if MICROPY_HW_ENABLE_HW_I2C
-#define MICROPY_PY_MACHINE_I2C_MAKE_NEW machine_hard_i2c_make_new
-#endif
-
#define MP_STATE_PORT MP_STATE_VM
#define MICROPY_PORT_ROOT_POINTERS \
@@ -361,12 +340,5 @@ static inline mp_uint_t disable_irq(void) {
#define free(p) m_free(p)
#define realloc(p, n) m_realloc(p, n)
-// see stm32f4XX_hal_conf.h USE_USB_FS & USE_USB_HS
-// at the moment only USB_FS is supported
-#define USE_DEVICE_MODE
-//#define USE_HOST_MODE
-
// We need to provide a declaration/definition of alloca()
#include <alloca.h>
-
-#define MICROPY_PIN_DEFS_PORT_H "pin_defs_stm32.h"