stm32/boards: Add support for SparkFun STM32 MicroMod Processor board.

Signed-off-by: Chris Wilson <christopher.david.wilson@gmail.com>
This commit is contained in:
Chris Wilson 2021-07-11 16:39:56 -07:00 committed by Damien George
parent 341158c251
commit aecb697c72
6 changed files with 231 additions and 0 deletions

View File

@ -0,0 +1,28 @@
#include "storage.h"
#if !MICROPY_HW_ENABLE_INTERNAL_FLASH_STORAGE
// External SPI flash uses standard SPI interface
STATIC const mp_soft_spi_obj_t soft_spi_bus = {
.delay_half = MICROPY_HW_SOFTSPI_MIN_DELAY,
.polarity = 0,
.phase = 0,
.sck = MICROPY_HW_SPIFLASH_SCK,
.mosi = MICROPY_HW_SPIFLASH_MOSI,
.miso = MICROPY_HW_SPIFLASH_MISO,
};
STATIC mp_spiflash_cache_t spi_bdev_cache;
const mp_spiflash_config_t spiflash_config = {
.bus_kind = MP_SPIFLASH_BUS_SPI,
.bus.u_spi.cs = MICROPY_HW_SPIFLASH_CS,
.bus.u_spi.data = (void*)&soft_spi_bus,
.bus.u_spi.proto = &mp_soft_spi_proto,
.cache = &spi_bdev_cache,
};
spi_bdev_t spi_bdev;
#endif

View File

@ -0,0 +1,11 @@
#include "py/mphal.h"
void board_early_init(void) {
#if !MICROPY_HW_ENABLE_INTERNAL_FLASH_STORAGE
// set external SPI flash CS pin high
mp_hal_pin_output(MICROPY_HW_SPIFLASH_CS);
mp_hal_pin_write(MICROPY_HW_SPIFLASH_CS, 1);
#endif
}

View File

