Compare commits

...

5 Commits

Author SHA1 Message Date
Damien George
41acdd8083 stm32/rtc: Make sure RTC is using LSE on N6 MCUs.
Some checks failed
JavaScript code lint and formatting with Biome / eslint (push) Has been cancelled
Check code formatting / code-formatting (push) Has been cancelled
Check spelling with codespell / codespell (push) Has been cancelled
Build docs / build (push) Has been cancelled
Check examples / embedding (push) Has been cancelled
Package mpremote / build (push) Has been cancelled
.mpy file format and tools / test (push) Has been cancelled
Build ports metadata / build (push) Has been cancelled
alif port / build_alif (alif_ae3_build) (push) Has been cancelled
cc3200 port / build (push) Has been cancelled
esp32 port / build_idf (esp32_build_c2_c5_c6) (push) Has been cancelled
esp32 port / build_idf (esp32_build_cmod_spiram_s2) (push) Has been cancelled
esp32 port / build_idf (esp32_build_s3_c3) (push) Has been cancelled
esp8266 port / build (push) Has been cancelled
mimxrt port / build (push) Has been cancelled
nrf port / build (push) Has been cancelled
powerpc port / build (push) Has been cancelled
qemu port / build_and_test_arm (bigendian) (push) Has been cancelled
qemu port / build_and_test_arm (sabrelite) (push) Has been cancelled
qemu port / build_and_test_arm (thumb_hardfp) (push) Has been cancelled
qemu port / build_and_test_arm (thumb_softfp) (push) Has been cancelled
qemu port / build_and_test_rv32 (push) Has been cancelled
qemu port / build_and_test_rv64 (push) Has been cancelled
renesas-ra port / build_renesas_ra_board (push) Has been cancelled
rp2 port / build (push) Has been cancelled
samd port / build (push) Has been cancelled
stm32 port / build_stm32 (stm32_misc_build) (push) Has been cancelled
stm32 port / build_stm32 (stm32_nucleo_build) (push) Has been cancelled
stm32 port / build_stm32 (stm32_pyb_build) (push) Has been cancelled
unix port / minimal (push) Has been cancelled
unix port / reproducible (push) Has been cancelled
unix port / standard (push) Has been cancelled
unix port / standard_v2 (push) Has been cancelled
unix port / coverage (push) Has been cancelled
unix port / coverage_32bit (push) Has been cancelled
unix port / nanbox (push) Has been cancelled
unix port / longlong (push) Has been cancelled
unix port / float (push) Has been cancelled
unix port / gil_enabled (push) Has been cancelled
unix port / stackless_clang (push) Has been cancelled
unix port / float_clang (push) Has been cancelled
unix port / settrace_stackless (push) Has been cancelled
unix port / repr_b (push) Has been cancelled
unix port / macos (push) Has been cancelled
unix port / qemu_mips (push) Has been cancelled
unix port / qemu_arm (push) Has been cancelled
unix port / qemu_riscv64 (push) Has been cancelled
unix port / sanitize_address (push) Has been cancelled
unix port / sanitize_undefined (push) Has been cancelled
webassembly port / build (push) Has been cancelled
windows port / build-vs (Debug, true, x64, dev, 2017, [15, 16)) (push) Has been cancelled
windows port / build-vs (Debug, true, x86, dev, 2017, [15, 16)) (push) Has been cancelled
windows port / build-vs (Debug, x64, dev, 2022, [17, 18)) (push) Has been cancelled
windows port / build-vs (Debug, x86, dev, 2022, [17, 18)) (push) Has been cancelled
windows port / build-vs (Release, true, x64, dev, 2017, [15, 16)) (push) Has been cancelled
windows port / build-vs (Release, true, x64, dev, 2019, [16, 17)) (push) Has been cancelled
windows port / build-vs (Release, true, x64, standard, 2017, [15, 16)) (push) Has been cancelled
windows port / build-vs (Release, true, x64, standard, 2019, [16, 17)) (push) Has been cancelled
windows port / build-vs (Release, true, x86, dev, 2017, [15, 16)) (push) Has been cancelled
windows port / build-vs (Release, true, x86, dev, 2019, [16, 17)) (push) Has been cancelled
windows port / build-vs (Release, true, x86, standard, 2017, [15, 16)) (push) Has been cancelled
windows port / build-vs (Release, true, x86, standard, 2019, [16, 17)) (push) Has been cancelled
windows port / build-vs (Release, x64, dev, 2022, [17, 18)) (push) Has been cancelled
windows port / build-vs (Release, x64, standard, 2022, [17, 18)) (push) Has been cancelled
windows port / build-vs (Release, x86, dev, 2022, [17, 18)) (push) Has been cancelled
windows port / build-vs (Release, x86, standard, 2022, [17, 18)) (push) Has been cancelled
windows port / build-mingw (i686, mingw32, dev) (push) Has been cancelled
windows port / build-mingw (i686, mingw32, standard) (push) Has been cancelled
windows port / build-mingw (x86_64, mingw64, dev) (push) Has been cancelled
windows port / build-mingw (x86_64, mingw64, standard) (push) Has been cancelled
windows port / cross-build-on-linux (push) Has been cancelled
zephyr port / build (push) Has been cancelled
Python code lint and formatting with ruff / ruff (push) Has been cancelled
Signed-off-by: Damien George <damien@micropython.org>
2025-11-29 23:57:10 +11:00
Damien George
63c94fe73e stm32: Fix init sequence of USB hardware and TinyUSB stack.
This commit fixes the initialization sequence for TinyUSB when enabled on
the stm32 port:

