-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
70 lines (57 loc) · 1.78 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# Makefile
TARGET = I2c-debug
LIBDIR = ../lib
OBJECTS = main.o \
i2c-scan.o \
i2c-cmd.o \
../Uart/id.o \
$(LIBDIR)/timers.o \
$(LIBDIR)/uart.o \
$(LIBDIR)/twi.o \
$(LIBDIR)/rpu_mgr.o \
$(LIBDIR)/adc.o \
$(LIBDIR)/parse.o
## Chip and project-specific global definitions
MCU = atmega328p
F_CPU = 16000000UL
BAUD = 38400UL
CPPFLAGS = -DF_CPU=$(F_CPU) -DBAUD=$(BAUD) -I.
## Cross-compilation
CC = avr-gcc
OBJCOPY = avr-objcopy
OBJDUMP = avr-objdump
SIZE = avr-size
# FTDI's USB to serial bridge shows as /dev/ttyUSB0,
# Uno's serial bridge (an ATmega16U2) shows as /dev/ttyACM0 (a modem,?)
# Pi Zero on chip hardware serial shows as /dev/ttyAMA0 (hardware UART on a Linux system)
detect_PORT := $(shell sh -c 'ls /dev/ttyAMA0 2>/dev/null || echo not')
ifeq ($(detect_PORT),/dev/ttyAMA0)
BOOTLOAD_PORT = /dev/ttyAMA0
endif
detect_PORT := $(shell sh -c 'ls /dev/ttyUSB0 2>/dev/null || echo not')
ifeq ($(detect_PORT),/dev/ttyUSB0)
BOOTLOAD_PORT = /dev/ttyUSB0
endif
## Compiler/linker options
CFLAGS = -Os -g -std=gnu99 -Wall
# CFLAGS += -funsigned-char -funsigned-bitfields
# CFLAGS += -fpack-struct -fshort-enums
CFLAGS += -ffunction-sections -fdata-sections
TARGET_ARCH = -mmcu=$(MCU)
LDFLAGS = -Wl,-Map,$(TARGET).map
LDFLAGS += -Wl,--gc-sections
all: $(TARGET).hex $(TARGET).lst
$(TARGET): $(TARGET).hex
$(TARGET).hex: $(TARGET).elf
$(OBJCOPY) -j .text -j .data -O ihex $< $@
## works with optiboot which erases flash without being told (e.g. -e )
bootload:
avrdude -v -p $(MCU) -c arduino -P $(BOOTLOAD_PORT) -b 38400 -U flash:w:$(TARGET).hex
$(TARGET).elf: $(OBJECTS)
$(CC) $(LDFLAGS) $(TARGET_ARCH) $^ -o $@
$(SIZE) -C --mcu=$(MCU) $@
rm -f $(TARGET).o $(OBJECTS)
clean:
rm -f $(TARGET).hex $(TARGET).map $(TARGET).elf $(TARGET).lst
%.lst: %.elf
$(OBJDUMP) -h -S $< > $@