-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmakefile
More file actions
115 lines (94 loc) · 4.05 KB
/
makefile
File metadata and controls
115 lines (94 loc) · 4.05 KB
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
# ===================================================================================
# Project Makefile
# ===================================================================================
# Project: CH32V003 Joypad Calibrator
# Author: Stefan Wagner
# Year: 2023
# URL: https://github.com/wagiminator
# ===================================================================================
# Install toolchain:
# sudo apt install build-essential libnewlib-dev gcc-riscv64-unknown-elf
# sudo apt install python3 python3-pip
# pip install rvprog
#
# Provide access permission to WCH-LinkE programmer:
# echo 'SUBSYSTEM=="usb", ATTR{idVendor}=="1a86", ATTR{idProduct}=="8010", MODE="666"' | sudo tee /etc/udev/rules.d/99-WCH-LinkE.rules
# echo 'SUBSYSTEM=="usb", ATTR{idVendor}=="1a86", ATTR{idProduct}=="8012", MODE="666"' | sudo tee -a /etc/udev/rules.d/99-WCH-LinkE.rules
# sudo udevadm control --reload-rules
#
# Connect WCH-LinkE programmer to your board. Type "make flash" in the command line.
# ===================================================================================
# Files and Folders
TARGET = splash
INCLUDE = include
SOURCE = src
BIN = bin
# Microcontroller Settings
F_CPU = 12000000
LDSCRIPT = ld/ch32v003.ld
CPUARCH = -march=rv32ec -mabi=ilp32e
# Toolchain
PREFIX = riscv64-unknown-elf
CC = $(PREFIX)-gcc
OBJCOPY = $(PREFIX)-objcopy
OBJDUMP = $(PREFIX)-objdump
OBJSIZE = $(PREFIX)-size
NEWLIB = /usr/include/newlib
ISPTOOL = rvprog -f $(BIN)/$(TARGET).bin
CLEAN = rm -f *.lst *.obj *.cof *.list *.map *.eep.hex *.o *.d
# Compiler Flags
CFLAGS = -g -Os -flto -ffunction-sections -fdata-sections -fno-builtin -nostdlib
CFLAGS += $(CPUARCH) -DF_CPU=$(F_CPU) -I$(NEWLIB) -I$(INCLUDE) -I$(SOURCE) -I. -Wall
LDFLAGS = -T$(LDSCRIPT) -lgcc -Wl,--gc-sections,--build-id=none
CFILES = $(wildcard ./*.c) $(wildcard $(SOURCE)/*.c) $(wildcard $(SOURCE)/*.S)
# Symbolic Targets
help:
@echo "Use the following commands:"
@echo "make all compile and build $(TARGET).elf/.bin/.hex/.asm"
@echo "make hex compile and build $(TARGET).hex"
@echo "make asm compile and disassemble to $(TARGET).asm"
@echo "make bin compile and build $(TARGET).bin"
@echo "make flash compile and upload to MCU"
@echo "make clean remove all build files"
$(BIN)/$(TARGET).elf: $(CFILES)
@echo "Building $(BIN)/$(TARGET).elf ..."
@mkdir -p $(BIN)
@$(CC) -o $@ $^ $(CFLAGS) $(LDFLAGS)
$(BIN)/$(TARGET).lst: $(BIN)/$(TARGET).elf
@echo "Building $(BIN)/$(TARGET).lst ..."
@$(OBJDUMP) -S $^ > $(BIN)/$(TARGET).lst
$(BIN)/$(TARGET).map: $(BIN)/$(TARGET).elf
@echo "Building $(BIN)/$(TARGET).map ..."
@$(OBJDUMP) -t $^ > $(BIN)/$(TARGET).map
$(BIN)/$(TARGET).bin: $(BIN)/$(TARGET).elf
@echo "Building $(BIN)/$(TARGET).bin ..."
@$(OBJCOPY) -O binary $< $(BIN)/$(TARGET).bin
$(BIN)/$(TARGET).hex: $(BIN)/$(TARGET).elf
@echo "Building $(BIN)/$(TARGET).hex ..."
@$(OBJCOPY) -O ihex $< $(BIN)/$(TARGET).hex
$(BIN)/$(TARGET).asm: $(BIN)/$(TARGET).elf
@echo "Disassembling to $(BIN)/$(TARGET).asm ..."
@$(OBJDUMP) -d $(BIN)/$(TARGET).elf > $(BIN)/$(TARGET).asm
all: $(BIN)/$(TARGET).lst $(BIN)/$(TARGET).map $(BIN)/$(TARGET).bin $(BIN)/$(TARGET).hex $(BIN)/$(TARGET).asm size
elf: $(BIN)/$(TARGET).elf removetemp size
bin: $(BIN)/$(TARGET).bin removetemp size removeelf
hex: $(BIN)/$(TARGET).hex removetemp size removeelf
asm: $(BIN)/$(TARGET).asm removetemp size removeelf
flash: $(BIN)/$(TARGET).bin size removeelf
@echo "Uploading to MCU ..."
@$(ISPTOOL)
clean:
@echo "Cleaning all up ..."
@$(CLEAN)
@rm -f $(BIN)/$(TARGET).elf $(BIN)/$(TARGET).lst $(BIN)/$(TARGET).map $(BIN)/$(TARGET).bin $(BIN)/$(TARGET).hex $(BIN)/$(TARGET).asm
size:
@echo "------------------"
@echo "FLASH: $(shell $(OBJSIZE) -d $(BIN)/$(TARGET).elf | awk '/[0-9]/ {print $$1 + $$2}') bytes"
@echo "SRAM: $(shell $(OBJSIZE) -d $(BIN)/$(TARGET).elf | awk '/[0-9]/ {print $$2 + $$3}') bytes"
@echo "------------------"
removetemp:
@echo "Removing temporary files ..."
@$(CLEAN)
removeelf:
@echo "Removing $(BIN)/$(TARGET).elf ..."
@rm -f $(BIN)/$(TARGET).elf