Merge branch 'feature/idfpy_add_baud_parameter_to_monitor_v4.1' into 'release/v4.1'

idf.py: add monitor-baud option to monitor command (v4.1)

See merge request espressif/esp-idf!7458
This commit is contained in:
Ivan Grokhotkov 2020-04-09 05:44:41 +08:00
commit 51c32997b1
2 changed files with 37 additions and 15 deletions

View File

@ -796,7 +796,7 @@ def main():
'--baud', '-b', '--baud', '-b',
help='Serial port baud rate', help='Serial port baud rate',
type=int, type=int,
default=os.environ.get('MONITOR_BAUD', 115200)) default=os.getenv('IDF_MONITOR_BAUD', os.getenv('MONITORBAUD', 115200)))
parser.add_argument( parser.add_argument(
'--make', '-m', '--make', '-m',

View File

@ -2,6 +2,8 @@ import json
import os import os
import sys import sys
import click
from idf_py_actions.errors import FatalError from idf_py_actions.errors import FatalError
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, run_tool from idf_py_actions.tools import ensure_build_directory, run_tool
@ -21,8 +23,9 @@ def action_extensions(base_actions, project_path):
ports = list(reversed(sorted(p.device for p in serial.tools.list_ports.comports()))) ports = list(reversed(sorted(p.device for p in serial.tools.list_ports.comports())))
try: try:
print("Choosing default port %s (use '-p PORT' option to set a specific serial port)" % print(
ports[0].encode("ascii", "ignore")) "Choosing default port %s (use '-p PORT' option to set a specific serial port)" %
ports[0].encode("ascii", "ignore"))
return ports[0] return ports[0]
except IndexError: except IndexError:
raise RuntimeError( raise RuntimeError(
@ -60,7 +63,7 @@ def action_extensions(base_actions, project_path):
return result return result
def monitor(action, ctx, args, print_filter, encrypted): def monitor(action, ctx, args, print_filter, encrypted, monitor_baud):
""" """
Run idf_monitor.py to watch build output Run idf_monitor.py to watch build output
""" """
@ -74,14 +77,24 @@ def action_extensions(base_actions, project_path):
elf_file = os.path.join(args.build_dir, project_desc["app_elf"]) elf_file = os.path.join(args.build_dir, project_desc["app_elf"])
if not os.path.exists(elf_file): if not os.path.exists(elf_file):
raise FatalError("ELF file '%s' not found. You need to build & flash the project before running 'monitor', " raise FatalError(
"and the binary on the device must match the one in the build directory exactly. " "ELF file '%s' not found. You need to build & flash the project before running 'monitor', "
"Try '%s flash monitor'." % (elf_file, ctx.info_name)) "and the binary on the device must match the one in the build directory exactly. "
"Try '%s flash monitor'." % (elf_file, ctx.info_name))
idf_monitor = os.path.join(os.environ["IDF_PATH"], "tools/idf_monitor.py") idf_monitor = os.path.join(os.environ["IDF_PATH"], "tools/idf_monitor.py")
monitor_args = [PYTHON, idf_monitor] monitor_args = [PYTHON, idf_monitor]
if args.port is not None: if args.port is not None:
monitor_args += ["-p", args.port] monitor_args += ["-p", args.port]
monitor_args += ["-b", project_desc["monitor_baud"]]
if not monitor_baud:
if os.getenv("IDF_MONITOR_BAUD"):
monitor_baud = os.getenv("IDF_MONITOR_BAUD", None)
elif os.getenv("MONITORBAUD"):
monitor_baud = os.getenv("MONITORBAUD", None)
else:
monitor_baud = project_desc["monitor_baud"]
monitor_args += ["-b", monitor_baud]
monitor_args += ["--toolchain-prefix", project_desc["monitor_toolprefix"]] monitor_args += ["--toolchain-prefix", project_desc["monitor_toolprefix"]]
if print_filter is not None: if print_filter is not None:
@ -130,7 +143,7 @@ def action_extensions(base_actions, project_path):
baud_rate = { baud_rate = {
"names": ["-b", "--baud"], "names": ["-b", "--baud"],
"help": "Baud rate.", "help": "Baud rate for flashing.",
"scope": "global", "scope": "global",
"envvar": "ESPBAUD", "envvar": "ESPBAUD",
"default": 460800, "default": 460800,
@ -163,8 +176,7 @@ def action_extensions(base_actions, project_path):
"callback": monitor, "callback": monitor,
"help": "Display serial output.", "help": "Display serial output.",
"options": [ "options": [
port, port, {
{
"names": ["--print-filter", "--print_filter"], "names": ["--print-filter", "--print_filter"],
"help": ( "help": (
"Filter monitor output.\n" "Filter monitor output.\n"
@ -180,10 +192,20 @@ def action_extensions(base_actions, project_path):
}, { }, {
"names": ["--encrypted", "-E"], "names": ["--encrypted", "-E"],
"is_flag": True, "is_flag": True,
"help": ("Enable encrypted flash targets.\n" "help": (
"IDF Monitor will invoke encrypted-flash and encrypted-app-flash targets " "Enable encrypted flash targets.\n"
"if this option is set. This option is set by default if IDF Monitor was invoked " "IDF Monitor will invoke encrypted-flash and encrypted-app-flash targets "
"together with encrypted-flash or encrypted-app-flash target."), "if this option is set. This option is set by default if IDF Monitor was invoked "
"together with encrypted-flash or encrypted-app-flash target."),
}, {
"names": ["--monitor-baud", "-B"],
"type": click.INT,
"help": (
"Baud rate for monitor.\n"
"If this option is not provided IDF_MONITOR_BAUD and MONITORBAUD "
"environment variables and project_description.json in build directory "
"(generated by CMake from project's sdkconfig) "
"will be checked for default value."),
} }
], ],
"order_dependencies": [ "order_dependencies": [