@@ -7,11 +7,6 @@ TARGET = badgemagic-ch582
77# #####################################
88# building variables
99# #####################################
10- # Uncomment below line to enable debugging
11- # DEBUG = 1
12- # Uncomment below to build for USB-C version
13- # USBC_VERSION = 1
14- # optimization for size
1510OPT = -Os
1611
1712
@@ -27,13 +22,11 @@ endif
2722# ######################################
2823# paths
2924# ######################################
30- # Build path
3125BUILD_DIR ?= build
3226
3327# #####################################
3428# source
3529# #####################################
36- # C sources
3730C_SOURCES = \
3831CH5xx_ble_firmware_library/StdPeriphDriver/CH58x_i2c.c \
3932CH5xx_ble_firmware_library/StdPeriphDriver/CH58x_timer2.c \
@@ -82,15 +75,13 @@ src/xbm.c \
8275src/resource.c \
8376src/animation.c \
8477src/font.c \
85- src/power.c
78+ src/power.c
8679
87-
88- # ASM sources
89- ASM_SOURCES = \
80+ ASM_SOURCES = \
9081CH5xx_ble_firmware_library/Startup/startup_CH583.S
9182
9283# ######################################
93- # binaries
84+ # toolchain
9485# ######################################
9586PREFIX ?= riscv-none-embed-
9687
@@ -103,77 +94,46 @@ HEX = $(CP) -O ihex
10394BIN = $(CP ) -O binary -S
10495
10596# ######################################
106- # CFLAGS
97+ # flags
10798# ######################################
108- # cpu
109- CPU = -march=rv32imac -mabi=ilp32 -msmall-data-limit=8
110-
111- # fpu
112- FPU =
113-
114- # float-abi
115- FLOAT-ABI =
99+ CPU = -march=rv32imac -mabi=ilp32 -msmall-data-limit=8
100+ MCU = $(CPU )
116101
117- # mcu
118- MCU = $(CPU ) $(FPU ) $(FLOAT-ABI )
119-
120- # AS includes
121- AS_INCLUDES =
122-
123- # C includes
124- C_INCLUDES = \
102+ C_INCLUDES = \
125103-ICH5xx_ble_firmware_library/StdPeriphDriver/inc \
126104-ICH5xx_ble_firmware_library/RVMSIS \
127105-ICH5xx_ble_firmware_library/Core \
128- -ICH5xx_ble_firmware_library/BLE
106+ -ICH5xx_ble_firmware_library/BLE
129107
130- # compile gcc flags
131- ASFLAGS = $(MCU ) $(AS_INCLUDES ) $(OPT ) -Wall -fdata-sections -ffunction-sections
108+ ASFLAGS = $(MCU ) $(OPT ) -Wall -fdata-sections -ffunction-sections
132109
133110CFLAGS = $(MCU ) $(C_INCLUDES ) $(OPT ) -Wall -fdata-sections -ffunction-sections
134111CFLAGS += -Werror=implicit-function-declaration
135-
136- ifeq ($(DEBUG ) , 1)
137- CFLAGS += -g -gdwarf-2 -DDEBUG=$(DEBUG )
138- endif
139-
140- ifeq ($(USBC_VERSION ) , 1)
141- CFLAGS += -DUSBC_VERSION=$(USBC_VERSION )
142- endif
143-
144112CFLAGS += -DVERSION='"$(VERSION ) "' -DVERSION_ABBR='"$(VERSION_ABBR ) "'
145-
146- # Generate dependency information
147113CFLAGS += -MMD -MP
148114
149-
150115# ######################################
151- # LDFLAGS
116+ # linker
152117# ######################################
153- # link script
154- LDSCRIPT = CH5xx_ble_firmware_library/Ld/Link.ld
118+ LDSCRIPT = CH5xx_ble_firmware_library/Ld/Link.ld
155119
156- # libraries
157120LIBS = -lc -lm -lnosys \
158- ./CH5xx_ble_firmware_library/StdPeriphDriver/libISP583.a \
159- ./CH5xx_ble_firmware_library/BLE/LIBCH58xBLE.a
160-
161- LIBDIR =
162- LDFLAGS = $(MCU ) -mno-save-restore -fmessage-length=0 -fsigned-char -ffunction-sections -fdata-sections -Wunused -Wuninitialized -T $(LDSCRIPT ) -nostartfiles -Xlinker --gc-sections -Wl,-Map=$(BUILD_DIR ) /$(TARGET ) .map --specs=nano.specs $(LIBS )
163-
164- # default action: build all
165- all : $(BUILD_DIR ) /$(TARGET ) .elf $(BUILD_DIR ) /$(TARGET ) .hex $(BUILD_DIR ) /$(TARGET ) .bin
121+ ./CH5xx_ble_firmware_library/StdPeriphDriver/libISP583.a \
122+ ./CH5xx_ble_firmware_library/BLE/LIBCH58xBLE.a
166123
124+ LDFLAGS = $(MCU ) -mno-save-restore -fmessage-length=0 -fsigned-char \
125+ -ffunction-sections -fdata-sections -Wunused -Wuninitialized \
126+ -T $(LDSCRIPT ) -nostartfiles -Xlinker --gc-sections \
127+ -Wl,-Map=$(BUILD_DIR ) /$(TARGET ) .map --specs=nano.specs $(LIBS )
167128
168129# ######################################
169- # build the application
130+ # build rules
170131# ######################################
171- # list of objects
172132OBJECTS = $(addprefix $(BUILD_DIR ) /, $(C_SOURCES:.c=.o ) )
173-
174- # list of ASM program objects
175133OBJECTS += $(addprefix $(BUILD_DIR ) /, $(ASM_SOURCES:.S=.o ) )
176134
135+ all : $(BUILD_DIR ) /$(TARGET ) .elf $(BUILD_DIR ) /$(TARGET ) .hex $(BUILD_DIR ) /$(TARGET ) .bin
136+
177137$(BUILD_DIR ) /% .o : % .c Makefile
178138 @mkdir -pv $(dir $@ )
179139 $(CC ) -c $(CFLAGS ) -Wa,-a,-ad,-alms=$(@:.o=.lst ) $< -o $@
@@ -190,33 +150,22 @@ $(BUILD_DIR)/$(TARGET).elf: $(OBJECTS) Makefile
190150$(BUILD_DIR ) /% .hex : $(BUILD_DIR ) /% .elf
191151 @mkdir -pv $(dir $@ )
192152 $(HEX ) $< $@
193-
153+
194154$(BUILD_DIR ) /% .bin : $(BUILD_DIR ) /% .elf
195155 @mkdir -pv $(dir $@ )
196- $(BIN ) $< $@
197-
198- # ######################################
199- # Program
200- # ######################################
201- program : $(BUILD_DIR ) /$(TARGET ) .elf
202- sudo wch-openocd -f /usr/share/wch-openocd/openocd/scripts/interface/wch-riscv.cfg -c ' init; halt; program $(BUILD_DIR)/$(TARGET).elf; reset; wlink_reset_resume; exit;'
203-
204- isp : $(BUILD_DIR ) /$(TARGET ) .bin
205- wchisp flash $(BUILD_DIR ) /$(TARGET ) .bin
156+ $(BIN ) $< $@
206157
207158# ######################################
208- # clean up
159+ # clean
209160# ######################################
210161clean :
211162 rm -f $(OBJECTS )
212163 rm -f $(OBJECTS:%.o=%.d )
213164 rm -f $(OBJECTS:%.o=%.lst )
214165 rm -f $(BUILD_DIR ) /$(TARGET ) .*
215- find $(BUILD_DIR ) -type d -empty -delete
166+ find $(BUILD_DIR ) -type d -empty -delete
216167
217168# ######################################
218- # dependencies
169+ # deps
219170# ######################################
220- -include $(OBJECTS :% .o=% .d)
221-
222- # *** EOF ***
171+ -include $(OBJECTS :% .o=% .d)
0 commit comments