135 lines
3.0 KiB
Makefile
135 lines
3.0 KiB
Makefile
# Toolchain
|
|
PREFIX = arm-none-eabi-
|
|
CC = $(PREFIX)gcc
|
|
AS = $(PREFIX)as
|
|
LD = $(PREFIX)ld
|
|
OBJCOPY = $(PREFIX)objcopy
|
|
SIZE = $(PREFIX)size
|
|
|
|
# Project configuration
|
|
PROJECT = firmware
|
|
MCU = cortex-m4
|
|
FLASH_START = 0x00000000
|
|
LOAD_ADDRESS = 0x10002000
|
|
LD_FILE=linker.ld
|
|
|
|
RAM_START := 0x10002000
|
|
|
|
# Compiler flags
|
|
CFLAGS = -mcpu=$(MCU) -mthumb \
|
|
-Wall -Wextra -g3 \
|
|
-Os -ffunction-sections -fdata-sections \
|
|
-nostartfiles -Wl,-T,$(LD_FILE) -u main -Wl,--gc-sections \
|
|
-DLOAD_ADDRESS=$(LOAD_ADDRESS)
|
|
|
|
ASFLAGS = \
|
|
-mcpu=$(MCU) -mthumb \
|
|
-g
|
|
|
|
LDFLAGS = \
|
|
-T linker.ld -Map=$(BUILD_DIR)/$(PROJECT).map \
|
|
--gc-sections --no-warn-rwx-segments \
|
|
--defsym=_RAM_START_ADDR=$(RAM_START)
|
|
|
|
# Directories
|
|
SRC_DIR = src
|
|
BUILD_DIR = build
|
|
INCLUDE_DIR = include
|
|
|
|
# Source files
|
|
SRCS = $(wildcard $(SRC_DIR)/*.c)
|
|
ASM_SRCS = $(wildcard $(SRC_DIR)/*.s)
|
|
OBJS = $(SRCS:$(SRC_DIR)/%.c=$(BUILD_DIR)/%.o)
|
|
ASM_OBJS = $(ASM_SRCS:$(SRC_DIR)/%.s=$(BUILD_DIR)/%.o)
|
|
|
|
# Include paths
|
|
INCLUDES = -I$(INCLUDE_DIR)
|
|
|
|
# Output files
|
|
ELF = $(BUILD_DIR)/$(PROJECT).elf
|
|
BIN = $(BUILD_DIR)/$(PROJECT).bin
|
|
HEX = $(BUILD_DIR)/$(PROJECT).hex
|
|
|
|
# flashing
|
|
INTERFACE = stlink
|
|
OPENOCD_BASE=openocd -f interface/$(INTERFACE).cfg -f rtl8710_openocd/script/rtl8710.ocd -c "init" -c "reset" -c "halt"
|
|
FLASH_BIN = $(BUILD_DIR)/$(PROJECT).bin
|
|
|
|
.PHONY: all clean flash size
|
|
|
|
# Default target
|
|
all: $(BUILD_DIR) $(ELF) $(BIN) $(HEX) size
|
|
|
|
# Create build directory
|
|
$(BUILD_DIR):
|
|
mkdir -p $(BUILD_DIR)
|
|
|
|
# Compile C files
|
|
$(BUILD_DIR)/%.o: $(SRC_DIR)/%.c
|
|
@echo "CC $<"
|
|
@$(CC) $(CFLAGS) $(INCLUDES) -c $< -o $@
|
|
|
|
# Compile assembly files
|
|
$(BUILD_DIR)/%.o: $(SRC_DIR)/%.s
|
|
@echo "AS $<"
|
|
@$(AS) $(ASFLAGS) -c $< -o $@
|
|
|
|
# Link
|
|
$(ELF): $(OBJS) $(ASM_OBJS)
|
|
@echo "LD $@"
|
|
@$(LD) $(LDFLAGS) -o $@ $^
|
|
|
|
# Generate binary
|
|
$(BIN): $(ELF)
|
|
@echo "OBJCOPY $@"
|
|
@$(OBJCOPY) -O binary $< $@
|
|
|
|
# Generate Intel HEX file
|
|
$(HEX): $(ELF)
|
|
@echo "OBJCOPY $@"
|
|
@$(OBJCOPY) -O ihex $< $@
|
|
|
|
# Print size information
|
|
size: $(ELF)
|
|
@echo
|
|
@$(SIZE) $<
|
|
|
|
# flash commands
|
|
test:
|
|
$(OPENOCD_BASE) -c "rtl8710_flash_read_id" -c "shutdown"
|
|
|
|
mac:
|
|
$(OPENOCD_BASE) -c "rtl8710_flash_read_mac" -c "shutdown"
|
|
|
|
dump:
|
|
$(OPENOCD_BASE) -c "rtl8710_flash_read_id" -c "rtl8710_flash_read dump.bin 0 1048576" -c "shutdown"
|
|
|
|
dump0:
|
|
$(OPENOCD_BASE) -c "rtl8710_flash_read_id" -c "rtl8710_flash_read dump0.bin 0 4096" -c "shutdown"
|
|
|
|
flash:
|
|
@$(OPENOCD_BASE) -c 'rtl8710_flash_auto_erase 1' \
|
|
-c 'rtl8710_flash_auto_verify 1' \
|
|
-c 'rtl8710_flash_write $(FLASH_BIN) 0' \
|
|
-c 'rtl8710_reboot' -c 'reset run' -c shutdown
|
|
|
|
full_erase:
|
|
$(OPENOCD_BASE) -c "rtl8710_flash_mass_erase" -c shutdown
|
|
|
|
restore:
|
|
$(OPENOCD_BASE) -c "rtl8710_flash_auto_erase 1" -c "rtl8710_flash_auto_verify 1" -c "rtl8710_flash_write dump.bin 0" -c shutdown
|
|
|
|
restore_nae:
|
|
$(OPENOCD_BASE) -c "rtl8710_flash_auto_erase 0" -c "rtl8710_flash_auto_verify 1" -c "rtl8710_flash_write dump.bin 0" -c shutdown
|
|
|
|
verify:
|
|
$(OPENOCD_BASE) -c "rtl8710_flash_verify dump.bin 0" -c shutdown
|
|
|
|
reset:
|
|
$(OPENOCD_BASE) -c "rtl8710_reboot" -c shutdown
|
|
|
|
# Clean build files
|
|
clean:
|
|
rm -rf $(BUILD_DIR)
|
|
|