forked from Suniasuta/CH592_Makefile_Template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
175 lines (145 loc) · 3.82 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
## Makefile
# Prefix for older riscv gcc is risv-none-embed
# Prefix for newer riscv gcc is risv-none-elf
# TOOLCHAIN_PREFIX := riscv-none-embed
TOOLCHAIN_PREFIX := riscv-none-elf
APP_C_SRCS += \
./src/main.c
SDK_BLE_HAL_C_SRCS := \
./sdk/BLE/HAL/MCU.c \
./sdk/BLE/HAL/RTC.c \
./sdk/BLE/HAL/SLEEP.c
SDK_STDPERIPHDRIVER_C_SRCS += \
./sdk/StdPeriphDriver/CH59x_adc.c \
./sdk/StdPeriphDriver/CH59x_clk.c \
./sdk/StdPeriphDriver/CH59x_flash.c \
./sdk/StdPeriphDriver/CH59x_gpio.c \
./sdk/StdPeriphDriver/CH59x_i2c.c \
./sdk/StdPeriphDriver/CH59x_lcd.c \
./sdk/StdPeriphDriver/CH59x_pwm.c \
./sdk/StdPeriphDriver/CH59x_pwr.c \
./sdk/StdPeriphDriver/CH59x_spi0.c \
./sdk/StdPeriphDriver/CH59x_sys.c \
./sdk/StdPeriphDriver/CH59x_timer0.c \
./sdk/StdPeriphDriver/CH59x_timer1.c \
./sdk/StdPeriphDriver/CH59x_timer2.c \
./sdk/StdPeriphDriver/CH59x_timer3.c \
./sdk/StdPeriphDriver/CH59x_uart0.c \
./sdk/StdPeriphDriver/CH59x_uart1.c \
./sdk/StdPeriphDriver/CH59x_uart2.c \
./sdk/StdPeriphDriver/CH59x_uart3.c \
./sdk/StdPeriphDriver/CH59x_usbdev.c \
./sdk/StdPeriphDriver/CH59x_usbhostBase.c \
./sdk/StdPeriphDriver/CH59x_usbhostClass.c
SDK_RVMSIS_C_SRCS += \
./sdk/RVMSIS/core_riscv.c
SDK_BLE_LIB_S_UPPER_SRCS += \
./sdk/BLE/LIB/ble_task_scheduler.S
SDK_STARTUP_S_UPPER_SRCS += \
./sdk/Startup/startup_CH592.S
C_SRCS := \
$(APP_C_SRCS) \
$(SDK_BLE_HAL_C_SRCS) \
$(SDK_STDPERIPHDRIVER_C_SRCS) \
$(SDK_RVMSIS_C_SRCS)
S_UPPER_SRCS := \
$(SDK_BLE_LIB_S_UPPER_SRCS) \
$(SDK_STARTUP_S_UPPER_SRCS)
OBJS := \
$(foreach src,$(C_SRCS),$(subst ./,obj/,$(patsubst %.c,%.o,$(src)))) \
$(foreach src,$(S_UPPER_SRCS),$(subst ./,obj/,$(patsubst %.S,%.o,$(src))))
MAKEFILE_DEPS := \
$(foreach obj,$(OBJS),$(patsubst %.o,%.d,$(obj)))
STDPERIPHDRIVER_LIBS := -L"./sdk/StdPeriphDriver" -lISP592
BLE_LIB_LIBS := -L"./sdk/BLE/LIB" -lCH59xBLE
LIBS := $(STDPERIPHDRIVER_LIBS) $(BLE_LIB_LIBS)
SECONDARY_FLASH := main.hex
SECONDARY_LIST := main.lst
SECONDARY_SIZE := main.siz
# ARCH is rv32imac on older gcc, rv32imac_zicsr on newer gcc
# ARCH := rv32imac
ARCH := rv32imac_zicsr
CFLAGS_COMMON := \
-march=$(ARCH) \
-mabi=ilp32 \
-mcmodel=medany \
-msmall-data-limit=8 \
-mno-save-restore \
-Os \
-fmessage-length=0 \
-fsigned-char \
-ffunction-sections \
-fdata-sections
#-g
.PHONY: all
all: main.elf secondary-outputs
.PHONY: clean
clean:
-rm $(OBJS)
-rm $(MAKEFILE_DEPS)
-rm $(SECONDARY_FLASH)
-rm $(SECONDARY_LIST)
-rm main.elf
-rm main.map
-rm -r ./obj
.PHONY: secondary-outputs
secondary-outputs: $(SECONDARY_FLASH) $(SECONDARY_LIST) $(SECONDARY_SIZE)
main.elf: $(OBJS)
${TOOLCHAIN_PREFIX}-gcc \
$(CFLAGS_COMMON) \
-T "sdk/Ld/Link.ld" \
-nostartfiles \
-Xlinker \
--gc-sections \
-Xlinker \
--print-memory-usage \
-Wl,-Map,"main.map" \
-Lobj \
--specs=nano.specs \
--specs=nosys.specs \
-o "main.elf" \
$(OBJS) \
$(LIBS)
%.hex: %.elf
@ ${TOOLCHAIN_PREFIX}-objcopy -O ihex "$<" "$@"
%.lst: %.elf
@ ${TOOLCHAIN_PREFIX}-objdump \
--source \
--all-headers \
--demangle \
--line-numbers \
--wide "$<" > "$@"
%.siz: %.elf
@ ${TOOLCHAIN_PREFIX}-size --format=berkeley "$<"
obj/%.o: ./%.c
@ mkdir --parents $(dir $@)
@ ${TOOLCHAIN_PREFIX}-gcc \
$(CFLAGS_COMMON) \
-DDEBUG=1 \
-I"src/include" \
-I"sdk/StdPeriphDriver/inc" \
-I"sdk/RVMSIS" \
-I"sdk/BLE/LIB" \
-I"sdk/BLE/HAL/include" \
-std=gnu99 \
-MMD \
-MP \
-MF"$(@:%.o=%.d)" \
-MT"$(@)" \
-c \
-o "$@" "$<"
obj/%.o: ./%.S
@ mkdir --parents $(dir $@)
@ ${TOOLCHAIN_PREFIX}-gcc \
$(CFLAGS_COMMON) \
-x assembler \
-MMD \
-MP \
-MF"$(@:%.o=%.d)" \
-MT"$(@)" \
-c \
-o "$@" "$<"
f: clean all
wchisp flash ./main.elf
flash:
wchisp flash ./main.elf