Makefile 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. ##########################
  2. # IAR Makefile for STM8S #
  3. ##########################
  4. PROJECT=VAXL
  5. # Location of build tools and atomthreads sources
  6. EWSTM8_DIR=C:\IAR\Embedded Workbench 8.3\stm8
  7. EWSTM8_BIN=C:/IAR/Embedded\ Workbench\ 8.3/stm8/bin
  8. CC=$(EWSTM8_BIN)/iccstm8
  9. ASM=$(EWSTM8_BIN)/iasmstm8
  10. LINK=$(EWSTM8_BIN)/ilinkstm8
  11. HEX=$(EWSTM8_BIN)/ielftool
  12. FLASHTOOL=C:/MCU/STMicroelectronics/st_toolset/stvp/STVP_CmdLine.exe
  13. FLASHOPT=-no_log -no_loop -Device=STM8S003F3
  14. DEFINES = -D USE_STDPERIPH_DRIVER
  15. DEFINES += -D STM8S003
  16. # Sources paths
  17. APP_SRC = src
  18. LIB_SRC = lib
  19. vpath %.c $(APP_SRC)
  20. vpath %.c $(LIB_SRC)
  21. vpath %.c StdPerphDrv/src
  22. # Include paths
  23. INCLUDES = -I inc
  24. INCLUDES += -I lib
  25. INCLUDES += -I StdPerphDrv/inc
  26. # CPU part number
  27. PART=stm8s003f3
  28. ICF=lnkstm8s003f3.icf
  29. LIB_MODEL = dlstm8ssn.h
  30. # Directory for built objects
  31. OUT_DIR = build
  32. OBJ_DIR = $(OUT_DIR)/Obj
  33. LIST_DIR = $(OUT_DIR)/List
  34. # Models
  35. CODE_MODEL = small
  36. DATA_MODEL = small
  37. # Application object files
  38. APP_OBJECTS = $(notdir $(patsubst %.c,%.o,$(wildcard $(APP_SRC)/*.c)))
  39. # Libraries object files
  40. LIB_OBJECTS = $(notdir $(patsubst %.c,%.o,$(wildcard $(LIB_SRC)/*.c)))
  41. # STM8S Peripheral driver object files
  42. PERIPH_OBJECTS = stm8s_adc1.o
  43. #PERIPH_OBJECTS += stm8s_awu.o
  44. #PERIPH_OBJECTS += stm8s_beep.o
  45. PERIPH_OBJECTS += stm8s_clk.o
  46. PERIPH_OBJECTS += stm8s_exti.o
  47. #PERIPH_OBJECTS += stm8s_flash.o
  48. PERIPH_OBJECTS += stm8s_gpio.o
  49. PERIPH_OBJECTS += stm8s_i2c.o
  50. PERIPH_OBJECTS += stm8s_itc.o
  51. #PERIPH_OBJECTS += stm8s_iwdg.o
  52. #PERIPH_OBJECTS += stm8s_rst.o
  53. #PERIPH_OBJECTS += stm8s_spi.o
  54. PERIPH_OBJECTS += stm8s_tim1.o
  55. #PERIPH_OBJECTS += stm8s_tim2.o
  56. PERIPH_OBJECTS += stm8s_tim4.o
  57. #PERIPH_OBJECTS += stm8s_uart1.o
  58. #PERIPH_OBJECTS += stm8s_wwdg.o
  59. # Collection of built objects (excluding test applications)
  60. ALL_OBJECTS = $(APP_OBJECTS) $(LIB_OBJECTS) $(PERIPH_OBJECTS)
  61. BUILT_OBJECTS = $(patsubst %,$(OUT_DIR)/%,$(ALL_OBJECTS))
  62. # Target application filenames (.elf) for object
  63. PROJ_ELFS = $(PROJECT).elf
  64. PROJ_S19S = $(PROJECT).s19
  65. PROJ_IHEX = $(PROJECT).hex
  66. # Search build/output directory for dependencies
  67. vpath %.o .\$(OBJ_DIR)
  68. vpath %.elf .\$(OUT_DIR)
  69. vpath %.hex .\$(OUT_DIR)
  70. # Compiler/Assembler flags
  71. CFLAGS = -e -Om $(DEFINES) -D NDEBUG
  72. CFLAGS += --code_model $(CODE_MODEL) --data_model $(DATA_MODEL)
  73. CFLAGS += --dlib_config "$(EWSTM8_DIR)\lib\$(LIB_MODEL)"
  74. CFLAGS += -lCN $(LIST_DIR) -lBN $(LIST_DIR)
  75. CFLAGS += --diag_suppress Pa050 --guard_calls
  76. # --silent
  77. DBG_CFLAGS = -e -Ol $(DEFINES) --no_cse --no_unroll --no_inline --no_code_motion --no_tbaa
  78. DBG_CFLAGS += --no_cross_call --debug --code_model $(CODE_MODEL) --data_model $(DATA_MODEL)
  79. DBG_CFLAGS += --dlib_config "$(EWSTM8_DIR)\lib\$(LIB_MODEL)"
  80. DBG_CFLAGS += -lC $(LIST_DIR) -lB $(LIST_DIR)
  81. DBG_CFLAGS += --diag_suppress Pa050
  82. ASMFLAGS = -M'<>' -ld $(OUT_DIR)\list --diag_suppress Pa050
  83. ASMFLAGS += --code_model $(CODE_MODEL) --data_model $(DATA_MODEL)
  84. DBG_ASMFLAGS = -M'<>' -r -ld $(OUT_DIR)\list --diag_suppress Pa050
  85. DBG_ASMFLAGS += --code_model $(CODE_MODEL) --data_model $(DATA_MODEL)
  86. LINKFLAGS = --redirect _Printf=_PrintfTinyNoMb
  87. LINKFLAGS += --redirect _Scanf=_ScanfSmallNoMb
  88. LINKFLAGS += --config "$(EWSTM8_DIR)\config\lnk$(PART).icf"
  89. LINKFLAGS += --config_def _CSTACK_SIZE=0x100
  90. LINKFLAGS += --config_def _HEAP_SIZE=0x100
  91. LINKFLAGS += --map $(OUT_DIR)
  92. LINKFLAGS += --entry __iar_program_start
  93. LINKFLAGS += --merge_duplicate_sections
  94. LINKFLAGS += --strip
  95. LINKFLAGS += -f "$(EWSTM8_DIR)\config\math_small.xcl"
  96. DBG_LINKFLAGS = --redirect _Printf=_PrintfTinyNoMb --redirect _Scanf=_ScanfSmallNoMb
  97. DBG_LINKFLAGS += --config "$(EWSTM8_DIR)\config\$(ICF)" --config_def
  98. DBG_LINKFLAGS += _CSTACK_SIZE=0x100 --config_def _HEAP_SIZE=0x100
  99. DBG_LINKFLAGS += --entry __iar_program_start
  100. #################
  101. # Build targets #
  102. #################
  103. # All tests
  104. all: $(OUT_DIR) $(PROJ_S19S) $(PROJ_IHEX)
  105. Release: all
  106. flash: all
  107. cleanRelease: clean
  108. # Make build/output directory
  109. $(OUT_DIR):
  110. @mkdir $(OUT_DIR)
  111. @mkdir $(OBJ_DIR)
  112. @mkdir $(LIST_DIR)
  113. # Test HEX files (one application build for each test)
  114. $(PROJ_S19S): %.s19: $(PROJECT).elf
  115. @echo
  116. @echo Building $@
  117. @$(HEX) $(OUT_DIR)/$(notdir $<) $(OUT_DIR)/$@ --srec --silent
  118. $(PROJ_IHEX): %.hex: $(PROJECT).elf
  119. @echo Building $@
  120. @$(HEX) $(OUT_DIR)/$(notdir $<) $(OUT_DIR)/$@ --ihex --silent
  121. # Test ELF files (one application build for each test)
  122. $(PROJ_ELFS): %.elf: $(PERIPH_OBJECTS) $(LIB_OBJECTS) $(APP_OBJECTS)
  123. @echo
  124. @echo Linking $@
  125. @$(LINK) $(OBJ_DIR)/*.o $(LINKFLAGS) -o $(OUT_DIR)/$@
  126. # All C objects builder
  127. $(ALL_OBJECTS): %.o: %.c
  128. @echo
  129. @echo Compiling $@
  130. @$(CC) $< $(CFLAGS) $(INCLUDES) -o $(OBJ_DIR)
  131. # Clean
  132. clean:
  133. rm -f *.o *.elf *.map *.hex *.bin *.lst *.stm8 *.s19 *.out *.s *.lst
  134. rm -rf $(LIST_DIR)
  135. rm -rf $(OBJ_DIR)
  136. rm -rf $(OUT_DIR)
  137. # Flash
  138. flash:
  139. @$(FLASHTOOL) $(FLASHOPT) -FileProg=$(OUT_DIR)\\$(PROJ_IHEX)