Skip to content

Commit 4bffbad

Browse files
committed
bricks/primehub: Generalize build target.
We'll have multiple hardware revisions for some hubs. Single targets are built as before, but we allow the zip file to contain multiple targets, identified by the pbio platform. The flashing tool will ultimately pick the right one by detecting what is attached, so the end user cannot accidentally pick the wrong one.
1 parent 661d8a5 commit 4bffbad

33 files changed

Lines changed: 365 additions & 142 deletions

.github/build-each-commit.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,13 @@
100100

101101
# upload firmware size
102102
if "firmware_size_table" in globals():
103+
# Monitor only size of original variant for each hub type.
104+
dir_name = args.hub
105+
if args.hub == "primehub":
106+
dir_name = "primehub_f4"
107+
103108
bin_path = os.path.join(
104-
PYBRICKS_PATH, "bricks", args.hub, "build", "firmware-base.bin"
109+
PYBRICKS_PATH, "bricks", dir_name, "build", "firmware-base.bin"
105110
)
106111
size = os.path.getsize(bin_path)
107112

.github/build-missing-commits.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,13 @@
139139
# Wait for the target to complete building or fail
140140
proc.wait()
141141

142+
dir_name = target
143+
if target == "primehub":
144+
dir_name = "primehub_f4"
145+
142146
# Get build size on success
143147
bin_path = os.path.join(
144-
PYBRICKS_PATH, "bricks", target, "build", "firmware-base.bin"
148+
PYBRICKS_PATH, "bricks", dir_name, "build", "firmware-base.bin"
145149
)
146150
try:
147151
sizes[target] = os.path.getsize(bin_path)

.vscode/c_cpp_properties.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
{
88
"configurations": [
99
{
10-
"name": "primehub",
10+
"name": "primehub f4",
1111
"includePath": [
1212
"${workspaceFolder}/micropython/lib/cmsis/inc",
1313
"${workspaceFolder}/micropython/lib/stm32lib/CMSIS/STM32F4xx/Include",
@@ -21,10 +21,10 @@
2121
"${workspaceFolder}/lib/lsm6ds3tr_c_STdC/driver",
2222
"${workspaceFolder}/lib/pbio/drv/usb/stm32_usbd",
2323
"${workspaceFolder}/lib/pbio/include",
24-
"${workspaceFolder}/lib/pbio/platform/prime_hub",
24+
"${workspaceFolder}/lib/pbio/platform/prime_hub_f4",
2525
"${workspaceFolder}",
26-
"${workspaceFolder}/bricks/primehub",
27-
"${workspaceFolder}/bricks/primehub/build",
26+
"${workspaceFolder}/bricks/primehub_f4",
27+
"${workspaceFolder}/bricks/primehub_f4/build",
2828
"${workspaceFolder}/micropython"
2929
],
3030
"defines": [

.vscode/tasks.json

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,34 +8,6 @@
88
"type": "shell",
99
"command": "make movehub -j"
1010
},
11-
{
12-
"label": "build and deploy primehub",
13-
"type": "shell",
14-
"command": "make",
15-
"args": ["-j", "deploy"],
16-
"group": {
17-
"kind": "build",
18-
"isDefault": true
19-
},
20-
"options": {
21-
"cwd": "${workspaceFolder}/bricks/primehub"
22-
},
23-
"problemMatcher": [
24-
{
25-
"owner": "cpp",
26-
"fileLocation": ["relative", "${workspaceFolder}/bricks/primehub"],
27-
"pattern": {
28-
"regexp": "^(.*?):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
29-
"file": 1,
30-
"line": 2,
31-
"column": 3,
32-
"severity": 4,
33-
"message": 5
34-
}
35-
}
36-
],
37-
"detail": "Build the PrimeHub project"
38-
},
3911
{
4012
"options": {
4113
"cwd": "${workspaceFolder}/bricks/virtualhub"

bricks/_common/common.mk

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ GIT = git
160160
ZIP = zip
161161
DFU = $(TOP)/tools/dfu.py
162162
PYDFU = $(TOP)/tools/pydfu.py
163-
PYBRICKSDEV = $(PYTHON) $(PBTOP)/tools/flash
163+
FLASH = $(PYTHON) $(PBTOP)/tools/flash
164164
METADATA = $(PBTOP)/tools/metadata.py
165165
MEDIA_CONVERT = $(PBTOP)/lib/pbio/src/image/media.py
166166
FONT_CONVERT = $(PBTOP)/lib/pbio/src/image/fontconvert.py
@@ -835,7 +835,7 @@ $(BUILD)/%.dfu: $(BUILD)/%-base.bin
835835
$(Q)$(PYTHON) $(DFU) -b $(TEXT0_ADDR):$< $@
836836

837837
deploy: $(BUILD)/firmware.zip
838-
$(Q)$(PYBRICKSDEV) $< $(if $(filter-out nxt ev3,$(PBIO_PLATFORM)),--name $(PBIO_PLATFORM))
838+
$(Q)$(FLASH) $< --name $(PBIO_PLATFORM)
839839

840840
deploy-openocd: $(BUILD)/firmware-base.bin
841841
$(ECHO) "Writing $< to the board via ST-LINK using OpenOCD"

bricks/essentialhub/manifest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
include("../_common/manifest.py")
33

44
# Essential Hub IMU is the same as the one in Prime Hub
5-
freeze_as_mpy("../primehub/modules", "_imu_calibrate.py")
5+
freeze_as_mpy("../primehub_f4/modules", "_imu_calibrate.py")

bricks/primehub/Makefile

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,32 @@
11
# SPDX-License-Identifier: MIT
2-
# Copyright (c) 2019-2020 The Pybricks Authors
3-
4-
PBIO_PLATFORM = prime_hub
5-
PB_MCU_FAMILY = STM32
6-
PB_MCU_SERIES = F4
7-
PB_CMSIS_MCU = STM32F413xx
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
2+
# Copyright (c) 2024 The Pybricks Authors
3+
4+
# Wrapper makefile that builds all primehub variants and combines them into a
5+
# single multi-variant firmware.zip.
6+
7+
VARIANTS = primehub_f4
8+
9+
BUILD = build
10+
PYTHON ?= python
11+
COMBINE = ../../tools/combine_firmware.py
12+
FLASH = $(PYTHON) ../../tools/flash
13+
VARIANT_ZIPS = $(foreach v,$(VARIANTS),../$(v)/build/firmware.zip)
14+
15+
all: $(BUILD)/firmware.zip
16+
17+
$(VARIANTS):
18+
$(MAKE) -C ../$@
19+
20+
# Always rebuild: the variant sub-makes decide what is up to date.
21+
$(BUILD)/firmware.zip: $(VARIANTS)
22+
mkdir -p $(BUILD)
23+
$(PYTHON) $(COMBINE) $@ $(VARIANT_ZIPS)
24+
25+
deploy: $(BUILD)/firmware.zip
26+
$(FLASH) $< --name primehub
27+
28+
clean:
29+
for variant in $(VARIANTS); do $(MAKE) -C ../$$variant clean; done
30+
rm -rf $(BUILD)
31+
32+
.PHONY: all clean deploy $(VARIANTS)

bricks/primehub/manifest.py

Lines changed: 0 additions & 4 deletions
This file was deleted.

bricks/primehub_f4/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-2020 The Pybricks Authors
3+
4+
PBIO_PLATFORM = prime_hub_f4
5+
PB_MCU_FAMILY = STM32
6+
PB_MCU_SERIES = F4
7+
PB_CMSIS_MCU = STM32F413xx
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)