Skip to content

Instantly share code, notes, and snippets.

@geky
Last active October 15, 2019 20:31
Show Gist options
  • Save geky/60ba84a1041e6ecc2e0b7506e0a4fe06 to your computer and use it in GitHub Desktop.
Save geky/60ba84a1041e6ecc2e0b7506e0a4fe06 to your computer and use it in GitHub Desktop.
Simple makefile for mbed OS
MBED = $(firstword $(wildcard mbed mbed-os core .))
TARGET = K82F
TOOLCHAIN = GCC_ARM
#SRC ?= $(firstword $(wildcard TESTS/*/*))
BUILD ?= BUILD
BOARD ?= BOARD
VENDOR ?= MBED ARM STMicroelectronics
BAUD ?= 9600
DEV ?= /dev/$(notdir $(firstword $(foreach v,$(VENDOR), \
$(shell udevadm trigger -v -n -s block -p ID_VENDOR=$(v)))))
TTY ?= /dev/$(notdir $(firstword $(foreach v,$(VENDOR), \
$(shell udevadm trigger -v -n -s tty -p ID_VENDOR=$(v)))))
CFLAGS += -j0
ifdef VERBOSE
CFLAGS += -v
endif
ifdef DEBUG
#CFLAGS += -o debug-info
CFLAGS += --profile debug
endif
ifdef SMALL
#CFLAGS += --profile small
CFLAGS += --profile release
endif
CFLAGS += -DMBED_HEAP_STATS_ENABLED -DMBED_STACK_STATS_ENABLED
all build:
mkdir -p $(BUILD)/$(TARGET)/$(TOOLCHAIN)
echo '*' > $(BUILD)/$(TARGET)/$(TOOLCHAIN)/.mbedignore
python $(MBED)/tools/make.py -t $(TOOLCHAIN) -m $(TARGET) \
$(addprefix --source=, . $(SRC)) \
$(addprefix --build=, $(BUILD)/$(TARGET)/$(TOOLCHAIN)) \
$(CFLAGS)
flash:
mkdir -p $(BOARD)
sudo umount $(BOARD) || true
sudo mount $(DEV) $(BOARD)
sudo cp $(BUILD)/$(TARGET)/$(TOOLCHAIN)/*.bin $(BOARD)
sync $(BOARD)
sudo umount $(BOARD)
@sleep 3
cat:
sudo stty -F $(TTY) sane nl $(BAUD)
sudo cat $(TTY)
reset:
sudo python -c '__import__("serial").Serial("$(TTY)").send_break()'
screen:
sudo screen $(TTY) $(BAUD)
debug:
sudo killall pyocd-gdbserver || true
@sleep 0.5
sudo pyocd-gdbserver &
arm-none-eabi-gdb $(BUILD)/$(TARGET)/$(TOOLCHAIN)/*.elf \
-ex "target remote :3333"
@sleep 0.5
size:
arm-none-eabi-size $(BUILD)/$(TARGET)/$(TOOLCHAIN)/*.elf
ctags:
ctags $$(find -regex '.*\.\(h\|c\|hpp\|cpp\)')
clean:
rm -rf $(BUILD) $(BOARD)
@kegilbert
Copy link

kegilbert commented Apr 24, 2017

VENDOR is defined twice

Edit: Resolved fam

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment