support multiple SWD adapter

This commit is contained in:
King Kévin 2016-06-05 17:54:56 +02:00
parent c679a74ba7
commit 02835fa72f
1 changed files with 12 additions and 1 deletions

View File

@ -108,13 +108,20 @@ LDLIBS += -Wl,--start-group -lc -lgcc -lnosys -Wl,--end-group
FP_FLAGS ?= -msoft-float
ARCH_FLAGS = -mthumb -mcpu=cortex-m3 $(FP_FLAGS) -mfix-cortex-m3-ldrd
# SWD adapter used
# supported are : st-link v2 (STLINKV2)
SWD_ADAPTER ?= STLINKV2
ifeq ($(SWD_ADAPTER),STLINKV2)
# OpenOCD configuration
OOCD ?= openocd
OOCD_INTERFACE ?= stlink-v2
OOCD_TARGET ?= stm32f1x
endif
# which USB CDC ACM port is used bu the device, so we can reset it
ifeq ($(SWD_ADAPTER),STLINKV2)
ACMPORT = /dev/ttyACM0
endif
ACMPORT_EXISTS = $(shell [ -e $(ACMPORT) ] && echo 1 || echo 0 )
# compile target rules
@ -163,7 +170,9 @@ $(LIB_DIR)/lib$(LIBNAME).a:
flash: $(BINARY).hex
$(info flashing $(<) using SWD)
ifeq ($(SWD_ADAPTER),STLINKV2)
$(Q)$(OOCD) --file interface/$(OOCD_INTERFACE).cfg --file target/$(OOCD_TARGET).cfg --command "init" --command "reset init" --command "flash write_image erase $(<)" --command "reset" --command "shutdown" $(NULL)
endif
# reset device by setting the data width to 5 bis on the USB CDC ACM port
reset:
@ -172,8 +181,10 @@ ifeq ($(ACMPORT_EXISTS), 1)
$(Q)sleep 0.5
endif
# debug using jtag (openOCB+GDB)
# debug using GDB
debug: $(BINARY).elf
ifeq ($(SWD_ADAPTER),STLINKV2)
$(Q)$(GDB) --eval-command="target remote | $(OOCD) --file interface/$(OOCD_INTERFACE).cfg --file target/$(OOCD_TARGET).cfg --command \"gdb_port pipe; log_output /dev/null; init\"" --eval-command="monitor reset halt" --eval-command="load" --eval-command="monitor reset init" $(<)
endif
.PHONY: clean elf bin hex srec list libraries flash reset