Makefile 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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. ifeq ($(OS),Windows_NT)
  13. RM = del /Q
  14. fixpath = $(strip $(subst /,\, $1))
  15. else
  16. RM = rm -f
  17. fixpath = $(strip $1)
  18. endif
  19. MODULE ?= libusb.a
  20. CFLAGS ?= -mcpu=cortex-m3
  21. DEFINES ?= STM32F1 STM32F103x6
  22. ARFLAGS = -cvq
  23. LDFLAGS = --specs=nano.specs -nostartfiles -Wl,--gc-sections
  24. INCLUDES = $(CMSISDEV)/ST $(CMSISCORE) inc
  25. CFLAGS2 = -mthumb -Os -std=gnu99 -fshort-wchar
  26. OBJDIR = obj
  27. SOURCES = $(wildcard src/*.c) $(wildcard src/*.S)
  28. OBJECTS = $(addprefix $(OBJDIR)/, $(addsuffix .o, $(notdir $(basename $(SOURCES)))))
  29. DSRC = $(wildcard demo/*.c) $(wildcard demo/*.S) $(STARTUP)
  30. DOBJ = $(addprefix $(OBJDIR)/, $(addsuffix .o, $(notdir $(basename $(DSRC)))))
  31. DOUT = cdc_loop
  32. SRCPATH = $(sort $(dir $(SOURCES) $(DSRC)))
  33. vpath %.c $(SRCPATH)
  34. vpath %.S $(SRCPATH)
  35. vpath %.s $(SRCPATH)
  36. help all:
  37. @echo 'Usage: make target [program]'
  38. @echo 'Available targets are:'
  39. @echo ' bluepill'
  40. @echo ' stm32f103x6 CDC loopback demo for STM32F103 based boards'
  41. @echo ' 32l100c-disco'
  42. @echo ' stm32l100xc CDC loopback demo for STM32L100xC based boards'
  43. @echo ' 32l476rg-nucleo'
  44. @echo ' stm32l476rg CDC loopback demo for STM32L476xG based boards'
  45. @echo ' stm32l052x8 CDC loopback demo for STM32L052x8 based boards'
  46. @echo ' 32f429zi-nucleo'
  47. @echo ' stm32f429xi CDC loopback demo for STM32F429xI based boards'
  48. @echo ' doc DOXYGEN documentation'
  49. @echo ' module static library module using following envars (defaults)'
  50. @echo ' MODULE module name (libusb.a)'
  51. @echo ' CFLAGS mcu specified compiler flags (-mcpu=cortex-m3)'
  52. @echo ' DEFINES mcu and module specified defines (STM32F1 STM32F103x6)'
  53. @echo ' see USB Device HW driver and core API section for the'
  54. @echo ' compile-time control macros'
  55. @echo ' '
  56. @echo 'Environmental variables (defaults):'
  57. @echo ' CMSIS Path to the CMSIS V4 or CMSIS V5 root folder ($(CMSIS))'
  58. @echo ' CMSISCORE Path to the CMSIS Core include folder(s) ($(CMSISCORE))'
  59. @echo ' CMSISDEV Path to the CMSIS Device folder ($(CMSISDEV))'
  60. @echo ' FLASH st-link flash utility ($(FLASH))'
  61. @echo ' '
  62. @echo 'Examples:'
  63. @echo ' make bluepill program'
  64. @echo ' make module MODULE="usbd.a" CFLAGS="-mcpu=cotrex-m4" DEFINES="STM32L4 STM32L476xx USBD_VBUS_DETECT"'
  65. $(OBJDIR):
  66. @mkdir $@
  67. program: $(DOUT).hex
  68. $(FLASH) --reset --format ihex write $(DOUT).hex
  69. program_dfu: $(DOUT).bin
  70. $(DFU_UTIL) -d 0483:DF11 -a 0 -D $(DOUT).bin -s 0x08000000
  71. program_stcube: $(DOUT).hex
  72. $(STPROG_CLI) -c port=SWD reset=HWrst -d $(DOUT).hex -hardRst
  73. demo: $(DOUT).hex $(DOUT).bin
  74. $(DOUT).bin : $(DOUT).elf
  75. @echo building $@
  76. @$(OBJCOPY) -O binary $< $@
  77. $(DOUT).hex : $(DOUT).elf
  78. @echo building $@
  79. @$(OBJCOPY) -O ihex $< $@
  80. $(DOUT).elf : $(OBJDIR) $(DOBJ) $(OBJECTS)
  81. @echo building $@
  82. @$(LD) $(CFLAGS) $(CFLAGS2) $(LDFLAGS) -Wl,--script='$(LDSCRIPT)' -Wl,-Map=$(DOUT).map $(DOBJ) $(OBJECTS) -o $@
  83. clean:
  84. @$(RM) $(DOUT).*
  85. @$(RM) $(call fixpath, $(OBJDIR)/*.*)
  86. doc:
  87. doxygen
  88. module: clean $(MODULE)
  89. $(MODULE): $(OBJDIR) $(OBJECTS)
  90. @$(AR) $(ARFLAGS) $(MODULE) $(OBJECTS)
  91. $(OBJDIR)/%.o: %.c
  92. @echo compiling $<
  93. @$(CC) $(CFLAGS) $(CFLAGS2) $(addprefix -D, $(DEFINES)) $(addprefix -I, $(INCLUDES)) -c $< -o $@
  94. $(OBJDIR)/%.o: %.S
  95. @echo assembling $<
  96. @$(CC) $(CFLAGS) $(CFLAGS2) $(addprefix -D, $(DEFINES)) $(addprefix -I, $(INCLUDES)) -c $< -o $@
  97. $(OBJDIR)/%.o: %.s
  98. @echo assembling $<
  99. @$(CC) $(CFLAGS) $(CFLAGS2) $(addprefix -D, $(DEFINES)) $(addprefix -I, $(INCLUDES)) -c $< -o $@
  100. .PHONY: module doc demo clean program help all program_stcube
  101. stm32f103x6 bluepill:
  102. @$(MAKE) clean demo STARTUP='$(CMSISDEV)/ST/STM32F1xx/Source/Templates/gcc/startup_stm32f103x6.s' \
  103. LDSCRIPT='demo/stm32f103x6.ld' \
  104. DEFINES='STM32F1 STM32F103x6 USBD_SOF_DISABLED' \
  105. CFLAGS='-mcpu=cortex-m3 -mthumb'
  106. stm32f303xe 32f303re-nucleo:
  107. @$(MAKE) clean demo STARTUP='$(CMSISDEV)/ST/STM32F3xx/Source/Templates/gcc/startup_stm32f303xe.s' \
  108. LDSCRIPT='demo/stm32f303xe.ld' \
  109. DEFINES='STM32F3 STM32F303xE USBD_SOF_DISABLED' \
  110. CFLAGS='-mcpu=cortex-m4 -mthumb'
  111. stm32f105xb:
  112. @$(MAKE) clean demo STARTUP='$(CMSISDEV)/ST/STM32F1xx/Source/Templates/gcc/startup_stm32f105xc.s' \
  113. LDSCRIPT='demo/stm32f105xb.ld' \
  114. DEFINES='STM32F1 STM32F105xC USBD_VBUS_DETECT USBD_SOF_DISABLED' \
  115. CFLAGS='-mcpu=cortex-m3 -mthumb -Wp,-w'
  116. stm32f107xb:
  117. @$(MAKE) clean demo STARTUP='$(CMSISDEV)/ST/STM32F1xx/Source/Templates/gcc/startup_stm32f107xc.s' \
  118. LDSCRIPT='demo/stm32f105xb.ld' \
  119. DEFINES='STM32F1 STM32F107xC HSE_25MHZ USBD_VBUS_DETECT USBD_SOF_DISABLED' \
  120. CFLAGS='-mcpu=cortex-m3 -mthumb -Wp,-w'
  121. stm32l052x8:
  122. @$(MAKE) clean demo STARTUP='$(CMSISDEV)/ST/STM32L0xx/Source/Templates/gcc/startup_stm32l052xx.s' \
  123. LDSCRIPT='demo/stm32l052x8.ld' \
  124. DEFINES='STM32L0 STM32L052xx USBD_SOF_DISABLED' \
  125. CFLAGS='-mcpu=cortex-m0plus -mthumb'
  126. stm32l100xc 32l100c-disco:
  127. @$(MAKE) clean demo STARTUP='$(CMSISDEV)/ST/STM32L1xx/Source/Templates/gcc/startup_stm32l100xc.s' \
  128. LDSCRIPT='demo/stm32l100xc.ld' \
  129. DEFINES='STM32L1 STM32L100xC USBD_SOF_DISABLED' \
  130. CFLAGS='-mcpu=cortex-m3 -mthumb'
  131. stm32l476xg 32l476rg-nucleo:
  132. @$(MAKE) clean demo STARTUP='$(CMSISDEV)/ST/STM32L4xx/Source/Templates/gcc/startup_stm32l476xx.s' \
  133. LDSCRIPT='demo/stm32l476xg.ld' \
  134. DEFINES='STM32L4 STM32L476xx USBD_SOF_DISABLED' \
  135. CFLAGS='-mcpu=cortex-m4 -mthumb'
  136. stm32f429xi 32f429zi-nucleo:
  137. @$(MAKE) clean demo STARTUP='$(CMSISDEV)/ST/STM32F4xx/Source/Templates/gcc/startup_stm32f429xx.s' \
  138. LDSCRIPT='demo/stm32f429xi.ld' \
  139. DEFINES='STM32F4 STM32F429xx USBD_SOF_DISABLED' \
  140. CFLAGS='-mcpu=cortex-m4 -mthumb'
  141. stm32f429xi_hs 32f429zi-nucleo_hs:
  142. @$(MAKE) clean demo STARTUP='$(CMSISDEV)/ST/STM32F4xx/Source/Templates/gcc/startup_stm32f429xx.s' \
  143. LDSCRIPT='demo/stm32f429xi.ld' \
  144. DEFINES='STM32F4 STM32F429xx USBD_PRIMARY_OTGHS USBD_SOF_DISABLED' \
  145. CFLAGS='-mcpu=cortex-m4 -mthumb'
  146. stm32l433cc:
  147. @$(MAKE) clean demo STARTUP='$(CMSISDEV)/ST/STM32L4xx/Source/Templates/gcc/startup_stm32l433xx.s' \
  148. LDSCRIPT='demo/stm32l433xc.ld' \
  149. DEFINES='STM32L4 STM32L433xx USBD_SOF_DISABLED' \
  150. CFLAGS='-mcpu=cortex-m4 -mthumb'