Fork from bluejay at github and modified for my custom ESC. I need to modify it because some mistake design on my ESC hardware.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

119 lines
3.5 KiB

  1. # set current revision
  2. REVISION ?= v0.1.0
  3. # targets
  4. TARGETS = A B C D E F G H I J K L M N O P Q R S T U V W
  5. MCUS = H L
  6. FETON_DELAYS = 0 5 10 15 20 25 30 40 50 70 90
  7. # example single target
  8. VARIANT ?= F
  9. MCU ?= H
  10. FETON_DELAY ?= 40
  11. WINE_BIN ?= /usr/local/bin/wine
  12. # path to the keil binaries
  13. KEIL_PATH ?= ~/Downloads/keil_8051/9.60/BIN
  14. # directory config
  15. OUTPUT_DIR ?= build
  16. OUTPUT_DIR_HEX ?= $(OUTPUT_DIR)/hex
  17. LOG_DIR ?= $(OUTPUT_DIR)/log
  18. # define the assembler/linker scripts
  19. AX51_BIN =$(KEIL_PATH)/AX51.exe
  20. LX51_BIN = $(KEIL_PATH)/LX51.exe
  21. OX51_BIN = $(KEIL_PATH)/Ohx51.exe
  22. AX51 = $(WINE_BIN) $(AX51_BIN)
  23. LX51 = $(WINE_BIN) $(LX51_BIN)
  24. OX51 = $(WINE_BIN) $(OX51_BIN)
  25. # set up flags
  26. AX51_FLAGS = DEBUG NOMOD51
  27. LX51_FLAGS =
  28. # set up sources
  29. ASM_SRC = Bluejay.asm
  30. ASM_INC = $(TARGETS:%=targets/%.inc) Common.inc BLHeliBootLoad.inc BLHeliPgm.inc Silabs/SI_EFM8BB1_Defs.inc Silabs/SI_EFM8BB2_Defs.inc
  31. # check that wine/simplicity studio is available
  32. EXECUTABLES = $(WINE_BIN) $(AX51_BIN) $(LX51_BIN) $(OX51_BIN)
  33. DUMMYVAR := $(foreach exec, $(EXECUTABLES), \
  34. $(if $(wildcard $(exec)),found, \
  35. $(error "Could not find $(exec). Make sure to set the correct paths to the simplicity install location")))
  36. # make sure the list of obj files is expanded twice
  37. .SECONDEXPANSION:
  38. OBJS =
  39. define MAKE_OBJ
  40. OBJS += $(1)_$(2)_$(3)_$(REVISION).OBJ
  41. $(OUTPUT_DIR)/$(1)_$(2)_$(3)_$(REVISION).OBJ : $(ASM_SRC) $(ASM_INC)
  42. $(eval _ESC := $(1))
  43. $(eval _ESC_INT := $(shell printf "%d" "'${_ESC}"))
  44. $(eval _ESCNO := $(shell echo $$(( $(_ESC_INT) - 65 + 1))))
  45. $(eval _MCU_48MHZ := $(subst L,0,$(subst H,1,$(2))))
  46. $(eval _FETON_DELAY := $(3))
  47. $(eval _LOG := $(LOG_DIR)/$(1)_$(2)_$(3)_$(REVISION).log)
  48. @mkdir -p $(OUTPUT_DIR)
  49. @mkdir -p $(LOG_DIR)
  50. @echo "AX51 : $$@"
  51. @$(AX51) $(ASM_SRC) \
  52. "DEFINE(ESCNO=$(_ESCNO)) " \
  53. "DEFINE(MCU_48MHZ=$(_MCU_48MHZ)) "\
  54. "DEFINE(FETON_DELAY=$(_FETON_DELAY)) "\
  55. "OBJECT($$@) "\
  56. "$(AX51_FLAGS)" > $(_LOG) 2>&1; test $$$$? -lt 2 || tail $(_LOG)
  57. endef
  58. HEX_TARGETS = $(OBJS:%.OBJ=$(OUTPUT_DIR_HEX)/%.hex)
  59. EFM8_LOAD_BIN ?= efm8load.py
  60. EFM8_LOAD_PORT ?= /dev/ttyUSB0
  61. EFM8_LOAD_BAUD ?= 57600
  62. SINGLE_TARGET_HEX = $(OUTPUT_DIR_HEX)/$(VARIANT)_$(MCU)_$(FETON_DELAY)_$(REVISION).hex
  63. single_target : $(SINGLE_TARGET_HEX)
  64. all : $$(HEX_TARGETS)
  65. @echo "\nbuild finished. built $(shell ls -l $(OUTPUT_DIR_HEX) | wc -l) hex targets\n"
  66. @grep -q "\*\*\* ERROR" build/log/*.log; test $$? -ne 0
  67. # create all obj targets using macro expansion
  68. $(foreach _e,$(TARGETS), \
  69. $(foreach _m, $(MCUS), \
  70. $(foreach _f, $(FETON_DELAYS), \
  71. $(eval $(call MAKE_OBJ,$(_e),$(_m),$(_f))))))
  72. $(OUTPUT_DIR)/%.OMF : $(OUTPUT_DIR)/%.OBJ
  73. $(eval LOG := $(LOG_DIR)/$(basename $(notdir $@)).log)
  74. @echo "LX51 : linking $< to $@"
  75. @$(LX51) "$<" TO "$@" "$(LX51_FLAGS)" >> $(LOG) 2>&1; test $$? -lt 2 || tail $(LOG)
  76. $(OUTPUT_DIR_HEX)/%.hex : $(OUTPUT_DIR)/%.OMF
  77. $(eval LOG := $(LOG_DIR)/$(basename $(notdir $@)).log)
  78. @mkdir -p $(OUTPUT_DIR_HEX)
  79. @echo "OHX : generating hex file $@"
  80. @$(OX51) "$<" "HEXFILE ($@)" >> $(LOG) 2>&1; test $$? -lt 2 || tail $(LOG)
  81. @mv ./Bluejay.LST $(OUTPUT_DIR)/
  82. help:
  83. @echo ""
  84. @echo "usage examples:"
  85. @echo "================================================================="
  86. @echo "make all # build all targets"
  87. @echo "make VARIANT=A MCU=H FETON_DELAY=5 # to build a single target"
  88. @echo
  89. clean:
  90. @rm -f $(OUTPUT_DIR)/*.{OBJ,MAP,LST}
  91. efm8load: single_target
  92. $(EFM8_LOAD_BIN) -p $(EFM8_LOAD_PORT) -b $(EFM8_LOAD_BAUD) -w $(SINGLE_TARGET_HEX)
  93. .PHONY: all clean help efm8load