@ -0,0 +1,100 @@
// The Sparkfun MicroMod spec uses a zero-based peripheral numbering scheme.
// In cases where the 0th peripheral is the default, the "0" is omitted from
// the name (e.g. "I2C" instead of "I2C0").
//
// Note: UART (UART0) is not present in the edge connector pinout because the
// primary debug serial port is exposed as a virtual serial port over USB,
// i.e. Serial.print() should print over USB VCP, not UART_TX1.
//
// For more details, see https://www.sparkfun.com/micromod#tech-specs
#define MICROPY_HW_BOARD_NAME "SparkFun STM32 MicroMod Processor"
#define MICROPY_HW_MCU_NAME "STM32F405RG"
// 1 = use STM32 internal flash (1 MByte)
// 0 = use onboard external SPI flash (16 MByte)
#define MICROPY_HW_ENABLE_INTERNAL_FLASH_STORAGE (0)
#define MICROPY_HW_HAS_FLASH (1)
#define MICROPY_HW_ENABLE_RNG (1)
#define MICROPY_HW_ENABLE_RTC (1)
#define MICROPY_HW_ENABLE_DAC (1)
#define MICROPY_HW_ENABLE_USB (1)
// External SPI Flash config
#if !MICROPY_HW_ENABLE_INTERNAL_FLASH_STORAGE
// 128 Mbit (16 MByte) external SPI flash
#define MICROPY_HW_SPIFLASH_SIZE_BITS (128 * 1024 * 1024)
#define MICROPY_HW_SPIFLASH_CS (pin_C3)
#define MICROPY_HW_SPIFLASH_SCK (pin_C10)
#define MICROPY_HW_SPIFLASH_MOSI (pin_C12)
#define MICROPY_HW_SPIFLASH_MISO (pin_C11)
#define MICROPY_BOARD_EARLY_INIT board_early_init
void board_early_init(void);
extern const struct _mp_spiflash_config_t spiflash_config;
extern struct _spi_bdev_t spi_bdev;
#define MICROPY_HW_SPIFLASH_ENABLE_CACHE (1)
#define MICROPY_HW_BDEV_IOCTL(op, arg) ( \
(op) == BDEV_IOCTL_NUM_BLOCKS ? (MICROPY_HW_SPIFLASH_SIZE_BITS / 8 / FLASH_BLOCK_SIZE) : \
(op) == BDEV_IOCTL_INIT ? spi_bdev_ioctl(&spi_bdev, (op), (uint32_t)&spiflash_config) : \
spi_bdev_ioctl(&spi_bdev, (op), (arg)) \
)
#define MICROPY_HW_BDEV_READBLOCKS(dest, bl, n) spi_bdev_readblocks(&spi_bdev, (dest), (bl), (n))
#define MICROPY_HW_BDEV_WRITEBLOCKS(src, bl, n) spi_bdev_writeblocks(&spi_bdev, (src), (bl), (n))
#define MICROPY_HW_BDEV_SPIFLASH_EXTENDED (&spi_bdev) // for extended block protocol
#endif // !MICROPY_HW_ENABLE_INTERNAL_FLASH_STORAGE
// STM32 HSE config
// The module has a 12 MHz crystal for the HSE oscillator.
#define MICROPY_HW_CLK_PLLM (12)
#define MICROPY_HW_CLK_PLLN (336)
#define MICROPY_HW_CLK_PLLP (RCC_PLLP_DIV2)
#define MICROPY_HW_CLK_PLLQ (7)
#define MICROPY_HW_CLK_LAST_FREQ (1)
// STM32 LSE config
// The module has a 32.768 kHz crystal for the LSE (RTC).
#define MICROPY_HW_RTC_USE_LSE (1)
#define MICROPY_HW_RTC_USE_US (0)
#define MICROPY_HW_RTC_USE_CALOUT (1)
// UART1 config (MicroMod UART1)
#define MICROPY_HW_UART1_NAME "UART1"
#define MICROPY_HW_UART1_TX (pin_A2)
#define MICROPY_HW_UART1_RX (pin_A3)
// CAN1 config (MicroMod CAN)
#define MICROPY_HW_CAN1_NAME "CAN"
#define MICROPY_HW_CAN1_TX (pin_B9)
#define MICROPY_HW_CAN1_RX (pin_B8)
// I2C1 config (MicroMod I2C)
#define MICROPY_HW_I2C1_NAME "I2C"
#define MICROPY_HW_I2C1_SCL (pin_B10)
#define MICROPY_HW_I2C1_SDA (pin_B11)
// I2C2 config (MicroMod I2C1)
#define MICROPY_HW_I2C2_NAME "I2C1"
#define MICROPY_HW_I2C2_SCL (pin_B6)
#define MICROPY_HW_I2C2_SDA (pin_B7)
// SPI1 config (MicroMod SPI)
#define MICROPY_HW_SPI1_NAME "SPI"
#define MICROPY_HW_SPI1_NSS (pin_C4)
#define MICROPY_HW_SPI1_SCK (pin_A5)
#define MICROPY_HW_SPI1_MISO (pin_A6)
#define MICROPY_HW_SPI1_MOSI (pin_A7)
// LED1 config
// The module has a single blue status LED.
#define MICROPY_HW_LED1 (pin_A15)
#define MICROPY_HW_LED_ON(pin) (mp_hal_pin_high(pin))
#define MICROPY_HW_LED_OFF(pin) (mp_hal_pin_low(pin))
// USB device config
#define MICROPY_HW_USB_FS (1)

View File

@ -0,0 +1,16 @@
MCU_SERIES = f4
CMSIS_MCU = STM32F405xx
AF_FILE = boards/stm32f405_af.csv
ifeq ($(USE_MBOOT),1)
# When using Mboot all the text goes together after the filesystem
LD_FILES = boards/stm32f405.ld boards/common_blifs.ld
TEXT0_ADDR = 0x08020000
else
# When not using Mboot the ISR text goes first, then the rest after the filesystem
LD_FILES = boards/stm32f405.ld boards/common_ifs.ld
TEXT0_ADDR = 0x08000000
TEXT1_ADDR = 0x08020000
endif
# MicroPython settings
MICROPY_VFS_LFS2 = 1

View File