- Following other ports, `mp_usbd_init()` should be called just after
  running `boot.py`, to give the user a chance to configure USB.

- Hardware initialization (via `pyb_usbd_init()`) should only occur once,
  the first time TinyUSB is started up.  This is achieved by adding a hook
  to the shared TinyUSB bindings to call `pyb_usbd_init()`, and only do the
  hardware init if TinyUSB was not already initialized.

Also, `pyb_usbd_init()` is renamed `mp_usbd_ll_init()` to make it match
with the rest of the stared TinyUSB binding code.

Signed-off-by: Damien George <damien@micropython.org>
2025-11-29 23:35:20 +11:00
Damien George
f43810b1cd stm32/usbd_conf: Clean up USBD hardware initialization functions.
Break the FS and HS initialization routines out into separate functions,
and call them as necessary from the TinyUSB or STM USB helper functions.

Signed-off-by: Damien George <damien@micropython.org>
2025-11-29 23:35:20 +11:00
Damien George
14b5080515 shared/tinyusb: Add optional port-specific hook on USBD init.
This allows a port to do hardware initialization just before the TinyUSB
stack is brought up.  That means the hardware is only turned on when it's
needed.

Signed-off-by: Damien George <damien@micropython.org>
2025-11-29 23:23:46 +11:00
Yuuki NAGAO
9b73e344eb stm32/boards/WEACTSTUDIO_MINI_STM32H743: Add WeAct H743VI board support.
This change adds WeAct Studio Mini STM32H743 board support to the STM32
port.  Some of the work from PR #12540 is combined here.

WeAct Studio Mini STM32H43 board:
https://github.com/WeActStudio/MiniSTM32H7xx

This board uses STM32H743VI:
https://www.st.com/en/microcontrollers-microprocessors/stm32h743vi.html

Signed-off-by: Yuuki NAGAO <wf.yn386@gmail.com>
2025-11-29 23:10:54 +11:00
18 changed files with 510 additions and 31 deletions

View File

@@ -0,0 +1,47 @@
/* This file is part of the MicroPython project, http://micropython.org/
* The MIT License (MIT)
* Copyright (c) 2019 Damien P. George
*/
#include "storage.h"
#include "spi.h"
#include "qspi.h"
#include "py/mpconfig.h"
static const spi_proto_cfg_t spi_bus = {
.spi = &spi_obj[0], // SPI1
.baudrate = 25000000,
.polarity = 0,
.phase = 0,
.bits = 8,
.firstbit = SPI_FIRSTBIT_MSB,
};
#if MICROPY_HW_SPIFLASH_ENABLE_CACHE
static mp_spiflash_cache_t spi_bdev_cache;
#endif
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 *)&spi_bus,
.bus.u_spi.proto = &spi_proto,
#if MICROPY_HW_SPIFLASH_ENABLE_CACHE
.cache = &spi_bdev_cache,
#endif
};
spi_bdev_t spi_bdev;
// Second external SPI flash uses hardware QSPI interface
const mp_spiflash_config_t spiflash2_config = {
.bus_kind = MP_SPIFLASH_BUS_QSPI,
.bus.u_qspi.data = NULL,
.bus.u_qspi.proto = &qspi_proto,
#if MICROPY_HW_SPIFLASH_ENABLE_CACHE
.cache = &spi_bdev_cache,
#endif
};
spi_bdev_t spi_bdev2;

View File

