pyboard.py: add "delay" argument in CLI
I used ampy to interact with ESP32 before. In my case, I need to give a delay (3 sencods) to enter raw REPL successfully.
ampy --port com14 --delay 3 ls
If I use pyboard.py CLI, I can't enter raw REPL, even if I set the --wait argument to 3.
pyboard.py --device com14 -w 3 -f ls
In ampy source code, --delay parameter is applied to the top of the enter_raw_repl () function to control the delay before enter raw REPL:
def enter_raw_repl(self):
# Brief delay before sending RAW MODE char if requests
if _rawdelay > 0:
time.sleep(_rawdelay)
# ...
I use a simple script to test orginal pyboard.py, and it is work:
import pyboard
import time
pyb = pyboard.Pyboard('COM14')
time.sleep(3) # delay before enter
pyb.enter_raw_repl()
ret = pyb.exec_('print(1+1)')
print(ret)
pyb.exit_raw_repl()
I hope pyboard.py CLI can provide a parameter to control the delay.
wait for >>> when attempting to enter_raw_repl
On some boards (notably esp32), pyboard.py hangs when attempting to enter raw repl mode. As outlined in this thread and this PR, @roaldarbol and I have resolved this issue. Basically, the issue/solution is this:
- After pressing ctrl+c twice, some boards take a while to respond (up to ~2 or ~3 seconds).
- Attempting to enter raw repl during this time will result in the command being ignored.
- To detect the board responding, the new change is to wait until the
>>>prompt is sent from device. - If the device is already in raw repl mode, the
>>>prompt will not be sent. To mitigate this, we will attempt to exit raw repl mode. If not in raw repl mode, this will do nothing. - Once the
>>>prompt is reached, we know the device is ready for more commands and we can set the device in raw repl mode.
This should also mitigate the issue in some other very old issues. This change is working well in Belay, but I didn't really test this exact PR for micropython.