rshell won't connect without SD card

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.
Jacob_Beningo
Posts: 12
Joined: Thu Jul 07, 2016 8:45 pm

rshell won't connect without SD card

Post by Jacob_Beningo » Mon Jul 18, 2016 12:50 pm

I'm having issues getting the rshell to connect to the pyboard if an SD card is not inserted.

I have disabled MSC by setting the following in my boot.py:

Code: Select all

pyb.usb_mode('CDC')
The internal /flash doesn't show up as MSC which is good but when an SD card is inserted it shows up as a drive.

Now with the SD card inserted, rshell connects and works great but if I boot-up without the SD card, I cannot connect to the PyBoard using rshell or screen.

1) Is there some switch, parameter, etc that needs to be set for rshell to connect to the PyBoard when an SD card is not inserted?

2) Is there a way to disable the SD card from showing up as a MSC?

Thanks for the insights!

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: rshell won't connect without SD card

Post by Roberthh » Mon Jul 18, 2016 3:01 pm

Hello Jacob,

boot.py and main.py are taken form the SD card if the SD card is present. Are you sure that these files are like you want to have them on the SD card?

Regards

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: rshell won't connect without SD card

Post by dhylands » Mon Jul 18, 2016 4:02 pm

My first suspicion would be that /flash/boot.py and /flash/main.py are messing things up (rshell needs those to execute without error in order to work).

When you use an sdcard, the /sd/boot.py and /sd/main.py are executed instead.

Jacob_Beningo
Posts: 12
Joined: Thu Jul 07, 2016 8:45 pm

Re: rshell won't connect without SD card

Post by Jacob_Beningo » Tue Jul 19, 2016 1:45 pm

Thanks Robert! I forgot about that when using an SD card. That definitely help remove the SD card from showing up as MSC.

I'm still having issues with rshell though. I did a factory reset on my PyBoard so that I have all the original boot.py and main.py scripts. I'm running it without the SD card so /flash only. I make the change in boot.py to uncomment:

#pyb.usb_mode('CDC+MSC') # act as a serial and a storage device

and change it to

pyb.usb_mode('CDC') # act as a serial and a storage device

I remove the drive power cycle and it shows up as a serial device. However, I am unable to connect through rshell or even screen.

At this point main.py has not been modified and is completely blank.

Jacob_Beningo
Posts: 12
Joined: Thu Jul 07, 2016 8:45 pm

Re: rshell won't connect without SD card

Post by Jacob_Beningo » Tue Jul 19, 2016 1:47 pm

Thanks Dave. Do you have an example for how your boot.py and main.py scripts should look to use rshell without an SD card attached?

(I've searched the forum but haven't found an example at the moment).

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: rshell won't connect without SD card

Post by dhylands » Tue Jul 19, 2016 4:11 pm

I normally use the stock boot.py and main.py, and modify boot.py to set the pyb.usb_mode.

Here is my typical boot.py and main.py (using rshell to show the contents):

Code: Select all

/home/dhylands> cat /flash/boot.py
# boot.py -- run on boot-up
# can run arbitrary Python, but best to keep it minimal

import machine
import pyb
#pyb.main('main.py') # main script to run after this one
pyb.usb_mode('CDC') # act as a serial port
#pyb.usb_mode('CDC+HID') # act as a serial device and a mouse
/home/dhylands> cat /flash/main.py
# main.py -- put your code here!
/home/dhylands> 
I had one board which wouldn't work with rshell until I upgraded the firmware. Make sure you have recent firmware on the pyboard and also make sure that you're running a recent version of rshell. The most recent is 0.0.5 (rshell --version). You should be able to update by using:

Code: Select all

pip3 install --upgrade rshell

Jacob_Beningo
Posts: 12
Joined: Thu Jul 07, 2016 8:45 pm

Re: rshell won't connect without SD card

Post by Jacob_Beningo » Tue Jul 19, 2016 8:49 pm

Thanks for the suggestions.

So I rebuilt my PYBV10 firmware using the latest release 1.8.2 from 9 days ago. I've also verified that I'm using rshell 0.0.5.

