RP2: Problem copying files using rshell to Pico over USB

Discussion about programs, libraries and tools that work with MicroPython. Mostly these are provided by a third party.
Target audience: All users and developers of MicroPython.
Post Reply
Mark_Tyler
Posts: 2
Joined: Thu Mar 17, 2022 11:09 am

RP2: Problem copying files using rshell to Pico over USB

Post by Mark_Tyler » Thu Mar 17, 2022 12:51 pm

Hi,

I have been having problems copying some files from the host (a Raspberry Pi 4B) to a Pico (RP2) using USB. The Pico has MicroPython v1.18 and I am using rshell v0.0.31 to do the copy.

If I try and copy any file that has a file size which is a multiple of 32 bytes but is *not* a multiple of 128 bytes then the file transfer results in the Pico hard hanging at the end of the transfer. The file does not end up being transferred, only a zero length file is created on the Pico. For example, files of size 32, 64, 96, 160, 192, 224, 288, etc bytes will fail to transfer. Files of other sizes that are not in the sequence transfer fine.

The rshell command I am using is:

Code: Select all

cp filename.ext /pyboard
The rsync command also fails to work with files of the problematic size.

I have done some debugging in rshell and the problem appears to be in the function recv_file_from_host which fails when it hits the line:

Code: Select all

bytes_read = sys.stdin.readinto(read_buf, read_size)
when read_size is one of the problematic values. As I understand it this indicated a bug in the underlying MicroPython implementation of the buffered IO stream being used by sys.stdin.

Note I have replicated the problem with two different Pico boards and MicroPython v1.17 and the latest nightly v1.18-218.

Any insight would be appreciated.

Regards - Mark

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: RP2: Problem copying files using rshell to Pico over USB

Post by pythoncoder » Fri Mar 18, 2022 11:34 am

I use the following invocation on RP2 and have experienced no problems.

Code: Select all

rshell -p /dev/ttyACM0 --editor nano --buffer-size=30 -a
Peter Hinch
Index to my micropython libraries.

Mark_Tyler
Posts: 2
Joined: Thu Mar 17, 2022 11:09 am

Re: RP2: Problem copying files using rshell to Pico over USB

Post by Mark_Tyler » Fri Mar 18, 2022 11:54 pm

Thanks Peter.

I had been using buffer_size of 512 which is the rshell default I believe. Changing to 30 as you suggested fixes the issue. I would have expected the bigger value to not work at all rather than being problematic only with particular file sizes. <Shrug>

Thanks for your help.

Regards - Mark

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: RP2: Problem copying files using rshell to Pico over USB

Post by pythoncoder » Sat Mar 19, 2022 10:02 am

Just FYI the -a flag forces ASCII transfers. I encountered a bug transferring some binary and mpy files which -a works round.
Peter Hinch
Index to my micropython libraries.

Post Reply