mirror of
https://github.com/platformio/platformio-core.git
synced 2025-07-30 10:07:14 +02:00
Refactor firmware uploading to the embedded boards with SAM-BA bootloader
This commit is contained in:
@ -14,7 +14,7 @@
|
|||||||
|
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
VERSION = (2, 9, "3.dev0")
|
VERSION = (2, 9, "3.dev1")
|
||||||
__version__ = ".".join([str(s) for s in VERSION])
|
__version__ = ".".join([str(s) for s in VERSION])
|
||||||
|
|
||||||
__title__ = "platformio"
|
__title__ = "platformio"
|
||||||
|
@ -65,7 +65,7 @@ def BeforeUpload(target, source, env): # pylint: disable=W0613,W0621
|
|||||||
if not upload_options.get("disable_flushing", False):
|
if not upload_options.get("disable_flushing", False):
|
||||||
env.FlushSerialBuffer("$UPLOAD_PORT")
|
env.FlushSerialBuffer("$UPLOAD_PORT")
|
||||||
|
|
||||||
before_ports = [i['port'] for i in get_serialports(use_grep=True)]
|
before_ports = get_serialports()
|
||||||
|
|
||||||
if upload_options.get("use_1200bps_touch", False):
|
if upload_options.get("use_1200bps_touch", False):
|
||||||
env.TouchSerialPort("$UPLOAD_PORT", 1200)
|
env.TouchSerialPort("$UPLOAD_PORT", 1200)
|
||||||
|
@ -41,7 +41,7 @@ def BeforeUpload(target, source, env): # pylint: disable=W0613,W0621
|
|||||||
if not upload_options.get("disable_flushing", False):
|
if not upload_options.get("disable_flushing", False):
|
||||||
env.FlushSerialBuffer("$UPLOAD_PORT")
|
env.FlushSerialBuffer("$UPLOAD_PORT")
|
||||||
|
|
||||||
before_ports = [i['port'] for i in get_serialports(use_grep=True)]
|
before_ports = get_serialports()
|
||||||
|
|
||||||
if upload_options.get("use_1200bps_touch", False):
|
if upload_options.get("use_1200bps_touch", False):
|
||||||
env.TouchSerialPort("$UPLOAD_PORT", 1200)
|
env.TouchSerialPort("$UPLOAD_PORT", 1200)
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
|
|
||||||
from __future__ import absolute_import
|
from __future__ import absolute_import
|
||||||
|
|
||||||
|
import sys
|
||||||
from os.path import isfile, join
|
from os.path import isfile, join
|
||||||
from shutil import copyfile
|
from shutil import copyfile
|
||||||
from time import sleep
|
from time import sleep
|
||||||
@ -49,21 +50,25 @@ def TouchSerialPort(env, port, baudrate):
|
|||||||
|
|
||||||
def WaitForNewSerialPort(env, before):
|
def WaitForNewSerialPort(env, before):
|
||||||
print "Waiting for the new upload port..."
|
print "Waiting for the new upload port..."
|
||||||
|
prev_port = env.subst("$UPLOAD_PORT")
|
||||||
new_port = None
|
new_port = None
|
||||||
elapsed = 0
|
elapsed = 0
|
||||||
while elapsed < 5:
|
while elapsed < 5 and new_port is None:
|
||||||
now = [i['port'] for i in get_serialports(use_grep=True)]
|
now = get_serialports()
|
||||||
diff = list(set(now) - set(before))
|
for p in now:
|
||||||
if diff:
|
if p not in before:
|
||||||
new_port = diff[0]
|
new_port = p['port']
|
||||||
break
|
break
|
||||||
|
|
||||||
before = now
|
before = now
|
||||||
sleep(0.25)
|
sleep(0.25)
|
||||||
elapsed += 0.25
|
elapsed += 0.25
|
||||||
|
|
||||||
if not new_port and env.subst("$UPLOAD_PORT") in now:
|
if not new_port:
|
||||||
new_port = env.subst("$UPLOAD_PORT")
|
for p in now:
|
||||||
|
if prev_port == p['port']:
|
||||||
|
new_port = p['port']
|
||||||
|
break
|
||||||
|
|
||||||
if not new_port:
|
if not new_port:
|
||||||
env.Exit("Error: Couldn't find a board on the selected port. "
|
env.Exit("Error: Couldn't find a board on the selected port. "
|
||||||
"Check that you have the correct port selected. "
|
"Check that you have the correct port selected. "
|
||||||
|
@ -280,34 +280,7 @@ def exec_command(*args, **kwargs):
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
def get_serialports(use_grep=False):
|
def get_serialports():
|
||||||
|
|
||||||
def _grep_serial_ports():
|
|
||||||
result = []
|
|
||||||
if system() == "Windows":
|
|
||||||
output = exec_command(["mode"]).get("out", "")
|
|
||||||
for line in output.split("\n"):
|
|
||||||
line = line.strip()
|
|
||||||
if "COM" in line:
|
|
||||||
result.append({"port": line[line.index("COM"):-1],
|
|
||||||
"description": "", "hwid": ""})
|
|
||||||
else:
|
|
||||||
if system() == "Linux":
|
|
||||||
patterns = ["/dev/%s*" % p for p in (
|
|
||||||
"ttyS", "ttyUSB", "ttyACM", "ttyAMA", "rfcomm", "ttyO")]
|
|
||||||
else:
|
|
||||||
patterns = ["/dev/tty.*", "/dev/cu.*"]
|
|
||||||
for pattern in patterns:
|
|
||||||
for port in glob(pattern):
|
|
||||||
result.append(
|
|
||||||
{"port": port, "description": "", "hwid": ""})
|
|
||||||
return result
|
|
||||||
|
|
||||||
if use_grep:
|
|
||||||
result = _grep_serial_ports()
|
|
||||||
if result:
|
|
||||||
return result
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from serial.tools.list_ports import comports
|
from serial.tools.list_ports import comports
|
||||||
except ImportError:
|
except ImportError:
|
||||||
@ -325,9 +298,9 @@ def get_serialports(use_grep=False):
|
|||||||
result.append({"port": p, "description": d, "hwid": h})
|
result.append({"port": p, "description": d, "hwid": h})
|
||||||
|
|
||||||
# fix for PySerial
|
# fix for PySerial
|
||||||
if not result and not use_grep and system() == "Darwin":
|
if not result and system() == "Darwin":
|
||||||
result = _grep_serial_ports()
|
for p in glob("/dev/tty.*"):
|
||||||
|
result.append({"port": p, "description": "", "hwid": ""})
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user