@ -0,0 +1,57 @@
G2,PA0
BUS2,PA0
BATT_SENSE,PA1
UART_TX1,PA2
UART_RX1,PA3
AUD_LRCLK,PA4
SPI_SCK,PA5
SPI_MISO,PA6
SPI_CIPO,PA6
SPI_MOSI,PA7
SPI_COPI,PA7
G1,PA8
BUS1,PA8
USB_DN,PA11
USB_DP,PA12
SWDIO,PA13
SWDCK,PA14
STATUS_LED,PA15
A1,PB0
I2C_INT,PB1
AUD_BCLK,PB3
AUD_OUT,PB4
AUD_IN,PB5
I2C_SCL1,PB6
I2C_SDA1,PB7
CAN_RX,PB8
CAN_TX,PB9
I2C_SCL,PB10
I2C_SDA,PB11
USB_HOST_ID,PB12
G11,PB12
USB_HOST_VBUS,PB13
G10,PB13
USB_HOST_DN,PB14
USB_HOST_DP,PB15
D0,PC0
D1,PC1
G6,PC2
BUS6,PC2
SPI_FLASH_CS,PC3
SPI_CS,PC4
A0,PC5
PWM0,PC6
PWM1,PC7
G3,PC8
BUS3,PC8
G4,PC9
BUS4,PC9
SPI_FLASH_SCK,PC10
SPI_FLASH_MISO,PC11
SPI_FLASH_MOSI,PC12
G5,PC13
BUS5,PC13
OSC32_IN,PC14
OSC32_OUT,PC15
G0,PD2
BUS0,PD2
1 G2 PA0
2 BUS2 PA0
3 BATT_SENSE PA1
4 UART_TX1 PA2
5 UART_RX1 PA3
6 AUD_LRCLK PA4
7 SPI_SCK PA5
8 SPI_MISO PA6
9 SPI_CIPO PA6
10 SPI_MOSI PA7
11 SPI_COPI PA7
12 G1 PA8
13 BUS1 PA8
14 USB_DN PA11
15 USB_DP PA12
16 SWDIO PA13
17 SWDCK PA14
18 STATUS_LED PA15
19 A1 PB0
20 I2C_INT PB1
21 AUD_BCLK PB3
22 AUD_OUT PB4
23 AUD_IN PB5
24 I2C_SCL1 PB6
25 I2C_SDA1 PB7
26 CAN_RX PB8
27 CAN_TX PB9
28 I2C_SCL PB10
29 I2C_SDA PB11
30 USB_HOST_ID PB12
31 G11 PB12
32 USB_HOST_VBUS PB13
33 G10 PB13
34 USB_HOST_DN PB14
35 USB_HOST_DP PB15
36 D0 PC0
37 D1 PC1
38 G6 PC2
39 BUS6 PC2
40 SPI_FLASH_CS PC3
41 SPI_CS PC4
42 A0 PC5
43 PWM0 PC6
44 PWM1 PC7
45 G3 PC8
46 BUS3 PC8
47 G4 PC9
48 BUS4 PC9
49 SPI_FLASH_SCK PC10
50 SPI_FLASH_MISO PC11
51 SPI_FLASH_MOSI PC12
52 G5 PC13
53 BUS5 PC13
54 OSC32_IN PC14
55 OSC32_OUT PC15
56 G0 PD2
57 BUS0 PD2

View File

@ -0,0 +1,19 @@
/* This file is part of the MicroPython project, http://micropython.org/
* The MIT License (MIT)
* Copyright (c) 2019 Damien P. George
*/
#ifndef MICROPY_INCLUDED_STM32F4XX_HAL_CONF_H
#define MICROPY_INCLUDED_STM32F4XX_HAL_CONF_H
#include "boards/stm32f4xx_hal_conf_base.h"
// Oscillator values in Hz
#define HSE_VALUE (12000000)
#define LSE_VALUE (32768)
#define EXTERNAL_CLOCK_VALUE (12288000)
// Oscillator timeouts in ms
#define HSE_STARTUP_TIMEOUT (100)
#define LSE_STARTUP_TIMEOUT (5000)
#endif // MICROPY_INCLUDED_STM32F4XX_HAL_CONF_H