Makefile 6.2 KB

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