Skip to content

Commit 767cde7

Browse files
committed
idf.py: add monitor-baud option to monitor command
1 parent 20742db commit 767cde7

File tree

2 files changed

+42
-20
lines changed

2 files changed

+42
-20
lines changed

tools/idf_monitor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -789,7 +789,7 @@ def _get_default_serial_port():
789789
'--baud', '-b',
790790
help='Serial port baud rate',
791791
type=int,
792-
default=os.environ.get('MONITOR_BAUD', 115200))
792+
default=os.getenv('IDF_MONITOR_BAUD', os.getenv('MONITORBAUD', 115200)))
793793

794794
parser.add_argument(
795795
'--make', '-m',

tools/idf_py_actions/serial_ext.py

Lines changed: 41 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
import os
33
import sys
44

5+
import click
6+
57
from idf_py_actions.errors import FatalError
68
from idf_py_actions.global_options import global_options
79
from idf_py_actions.tools import ensure_build_directory, run_tool
@@ -60,7 +62,7 @@ def _get_commandline_options(ctx):
6062

6163
return result
6264

63-
def monitor(action, ctx, args, print_filter):
65+
def monitor(action, ctx, args, print_filter, monitor_baud):
6466
"""
6567
Run idf_monitor.py to watch build output
6668
"""
@@ -81,7 +83,16 @@ def monitor(action, ctx, args, print_filter):
8183
monitor_args = [PYTHON, idf_monitor]
8284
if args.port is not None:
8385
monitor_args += ["-p", args.port]
84-
monitor_args += ["-b", project_desc["monitor_baud"]]
86+
87+
if not monitor_baud:
88+
if os.getenv("IDF_MONITOR_BAUD"):
89+
monitor_baud = os.getenv("IDF_MONITOR_BAUD", None)
90+
elif os.getenv("MONITORBAUD"):
91+
monitor_baud = os.getenv("MONITORBAUD", None)
92+
else:
93+
monitor_baud = project_desc["monitor_baud"]
94+
95+
monitor_args += ["-b", monitor_baud]
8596
monitor_args += ["--toolchain-prefix", project_desc["monitor_toolprefix"]]
8697

8798
if print_filter is not None:
@@ -119,7 +130,7 @@ def erase_flash(action, ctx, args):
119130

120131
baud_rate = {
121132
"names": ["-b", "--baud"],
122-
"help": "Baud rate.",
133+
"help": "Baud rate for flashing.",
123134
"scope": "global",
124135
"envvar": "ESPBAUD",
125136
"default": 460800,
@@ -148,24 +159,35 @@ def erase_flash(action, ctx, args):
148159
"options": [baud_rate, port],
149160
},
150161
"monitor": {
151-
"callback": monitor,
152-
"help": "Display serial output.",
162+
"callback":
163+
monitor,
164+
"help":
165+
"Display serial output.",
153166
"options": [
154-
port,
155-
{
167+
port, {
156168
"names": ["--print-filter", "--print_filter"],
157-
"help": (
158-
"Filter monitor output.\n"
159-
"Restrictions on what to print can be specified as a series of <tag>:<log_level> items "
160-
"where <tag> is the tag string and <log_level> is a character from the set "
161-
"{N, E, W, I, D, V, *} referring to a level. "
162-
'For example, "tag1:W" matches and prints only the outputs written with '
163-
'ESP_LOGW("tag1", ...) or at lower verbosity level, i.e. ESP_LOGE("tag1", ...). '
164-
'Not specifying a <log_level> or using "*" defaults to Verbose level.\n'
165-
'Please see the IDF Monitor section of the ESP-IDF documentation '
166-
'for a more detailed description and further examples.'),
167-
"default": None,
168-
},
169+
"help":
170+
("Filter monitor output.\n"
171+
"Restrictions on what to print can be specified as a series of <tag>:<log_level> items "
172+
"where <tag> is the tag string and <log_level> is a character from the set "
173+
"{N, E, W, I, D, V, *} referring to a level. "
174+
'For example, "tag1:W" matches and prints only the outputs written with '
175+
'ESP_LOGW("tag1", ...) or at lower verbosity level, i.e. ESP_LOGE("tag1", ...). '
176+
'Not specifying a <log_level> or using "*" defaults to Verbose level.\n'
177+
'Please see the IDF Monitor section of the ESP-IDF documentation '
178+
'for a more detailed description and further examples.'),
179+
"default":
180+
None,
181+
}, {
182+
"names": ["--monitor-baud", "-B"],
183+
"type":
184+
click.INT,
185+
"help": ("Baud rate for monitor.\n"
186+
"If this option is not provided IDF_MONITOR_BAUD and MONITORBAUD "
187+
"environment variables and project_description.json in build directory "
188+
"(generated by CMake from project's sdkconfig) "
189+
"will be checked for default value."),
190+
}
169191
],
170192
"order_dependencies": [
171193
"flash",

0 commit comments

Comments
 (0)