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

fwflash_6703_rt:	
	st-flash --reset write output/stm32bt6703_rt.bin 0x8020000

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

fullflash_6703_rt:
	st-flash --reset write output/iap.bin 0x8000000
	sleep 1
	st-flash --reset write output/stm32bt6703_rt.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	

fullflash_6709_mts:
	st-flash --reset write output/iap.bin 0x8000000
	sleep 1
	st-flash --reset write output/stm32bt6709_mts.bin 0x8020000	

fullflash_6710:
	st-flash --reset write output/iap.bin 0x8000000
	sleep 1
	st-flash --reset write output/stm32bt6710.bin 0x8020000	

fullflash_6711:
	st-flash --reset write output/iap.bin 0x8000000
	sleep 1
	st-flash --reset write output/stm32bt6711.bin 0x8020000	

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

release_6703_rt:
	$(MAKE) -C modules HARDWARE=bt6703_rt 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_mts:
	$(MAKE) -C modules HARDWARE=bt6709_mts VERBOSE=1 DEBUG=0 PRINTF=custom MAC=EC-4C-4D-00-80-0A release

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

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

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

