Skip to content

Commit

Permalink
Fix serial monitor for esp32c3
Browse files Browse the repository at this point in the history
  • Loading branch information
Philipp v. K committed Mar 11, 2022
1 parent f4df8f6 commit b0ff8e6
Showing 1 changed file with 22 additions and 15 deletions.
37 changes: 22 additions & 15 deletions mlonmcu/platform/espidf.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import os
import sys
import time
import signal
import shutil
import serial
Expand Down Expand Up @@ -404,25 +405,29 @@ def _monitor_helper(*args, verbose=False, start_match=None, end_match=None, time

def _monitor_helper2(port, baud, verbose=False, start_match=None, end_match=None, timeout=60):
# start_match and end_match are inclusive
print(
"port",
port,
"baud",
baud,
"verbose",
verbose,
"start_match",
start_match,
"end_match",
end_match,
"timeout",
timeout,
)
found_start = start_match is None
outStr = ""
if timeout:
pass # TODO: implement timeout
with serial.Serial(port, baud) as ser:
# The following is a custom initialization sequence inspired by (https://github.com/espressif/esp-idf/blob/4e03a9c34c24ce44921fa48ad1da67fe16162471/tools/idf_monitor_base/serial_reader.py)
high = False
low = True
ser = serial.Serial(port, baud)
ser.close()
ser.dtr = False
ser.rts = False
time.sleep(1)
ser.dtr = low
ser.rts = high
ser.dtr = ser.dtr
ser.open()
ser.dtr = high
ser.rts = low
ser.dtr = ser.dtr
time.sleep(0.002)
ser.rts = high
ser.dtr = ser.dtr
try:
while True:
try:
ser_bytes = ser.readline()
Expand All @@ -439,6 +444,8 @@ def _monitor_helper2(port, baud, verbose=False, start_match=None, end_match=None
break
except KeyboardInterrupt:
logger.warning("Stopped processing serial port (KeyboardInterrupt)")
finally:
ser.close()
return outStr

logger.debug("Monitoring target software")
Expand Down

0 comments on commit b0ff8e6

Please sign in to comment.