Merge branch 'bugfix/fix-automatic-connection_v4.3' into 'release/v4.3'

bugfix: fixed automatic connection in idf_monitor (v4.3)

See merge request espressif/esp-idf!13130
This commit is contained in:
Ivan Grokhotkov
2021-04-14 18:06:09 +00:00
2 changed files with 20 additions and 6 deletions

View File

@ -2,9 +2,14 @@ class FatalError(RuntimeError):
""" """
Wrapper class for runtime errors that aren't caused by bugs in idf.py or the build process. Wrapper class for runtime errors that aren't caused by bugs in idf.py or the build process.
""" """
def __init__(self, message, ctx=None): def __init__(self, message, ctx=None):
super(RuntimeError, self).__init__(message) super(RuntimeError, self).__init__(message)
# if context is defined, check for the cleanup tasks # if context is defined, check for the cleanup tasks
if ctx is not None and 'cleanup' in ctx.meta: if ctx is not None and 'cleanup' in ctx.meta:
# cleans up the environment before failure # cleans up the environment before failure
ctx.meta['cleanup']() ctx.meta['cleanup']()
class NoSerialPortFoundError(FatalError):
pass

View File

@ -3,7 +3,7 @@ import os
import sys import sys
import click import click
from idf_py_actions.errors import FatalError from idf_py_actions.errors import FatalError, NoSerialPortFoundError
from idf_py_actions.global_options import global_options from idf_py_actions.global_options import global_options
from idf_py_actions.tools import ensure_build_directory, get_sdkconfig_value, run_target, run_tool from idf_py_actions.tools import ensure_build_directory, get_sdkconfig_value, run_target, run_tool
@ -19,12 +19,21 @@ def action_extensions(base_actions, project_path):
sys.path.insert(0, esptool_path) sys.path.insert(0, esptool_path)
import esptool import esptool
ports = list(sorted(p.device for p in serial.tools.list_ports.comports())) ports = list(sorted(p.device for p in serial.tools.list_ports.comports()))
esp = esptool.get_default_connected_device(serial_list=ports, port=None, connect_attempts=3, # high baud rate could cause the failure of creation of the connection
initial_baud=args.baud) esp = esptool.get_default_connected_device(serial_list=ports, port=None, connect_attempts=4,
initial_baud=115200)
if esp is None:
raise NoSerialPortFoundError(
"No serial ports found. Connect a device, or use '-p PORT' option to set a specific port.")
return esp.serial_port serial_port = esp.serial_port
except Exception: esp._port.close()
raise FatalError("No serial ports found. Connect a device, or use '-p PORT' option to set a specific port.")
return serial_port
except NoSerialPortFoundError:
raise
except Exception as e:
raise FatalError('An exception occurred during detection of the serial port: {}'.format(e))
def _get_esptool_args(args): def _get_esptool_args(args):
esptool_path = os.path.join(os.environ['IDF_PATH'], 'components/esptool_py/esptool/esptool.py') esptool_path = os.path.join(os.environ['IDF_PATH'], 'components/esptool_py/esptool/esptool.py')