Makefile 4.7 KB

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