@@ -0,0 +1,13 @@
{
"deploy": [
"deploy.md"
],
"features": ["External Flash", "DAC", "Display","microSD", "USB", "USB-C"],
"images": [
"weact_stm32h743.jpg"
],
"mcu": "stm32h7",
"product": "Mini STM32H743",
"url": "https://github.com/WeActStudio/MiniSTM32H7xx",
"vendor": "WeAct Studio"
}

View File

@@ -0,0 +1,16 @@
/* This file is part of the MicroPython project, http://micropython.org/
* The MIT License (MIT)
* Copyright (c) 2019 Damien P. George
*/
#include "py/mphal.h"
#include "storage.h"
void WeAct_Core_early_init(void) {
// Turn off the USB switch.
mp_hal_pin_output(pyb_pin_OTG_FS_POWER);
mp_hal_pin_low(pyb_pin_OTG_FS_POWER);
// Explicitly init SPI2 because it's not enabled as a block device
spi_bdev_ioctl(&spi_bdev2, BDEV_IOCTL_INIT, (uint32_t)&spiflash2_config);
}

View File

@@ -0,0 +1,19 @@
### WeAct Studio STM32H7xx
WeAct Studio make a number of STM32H7xx-based boards, they can all be updated
using
[DFU](https://en.wikipedia.org/wiki/USB?useskin=vector#Device_Firmware_Upgrade_mechanism).
### DFU update
Hold the Boot button - the middle of the cluster of three buttons - while the
board is reset (either by connecting USB or by pressing reset). Release the Boot
button shortly after the board has reset. The board ought to now be in DFU mode
and detectable as such from a connected computer.
Use a tool like [`dfu-util`](https://dfu-util.sourceforge.net/) to update the
firmware:
```bash
dfu-util --alt 0 -D firmware.dfu
```

View File

@@ -0,0 +1,4 @@
include("$(PORT_DIR)/boards/manifest.py")
# Currently this file is a placeholder.
# It would be good to extend to add an LCD driver.

View File

@@ -0,0 +1,171 @@
#define MICROPY_HW_BOARD_NAME "WEACTSTUDIO_MINI_STM32H743"
#define MICROPY_HW_MCU_NAME "STM32H743VIT6"
#define MICROPY_FATFS_EXFAT (1)
#define MICROPY_HW_ENABLE_RTC (1)
#define MICROPY_HW_ENABLE_RNG (1)
#define MICROPY_HW_ENABLE_ADC (1)
#define MICROPY_HW_ENABLE_DAC (1)
#define MICROPY_HW_ENABLE_USB (1)
#define MICROPY_HW_HAS_SWITCH (1)
#define MICROPY_HW_HAS_FLASH (1)
#define MICROPY_HW_ENABLE_SERVO (1)
#define MICROPY_HW_ENABLE_TIMER (1)
#define MICROPY_HW_ENABLE_SDCARD (1)
#define MICROPY_HW_ENABLE_MMCARD (0)
// ROMFS config
#define MICROPY_HW_ROMFS_ENABLE_EXTERNAL_QSPI (1)
#define MICROPY_HW_ROMFS_QSPI_SPIFLASH_OBJ (&spi_bdev2.spiflash)
#define MICROPY_HW_ROMFS_ENABLE_PART0 (1)
// Flash storage config
#define MICROPY_HW_SPIFLASH_ENABLE_CACHE (1)
// Disable internal filesystem to use spiflash.
#define MICROPY_HW_ENABLE_INTERNAL_FLASH_STORAGE (0)
// W25Q64 for storage
#define MICROPY_HW_SPIFLASH_SIZE_BYTES (8 * 1024 * 1024)
// SPI flash #1, for R/W storage
#define MICROPY_HW_SPIFLASH_CS (pin_D6)
#define MICROPY_HW_SPIFLASH_SCK (pin_B3)
#define MICROPY_HW_SPIFLASH_MOSI (pin_D7)
#define MICROPY_HW_SPIFLASH_MISO (pin_B4)
// External SPI Flash configuration
#define MICROPY_HW_SPI_IS_RESERVED(id) (id == 1)
// SPI flash #1, block device config
extern const struct _mp_spiflash_config_t spiflash_config;
extern struct _spi_bdev_t spi_bdev;
#define MICROPY_HW_BDEV_SPIFLASH (&spi_bdev)
#define MICROPY_HW_BDEV_SPIFLASH_CONFIG (&spiflash_config)
#define MICROPY_HW_BDEV_SPIFLASH_SIZE_BYTES (MICROPY_HW_SPIFLASH_SIZE_BITS / 8)
#define MICROPY_HW_BDEV_SPIFLASH_EXTENDED (&spi_bdev) // for extended block protocol
#define MICROPY_HW_SPIFLASH_SIZE_BITS (MICROPY_HW_SPIFLASH_SIZE_BYTES * 8)
// SPI flash #2, to be memory mapped
#define MICROPY_HW_QSPI_PRESCALER (2) // 120 MHz
#define MICROPY_HW_QSPIFLASH_SIZE_BITS_LOG2 (26)
#define MICROPY_HW_QSPIFLASH_CS (pin_B6)
#define MICROPY_HW_QSPIFLASH_SCK (pin_B2)
#define MICROPY_HW_QSPIFLASH_IO0 (pin_D11)
#define MICROPY_HW_QSPIFLASH_IO1 (pin_D12)
#define MICROPY_HW_QSPIFLASH_IO2 (pin_E2)
#define MICROPY_HW_QSPIFLASH_IO3 (pin_D13)
// SPI flash #2, block device config
extern const struct _mp_spiflash_config_t spiflash2_config;
extern struct _spi_bdev_t spi_bdev2;
#define MICROPY_BOARD_EARLY_INIT WeAct_Core_early_init
// This board has 25MHz HSE.
// The following gives a 480MHz CPU speed.
#define MICROPY_HW_CLK_USE_HSE (1)
#define MICROPY_HW_CLK_PLLM (5)
#define MICROPY_HW_CLK_PLLN (192)
#define MICROPY_HW_CLK_PLLP (2)
#define MICROPY_HW_CLK_PLLQ (20)
#define MICROPY_HW_CLK_PLLR (2)
#define MICROPY_HW_CLK_PLLVCI (RCC_PLL1VCIRANGE_2)
#define MICROPY_HW_CLK_PLLVCO (RCC_PLL1VCOWIDE)
#define MICROPY_HW_CLK_PLLFRAC (0)
// The USB clock is set using PLL3
#define MICROPY_HW_CLK_PLL3M (5)
#define MICROPY_HW_CLK_PLL3N (192)
#define MICROPY_HW_CLK_PLL3P (2)
#define MICROPY_HW_CLK_PLL3Q (20)
#define MICROPY_HW_CLK_PLL3R (2)
#define MICROPY_HW_CLK_PLL3VCI (RCC_PLL3VCIRANGE_2)
#define MICROPY_HW_CLK_PLL3VCO (RCC_PLL3VCOWIDE)
#define MICROPY_HW_CLK_PLL3FRAC (0)
// 32kHz crystal for RTC
#define MICROPY_HW_RTC_USE_LSE (1)
#define MICROPY_HW_RTC_USE_US (0)
// 6 wait states
#define MICROPY_HW_FLASH_LATENCY FLASH_LATENCY_6
// UART
#define MICROPY_HW_UART1_TX (pin_A9)
#define MICROPY_HW_UART1_RX (pin_A10)
#define MICROPY_HW_UART2_TX (pin_A2)
#define MICROPY_HW_UART2_RX (pin_A3)
#define MICROPY_HW_UART3_TX (pin_B10)
#define MICROPY_HW_UART3_RX (pin_B11)
#define MICROPY_HW_UART4_TX (pin_C11)
#define MICROPY_HW_UART4_RX (pin_C10)
#define MICROPY_HW_UART5_TX (pin_B12) // or SPI2
#define MICROPY_HW_UART5_RX (pin_B13) // or SPI2
#define MICROPY_HW_UART6_TX (pin_C6)
#define MICROPY_HW_UART6_RX (pin_C7)
#define MICROPY_HW_UART7_TX (pin_E8)
#define MICROPY_HW_UART7_RX (pin_E7)
// I2C buses
#define MICROPY_HW_I2C1_SCL (pin_B8)
#define MICROPY_HW_I2C1_SDA (pin_B9)
#define MICROPY_HW_I2C2_SCL (pin_B10)
#define MICROPY_HW_I2C2_SDA (pin_B11)
// SPI buses
// NOTE: SPI1 is used for the SPI flash.
#define MICROPY_HW_SPI1_NSS (pin_D6)
#define MICROPY_HW_SPI1_SCK (pin_B3)
#define MICROPY_HW_SPI1_MISO (pin_B4)
#define MICROPY_HW_SPI1_MOSI (pin_D7)
#define MICROPY_HW_SPI2_NSS (pin_B12)
#define MICROPY_HW_SPI2_SCK (pin_B13)
#define MICROPY_HW_SPI2_MISO (pin_B14)
#define MICROPY_HW_SPI2_MOSI (pin_B15)
// NOTE: SPI3 is used for the QSPI flash.
#define MICROPY_HW_SPI3_NSS (pin_A4)
#define MICROPY_HW_SPI3_SCK (pin_B3)
#define MICROPY_HW_SPI3_MISO (pin_B4)
#define MICROPY_HW_SPI3_MOSI (pin_B5)
// NOTE: SPI4 is used for the ST7735 LCD.
#define MICROPY_HW_SPI4_NSS (pin_E11)
#define MICROPY_HW_SPI4_SCK (pin_E12)
#define MICROPY_HW_SPI4_MISO (pin_E13)
#define MICROPY_HW_SPI4_MOSI (pin_E14)
// CAN buses
#define MICROPY_HW_CAN1_TX (pin_B9)
#define MICROPY_HW_CAN1_RX (pin_B8)
// USRSW is pulled low. Pressing the button makes the input go high.
#define MICROPY_HW_USRSW_PIN (pin_C13) // K1 on the board.
#define MICROPY_HW_USRSW_PULL (GPIO_PULLDOWN)
#define MICROPY_HW_USRSW_EXTI_MODE (GPIO_MODE_IT_RISING)
#define MICROPY_HW_USRSW_PRESSED (1)
// LEDs
#define MICROPY_HW_LED1 (pin_E3) // the only controllable LED on the board.
#define MICROPY_HW_LED_ON(pin) (mp_hal_pin_high(pin))
#define MICROPY_HW_LED_OFF(pin) (mp_hal_pin_low(pin))
// SD Card SDMMC
#define MICROPY_HW_SDCARD_SDMMC (1)
#define MICROPY_HW_SDCARD_CK (pin_C12)
#define MICROPY_HW_SDCARD_CMD (pin_D2)
#define MICROPY_HW_SDCARD_D0 (pin_C8)
#define MICROPY_HW_SDCARD_D1 (pin_C9)
#define MICROPY_HW_SDCARD_D2 (pin_C10)
#define MICROPY_HW_SDCARD_D3 (pin_C11)
// SD card detect switch
#define MICROPY_HW_SDCARD_DETECT_PIN (pin_D4)
#define MICROPY_HW_SDCARD_DETECT_PULL (GPIO_PULLUP)
#define MICROPY_HW_SDCARD_DETECT_PRESENT (GPIO_PIN_SET)
// USB config
#define MICROPY_HW_USB_FS (1)
void WeAct_Core_early_init(void);

View File

@@ -0,0 +1,22 @@
USE_MBOOT ?= 0
# MCU settings
MCU_SERIES = h7
CMSIS_MCU = STM32H743xx
MICROPY_FLOAT_IMPL = double
AF_FILE = boards/stm32h743_af.csv
ifeq ($(USE_MBOOT),1)
# When using Mboot everything goes after the bootloader
LD_FILES = boards/stm32h723.ld boards/common_bl.ld
TEXT0_ADDR = 0x08020000
else
# When not using Mboot everything goes at the start of flash
LD_FILES = boards/WEACTSTUDIO_MINI_STM32H743/weact_stm32h743.ld boards/common_basic.ld
TEXT0_ADDR = 0x08000000
endif
# MicroPython settings
MICROPY_VFS_LFS2 = 1
FROZEN_MANIFEST ?= $(BOARD_DIR)/manifest.py

View File

@@ -0,0 +1,100 @@
A0,PA0
A1,PA1
A2,PA2
A3,PA3
A4,PA4
A5,PA5
A6,PA6
A7,PA7
A8,PA8
A9,PA9
A10,PA10
A11,PA11
A12,PA12
A15,PA15
B0,PB0
B1,PB1
B2,PB2
B3,PB3
B4,PB4
B5,PB5
B6,PB6
B7,PB7
B8,PB8
B9,PB9
B10,PB10
B11,PB11
B12,PB12
B13,PB13
B14,PB14
B15,PB15
C0,PC0
C1,PC1
C2,PC2
C3,PC3
C4,PC4
C5,PC5
C6,PC6
C7,PC7
C8,PC8
C9,PC9
C10,PC10
C11,PC11
C12,PC12
C13,PC13
D0,PD0
D1,PD1
D2,PD2
D3,PD3
D4,PD4
D5,PD5
D6,PD6
D7,PD7
D8,PD8
D9,PD9
D10,PD10
D11,PD11
D12,PD12
D13,PD13
D14,PD14
D15,PD15
E0,PE0
E1,PE1
E2,PE2
E3,PE3
E4,PE4
E5,PE5
E6,PE6
E7,PE7
E8,PE8
E9,PE9
E10,PE10
E11,PE11
E11,PE11
E12,PE12
E13,PE13
E14,PE14
E15,PE15
LED_BLUE,PE3
KEY_1,PC13
QSPI_CS,PB6
QSPI_CLK,PB2
QSPI_D0,PD11
QSPI_D1,PD12
QSPI_D2,PE2
QSPI_D3,PD13
USB_DM,PA11
USB_DP,PA12
OSC32_IN,PC14
OSC32_OUT,PC15
SDIO_D0,PC8
SDIO_D1,PC9
SDIO_D2,PC10
SDIO_D3,PC11
SDIO_CMD,PD2
SDIO_CK,PC12
SD_SW,PD4
OTG_FS_POWER,PD10
OTG_FS_OVER_CURRENT,PG7
USB_VBUS,PA9
USB_ID,PA10
1 A0 PA0
2 A1 PA1
3 A2 PA2
4 A3 PA3
5 A4 PA4
6 A5 PA5
7 A6 PA6
8 A7 PA7
9 A8 PA8
10 A9 PA9
11 A10 PA10
12 A11 PA11
13 A12 PA12
14 A15 PA15
15 B0 PB0
16 B1 PB1
17 B2 PB2
18 B3 PB3
19 B4 PB4
20 B5 PB5
21 B6 PB6
22 B7 PB7
23 B8 PB8
24 B9 PB9
25 B10 PB10
26 B11 PB11
27 B12 PB12
28 B13 PB13
29 B14 PB14
30 B15 PB15
31 C0 PC0
32 C1 PC1
33 C2 PC2
34 C3 PC3
35 C4 PC4
36 C5 PC5
37 C6 PC6
38 C7 PC7
39 C8 PC8
40 C9 PC9
41 C10 PC10
42 C11 PC11
43 C12 PC12
44 C13 PC13
45 D0 PD0
46 D1 PD1
47 D2 PD2
48 D3 PD3
49 D4 PD4
50 D5 PD5
51 D6 PD6
52 D7 PD7
53 D8 PD8
54 D9 PD9
55 D10 PD10
56 D11 PD11
57 D12 PD12
58 D13 PD13
59 D14 PD14
60 D15 PD15
61 E0 PE0
62 E1 PE1
63 E2 PE2
64 E3 PE3
65 E4 PE4
66 E5 PE5
67 E6 PE6
68 E7 PE7
69 E8 PE8
70 E9 PE9
71 E10 PE10
72 E11 PE11
73 E11 PE11
74 E12 PE12
75 E13 PE13
76 E14 PE14
77 E15 PE15
78 LED_BLUE PE3
79 KEY_1 PC13
80 QSPI_CS PB6
81 QSPI_CLK PB2
82 QSPI_D0 PD11
83 QSPI_D1 PD12
84 QSPI_D2 PE2
85 QSPI_D3 PD13
86 USB_DM PA11
87 USB_DP PA12
88 OSC32_IN PC14
89 OSC32_OUT PC15
90 SDIO_D0 PC8
91 SDIO_D1 PC9
92 SDIO_D2 PC10
93 SDIO_D3 PC11
94 SDIO_CMD PD2
95 SDIO_CK PC12
96 SD_SW PD4
97 OTG_FS_POWER PD10
98 OTG_FS_OVER_CURRENT PG7
99 USB_VBUS PA9
100 USB_ID PA10

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_STM32H7XX_HAL_CONF_H
#define MICROPY_INCLUDED_STM32H7XX_HAL_CONF_H
// Oscillator values in Hz
#define HSE_VALUE (25000000)
#define LSE_VALUE (32768)
#define EXTERNAL_CLOCK_VALUE (12288000)
// Oscillator timeouts in ms
#define HSE_STARTUP_TIMEOUT (5000)
#define LSE_STARTUP_TIMEOUT (5000)
#include "boards/stm32h7xx_hal_conf_base.h"
#endif // MICROPY_INCLUDED_STM32H7XX_HAL_CONF_H

View File

@@ -0,0 +1,33 @@
/*
GNU linker script for WeAct Studio STM32H743
*/
/* Specify the memory areas */
MEMORY
{
FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 2048K /* sectors (0-15) */
FLASH_APP (rx) : ORIGIN = 0x08020000, LENGTH = 1920K /* sectors (1-15) */
FLASH_ROMFS (rx): ORIGIN = 0x90000000, LENGTH = 8192K /* external QSPI */
DTCM (xrw) : ORIGIN = 0x20000000, LENGTH = 128K /* Used for storage cache */
RAM (xrw) : ORIGIN = 0x24000000, LENGTH = 512K /* AXI SRAM */
RAM_D2 (xrw) : ORIGIN = 0x30000000, LENGTH = 288K
}
/* produce a link error if there is not this amount of RAM for these sections */
_minimum_stack_size = 2K;
_minimum_heap_size = 16K;
/* Define the stack. The stack is full descending so begins just above last byte
of RAM. Note that EABI requires the stack to be 8-byte aligned for a call. */
_estack = ORIGIN(RAM) + LENGTH(RAM) - _estack_reserve;
_sstack = _estack - 16K; /* tunable */
/* RAM extents for the garbage collector */
_ram_start = ORIGIN(RAM);
_ram_end = ORIGIN(RAM) + LENGTH(RAM);
_heap_start = _ebss; /* heap starts just after statically allocated memory */
_heap_end = _sstack;
/* ROMFS location */
_micropy_hw_romfs_part0_start = ORIGIN(FLASH_ROMFS);
_micropy_hw_romfs_part0_size = LENGTH(FLASH_ROMFS);

View File

@@ -611,14 +611,9 @@ soft_reset:
pyb_can_init0();
#endif
#if MICROPY_HW_ENABLE_USB
#if MICROPY_HW_TINYUSB_STACK
pyb_usbd_init();
mp_usbd_init();
#else
#if MICROPY_HW_STM_USB_STACK && MICROPY_HW_ENABLE_USB
pyb_usb_init0();
#endif
#endif
#if MICROPY_PY_MACHINE_I2S
machine_i2s_init0();
@@ -690,6 +685,10 @@ soft_reset:
}
#endif
#if MICROPY_HW_TINYUSB_STACK && MICROPY_HW_ENABLE_USBDEV
mp_usbd_init();
#endif
#if MICROPY_HW_HAS_MMA7660
// MMA accel: init and reset
accel_init();

View File

@@ -261,6 +261,7 @@
#if MICROPY_HW_TINYUSB_STACK
#ifndef MICROPY_HW_ENABLE_USBDEV
#define MICROPY_HW_ENABLE_USBDEV (1)
#define MICROPY_HW_TINYUSB_LL_INIT mp_usbd_ll_init
#endif
#ifndef MICROPY_HW_USB_CDC

View File

@@ -1,6 +1,7 @@
// We use the ST Cube HAL library for most hardware peripherals
#include STM32_HAL_H
#include "pin.h"
#include "usbd_conf.h"
#include "py/ringbuf.h"
#include "shared/runtime/interrupt_char.h"

View File

@@ -134,19 +134,27 @@ void rtc_init_start(bool force_init) {
if (!force_init) {
bool rtc_running = false;
#if defined(STM32N6)
// Note: the low-level boot on the N6 seems to always enable the RTC and the LSI, and
// switch the RTC to LSI mode. So the logic below needs to account for that:
// - if LSE is ready then switch back to the LSE
// - even if LSI is ready, don't use it if the board is configured to use LSE
uint32_t rtc_clock_source = LL_RCC_GetRTCClockSource();
if (LL_RCC_IsEnabledRTC()
&& LL_RCC_GetRTCClockSource() == LL_RCC_RTC_CLKSOURCE_LSE
&& LL_RCC_LSE_IsReady()) {
// LSE is enabled & ready --> no need to (re-)init RTC
rtc_running = true;
if (rtc_clock_source != LL_RCC_RTC_CLKSOURCE_LSE) {
LL_RCC_SetRTCClockSource(LL_RCC_RTC_CLKSOURCE_LSE);
}
// remove Backup Domain write protection
HAL_PWR_EnableBkUpAccess();
// Clear source Reset Flag
__HAL_RCC_CLEAR_RESET_FLAGS();
// provide some status information
rtc_info |= 0x40000;
} else if (LL_RCC_IsEnabledRTC()
&& LL_RCC_GetRTCClockSource() == LL_RCC_RTC_CLKSOURCE_LSI) {
} else if (!rtc_use_lse
&& LL_RCC_IsEnabledRTC()
&& rtc_clock_source == LL_RCC_RTC_CLKSOURCE_LSI) {
// LSI configured as the RTC clock source --> no need to (re-)init RTC
rtc_running = true;
// remove Backup Domain write protection

View File

@@ -32,6 +32,7 @@
#include "usbd_core.h"
#include "py/obj.h"
#include "py/mphal.h"
#include "shared/tinyusb/mp_usbd.h"
#include "irq.h"
#include "usb.h"
@@ -62,16 +63,8 @@ PCD_HandleTypeDef pcd_hs_handle;
#define OTG_HS_IRQn USB1_OTG_HS_IRQn
#endif
#if MICROPY_HW_TINYUSB_STACK
void pyb_usbd_init(void)
#else
void HAL_PCD_MspInit(PCD_HandleTypeDef *hpcd)
#endif
{
#if MICROPY_HW_USB_FS
#if MICROPY_HW_STM_USB_STACK
if (hpcd->Instance == USB_OTG_FS)
#endif
#if MICROPY_HW_USB_FS
static void mp_usbd_ll_init_fs(void) {
{
// Configure USB GPIO's.
@@ -192,17 +185,12 @@ void HAL_PCD_MspInit(PCD_HandleTypeDef *hpcd)
#endif
#endif
#endif
#if MICROPY_HW_STM_USB_STACK
return;
#endif
}
#endif
}
#endif // MICROPY_HW_USB_FS
#if MICROPY_HW_USB_HS
#if MICROPY_HW_STM_USB_STACK
if (hpcd->Instance == USB_OTG_HS)
#endif
#if MICROPY_HW_USB_HS
static void mp_usbd_ll_init_hs(void) {
{
#if MICROPY_HW_USB_HS_IN_FS
@@ -342,10 +330,41 @@ void HAL_PCD_MspInit(PCD_HandleTypeDef *hpcd)
NVIC_SetPriority(OTG_HS_IRQn, IRQ_PRI_OTG_HS);
HAL_NVIC_EnableIRQ(OTG_HS_IRQn);
}
#endif // MICROPY_HW_USB_HS
}
#endif // MICROPY_HW_USB_HS
#if MICROPY_HW_TINYUSB_STACK
void mp_usbd_ll_init(void) {
// Only initialize the USB hardware once.
if (tusb_inited()) {
return;
}
#if MICROPY_HW_USB_FS
mp_usbd_ll_init_fs();
#endif
#if MICROPY_HW_USB_HS
mp_usbd_ll_init_hs();
#endif
}
#if MICROPY_HW_STM_USB_STACK
#elif MICROPY_HW_STM_USB_STACK
void HAL_PCD_MspInit(PCD_HandleTypeDef *hpcd) {
#if MICROPY_HW_USB_FS
if (hpcd->Instance == USB_OTG_FS) {
mp_usbd_ll_init_fs();
}
#endif
#if MICROPY_HW_USB_HS
if (hpcd->Instance == USB_OTG_HS) {
mp_usbd_ll_init_hs();
}
#endif
}
/**
* @brief DeInitializes the PCD MSP.

View File

@@ -65,7 +65,7 @@
#define USBD_HS_NUM_FIFO (1 + USBD_HS_NUM_TX_FIFO)
#if MICROPY_HW_TINYUSB_STACK
void pyb_usbd_init(void);
void mp_usbd_ll_init(void);
#endif
#endif // MICROPY_INCLUDED_STM32_USBD_CONF_H

View File

@@ -45,6 +45,10 @@
#define MICROPY_WRAP_TUD_EVENT_HOOK_CB(name) name
#endif
#ifndef MICROPY_HW_TINYUSB_LL_INIT
#define MICROPY_HW_TINYUSB_LL_INIT()
#endif
#if MICROPY_HW_ENABLE_USBDEV
#include "py/obj.h"
@@ -102,6 +106,7 @@ void mp_usbd_task_callback(mp_sched_node_t *node);
static inline void mp_usbd_init(void) {
// Without runtime USB support, this can be a thin wrapper wrapper around tusb_init()
// which is called in the below helper function.
MICROPY_HW_TINYUSB_LL_INIT();
mp_usbd_init_tud();
}

View File

@@ -430,6 +430,8 @@ void mp_usbd_init(void) {
}
if (need_usb) {
// Call any port-specific initialization code.
MICROPY_HW_TINYUSB_LL_INIT();
// The following will call tusb_init(), which is safe to call redundantly.
mp_usbd_init_tud();
// Reconnect if mp_usbd_deinit() has disconnected.