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. $(MAKE) --version
  94. @$(RM) $(DOUT).*
  95. @$(RM) $(call fixpath, $(OBJDIR)/*.*)
  96. doc:
  97. doxygen
  98. module: clean
  99. $(MAKE) $(MODULE)
  100. $(MODULE): $(OBJDIR) $(OBJECTS)
  101. @$(AR) $(ARFLAGS) $(MODULE) $(OBJECTS)
  102. $(OBJDIR)/%.o: %.c
  103. @echo compiling $<
  104. @$(CC) $(CFLAGS2) $(addprefix -D, $(DEFINES)) $(addprefix -I, $(INCLUDES)) -c $< -o $@
  105. $(OBJDIR)/%.o: %.S
  106. @echo assembling $<
  107. @$(CC) $(CFLAGS2) $(addprefix -D, $(DEFINES)) $(addprefix -I, $(INCLUDES)) -c $< -o $@
  108. $(OBJDIR)/%.o: %.s
  109. @echo assembling $<
  110. @$(CC) $(CFLAGS2) $(addprefix -D, $(DEFINES)) $(addprefix -I, $(INCLUDES)) -c $< -o $@
  111. .PHONY: module doc demo clean program help all program_stcube cmsis
  112. stm32f103x6 bluepill: clean
  113. @$(MAKE) demo STARTUP='$(CMSISDEV)/ST/STM32F1xx/Source/Templates/gcc/startup_stm32f103x6.s' \
  114. LDSCRIPT='demo/stm32f103x6.ld' \
  115. DEFINES='STM32F1 STM32F103x6 USBD_SOF_DISABLED' \
  116. CFLAGS='-mcpu=cortex-m3'
  117. stm32f303xe 32f303re-nucleo: clean
  118. @$(MAKE) demo STARTUP='$(CMSISDEV)/ST/STM32F3xx/Source/Templates/gcc/startup_stm32f303xe.s' \
  119. LDSCRIPT='demo/stm32f303xe.ld' \
  120. DEFINES='STM32F3 STM32F303xE USBD_SOF_DISABLED' \
  121. CFLAGS='-mcpu=cortex-m4'
  122. stm32f303xc: clean
  123. @$(MAKE) demo STARTUP='$(CMSISDEV)/ST/STM32F3xx/Source/Templates/gcc/startup_stm32f303xc.s' \
  124. LDSCRIPT='demo/stm32f303xc.ld' \
  125. DEFINES='STM32F3 STM32F303xC USBD_SOF_DISABLED' \
  126. CFLAGS='-mcpu=cortex-m4'
  127. stm32f105xb: clean
  128. @$(MAKE) demo STARTUP='$(CMSISDEV)/ST/STM32F1xx/Source/Templates/gcc/startup_stm32f105xc.s' \
  129. LDSCRIPT='demo/stm32f105xb.ld' \
  130. DEFINES='STM32F1 STM32F105xC USBD_VBUS_DETECT USBD_SOF_DISABLED' \
  131. CFLAGS='-mcpu=cortex-m3 -Wp,-w'
  132. stm32f107xb: clean
  133. @$(MAKE) demo STARTUP='$(CMSISDEV)/ST/STM32F1xx/Source/Templates/gcc/startup_stm32f107xc.s' \
  134. LDSCRIPT='demo/stm32f105xb.ld' \
  135. DEFINES='STM32F1 STM32F107xC HSE_25MHZ USBD_VBUS_DETECT USBD_SOF_DISABLED' \
  136. CFLAGS='-mcpu=cortex-m3 -Wp,-w'
  137. stm32l052x8: clean
  138. @$(MAKE) demo STARTUP='$(CMSISDEV)/ST/STM32L0xx/Source/Templates/gcc/startup_stm32l052xx.s' \
  139. LDSCRIPT='demo/stm32l052x8.ld' \
  140. DEFINES='STM32L0 STM32L052xx USBD_SOF_DISABLED' \
  141. CFLAGS='-mcpu=cortex-m0plus'
  142. stm32l100xc 32l100c-disco: clean
  143. @$(MAKE) demo STARTUP='$(CMSISDEV)/ST/STM32L1xx/Source/Templates/gcc/startup_stm32l100xc.s' \
  144. LDSCRIPT='demo/stm32l100xc.ld' \
  145. DEFINES='STM32L1 STM32L100xC USBD_SOF_DISABLED' \
  146. CFLAGS='-mcpu=cortex-m3'
  147. stm32l476xg 32l476rg-nucleo: clean
  148. @$(MAKE) demo STARTUP='$(CMSISDEV)/ST/STM32L4xx/Source/Templates/gcc/startup_stm32l476xx.s' \
  149. LDSCRIPT='demo/stm32l476xg.ld' \
  150. DEFINES='STM32L4 STM32L476xx USBD_SOF_DISABLED' \
  151. CFLAGS='-mcpu=cortex-m4'
  152. stm32f429xi 32f429zi-nucleo: clean
  153. @$(MAKE) demo STARTUP='$(CMSISDEV)/ST/STM32F4xx/Source/Templates/gcc/startup_stm32f429xx.s' \
  154. LDSCRIPT='demo/stm32f429xi.ld' \
  155. DEFINES='STM32F4 STM32F429xx USBD_SOF_DISABLED' \
  156. CFLAGS='-mcpu=cortex-m4'
  157. stm32f429xi_hs 32f429zi-nucleo_hs: clean
  158. @$(MAKE) demo STARTUP='$(CMSISDEV)/ST/STM32F4xx/Source/Templates/gcc/startup_stm32f429xx.s' \
  159. LDSCRIPT='demo/stm32f429xi.ld' \
  160. DEFINES='STM32F4 STM32F429xx USBD_PRIMARY_OTGHS USBD_SOF_DISABLED' \
  161. CFLAGS='-mcpu=cortex-m4'
  162. stm32l433cc: clean
  163. @$(MAKE) demo STARTUP='$(CMSISDEV)/ST/STM32L4xx/Source/Templates/gcc/startup_stm32l433xx.s' \
  164. LDSCRIPT='demo/stm32l433xc.ld' \
  165. DEFINES='STM32L4 STM32L433xx USBD_SOF_DISABLED' \
  166. CFLAGS='-mcpu=cortex-m4'
  167. stm32f070xb: clean
  168. @$(MAKE) demo STARTUP='$(CMSISDEV)/ST/STM32F0xx/Source/Templates/gcc/startup_stm32f070xb.s' \
  169. LDSCRIPT='demo/stm32f070xb.ld' \
  170. DEFINES='STM32F0 STM32F070xB USBD_SOF_DISABLED' \
  171. CFLAGS='-mcpu=cortex-m0'
  172. stm32g431xb 32g431rb-nucleo: clean
  173. @$(MAKE) demo STARTUP='$(CMSISDEV)/ST/STM32G4xx/Source/Templates/gcc/startup_stm32g431xx.s' \
  174. LDSCRIPT='demo/stm32g431xb.ld' \
  175. DEFINES='STM32G4 STM32G431xx USBD_SOF_DISABLED' \
  176. CFLAGS='-mcpu=cortex-m4'
  177. stm32f446xc 32f446re-nucleo: clean
  178. @$(MAKE) demo STARTUP='$(CMSISDEV)/ST/STM32F4xx/Source/Templates/gcc/startup_stm32f446xx.s' \
  179. LDSCRIPT='demo/stm32f446xc.ld' \
  180. DEFINES='STM32F4 STM32F446xx USBD_SOF_DISABLED' \
  181. CFLAGS='-mcpu=cortex-m4'
  182. stm32f446xc_hs 32f446re-nucleo_hs: clean
  183. @$(MAKE) demo STARTUP='$(CMSISDEV)/ST/STM32F4xx/Source/Templates/gcc/startup_stm32f446xx.s' \
  184. LDSCRIPT='demo/stm32f446xc.ld' \
  185. DEFINES='STM32F4 STM32F446xx USBD_SOF_DISABLED USBD_PRIMARY_OTGHS' \
  186. CFLAGS='-mcpu=cortex-m4'
  187. stm32f373xc: clean
  188. @$(MAKE) demo STARTUP='$(CMSISDEV)/ST/STM32F3xx/Source/Templates/gcc/startup_stm32f373xc.s' \
  189. LDSCRIPT='demo/stm32f373xc.ld' \
  190. DEFINES='STM32F3 STM32F373xC USBD_SOF_DISABLED' \
  191. CFLAGS='-mcpu=cortex-m4'
  192. stm32l053x8 32l053r8-nucleo: clean
  193. @$(MAKE) demo STARTUP='$(CMSISDEV)/ST/STM32L0xx/Source/Templates/gcc/startup_stm32l053xx.s' \
  194. LDSCRIPT='demo/stm32l052x8.ld' \
  195. DEFINES='STM32L0 STM32L053xx USBD_SOF_DISABLED' \
  196. CFLAGS='-mcpu=cortex-m0plus'
  197. stm32f405xg: clean
  198. @$(MAKE) demo STARTUP='$(CMSISDEV)/ST/STM32F4xx/Source/Templates/gcc/startup_stm32f405xx.s' \
  199. LDSCRIPT='demo/stm32f405xg.ld' \
  200. DEFINES='STM32F4 STM32F405xx USBD_SOF_DISABLED' \
  201. CFLAGS='-mcpu=cortex-m4'
  202. stm32f405xg_hs: clean
  203. @$(MAKE) demo STARTUP='$(CMSISDEV)/ST/STM32F4xx/Source/Templates/gcc/startup_stm32f405xx.s' \
  204. LDSCRIPT='demo/stm32f405xg.ld' \
  205. DEFINES='STM32F4 STM32F405xx USBD_SOF_DISABLED USBD_PRIMARY_OTGHS' \
  206. CFLAGS='-mcpu=cortex-m4'
  207. stm32f401xc: clean
  208. @$(MAKE) demo STARTUP='$(CMSISDEV)/ST/STM32F4xx/Source/Templates/gcc/startup_stm32f401xc.s' \
  209. LDSCRIPT='demo/stm32f401xc.ld' \
  210. DEFINES='STM32F4 STM32F401xC USBD_SOF_DISABLED' \
  211. CFLAGS='-mcpu=cortex-m4'
  212. stm32f401xe: clean
  213. @$(MAKE) demo STARTUP='$(CMSISDEV)/ST/STM32F4xx/Source/Templates/gcc/startup_stm32f401xe.s' \
  214. LDSCRIPT='demo/stm32f401xe.ld' \
  215. DEFINES='STM32F4 STM32F401xE USBD_SOF_DISABLED' \
  216. CFLAGS='-mcpu=cortex-m4'
  217. stm32f745xe: clean
  218. @$(MAKE) demo STARTUP='$(CMSISDEV)/ST/STM32F7xx/Source/Templates/gcc/startup_stm32f745xx.s' \
  219. LDSCRIPT='demo/stm32f745xe.ld' \
  220. DEFINES='STM32F7 STM32F745xx USBD_SOF_DISABLED' \
  221. CFLAGS='-mcpu=cortex-m7'
  222. stm32f745xe_hs: clean
  223. @$(MAKE) demo STARTUP='$(CMSISDEV)/ST/STM32F7xx/Source/Templates/gcc/startup_stm32f745xx.s' \
  224. LDSCRIPT='demo/stm32f745xe.ld' \
  225. DEFINES='STM32F7 STM32F745xx USBD_SOF_DISABLED USBD_PRIMARY_OTGHS' \
  226. CFLAGS='-mcpu=cortex-m7'
  227. stm32f042f6: clean
  228. @$(MAKE) demo STARTUP='$(CMSISDEV)/ST/STM32F0xx/Source/Templates/gcc/startup_stm32f042x6.s' \
  229. LDSCRIPT='demo/stm32f042x6.ld' \
  230. DEFINES='STM32F0 STM32F042x6 USBD_SOF_DISABLED' \
  231. CFLAGS='-mcpu=cortex-m0 -DUSBD_PINS_REMAP'
  232. stm32wb55xg: clean
  233. @$(MAKE) demo STARTUP='$(CMSISDEV)/ST/STM32WBxx/Source/Templates/gcc/startup_stm32wb55xx_cm4.s' \
  234. LDSCRIPT='demo/stm32wb55xg.ld' \
  235. DEFINES='STM32WB STM32WB55xx USBD_SOF_DISABLED' \
  236. CFLAGS='-mcpu=cortex-m4'
  237. stm32h743xx: clean
  238. @$(MAKE) demo STARTUP='$(CMSISDEV)/ST/STM32H7xx/Source/Templates/gcc/startup_stm32h743xx.s' \
  239. LDSCRIPT='demo/stm32h743xx.ld' \
  240. DEFINES='STM32H7 STM32H743xx USBD_VBUS_DETECT USBD_SOF_DISABLED' \
  241. CFLAGS='-mcpu=cortex-m7'
  242. stm32f411xe stm32f411e-disco: clean
  243. @$(MAKE) demo STARTUP='$(CMSISDEV)/ST/STM32F4xx/Source/Templates/gcc/startup_stm32f411xe.s' \
  244. LDSCRIPT='demo/stm32f401xe.ld' \
  245. DEFINES='STM32F4 STM32F411xE USBD_SOF_DISABLED' \
  246. CFLAGS='-mcpu=cortex-m4'