dhylands / rshell

Remote Shell for MicroPython
MIT License
915 stars 131 forks source link

Problem writing to /flash via UART #20

Open peterhinch opened 7 years ago

peterhinch commented 7 years ago

Setup: a Pyboard V1.1 connected via an FTDI adaptor to UART2. No USB connection. Rshell invocation: rshell -p /dev/ftdi --editor nano --buffer-size=30 boot.py:

import pyb
pyb.usb_mode(None)
uart = pyb.UART(2, 115200)
pyb.repl_uart(uart)

At the rshell prompt I can copy files of all sizes to /sd Copying to /flash is unreliable. Small (< 300 bytes) files sometimes work, but sometimes fail to replace existing files. A 19.1K file appears to copy (the red LED comes on for a while) but the rshell prompt never reappears and the Pyboard seems to have crashed: a reboot is required to reconnect. At the rshell prompt ls -l /flash shows that most files have size 0.

dhylands commented 7 years ago

I can reproduce the problem. I'm pretty sure that what's happening is that interrupts are being disabled for a period of time while the flash is being written and characters are getting dropped.

Now to see if I can figure out a way to work around it.

dhylands commented 7 years ago

It seems that while a flash erase is happening, if an attempt is made to access flash (to fetch CPU instructions, read a constant or any other reason) then the CPU stalls until the flash erase occurs.

My current speculation is that this is happening and UART characters are being dropped. So I need to see if I can arrange some type of flow control to get the host to stop sending data while the flash is being manipulated.

pmaene commented 7 years ago

The file operations of Adafruit's ampy tool rely on Python code executed on the board (https://github.com/adafruit/ampy/blob/master/ampy/files.py#L125). This might be an alternative to the UART-based approach?