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.

127 lines
4.1 KiB

  1. # set current revision
  2. REVISION ?= REV16_6
  3. # targets
  4. TARGETS = A B C D E F G H I J K L M N O P Q R S
  5. MCUS = H L
  6. FETON_DELAYS = 0 5 10 15 20 25 30 40 50 70 90
  7. # example single target
  8. VARIANT ?= A
  9. MCU ?= H
  10. FETON_DELAY ?= 5
  11. # configure the script to use the wine installation delivered with
  12. # SimplicityStudio. these wine settings are quite important. if you get
  13. # ERROR L250: CODE SIZE LIMIT IN RESTRICTED VERSION EXCEEDED
  14. # you messed up your simplicity studio install/path settins below:
  15. SIMPLICITY_PATH ?= ~/local/SimplicityStudio_v4/
  16. WINE_PREFIX ?= ~/.config/SimplicityStudio/v4/studio-wine
  17. WINE_BIN ?= $(SIMPLICITY_PATH)/support/common/wine/usr/bin/wine
  18. WINE = export WINEPREFIX=`realpath $(WINE_PREFIX)`; $(WINE_BIN)
  19. # path to the keil binaries
  20. KEIL_PATH = $(SIMPLICITY_PATH)/developer/toolchains/keil_8051/9.53/BIN
  21. # some directory config
  22. OUTPUT_DIR ?= build
  23. OUTPUT_DIR_HEX ?= $(OUTPUT_DIR)/hex
  24. LOG_DIR ?= $(OUTPUT_DIR)/log
  25. # define the assembler/linker scripts
  26. AX51_BIN = $(KEIL_PATH)/AX51.exe
  27. LX51_BIN = $(KEIL_PATH)/LX51.exe
  28. OX51_BIN = $(KEIL_PATH)/Ohx51.exe
  29. AX51 = $(WINE) $(AX51_BIN)
  30. LX51 = $(WINE) $(LX51_BIN)
  31. OX51 = $(WINE) $(OX51_BIN)
  32. # set up flags
  33. AX51_FLAGS = DEBUG MACRO NOMOD51 COND SYMBOLS PAGEWIDTH(120) PAGELENGTH(65)
  34. LX51_FLAGS = PAGEWIDTH (120) PAGELENGTH (65)
  35. # set up sources
  36. ASM_SRC = BLHeli_S.asm
  37. ASM_INC = $(TARGETS:=.inc) BLHeliBootLoad.inc BLHeliPgm.inc SI_EFM8BB1_Defs.inc SI_EFM8BB2_Defs.inc
  38. # check that wine/simplicity studio is available
  39. EXECUTABLES = $(WINE_BIN) $(AX51_BIN) $(LX51_BIN) $(OX51_BIN)
  40. DUMMYVAR := $(foreach exec, $(EXECUTABLES), \
  41. $(if $(wildcard $(exec)),found, \
  42. $(error "Could not find $(exec). Make sure to set the correct paths to the simplicity install location")))
  43. # make sure the list of obj files is expanded twice
  44. .SECONDEXPANSION:
  45. OBJS =
  46. define MAKE_OBJ
  47. OBJS += $(OUTPUT_DIR)/$(1)_$(2)_$(3)_$(REVISION).OBJ
  48. $(OUTPUT_DIR)/$(1)_$(2)_$(3)_$(REVISION).OBJ : $(ASM_SRC) $(ASM_INC)
  49. $(eval _ESC := $(1))
  50. $(eval _ESC_INT := $(shell printf "%d" "'${_ESC}"))
  51. $(eval _ESCNO := $(shell echo $$(( $(_ESC_INT) - 65 + 1))))
  52. $(eval _MCU_48MHZ := $(subst L,0,$(subst H,1,$(2))))
  53. $(eval _FETON_DELAY := $(3))
  54. $(eval _LOG := $(LOG_DIR)/$(1)_$(2)_$(3)_$(REVISION).log)
  55. @mkdir -p $(OUTPUT_DIR)
  56. @mkdir -p $(LOG_DIR)
  57. @echo "AX51 : $$@"
  58. @$(AX51) $(ASM_SRC) \
  59. "DEFINE(ESCNO=$(_ESCNO)) " \
  60. "DEFINE(MCU_48MHZ=$(_MCU_48MHZ)) "\
  61. "DEFINE(FETON_DELAY=$(_FETON_DELAY)) "\
  62. "OBJECT($$@) "\
  63. "$(AX51_FLAGS)" >> $(_LOG) 2>&1; test $$$$? -lt 2 || tail $(_LOG)
  64. endef
  65. HEX_TARGETS = $(OBJS:.OBJ=.HEX)
  66. EFM8_LOAD_BIN ?= efm8load.py
  67. EFM8_LOAD_PORT ?= /dev/ttyUSB0
  68. EFM8_LOAD_BAUD ?= 57600
  69. SINGLE_TARGET_HEX = $(OUTPUT_DIR)/$(VARIANT)_$(MCU)_$(FETON_DELAY)_$(REVISION).HEX
  70. single_target : $(SINGLE_TARGET_HEX)
  71. all : $$(HEX_TARGETS)
  72. @echo "\nbuild finished. built $(shell ls -l $(OUTPUT_DIR_HEX) | wc -l) hex targets\n"
  73. # create all obj targets using macro expansion
  74. $(foreach _e,$(TARGETS), \
  75. $(foreach _m, $(MCUS), \
  76. $(foreach _f, $(FETON_DELAYS), \
  77. $(eval $(call MAKE_OBJ,$(_e),$(_m),$(_f))))))
  78. $(OUTPUT_DIR)/%.OMF : $(OUTPUT_DIR)/%.OBJ
  79. $(eval LOG := $(LOG_DIR)/$(basename $(notdir $@)).log)
  80. @echo "LX51 : linking $< to $@"
  81. @$(LX51) "$<" TO "$@" "$(LX51_FLAGS)" >> $(LOG) 2>&1; test $$? -lt 2 || tail $(LOG)
  82. $(OUTPUT_DIR)/%.HEX : $(OUTPUT_DIR)/%.OMF
  83. $(eval LOG := $(LOG_DIR)/$(basename $(notdir $@)).log)
  84. @mkdir -p $(OUTPUT_DIR_HEX)
  85. @echo "OHX : generating hex file $@"
  86. @$(OX51) "$<" "HEXFILE ($@)" "H386" >> $(LOG) 2>&1; test $$? -lt 2 || tail $(LOG)
  87. @cp $@ $(OUTPUT_DIR_HEX)/$(notdir $@)
  88. help:
  89. @echo ""
  90. @echo "usage examples:"
  91. @echo "================================================================="
  92. @echo "make all # build all targets"
  93. @echo "make VARIANT=A MCU=H FETON_DELAY=5 # to build a single target"
  94. @echo
  95. clean:
  96. @rm -rf $(LOG_DIR)/*
  97. @rm -rf $(OUTPUT_DIR)/*
  98. efm8load: single_target
  99. $(EFM8_LOAD_BIN) -p $(EFM8_LOAD_PORT) -b $(EFM8_LOAD_BAUD) -w $(SINGLE_TARGET_HEX)
  100. .PHONY: all clean help efm8load