Skip to content

Commit 22804fc

Browse files
andrewleechdpgeorge
authored andcommitted
stm32/boards/WEACT_F411_BLACKPILL: Add WeAct F411 'blackpill' boards.
Adds board profile for the WeAct F411 'blackpill' which is a quite popular low cost ST dev board. This board also has optional spiflash so can be purchased in a few different configurations. Builds for v3.1 with no SPI Flash by default. Includes variants for different board versions and spi flash sizes. Signed-off-by: Andrew Leech <[email protected]>
1 parent a9945fc commit 22804fc

12 files changed

+345
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
WeAct F411 'blackpill'
2+
======================
3+
4+
The WeAct F411 blackpill board comes in a number of versions and variants.
5+
All have a footprint for a SPI flash chip on the back, though the board is
6+
often sold without any flash chip loaded.
7+
8+
At the time of writing (Sep 2024) v3.1 is the current version.
9+
This version is sold with both 25Mhz HSE crystal (same as previous versions) and also
10+
with a 8Mhz crystal. The end user should be careful to confirm which variant is
11+
purchased and/or read the markings on the crystal to know which variant build to load.
12+
13+
The previous v2.0 boards had changed the MCU pinout for the spi flash chip so requires
14+
soft-spi support enabled in the variant settings, unlike v3.1 or v1.3 which is
15+
compatible with the hardware spi peripheral.
16+
17+
The original v1.3 boards did not include a user switch on the top, it only has
18+
"BOOT0" and "NRST" switches to load bootloader and reset the board respectively.
19+
20+
For more information see: https://github.com/WeActStudio/WeActStudio.MiniSTM32F4x1
21+
22+
Note: The pins used by features like spiflash and USB are also broken out to the
23+
gpio headers on the sides of the board.
24+
If these peripherals / features are enabled then these external pins must be avoided to ensure
25+
there are no conflicts. [pins.csv](pins.csv) should be consulted to check all pins assigned
26+
to alternate functions on the board.
27+
28+
Customising the build
29+
---------------------
30+
31+
After purchasing a board without any spiflash chip loaded the user can solder on
32+
their own of any desired size. Most brands of spiflash in SO8 pinout are compatible
33+
however some do have a slightly different protocol so may not work out of the box
34+
with micropython. Brand compatibility is outide the scope of this doc.
35+
36+
Once a custom spiflash chip has been loaded onto the board micropython should
37+
be built with the flash size specified. After doing so the spiflash chip will
38+
be used for the FAT/LFS main filesystem.
39+
40+
Examples:
41+
42+
For a v3.1 / 25Mhz (default version) board with 16MiB flash chip loaded:
43+
``` bash
44+
make -C ports/stm32 BOARD=WEACT_F411_BLACKPILL SPI_FLASH_SIZE_MB=16
45+
```
46+
47+
For a v3.1 / 8Mhz board with 4MiB flash chip loaded:
48+
``` bash
49+
make -C ports/stm32 BOARD=WEACT_F411_BLACKPILL BOARD_VARIANT=V31_XTAL_8M SPI_FLASH_SIZE_MB=4
50+
```
51+
52+
For a v1.3 board with 2MiB flash chip loaded and XTAL manually replaced with 8Mhz:
53+
``` bash
54+
make -C ports/stm32 BOARD=WEACT_F411_BLACKPILL BOARD_VARIANT=V13 SPI_FLASH_SIZE_MB=2 XTAL_FREQ_MHZ=8
55+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#include "storage.h"
2+
#include "spi.h"
3+
#include "py/mpconfig.h"
4+
5+
#if !MICROPY_HW_ENABLE_INTERNAL_FLASH_STORAGE
6+
7+
#if WEACT_F411_V20
8+
// External SPI flash uses SPI interface, but not on all HW spi pins.
9+
static const mp_soft_spi_obj_t spi_bus = {
10+
.delay_half = MICROPY_HW_SOFTSPI_MIN_DELAY,
11+
.polarity = 0,
12+
.phase = 0,
13+
.sck = MICROPY_HW_SPIFLASH_SCK,
14+
.mosi = MICROPY_HW_SPIFLASH_MOSI,
15+
.miso = MICROPY_HW_SPIFLASH_MISO,
16+
};
17+
18+
#else // WEACT_F411_V1.3 or WEACT_F411_V3.1
19+
static const spi_proto_cfg_t spi_bus = {
20+
.spi = &spi_obj[0], // SPI1
21+
.baudrate = 25000000,
22+
.polarity = 0,
23+
.phase = 0,
24+
.bits = 8,
25+
.firstbit = SPI_FIRSTBIT_MSB,
26+
};
27+
#endif
28+
29+
#if MICROPY_HW_SPIFLASH_ENABLE_CACHE
30+
static mp_spiflash_cache_t spi_bdev_cache;
31+
#endif
32+
33+
const mp_spiflash_config_t spiflash_config = {
34+
.bus_kind = MP_SPIFLASH_BUS_SPI,
35+
.bus.u_spi.cs = MICROPY_HW_SPIFLASH_CS,
36+
.bus.u_spi.data = (void *)&spi_bus,
37+
.bus.u_spi.proto = &spi_proto,
38+
#if MICROPY_HW_SPIFLASH_ENABLE_CACHE
39+
.cache = &spi_bdev_cache,
40+
#endif
41+
};
42+
43+
spi_bdev_t spi_bdev;
44+
45+
#endif
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"deploy": [
3+
"../PYBV10/deploy.md"
4+
],
5+
"docs": "",
6+
"features": [],
7+
"images": [
8+
"WEACTV20_F411.jpg"
9+
],
10+
"mcu": "stm32f411",
11+
"product": "WeAct F411 'blackpill'. Default variant is v3.1 with no SPI Flash.",
12+
"thumbnail": "",
13+
"url": "https://github.com/WeActStudio/WeActStudio.MiniSTM32F4x1",
14+
"variants": {
15+
"V13": "v1.3 board with no SPI Flash",
16+
"V13_FLASH_4M": "v1.3 board with 4MB SPI Flash",
17+
"V20_FLASH_4M": "v2.0 board with 4MB SPI Flash",
18+
"V31_FLASH_8M": "v3.1 board with 8MB SPI Flash",
19+
"V31_XTAL_8M": "v3.1 board with 8MHz crystal"
20+
},
21+
"vendor": "WeAct Studio"
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
// based off the following two repositories:
2+
// * https://github.com/mcauser/WEACT_F411CEU6
3+
// * https://github.com/YXZhu/micropython
4+
5+
#define MICROPY_HW_BOARD_NAME "WEACT_F411_BLACKPILL"
6+
#define MICROPY_HW_MCU_NAME "STM32F411CE"
7+
#define MICROPY_HW_FLASH_FS_LABEL "WEACT_F411_BLACKPILL"
8+
9+
// some users having issues with FLASH_LATENCY_2, so set to 3
10+
// from https://forum.micropython.org/viewtopic.php?t=7154
11+
#define MICROPY_HW_FLASH_LATENCY FLASH_LATENCY_3
12+
13+
#define MICROPY_HW_HAS_FLASH (1)
14+
#define MICROPY_HW_ENABLE_RTC (1)
15+
#define MICROPY_HW_ENABLE_USB (1)
16+
#define MICROPY_HW_USB_FS (1)
17+
18+
// Switch
19+
#if WEACT_F411_V13
20+
#define MICROPY_HW_HAS_SWITCH (0)
21+
#else
22+
#define MICROPY_HW_HAS_SWITCH (1)
23+
#define MICROPY_HW_USRSW_PIN (pyb_pin_SW)
24+
#define MICROPY_HW_USRSW_PULL (GPIO_PULLUP)
25+
#define MICROPY_HW_USRSW_EXTI_MODE (GPIO_MODE_IT_FALLING)
26+
#define MICROPY_HW_USRSW_PRESSED (0)
27+
#endif
28+
29+
// LEDs
30+
#define MICROPY_HW_LED1 (pyb_pin_LED_BLUE)
31+
#define MICROPY_HW_LED_ON(pin) (mp_hal_pin_low(pin))
32+
#define MICROPY_HW_LED_OFF(pin) (mp_hal_pin_high(pin))
33+
34+
// RTC
35+
#define MICROPY_HW_RTC_USE_LSE (1)
36+
#define MICROPY_HW_RTC_USE_US (0)
37+
#define MICROPY_HW_RTC_USE_CALOUT (1)
38+
39+
// Set PLLM same as HSE in MHZ.
40+
#define MICROPY_HW_CLK_PLLM (MICROPY_HW_HSE_SPEED_MHZ)
41+
// Configure PLL for final CPU freq of 96MHz
42+
#define MICROPY_HW_CLK_PLLN (192)
43+
#define MICROPY_HW_CLK_PLLP (RCC_PLLP_DIV2)
44+
#define MICROPY_HW_CLK_PLLQ (4)
45+
46+
// UART config
47+
#define MICROPY_HW_UART1_TX (pin_A9)
48+
#define MICROPY_HW_UART1_RX (pin_A10)
49+
50+
#define MICROPY_HW_UART2_TX (pin_A2)
51+
#define MICROPY_HW_UART2_RX (pin_A3)
52+
53+
#define MICROPY_HW_UART_REPL (PYB_UART_1)
54+
#define MICROPY_HW_UART_REPL_BAUD (115200)
55+
56+
// I2C bus
57+
#define MICROPY_HW_I2C1_SCL (pin_B6)
58+
#define MICROPY_HW_I2C1_SDA (pin_B7)
59+
#define MICROPY_HW_I2C2_SCL (pin_B10)
60+
#define MICROPY_HW_I2C2_SDA (pin_B9)
61+
#define MICROPY_HW_I2C3_SCL (pin_A8)
62+
#define MICROPY_HW_I2C3_SDA (pin_B8)
63+
64+
// SPI bus
65+
// SPI 1 is generally used for the SPI flash if enabled below.
66+
#define MICROPY_HW_SPI1_NSS (pin_A4)
67+
#define MICROPY_HW_SPI1_SCK (pin_A5)
68+
#define MICROPY_HW_SPI1_MISO (pin_A6)
69+
#define MICROPY_HW_SPI1_MOSI (pin_A7)
70+
71+
#define MICROPY_HW_SPI2_NSS (pin_B12)
72+
#define MICROPY_HW_SPI2_SCK (pin_B13)
73+
#define MICROPY_HW_SPI2_MISO (pin_B14)
74+
#define MICROPY_HW_SPI2_MOSI (pin_B15)
75+
76+
// SPI 3 is not accessible if SPI flash module is used on V2.0 (PB4 conflict)
77+
#define MICROPY_HW_SPI3_NSS (pin_A15)
78+
#define MICROPY_HW_SPI3_SCK (pin_B3)
79+
#define MICROPY_HW_SPI3_MISO (pin_B4)
80+
#define MICROPY_HW_SPI3_MOSI (pin_B5)
81+
82+
// External SPI Flash configuration
83+
84+
#if !MICROPY_HW_SPIFLASH_SIZE_BYTES
85+
// Use internal filesystem if spiflash not enabled.
86+
#define MICROPY_HW_ENABLE_INTERNAL_FLASH_STORAGE (1)
87+
88+
#else
89+
// Disable internal filesystem to use spiflash.
90+
#define MICROPY_HW_ENABLE_INTERNAL_FLASH_STORAGE (0)
91+
92+
// SPI flash pins
93+
#define MICROPY_HW_SPIFLASH_CS (pyb_pin_FLASH_CS)
94+
#define MICROPY_HW_SPIFLASH_SCK (pyb_pin_FLASH_SCK)
95+
#define MICROPY_HW_SPIFLASH_MOSI (pyb_pin_FLASH_MOSI)
96+
#if WEACT_F411_V13
97+
#define MICROPY_HW_SPIFLASH_MISO (pyb_pin_FLASH_MISO_V13)
98+
#elif WEACT_F411_V20
99+
#define MICROPY_HW_SPIFLASH_MISO (pyb_pin_FLASH_MISO_V20)
100+
#else
101+
#define MICROPY_HW_SPIFLASH_MISO (pyb_pin_FLASH_MISO_V31)
102+
#endif
103+
104+
extern const struct _mp_spiflash_config_t spiflash_config;
105+
extern struct _spi_bdev_t spi_bdev;
106+
#define MICROPY_HW_SPIFLASH_ENABLE_CACHE (1)
107+
#define MICROPY_HW_BDEV_SPIFLASH (&spi_bdev)
108+
#define MICROPY_HW_BDEV_SPIFLASH_CONFIG (&spiflash_config)
109+
#define MICROPY_HW_BDEV_SPIFLASH_SIZE_BYTES (MICROPY_HW_SPIFLASH_SIZE_BITS / 8)
110+
#define MICROPY_HW_BDEV_SPIFLASH_EXTENDED (&spi_bdev) // for extended block protocol
111+
#define MICROPY_HW_SPIFLASH_SIZE_BITS (MICROPY_HW_SPIFLASH_SIZE_BYTES * 8)
112+
#endif
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
MCU_SERIES = f4
2+
CMSIS_MCU = STM32F411xE
3+
AF_FILE = boards/stm32f411_af.csv
4+
LD_FILES = boards/stm32f411.ld boards/common_ifs.ld
5+
TEXT0_ADDR = 0x08000000
6+
TEXT1_ADDR = 0x08020000
7+
8+
MICROPY_VFS_LFS2 = 1
9+
10+
# Settings for version, spi flash and HSE xtal.
11+
# These are used in variant configs and/or on make command line.
12+
# If provided on make command line the build folder name will be updated to match
13+
# When set in variant they're included after this file so the following ifdef blocks are ignored.
14+
15+
ifdef BOARD_VERSION
16+
BUILD := $(BUILD)_V$(BOARD_VERSION)
17+
endif
18+
19+
ifdef SPI_FLASH_SIZE_MB
20+
BUILD := $(BUILD)_FLASH_$(SPI_FLASH_SIZE_MB)M
21+
endif
22+
23+
ifdef XTAL_FREQ_MHZ
24+
BUILD := $(BUILD)_XTAL_$(XTAL_FREQ_MHZ)M
25+
endif
26+
27+
# Blackpill v3.1 board by default
28+
BOARD_VERSION ?= 31
29+
30+
# No flash chip in default build - use internal flash
31+
SPI_FLASH_SIZE_MB ?= 0
32+
33+
# 25Mhz HSE crystal by default.
34+
XTAL_FREQ_MHZ ?= 25
35+
36+
CFLAGS += -DWEACT_F411_V$(BOARD_VERSION)=1
37+
CFLAGS += -DMICROPY_HW_SPIFLASH_SIZE_BYTES="($(SPI_FLASH_SIZE_MB) * 1024 * 1024)"
38+
CFLAGS += -DMICROPY_HW_HSE_SPEED_MHZ="($(XTAL_FREQ_MHZ))"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
BOARD_VERSION = 13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
BOARD_VERSION = 13
2+
SPI_FLASH_SIZE_MB = 4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
BOARD_VERSION = 20
2+
SPI_FLASH_SIZE_MB = 4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
BOARD_VERSION = 31
2+
SPI_FLASH_SIZE_MB = 8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
BOARD_VERSION = 31
2+
XTAL_FREQ_MHZ = 8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
,PA0
2+
,PA1
3+
,PA2
4+
,PA3
5+
,PA4
6+
,PA5
7+
,PA6
8+
,PA7
9+
,PA8
10+
,PA9
11+
,PA10
12+
,PA11
13+
,PA12
14+
,PA15
15+
,PB0
16+
,PB1
17+
,PB2
18+
,PB3
19+
,PB4
20+
,PB5
21+
,PB6
22+
,PB7
23+
,PB8
24+
,PB9
25+
,PB10
26+
,PB12
27+
,PB13
28+
,PB14
29+
,PB15
30+
,PC14
31+
,PC15
32+
LED_BLUE,PC13
33+
SW,PA0
34+
-SWDIO,PA13
35+
-SWCLK,PA14
36+
-OSC32_IN,PH0
37+
-OSC32_OUT,PH1
38+
-USB_DM,PA11
39+
-USB_DP,PA12
40+
-FLASH_CS,PA4
41+
-FLASH_SCK,PA5
42+
-FLASH_MOSI,PA7
43+
-FLASH_MISO_V13,PA6
44+
-FLASH_MISO_V20,PB4
45+
-FLASH_MISO_V31,PA6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/* This file is part of the MicroPython project, http://micropython.org/
2+
* The MIT License (MIT)
3+
* Copyright (c) 2024 Andrew Leech
4+
*/
5+
#ifndef MICROPY_INCLUDED_STM32F4XX_HAL_CONF_H
6+
#define MICROPY_INCLUDED_STM32F4XX_HAL_CONF_H
7+
8+
#include "boards/stm32f4xx_hal_conf_base.h"
9+
10+
// Oscillator values in Hz
11+
#define HSE_VALUE (MICROPY_HW_HSE_SPEED_MHZ * 1000000)
12+
#define LSE_VALUE (32768)
13+
#define EXTERNAL_CLOCK_VALUE (12288000)
14+
15+
// Oscillator timeouts in ms
16+
#define HSE_STARTUP_TIMEOUT (100)
17+
#define LSE_STARTUP_TIMEOUT (5000)
18+
19+
#endif // MICROPY_INCLUDED_STM32F4XX_HAL_CONF_H

0 commit comments

Comments
 (0)