Skip to content

Commit 79560dd

Browse files
committed
fix(daplink_bridge): Address review on portability and venv staleness.
Three issues raised on PR #387: 1. Toolchain download was hard-coded to x86_64-linux. Detect uname and pick the matching ARM-published archive (Linux x86_64, Linux aarch64, Intel macOS). Fail with a clear message — and a pointer to the dev container — on Apple Silicon and Windows, where 10.3-2021.10 is not published. 2. Deprecated `deploy-pyocd` / `deploy-openocd` advertised non-existent `daplink-deploy-pyocd` / `daplink-deploy-openocd` targets. Suggest only the `micropython-` variant until the SWD-based DAPLink targets land (tracked in #388). 3. The DAPLink venv was created once and never refreshed, so a `daplink-update` that bumped requirements.txt would silently reuse stale dependencies. Replace the manual check with a sentinel file that depends on requirements.txt, so pip install re-runs whenever upstream bumps a dep. Also document the platform constraint in CONTRIBUTING.md.
1 parent 9e6ac93 commit 79560dd

3 files changed

Lines changed: 52 additions & 12 deletions

File tree

CONTRIBUTING.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,9 @@ For local development (without dev container):
119119

120120
* Python 3.10+
121121
* Node.js 22+ (for husky, commitlint, lint-staged, semantic-release)
122-
* `arm-none-eabi-gcc` toolchain (for `make micropython-firmware` and `make daplink-firmware`)
122+
* `arm-none-eabi-gcc` toolchain (for `make micropython-firmware`; `make daplink-firmware` ignores the system toolchain and downloads its own pinned 10.3-2021.10 build)
123123
* `ccache` and `ninja-build` (for `make daplink-firmware`)
124+
* For `make daplink-firmware`: Linux x86_64, Linux aarch64, or Intel macOS only (the pinned toolchain is not published for Apple Silicon or Windows — use the dev container on those platforms)
124125
* `pyocd` (for `make micropython-deploy`, installed via `pip install -e ".[flash]"`)
125126
* OpenOCD (optional, for `make micropython-deploy-openocd`)
126127
* `mpremote` (installed via `pip install -e ".[test]"`)

Makefile

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,15 @@ micropython-deploy-usb: $(MPY_DIR) ## Flash MicroPython firmware via DAPLink USB
147147
define DEPRECATED_FIRMWARE
148148
@echo "Error: 'make $(1)' is ambiguous. Use one of:"; \
149149
echo " make micropython-$(2) (MicroPython firmware)"; \
150-
echo " make daplink-$(2) (DAPLink firmware, see #377)"; \
150+
echo " make daplink-$(2) (DAPLink firmware)"; \
151+
exit 1
152+
endef
153+
154+
# Variant for short names whose DAPLink counterpart does not exist yet
155+
# (daplink-deploy-pyocd / daplink-deploy-openocd are tracked in #388).
156+
define DEPRECATED_MICROPYTHON_ONLY
157+
@echo "Error: 'make $(1)' has been renamed. Use:"; \
158+
echo " make micropython-$(2) (MicroPython firmware)"; \
151159
exit 1
152160
endef
153161

@@ -161,9 +169,9 @@ firmware-clean:
161169
deploy:
162170
$(call DEPRECATED_FIRMWARE,deploy,deploy)
163171
deploy-pyocd:
164-
$(call DEPRECATED_FIRMWARE,deploy-pyocd,deploy-pyocd)
172+
$(call DEPRECATED_MICROPYTHON_ONLY,deploy-pyocd,deploy-pyocd)
165173
deploy-openocd:
166-
$(call DEPRECATED_FIRMWARE,deploy-openocd,deploy-openocd)
174+
$(call DEPRECATED_MICROPYTHON_ONLY,deploy-openocd,deploy-openocd)
167175
deploy-usb:
168176
$(call DEPRECATED_FIRMWARE,deploy-usb,deploy-usb)
169177

@@ -206,20 +214,32 @@ $(DAPLINK_DIR):
206214
git clone --branch $(DAPLINK_BRANCH) $(DAPLINK_REPO) $(CURDIR)/$(DAPLINK_DIR)
207215

208216
$(DAPLINK_GCC_DIR)/bin/arm-none-eabi-gcc:
209-
@echo "Downloading gcc-arm-none-eabi $(DAPLINK_GCC_VERSION) for DAPLink..."
217+
@set -e
218+
@if [ -z "$(DAPLINK_GCC_ARCHIVE)" ]; then \
219+
echo "Error: no prebuilt gcc-arm-none-eabi $(DAPLINK_GCC_VERSION) for $(DAPLINK_GCC_HOST_OS)/$(DAPLINK_GCC_HOST_ARCH)."; \
220+
echo "Supported by this target: Linux x86_64, Linux aarch64, macOS Intel."; \
221+
echo "Other platforms: install the toolchain manually and override DAPLINK_GCC_DIR,"; \
222+
echo "or build inside the dev container."; \
223+
exit 1; \
224+
fi
225+
@echo "Downloading gcc-arm-none-eabi $(DAPLINK_GCC_VERSION) for $(DAPLINK_GCC_HOST_OS)/$(DAPLINK_GCC_HOST_ARCH)..."
210226
@mkdir -p $(BUILD_DIR)
211227
curl -fL -o $(BUILD_DIR)/gcc-arm-none-eabi.tar.bz2 "$(DAPLINK_GCC_URL)"
212228
tar -xjf $(BUILD_DIR)/gcc-arm-none-eabi.tar.bz2 -C $(BUILD_DIR)
213229
rm -f $(BUILD_DIR)/gcc-arm-none-eabi.tar.bz2
214230

