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.

132 lines
4.1 KiB

  1. # Current version
  2. VERSION ?= v0.9
  3. # Target parameters
  4. LAYOUTS = 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. DEADTIMES = 0 5 10 15 20 25 30 40 50 70 90
  7. PWM_FREQS = 24 48 96
  8. # Example single target
  9. LAYOUT ?= A
  10. MCU ?= H
  11. DEADTIME ?= 5
  12. PWM ?= 24
  13. # Directory configuration
  14. OUTPUT_DIR ?= build
  15. HEX_DIR ?= $(OUTPUT_DIR)/hex
  16. LOG_DIR ?= $(OUTPUT_DIR)/logs
  17. # Path to the keil binaries
  18. KEIL_PATH ?= ~/Downloads/keil_8051/9.60/BIN
  19. WINE_BIN ?= /usr/local/bin/wine
  20. # Assembler and linker binaries
  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 NOSYMBOLS
  30. LX51_FLAGS =
  31. # Source files
  32. ASM_SRC = Bluejay.asm
  33. ASM_INC = $(LAYOUTS:%=targets/%.inc) Common.inc BLHeliBootLoad.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. # Set up efm8load
  40. EFM8_LOAD_BIN ?= efm8load.py
  41. EFM8_LOAD_PORT ?= /dev/ttyUSB0
  42. EFM8_LOAD_BAUD ?= 57600
  43. # Delete object files on error and warnings
  44. .DELETE_ON_ERROR:
  45. # AX51 mixes up input defines when run in parallel. Maybe because you cannot change the TMP directory per invocation.
  46. .NOTPARALLEL:
  47. define MAKE_OBJ
  48. OBJS += $(1)_$(2)_$(3)_$(4)_$(VERSION).OBJ
  49. $(OUTPUT_DIR)/$(1)_$(2)_$(3)_$(4)_$(VERSION).OBJ : $(ASM_SRC) $(ASM_INC)
  50. $(eval _ESC := $(1))
  51. $(eval _ESC_INT := $(shell printf "%d" "'${_ESC}"))
  52. $(eval _ESCNO := $(shell echo $$(( $(_ESC_INT) - 65 + 1))))
  53. $(eval _MCU_48MHZ := $(subst L,0,$(subst H,1,$(2))))
  54. $(eval _DEADTIME := $(3))
  55. $(eval _PWM_FREQ := $(subst 24,0,$(subst 48,1,$(subst 96,2,$(4)))))
  56. $(eval _LOG := $(LOG_DIR)/$(1)_$(2)_$(3)_$(4)_$(VERSION).log)
  57. $$(eval _LST := $$(patsubst %.OBJ,%.LST,$$@))
  58. @mkdir -p $(OUTPUT_DIR)
  59. @mkdir -p $(LOG_DIR)
  60. @echo "AX51 : $$@"
  61. @$(AX51) $(ASM_SRC) \
  62. "DEFINE(ESCNO=$(_ESCNO)) " \
  63. "DEFINE(MCU_48MHZ=$(_MCU_48MHZ)) "\
  64. "DEFINE(FETON_DELAY=$(_DEADTIME)) "\
  65. "DEFINE(PWM_FREQ=$(_PWM_FREQ)) "\
  66. "OBJECT($$@) "\
  67. "PRINT($$(_LST)) "\
  68. "$(AX51_FLAGS)" > $(_LOG) 2>&1 || (grep -B 3 -E "\*\*\* (ERROR|WARNING)" $$(_LST); exit 1)
  69. endef
  70. SINGLE_TARGET_HEX = $(HEX_DIR)/$(LAYOUT)_$(MCU)_$(DEADTIME)_$(PWM)_$(VERSION).hex
  71. single_target : $(SINGLE_TARGET_HEX)
  72. # Create all obj targets using macro expansion
  73. $(foreach _t,$(LAYOUTS), \
  74. $(foreach _m, $(MCUS), \
  75. $(foreach _f, $(DEADTIMES), \
  76. $(foreach _p, $(filter-out $(subst L,96,$(_m)), $(PWM_FREQS)), \
  77. $(eval $(call MAKE_OBJ,$(_t),$(_m),$(_f),$(_p)))))))
  78. HEX_TARGETS = $(OBJS:%.OBJ=$(HEX_DIR)/%.hex)
  79. all : $(HEX_TARGETS)
  80. @echo "\nbuild finished. built $(shell ls -Aq $(HEX_DIR) | wc -l) hex targets\n"
  81. $(OUTPUT_DIR)/%.OMF : $(OUTPUT_DIR)/%.OBJ
  82. $(eval LOG := $(LOG_DIR)/$(basename $(notdir $@)).log)
  83. @echo "LX51 : linking $< to $@"
  84. # Linking should produce exactly 1 warning
  85. @$(LX51) "$<" TO "$@" "$(LX51_FLAGS)" >> $(LOG) 2>&1; test $$? -lt 2 && grep -q "1 WARNING" $(LOG) || (tail $(LOG); exit 1)
  86. $(HEX_DIR)/%.hex : $(OUTPUT_DIR)/%.OMF
  87. $(eval LOG := $(LOG_DIR)/$(basename $(notdir $@)).log)
  88. @mkdir -p $(HEX_DIR)
  89. @echo "OHX : generating hex file $@"
  90. @$(OX51) "$<" "HEXFILE ($@)" >> $(LOG) 2>&1 || (tail $(LOG); exit 1)
  91. changelog:
  92. @npx -q commitlint --config .github/workflows/commitlint.config.js --from v0.1.0
  93. @npx -q mathiasvr/generate-changelog --exclude build,chore,ci,docs,refactor,style,other
  94. help:
  95. @echo ""
  96. @echo "Usage examples"
  97. @echo "================================================================"
  98. @echo "make all # Build all targets"
  99. @echo "make LAYOUT=A MCU=H DEADTIME=5 PWM=24 # Build a single target"
  100. @echo
  101. clean:
  102. @rm -f $(OUTPUT_DIR)/*.{OBJ,MAP,OMF,LST}
  103. @rm -f $(LOG_DIR)/*.log
  104. efm8load: single_target
  105. $(EFM8_LOAD_BIN) -p $(EFM8_LOAD_PORT) -b $(EFM8_LOAD_BAUD) -w $(SINGLE_TARGET_HEX)
  106. .PHONY: single_target all changelog help clean efm8load