-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
112 lines (81 loc) · 2.59 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#############
# Variables #
#############
# Device type (GCC)
DEVICE = atmega328p
# Clock frequency in Hz
F_CPU = 16000000
# Programmer software
PROGRAMMER_SOFTWARE = avrdude
# Programmer software parameters
PROGRAMMER_SOFTWARE_PARAMETERS = -c usbtiny -p m328p -F
# Extended fuse byte of microcontroller
EXTENDED_FUSE = efuse:w:0xff:m
# High fuse byte of microcontroller
HIGH_FUSE = hfuse:w:0xd8:m
# Low fuse byte of microcontroller
LOW_FUSE = lfuse:w:0xff:m
# Start bootloader section
START_BOOTLOADER_SECTION = 0x7000
# Linker
LD = avr-gcc
# Compiler
CC = avr-gcc
# Objcopy
OBJCOPY = avr-objcopy
# Linker flags
LDFLAGS = -O1 -DF_CPU=$(F_CPU) -mmcu=$(DEVICE) -Ttext=$(START_BOOTLOADER_SECTION)
# Compiler flags
CFLAGS = -O1 -c -DF_CPU=$(F_CPU) -mmcu=$(DEVICE) -Ttext=$(START_BOOTLOADER_SECTION)
# Object Files
OBJECTS = main.o standard_library/standard_library.o platforms/megaavr/http_user_interface.o platforms/megaavr/uart.o platforms/megaavr/wiznet_5100.o
###################
# Building Events #
###################
# Last event
all: binaries/bootloader.hex binaries/bootloader.bin
# Create bootloader.bin
binaries/bootloader.bin: binaries/bootloader.elf
$(OBJCOPY) -j .text -j .data -O binary $? $@
# Create bootloader.hex
binaries/bootloader.hex: binaries/bootloader.elf
$(OBJCOPY) -j .text -j .data -O ihex $? $@
# Create bootloader.elf
binaries/bootloader.elf: $(OBJECTS)
$(LD) $(LDFLAGS) $? -o $@
# Create main object
main.o: main.c
$(CC) $(CFLAGS) $? -o $@
# Create standard library object
standard_library/standard_library.o: standard_library/standard_library.c
$(CC) $(CFLAGS) $? -o $@
# Create http object
platforms/megaavr/http_user_interface.o: platforms/megaavr/http_user_interface.c
$(CC) $(CFLAGS) $? -o $@
# Create uart object
platforms/megaavr/uart.o: platforms/megaavr/uart.c
$(CC) $(CFLAGS) $? -o $@
# Create wiznet_5100 object
platforms/megaavr/wiznet_5100.o: platforms/megaavr/wiznet_5100.c
$(CC) $(CFLAGS) $? -o $@
####################
# Installing Event #
####################
install: binaries/bootloader.hex
$(PROGRAMMER_SOFTWARE) $(PROGRAMMER_SOFTWARE_PARAMETERS) -U flash:w:binaries/bootloader.hex:i
################
# Setting Fuse #
################
set-fuses:
$(PROGRAMMER_SOFTWARE) $(PROGRAMMER_SOFTWARE_PARAMETERS) -U $(EXTENDED_FUSE)
$(PROGRAMMER_SOFTWARE) $(PROGRAMMER_SOFTWARE_PARAMETERS) -U $(HIGH_FUSE)
$(PROGRAMMER_SOFTWARE) $(PROGRAMMER_SOFTWARE_PARAMETERS) -U $(LOW_FUSE)
###################
# Cleaning Events #
###################
# Clean all compiled and linked files
clean:
rm -f binaries/*.* $(OBJECTS)
# Clean all compiled files
clean-objects:
rm -f $(OBJECTS)