1
0

Makefile 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. CMSIS ?= CMSIS
  2. CMSISDEV ?= $(CMSIS)/Device
  3. CMSISCORE ?= $(CMSIS)/CMSIS/Include $(CMSIS)/CMSIS/Core/Include
  4. FLASH ?= st-flash
  5. TOOLSET ?= arm-none-eabi-
  6. CC = $(TOOLSET)gcc
  7. LD = $(TOOLSET)gcc
  8. AR = $(TOOLSET)gcc-ar
  9. OBJCOPY = $(TOOLSET)objcopy
  10. DFU_UTIL ?= dfu-util
  11. STPROG_CLI ?= ~/STMicroelectronics/STM32Cube/STM32CubeProgrammer/bin/STM32_Programmer_CLI
  12. OPTFLAGS ?= -Os
  13. ifeq ($(OS),Windows_NT)
  14. RM = del /Q
  15. fixpath = $(strip $(subst /,\, $1))
  16. else
  17. RM = rm -f
  18. fixpath = $(strip $1)
  19. endif
  20. MODULE ?= libusb.a
  21. CFLAGS ?= -mcpu=cortex-m3
  22. DEFINES ?= STM32F1 STM32F103x6
  23. ARFLAGS = -cvq
  24. LDFLAGS = --specs=nano.specs -nostartfiles -Wl,--gc-sections -L demo
  25. INCLUDES = $(CMSISDEV)/ST $(CMSISCORE) inc
  26. CFLAGS2 ?= $(CFLAGS) -mthumb -std=gnu99 $(OPTFLAGS)
  27. OBJDIR = obj
  28. SOURCES = $(wildcard src/*.c) $(wildcard src/*.S)
  29. OBJECTS = $(addprefix $(OBJDIR)/, $(addsuffix .o, $(notdir $(basename $(SOURCES)))))
  30. DSRC = $(wildcard demo/*.c) $(wildcard demo/*.S) $(STARTUP)
  31. DOBJ = $(addprefix $(OBJDIR)/, $(addsuffix .o, $(notdir $(basename $(DSRC)))))
  32. DOUT = cdc_loop
  33. SRCPATH = $(sort $(dir $(SOURCES) $(DSRC)))
  34. vpath %.c $(SRCPATH)
  35. vpath %.S $(SRCPATH)
  36. vpath %.s $(SRCPATH)
  37. help all:
  38. @echo 'Usage: make target [program]'
  39. @echo 'Available targets are:'
  40. @echo ' bluepill'
  41. @echo ' stm32f103x6 CDC loopback demo for STM32F103 based boards'
  42. @echo ' 32l100c-disco'
  43. @echo ' stm32l100xc CDC loopback demo for STM32L100xC based boards'
  44. @echo ' 32l476rg-nucleo'
  45. @echo ' stm32l476rg CDC loopback demo for STM32L476xG based boards'
  46. @echo ' stm32l052x8 CDC loopback demo for STM32L052x8 based boards'
  47. @echo ' 32f429zi-nucleo'
  48. @echo ' stm32f429xi CDC loopback demo for STM32F429xI based boards'
  49. @echo ' stm32f401xc CDC loopback demo for STM32F401xC based boards'
  50. @echo ' stm32f401xe CDC loopback demo for STM32F401xE based boards'
  51. @echo ' cmsis Download CMSIS 5 and stm32.h into a $$(CMSIS) directory'
  52. @echo ' doc DOXYGEN documentation'
  53. @echo ' module static library module using following envars (defaults)'
  54. @echo ' MODULE module name ($(MODULE))'
  55. @echo ' CFLAGS mcu specified compiler flags ($(CFLAGS))'
  56. @echo ' DEFINES mcu and module specified defines ($(DEFINES))'
  57. @echo ' see USB Device HW driver and core API section for the'
  58. @echo ' compile-time control macros'
  59. @echo ' '
  60. @echo 'Environmental variables (defaults):'
  61. @echo ' CMSIS Path to the CMSIS V4 or CMSIS V5 root folder ($(CMSIS))'
  62. @echo ' CMSISCORE Path to the CMSIS Core include folder(s) ($(CMSISCORE))'
  63. @echo ' CMSISDEV Path to the CMSIS Device folder ($(CMSISDEV))'
  64. @echo ' FLASH st-link flash utility ($(FLASH))'
  65. @echo ' '
  66. @echo 'Examples:'
  67. @echo ' make bluepill program'
  68. @echo ' make module MODULE="usbd.a" CFLAGS="-mcpu=cortex-m4" DEFINES="STM32L4 STM32L476xx USBD_VBUS_DETECT"'
  69. cmsis: $(CMSISDEV)/ST
  70. $(CMSISDEV)/ST: $(CMSIS)
  71. @git clone --recurse-submodules --depth 1 https://github.com/dmitrystu/stm32h.git $@
  72. $(CMSIS):
  73. @git clone --depth 1 https://github.com/ARM-software/CMSIS_5.git $@
  74. $(OBJDIR):
  75. @mkdir $@
  76. program: $(DOUT).hex
  77. $(FLASH) --reset --format ihex write $(DOUT).hex
  78. program_dfu: $(DOUT).bin
  79. $(DFU_UTIL) -d 0483:DF11 -a 0 -D $(DOUT).bin -s 0x08000000
  80. program_stcube: $(DOUT).hex
  81. $(STPROG_CLI) -c port=SWD reset=HWrst -d $(DOUT).hex -hardRst
  82. demo: $(DOUT).hex $(DOUT).bin
  83. $(DOUT).bin : $(DOUT).elf
  84. @echo building $@
  85. @$(OBJCOPY) -O binary $< $@
  86. $(DOUT).hex : $(DOUT).elf
  87. @echo building $@
  88. @$(OBJCOPY) -O ihex $< $@
  89. $(DOUT).elf : $(OBJDIR) $(DOBJ) $(OBJECTS)
  90. @echo building $@
  91. @$(LD) $(CFLAGS2) $(LDFLAGS) -Wl,--script='$(LDSCRIPT)' -Wl,-Map=$(DOUT).map $(DOBJ) $(OBJECTS) -o $@
  92. clean: $(OBJDIR)
  93. @$(RM) $(DOUT).*
  94. @$(RM) $(call fixpath, $(OBJDIR)/*.*)
  95. doc:
  96. doxygen
  97. module: clean
  98. $(MAKE) $(MODULE)
  99. $(MODULE): $(OBJDIR) $(OBJECTS)
  100. @$(AR) $(ARFLAGS) $(MODULE) $(OBJECTS)
  101. $(OBJDIR)/%.o: %.c
  102. @echo compiling $<
  103. @$(CC) $(CFLAGS2) $(addprefix -D, $(DEFINES)) $(addprefix -I, $(INCLUDES)) -c $< -o $@
  104. $(OBJDIR)/%.o: %.S
  105. @echo assembling $<
  106. @$(CC) $(CFLAGS2) $(addprefix -D, $(DEFINES)) $(addprefix -I, $(INCLUDES)) -c $< -o $@
  107. $(OBJDIR)/%.o: %.s
  108. @echo assembling $<
  109. @$(CC) $(CFLAGS2) $(addprefix -D, $(DEFINES)) $(addprefix -I, $(INCLUDES)) -c $< -o $@
  110. .PHONY: module doc demo clean program help all program_stcube cmsis
  111. stm32f103x6 bluepill: clean
  112. @$(MAKE) demo STARTUP='$(CMSISDEV)/ST/STM32F1xx/Source/Templates/gcc/startup_stm32f103x6.s' \
  113. LDSCRIPT='demo/stm32f103x6.ld' \
  114. DEFINES='STM32F1 STM32F103x6 USBD_SOF_DISABLED' \
  115. CFLAGS='-mcpu=cortex-m3'
  116. stm32f303xe 32f303re-nucleo: clean
  117. @$(MAKE) demo STARTUP='$(CMSISDEV)/ST/STM32F3xx/Source/Templates/gcc/startup_stm32f303xe.s' \
  118. LDSCRIPT='demo/stm32f303xe.ld' \
  119. DEFINES='STM32F3 STM32F303xE USBD_SOF_DISABLED' \
  120. CFLAGS='-mcpu=cortex-m4'
  121. stm32f303xc: clean
  122. @$(MAKE) demo STARTUP='$(CMSISDEV)/ST/STM32F3xx/Source/Templates/gcc/startup_stm32f303xc.s' \
  123. LDSCRIPT='demo/stm32f303xc.ld' \
  124. DEFINES='STM32F3 STM32F303xC USBD_SOF_DISABLED' \
  125. CFLAGS='-mcpu=cortex-m4'
  126. stm32f105xb: clean
  127. @$(MAKE) demo STARTUP='$(CMSISDEV)/ST/STM32F1xx/Source/Templates/gcc/startup_stm32f105xc.s' \
  128. LDSCRIPT='demo/stm32f105xb.ld' \
  129. DEFINES='STM32F1 STM32F105xC USBD_VBUS_DETECT USBD_SOF_DISABLED' \
  130. CFLAGS='-mcpu=cortex-m3 -Wp,-w'
  131. stm32f107xb: clean
  132. @$(MAKE) demo STARTUP='$(CMSISDEV)/ST/STM32F1xx/Source/Templates/gcc/startup_stm32f107xc.s' \
  133. LDSCRIPT='demo/stm32f105xb.ld' \
  134. DEFINES='STM32F1 STM32F107xC HSE_25MHZ USBD_VBUS_DETECT USBD_SOF_DISABLED' \
  135. CFLAGS='-mcpu=cortex-m3 -Wp,-w'
  136. stm32l052x8: clean
  137. @$(MAKE) demo STARTUP='$(CMSISDEV)/ST/STM32L0xx/Source/Templates/gcc/startup_stm32l052xx.s' \
  138. LDSCRIPT='demo/stm32l052x8.ld' \
  139. DEFINES='STM32L0 STM32L052xx USBD_SOF_DISABLED' \
  140. CFLAGS='-mcpu=cortex-m0plus'
  141. stm32l100xc 32l100c-disco: clean
  142. @$(MAKE) demo STARTUP='$(CMSISDEV)/ST/STM32L1xx/Source/Templates/gcc/startup_stm32l100xc.s' \
  143. LDSCRIPT='demo/stm32l100xc.ld' \
  144. DEFINES='STM32L1 STM32L100xC USBD_SOF_DISABLED' \
  145. CFLAGS='-mcpu=cortex-m3'
  146. stm32l476xg 32l476rg-nucleo: clean
  147. @$(MAKE) demo STARTUP='$(CMSISDEV)/ST/STM32L4xx/Source/Templates/gcc/startup_stm32l476xx.s' \
  148. LDSCRIPT='demo/stm32l476xg.ld' \
  149. DEFINES='STM32L4 STM32L476xx USBD_SOF_DISABLED' \
  150. CFLAGS='-mcpu=cortex-m4'
  151. stm32f429xi 32f429zi-nucleo: clean
  152. @$(MAKE) demo STARTUP='$(CMSISDEV)/ST/STM32F4xx/Source/Templates/gcc/startup_stm32f429xx.s' \
  153. LDSCRIPT='demo/stm32f429xi.ld' \
  154. DEFINES='STM32F4 STM32F429xx USBD_SOF_DISABLED' \
  155. CFLAGS='-mcpu=cortex-m4'
  156. stm32f429xi_hs 32f429zi-nucleo_hs: clean
  157. @$(MAKE) demo STARTUP='$(CMSISDEV)/ST/STM32F4xx/Source/Templates/gcc/startup_stm32f429xx.s' \
  158. LDSCRIPT='demo/stm32f429xi.ld' \
  159. DEFINES='STM32F4 STM32F429xx USBD_PRIMARY_OTGHS USBD_SOF_DISABLED' \
  160. CFLAGS='-mcpu=cortex-m4'
  161. stm32l433cc: clean
  162. @$(MAKE) demo STARTUP='$(CMSISDEV)/ST/STM32L4xx/Source/Templates/gcc/startup_stm32l433xx.s' \
  163. LDSCRIPT='demo/stm32l433xc.ld' \
  164. DEFINES='STM32L4 STM32L433xx USBD_SOF_DISABLED' \
  165. CFLAGS='-mcpu=cortex-m4'
  166. stm32f070xb: clean
  167. @$(MAKE) demo STARTUP='$(CMSISDEV)/ST/STM32F0xx/Source/Templates/gcc/startup_stm32f070xb.s' \
  168. LDSCRIPT='demo/stm32f070xb.ld' \
  169. DEFINES='STM32F0 STM32F070xB USBD_SOF_DISABLED' \
  170. CFLAGS='-mcpu=cortex-m0'
  171. stm32g431xb 32g431rb-nucleo: clean
  172. @$(MAKE) demo STARTUP='$(CMSISDEV)/ST/STM32G4xx/Source/Templates/gcc/startup_stm32g431xx.s' \
  173. LDSCRIPT='demo/stm32g431xb.ld' \
  174. DEFINES='STM32G4 STM32G431xx USBD_SOF_DISABLED' \
  175. CFLAGS='-mcpu=cortex-m4'
  176. stm32f446xc 32f446re-nucleo: clean
  177. @$(MAKE) demo STARTUP='$(CMSISDEV)/ST/STM32F4xx/Source/Templates/gcc/startup_stm32f446xx.s' \
  178. LDSCRIPT='demo/stm32f446xc.ld' \
  179. DEFINES='STM32F4 STM32F446xx USBD_SOF_DISABLED' \
  180. CFLAGS='-mcpu=cortex-m4'
  181. stm32f446xc_hs 32f446re-nucleo_hs: clean
  182. @$(MAKE) demo STARTUP='$(CMSISDEV)/ST/STM32F4xx/Source/Templates/gcc/startup_stm32f446xx.s' \
  183. LDSCRIPT='demo/stm32f446xc.ld' \
  184. DEFINES='STM32F4 STM32F446xx USBD_SOF_DISABLED USBD_PRIMARY_OTGHS' \
  185. CFLAGS='-mcpu=cortex-m4'
  186. stm32f373xc: clean
  187. @$(MAKE) demo STARTUP='$(CMSISDEV)/ST/STM32F3xx/Source/Templates/gcc/startup_stm32f373xc.s' \
  188. LDSCRIPT='demo/stm32f373xc.ld' \
  189. DEFINES='STM32F3 STM32F373xC USBD_SOF_DISABLED' \
  190. CFLAGS='-mcpu=cortex-m4'
  191. stm32l053x8 32l053r8-nucleo: clean
  192. @$(MAKE) demo STARTUP='$(CMSISDEV)/ST/STM32L0xx/Source/Templates/gcc/startup_stm32l053xx.s' \
  193. LDSCRIPT='demo/stm32l052x8.ld' \
  194. DEFINES='STM32L0 STM32L053xx USBD_SOF_DISABLED' \
  195. CFLAGS='-mcpu=cortex-m0plus'
  196. stm32f405xg: clean
  197. @$(MAKE) demo STARTUP='$(CMSISDEV)/ST/STM32F4xx/Source/Templates/gcc/startup_stm32f405xx.s' \
  198. LDSCRIPT='demo/stm32f405xg.ld' \
  199. DEFINES='STM32F4 STM32F405xx USBD_SOF_DISABLED' \
  200. CFLAGS='-mcpu=cortex-m4'
  201. stm32f405xg_hs: clean
  202. @$(MAKE) demo STARTUP='$(CMSISDEV)/ST/STM32F4xx/Source/Templates/gcc/startup_stm32f405xx.s' \
  203. LDSCRIPT='demo/stm32f405xg.ld' \
  204. DEFINES='STM32F4 STM32F405xx USBD_SOF_DISABLED USBD_PRIMARY_OTGHS' \
  205. CFLAGS='-mcpu=cortex-m4'
  206. stm32f401xc: clean
  207. @$(MAKE) demo STARTUP='$(CMSISDEV)/ST/STM32F4xx/Source/Templates/gcc/startup_stm32f401xc.s' \
  208. LDSCRIPT='demo/stm32f401xc.ld' \
  209. DEFINES='STM32F4 STM32F401xC USBD_SOF_DISABLED' \
  210. CFLAGS='-mcpu=cortex-m4'
  211. stm32f401xe: clean
  212. @$(MAKE) demo STARTUP='$(CMSISDEV)/ST/STM32F4xx/Source/Templates/gcc/startup_stm32f401xe.s' \
  213. LDSCRIPT='demo/stm32f401xe.ld' \
  214. DEFINES='STM32F4 STM32F401xE USBD_SOF_DISABLED' \
  215. CFLAGS='-mcpu=cortex-m4'
  216. stm32f745xe: clean
  217. @$(MAKE) demo STARTUP='$(CMSISDEV)/ST/STM32F7xx/Source/Templates/gcc/startup_stm32f745xx.s' \
  218. LDSCRIPT='demo/stm32f745xe.ld' \
  219. DEFINES='STM32F7 STM32F745xx USBD_SOF_DISABLED' \
  220. CFLAGS='-mcpu=cortex-m7'
  221. stm32f745xe_hs: clean
  222. @$(MAKE) demo STARTUP='$(CMSISDEV)/ST/STM32F7xx/Source/Templates/gcc/startup_stm32f745xx.s' \
  223. LDSCRIPT='demo/stm32f745xe.ld' \
  224. DEFINES='STM32F7 STM32F745xx USBD_SOF_DISABLED USBD_PRIMARY_OTGHS' \
  225. CFLAGS='-mcpu=cortex-m7'
  226. stm32f042f6: clean
  227. @$(MAKE) demo STARTUP='$(CMSISDEV)/ST/STM32F0xx/Source/Templates/gcc/startup_stm32f042x6.s' \
  228. LDSCRIPT='demo/stm32f042x6.ld' \
  229. DEFINES='STM32F0 STM32F042x6 USBD_SOF_DISABLED' \
  230. CFLAGS='-mcpu=cortex-m0 -DUSBD_PINS_REMAP'
  231. stm32wb55xg: clean
  232. @$(MAKE) demo STARTUP='$(CMSISDEV)/ST/STM32WBxx/Source/Templates/gcc/startup_stm32wb55xx_cm4.s' \
  233. LDSCRIPT='demo/stm32wb55xg.ld' \
  234. DEFINES='STM32WB STM32WB55xx USBD_SOF_DISABLED' \
  235. CFLAGS='-mcpu=cortex-m4'
  236. stm32h743xx: clean
  237. @$(MAKE) demo STARTUP='$(CMSISDEV)/ST/STM32H7xx/Source/Templates/gcc/startup_stm32h743xx.s' \
  238. LDSCRIPT='demo/stm32h743xx.ld' \
  239. DEFINES='STM32H7 STM32H743xx USBD_VBUS_DETECT USBD_SOF_DISABLED' \
  240. CFLAGS='-mcpu=cortex-m7'
  241. stm32f411xe stm32f411e-disco: clean
  242. @$(MAKE) demo STARTUP='$(CMSISDEV)/ST/STM32F4xx/Source/Templates/gcc/startup_stm32f411xe.s' \
  243. LDSCRIPT='demo/stm32f401xe.ld' \
  244. DEFINES='STM32F4 STM32F411xE USBD_SOF_DISABLED' \
  245. CFLAGS='-mcpu=cortex-m4'