65 lines
2.2 KiB
Makefile
65 lines
2.2 KiB
Makefile
REV := master
|
|
BASE := https://raw.githubusercontent.com/cnlohr/ch32v003fun/$(REV)/ch32fun
|
|
CURL_FLAGS := -O -\# --fail --location --tlsv1.3 --proto =https --max-time 300
|
|
|
|
TARGET = blink
|
|
TARGET_MCU?=CH32V003
|
|
NEWLIB=/usr/arm-none-eabi/include
|
|
CFLAGS=-g -Os -flto -ffunction-sections -fdata-sections -fmessage-length=0 -msmall-data-limit=8
|
|
LDFLAGS+=-Wl,--print-memory-usage -Wl,-Map=$(TARGET).map
|
|
PREFIX := riscv64-linux-gnu
|
|
CC := $(PREFIX)-gcc
|
|
|
|
# riscv64-linux-gnu-gcc -E -P -x c -DTARGET_MCU=CH32V003 -DMCU_PACKAGE= -DTARGET_MCU_LD=0 -DTARGET_MCU_MEMORY_SPLIT= ../../ch32fun/ch32fun.ld > ../../ch32fun/generated_ch32v003.ld
|
|
# riscv64-linux-gnu-gcc -o blink.elf ../../ch32fun/ch32fun.c blink.c -g -Os -flto -ffunction-sections -fdata-sections -fmessage-length=0 -msmall-data-limit=8 -march=rv32ec -mabi=ilp32e -DCH32V003=1 -static-libgcc -I/usr/arm-none-eabi/include -I../../ch32fun/../extralibs -I../../ch32fun -nostdlib -I. -Wall -Wl,--print-memory-usage -Wl,-Map=blink.map -L../../ch32fun/../misc -lgcc -T ../../ch32fun/generated_ch32v003.ld -Wl,--gc-sections
|
|
|
|
# Correct?
|
|
EXTFLAGS := -march=rv32ec -mabi=ilp32e -DCH32V003=1 -static-libgcc -I/usr/arm-none-eabi/include -nostdlib -I. -Wall -L. -lgcc -T ch32v003.ld -Wl,--gc-sections
|
|
|
|
default: $(TARGET).bin
|
|
|
|
$(TARGET).elf: ch32fun.c blink.c | ch32v003.ld ch32fun.h ch32v003hw.h
|
|
@echo CC $@
|
|
@$(CC) $(CFLAGS) $(LDFLAGS) $(EXTFLAGS) -o $@ $^
|
|
|
|
ch32v003.ld: ch32fun.ld
|
|
@riscv64-linux-gnu-gcc -E -P -x c -DTARGET_MCU=$(TARGET_MCU) -DMCU_PACKAGE= -DTARGET_MCU_LD=0 -DTARGET_MCU_MEMORY_SPLIT= $< > $@
|
|
|
|
ch32fun.ld:
|
|
@curl $(CURL_FLAGS) $(BASE)/ch32fun.ld
|
|
|
|
ch32fun.c:
|
|
@curl $(CURL_FLAGS) $(BASE)/ch32fun.c
|
|
|
|
ch32v003hw.h:
|
|
@curl $(CURL_FLAGS) $(BASE)/ch32v003hw.h
|
|
|
|
ch32fun.h:
|
|
@curl $(CURL_FLAGS) $(BASE)/ch32fun.h
|
|
|
|
deps:
|
|
@curl $(CURL_FLAGS) $(BASE)/ch32fun.ld
|
|
@curl $(CURL_FLAGS) $(BASE)/ch32v003hw.h
|
|
@curl $(CURL_FLAGS) $(BASE)/ch32fun.c
|
|
@curl $(CURL_FLAGS) $(BASE)/ch32fun.h
|
|
|
|
$(TARGET).bin : $(TARGET).elf
|
|
$(PREFIX)-objdump -S $^ > $(TARGET).lst
|
|
$(PREFIX)-objcopy -O binary $< $(TARGET).bin
|
|
$(PREFIX)-objcopy -O ihex $< $(TARGET).hex
|
|
|
|
flash:
|
|
minichlink -w $(TARGET).bin flash -b
|
|
|
|
clean:
|
|
rm -f ch32*.[ch]
|
|
rm -f *.ld
|
|
rm -f *.hex
|
|
rm -f *.bin
|
|
rm -f *.map
|
|
rm -f *.lst
|
|
rm -f *.elf
|
|
rm -f *.ld
|
|
|
|
.PHONY: clean flash deps default
|
|
|