After reflashing my board I find that if I try to connect with rshell to just the /flash without an SD card inserted I still get:

Connecting to /dev/ttyACM1 ...
failed to access /dev/ttyACM1

My /flash/boot.py is identical to the listing that dhylands posted.

Commenting out my changes to boot.py and leaving it as default, with 'CDC+MSC', and then power cycling, I find that I am able to connect over rshell. So for some reason changing boot.py to use CDC only seems to be breaking the communication.

I've tried this on both my PYBV10 board and also a custom board that uses the STM32F429 but the results are identical.

Is there a verbose mode for rshell or any other thoughts on how I might resolve this? Thanks again!

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: rshell won't connect without SD card

Post by dhylands » Tue Jul 19, 2016 9:44 pm

rshell has a -d command that causes all of the commands and responses that are sent to the board to be printed.

Can you also try running this script: https://github.com/dhylands/usb-ser-mon ... nd_port.py

You can use this link to directly download: https://raw.githubusercontent.com/dhyla ... nd_port.py

I'd like to see the output of running

Code: Select all

find_port.py --list
When using rshell, make sure that whatever terminal program you normally use for the REPL has been shutdown. If you use tmux or screen make sure that there aren't any background ones running. If anything else is connected to the serial port (/dev/ttyACM1 in your example) then rshell won't work.

Under linux, you can use a command like:

Code: Select all

lsof | grep ttyACM
to see if anybody else has that serial port open. I somtimes wind up with other copies of rshell on other windows which also messes things up.

Note to self: I really need to implement the proper serial port locking.

And it would also be good to see what

Code: Select all

ls -l /dev/ttyACM1
shows. Is your user a member of the dialout group? (You can use the id command to see what groups your user belongs to:

Code: Select all

2051 >id
uid=35029(dhylands) gid=1000(dhylands) groups=1000(dhylands),4(adm),20(dialout),24(cdrom),27(sudo),30(dip),46(plugdev),113(lpadmin),128(sambashare)

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: rshell won't connect without SD card

Post by dhylands » Tue Jul 19, 2016 10:16 pm

And if you have a main.py which doesn't exit thru to the REPL, then rshell won't work either.

And it just occurred to me that there is a subtle thing you might be tripping over.
When the pyboard switches between CDC mode and CDC+MSC mode, it uses a different USB PID. CDC+MSC shows as f055:9800 where CDC only shows as f055:9802 (and I think CDC+HID shows as f055:9801) so this will affect your udev if you're using udev rules to set the permissions on your /dev/ttyACMx files.

I now use:

Code: Select all

# f055:9800 MicroPython pyboard
ATTRS{idVendor}=="f055", ENV{ID_MM_DEVICE_IGNORE}="1"
ATTRS{idVendor}=="f055", ENV{MTP_NO_PROBE}="1"
SUBSYSTEMS=="usb", ATTRS{idVendor}=="f055", MODE:="0666"
KERNEL=="ttyACM*", ATTRS{idVendor}=="f055", MODE:="0666"
so I removed the idProiduct checks altogether.

Adding yourself to the dialout group will also get you the same benefit.

Note to self: Time to update the rshell docs in regards to this.

Jacob_Beningo
Posts: 12
Joined: Thu Jul 07, 2016 8:45 pm

Re: rshell won't connect without SD card

Post by Jacob_Beningo » Tue Jul 19, 2016 11:57 pm

Awesome! Thanks for all the information. Super helpful!

The issue turned out to be my udev rules and the usb PID ( I was really started to think something USB related but forgot all about these rules as I set them up a long time ago). I removed the '9800' PID entries to match your rules and after reloading the rules it came up immediately. Thank-you for the insights!

On a side note, (hopefully this is appropriate), I updated the page I originally retrieved the udev rules from ( https://github.com/micropython/micropyt ... -Discovery) to show the changes. That way anyone who sets the rules up for the first time will have the latest rules that you are using and won't encounter this issue.

Post Reply