This repository was archived by the owner on Jun 2, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmakefile
More file actions
184 lines (166 loc) · 5.48 KB
/
makefile
File metadata and controls
184 lines (166 loc) · 5.48 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
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
# All libraries (subdirectories/folders) in lib-common
# Need to put uart first because other libraries depend on it (otherwise get error of "No rule to make target...")
LIBNAMES = uart adc can conversions dac heartbeat pex queue spi stack test timer uptime utilities watchdog
# Subfolders in src folder
SRC = $(addprefix src/,$(LIBNAMES))
# Subfolders in build folder
BUILD = $(addprefix build/,$(LIBNAMES))
# Subfolders in examples folder
EXAMPLES = $(dir $(wildcard examples/*/.))
# Subfolders in manual_tests folder
MANUAL_TESTS = $(dir $(wildcard manual_tests/*/.))
# Microcontroller - "32m1" or "64m1"
MCU = 64m1
# AVR device for avrdude uploading - must be prefixed with "m"
DEVICE = m$(MCU)
# Harness testing folder
TEST = harness_tests
# HARNESS_ARGS - can specify from the command line when calling `make`
export CC = avr-gcc
export AR = avr-ar
export RANLIB = avr-ranlib
export INCLUDES = -I../../include
export CFLAGS = -Wall -std=gnu99 -g -mmcu=atmega$(MCU) -Os -mcall-prologues
# Detect operating system - based on https://gist.github.com/sighingnow/deee806603ec9274fd47
# One of these flags will be set to true based on the operating system
WINDOWS := false
MAC_OS := false
LINUX := false
ifeq ($(OS),Windows_NT)
WINDOWS := true
else
# Unix - get the operating system
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Darwin)
MAC_OS := true
endif
ifeq ($(UNAME_S),Linux)
LINUX := true
endif
endif
# PORT - Computer port that the programmer is connected to
# Try to automatically detect the port
ifeq ($(WINDOWS), true)
# higher number
PORT = $(shell powershell "[System.IO.Ports.SerialPort]::getportnames() | sort | select -First 2 | select -Last 1")
UART = $(shell powershell "[System.IO.Ports.SerialPort]::getportnames() | sort | select -First 1")
endif
ifeq ($(MAC_OS), true)
# lower number
PORT = $(shell find /dev -name 'tty.usbmodem[0-9]*' | sort | head -n1)
UART = $(shell find /dev -name 'tty.usbmodem[0-9]*' | sort | sed -n 2p)
endif
ifeq ($(LINUX), true)
# lower number
PORT = $(shell find /dev -name 'ttyS[0-9]*' | sort | head -n1)
UART = $(shell find /dev -name 'ttyS[0-9]*' | sort | sed -n 2p)
endif
# Set the PYTHON variable - Python interpreter
# Windows uses `python` for either Python 2 or 3,
# while macOS/Linux use `python3` to explicitly use Python 3
ifeq ($(WINDOWS), true)
PYTHON := python
endif
ifeq ($(MAC_OS), true)
PYTHON := python3
endif
ifeq ($(LINUX), true)
PYTHON := python3
endif
.PHONY: all $(SRC) clean debug examples harness help manual_tests read-eeprom
all: $(SRC)
# Remove all files in the `lib` directory and each of the `build` subdirectories
# Calling `make clean` in each subdirectory on Windows does not properly pass
# the `clean` argument, so manually remove the files
clean:
rm -f lib/*.*
@echo "Removing files in build"
@for dir in $(BUILD) ; do \
rm -f $$dir/*.* ; \
done
# Compile each of the source libraries
# -e: "Environment variables override makefiles."
# -C: "Change to DIRECTORY before doing anything."
# $@: The source file being generated
$(SRC):
@$(MAKE) -e -C $@
# Print debug information
debug:
@echo ------------
@echo $(LIBNAMES)
@echo ------------
@echo $(SRC)
@echo ------------
@echo $(BUILD)
@echo ------------
@echo $(EXAMPLES)
@echo ------------
@echo $(MANUAL_TESTS)
@echo ------------
@echo $(MCU)
@echo ------------
@echo $(DEVICE)
@echo ------------
@echo $(TEST)
@echo ------------
@echo $(WINDOWS)
@echo ------------
@echo $(MAC_OS)
@echo ------------
@echo $(LINUX)
@echo ------------
@echo $(PORT)
@echo ------------
@echo $(PYTHON)
@echo ------------
@echo $(HARNESS_ARGS)
@echo ------------
# For each example program, clean directory then build
# Calling `make clean` in each subdirectory on Windows does not properly pass
# the `clean` argument, so manually remove the files
examples:
@for dir in $(EXAMPLES) ; do \
cd $$dir ; \
rm -f ./*.o ; \
rm -f ./*.elf ; \
rm -f ./*.hex ; \
make ; \
cd ../.. ; \
done
# If multi-board testing, PORT2 and UART2 must both be specified
harness:
$(PYTHON) ./bin/harness.py -m $(MCU) -p $(PORT) $(PORT2) -u $(UART) $(UART2) -d $(TEST) $(HARNESS_ARGS)
help:
@echo "usage: make [all | clean | debug | examples | harness | help | manual_tests | read-eeprom]"
@echo "Running make without any arguments is equivalent to running make all."
@echo "all build the lib-common library"
@echo "clean clear the build directory and all subdirectories"
@echo "debug display debugging information"
@echo "examples build all examples (see examples/makefile)"
@echo "harness run the test harness"
@echo "help display this help message"
@echo "manual_tests build all manual tests (see manual_tests/makefile)"
@echo "read-eeprom read and display the contents of the microcontroller's EEPROM"
# For each manual test program, clean directory then build
# Calling `make clean` in each subdirectory on Windows does not properly pass
# the `clean` argument, so manually remove the files
manual_tests:
@for dir in $(MANUAL_TESTS) ; do \
cd $$dir ; \
rm -f ./*.o ; \
rm -f ./*.elf ; \
rm -f ./*.hex ; \
make ; \
cd ../.. ; \
done
# Create a file called eeprom.bin, which contains a raw binary copy of the micro's EEPROM memory.
# View the contents of the binary file in hex
read-eeprom:
@echo "Reading EEPROM to binary file eeprom.bin..."
avrdude -p $(DEVICE) -c stk500 -P $(PORT) -U eeprom:r:eeprom.bin:r
@echo "Displaying eeprom.bin in hex..."
ifeq ($(WINDOWS), true)
powershell Format-Hex eeprom.bin
else
hexdump eeprom.bin
endif