-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
47 lines (36 loc) · 1.17 KB
/
Makefile
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
FAMILY := nrf51
SOURCES := main.c uart.c
BUILD_DIR := .build_system
LINKER_SCRIPT := $(BUILD_DIR)/linker_script.ld
GNU_PREFIX := arm-none-eabi
CC := $(GNU_PREFIX)-gcc
OBJCOPY := $(GNU_PREFIX)-objcopy
OBJDUMP := $(GNU_PREFIX)-objdump
QUIET := @
## Compiler flags
# CPU specific
CFLAGS += -mcpu=cortex-m0 -mthumb -mabi=aapcs -mfloat-abi=soft
# Get linker optimization for free
CFLAGS += -ffunction-sections -fdata-sections --short-enums
CFLAGS += -fno-strict-aliasing -fno-builtin
# Good pracice
CFLAGS += -Wall -Werror -std=gnu99
# CFLAGS += -ggdb -Og / -O0 / -O3 etc
## Linker flags
CFLAGS += --specs=nosys.specs -Wl,--gc-sections -T $(LINKER_SCRIPT)
# or --specs=nano.specs -lc -lnosys
SOURCES += $(BUILD_DIR)/system_nrf51.c
SOURCES += $(BUILD_DIR)/gcc_startup_nrf51.S
.PHONY: default flash clean
default:
@echo Compiling project
$(QUIET)$(CC) $(CFLAGS) $(SOURCES) -o $(BUILD_DIR)/main.elf
@echo Creating hex file
$(QUIET)$(OBJCOPY) -O ihex $(BUILD_DIR)/main.elf $(BUILD_DIR)/main.hex
flash:
nrfjprog -f $(FAMILY) --sectorerase --program $(BUILD_DIR)/main.hex
nrfjprog -f $(FAMILY) --reset
erase:
nrfjprog -f $(FAMILY) --eraseall
clean:
$(QUIET)rm $(BUILD_DIR)/main.{elf,hex}