-
Notifications
You must be signed in to change notification settings - Fork 3
/
Makefile
85 lines (69 loc) · 2.19 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
######################################################################
# User configuration
######################################################################
# Linux Debian/Ubuntu
# Serial port
PORT=ttyUSB0
SPEED=460800
# Path to programs
MPFSHELL=mpfshell --open $(PORT)
ESPTOOL=esptool.py
FIRMWARE=./firmware.bin
# Get latest version from http://www.micropython.org/download#esp8266
FIRMWAREVERSION=esp8266-20190125-v1.10.bin
######################################################################
# End of user config
######################################################################
FILES=boot.py \
config.json \
main.py \
soil_moisture.py \
water_pump.py \
utils.py
.PHONY: erase # : Erase flash on chip
erase:
$(ESPTOOL) --port /dev/$(PORT) erase_flash
@sleep 5
.PHONY: flash # : Upload new firmware to chip
flash: firmware
$(ESPTOOL) --port /dev/$(PORT) --baud $(SPEED) write_flash --flash_size=detect 0 $(FIRMWARE)
@sleep 10
@echo 'Power cycle the device'
.PHONY: reset # : Hard reset chip
reset:
$(MPFSHELL) --reset
.PHONY: install
install:
@bash -c "if ! command -v esptool.py >/dev/null 2>&1; then python3 -m pip install --user -U esptool;fi"
@bash -c "if ! command -v mpfshell >/dev/null 2>&1; then python3 -m pip install --user -U mpfshell;fi"
.PHONY: firmware # : Download latest firmware from http://www.micropython.org/download#esp8266
firmware:
@bash -c "[ -f $(FIRMWARE) ] || wget -O ./firmware.bin http://micropython.org/resources/firmware/"$(FIRMWAREVERSION)
.PHONY: upload_all # : Upload latest firmware"
upload_all:
for f in $(FILES); do \
echo installing $$f; \
$(MPFSHELL) -nc rm $$f > /dev/null 2>&1; \
$(MPFSHELL) -nc put $$f; \
echo done installing; \
done
.PHONY: check # : Compile Python code
check:
python3 -m py_compile *.py
rm -rf __pycache__
rm -f *.pyc
.PHONY: repl # : Open repl on chip
repl:
$(MPFSHELL) -c repl
.PHONY: all # :Bootstrap ie erase, flash, and upload
all: install erase flash check upload_all clean
.PHONY: help # : Please use \`make <target>' where <target> is one of
help:
@grep '^.PHONY: .* #' Makefile | sed 's/\.PHONY: \(.*\) # \(.*\)/\1 \2/' | expand -t20
.PHONY: clean
clean:
rm -rf $(FIRMWARE)
rm -rf *.pyc
.PHONY: test
test:
ls