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.

129 lines
3.9 KiB

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