Skip to content

Commit

Permalink
Add idf.py monitor argument --no-reset (-R) to prevent resetting the …
Browse files Browse the repository at this point in the history
…MCU target on monitor startup

Add idf.py monitor argument --no-reset (-R) to prevent resetting the CPU on monitor startup

idf.py monitor: fix type signature

idf.py monitor: fix reset key shortcut when --no-reset (-R) argument is used

idf.py monitor: change --no-reset (-R) argument descriptions in help

idf.py monitor: simplify --no-reset (-R) argument checks

idf.py monitor: add warning if --no-reset is used, but --port is not given

idf.py monitor: ignore --no-reset if --port is not given
  • Loading branch information
nonoo committed May 3, 2022
1 parent 3aeb80a commit 9266a7c
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 10 deletions.
6 changes: 4 additions & 2 deletions tools/idf_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ def __init__(
print_filter, # type: str
make='make', # type: str
encrypted=False, # type: bool
reset=True, # type: bool
toolchain_prefix=DEFAULT_TOOLCHAIN_PREFIX, # type: str
eol='CRLF', # type: str
decode_coredumps=COREDUMP_DECODE_INFO, # type: str
Expand Down Expand Up @@ -109,7 +110,7 @@ def __init__(
if isinstance(self, SerialMonitor):
socket_mode = serial_instance.port.startswith('socket://')
self.serial = serial_instance
self.serial_reader = SerialReader(self.serial, self.event_queue)
self.serial_reader = SerialReader(self.serial, self.event_queue, reset)

self.gdb_helper = GDBHelper(toolchain_prefix, websocket_client, self.elf_file, self.serial.port,
self.serial.baudrate) if self.elf_exists else None
Expand All @@ -124,7 +125,7 @@ def __init__(

cls = SerialHandler if self.elf_exists else SerialHandlerNoElf
self.serial_handler = cls(b'', socket_mode, self.logger, decode_panic, PANIC_IDLE, b'', target,
False, False, self.serial, encrypted, self.elf_file)
False, False, self.serial, encrypted, reset, self.elf_file)

self.console_parser = ConsoleParser(eol)
self.console_reader = ConsoleReader(self.console, self.event_queue, self.cmd_queue, self.console_parser,
Expand Down Expand Up @@ -343,6 +344,7 @@ def main() -> None:
args.print_filter,
args.make,
args.encrypted,
not args.no_reset,
args.toolchain_prefix,
args.eol,
args.decode_coredumps,
Expand Down
7 changes: 7 additions & 0 deletions tools/idf_monitor_base/argument_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ def get_parser(): # type: () -> argparse.ArgumentParser
default=os.environ.get('ESPTOOL_PORT', '/dev/ttyUSB0')
)

parser.add_argument(
'--no-reset', '-R',
help='Do not reset the chip on monitor startup',
default=False,
action='store_true'
)

parser.add_argument(
'--disable-address-decoding', '-d',
help="Don't print lines about decoded addresses from the application ELF file",
Expand Down
10 changes: 6 additions & 4 deletions tools/idf_monitor_base/serial_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ class SerialHandler:
The class is responsible for buffering serial input and performing corresponding commands.
"""
def __init__(self, last_line_part, serial_check_exit, logger, decode_panic, reading_panic, panic_buffer, target,
force_line_print, start_cmd_sent, serial_instance, encrypted, elf_file):
# type: (bytes, bool, Logger, str, int, bytes,str, bool, bool, serial.Serial, bool, str) -> None
force_line_print, start_cmd_sent, serial_instance, encrypted, reset, elf_file):
# type: (bytes, bool, Logger, str, int, bytes,str, bool, bool, serial.Serial, bool, bool, str) -> None
self._last_line_part = last_line_part
self._serial_check_exit = serial_check_exit
self.logger = logger
Expand All @@ -71,6 +71,7 @@ def __init__(self, last_line_part, serial_check_exit, logger, decode_panic, read
self.start_cmd_sent = start_cmd_sent
self.serial_instance = serial_instance
self.encrypted = encrypted
self.reset = reset
self.elf_file = elf_file

def handle_serial_input(self, data, console_parser, coredump, gdb_helper, line_matcher,
Expand Down Expand Up @@ -192,10 +193,11 @@ def handle_commands(self, cmd, chip, run_make_func, console_reader, serial_reade
console_reader.stop()
serial_reader.stop()
elif cmd == CMD_RESET:
self.serial_instance.setRTS(low)
self.serial_instance.setDTR(high) # IO0=HIGH, default state
self.serial_instance.setRTS(low) # EN=LOW, chip in reset
self.serial_instance.setDTR(self.serial_instance.dtr) # usbser.sys workaround
time.sleep(reset_delay)
self.serial_instance.setRTS(high)
self.serial_instance.setRTS(high) # EN=HIGH, chip out of reset
self.serial_instance.setDTR(self.serial_instance.dtr) # usbser.sys workaround
self.logger.output_enabled = True
elif cmd == CMD_MAKE:
Expand Down
7 changes: 4 additions & 3 deletions tools/idf_monitor_base/serial_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@ class SerialReader(Reader):
event queue, until stopped.
"""

def __init__(self, serial_instance, event_queue):
# type: (serial.Serial, queue.Queue) -> None
def __init__(self, serial_instance, event_queue, reset):
# type: (serial.Serial, queue.Queue, bool) -> None
super(SerialReader, self).__init__()
self.baud = serial_instance.baudrate
self.serial = serial_instance
self.event_queue = event_queue
self.gdb_exit = False
self.reset = reset
if not hasattr(self.serial, 'cancel_read'):
# enable timeout for checking alive flag,
# if cancel_read not available
Expand All @@ -49,7 +50,7 @@ def run(self):
self.serial.dtr = self.serial.dtr # usbser.sys workaround
# Current state not reset the target!
self.serial.open()
if not self.gdb_exit:
if not self.gdb_exit and self.reset:
self.serial.dtr = high # Set dtr to reset state (affected by rts)
self.serial.rts = low # Set rts/dtr to the reset state
self.serial.dtr = self.serial.dtr # usbser.sys workaround
Expand Down
15 changes: 14 additions & 1 deletion tools/idf_py_actions/serial_ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def _get_commandline_options(ctx):

return result

def monitor(action, ctx, args, print_filter, monitor_baud, encrypted, timestamps, timestamp_format):
def monitor(action, ctx, args, print_filter, monitor_baud, encrypted, no_reset, timestamps, timestamp_format):
"""
Run idf_monitor.py to watch build output
"""
Expand All @@ -94,6 +94,10 @@ def monitor(action, ctx, args, print_filter, monitor_baud, encrypted, timestamps
monitor_args = [PYTHON, idf_monitor]

if project_desc['target'] != 'linux':
if no_reset and args.port is None:
sys.stderr.write('WARNING: --no-reset is ignored. Please specify the port with the --port argument in order to use this option.\n')
no_reset = False

esp_port = args.port or _get_default_serial_port(args)
monitor_args += ['-p', esp_port]

Expand Down Expand Up @@ -134,6 +138,9 @@ def monitor(action, ctx, args, print_filter, monitor_baud, encrypted, timestamps
if encrypted:
monitor_args += ['--encrypted']

if no_reset:
monitor_args += ['--no-reset']

if timestamps:
monitor_args += ['--timestamps']

Expand Down Expand Up @@ -261,6 +268,12 @@ def ota_targets(target_name, ctx, args):
'IDF Monitor will invoke encrypted-flash and encrypted-app-flash targets '
'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': ['--no-reset', '-R'],
'is_flag': True,
'help': ('Disable reset on monitor startup. '
'IDF Monitor will not reset the MCU target by toggling DTR/RTS lines on startup '
'if this option is set.'),
}, {
'names': ['--timestamps'],
'is_flag': True,
Expand Down

0 comments on commit 9266a7c

Please sign in to comment.