mirror of
https://github.com/espressif/esp-idf.git
synced 2025-10-04 02:50:58 +02:00
tools: added idf.py coredump sub-command
This commit is contained in:
committed by
Aleksei Apaseev
parent
72a9bbebd3
commit
06ac2166d6
@@ -8,13 +8,30 @@ from typing import Any, Dict, List
|
||||
|
||||
import click
|
||||
from idf_monitor_base.output_helpers import yellow_print
|
||||
from idf_py_actions.errors import FatalError, NoSerialPortFoundError
|
||||
from idf_py_actions.global_options import global_options
|
||||
from idf_py_actions.tools import PropertyDict, RunTool, ensure_build_directory, get_sdkconfig_value, run_target
|
||||
from idf_py_actions.tools import (PropertyDict, RunTool, ensure_build_directory, get_default_serial_port,
|
||||
get_sdkconfig_value, run_target)
|
||||
|
||||
PYTHON = sys.executable
|
||||
|
||||
|
||||
BAUD_RATE = {
|
||||
'names': ['-b', '--baud'],
|
||||
'help': 'Baud rate for flashing. It can imply monitor baud rate as well if it hasn\'t been defined locally.',
|
||||
'scope': 'global',
|
||||
'envvar': 'ESPBAUD',
|
||||
'default': 460800,
|
||||
}
|
||||
|
||||
PORT = {
|
||||
'names': ['-p', '--port'],
|
||||
'help': 'Serial port.',
|
||||
'scope': 'global',
|
||||
'envvar': 'ESPPORT',
|
||||
'default': None,
|
||||
}
|
||||
|
||||
|
||||
def action_extensions(base_actions: Dict, project_path: str) -> Dict:
|
||||
def _get_project_desc(ctx: click.core.Context, args: PropertyDict) -> Any:
|
||||
desc_path = os.path.join(args.build_dir, 'project_description.json')
|
||||
@@ -24,33 +41,11 @@ def action_extensions(base_actions: Dict, project_path: str) -> Dict:
|
||||
project_desc = json.load(f)
|
||||
return project_desc
|
||||
|
||||
def _get_default_serial_port(args: PropertyDict) -> Any:
|
||||
# Import is done here in order to move it after the check_environment() ensured that pyserial has been installed
|
||||
try:
|
||||
import esptool
|
||||
import serial.tools.list_ports
|
||||
ports = list(sorted(p.device for p in serial.tools.list_ports.comports()))
|
||||
# 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.")
|
||||
|
||||
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: PropertyDict) -> List:
|
||||
esptool_path = os.path.join(os.environ['IDF_PATH'], 'components/esptool_py/esptool/esptool.py')
|
||||
esptool_wrapper_path = os.environ.get('ESPTOOL_WRAPPER', '')
|
||||
if args.port is None:
|
||||
args.port = _get_default_serial_port(args)
|
||||
args.port = get_default_serial_port()
|
||||
result = [PYTHON]
|
||||
if os.path.exists(esptool_wrapper_path):
|
||||
result += [esptool_wrapper_path]
|
||||
@@ -100,7 +95,7 @@ def action_extensions(base_actions: Dict, project_path: str) -> Dict:
|
||||
yellow_print(msg)
|
||||
no_reset = False
|
||||
|
||||
esp_port = args.port or _get_default_serial_port(args)
|
||||
esp_port = args.port or get_default_serial_port()
|
||||
monitor_args += ['-p', esp_port]
|
||||
|
||||
baud = monitor_baud or os.getenv('IDF_MONITOR_BAUD') or os.getenv('MONITORBAUD')
|
||||
@@ -168,7 +163,7 @@ def action_extensions(base_actions: Dict, project_path: str) -> Dict:
|
||||
yellow_print('skipping flash since running on linux...')
|
||||
return
|
||||
|
||||
esp_port = args.port or _get_default_serial_port(args)
|
||||
esp_port = args.port or get_default_serial_port()
|
||||
run_target(action, args, {'ESPBAUD': str(args.baud), 'ESPPORT': esp_port})
|
||||
|
||||
def erase_flash(action: str, ctx: click.core.Context, args: PropertyDict) -> None:
|
||||
@@ -192,27 +187,11 @@ def action_extensions(base_actions: Dict, project_path: str) -> Dict:
|
||||
Calls ensure_build_directory() which will run cmake to generate a build
|
||||
directory (with the specified generator) as needed.
|
||||
"""
|
||||
args.port = args.port or _get_default_serial_port(args)
|
||||
args.port = args.port or get_default_serial_port()
|
||||
ensure_build_directory(args, ctx.info_name)
|
||||
run_target(target_name, args, {'ESPBAUD': str(args.baud), 'ESPPORT': args.port})
|
||||
|
||||
baud_rate = {
|
||||
'names': ['-b', '--baud'],
|
||||
'help': 'Baud rate for flashing. It can imply monitor baud rate as well if it hasn\'t been defined locally.',
|
||||
'scope': 'global',
|
||||
'envvar': 'ESPBAUD',
|
||||
'default': 460800,
|
||||
}
|
||||
|
||||
port = {
|
||||
'names': ['-p', '--port'],
|
||||
'help': 'Serial port.',
|
||||
'scope': 'global',
|
||||
'envvar': 'ESPPORT',
|
||||
'default': None,
|
||||
}
|
||||
|
||||
BAUD_AND_PORT = [baud_rate, port]
|
||||
BAUD_AND_PORT = [BAUD_RATE, PORT]
|
||||
serial_actions = {
|
||||
'global_action_callbacks': [global_callback],
|
||||
'actions': {
|
||||
@@ -244,7 +223,7 @@ def action_extensions(base_actions: Dict, project_path: str) -> Dict:
|
||||
'help':
|
||||
'Display serial output.',
|
||||
'options': [
|
||||
port, {
|
||||
PORT, {
|
||||
'names': ['--print-filter', '--print_filter'],
|
||||
'help':
|
||||
('Filter monitor output. '
|
||||
|
Reference in New Issue
Block a user