diff --git a/V203/usb/cdc/Makefile b/V203/usb/cdc/Makefile index 52ddce6..c351225 100644 --- a/V203/usb/cdc/Makefile +++ b/V203/usb/cdc/Makefile @@ -1,25 +1,25 @@ +TARGET?= ch32v203 TOOL ?= gcc #TOOL ?= clang -TARGET = ch32v203 PRJ = example -VPATH += ./ch32v203 + +VPATH = . ./$(TARGET) BLD = ./build/ DFLAGS = -d LFLAGS = -g LDLIBS = BFLAGS = --strip-unneeded -CFLAGS = -MMD -Wall -Wno-format -Wno-parentheses -ggdb -fno-exceptions -ffunction-sections -fdata-sections -CFLAGS+= -I. -I./ch32v203 +CFLAGS = -MMD -Wall -Wno-parentheses -ggdb -fno-exceptions -ffunction-sections -fdata-sections +CFLAGS+= -I. -I./$(TARGET) DEL = rm -f # zdrojaky OBJS = main.o hack.o print.o -OBJS += startup.o system.o usb_desc.o -OBJS += cdc_class.o +OBJS += usb_desc.o cdc_class.o -include $(TOOL).mk +include $(TARGET)/$(TOOL).mk BOBJS = $(addprefix $(BLD),$(OBJS)) all: $(BLD) $(PRJ).elf @@ -36,9 +36,6 @@ $(PRJ).elf: $(BOBJS) -@echo "OK." $(COPY) $(BFLAGS) -O binary $(PRJ).elf $(PRJ).bin # preloz co je potreba -$(BLD)%.o: %.S - -@echo [AS $(TOOL),$(TARGET)] $@ - $(AS) -$(CCPU) $< -o $@ $(BLD)%.o: %.c -@echo [CC $(TOOL),$(TARGET)] $@ @$(CC) -std=gnu99 -c $(CFLAGS) $< -o $@ @@ -51,5 +48,5 @@ flash: $(PRJ).elf minichlink -w $(PRJ).bin flash -b # vycisti clean: - $(DEL) $(BLD)* *.lst *.bin *.elf *.map *~ mystrings.inc + $(DEL) $(BLD)* *.lst *.bin *.elf *.map *~ .PHONY: all clean flash run diff --git a/V203/usb/cdc/clang.mk b/V203/usb/cdc/ch32v203/clang.mk similarity index 82% rename from V203/usb/cdc/clang.mk rename to V203/usb/cdc/ch32v203/clang.mk index 06e0028..5e3e2b2 100644 --- a/V203/usb/cdc/clang.mk +++ b/V203/usb/cdc/ch32v203/clang.mk @@ -6,13 +6,13 @@ LD = ld.lld SIZE = llvm-size DUMP = riscv64-unknown-elf-objdump COPY = riscv64-unknown-elf-objcopy -AS = riscv64-unknown-elf-as -#OBJS += startup.o system.o +OBJS += startup.o system.o CCPU = -march=rv32imac -mabi=ilp32 MCPU = $(CCPU) TRIP = riscv32-unknown-none-elf CFLAGS+= -Oz +CFLAGS+= -flto CFLAGS+= -fmessage-length=0 -fsigned-char -I/usr/include/newlib #CFLAGS+= -fconstexpr-steps=2097152 CFLAGS+= --target=$(TRIP) $(MCPU) @@ -20,6 +20,6 @@ LFLAGS+= --Map=$(@:%.elf=%.map) --gc-sections # 16-bit instrukce se do toho asi dostanou až na úrovni LLVM linkeru. # Bohužel to není nikde pořádně popsáno. LFLAGS+= -mllvm -mattr=+c +LFLAGS+= -lto-O3 LFLAGS+= -nostdlib -#LDLIBS+= -L$(SRCDIR)/Ld -T Link.ld -LDLIBS+= -L./ch32v203 -T script.ld +LDLIBS+= -L./$(TARGET) -T script.ld diff --git a/V203/usb/cdc/ch32v203/gcc.mk b/V203/usb/cdc/ch32v203/gcc.mk new file mode 100644 index 0000000..d2b196c --- /dev/null +++ b/V203/usb/cdc/ch32v203/gcc.mk @@ -0,0 +1,20 @@ +# Use gcc / binutils toolchain +PREFIX = riscv64-unknown-elf- +CC = $(PREFIX)gcc +CXX = $(PREFIX)g++ +LD = $(PREFIX)gcc +SIZE = $(PREFIX)size +DUMP = $(PREFIX)objdump +COPY = $(PREFIX)objcopy +OBJS += startup.o system.o +CFLAGS+= -Os +CFLAGS+= -flto +CCPU = -march=rv32imac -mabi=ilp32 +MCPU = $(CCPU) + +CFLAGS+= $(MCPU) -msmall-data-limit=8 -mno-save-restore -fmessage-length=0 -fsigned-char -I/usr/include/newlib +LFLAGS+= -Wl,--Map=$(@:%.elf=%.map),--gc-sections +#LFLAGS+= -Wl,--print-sysroot -- chyba ld ? +LFLAGS+= -flto +LFLAGS+= -Os $(MCPU) -nostartfiles -nostdlib +LDLIBS+= -lgcc -L./$(TARGET) -T script.ld diff --git a/V203/usb/cdc/ch32v203/script.ld b/V203/usb/cdc/ch32v203/script.ld index ff0035b..79eb3dc 100644 --- a/V203/usb/cdc/ch32v203/script.ld +++ b/V203/usb/cdc/ch32v203/script.ld @@ -1,4 +1,4 @@ -ENTRY( Init ) +ENTRY( InterruptVector ) MEMORY { FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 64K diff --git a/V203/usb/cdc/gcc.mk b/V203/usb/cdc/gcc.mk deleted file mode 100644 index b318671..0000000 --- a/V203/usb/cdc/gcc.mk +++ /dev/null @@ -1,21 +0,0 @@ -# Use gcc / binutils toolchain -PREFIX = riscv64-unknown-elf- -CC = $(PREFIX)gcc -CXX = $(PREFIX)g++ -LD = $(PREFIX)gcc -AS = $(PREFIX)as -SIZE = $(PREFIX)size -DUMP = $(PREFIX)objdump -COPY = $(PREFIX)objcopy -#OBJS += startup.o system.o -CFLAGS+= -Os -CCPU = -march=rv32imac -mabi=ilp32 -MCPU = $(CCPU) - -CFLAGS+= $(MCPU) -fmessage-length=0 -I/usr/include/newlib -LFLAGS+= -Wl,--Map=$(@:%.elf=%.map),--gc-sections -#LFLAGS+= -Wl,--print-sysroot -- chyba ld ? -LFLAGS+= -O3 $(MCPU) -nostartfiles -nostdlib -#LFLAGS+= -L${HOME}/Downloads/MRS_Toolchain_Linux_x64_V1.91/RISC-V_Embedded_GCC/riscv-none-embed/lib/rv32imac/ilp32 -lprintf -lc -#LDLIBS+= -L$(SRCDIR)/Ld -T Link.ld -LDLIBS+= -L./ch32v203 -T script.ld