Makefile 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. # Project
  2. #-------------------------------------------------------------------------------
  3. TARGET = armpsu
  4. #
  5. #-------------------------------------------------------------------------------
  6. PROGRAMMATOR = "C:/MCU/STMicroelectronics/STM32 ST-LINK Utility/ST-LINK Utility/ST-LINK_CLI.exe"
  7. # Used modules of Stamdart Perephireal Library
  8. #-------------------------------------------------------------------------------
  9. # PERIPHDRIVERS += stm32f10x_adc
  10. # PERIPHDRIVERS += stm32f10x_bkp
  11. # PERIPHDRIVERS += stm32f10x_can
  12. # PERIPHDRIVERS += stm32f10x_cec
  13. # PERIPHDRIVERS += stm32f10x_crc
  14. # PERIPHDRIVERS += stm32f10x_dbgmcu
  15. # PERIPHDRIVERS += stm32f10x_exti
  16. # PERIPHDRIVERS += stm32f10x_flash
  17. # PERIPHDRIVERS += stm32f10x_fsmc
  18. # PERIPHDRIVERS += stm32f10x_gpio
  19. # PERIPHDRIVERS += stm32f10x_i2c
  20. # PERIPHDRIVERS += stm32f10x_iwdg
  21. # PERIPHDRIVERS += stm32f10x_pwr
  22. # PERIPHDRIVERS += stm32f10x_rcc
  23. # PERIPHDRIVERS += stm32f10x_rtc
  24. # PERIPHDRIVERS += stm32f10x_sdio
  25. # PERIPHDRIVERS += stm32f10x_spi
  26. # PERIPHDRIVERS += stm32f10x_tim
  27. # PERIPHDRIVERS += stm32f10x_usart
  28. # PERIPHDRIVERS += stm32f10x_wwdg
  29. # PERIPHDRIVERS += misc.c
  30. # Defines
  31. #-------------------------------------------------------------------------------
  32. #DEFINES += USE_STDPERIPH_DRIVER
  33. DEFINES += STM32F10X_LD_VL
  34. DEFINES += GCC_ARMCM3
  35. DEFINES += VECT_TAB_FLASH
  36. DEFINES += REAL_FLASH
  37. DEFINES += BIG
  38. DEFINES += CLOCK_ENABLED
  39. DEFINES += AWD_ENABLED
  40. # Tools
  41. #-------------------------------------------------------------------------------
  42. GCC_PREFIX = C:/MCU/gcc-arm/bin/arm-none-eabi-
  43. AS = $(GCC_PREFIX)gcc
  44. CC = $(GCC_PREFIX)gcc
  45. LD = $(GCC_PREFIX)gcc
  46. CP = $(GCC_PREFIX)objcopy
  47. SZ = $(GCC_PREFIX)size
  48. RM = rm
  49. # Patches
  50. #-------------------------------------------------------------------------------
  51. CMSIS_PATH = lib/CMSIS/CM3
  52. #STDPERIPH_INC_PATH = mcu/stdperiph/inc
  53. #STDPERIPH_SRC_PATH = mcu/stdperiph/src
  54. # Startup file
  55. #-------------------------------------------------------------------------------
  56. STARTUP = $(CMSIS_PATH)/DeviceSupport/ST/STM32F10x/startup/gcc_ride7/startup_stm32f10x_ld_vl.s
  57. # Sources search paths
  58. #-------------------------------------------------------------------------------
  59. SOURCEDIRS := src
  60. SOURCEDIRS += $(CMSIS_PATH)/CoreSupport
  61. #SOURCEDIRS += $(CMSIS_PATH)/DeviceSupport/ST/STM32F10x
  62. # Headers search paths
  63. #-------------------------------------------------------------------------------
  64. INCLUDES += inc
  65. #INCLUDES += $(SOURCEDIRS)
  66. INCLUDES += $(CMSIS_PATH)/CoreSupport
  67. INCLUDES += $(CMSIS_PATH)/DeviceSupport/ST/STM32F10x
  68. #INCLUDES += $(STDPERIPH_INC_PATH)
  69. # Libraries
  70. #-------------------------------------------------------------------------------
  71. LIBPATH +=
  72. LIBS +=
  73. # Compiler settings
  74. #-------------------------------------------------------------------------------
  75. CFLAGS += -mthumb -mcpu=cortex-m3 # Architecture and command system
  76. CFLAGS += -std=gnu11 # C language standart
  77. CFLAGS += -Wall -pedantic # Show all warnings
  78. CFLAGS += -Os # Optimization
  79. CFLAGS += -ggdb # Generate debugging info for gdb
  80. #CFLAGS += -fno-builtin
  81. CFLAGS += $(addprefix -I, $(INCLUDES))
  82. CFLAGS += $(addprefix -D, $(DEFINES))
  83. CFLAGS += -c
  84. CFLAGS += -fmessage-length=0
  85. CFLAGS += -ffunction-sections
  86. #CFLAGS += -fdata-sections
  87. #CFLAGS += -msoft-float
  88. CFLAGS += -mapcs-frame
  89. CFLAGS += -D__thumb2__=1
  90. CFLAGS += -mno-sched-prolog
  91. #CFLAGS += -fno-hosted
  92. CFLAGS += -mtune=cortex-m3
  93. CFLAGS += -mfix-cortex-m3-ldrd
  94. #CFLAGS += -fno-strict-aliasing
  95. CFLAGS += -ffast-math
  96. CFLAGS += -MD -MP -MF .dep/$(@F).d
  97. # Linker script
  98. #-------------------------------------------------------------------------------
  99. LDSCR_PATH = ld
  100. LDSCRIPT = stm32f100c6_sec.ld
  101. # Linker settings
  102. #-------------------------------------------------------------------------------
  103. LDFLAGS += -nostartfiles
  104. LDFLAGS += -L$(LDSCR_PATH)
  105. LDFLAGS += -T$(LDSCR_PATH)/$(LDSCRIPT)
  106. LDFLAGS += $(addprefix -L, $(LIBPATH))
  107. LDFLAGS += $(LIBS)
  108. LDFLAGS += -Xlinker -Map=$(TARGET).map
  109. LDFLAGS += -Wl,--gc-sections
  110. LDFLAGS += -mcpu=cortex-m3
  111. LDFLAGS += -mthumb
  112. #LDFLAGS += -static
  113. #LDFLAGS += -nostdlib
  114. # Assembler settings
  115. #-------------------------------------------------------------------------------
  116. AFLAGS += -ahls -mapcs-32
  117. AFLAGS = -D__ASSEMBLY__
  118. AFLAGS += -g $(CFLAGS)
  119. AFLAGS += -Iinc -x assembler-with-cpp
  120. # Object files list
  121. #-------------------------------------------------------------------------------
  122. OBJS += $(patsubst %.c, %.o, $(wildcard $(addsuffix /*.c, $(SOURCEDIRS))))
  123. #OBJS += $(addprefix $(STDPERIPH_SRC_PATH)/, $(addsuffix .o, $(PERIPHDRIVERS)))
  124. OBJS += $(patsubst %.s, %.o, $(STARTUP))
  125. # Search paths for make
  126. #-------------------------------------------------------------------------------
  127. VPATH := $(SOURCEDIRS)
  128. # List of files to remove with "make clean"
  129. #-------------------------------------------------------------------------------
  130. TOREMOVE += $(TARGET).elf $(TARGET).hex $(TARGET).map
  131. TOREMOVE += $(addsuffix /*.o, $(SOURCEDIRS))
  132. TOREMOVE += .dep/*.d
  133. #TOREMOVE += $(STDPERIPH_SRC_PATH)/*.o
  134. TOREMOVE += $(patsubst %.s, %.o, $(STARTUP))
  135. # Make all
  136. #-------------------------------------------------------------------------------
  137. all: $(TARGET).hex size
  138. load: $(TARGET).hex mcu_prog
  139. # Download firmware
  140. #-------------------------------------------------------------------------------
  141. mcu_prog:
  142. @$(PROGRAMMATOR) -c SWD -ME
  143. @$(PROGRAMMATOR) -c SWD -P "$(TARGET).hex" -V "$(TARGET).hex" -Q -Rst -Run
  144. mcu_reset:
  145. @$(PROGRAMMATOR) -c SWD -Rst -Run
  146. # Cleaning
  147. #-------------------------------------------------------------------------------
  148. clean:
  149. @$(RM) -f $(TOREMOVE)
  150. # Create .hex
  151. #-------------------------------------------------------------------------------
  152. $(TARGET).hex: $(TARGET).elf
  153. @$(CP) -Oihex $(TARGET).elf $(TARGET).hex
  154. # Show Size
  155. #-------------------------------------------------------------------------------
  156. size:
  157. @echo "---------------------------------------------------"
  158. @$(SZ) $(TARGET).elf
  159. @rm -f $(STDPERIPH_SRC_PATH)/*.o
  160. # Linking
  161. #-------------------------------------------------------------------------------
  162. $(TARGET).elf: $(OBJS)
  163. @$(LD) $(LDFLAGS) $^ -o $@
  164. # Compiling
  165. #-------------------------------------------------------------------------------
  166. %.o: %.c
  167. @echo Compiling: $<
  168. @$(CC) $(CFLAGS) -MD -c $< -o $@
  169. %.o: %.s
  170. @echo Compiling: $<
  171. @$(AS) $(AFLAGS) -c $< -o $@
  172. # Include the dependency files, should be the last of the makefile
  173. #-------------------------------------------------------------------------------
  174. -include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)