CH592_Makefile_Template/Makefile

176 lines
3.8 KiB
Makefile
Raw Normal View History

2023-12-20 16:58:45 +01:00
## 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 += \
2024-05-10 02:40:12 +02:00
./src/main.c
2023-12-20 16:58:45 +01:00
SDK_BLE_HAL_C_SRCS := \
./sdk/BLE/HAL/MCU.c \
./sdk/BLE/HAL/RTC.c \
./sdk/BLE/HAL/SLEEP.c
2024-05-11 14:03:47 +02:00
2023-12-20 16:58:45 +01:00
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 \
2024-05-11 14:03:47 +02:00
./sdk/StdPeriphDriver/CH59x_pwm.c \
2023-12-20 16:58:45 +01:00
./sdk/StdPeriphDriver/CH59x_pwr.c \
2024-05-11 14:03:47 +02:00
./sdk/StdPeriphDriver/CH59x_spi0.c \
2023-12-20 16:58:45 +01:00
./sdk/StdPeriphDriver/CH59x_sys.c \
2024-05-11 14:03:47 +02:00
./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_usbhestClass.c
2023-12-20 16:58:45 +01:00
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)
2024-05-10 02:40:12 +02:00
SECONDARY_FLASH := main.hex
SECONDARY_LIST := main.lst
SECONDARY_SIZE := main.siz
2023-12-20 16:58:45 +01:00
# 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 \
2024-05-10 02:40:12 +02:00
-fdata-sections
#-g
2023-12-20 16:58:45 +01:00
.PHONY: all
2024-05-10 02:40:12 +02:00
all: main.elf secondary-outputs
2023-12-20 16:58:45 +01:00
.PHONY: clean
clean:
-rm $(OBJS)
-rm $(MAKEFILE_DEPS)
-rm $(SECONDARY_FLASH)
-rm $(SECONDARY_LIST)
2024-05-10 02:40:12 +02:00
-rm main.elf
-rm main.map
-rm -r ./obj
2023-12-20 16:58:45 +01:00
.PHONY: secondary-outputs
secondary-outputs: $(SECONDARY_FLASH) $(SECONDARY_LIST) $(SECONDARY_SIZE)
2024-05-10 02:40:12 +02:00
main.elf: $(OBJS)
2023-12-20 16:58:45 +01:00
${TOOLCHAIN_PREFIX}-gcc \
$(CFLAGS_COMMON) \
-T "sdk/Ld/Link.ld" \
-nostartfiles \
-Xlinker \
--gc-sections \
-Xlinker \
--print-memory-usage \
2024-05-10 02:40:12 +02:00
-Wl,-Map,"main.map" \
2023-12-20 16:58:45 +01:00
-Lobj \
--specs=nano.specs \
--specs=nosys.specs \
2024-05-10 02:40:12 +02:00
-o "main.elf" \
2023-12-20 16:58:45 +01:00
$(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 \
2024-05-10 02:40:12 +02:00
-I"src/include" \
2023-12-20 16:58:45 +01:00
-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 "$@" "$<"
2024-05-10 02:40:12 +02:00
f: clean all
wchisp flash ./main.elf
2024-05-11 12:55:33 +02:00
flash:
wchisp flash ./main.elf