You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
146 lines
4.9 KiB
Python
146 lines
4.9 KiB
Python
6 years ago
|
#!/usr/bin/env python
|
||
7 years ago
|
#
|
||
|
# Builds custom upload command
|
||
|
# 1) Run platformio as a subprocess to find a COM port
|
||
|
# 2) Build the upload command
|
||
|
# 3) Exit and let upload tool do the work
|
||
|
#
|
||
|
# This script runs between completion of the library/dependencies installation and compilation.
|
||
|
#
|
||
|
# Will continue on if a COM port isn't found so that the compilation can be done.
|
||
|
#
|
||
|
|
||
6 years ago
|
from __future__ import print_function
|
||
|
from __future__ import division
|
||
|
|
||
7 years ago
|
import subprocess
|
||
|
import os
|
||
7 years ago
|
import sys
|
||
7 years ago
|
from SCons.Script import DefaultEnvironment
|
||
|
import platform
|
||
|
current_OS = platform.system()
|
||
7 years ago
|
|
||
7 years ago
|
env = DefaultEnvironment()
|
||
7 years ago
|
|
||
7 years ago
|
build_type = os.environ.get("BUILD_TYPE", 'Not Set')
|
||
7 years ago
|
|
||
|
|
||
7 years ago
|
if not(build_type == 'upload' or build_type == 'traceback' or build_type == 'Not Set') :
|
||
|
env.Replace(UPLOAD_PROTOCOL = 'teensy-gui') # run normal Teensy2 scripts
|
||
|
else:
|
||
|
com_first = ''
|
||
|
com_last = ''
|
||
|
com_CDC = ''
|
||
|
description_first = ''
|
||
|
description_last = ''
|
||
|
description_CDC = ''
|
||
7 years ago
|
|
||
7 years ago
|
#
|
||
|
# grab the first com port that pops up unless we find one we know for sure
|
||
|
# is a CDC device
|
||
|
#
|
||
|
def get_com_port(com_search_text, descr_search_text, start):
|
||
7 years ago
|
|
||
7 years ago
|
global com_first
|
||
|
global com_last
|
||
|
global com_CDC
|
||
|
global description_first
|
||
|
global description_last
|
||
|
global description_CDC
|
||
7 years ago
|
|
||
|
|
||
6 years ago
|
print('\nLooking for Serial Port\n')
|
||
7 years ago
|
|
||
|
# stream output from subprocess and split it into lines
|
||
|
pio_subprocess = subprocess.Popen(['platformio', 'device', 'list'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
||
|
|
||
|
looking_for_description = False
|
||
|
for line in iter(pio_subprocess.stdout.readline, ''):
|
||
|
if 0 <= line.find(com_search_text):
|
||
|
looking_for_description = True
|
||
|
com_last = line.replace('\n', '')
|
||
|
if com_first == '':
|
||
|
com_first = com_last
|
||
|
if 0 <= line.find(descr_search_text) and looking_for_description:
|
||
|
looking_for_description = False
|
||
|
description_last = line[ start : ]
|
||
|
if description_first == '':
|
||
|
description_first = description_last
|
||
|
if 0 <= description_last.find('CDC'):
|
||
|
com_CDC = com_last
|
||
|
description_CDC = description_last
|
||
|
|
||
5 years ago
|
if com_CDC == '' and com_first != '':
|
||
7 years ago
|
com_CDC = com_first
|
||
|
description_CDC = description_first
|
||
|
elif com_CDC == '':
|
||
|
com_CDC = 'COM_PORT_NOT_FOUND'
|
||
|
|
||
|
while 0 <= com_CDC.find('\n'):
|
||
|
com_CDC = com_CDC.replace('\n', '')
|
||
|
while 0 <= com_CDC.find('\r'):
|
||
|
com_CDC = com_CDC.replace('\r', '')
|
||
|
|
||
|
if com_CDC == 'COM_PORT_NOT_FOUND':
|
||
6 years ago
|
print(com_CDC, '\n')
|
||
7 years ago
|
else:
|
||
6 years ago
|
print('FOUND: ', com_CDC)
|
||
|
print('DESCRIPTION: ', description_CDC, '\n')
|
||
7 years ago
|
|
||
7 years ago
|
if current_OS == 'Windows':
|
||
7 years ago
|
|
||
7 years ago
|
get_com_port('COM', 'Hardware ID:', 13)
|
||
7 years ago
|
|
||
7 years ago
|
# avrdude_conf_path = env.get("PIOHOME_DIR") + '\\packages\\toolchain-atmelavr\\etc\\avrdude.conf'
|
||
|
avrdude_conf_path = 'buildroot\\share\\atom\\avrdude.conf'
|
||
7 years ago
|
|
||
7 years ago
|
avrdude_exe_path = 'buildroot\\share\\atom\\avrdude_5.10.exe'
|
||
7 years ago
|
|
||
7 years ago
|
# source_path = env.get("PROJECTBUILD_DIR") + '\\' + env.get("PIOENV") + '\\firmware.hex'
|
||
5 years ago
|
source_path = '.pio\\build\\' + env.get("PIOENV") + '\\firmware.hex'
|
||
7 years ago
|
|
||
7 years ago
|
upload_string = avrdude_exe_path + ' -p usb1286 -c avr109 -P ' + com_CDC + ' -U flash:w:' + source_path + ':i'
|
||
7 years ago
|
|
||
|
|
||
7 years ago
|
if current_OS == 'Darwin': # MAC
|
||
7 years ago
|
|
||
7 years ago
|
get_com_port('usbmodem', 'Description:', 13)
|
||
7 years ago
|
|
||
7 years ago
|
# avrdude_conf_path = env.get("PIOHOME_DIR") + '/packages/toolchain-atmelavr/etc/avrdude.conf'
|
||
5 years ago
|
avrdude_conf_path = 'buildroot/share/vscode/avrdude_macOS.conf'
|
||
7 years ago
|
|
||
|
|
||
5 years ago
|
avrdude_exe_path = 'buildroot/share/vscode/avrdude_5.10_macOS'
|
||
7 years ago
|
|
||
7 years ago
|
# source_path = env.get("PROJECTBUILD_DIR") + '/' + env.get("PIOENV") + '/firmware.hex'
|
||
5 years ago
|
source_path = '.pio/build/' + env.get("PIOENV") + '/firmware.hex'
|
||
7 years ago
|
|
||
|
|
||
7 years ago
|
# upload_string = 'avrdude -p usb1286 -c avr109 -P ' + com_CDC + ' -U flash:w:' + source_path + ':i'
|
||
|
upload_string = avrdude_exe_path + ' -p usb1286 -c avr109 -P ' + com_CDC + ' -C ' + avrdude_conf_path + ' -U flash:w:' + source_path + ':i'
|
||
6 years ago
|
print('upload_string: ', upload_string)
|
||
7 years ago
|
|
||
|
|
||
|
|
||
7 years ago
|
if current_OS == 'Linux':
|
||
7 years ago
|
|
||
7 years ago
|
get_com_port('/dev/tty', 'Description:', 13)
|
||
7 years ago
|
|
||
7 years ago
|
# avrdude_conf_path = env.get("PIOHOME_DIR") + '/packages/toolchain-atmelavr/etc/avrdude.conf'
|
||
5 years ago
|
avrdude_conf_path = 'buildroot/share/vscode/avrdude_linux.conf'
|
||
7 years ago
|
|
||
|
|
||
5 years ago
|
avrdude_exe_path = 'buildroot/share/vscode/avrdude_5.10_linux'
|
||
7 years ago
|
# source_path = env.get("PROJECTBUILD_DIR") + '/' + env.get("PIOENV") + '/firmware.hex'
|
||
5 years ago
|
source_path = '.pio/build/' + env.get("PIOENV") + '/firmware.hex'
|
||
7 years ago
|
|
||
7 years ago
|
# upload_string = 'avrdude -p usb1286 -c avr109 -P ' + com_CDC + ' -U flash:w:' + source_path + ':i'
|
||
|
upload_string = avrdude_exe_path + ' -p usb1286 -c avr109 -P ' + com_CDC + ' -C ' + avrdude_conf_path + ' -U flash:w:' + source_path + ':i'
|
||
7 years ago
|
|
||
|
|
||
7 years ago
|
env.Replace(
|
||
|
UPLOADCMD = upload_string,
|
||
|
MAXIMUM_RAM_SIZE = 8192,
|
||
|
MAXIMUM_SIZE = 130048
|
||
|
)
|