Skip to content

Commit

Permalink
Update Makefile openocd rules
Browse files Browse the repository at this point in the history
Remove leftover blackmagicprobe/stlink/ftdi rules
Change `OOCD_INTERFACE` and `OOCD_BOARD` variables to explicitly include
`interface/` and `target/` to allow for local interface/board cfg files
Update debug.cfg to make usable with piping
Add `make debug` target to launch GDB
Add rule to optionally include `local.mk` for local customization
  • Loading branch information
devanlai committed May 2, 2016
1 parent d6d1c9d commit 44ead09
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 46 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,7 @@ GTAGS
*.bin
*.elf
*.axf
*.map
*.map

# ignore local makefile settings
src/local.mk
35 changes: 2 additions & 33 deletions libopencm3.rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -198,46 +198,15 @@ styleclean: $(STYLECHECKFILES:=.styleclean)
@printf " FLASH $<\n"
$(Q)$(STFLASH) write $(*).bin 0x8000000

ifeq ($(STLINK_PORT),)
ifeq ($(BMP_PORT),)
ifeq ($(OOCD_SERIAL),)
%.flash: %.hex
@printf " FLASH $<\n"
@# IMPORTANT: Don't use "resume", only "reset" will work correctly!
$(Q)$(OOCD) -f interface/$(OOCD_INTERFACE).cfg \
-f board/$(OOCD_BOARD).cfg \
$(Q)$(OOCD) -f $(OOCD_INTERFACE) \
-f $(OOCD_BOARD) \
-c "init" -c "reset init" \
-c "flash write_image erase $(*).hex" \
-c "reset" \
-c "shutdown" $(NULL)
else
%.flash: %.hex
@printf " FLASH $<\n"
@# IMPORTANT: Don't use "resume", only "reset" will work correctly!
$(Q)$(OOCD) -f interface/$(OOCD_INTERFACE).cfg \
-f board/$(OOCD_BOARD).cfg \
-c "ft2232_serial $(OOCD_SERIAL)" \
-c "init" -c "reset init" \
-c "flash write_image erase $(*).hex" \
-c "reset" \
-c "shutdown" $(NULL)
endif
else
%.flash: %.elf
@printf " GDB $(*).elf (flash)\n"
$(Q)$(GDB) --batch \
-ex 'target extended-remote $(BMP_PORT)' \
-x $(SCRIPT_DIR)/black_magic_probe_flash.scr \
$(*).elf
endif
else
%.flash: %.elf
@printf " GDB $(*).elf (flash)\n"
$(Q)$(GDB) --batch \
-ex 'target extended-remote $(STLINK_PORT)' \
-x $(SCRIPT_DIR)/stlink_flash.scr \
$(*).elf
endif

.PHONY: images clean stylecheck styleclean elf bin hex srec list

Expand Down
7 changes: 7 additions & 0 deletions openocd/debug.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
gdb_port pipe
gdb_memory_map disable

$_TARGETNAME configure -event gdb-attach {
echo "Halting target"
halt
}

$_TARGETNAME configure -event gdb-detach {
echo "Resetting target"
reset
}
7 changes: 7 additions & 0 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
## NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
## CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

-include local.mk

BINARY = DAP42
OPENCM3_DIR = ../libopencm3

Expand Down Expand Up @@ -52,6 +54,11 @@ include libopencm3.target.mk
size: $(OBJS) $(BINARY).elf
@$(PREFIX)-size $(OBJS) $(BINARY).elf

debug: $(BINARY).elf
-$(GDB) --tui --eval "target remote | $(OOCD) -f $(OOCD_INTERFACE) -f $(OOCD_BOARD) -f ../openocd/debug.cfg" $(BINARY).elf

.PHONY += debug size dfuse-flash

OBJS := $(sort $(OBJS))

# Add the base directory to the header search path
Expand Down
16 changes: 4 additions & 12 deletions src/libopencm3.target.mk
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@ ifeq ($(ARCH),STM32F0)
DEFS += -DSTM32F0
FP_FLAGS ?= -msoft-float
ARCH_FLAGS = -mthumb -mcpu=cortex-m0 $(FP_FLAGS)
OOCD_BOARD ?= target/stm32f0x.cfg
endif
ifeq ($(ARCH),STM32F1)
LIBNAME = opencm3_stm32f1
DEFS += -DSTM32F1
FP_FLAGS ?= -msoft-float
ARCH_FLAGS = -mthumb -mcpu=cortex-m3 $(FP_FLAGS) -mfix-cortex-m3-ldrd
OOCD_BOARD ?= target/stm32f1x.cfg
endif

LIBNAME ?= opencm3_stm32f0
Expand All @@ -40,17 +42,7 @@ ARCH_FLAGS ?= -mthumb -mcpu=cortex-m0 $(FP_FLAGS)
# OpenOCD specific variables

OOCD ?= openocd
OOCD_INTERFACE ?= flossjtag
OOCD_BOARD ?= olimex_stm32_h103

################################################################################
# Black Magic Probe specific variables
# Set the BMP_PORT to a serial port and then BMP is used for flashing
BMP_PORT ?=

################################################################################
# texane/stlink specific variables
#STLINK_PORT ?= :4242

OOCD_INTERFACE ?= interface/cmsis-dap.cfg
OOCD_BOARD ?= target/stm32f1x.cfg

include ../libopencm3.rules.mk

0 comments on commit 44ead09

Please sign in to comment.