Makefile 2.49 KB
Newer Older
1
2
3
PORT :=
BAUD := 115200

4
PIOBOARD = nodemcuv2
5
6
7
8
9
PIOPROJ = firmware/esplogger
PIODIR = .pio

.PHONY: firmware monitor reset getport

10
all: firmware
11

12
13
14
15
install-pip3:
	wget https://bootstrap.pypa.io/get-pip.py && \
		sudo python3 get-pip.py && rm get-pip.py

16
17
18
19
install-platformio:
	wget https://bootstrap.pypa.io/get-pip.py && \
		sudo python get-pip.py && rm get-pip.py
	sudo pip install platformio
20
21
22
23
24
25
26
27
28
29
	$(MAKE) add-udev-rules
	$(MAKE) add-dialout

add-dialout:
	sudo usermod -a -G dialout $$USER

add-udevrules:
	wget https://raw.githubusercontent.com/platformio/platformio/develop/scripts/99-platformio-udev.rules
	sudo cp -v 99-platformio-udev.rules /etc/udev/rules.d
	sudo service udev restart
30

31
32
33
firmware: build upload monitor

build:
34
	which platformio || $(MAKE) install-platformio
35
	@ echo "$$PIO_BUILD" | sh
36
37

upload:
38
	which platformio || $(MAKE) install-platformio
39
	cd $(PIODIR) && platformio run -t upload
40

41
42
monitor:
	platformio device monitor
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

reset: getport
	@ echo "-----------------------------------------"
	@ echo "Reseting the board"
	esptool.py --port /dev/$(PORT) run
	@ python -c "import time; time.sleep(1)"

getport:
	@ $(eval PORT := `python utils/getport.py`)
	@ echo $(PORT)

example-blink:
	$(eval PIOPROJ := examples/blink)
	@ echo "$$PIO_BUILD" | sh

example-wifiscan:
	$(eval PIOPROJ := examples/wifiscan)
	@ echo "$$PIO_BUILD" | sh
	$(MAKE) monitor

example-sdcardinfo:
	$(eval PIOPROJ := examples/sd_card_info)
	@ echo "$$PIO_BUILD" | sh
	$(MAKE) monitor

help:
	@ echo "$$HELP_MAKEFILE"

71
72
73
clean:
	rm -rfv $(PIODIR)

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
define HELP_MAKEFILE
Usage:  make <target>   where <target> can be:

  firmware        Build and upload the esplogger firmware using platformio
  monitor         Start the picocom serial monitor (autodetect port)
  reset           Attempt a soft reset of the ESP devkit board

  example-____    Build and upload one of the examples/ projects:
                      blink      -- turn on and off the led on pin 2
                      wifiscan   -- detect and print all available SSIDs
endef
export HELP_MAKEFILE


define PY_GET_PORT
import os
ports = [x for x in os.listdir("/dev") if x.startswith("ttyUSB")
									   or x.startswith("ttyACM")]
if ports and isinstance(ports[0], str):
	print(ports[0])
else:
	print("Error: Unable to find a ttyUSB/ttyACM serial port")
	raise SystemExit(1)
endef
export PY_GET_PORT


define PIO_BUILD
	mkdir -p $(PIODIR)
	rm -rf $(PIODIR)/src
	platformio init --board $(PIOBOARD) -d $(PIODIR)
	cp -rf $(PIOPROJ)/* $(PIODIR)/src/
106
	cd $(PIODIR) && platformio run
107
108
endef
export PIO_BUILD