-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakefile
73 lines (58 loc) · 2.12 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
71
72
73
# Source
EXAMPLE = avrshock2-example
EXAMPLE_SOURCES = src/example.c
LIB_SOURCES = src/avrshock2.c
LIB_HEADERS = src/avrshock2.h
# AVR config
MCU = atmega328p
F_CPU = 16000000
# UART config
BAUD = 9600
# AVRSHOCK2 config
MODE = SPI
# SPI SS
PORT_ATT = PORTB
DDR_ATT = DDRB
BIT_ATT = PB2
# SPI MOSI
PORT_CMD = PORTB
DDR_CMD = DDRB
BIT_CMD = PB3
# SPI MISO
PORT_DAT = PORTB
DDR_DAT = DDRB
PIN_DAT = PINB
BIT_DAT = PB4
# SPI SCK
PORT_CLK = PORTB
DDR_CLK = DDRB
BIT_CLK = PB5
# build tools
CC = avr-gcc
AR = avr-ar
OBJCOPY = avr-objcopy
SIZE = avr-size
CFLAGS = -std=c11 -pedantic-errors -Wall -Wextra -Wno-main -DNDEBUG -DAVRSHOCK2_UART_DEBUG \
-Os -flto -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums \
-ffast-math -fstrict-aliasing -ffunction-sections -fdata-sections \
-fwhole-program -ffreestanding -fno-tree-scev-cprop \
-Wl,--relax -fno-unwind-tables -fno-asynchronous-unwind-tables \
-DNDEBUG -mmcu=$(MCU) -DF_CPU=$(F_CPU)UL -DBAUD=$(BAUD) \
-DAVRSHOCK2_PORT_ATT=$(PORT_ATT) -DAVRSHOCK2_DDR_ATT=$(DDR_ATT) -DAVRSHOCK2_BIT_ATT=$(BIT_ATT) \
-DAVRSHOCK2_PORT_CMD=$(PORT_CMD) -DAVRSHOCK2_DDR_CMD=$(DDR_CMD) -DAVRSHOCK2_BIT_CMD=$(BIT_CMD) \
-DAVRSHOCK2_PORT_DAT=$(PORT_DAT) -DAVRSHOCK2_DDR_DAT=$(DDR_DAT) -DAVRSHOCK2_PIN_DAT=$(PIN_DAT) -DAVRSHOCK2_BIT_DAT=$(BIT_DAT) \
-DAVRSHOCK2_PORT_CLK=$(PORT_CLK) -DAVRSHOCK2_DDR_CLK=$(DDR_CLK) -DAVRSHOCK2_BIT_CLK=$(BIT_CLK) \
-DAVRSHOCK2_$(MODE)
# AVRDUDE
AVRDUDE = avrdude
AVRDUDE_PORT = /dev/ttyUSB0
AVRDUDE_PROGRAMMER = arduino
all: $(EXAMPLE)
$(EXAMPLE): $(EXAMPLE_SOURCES) $(LIB_SOURCES) $(LIB_HEADERS)
$(CC) $(CFLAGS) $(EXAMPLE_SOURCES) $(LIB_SOURCES) -o $(EXAMPLE).elf
$(OBJCOPY) -j .text -j .data -O ihex $(EXAMPLE).elf $(EXAMPLE).hex
$(SIZE) $(EXAMPLE).elf
program: $(EXAMPLE)
$(AVRDUDE) -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER) -b 115200 -U flash:w:$(EXAMPLE).hex:i
clean:
rm -rf *.elf *.hex