-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
70 lines (55 loc) · 1.92 KB
/
Makefile
File metadata and controls
70 lines (55 loc) · 1.92 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
#
# Makefile for building an ARM Cortex-M4 project and running it in QEMU.
#
# --- Toolchain Definition ---
PREFIX = arm-none-eabi-
CC = $(PREFIX)gcc
AS = $(PREFIX)as
LD = $(PREFIX)gcc
OBJCOPY = $(PREFIX)objcopy
GDB = $(PREFIX)gdb
# --- Project Files ---
C_SOURCES = src/main.c src/tusk.c src/uart.c src/m_queue.c src/mem.c
ASM_SOURCES = src/rtos_asm.s src/startup.s
OBJECTS = $(C_SOURCES:.c=.o) $(ASM_SOURCES:.s=.o)
TARGET_ELF= rtos_project.elf
TARGET_BIN= rtos_project.bin
# --- Build Flags ---
CPU_FLAGS = -mcpu=cortex-m4 -mthumb -mfloat-abi=soft
SPECS = --specs=nosys.specs
CFLAGS = $(CPU_FLAGS) -g -O0 -Wall -Iinclude $(SPECS)
LDFLAGS = $(CPU_FLAGS) -nostdlib -Tqemu.ld -Wl,-Map=$(TARGET_ELF:.elf=.map) $(SPECS)
# --- QEMU Settings ---
QEMU_MACHINE = netduinoplus2
QEMU = qemu-system-arm
QEMU_FLAGS = -M $(QEMU_MACHINE) -kernel $(TARGET_ELF) -nographic -serial mon:stdio
# --- Build Rules ---
all: $(TARGET_BIN)
$(TARGET_ELF): $(OBJECTS)
@echo "[LD] Linking to create $(TARGET_ELF)"
$(LD) $(LDFLAGS) -o $@ $^
$(TARGET_BIN): $(TARGET_ELF)
@echo "[OBJCOPY] Creating $(TARGET_BIN)"
$(OBJCOPY) -O binary $< $@
%.o: %.c
@echo "[CC] Compiling $<"
$(CC) $(CFLAGS) -c -o $@ $<
%.o: %.s
@echo "[AS] Assembling $<"
$(CC) $(CFLAGS) -c -o $@ $<
# --- QEMU & Debugging Rules ---
run: all
@echo "[QEMU] Starting emulation. Press Ctrl+A, then X to exit."
$(QEMU) $(QEMU_FLAGS)
# In 'debug' mode, we use a separate port for GDB and leave stdio for the monitor.
debug: all
@echo "[QEMU-GDB] Starting GDB server on tcp::1234. Waiting for connection..."
$(QEMU) -M $(QEMU_MACHINE) -kernel $(TARGET_ELF) -nographic -S -gdb tcp::1234
gdb:
@echo "[GDB] Connecting to QEMU GDB server..."
$(GDB) -ex "target remote localhost:1234" $(TARGET_ELF)
# --- Housekeeping ---
clean:
@echo "[CLEAN] Removing build artifacts."
rm -f src/*.o $(TARGET_ELF) $(TARGET_BIN) *.map
.PHONY: all run debug gdb clean