mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
Fixed automatic connection in idf_monitor
Closes https://github.com/espressif/esp-idf/issues/6415
This commit is contained in:
parent
31e565c3d5
commit
179e23b38a
@ -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.
|
||||
"""
|
||||
|
||||
def __init__(self, message, ctx=None):
|
||||
super(RuntimeError, self).__init__(message)
|
||||
# if context is defined, check for the cleanup tasks
|
||||
if ctx is not None and 'cleanup' in ctx.meta:
|
||||
# cleans up the environment before failure
|
||||
ctx.meta['cleanup']()
|
||||
|
||||
|
||||
class NoSerialPortFoundError(FatalError):
|
||||
pass
|
||||
|
@ -3,7 +3,7 @@ import os
|
||||
import sys
|
||||
|
||||
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.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)
|
||||
import esptool
|
||||
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,
|
||||
initial_baud=args.baud)
|
||||
# high baud rate could cause the failure of creation of the connection
|
||||
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
|
||||
except Exception:
|
||||
raise FatalError("No serial ports found. Connect a device, or use '-p PORT' option to set a specific port.")
|
||||
serial_port = esp.serial_port
|
||||
esp._port.close()
|
||||
|
||||
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):
|
||||
esptool_path = os.path.join(os.environ['IDF_PATH'], 'components/esptool_py/esptool/esptool.py')
|
||||
|
Loading…
Reference in New Issue
Block a user