-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
53 lines (40 loc) · 1.58 KB
/
Makefile
File metadata and controls
53 lines (40 loc) · 1.58 KB
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
## Adapted from
## https://balau82.wordpress.com/2011/03/29/programming-arduino-uno-in-pure-c/
## which is licensed under CC-BY-SA http://creativecommons.org/licenses/by-sa/4.0/
CC = avr-gcc
CFLAGS = -std=c99
OBJ_COPY = avr-objcopy
F_CPU = 16000000
MCU = atmega168
PROGRAMMER = arduino
BOARD = ATMEGA168
PORT = /dev/ttyUSB0
BAUD = 19200
MAIN_FILE = led
# Note about Makefile vars:
# https://www.gnu.org/software/make/manual/html_node/Static-Usage.html
# $< prereq
# $@ output
# The first command line takes the C source file and compiles it into an object
# file. The options tell the compilerto optimize for code size,what is the
# clock frequency (it’s useful for delay functions for example) and which is
# the processor for which to compile code.
%.o: %.c
$(CC) $(CFLAGS) -Os -DF_CPU=$(F_CPU)UL -mmcu=$(MCU) -c -o $@ $<
# The second commands links the object file together with system libraries
# (that are linked implicitly as needed) into an ELF program.
%.elf: %.o
$(CC) -mmcu=$(MCU) $< -o $@
# The third command converts the ELF program into an IHEX file.
%.hex: %.elf
$(OBJ_COPY) -O ihex -R .eeprom $< $@
build: $(MAIN_FILE).hex
# The fourth command uploads the IHEX data ito the Atmega chip embedded flash,
# and the options tells avrdude program to communicate using the Arduino serial
# protocol, through a particular serial port which is the Linux device
# “/dev/ttyACM0“, and to use 115200bps as the data rate.
upload: build
avrdude -F -V -c $(PROGRAMMER) -p $(BOARD) -P $(PORT) -b $(BAUD) -U flash:w:$(MAIN_FILE).hex
clean:
rm -f *.hex *.elf *.o
.PHONY: build upload clean