1 |
ron |
1 |
#
|
|
|
2 |
# Builds custom upload command
|
|
|
3 |
# 1) Run platformio as a subprocess to find a COM port
|
|
|
4 |
# 2) Build the upload command
|
|
|
5 |
# 3) Exit and let upload tool do the work
|
|
|
6 |
#
|
|
|
7 |
# This script runs between completion of the library/dependencies installation and compilation.
|
|
|
8 |
#
|
|
|
9 |
# Will continue on if a COM port isn't found so that the compilation can be done.
|
|
|
10 |
#
|
|
|
11 |
|
|
|
12 |
import subprocess
|
|
|
13 |
import os
|
|
|
14 |
import sys
|
|
|
15 |
from SCons.Script import DefaultEnvironment
|
|
|
16 |
import platform
|
|
|
17 |
current_OS = platform.system()
|
|
|
18 |
|
|
|
19 |
env = DefaultEnvironment()
|
|
|
20 |
|
|
|
21 |
build_type = os.environ.get("BUILD_TYPE", 'Not Set')
|
|
|
22 |
|
|
|
23 |
|
|
|
24 |
if not(build_type == 'upload' or build_type == 'traceback' or build_type == 'Not Set') :
|
|
|
25 |
env.Replace(UPLOAD_PROTOCOL = 'teensy-gui') # run normal Teensy2 scripts
|
|
|
26 |
else:
|
|
|
27 |
com_first = ''
|
|
|
28 |
com_last = ''
|
|
|
29 |
com_CDC = ''
|
|
|
30 |
description_first = ''
|
|
|
31 |
description_last = ''
|
|
|
32 |
description_CDC = ''
|
|
|
33 |
|
|
|
34 |
#
|
|
|
35 |
# grab the first com port that pops up unless we find one we know for sure
|
|
|
36 |
# is a CDC device
|
|
|
37 |
#
|
|
|
38 |
def get_com_port(com_search_text, descr_search_text, start):
|
|
|
39 |
|
|
|
40 |
global com_first
|
|
|
41 |
global com_last
|
|
|
42 |
global com_CDC
|
|
|
43 |
global description_first
|
|
|
44 |
global description_last
|
|
|
45 |
global description_CDC
|
|
|
46 |
|
|
|
47 |
|
|
|
48 |
print '\nLooking for Serial Port\n'
|
|
|
49 |
|
|
|
50 |
# stream output from subprocess and split it into lines
|
|
|
51 |
pio_subprocess = subprocess.Popen(['platformio', 'device', 'list'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
|
|
52 |
|
|
|
53 |
looking_for_description = False
|
|
|
54 |
for line in iter(pio_subprocess.stdout.readline, ''):
|
|
|
55 |
if 0 <= line.find(com_search_text):
|
|
|
56 |
looking_for_description = True
|
|
|
57 |
com_last = line.replace('\n', '')
|
|
|
58 |
if com_first == '':
|
|
|
59 |
com_first = com_last
|
|
|
60 |
if 0 <= line.find(descr_search_text) and looking_for_description:
|
|
|
61 |
looking_for_description = False
|
|
|
62 |
description_last = line[ start : ]
|
|
|
63 |
if description_first == '':
|
|
|
64 |
description_first = description_last
|
|
|
65 |
if 0 <= description_last.find('CDC'):
|
|
|
66 |
com_CDC = com_last
|
|
|
67 |
description_CDC = description_last
|
|
|
68 |
|
|
|
69 |
if com_CDC == '' and not(com_first == ''):
|
|
|
70 |
com_CDC = com_first
|
|
|
71 |
description_CDC = description_first
|
|
|
72 |
elif com_CDC == '':
|
|
|
73 |
com_CDC = 'COM_PORT_NOT_FOUND'
|
|
|
74 |
|
|
|
75 |
while 0 <= com_CDC.find('\n'):
|
|
|
76 |
com_CDC = com_CDC.replace('\n', '')
|
|
|
77 |
while 0 <= com_CDC.find('\r'):
|
|
|
78 |
com_CDC = com_CDC.replace('\r', '')
|
|
|
79 |
|
|
|
80 |
if com_CDC == 'COM_PORT_NOT_FOUND':
|
|
|
81 |
print com_CDC, '\n'
|
|
|
82 |
else:
|
|
|
83 |
print 'FOUND: ' ,com_CDC
|
|
|
84 |
print 'DESCRIPTION: ', description_CDC , '\n'
|
|
|
85 |
|
|
|
86 |
if current_OS == 'Windows':
|
|
|
87 |
|
|
|
88 |
get_com_port('COM', 'Hardware ID:', 13)
|
|
|
89 |
|
|
|
90 |
# avrdude_conf_path = env.get("PIOHOME_DIR") + '\\packages\\toolchain-atmelavr\\etc\\avrdude.conf'
|
|
|
91 |
avrdude_conf_path = 'buildroot\\share\\atom\\avrdude.conf'
|
|
|
92 |
|
|
|
93 |
avrdude_exe_path = 'buildroot\\share\\atom\\avrdude_5.10.exe'
|
|
|
94 |
|
|
|
95 |
# source_path = env.get("PROJECTBUILD_DIR") + '\\' + env.get("PIOENV") + '\\firmware.hex'
|
|
|
96 |
source_path = '.pioenvs\\' + env.get("PIOENV") + '\\firmware.hex'
|
|
|
97 |
|
|
|
98 |
upload_string = avrdude_exe_path + ' -p usb1286 -c avr109 -P ' + com_CDC + ' -U flash:w:' + source_path + ':i'
|
|
|
99 |
|
|
|
100 |
|
|
|
101 |
if current_OS == 'Darwin': # MAC
|
|
|
102 |
|
|
|
103 |
get_com_port('usbmodem', 'Description:', 13)
|
|
|
104 |
|
|
|
105 |
# avrdude_conf_path = env.get("PIOHOME_DIR") + '/packages/toolchain-atmelavr/etc/avrdude.conf'
|
|
|
106 |
avrdude_conf_path = 'buildroot/share/atom/avrdude_macOS.conf'
|
|
|
107 |
|
|
|
108 |
|
|
|
109 |
avrdude_exe_path = 'buildroot/share/atom/avrdude_5.10_macOS'
|
|
|
110 |
|
|
|
111 |
# source_path = env.get("PROJECTBUILD_DIR") + '/' + env.get("PIOENV") + '/firmware.hex'
|
|
|
112 |
source_path = '.pioenvs/' + env.get("PIOENV") + '/firmware.hex'
|
|
|
113 |
|
|
|
114 |
|
|
|
115 |
# upload_string = 'avrdude -p usb1286 -c avr109 -P ' + com_CDC + ' -U flash:w:' + source_path + ':i'
|
|
|
116 |
upload_string = avrdude_exe_path + ' -p usb1286 -c avr109 -P ' + com_CDC + ' -C ' + avrdude_conf_path + ' -U flash:w:' + source_path + ':i'
|
|
|
117 |
print 'upload_string: ', upload_string
|
|
|
118 |
|
|
|
119 |
|
|
|
120 |
|
|
|
121 |
if current_OS == 'Linux':
|
|
|
122 |
|
|
|
123 |
get_com_port('/dev/tty', 'Description:', 13)
|
|
|
124 |
|
|
|
125 |
# avrdude_conf_path = env.get("PIOHOME_DIR") + '/packages/toolchain-atmelavr/etc/avrdude.conf'
|
|
|
126 |
avrdude_conf_path = 'buildroot/share/atom/avrdude_linux.conf'
|
|
|
127 |
|
|
|
128 |
|
|
|
129 |
avrdude_exe_path = 'buildroot/share/atom/avrdude_5.10_linux'
|
|
|
130 |
# source_path = env.get("PROJECTBUILD_DIR") + '/' + env.get("PIOENV") + '/firmware.hex'
|
|
|
131 |
source_path = '.pioenvs/' + env.get("PIOENV") + '/firmware.hex'
|
|
|
132 |
|
|
|
133 |
# upload_string = 'avrdude -p usb1286 -c avr109 -P ' + com_CDC + ' -U flash:w:' + source_path + ':i'
|
|
|
134 |
upload_string = avrdude_exe_path + ' -p usb1286 -c avr109 -P ' + com_CDC + ' -C ' + avrdude_conf_path + ' -U flash:w:' + source_path + ':i'
|
|
|
135 |
|
|
|
136 |
|
|
|
137 |
env.Replace(
|
|
|
138 |
UPLOADCMD = upload_string,
|
|
|
139 |
MAXIMUM_RAM_SIZE = 8192,
|
|
|
140 |
MAXIMUM_SIZE = 130048
|
|
|
141 |
)
|