TARGETS = projects/gcc/tools iap modules service_hw 
BUILDDIR = build

.PHONY: all config $(TARGETS) tools distclean

all: config $(TARGETS) 

CFLAGS += -DHARDWARE_$(HARDWARE)

bt6703:
	@$(MAKE) HARDWARE=$@

$(TARGETS):
	@$(MAKE) -C $@

clean: $(TARGETS)

distclean:
	rm -rf build output

output: $(TARGETS)


openocd_ups:
	$(shell openocd -f projects/gcc/configs/stm32f4discovery.cfg)

gdb:
	$(shell arm-none-eabi-gdb build/stm32bt6703/stm32bt6703.elf)

reset:
	st-flash --reset read /dev/null 0x8000000 1

erase:
	st-flash --reset erase

iapflash:
	st-flash --reset write output/iap.bin 0x8000000

fwflash_6703:	
	st-flash --reset write output/stm32bt6703.bin 0x8020000

fullflash_6703:
	st-flash --reset write output/iap.bin 0x8000000
	sleep 1
	st-flash --reset write output/stm32bt6703.bin 0x8020000
	
fwflash_6707:	
	st-flash --reset write output/stm32bt6707.bin 0x8020000

fullflash_6707:
	st-flash --reset write output/iap.bin 0x8000000
	sleep 1
	st-flash --reset write output/stm32bt6707.bin 0x8020000	
	
fullflash_6709:
	st-flash --reset write output/iap.bin 0x8000000
	sleep 1
	st-flash --reset write output/stm32bt6709.bin 0x8020000	

release_6703:
	$(MAKE) -C modules HARDWARE=bt6703 VERBOSE=1 DEBUG=0 PRINTF=custom MAC=EC-4C-4D-00-80-0A release
	
release_6707:
	$(MAKE) -C modules HARDWARE=bt6707 VERBOSE=1 DEBUG=0 PRINTF=custom MAC=EC-4C-4D-00-80-0A release

release_6709:
	$(MAKE) -C modules HARDWARE=bt6709 VERBOSE=1 DEBUG=0 PRINTF=custom MAC=EC-4C-4D-00-80-0A release