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.
tools/pyboard: Split Ctrl-C into two separate steps with small delay
This makes pyboard.py successfully enter raw-repl on an ESP32 board.
Without the split the running program won't always successfully abort and thus entering raw-repl fails.
I'm not completely sure, if this also depends on the actual program that is running on the device and whether this also happens on a real pyboard.
So for reference, here's the program running on the device which triggers the behaviour for me:
from machine import Pin
from time import sleep
import micropython
p = Pin(0, Pin.OUT)
#@micropython.native
def func():
for _ in range(1000):
p.value(not p.value())
while 1:
func()
This change has not been tested on an actual pyboard, because I don't have one.