Skip to content

Instantly share code, notes, and snippets.

@shima-529
Last active March 11, 2021 13:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shima-529/601efe9c1235e71441b6a5d2ed314836 to your computer and use it in GitHub Desktop.
Save shima-529/601efe9c1235e71441b6a5d2ed314836 to your computer and use it in GitHub Desktop.
ARCH = arm-none-eabi
AS = $(ARCH)-gcc -x assembler-with-cpp
CC = $(ARCH)-gcc
LD = $(ARCH)-gcc
TARGET = output.elf
ASMS = ./nrfx/mdk/gcc_startup_nrf51.S
CSRCS = $(wildcard src/*.c) $(wildcard ./nrfx/drivers/src/*.c) nrfx/mdk/system_nrf51.c
OBJS = $(addprefix obj/,$(ASMS:.S=.o) $(CSRCS:.c=.o))
INCLUDES = -I ./nrfx -I ./nrfx/drivers/include -I ./nrfx/mdk -I ./nrfx/hal -I./inc -I ./CMSIS_5/CMSIS/Core/Include -I ./CMSIS_5/Device/ARM/ARMCM0/Include
DEFINES = -DNRF51 -DARMCM0 -D__START=main -D__STARTUP_CLEAR_BSS
FLAGS = -mcpu=cortex-m0 -mthumb -fsingle-precision-constant $(DEFINES)
CFLAGS = $(FLAGS) -ffunction-sections -fdata-sections -Wall -std=gnu11
LDFLAGS = $(FLAGS) -Wl,--gc-sections -T ./nrf51_xxaa.ld -nostartfiles --specs=nano.specs -u _printf_float
LIBS =
all: $(TARGET)
$(ARCH)-size $^
$(TARGET): $(OBJS)
$(LD) $(LDFLAGS) -o $@ $^ $(LIBS)
obj/%.o: %.c
@if [ ! -d $(dir $@) ]; then \
mkdir -p $(dir $@); \
fi
$(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $^
obj/%.o: %.S
@if [ ! -d $(dir $@) ]; then \
mkdir -p $(dir $@); \
fi
$(AS) $(FLAGS) -c -o $@ $^
.PHONY: flash
flash: $(TARGET)
openocd -f interface/cmsis-dap.cfg -f target/nrf51.cfg -c 'program output.elf;reset;exit'
.PHONY: clean
clean:
$(RM) -r $(TARGET) obj
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment