summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Leech <andrew.leech@planetinnovation.com.au>2020-02-24 17:20:20 +1100
committerDamien George <damien.p.george@gmail.com>2020-04-18 23:02:00 +1000
commit8ee2e1fdbcf494d39162b38d9a8427aa012fe044 (patch)
tree745dcb3ab86689a654c73b993e114c69fd02cb13
parent30840ebc9925bb8ef025dbc2d5982b1bfeb75f1b (diff)
stm32/mboot: Expose custom DFU USB VID/PID values at makefile level.
In mboot, the ability to override the USB vendor/product id's was added back in 5688c9ba09ea8f9ffeeb25bd577a08b57828ffa7. However, when the main firmware is turned into a DFU file the default VID/PID are used there. pydfu.py doesn't care about this but dfu-util does and prevents its use when the VID/PID don't match. This commit exposes BOOTLOADER_DFU_USB_VID/PID as make variables, for use on either command line or mpconfigboard.mk, to set VID/PID in both mboot and DFU files.
-rw-r--r--ports/stm32/Makefile11
-rwxr-xr-xports/stm32/mboot/Makefile4
-rw-r--r--ports/stm32/mboot/main.c4
3 files changed, 11 insertions, 8 deletions
diff --git a/ports/stm32/Makefile b/ports/stm32/Makefile
index 2ddebd1cf..28408c62f 100644
--- a/ports/stm32/Makefile
+++ b/ports/stm32/Makefile
@@ -45,7 +45,8 @@ DFU=$(TOP)/tools/dfu.py
USE_PYDFU ?= 1
PYDFU ?= $(TOP)/tools/pydfu.py
DFU_UTIL ?= dfu-util
-DEVICE=0483:df11
+BOOTLOADER_DFU_USB_VID ?= 0x0483
+BOOTLOADER_DFU_USB_PID ?= 0xDF11
STFLASH ?= st-flash
OPENOCD ?= openocd
OPENOCD_CONFIG ?= boards/openocd_stm32f4.cfg
@@ -551,9 +552,9 @@ endif
deploy: $(BUILD)/firmware.dfu
$(ECHO) "Writing $< to the board"
ifeq ($(USE_PYDFU),1)
- $(Q)$(PYTHON) $(PYDFU) -u $<
+ $(Q)$(PYTHON) $(PYDFU) --vid $(BOOTLOADER_DFU_USB_VID) --pid $(BOOTLOADER_DFU_USB_PID) -u $<
else
- $(Q)$(DFU_UTIL) -a 0 -d $(DEVICE) -D $<
+ $(Q)$(DFU_UTIL) -a 0 -d $(BOOTLOADER_DFU_USB_VID):$(BOOTLOADER_DFU_USB_PID) -D $<
endif
# A board should specify TEXT0_ADDR if to use a different location than the
@@ -577,7 +578,7 @@ deploy-openocd: $(BUILD)/firmware.dfu
$(BUILD)/firmware.dfu: $(BUILD)/firmware.elf
$(ECHO) "Create $@"
$(Q)$(OBJCOPY) -O binary $(addprefix -j ,$(TEXT0_SECTIONS)) $^ $(BUILD)/firmware.bin
- $(Q)$(PYTHON) $(DFU) -b $(TEXT0_ADDR):$(BUILD)/firmware.bin $@
+ $(Q)$(PYTHON) $(DFU) -D $(BOOTLOADER_DFU_USB_VID):$(BOOTLOADER_DFU_USB_PID) -b $(TEXT0_ADDR):$(BUILD)/firmware.bin $@
else
# TEXT0_ADDR and TEXT1_ADDR are specified so split firmware between these locations
@@ -599,7 +600,7 @@ $(BUILD)/firmware.dfu: $(BUILD)/firmware.elf
$(ECHO) "GEN $@"
$(Q)$(OBJCOPY) -O binary $(addprefix -j ,$(TEXT0_SECTIONS)) $^ $(BUILD)/firmware0.bin
$(Q)$(OBJCOPY) -O binary $(addprefix -j ,$(TEXT1_SECTIONS)) $^ $(BUILD)/firmware1.bin
- $(Q)$(PYTHON) $(DFU) -b $(TEXT0_ADDR):$(BUILD)/firmware0.bin -b $(TEXT1_ADDR):$(BUILD)/firmware1.bin $@
+ $(Q)$(PYTHON) $(DFU) -D $(BOOTLOADER_DFU_USB_VID):$(BOOTLOADER_DFU_USB_PID) -b $(TEXT0_ADDR):$(BUILD)/firmware0.bin -b $(TEXT1_ADDR):$(BUILD)/firmware1.bin $@
endif
diff --git a/ports/stm32/mboot/Makefile b/ports/stm32/mboot/Makefile
index 89fe97ab2..36d8613ff 100755
--- a/ports/stm32/mboot/Makefile
+++ b/ports/stm32/mboot/Makefile
@@ -28,7 +28,8 @@ HAL_DIR=lib/stm32lib/STM32$(MCU_SERIES_UPPER)xx_HAL_Driver
USBDEV_DIR=usbdev
DFU=$(TOP)/tools/dfu.py
PYDFU ?= $(TOP)/tools/pydfu.py
-DEVICE=0483:df11
+BOOTLOADER_DFU_USB_VID ?= 0x0483
+BOOTLOADER_DFU_USB_PID ?= 0xDF11
STFLASH ?= st-flash
OPENOCD ?= openocd
OPENOCD_CONFIG ?= boards/openocd_stm32f4.cfg
@@ -64,6 +65,7 @@ CFLAGS += -DBOARD_$(BOARD)
CFLAGS += -DAPPLICATION_ADDR=$(TEXT0_ADDR)
CFLAGS += -DFFCONF_H=\"ports/stm32/mboot/ffconf.h\"
CFLAGS += -DBUILDING_MBOOT=1
+CFLAGS += -DBOOTLOADER_DFU_USB_VID=$(BOOTLOADER_DFU_USB_VID) -DBOOTLOADER_DFU_USB_PID=$(BOOTLOADER_DFU_USB_PID)
LDFLAGS = -nostdlib -L . -T stm32_generic.ld -Map=$(@:.elf=.map) --cref
LIBS = $(shell $(CC) $(CFLAGS) -print-libgcc-file-name)
diff --git a/ports/stm32/mboot/main.c b/ports/stm32/mboot/main.c
index da4463e1c..4ae575f3d 100644
--- a/ports/stm32/mboot/main.c
+++ b/ports/stm32/mboot/main.c
@@ -1109,11 +1109,11 @@ typedef struct _pyb_usbdd_obj_t {
#endif
#ifndef MBOOT_USB_VID
-#define MBOOT_USB_VID 0x0483
+#define MBOOT_USB_VID BOOTLOADER_DFU_USB_VID
#endif
#ifndef MBOOT_USB_PID
-#define MBOOT_USB_PID 0xDF11
+#define MBOOT_USB_PID BOOTLOADER_DFU_USB_PID
#endif
static const uint8_t usbd_fifo_size[] = {