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.

125 lines
3.8 KiB

  1. # set current revision
  2. REVISION ?= v0.3.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
  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)/log
  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. # make sure the list of obj files is expanded twice
  40. .SECONDEXPANSION:
  41. OBJS =
  42. define MAKE_OBJ
  43. OBJS += $(1)_$(2)_$(3)_$(4)_$(REVISION).OBJ
  44. $(OUTPUT_DIR)/$(1)_$(2)_$(3)_$(4)_$(REVISION).OBJ : $(ASM_SRC) $(ASM_INC)
  45. $(eval _ESC := $(1))
  46. $(eval _ESC_INT := $(shell printf "%d" "'${_ESC}"))
  47. $(eval _ESCNO := $(shell echo $$(( $(_ESC_INT) - 65 + 1))))
  48. $(eval _MCU_48MHZ := $(subst L,0,$(subst H,1,$(2))))
  49. $(eval _FETON_DELAY := $(3))
  50. $(eval _PWM_48KHZ := $(subst 24,0,$(subst 48,1,$(4))))
  51. $(eval _LOG := $(LOG_DIR)/$(1)_$(2)_$(3)_$(REVISION).log)
  52. @mkdir -p $(OUTPUT_DIR)
  53. @mkdir -p $(LOG_DIR)
  54. @echo "AX51 : $$@"
  55. @$(AX51) $(ASM_SRC) \
  56. "DEFINE(ESCNO=$(_ESCNO)) " \
  57. "DEFINE(MCU_48MHZ=$(_MCU_48MHZ)) "\
  58. "DEFINE(FETON_DELAY=$(_FETON_DELAY)) "\
  59. "DEFINE(PWM_48KHZ=$(_PWM_48KHZ)) "\
  60. "OBJECT($$@) "\
  61. "$(AX51_FLAGS)" > $(_LOG) 2>&1; test $$$$? -lt 2 || (mv ./Bluejay.LST $(OUTPUT_DIR)/; tail $(_LOG); exit 1)
  62. @mv ./Bluejay.LST $(OUTPUT_DIR)/
  63. endef
  64. HEX_TARGETS = $(OBJS:%.OBJ=$(OUTPUT_DIR_HEX)/%.hex)
  65. EFM8_LOAD_BIN ?= efm8load.py
  66. EFM8_LOAD_PORT ?= /dev/ttyUSB0
  67. EFM8_LOAD_BAUD ?= 57600
  68. SINGLE_TARGET_HEX = $(OUTPUT_DIR_HEX)/$(TARGET)_$(MCU)_$(FETON_DELAY)_$(PWM_FREQUENCY)_$(REVISION).hex
  69. single_target : $(SINGLE_TARGET_HEX)
  70. all : $$(HEX_TARGETS)
  71. @echo "\nbuild finished. built $(shell ls -l $(OUTPUT_DIR_HEX) | wc -l) hex targets\n"
  72. # create all obj targets using macro expansion
  73. $(foreach _t,$(TARGETS), \
  74. $(foreach _m, $(MCUS), \
  75. $(foreach _f, $(FETON_DELAYS), \
  76. $(foreach _p, $(PWM_FREQUENCIES), \
  77. $(eval $(call MAKE_OBJ,$(_t),$(_m),$(_f),$(_p)))))))
  78. $(OUTPUT_DIR)/%.OMF : $(OUTPUT_DIR)/%.OBJ
  79. $(eval LOG := $(LOG_DIR)/$(basename $(notdir $@)).log)
  80. @echo "LX51 : linking $< to $@"
  81. # # Linking should produce exactly 1 warning
  82. @$(LX51) "$<" TO "$@" "$(LX51_FLAGS)" >> $(LOG) 2>&1; test $$? -lt 2 && grep -q "1 WARNING" $(LOG) || (tail $(LOG); exit 1)
  83. $(OUTPUT_DIR_HEX)/%.hex : $(OUTPUT_DIR)/%.OMF
  84. $(eval LOG := $(LOG_DIR)/$(basename $(notdir $@)).log)
  85. @mkdir -p $(OUTPUT_DIR_HEX)
  86. @echo "OHX : generating hex file $@"
  87. @$(OX51) "$<" "HEXFILE ($@)" >> $(LOG) 2>&1; test $$? -lt 2 || (tail $(LOG); exit 1)
  88. help:
  89. @echo ""
  90. @echo "usage examples:"
  91. @echo "================================================================"
  92. @echo "make all # build all targets"
  93. @echo "make TARGET=A MCU=H FETON_DELAY=5 # to build a single target"
  94. @echo
  95. clean:
  96. @rm -f $(OUTPUT_DIR)/*.{OBJ,MAP,OMF,LST}
  97. efm8load: single_target
  98. $(EFM8_LOAD_BIN) -p $(EFM8_LOAD_PORT) -b $(EFM8_LOAD_BAUD) -w $(SINGLE_TARGET_HEX)
  99. .PHONY: all clean help efm8load