Skip to content

Commit edbf06a

Browse files
committed
separate iar and gcc build for clean make, also add cpu specific make
1 parent 50e61e0 commit edbf06a

File tree

10 files changed

+277
-223
lines changed

10 files changed

+277
-223
lines changed

examples/device/cdc_msc/Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ INC += \
55
$(TOP)/hw \
66

77
# Example source
8-
EXAMPLE_SOURCE += $(wildcard src/*.c)
8+
EXAMPLE_SOURCE += \
9+
src/main.c \
10+
src/msc_disk.c \
11+
src/usb_descriptors.c \
12+
913
SRC_C += $(addprefix $(CURRENT_PATH)/, $(EXAMPLE_SOURCE))
1014

1115
include ../../rules.mk

examples/make.mk

Lines changed: 23 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# Common make definition for all examples
33
# ---------------------------------------
44

5+
# Supported toolchain: gcc, iar
56
TOOLCHAIN ?= gcc
67

78
#-------------- TOP and CURRENT_PATH ------------
@@ -32,13 +33,6 @@ CMDEXE := 1
3233
SHELL := cmd.exe
3334
endif
3435

35-
36-
# Build directory
37-
BUILD := _build/$(BOARD)
38-
39-
PROJECT := $(notdir $(CURDIR))
40-
BIN := $(TOP)/_bin/$(BOARD)/$(notdir $(CURDIR))
41-
4236
# Handy check parameter function
4337
check_defined = \
4438
$(strip $(foreach 1,$1, \
@@ -47,6 +41,13 @@ __check_defined = \
4741
$(if $(value $1),, \
4842
$(error Undefined make flag: $1$(if $2, ($2))))
4943

44+
45+
# Build directory
46+
BUILD := _build/$(BOARD)
47+
48+
PROJECT := $(notdir $(CURDIR))
49+
BIN := $(TOP)/_bin/$(BOARD)/$(notdir $(CURDIR))
50+
5051
#-------------- Select the board to build for. ------------
5152

5253
# Board without family
@@ -81,25 +82,12 @@ endif
8182
# Can be set by board, default to ARM GCC
8283
CROSS_COMPILE ?= arm-none-eabi-
8384

84-
ifeq ($(CC),iccarm)
85-
USE_IAR = 1
85+
ifeq ($(TOOLCHAIN),iar)
86+
CC := iccarm
8687
endif
8788

88-
ifdef USE_IAR
89-
AS = iasmarm
90-
LD = ilinkarm
91-
OBJCOPY = ielftool
92-
SIZE = size
93-
94-
else
95-
CC = $(CROSS_COMPILE)gcc
96-
CXX = $(CROSS_COMPILE)g++
97-
AS = $(CC) -x assembler-with-cpp
98-
LD = $(CC)
99-
100-
GDB = $(CROSS_COMPILE)gdb
101-
OBJCOPY = $(CROSS_COMPILE)objcopy
102-
SIZE = $(CROSS_COMPILE)size
89+
ifeq ($(CC),iccarm)
90+
USE_IAR = 1
10391
endif
10492

10593
ifeq ($(CMDEXE),1)
@@ -115,57 +103,19 @@ else
115103
endif
116104

117105
#-------------- Source files and compiler flags --------------
106+
# tinyusb makefile
107+
include $(TOP)/src/tinyusb.mk
118108

119109
# Include all source C in family & board folder
120110
SRC_C += hw/bsp/board.c
121111
SRC_C += $(subst $(TOP)/,,$(wildcard $(TOP)/$(BOARD_PATH)/*.c))
122112

123-
INC += $(TOP)/$(FAMILY_PATH)
124-
125-
# Allow for -Os to be changed by board makefiles in case -Os is not allowed
126-
CFLAGS_OPTIMIZED ?= -Os
127-
128-
# GCC Compiler Flags
129-
GCC_CFLAGS += \
130-
-ggdb \
131-
-fdata-sections \
132-
-ffunction-sections \
133-
-fsingle-precision-constant \
134-
-fno-strict-aliasing \
135-
-Wall \
136-
-Wextra \
137-
-Werror \
138-
-Wfatal-errors \
139-
-Wdouble-promotion \
140-
-Wstrict-prototypes \
141-
-Wstrict-overflow \
142-
-Werror-implicit-function-declaration \
143-
-Wfloat-equal \
144-
-Wundef \
145-
-Wshadow \
146-
-Wwrite-strings \
147-
-Wsign-compare \
148-
-Wmissing-format-attribute \
149-
-Wunreachable-code \
150-
-Wcast-align \
151-
-Wcast-function-type \
152-
-Wcast-qual \
153-
-Wnull-dereference \
154-
-Wuninitialized \
155-
-Wunused \
156-
-Wreturn-type \
157-
-Wredundant-decls
158-
159-
# conversion is too strict for most mcu driver, may be disable sign/int/arith-conversion
160-
# -Wconversion
161-
162-
# Debugging/Optimization
163-
ifeq ($(DEBUG), 1)
164-
GCC_CFLAGS += -O0
165-
NO_LTO = 1
166-
else
167-
GCC_CFLAGS += $(CFLAGS_OPTIMIZED)
168-
endif
113+
SRC_C += $(TINYUSB_SRC_C)
114+
115+
INC += \
116+
$(TOP)/$(FAMILY_PATH) \
117+
$(TOP)/src \
118+
169119

170120
# Log level is mapped to TUSB DEBUG option
171121
ifneq ($(LOG),)
@@ -186,3 +136,6 @@ ifeq ($(LOGGER),rtt)
186136
else ifeq ($(LOGGER),swo)
187137
CFLAGS += -DLOGGER_SWO
188138
endif
139+
140+
# toolchain specific
141+
include $(TOP)/tools/make/toolchain/arm_$(TOOLCHAIN).mk

examples/rules.mk

Lines changed: 7 additions & 137 deletions
Original file line numberDiff line numberDiff line change
@@ -13,103 +13,15 @@ ifeq (,$(findstring $(FAMILY),espressif rp2040))
1313
# Compiler Flags
1414
# ---------------------------------------
1515

16-
LIBS_GCC ?= -lgcc -lm -lnosys
17-
18-
# libc
19-
LIBS += $(LIBS_GCC)
20-
21-
ifneq ($(BOARD), spresense)
22-
LIBS += -lc
23-
endif
24-
25-
# TinyUSB Stack source
26-
SRC_C += \
27-
src/tusb.c \
28-
src/common/tusb_fifo.c \
29-
src/device/usbd.c \
30-
src/device/usbd_control.c \
31-
src/typec/usbc.c \
32-
src/class/audio/audio_device.c \
33-
src/class/cdc/cdc_device.c \
34-
src/class/dfu/dfu_device.c \
35-
src/class/dfu/dfu_rt_device.c \
36-
src/class/hid/hid_device.c \
37-
src/class/midi/midi_device.c \
38-
src/class/msc/msc_device.c \
39-
src/class/net/ecm_rndis_device.c \
40-
src/class/net/ncm_device.c \
41-
src/class/usbtmc/usbtmc_device.c \
42-
src/class/video/video_device.c \
43-
src/class/vendor/vendor_device.c
44-
45-
# TinyUSB stack include
46-
INC += $(TOP)/src
47-
4816
CFLAGS += $(addprefix -I,$(INC))
4917

50-
ifdef USE_IAR
51-
52-
SRC_S += $(IAR_SRC_S)
53-
54-
ASFLAGS := $(CFLAGS) $(IAR_ASFLAGS) $(ASFLAGS) -S
55-
IAR_LDFLAGS += --config $(TOP)/$(IAR_LD_FILE)
56-
CFLAGS += $(IAR_CFLAGS) -e --debug --silent
57-
58-
else
59-
60-
SRC_S += $(GCC_SRC_S)
61-
62-
CFLAGS += $(GCC_CFLAGS) -MD
63-
64-
# LTO makes it difficult to analyze map file for optimizing size purpose
65-
# We will run this option in ci
66-
ifeq ($(NO_LTO),1)
67-
CFLAGS := $(filter-out -flto,$(CFLAGS))
68-
endif
69-
70-
ifneq ($(CFLAGS_SKIP),)
71-
CFLAGS := $(filter-out $(CFLAGS_SKIP),$(CFLAGS))
72-
endif
73-
74-
LDFLAGS += $(CFLAGS) -Wl,-Map=$@.map -Wl,-cref -Wl,-gc-sections
75-
76-
# Some toolchain such as renesas rx does not support --print-memory-usage flags
77-
ifneq ($(FAMILY),rx)
78-
LDFLAGS += -Wl,--print-memory-usage
79-
endif
80-
81-
ifdef LD_FILE
82-
LDFLAGS += -Wl,-T,$(TOP)/$(LD_FILE)
83-
endif
84-
85-
ifdef GCC_LD_FILE
86-
LDFLAGS += -Wl,-T,$(TOP)/$(GCC_LD_FILE)
87-
endif
88-
89-
ifneq ($(SKIP_NANOLIB), 1)
90-
LDFLAGS += --specs=nosys.specs --specs=nano.specs
91-
endif
92-
93-
ASFLAGS += $(CFLAGS)
94-
95-
endif # USE_IAR
96-
9718
# Verbose mode
9819
ifeq ("$(V)","1")
9920
$(info CFLAGS $(CFLAGS) ) $(info )
10021
$(info LDFLAGS $(LDFLAGS)) $(info )
10122
$(info ASFLAGS $(ASFLAGS)) $(info )
10223
endif
10324

104-
# Assembly files can be name with upper case .S, convert it to .s
105-
SRC_S := $(SRC_S:.S=.s)
106-
107-
# Due to GCC LTO bug https://bugs.launchpad.net/gcc-arm-embedded/+bug/1747966
108-
# assembly file should be placed first in linking order
109-
# '_asm' suffix is added to object of assembly file
110-
OBJ += $(addprefix $(BUILD)/obj/, $(SRC_S:.s=_asm.o))
111-
OBJ += $(addprefix $(BUILD)/obj/, $(SRC_C:.c=.o))
112-
11325
# ---------------------------------------
11426
# Rules
11527
# ---------------------------------------
@@ -118,65 +30,23 @@ all: $(BUILD)/$(PROJECT).bin $(BUILD)/$(PROJECT).hex size
11830

11931
uf2: $(BUILD)/$(PROJECT).uf2
12032

121-
OBJ_DIRS = $(sort $(dir $(OBJ)))
122-
$(OBJ): | $(OBJ_DIRS)
123-
$(OBJ_DIRS):
124-
ifeq ($(CMDEXE),1)
125-
-@$(MKDIR) $(subst /,\,$@)
126-
else
127-
@$(MKDIR) -p $@
128-
endif
129-
13033
# We set vpath to point to the top of the tree so that the source files
13134
# can be located. By following this scheme, it allows a single build rule
13235
# to be used to compile all .c files.
13336
vpath %.c . $(TOP)
13437
vpath %.s . $(TOP)
13538
vpath %.S . $(TOP)
13639

137-
# Compile .c file
138-
$(BUILD)/obj/%.o: %.c
139-
@echo CC $(notdir $@)
140-
@$(CC) $(CFLAGS) -c -o $@ $<
141-
142-
# ASM sources lower case .s
143-
$(BUILD)/obj/%_asm.o: %.s
144-
@echo AS $(notdir $@)
145-
@$(AS) $(ASFLAGS) -c -o $@ $<
40+
include $(TOP)/tools/make/toolchain/arm_$(TOOLCHAIN)_rules.mk
14641

147-
# ASM sources upper case .S
148-
$(BUILD)/obj/%_asm.o: %.S
149-
@echo AS $(notdir $@)
150-
@$(AS) $(ASFLAGS) -c -o $@ $<
151-
152-
ifdef USE_IAR
153-
# IAR Compiler
154-
$(BUILD)/$(PROJECT).bin: $(BUILD)/$(PROJECT).elf
155-
@echo CREATE $@
156-
@$(OBJCOPY) --silent --bin $^ $@
157-
158-
$(BUILD)/$(PROJECT).hex: $(BUILD)/$(PROJECT).elf
159-
@echo CREATE $@
160-
@$(OBJCOPY) --silent --ihex $^ $@
161-
162-
$(BUILD)/$(PROJECT).elf: $(OBJ)
163-
@echo LINK $@
164-
@$(LD) -o $@ $(IAR_LDFLAGS) $^
16542

43+
OBJ_DIRS = $(sort $(dir $(OBJ)))
44+
$(OBJ): | $(OBJ_DIRS)
45+
$(OBJ_DIRS):
46+
ifeq ($(CMDEXE),1)
47+
-@$(MKDIR) $(subst /,\,$@)
16648
else
167-
# GCC based compiler
168-
$(BUILD)/$(PROJECT).bin: $(BUILD)/$(PROJECT).elf
169-
@echo CREATE $@
170-
@$(OBJCOPY) -O binary $^ $@
171-
172-
$(BUILD)/$(PROJECT).hex: $(BUILD)/$(PROJECT).elf
173-
@echo CREATE $@
174-
@$(OBJCOPY) -O ihex $^ $@
175-
176-
$(BUILD)/$(PROJECT).elf: $(OBJ)
177-
@echo LINK $@
178-
@$(LD) -o $@ $(LDFLAGS) $^ -Wl,--start-group $(LIBS) -Wl,--end-group
179-
49+
@$(MKDIR) -p $@
18050
endif
18151

18252
# UF2 generation, iMXRT need to strip to text only before conversion

hw/bsp/stm32h7/family.mk

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ ST_CMSIS = hw/mcu/st/cmsis_device_$(ST_FAMILY)
66
ST_HAL_DRIVER = hw/mcu/st/stm32$(ST_FAMILY)xx_hal_driver
77

88
include $(TOP)/$(BOARD_PATH)/board.mk
9+
CPU_CORE ?= cortex-m7
910

1011
# --------------
1112
# Compiler Flags
@@ -29,20 +30,11 @@ endif
2930
# GCC Flags
3031
GCC_CFLAGS += \
3132
-flto \
32-
-mthumb \
33-
-mabi=aapcs \
34-
-mcpu=cortex-m7 \
35-
-mfloat-abi=hard \
36-
-mfpu=fpv5-d16 \
3733
-nostdlib -nostartfiles
3834

3935
# suppress warning caused by vendor mcu driver
4036
GCC_CFLAGS += -Wno-error=maybe-uninitialized -Wno-error=cast-align -Wno-error=unused-parameter
4137

42-
# IAR Flags
43-
IAR_CFLAGS += --cpu cortex-m7 --fpu VFPv5_D16
44-
IAR_ASFLAGS += --cpu cortex-m7 --fpu VFPv5_D16
45-
4638
# -----------------
4739
# Sources & Include
4840
# -----------------
@@ -66,6 +58,3 @@ INC += \
6658
$(TOP)/lib/CMSIS_5/CMSIS/Core/Include \
6759
$(TOP)/$(ST_CMSIS)/Include \
6860
$(TOP)/$(ST_HAL_DRIVER)/Inc
69-
70-
# For freeRTOS port source
71-
FREERTOS_PORTABLE_SRC = $(FREERTOS_PORTABLE_PATH)/ARM_CM7/r0p1

src/tinyusb.mk

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# C source files
2+
TINYUSB_SRC_C += \
3+
src/tusb.c \
4+
src/common/tusb_fifo.c \
5+
src/device/usbd.c \
6+
src/device/usbd_control.c \
7+
src/typec/usbc.c \
8+
src/class/audio/audio_device.c \
9+
src/class/cdc/cdc_device.c \
10+
src/class/dfu/dfu_device.c \
11+
src/class/dfu/dfu_rt_device.c \
12+
src/class/hid/hid_device.c \
13+
src/class/midi/midi_device.c \
14+
src/class/msc/msc_device.c \
15+
src/class/net/ecm_rndis_device.c \
16+
src/class/net/ncm_device.c \
17+
src/class/usbtmc/usbtmc_device.c \
18+
src/class/video/video_device.c \
19+
src/class/vendor/vendor_device.c \

0 commit comments

Comments
 (0)