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