215-
.PHONY: daplink-firmware
216-
daplink-firmware: $(DAPLINK_DIR) $(DAPLINK_GCC_DIR)/bin/arm-none-eabi-gcc ## Build DAPLink interface firmware for the STeaMi STM32F103
217-
@set -e
218-
@if [ ! -d "$(DAPLINK_DIR)/venv" ]; then \
219-
echo "Setting up DAPLink Python virtualenv..."; \
231+
# Sentinel: re-runs pip install whenever DAPLink's requirements.txt changes
232+
# (e.g. after `make daplink-update`).
233+
$(DAPLINK_DIR)/venv/.installed: $(DAPLINK_DIR)/requirements.txt
234+
@echo "Setting up DAPLink Python virtualenv..."
235+
@if [ ! -x "$(DAPLINK_DIR)/venv/bin/python" ]; then \
220236
$(PYTHON) -m venv $(DAPLINK_DIR)/venv; \
221-
$(DAPLINK_DIR)/venv/bin/pip install -r $(DAPLINK_DIR)/requirements.txt; \
222237
fi
238+
$(DAPLINK_DIR)/venv/bin/pip install -r $(DAPLINK_DIR)/requirements.txt
239+
@touch $@
240+
241+
.PHONY: daplink-firmware
242+
daplink-firmware: $(DAPLINK_DIR) $(DAPLINK_GCC_DIR)/bin/arm-none-eabi-gcc $(DAPLINK_DIR)/venv/.installed ## Build DAPLink interface firmware for the STeaMi STM32F103
223243
@echo "Building DAPLink target $(DAPLINK_TARGET) with gcc-arm-none-eabi $(DAPLINK_GCC_VERSION)..."
224244
cd $(CURDIR)/$(DAPLINK_DIR) && \
225245
PATH="$(CURDIR)/$(DAPLINK_GCC_DIR)/bin:$(CURDIR)/$(DAPLINK_DIR)/venv/bin:$$PATH" \

env.mk

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,25 @@ DAPLINK_BUILD_DIR ?= $(DAPLINK_DIR)/projectfiles/make_gcc_arm/$(DAPLINK_TARGET)/
2020
# DAPLink requires gcc-arm-none-eabi 10.3-2021.10. System toolchains >= 11.3
2121
# produce code that overflows m_text (see DAPLink docs/DEVELOPERS-GUIDE.md and
2222
# ARMmbed/DAPLink#1043). The toolchain is downloaded once into BUILD_DIR.
23+
#
24+
# ARM publishes 10.3-2021.10 binaries for: x86_64 Linux, aarch64 Linux, and
25+
# Intel macOS. Apple Silicon and Windows are NOT supported by this target —
26+
# users on those platforms must install the toolchain manually and override
27+
# DAPLINK_GCC_DIR / DAPLINK_GCC_URL, or build inside the dev container.
2328
DAPLINK_GCC_VERSION ?= 10.3-2021.10
2429
DAPLINK_GCC_DIR ?= $(BUILD_DIR)/gcc-arm-none-eabi-$(DAPLINK_GCC_VERSION)
25-
DAPLINK_GCC_URL ?= https://developer.arm.com/-/media/Files/downloads/gnu-rm/$(DAPLINK_GCC_VERSION)/gcc-arm-none-eabi-$(DAPLINK_GCC_VERSION)-x86_64-linux.tar.bz2
30+
31+
DAPLINK_GCC_HOST_OS := $(shell uname -s)
32+
DAPLINK_GCC_HOST_ARCH := $(shell uname -m)
33+
ifeq ($(DAPLINK_GCC_HOST_OS),Linux)
34+
ifeq ($(DAPLINK_GCC_HOST_ARCH),x86_64)
35+
DAPLINK_GCC_ARCHIVE ?= gcc-arm-none-eabi-$(DAPLINK_GCC_VERSION)-x86_64-linux.tar.bz2
36+
else ifeq ($(DAPLINK_GCC_HOST_ARCH),aarch64)
37+
DAPLINK_GCC_ARCHIVE ?= gcc-arm-none-eabi-$(DAPLINK_GCC_VERSION)-aarch64-linux.tar.bz2
38+
endif
39+
else ifeq ($(DAPLINK_GCC_HOST_OS),Darwin)
40+
ifeq ($(DAPLINK_GCC_HOST_ARCH),x86_64)
41+
DAPLINK_GCC_ARCHIVE ?= gcc-arm-none-eabi-$(DAPLINK_GCC_VERSION)-mac.tar.bz2
42+
endif
43+
endif
44+
DAPLINK_GCC_URL ?= https://developer.arm.com/-/media/Files/downloads/gnu-rm/$(DAPLINK_GCC_VERSION)/$(DAPLINK_GCC_ARCHIVE)

0 commit comments

Comments
 (0)