[nRF52] How to get rshell to work with an nRF52?

Discussion and questions about boards that can run MicroPython but don't have a dedicated forum.
Target audience: Everyone interested in running MicroPython on other hardware.
User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: [nRF52] How to get rshell to work with an nRF52?

Post by pythoncoder » Mon Oct 29, 2018 7:35 am

Re rshell I suggest first connecting with a basic terminal program to check that the serial device is working. I use miniterm.py which is part of the pyserial package.

Code: Select all

$ miniterm.py /dev/ttyACM0
should connect and give you a REPL. If not you may need to experiment with baudrate etc.

If you can connect with a terminal rshell should work, although on some platforms such as ESP8266 it's necessary to specify --buffer-size 30. I highly recommend getting rshell working and taking the time to learn its features.
Peter Hinch
Index to my micropython libraries.

User avatar
WhiteHare
Posts: 129
Joined: Thu Oct 04, 2018 4:00 am

Re: [nRF52] How to get rshell to work with an nRF52?

Post by WhiteHare » Mon Oct 29, 2018 7:55 am

In my case, connecting with a terminal and getting a REPL prompt isn't a problem. For example, the following is done via putty:

Code: Select all

>>> MicroPython v1.9.4-651-g0f6f86ca4-dirty on 2018-10-28; PCA10056 with NRF52840
Type "help()" for more information.
>>> import os
>>> os.listdir()
['update.txt', 'main.py']
>>>
However, as per the OP of this thread, rshell still doesn't work.

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

Re: [nRF52] How to get rshell to work with an nRF52?

Post by pythoncoder » Mon Oct 29, 2018 8:20 am

I find if I can connect with a terminal rshell "just works" so there must be something odd with the platform. When you connect with a terminal does the raw REPL produce a prompt (ctrl-a, ctrl-b to exit)?

It might be worth contacting Dave Hylands (@dhylands), the author of rshell. I'm sure he'll suggest an approach.
Peter Hinch
Index to my micropython libraries.

User avatar
WhiteHare
Posts: 129
Joined: Thu Oct 04, 2018 4:00 am

Re: [nRF52] How to get rshell to work with an nRF52?

Post by WhiteHare » Mon Oct 29, 2018 11:58 am

Yup:

Code: Select all

MicroPython v1.9.4-651-g0f6f86ca4-dirty on 2018-10-28; PCA10056 with NRF52840
Type "help()" for more information.
>>>
raw REPL; CTRL-B to exit
>
and CTRL-B does exit to regular >>> prompt too.

Thanks. I'll try contacting Dave Hylands (@dhylands) through PM.

User avatar
devnull
Posts: 473
Joined: Sat Jan 07, 2017 1:52 am
Location: Singapore / Cornwall
Contact:

Re: [nRF52] How to get rshell to work with an nRF52?

Post by devnull » Mon Oct 29, 2018 12:34 pm

Just want to add that although rshell is a great app, even if it could connect most of the file dsystem commans would not work as the NRF port is missing pretty much all of the os functions:

Code: Select all

>>> import os
>>> dir(os)
['__class__', '__name__', 'dupterm', 'ilistdir', 'listdir', 'remove', 'sep', 'stat', 'uname']
>>> 
These are missing:

Code: Select all

os.chdir
os.mkdir
os.rename
os.rmdir
And these are used in pretty much all of the filesystem commands used in rshell and ampy !

User avatar
WhiteHare
Posts: 129
Joined: Thu Oct 04, 2018 4:00 am

Re: [nRF52] How to get rshell to work with an nRF52?

Post by WhiteHare » Mon Oct 29, 2018 4:58 pm

I'd really like to have a way to copy a file from the target so that I can run a diff against the file that I transmitted OTA there. Right now the closest I can do is print a file to the UART.

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

Re: [nRF52] How to get rshell to work with an nRF52?

Post by dhylands » Mon Oct 29, 2018 5:25 pm

@WhiteHare It would be useful to get a logfile of the output of running rshell with the -d command line option, in addition to whatever other command line options you're using.

One of the commands rshell issues when first connecting to a board is the os.listdir command.

