2018-02-09 02:40:13 -05:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
|
2018-02-23 00:54:07 -05:00
|
|
|
#include STM32_HAL_H
|
|
|
|
|
2018-02-09 02:40:13 -05:00
|
|
|
/*****************************************************************************/
|
|
|
|
// Feature settings with defaults
|
|
|
|
|
2018-04-23 22:01:49 -04:00
|
|
|
// Whether to include the stm module, with peripheral register constants
|
|
|
|
#ifndef MICROPY_PY_STM
|
|
|
|
#define MICROPY_PY_STM (1)
|
|
|
|
#endif
|
|
|
|
|
2018-05-13 23:49:22 -04:00
|
|
|
// Whether to include legacy functions and classes in the pyb module
|
|
|
|
#ifndef MICROPY_PY_PYB_LEGACY
|
|
|
|
#define MICROPY_PY_PYB_LEGACY (1)
|
|
|
|
#endif
|
|
|
|
|
2018-03-09 08:50:27 -05:00
|
|
|
// Whether to enable storage on the internal flash of the MCU
|
|
|
|
#ifndef MICROPY_HW_ENABLE_INTERNAL_FLASH_STORAGE
|
|
|
|
#define MICROPY_HW_ENABLE_INTERNAL_FLASH_STORAGE (1)
|
|
|
|
#endif
|
|
|
|
|
2018-02-09 02:40:13 -05:00
|
|
|
// 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
|
|
|
|
|
2018-02-21 22:22:45 -05:00
|
|
|
// Whether to enable the ADC peripheral, exposed as pyb.ADC and pyb.ADCAll
|
|
|
|
#ifndef MICROPY_HW_ENABLE_ADC
|
|
|
|
#define MICROPY_HW_ENABLE_ADC (1)
|
|
|
|
#endif
|
|
|
|
|
2018-02-09 02:40:13 -05:00
|
|
|
// Whether to enable the DAC peripheral, exposed as pyb.DAC
|
|
|
|
#ifndef MICROPY_HW_ENABLE_DAC
|
|
|
|
#define MICROPY_HW_ENABLE_DAC (0)
|
|
|
|
#endif
|
|
|
|
|
2018-09-16 23:47:54 -04:00
|
|
|
// Whether to enable the DCMI peripheral
|
|
|
|
#ifndef MICROPY_HW_ENABLE_DCMI
|
|
|
|
#define MICROPY_HW_ENABLE_DCMI (0)
|
|
|
|
#endif
|
|
|
|
|
2018-02-13 02:51:08 -05:00
|
|
|
// Whether to enable USB support
|
|
|
|
#ifndef MICROPY_HW_ENABLE_USB
|
|
|
|
#define MICROPY_HW_ENABLE_USB (0)
|
|
|
|
#endif
|
|
|
|
|
2018-02-09 02:40:13 -05:00
|
|
|
// 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
|
2019-04-01 00:21:26 -04:00
|
|
|
#ifndef MICROPY_HW_ENABLE_SDCARD
|
|
|
|
#define MICROPY_HW_ENABLE_SDCARD (0)
|
2018-02-09 02:40:13 -05:00
|
|
|
#endif
|
|
|
|
|
2019-04-01 00:55:04 -04:00
|
|
|
// Whether to enable the MMC interface, exposed as pyb.MMCard
|
|
|
|
#ifndef MICROPY_HW_ENABLE_MMCARD
|
|
|
|
#define MICROPY_HW_ENABLE_MMCARD (0)
|
|
|
|
#endif
|
|
|
|
|
2018-12-02 15:44:42 -05:00
|
|
|
// Whether to automatically mount (and boot from) the SD card if it's present
|
|
|
|
#ifndef MICROPY_HW_SDCARD_MOUNT_AT_BOOT
|
2019-04-01 00:21:26 -04:00
|
|
|
#define MICROPY_HW_SDCARD_MOUNT_AT_BOOT (MICROPY_HW_ENABLE_SDCARD)
|
2018-12-02 15:44:42 -05:00
|
|
|
#endif
|
|
|
|
|
2018-02-09 02:40:13 -05:00
|
|
|
// 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
|
|
|
|
|
2018-04-11 02:52:22 -04:00
|
|
|
// The volume label used when creating the flash filesystem
|
|
|
|
#ifndef MICROPY_HW_FLASH_FS_LABEL
|
|
|
|
#define MICROPY_HW_FLASH_FS_LABEL "pybflash"
|
|
|
|
#endif
|
|
|
|
|
2018-02-09 02:40:13 -05:00
|
|
|
/*****************************************************************************/
|
|
|
|
// General configuration
|
|
|
|
|
2018-10-02 08:08:25 -04:00
|
|
|
// Heap start / end definitions
|
|
|
|
#ifndef MICROPY_HEAP_START
|
|
|
|
#define MICROPY_HEAP_START &_heap_start
|
|
|
|
#endif
|
|
|
|
#ifndef MICROPY_HEAP_END
|
|
|
|
#define MICROPY_HEAP_END &_heap_end
|
|
|
|
#endif
|
|
|
|
|
2018-05-28 04:10:53 -04:00
|
|
|
// Configuration for STM32F0 series
|
|
|
|
#if defined(STM32F0)
|
|
|
|
|
|
|
|
#define MP_HAL_UNIQUE_ID_ADDRESS (0x1ffff7ac)
|
|
|
|
#define PYB_EXTI_NUM_VECTORS (23)
|
2019-04-17 20:31:44 -04:00
|
|
|
#define MICROPY_HW_MAX_I2C (2)
|
2018-05-28 04:10:53 -04:00
|
|
|
#define MICROPY_HW_MAX_TIMER (17)
|
|
|
|
#define MICROPY_HW_MAX_UART (8)
|
|
|
|
|
2018-02-23 00:54:07 -05:00
|
|
|
// Configuration for STM32F4 series
|
2018-05-28 04:10:53 -04:00
|
|
|
#elif defined(STM32F4)
|
2018-02-23 00:54:07 -05:00
|
|
|
|
|
|
|
#define MP_HAL_UNIQUE_ID_ADDRESS (0x1fff7a10)
|
|
|
|
#define PYB_EXTI_NUM_VECTORS (23)
|
2019-04-17 20:31:44 -04:00
|
|
|
#define MICROPY_HW_MAX_I2C (3)
|
2018-02-23 00:54:07 -05:00
|
|
|
#define MICROPY_HW_MAX_TIMER (14)
|
2019-04-19 01:15:18 -04:00
|
|
|
#if defined(UART10)
|
|
|
|
#define MICROPY_HW_MAX_UART (10)
|
|
|
|
#elif defined(UART9)
|
|
|
|
#define MICROPY_HW_MAX_UART (9)
|
|
|
|
#elif defined(UART8)
|
2018-05-14 22:46:58 -04:00
|
|
|
#define MICROPY_HW_MAX_UART (8)
|
2019-04-19 01:15:18 -04:00
|
|
|
#elif defined(UART7)
|
|
|
|
#define MICROPY_HW_MAX_UART (7)
|
2018-05-14 22:46:58 -04:00
|
|
|
#else
|
2018-02-23 00:54:07 -05:00
|
|
|
#define MICROPY_HW_MAX_UART (6)
|
2018-05-14 22:46:58 -04:00
|
|
|
#endif
|
2018-02-23 00:54:07 -05:00
|
|
|
|
|
|
|
// Configuration for STM32F7 series
|
|
|
|
#elif defined(STM32F7)
|
|
|
|
|
|
|
|
#if defined(STM32F722xx) || defined(STM32F723xx) || defined(STM32F732xx) || defined(STM32F733xx)
|
|
|
|
#define MP_HAL_UNIQUE_ID_ADDRESS (0x1ff07a10)
|
|
|
|
#else
|
|
|
|
#define MP_HAL_UNIQUE_ID_ADDRESS (0x1ff0f420)
|
|
|
|
#endif
|
|
|
|
|
2018-02-09 02:40:13 -05:00
|
|
|
#define PYB_EXTI_NUM_VECTORS (24)
|
2019-04-17 20:31:44 -04:00
|
|
|
#define MICROPY_HW_MAX_I2C (4)
|
2018-02-09 02:40:13 -05:00
|
|
|
#define MICROPY_HW_MAX_TIMER (17)
|
|
|
|
#define MICROPY_HW_MAX_UART (8)
|
2018-02-23 00:54:07 -05:00
|
|
|
|
2018-02-24 19:00:12 -05:00
|
|
|
// Configuration for STM32H7 series
|
|
|
|
#elif defined(STM32H7)
|
|
|
|
|
|
|
|
#define MP_HAL_UNIQUE_ID_ADDRESS (0x1ff1e800)
|
|
|
|
#define PYB_EXTI_NUM_VECTORS (24)
|
2019-05-20 22:38:34 -04:00
|
|
|
#define MICROPY_HW_MAX_I2C (4)
|
2018-02-24 19:00:12 -05:00
|
|
|
#define MICROPY_HW_MAX_TIMER (17)
|
|
|
|
#define MICROPY_HW_MAX_UART (8)
|
|
|
|
|
2019-07-05 03:24:59 -04:00
|
|
|
// Configuration for STM32L0 series
|
|
|
|
#elif defined(STM32L0)
|
|
|
|
|
|
|
|
#define MP_HAL_UNIQUE_ID_ADDRESS (0x1FF80050)
|
|
|
|
#define PYB_EXTI_NUM_VECTORS (30) // TODO (22 configurable, 7 direct)
|
|
|
|
#define MICROPY_HW_MAX_I2C (3)
|
|
|
|
#define MICROPY_HW_MAX_TIMER (22)
|
|
|
|
#define MICROPY_HW_MAX_UART (4)
|
|
|
|
|
2018-02-23 00:54:07 -05:00
|
|
|
// Configuration for STM32L4 series
|
|
|
|
#elif defined(STM32L4)
|
|
|
|
|
|
|
|
#define MP_HAL_UNIQUE_ID_ADDRESS (0x1fff7590)
|
2018-02-09 02:40:13 -05:00
|
|
|
#define PYB_EXTI_NUM_VECTORS (23)
|
2019-05-20 22:38:34 -04:00
|
|
|
#define MICROPY_HW_MAX_I2C (4)
|
2018-02-09 02:40:13 -05:00
|
|
|
#define MICROPY_HW_MAX_TIMER (17)
|
|
|
|
#define MICROPY_HW_MAX_UART (6)
|
2018-02-23 00:54:07 -05:00
|
|
|
|
2018-02-09 02:40:13 -05:00
|
|
|
#else
|
2018-02-23 00:54:07 -05:00
|
|
|
#error Unsupported MCU series
|
2018-02-09 02:40:13 -05:00
|
|
|
#endif
|
|
|
|
|
2019-03-03 18:50:23 -05:00
|
|
|
#if MICROPY_HW_CLK_USE_HSI
|
|
|
|
// Use HSI as clock source
|
|
|
|
#define MICROPY_HW_CLK_VALUE (HSI_VALUE)
|
|
|
|
#define MICROPY_HW_RCC_OSCILLATOR_TYPE (RCC_OSCILLATORTYPE_HSI)
|
|
|
|
#define MICROPY_HW_RCC_PLL_SRC (RCC_PLLSOURCE_HSI)
|
|
|
|
#define MICROPY_HW_RCC_CR_HSxON (RCC_CR_HSION)
|
|
|
|
#define MICROPY_HW_RCC_HSI_STATE (RCC_HSI_ON)
|
|
|
|
#define MICROPY_HW_RCC_FLAG_HSxRDY (RCC_FLAG_HSIRDY)
|
|
|
|
#define MICROPY_HW_RCC_HSE_STATE (RCC_HSE_OFF)
|
|
|
|
#else
|
|
|
|
// Use HSE as a clock source (bypass or oscillator)
|
|
|
|
#define MICROPY_HW_CLK_VALUE (HSE_VALUE)
|
|
|
|
#define MICROPY_HW_RCC_OSCILLATOR_TYPE (RCC_OSCILLATORTYPE_HSE)
|
|
|
|
#define MICROPY_HW_RCC_PLL_SRC (RCC_PLLSOURCE_HSE)
|
|
|
|
#define MICROPY_HW_RCC_CR_HSxON (RCC_CR_HSEON)
|
|
|
|
#define MICROPY_HW_RCC_HSI_STATE (RCC_HSI_OFF)
|
|
|
|
#define MICROPY_HW_RCC_FLAG_HSxRDY (RCC_FLAG_HSERDY)
|
2018-04-11 02:46:47 -04:00
|
|
|
#if MICROPY_HW_CLK_USE_BYPASS
|
2019-03-03 18:50:23 -05:00
|
|
|
#define MICROPY_HW_RCC_HSE_STATE (RCC_HSE_BYPASS)
|
2018-04-11 02:46:47 -04:00
|
|
|
#else
|
2019-03-03 18:50:23 -05:00
|
|
|
#define MICROPY_HW_RCC_HSE_STATE (RCC_HSE_ON)
|
|
|
|
#endif
|
2018-04-11 02:46:47 -04:00
|
|
|
#endif
|
|
|
|
|
2019-04-10 22:09:21 -04:00
|
|
|
// If disabled then try normal (non-bypass) LSE first, with fallback to LSI.
|
|
|
|
// If enabled first try LSE in bypass mode. If that fails to start, try non-bypass mode, with fallback to LSI.
|
|
|
|
#ifndef MICROPY_HW_RTC_USE_BYPASS
|
|
|
|
#define MICROPY_HW_RTC_USE_BYPASS (0)
|
|
|
|
#endif
|
|
|
|
|
2018-03-09 08:50:27 -05:00
|
|
|
#if MICROPY_HW_ENABLE_INTERNAL_FLASH_STORAGE
|
|
|
|
// Provide block device macros if internal flash storage is enabled
|
|
|
|
#define MICROPY_HW_BDEV_IOCTL flash_bdev_ioctl
|
|
|
|
#define MICROPY_HW_BDEV_READBLOCK flash_bdev_readblock
|
|
|
|
#define MICROPY_HW_BDEV_WRITEBLOCK flash_bdev_writeblock
|
|
|
|
#endif
|
|
|
|
|
2018-05-27 20:57:27 -04:00
|
|
|
// Enable the storage sub-system if a block device is defined
|
|
|
|
#if defined(MICROPY_HW_BDEV_IOCTL)
|
|
|
|
#define MICROPY_HW_ENABLE_STORAGE (1)
|
|
|
|
#else
|
|
|
|
#define MICROPY_HW_ENABLE_STORAGE (0)
|
|
|
|
#endif
|
|
|
|
|
2018-02-09 02:40:13 -05:00
|
|
|
// 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
|
|
|
|
|
2018-04-11 02:27:48 -04:00
|
|
|
// Enable CAN if there are any peripherals defined
|
2019-04-19 01:15:18 -04:00
|
|
|
#if defined(MICROPY_HW_CAN1_TX) || defined(MICROPY_HW_CAN2_TX) || defined(MICROPY_HW_CAN3_TX)
|
2018-04-11 02:27:48 -04:00
|
|
|
#define MICROPY_HW_ENABLE_CAN (1)
|
|
|
|
#else
|
|
|
|
#define MICROPY_HW_ENABLE_CAN (0)
|
2019-04-19 01:15:18 -04:00
|
|
|
#define MICROPY_HW_MAX_CAN (0)
|
2018-04-11 02:27:48 -04:00
|
|
|
#endif
|
2019-04-19 01:15:18 -04:00
|
|
|
#if defined(MICROPY_HW_CAN3_TX)
|
|
|
|
#define MICROPY_HW_MAX_CAN (3)
|
|
|
|
#elif defined(MICROPY_HW_CAN2_TX)
|
|
|
|
#define MICROPY_HW_MAX_CAN (2)
|
|
|
|
#elif defined(MICROPY_HW_CAN1_TX)
|
|
|
|
#define MICROPY_HW_MAX_CAN (1)
|
|
|
|
#endif
|
|
|
|
|
2019-07-16 00:39:21 -04:00
|
|
|
// Configure maximum number of CDC VCP interfaces, and whether MSC/HID are supported
|
2019-05-18 09:01:36 -04:00
|
|
|
#ifndef MICROPY_HW_USB_CDC_NUM
|
|
|
|
#define MICROPY_HW_USB_CDC_NUM (1)
|
|
|
|
#endif
|
2019-07-16 00:39:21 -04:00
|
|
|
#ifndef MICROPY_HW_USB_MSC
|
|
|
|
#define MICROPY_HW_USB_MSC (MICROPY_HW_ENABLE_USB)
|
|
|
|
#endif
|
|
|
|
#ifndef MICROPY_HW_USB_HID
|
|
|
|
#define MICROPY_HW_USB_HID (MICROPY_HW_ENABLE_USB)
|
|
|
|
#endif
|
2018-04-11 02:27:48 -04:00
|
|
|
|
2018-02-09 02:40:13 -05:00
|
|
|
// Pin definition header file
|
|
|
|
#define MICROPY_PIN_DEFS_PORT_H "pin_defs_stm32.h"
|
2018-02-23 00:54:07 -05:00
|
|
|
|
|
|
|
// D-cache clean/invalidate helpers
|
|
|
|
#if __DCACHE_PRESENT == 1
|
|
|
|
#define MP_HAL_CLEANINVALIDATE_DCACHE(addr, size) \
|
|
|
|
(SCB_CleanInvalidateDCache_by_Addr((uint32_t*)((uint32_t)addr & ~0x1f), \
|
|
|
|
((uint32_t)((uint8_t*)addr + size + 0x1f) & ~0x1f) - ((uint32_t)addr & ~0x1f)))
|
|
|
|
#define MP_HAL_CLEAN_DCACHE(addr, size) \
|
|
|
|
(SCB_CleanDCache_by_Addr((uint32_t*)((uint32_t)addr & ~0x1f), \
|
|
|
|
((uint32_t)((uint8_t*)addr + size + 0x1f) & ~0x1f) - ((uint32_t)addr & ~0x1f)))
|
|
|
|
#else
|
|
|
|
#define MP_HAL_CLEANINVALIDATE_DCACHE(addr, size)
|
|
|
|
#define MP_HAL_CLEAN_DCACHE(addr, size)
|
|
|
|
#endif
|
2018-03-29 01:16:58 -04:00
|
|
|
|
|
|
|
#define MICROPY_HW_USES_BOOTLOADER (MICROPY_HW_VTOR != 0x08000000)
|