Skip to content

Commit f4a93c3

Browse files
dlechlaurensvalk
andcommitted
pbio/platform: Add support for Prime Hub variant.
There is a Prime Hub with slightly different hardware. This commit adds support for this variant. Everything should work the same as before. Authored-by: David Lechner <david@pybricks.com> Co-authored-by: Laurens Valk <laurens@pybricks.com>
1 parent c67374e commit f4a93c3

31 files changed

Lines changed: 4420 additions & 33 deletions

.vscode/c_cpp_properties.json

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
{
88
"configurations": [
99
{
10-
"name": "primehub f4",
10+
"name": "primehub_f4",
1111
"includePath": [
1212
"${workspaceFolder}/micropython/lib/cmsis/inc",
1313
"${workspaceFolder}/micropython/lib/stm32lib/CMSIS/STM32F4xx/Include",
@@ -34,6 +34,9 @@
3434
"STM32F413xx",
3535
"STM32_H=<stm32f4xx.h>",
3636
"STM32_HAL_H=<stm32f4xx_hal.h>",
37+
"STM32_HAL_PCD_EX_H=<stm32f4xx_hal_pcd_ex.h>",
38+
"STM32_LL_RCC_H=<stm32f4xx_ll_rcc.h>",
39+
"STM32_LL_USART_H=<stm32f4xx_ll_usart.h>",
3740
"USE_FULL_LL_DRIVER"
3841
],
3942
"compilerArgs": [
@@ -54,6 +57,58 @@
5457
"cStandard": "c11",
5558
"intelliSenseMode": "gcc-arm"
5659
},
60+
{
61+
"name": "primehub_h5",
62+
"includePath": [
63+
"${workspaceFolder}/micropython/lib/cmsis/inc",
64+
"${workspaceFolder}/micropython/lib/stm32lib/CMSIS/STM32H5xx/Include",
65+
"${workspaceFolder}/micropython/lib/stm32lib/STM32H5xx_HAL_Driver/Inc",
66+
"${workspaceFolder}/lib/STM32_USB_Device_Library/Core/Inc",
67+
"${workspaceFolder}/lib/STM32_USB_Device_Library/Class/CDC/Inc",
68+
"${workspaceFolder}/lib/btstack/chipset/cc256x",
69+
"${workspaceFolder}/lib/btstack/src",
70+
"${workspaceFolder}/lib/lego",
71+
"${workspaceFolder}/lib/lwrb/src/include",
72+
"${workspaceFolder}/lib/lsm6ds3tr_c_STdC/driver",
73+
"${workspaceFolder}/lib/pbio/drv/usb/stm32_usbd",
74+
"${workspaceFolder}/lib/pbio/include",
75+
"${workspaceFolder}/lib/pbio/platform/prime_hub_h5",
76+
"${workspaceFolder}",
77+
"${workspaceFolder}/bricks/primehub_h5",
78+
"${workspaceFolder}/bricks/primehub_h5/build",
79+
"${workspaceFolder}/micropython"
80+
],
81+
"defines": [
82+
"MICROPY_MODULE_FROZEN_MPY",
83+
"MICROPY_ROM_TEXT_COMPRESSION",
84+
"HSE_VALUE=16000000",
85+
"STM32H562xx",
86+
"STM32_H=<stm32h5xx.h>",
87+
"STM32_HAL_H=<stm32h5xx_hal.h>",
88+
"STM32_HAL_PCD_EX_H=<stm32h5xx_hal_pcd_ex.h>",
89+
"STM32_LL_RCC_H=<stm32h5xx_ll_rcc.h>",
90+
"STM32_LL_USART_H=<stm32h5xx_ll_usart.h>",
91+
"USE_FULL_LL_DRIVER"
92+
],
93+
"compilerArgs": [
94+
"-Wall",
95+
"-Werror",
96+
"-Wextra",
97+
"-Wno-unused-parameter",
98+
"-Wdouble-promotion",
99+
"-nostdlib",
100+
"-fshort-enums",
101+
"-mthumb",
102+
"-mtune=cortex-m33",
103+
"-mcpu=cortex-m33",
104+
"-mfpu=fpv5-sp-d16",
105+
"-mfloat-abi=hard",
106+
"-fsingle-precision-constant"
107+
],
108+
"cStandard": "c11",
109+
"intelliSenseMode": "gcc-arm",
110+
"compilerPath": "arm-none-eabi-gcc"
111+
},
57112
{
58113
"name": "ev3",
59114
"includePath": [

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44

55
## [Unreleased]
66

7+
### Added
8+
- Added a version of SPIKE Prime with slightly updated electronics. Everything
9+
should work the same as the original.
10+
711
### Fixed
812
- Fixed SPIKE Prime `speaker.beep` playing at double the intended frequency.
913
- Fixed sensors not raising `ENODEV` if the sensor was used after being unplugged.

bricks/_common/common.mk

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ ifeq ($(PB_MCU_FAMILY),STM32)
1717
ifeq ($(PB_MCU_SERIES),)
1818
$(error "PB_MCU_SERIES is not specified - add it in <hub>/Makefile)
1919
else
20-
PB_MCU_SERIES_LCASE = $(subst F,f,$(subst L,l,$(PB_MCU_SERIES)))
20+
PB_MCU_SERIES_LCASE = $(subst H,h,$(subst F,f,$(subst L,l,$(PB_MCU_SERIES))))
2121
endif
2222
ifeq ($(PB_CMSIS_MCU),)
2323
$(error "PB_CMSIS_MCU is not specified - add it in <hub>/Makefile")
@@ -190,6 +190,7 @@ ifeq ($(PB_MCU_FAMILY),STM32)
190190
CFLAGS_MCU_F0 = -mthumb -mtune=cortex-m0 -mcpu=cortex-m0 -msoft-float
191191
CFLAGS_MCU_F4 = -mthumb -mtune=cortex-m4 -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard
192192
CFLAGS_MCU_L4 = -mthumb -mtune=cortex-m4 -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard
193+
CFLAGS_MCU_H5 = -mthumb -mtune=cortex-m33 -mcpu=cortex-m33 -mfpu=fpv5-sp-d16 -mfloat-abi=hard
193194
CFLAGS_MCU = $(CFLAGS_MCU_$(PB_MCU_SERIES))
194195
else
195196
ifeq ($(PB_MCU_FAMILY),AT91SAM7)
@@ -207,6 +208,9 @@ CFLAGS_WARN = -Wall -Werror -Wextra -Wno-unused-parameter -Wno-maybe-uninitializ
207208
CFLAGS += $(INC) -std=c11 -nostdlib -fshort-enums $(CFLAGS_MCU) $(CFLAGS_WARN) $(COPT) $(CFLAGS_EXTRA)
208209
$(BUILD)/lib/libm/%.o: CFLAGS += -Wno-sign-compare
209210

211+
# assembler flags
212+
AFLAGS += $(filter -mcpu=%,$(CFLAGS_MCU))
213+
210214
# linker scripts
211215
LD_FILES = $(PBTOP)/lib/pbio/platform/$(PBIO_PLATFORM)/platform.ld
212216
ifeq ($(PB_MCU_FAMILY),STM32)
@@ -262,6 +266,11 @@ CFLAGS += -D$(PB_CMSIS_MCU)
262266
# Required by pbio drivers
263267
CFLAGS += -DSTM32_H='<stm32$(PB_MCU_SERIES_LCASE)xx.h>'
264268
CFLAGS += -DSTM32_HAL_H='<stm32$(PB_MCU_SERIES_LCASE)xx_hal.h>'
269+
ifeq ($(PB_MCU_SERIES),$(filter $(PB_MCU_SERIES),F4 H5))
270+
CFLAGS += -DSTM32_HAL_PCD_EX_H='<stm32$(PB_MCU_SERIES_LCASE)xx_hal_pcd_ex.h>'
271+
CFLAGS += -DSTM32_LL_RCC_H='<stm32$(PB_MCU_SERIES_LCASE)xx_ll_rcc.h>'
272+
CFLAGS += -DSTM32_LL_USART_H='<stm32$(PB_MCU_SERIES_LCASE)xx_ll_usart.h>'
273+
endif
265274
endif
266275

267276
LIBS += "$(shell $(CC) $(CFLAGS) -print-libgcc-file-name)"
@@ -455,12 +464,14 @@ STM32_HAL_SRC_C = $(addprefix lib/stm32lib/STM32$(PB_MCU_SERIES)xx_HAL_Driver/Sr
455464
stm32$(PB_MCU_SERIES_LCASE)xx_hal_cortex.c \
456465
stm32$(PB_MCU_SERIES_LCASE)xx_hal_dac_ex.c \
457466
stm32$(PB_MCU_SERIES_LCASE)xx_hal_dac.c \
467+
stm32$(PB_MCU_SERIES_LCASE)xx_hal_dma_ex.c \
458468
stm32$(PB_MCU_SERIES_LCASE)xx_hal_dma.c \
459469
stm32$(PB_MCU_SERIES_LCASE)xx_hal_flash_ex.c \
460470
stm32$(PB_MCU_SERIES_LCASE)xx_hal_flash.c \
461471
stm32$(PB_MCU_SERIES_LCASE)xx_hal_fmpi2c.c \
462472
stm32$(PB_MCU_SERIES_LCASE)xx_hal_gpio.c \
463473
stm32$(PB_MCU_SERIES_LCASE)xx_hal_i2c.c \
474+
stm32$(PB_MCU_SERIES_LCASE)xx_hal_icache.c \
464475
stm32$(PB_MCU_SERIES_LCASE)xx_hal_pcd_ex.c \
465476
stm32$(PB_MCU_SERIES_LCASE)xx_hal_pcd.c \
466477
stm32$(PB_MCU_SERIES_LCASE)xx_hal_pwr_ex.c \
@@ -472,6 +483,7 @@ STM32_HAL_SRC_C = $(addprefix lib/stm32lib/STM32$(PB_MCU_SERIES)xx_HAL_Driver/Sr
472483
stm32$(PB_MCU_SERIES_LCASE)xx_hal_tim.c \
473484
stm32$(PB_MCU_SERIES_LCASE)xx_hal_uart_ex.c \
474485
stm32$(PB_MCU_SERIES_LCASE)xx_hal_uart.c \
486+
stm32$(PB_MCU_SERIES_LCASE)xx_hal_xspi.c \
475487
stm32$(PB_MCU_SERIES_LCASE)xx_hal.c \
476488
stm32$(PB_MCU_SERIES_LCASE)xx_ll_lpuart.c \
477489
stm32$(PB_MCU_SERIES_LCASE)xx_ll_rcc.c \
@@ -489,6 +501,11 @@ endif
489501
ifneq ($(PB_MCU_SERIES),F4)
490502
STM32_HAL_SRC_C := $(filter-out %xx_hal_fmpi2c.c, $(STM32_HAL_SRC_C))
491503
endif
504+
ifneq ($(PB_MCU_SERIES),H5)
505+
STM32_HAL_SRC_C := $(filter-out %xx_hal_dma_ex.c, $(STM32_HAL_SRC_C))
506+
STM32_HAL_SRC_C := $(filter-out %xx_hal_icache.c, $(STM32_HAL_SRC_C))
507+
STM32_HAL_SRC_C := $(filter-out %xx_hal_xspi.c, $(STM32_HAL_SRC_C))
508+
endif
492509
ifneq ($(PB_MCU_SERIES),L4)
493510
STM32_HAL_SRC_C := $(filter-out %xx_ll_lpuart.c, $(STM32_HAL_SRC_C))
494511
endif
@@ -812,7 +829,9 @@ $(BUILD)/firmware-base.bin: $(BUILD)/firmware-obj.bin
812829
# Safety requirement for SPIKE Prime
813830
ifneq ($(findstring prime_hub,$(PBIO_PLATFORM)),)
814831
$(Q)od -An -t u1 -j 0x264 -N 1 $< | awk '{if ($$1 >= 15) { print "Error: byte at 0x264 must be < 0xf"; exit 1 } }'
832+
ifeq ($(PBIO_PLATFORM),prime_hub_f4)
815833
$(Q)od -An -t u1 -j 0x1f0 -N 1 $< | awk '{if ($$1 >= 15) { print "Error: byte at 0x1f0 must be < 0xf"; exit 1 } }'
834+
endif
816835
endif
817836
$(Q)cp $< $@
818837
endif

bricks/primehub/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# Wrapper makefile that builds all primehub variants and combines them into a
55
# single multi-variant firmware.zip.
66

7-
VARIANTS = primehub_f4
7+
VARIANTS = primehub_f4 primehub_h5
88

99
BUILD = build
1010
PYTHON ?= python

bricks/primehub_h5/Makefile

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# SPDX-License-Identifier: MIT
2+
# Copyright (c) 2019-2026 The Pybricks Authors
3+
4+
PBIO_PLATFORM = prime_hub_h5
5+
PB_MCU_FAMILY = STM32
6+
PB_MCU_SERIES = H5
7+
PB_CMSIS_MCU = STM32H562xx
8+
PB_MCU_EXT_OSC_HZ = 16000000
9+
PB_LIB_STM32_HAL = 1
10+
PB_LIB_LSM6DS3TR_C = 1
11+
PB_LIB_BLUENRG = 0
12+
PB_LIB_BTSTACK = 1
13+
PB_LIB_STM32_USB_DEVICE = 1
14+
TEXT0_ADDR = 0x8008000
15+
DFU_VID = 0x0694
16+
DFU_PID = 0x0008
17+
PB_FROZEN_MODULES = 1
18+
19+
include ../_common/common.mk

0 commit comments

Comments
 (0)