User avatar
WhiteHare
Posts: 129
Joined: Thu Oct 04, 2018 4:00 am

Re: [nRF52] How to get rshell to work with an nRF52?

Post by WhiteHare » Mon Oct 29, 2018 6:13 pm

dhylands wrote:
Mon Oct 29, 2018 5:25 pm
@WhiteHare It would be useful to get a logfile of the output of running rshell with the -d command line option, in addition to whatever other command line options you're using.

One of the commands rshell issues when first connecting to a board is the os.listdir command.
Behold:

Code: Select all

root@debian:/home/david/micropython/ports/nrf# rshell -d
Debug = True
Port = None
Baud = 115200
User = micro
Password = python
Wait = 0
nocolor = 0
binary = 0
Timing = 0
Quiet = 0
Buffer_size = 512
Cmd = []
Welcome to rshell. Use Control-D (or the exit command) to exit rshell.

No MicroPython boards connected - use the connect command to add one

/home/david/micropython/ports/nrf> 

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

Re: [nRF52] How to get rshell to work with an nRF52?

Post by dhylands » Mon Oct 29, 2018 6:17 pm

You seem to be missing the options to specify the serial port to connect to. rshell only connects automatically to USB Serial ports which have a vendor name of "MicroPython", otherwise you need to specify the serial port using the --port command line option.

User avatar
WhiteHare
Posts: 129
Joined: Thu Oct 04, 2018 4:00 am

Re: [nRF52] How to get rshell to work with an nRF52?

Post by WhiteHare » Mon Oct 29, 2018 7:04 pm

dhylands wrote:
Mon Oct 29, 2018 6:17 pm
You seem to be missing the options to specify the serial port to connect to. rshell only connects automatically to USB Serial ports which have a vendor name of "MicroPython", otherwise you need to specify the serial port using the --port command line option.
You mean like this?

Code: Select all

root@debian:/home/david/micropython/ports/nrf# rshell -d --port /dev/ttyACM0
Debug = True
Port = /dev/ttyACM0
Baud = 115200
User = micro
Password = python
Wait = 0
nocolor = 0
binary = 0
Timing = 0
Quiet = 0
Buffer_size = 512
Cmd = []
Connecting to /dev/ttyACM0 ...
----- About to send 286 bytes of code to the pyboard -----
def test_buffer():
    """Checks the micropython firmware to see if sys.stdin.buffer exists."""
    import sys
    try:
        _ = sys.stdin.buffer
        return True
    except:
        return False
output = test_buffer()
if output is None:
    print("None")
else:
    print(output)

-----
-----Response-----
b''
-----
Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/rshell/main.py", line 1197, in connect
    ip_address = socket.gethostbyname(port)
socket.gaierror: [Errno -2] Name or service not known

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/bin/rshell", line 11, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.5/dist-packages/rshell/command_line.py", line 4, in main
    rshell.main.main()
  File "/usr/local/lib/python3.5/dist-packages/rshell/main.py", line 2730, in main
    real_main()
  File "/usr/local/lib/python3.5/dist-packages/rshell/main.py", line 2692, in real_main
    connect(args.port, baud=args.baud, wait=args.wait, user=args.user, password=args.password)
  File "/usr/local/lib/python3.5/dist-packages/rshell/main.py", line 1203, in connect
    connect_serial(port, baud=baud, wait=wait)
  File "/usr/local/lib/python3.5/dist-packages/rshell/main.py", line 1227, in connect_serial
    dev = DeviceSerial(port, baud, wait)
  File "/usr/local/lib/python3.5/dist-packages/rshell/main.py", line 1473, in __init__
    Device.__init__(self, pyb)
  File "/usr/local/lib/python3.5/dist-packages/rshell/main.py", line 1276, in __init__
    self.has_buffer = self.remote_eval(test_buffer)
  File "/usr/local/lib/python3.5/dist-packages/rshell/main.py", line 1390, in remote_eval
    return eval(self.remote(func, *args, **kwargs))
  File "<string>", line 0
    
    ^
SyntaxError: unexpected EOF while parsing
root@debian:/home/david/micropython/ports/nrf# 

Post Reply