Makefile 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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
  25. INCLUDES = $(CMSISDEV)/ST $(CMSISCORE) inc
  26. CFLAGS2 = -mthumb -std=gnu99 -fshort-wchar $(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 ' doc DOXYGEN documentation'
  50. @echo ' module static library module using following envars (defaults)'
  51. @echo ' MODULE module name (libusb.a)'
  52. @echo ' CFLAGS mcu specified compiler flags (-mcpu=cortex-m3)'
  53. @echo ' DEFINES mcu and module specified defines (STM32F1 STM32F103x6)'
  54. @echo ' see USB Device HW driver and core API section for the'
  55. @echo ' compile-time control macros'
  56. @echo ' '
  57. @echo 'Environmental variables (defaults):'
  58. @echo ' CMSIS Path to the CMSIS V4 or CMSIS V5 root folder ($(CMSIS))'
  59. @echo ' CMSISCORE Path to the CMSIS Core include folder(s) ($(CMSISCORE))'
  60. @echo ' CMSISDEV Path to the CMSIS Device folder ($(CMSISDEV))'
  61. @echo ' FLASH st-link flash utility ($(FLASH))'
  62. @echo ' '
  63. @echo 'Examples:'
  64. @echo ' make bluepill program'
  65. @echo ' make module MODULE="usbd.a" CFLAGS="-mcpu=cotrex-m4" DEFINES="STM32L4 STM32L476xx USBD_VBUS_DETECT"'
  66. $(OBJDIR):
  67. @mkdir $@
  68. program: $(DOUT).hex
  69. $(FLASH) --reset --format ihex write $(DOUT).hex
  70. program_dfu: $(DOUT).bin
  71. $(DFU_UTIL) -d 0483:DF11 -a 0 -D $(DOUT).bin -s 0x08000000
  72. program_stcube: $(DOUT).hex
  73. $(STPROG_CLI) -c port=SWD reset=HWrst -d $(DOUT).hex -hardRst
  74. demo: $(DOUT).hex $(DOUT).bin
  75. $(DOUT).bin : $(DOUT).elf
  76. @echo building $@
  77. @$(OBJCOPY) -O binary $< $@
  78. $(DOUT).hex : $(DOUT).elf
  79. @echo building $@
  80. @$(OBJCOPY) -O ihex $< $@
  81. $(DOUT).elf : $(OBJDIR) $(DOBJ) $(OBJECTS)
  82. @echo building $@
  83. @$(LD) $(CFLAGS) $(CFLAGS2) $(LDFLAGS) -Wl,--script='$(LDSCRIPT)' -Wl,-Map=$(DOUT).map $(DOBJ) $(OBJECTS) -o $@
  84. clean:
  85. @$(RM) $(DOUT).*
  86. @$(RM) $(call fixpath, $(OBJDIR)/*.*)
  87. doc:
  88. doxygen
  89. module: clean $(MODULE)
  90. $(MODULE): $(OBJDIR) $(OBJECTS)
  91. @$(AR) $(ARFLAGS) $(MODULE) $(OBJECTS)
  92. $(OBJDIR)/%.o: %.c
  93. @echo compiling $<
  94. @$(CC) $(CFLAGS) $(CFLAGS2) $(addprefix -D, $(DEFINES)) $(addprefix -I, $(INCLUDES)) -c $< -o $@
  95. $(OBJDIR)/%.o: %.S
  96. @echo assembling $<
  97. @$(CC) $(CFLAGS) $(CFLAGS2) $(addprefix -D, $(DEFINES)) $(addprefix -I, $(INCLUDES)) -c $< -o $@
  98. $(OBJDIR)/%.o: %.s
  99. @echo assembling $<
  100. @$(CC) $(CFLAGS) $(CFLAGS2) $(addprefix -D, $(DEFINES)) $(addprefix -I, $(INCLUDES)) -c $< -o $@
  101. .PHONY: module doc demo clean program help all program_stcube
  102. stm32f103x6 bluepill:
  103. @$(MAKE) clean demo STARTUP='$(CMSISDEV)/ST/STM32F1xx/Source/Templates/gcc/startup_stm32f103x6.s' \
  104. LDSCRIPT='demo/stm32f103x6.ld' \
  105. DEFINES='STM32F1 STM32F103x6 USBD_SOF_DISABLED' \
  106. CFLAGS='-mcpu=cortex-m3 -mthumb'
  107. stm32f303xe 32f303re-nucleo:
  108. @$(MAKE) clean demo STARTUP='$(CMSISDEV)/ST/STM32F3xx/Source/Templates/gcc/startup_stm32f303xe.s' \
  109. LDSCRIPT='demo/stm32f303xe.ld' \
  110. DEFINES='STM32F3 STM32F303xE USBD_SOF_DISABLED' \
  111. CFLAGS='-mcpu=cortex-m4 -mthumb'
  112. stm32f105xb:
  113. @$(MAKE) clean demo STARTUP='$(CMSISDEV)/ST/STM32F1xx/Source/Templates/gcc/startup_stm32f105xc.s' \
  114. LDSCRIPT='demo/stm32f105xb.ld' \
  115. DEFINES='STM32F1 STM32F105xC USBD_VBUS_DETECT USBD_SOF_DISABLED' \
  116. CFLAGS='-mcpu=cortex-m3 -mthumb -Wp,-w'
  117. stm32f107xb:
  118. @$(MAKE) clean demo STARTUP='$(CMSISDEV)/ST/STM32F1xx/Source/Templates/gcc/startup_stm32f107xc.s' \
  119. LDSCRIPT='demo/stm32f105xb.ld' \
  120. DEFINES='STM32F1 STM32F107xC HSE_25MHZ USBD_VBUS_DETECT USBD_SOF_DISABLED' \
  121. CFLAGS='-mcpu=cortex-m3 -mthumb -Wp,-w'
  122. stm32l052x8:
  123. @$(MAKE) clean demo STARTUP='$(CMSISDEV)/ST/STM32L0xx/Source/Templates/gcc/startup_stm32l052xx.s' \
  124. LDSCRIPT='demo/stm32l052x8.ld' \
  125. DEFINES='STM32L0 STM32L052xx USBD_SOF_DISABLED' \
  126. CFLAGS='-mcpu=cortex-m0plus -mthumb'
  127. stm32l100xc 32l100c-disco:
  128. @$(MAKE) clean demo STARTUP='$(CMSISDEV)/ST/STM32L1xx/Source/Templates/gcc/startup_stm32l100xc.s' \
  129. LDSCRIPT='demo/stm32l100xc.ld' \
  130. DEFINES='STM32L1 STM32L100xC USBD_SOF_DISABLED' \
  131. CFLAGS='-mcpu=cortex-m3 -mthumb'
  132. stm32l476xg 32l476rg-nucleo:
  133. @$(MAKE) clean demo STARTUP='$(CMSISDEV)/ST/STM32L4xx/Source/Templates/gcc/startup_stm32l476xx.s' \
  134. LDSCRIPT='demo/stm32l476xg.ld' \
  135. DEFINES='STM32L4 STM32L476xx USBD_SOF_DISABLED' \
  136. CFLAGS='-mcpu=cortex-m4 -mthumb'
  137. stm32f429xi 32f429zi-nucleo:
  138. @$(MAKE) clean demo STARTUP='$(CMSISDEV)/ST/STM32F4xx/Source/Templates/gcc/startup_stm32f429xx.s' \
  139. LDSCRIPT='demo/stm32f429xi.ld' \
  140. DEFINES='STM32F4 STM32F429xx USBD_SOF_DISABLED' \
  141. CFLAGS='-mcpu=cortex-m4 -mthumb'
  142. stm32f429xi_hs 32f429zi-nucleo_hs:
  143. @$(MAKE) clean demo STARTUP='$(CMSISDEV)/ST/STM32F4xx/Source/Templates/gcc/startup_stm32f429xx.s' \
  144. LDSCRIPT='demo/stm32f429xi.ld' \
  145. DEFINES='STM32F4 STM32F429xx USBD_PRIMARY_OTGHS USBD_SOF_DISABLED' \
  146. CFLAGS='-mcpu=cortex-m4 -mthumb'
  147. stm32l433cc:
  148. @$(MAKE) clean demo STARTUP='$(CMSISDEV)/ST/STM32L4xx/Source/Templates/gcc/startup_stm32l433xx.s' \
  149. LDSCRIPT='demo/stm32l433xc.ld' \
  150. DEFINES='STM32L4 STM32L433xx USBD_SOF_DISABLED' \
  151. CFLAGS='-mcpu=cortex-m4 -mthumb'