Zephyr port: can't access raw REPL

The official pyboard running MicroPython.
This is the reference design and main target board for MicroPython.
You can buy one at the store.
Target audience: Users with a pyboard.
Post Reply
M.Ridwan
Posts: 9
Joined: Mon Aug 24, 2020 2:03 pm

Zephyr port: can't access raw REPL

Post by M.Ridwan » Tue Aug 25, 2020 2:37 am

Dear Group Members,
I want to ask you, is there any alternative to REPL in Micropython? Is it possible if I write a code in Python and save a file for example MAIN.PY and flash it on to the board.
I have tried using AMPY but getting the following error:
ampy --port /dev/ttyACM0 run light.py
b'\r'
Traceback (most recent call last):
File "/home/rg/.local/bin/ampy", line 8, in <module>
sys.exit(cli())
File "/usr/lib/python3/dist-packages/click/core.py", line 764, in __call__
return self.main(*args, **kwargs)
File "/usr/lib/python3/dist-packages/click/core.py", line 717, in main
rv = self.invoke(ctx)
File "/usr/lib/python3/dist-packages/click/core.py", line 1137, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/usr/lib/python3/dist-packages/click/core.py", line 956, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/usr/lib/python3/dist-packages/click/core.py", line 555, in invoke
return callback(*args, **kwargs)
File "/home/rg/.local/lib/python3.8/site-packages/ampy/cli.py", line 337, in run
output = board_files.run(local_file, not no_output)
File "/home/rg/.local/lib/python3.8/site-packages/ampy/files.py", line 299, in run
self._pyboard.enter_raw_repl()
File "/home/rg/.local/lib/python3.8/site-packages/ampy/pyboard.py", line 192, in enter_raw_repl
raise PyboardError('could not enter raw repl')
ampy.pyboard.PyboardError: could not enter raw repl

Moreover, if I am using the method given in the link: http://docs.micropython.org/en/v1.12/re ... rd.py.html. I am getting the following error: pyboard.py: command not found

Please advise.

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

Re: pyboard.py command not found

Post by pythoncoder » Tue Aug 25, 2020 5:40 am

Taking your problems in reverse order, pyboard.py is an external tool which you will need to get from GitHub.

Re Ampy. My approach is to copy my script to the board and run it at the REPL. When it is debugged and working reliably I edit main.py to include the command to run the script. You might like to try this approach with Ampy.

Note I have no experience of Ampy - I use rshell.
Peter Hinch
Index to my micropython libraries.

M.Ridwan
Posts: 9
Joined: Mon Aug 24, 2020 2:03 pm

Re: pyboard.py command not found

Post by M.Ridwan » Tue Aug 25, 2020 6:57 am

Thanks Sir for your kind response. I have tried RSHELL as well and facing the same issue like AMPY. It is requested to guide me as how to copy the Python Script to the board? Is there any special command to perform this action? Using RSHELL my computer hangs at the following point:
rshell -p /dev/ttyACM0
Using buffer-size of 32
Connecting to /dev/ttyACM0 (buffer-size 32)...
Trying to connect to REPL.

Please advise.

Thank you.
Regards

M.Ridwan
Posts: 9
Joined: Mon Aug 24, 2020 2:03 pm

Re: pyboard.py command not found

Post by M.Ridwan » Tue Aug 25, 2020 7:02 am

Moreover sir, I am using Micropython Zephyr Port

M.Ridwan
Posts: 9
Joined: Mon Aug 24, 2020 2:03 pm

Re: pyboard.py command not found

Post by M.Ridwan » Tue Aug 25, 2020 7:36 am

Sir, Complete Error While Executing the RSHELL command
rshell -p /dev/ttyACM0
Using buffer-size of 32
Connecting to /dev/ttyACM0 (buffer-size 32)...
Trying to connect to REPL .. connected
Testing if ubinascii.unhexlify exists ... b'\r\n>>>elp()" for more information.\r\n>>> hzhelp()" for more information.\r\n>>> elp()" for more information.\r\n>>> help()" for more information.\r\n>>> help()" for more information.\r\n>>> help()" for more information.\r\n>>> help()" for more information.\r\n>>> help()" forhelp()" for more information.\r\n>>> help()" for'
Traceback (most recent call last):
File "/usr/local/lib/python3.8/dist-packages/rshell/main.py", line 1307, 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 8, in <module>
sys.exit(main())
File "/usr/local/lib/python3.8/dist-packages/rshell/command_line.py", line 4, in main
rshell.main.main()
File "/usr/local/lib/python3.8/dist-packages/rshell/main.py", line 2966, in main
real_main()
File "/usr/local/lib/python3.8/dist-packages/rshell/main.py", line 2928, in real_main
connect(args.port, baud=args.baud, wait=args.wait, user=args.user, password=args.password)
File "/usr/local/lib/python3.8/dist-packages/rshell/main.py", line 1313, in connect
connect_serial(port, baud=baud, wait=wait)
File "/usr/local/lib/python3.8/dist-packages/rshell/main.py", line 1337, in connect_serial
dev = DeviceSerial(port, baud, wait)
File "/usr/local/lib/python3.8/dist-packages/rshell/main.py", line 1627, in __init__
Device.__init__(self, pyb)
File "/usr/local/lib/python3.8/dist-packages/rshell/main.py", line 1391, in __init__
unhexlify_exists = self.remote_eval(test_unhexlify)
File "/usr/local/lib/python3.8/dist-packages/rshell/main.py", line 1515, in remote_eval
return eval(self.remote(func, *args, **kwargs))
File "/usr/local/lib/python3.8/dist-packages/rshell/main.py", line 1493, in remote
self.pyb.enter_raw_repl()
File "/usr/local/lib/python3.8/dist-packages/rshell/pyboard.py", line 197, in enter_raw_repl
raise PyboardError('could not enter raw repl')
rshell.pyboard.PyboardError: could not enter raw repl

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

Re: pyboard.py command not found

Post by pythoncoder » Tue Aug 25, 2020 3:54 pm

I think you need help from someone with experience of the Zephyr port. I've amended the title of your OP in the hope of triggering such a response.
Peter Hinch
Index to my micropython libraries.

mhelm
Posts: 3
Joined: Tue Aug 25, 2020 2:09 pm

Re: Zephyr port: can't access raw REPL

Post by mhelm » Tue Aug 25, 2020 9:42 pm

Is it possible if I write a code in Python and save a file for example MAIN.PY and flash it on to the board.
It is possible on boards that enable a block device for the VFS. For example, the mimxrt1050_evk board sets CONFIG_DISK_ACCESS_SDHC=y in ports/zephyr/boards/mimxrt1050_evk.conf, which enables the Zephyr SD card driver and Zephyr.DiskAccess block device class. The Zephyr port tries to mount a file system on the SD card during startup, but does not format a new file system if mounting fails.

Similarly, the reel_board sets CONFIG_FLASH_MAP=y in ports/zephyr/boards/reel_board.conf, which enables the flash driver and Zephyr.FlashArea block device class. The Zephyr port tries to mount a file system on the on-chip flash storage partition during startup, but does not format a new file system if mounting fails.

Your nrf board is more like the reel_board, so you should probably copy ports/zephyr/boards/reel_board.conf and rename it for your board. The name must match exactly to the board name you use to build zephyr, which will allow the build system to automatically pick up the supplemental Kconfig settings. You will also need to format a new file system on the flash storage partition.

You can find more information in the commit messages from the following pull requests:
https://github.com/micropython/micropython/pull/5462
https://github.com/micropython/micropython/pull/5747

I haven't done it recently, but I tested with pyboard.py when I created these pull requests.

M.Ridwan
Posts: 9
Joined: Mon Aug 24, 2020 2:03 pm

Re: Zephyr port: can't access raw REPL

Post by M.Ridwan » Wed Aug 26, 2020 2:06 am

Dear Sir @Peter Hinch, thank you for your kind support.

Dear Madam, @mhelm thank you very much for your detailed response. I have tried all the combination of Configurations. Starting from as you suggested, I copied all the "reel_board" configurations to "nrf52840dk_nrf52840.conf" file and I am getting the following error after running the command "make BOARD=nrf52840dk_nrf52840".
Note: I am pasting the error part of execution:

CC main.c
CC help.c
CC moduos.c
CC modusocket.c
CC modutime.c
CC modzephyr.c
In file included from modzephyr.h:30,
from modzephyr.c:35:
modzephyr.c:83:19: error: 'MP_QSTR_FlashArea' undeclared here (not in a function); did you mean 'MP_QSTR_measure'?
83 | { MP_ROM_QSTR(MP_QSTR_FlashArea), MP_ROM_PTR(&zephyr_flash_area_type) },
| ^~~~~~~~~~~~~~~~~
../../py/obj.h:96:56: note: in definition of macro 'MP_OBJ_NEW_QSTR'
96 | #define MP_OBJ_NEW_QSTR(qst) ((mp_obj_t)((((mp_uint_t)(qst)) << 3) | 2))
| ^~~
modzephyr.c:83:7: note: in expansion of macro 'MP_ROM_QSTR'
83 | { MP_ROM_QSTR(MP_QSTR_FlashArea), MP_ROM_PTR(&zephyr_flash_area_type) },
| ^~~~~~~~~~~
make: *** [../../py/mkrules.mk:63: build/modzephyr.o] Error 1

Moreover, I also tried the configurations by enabling only "CONFIG_FLASH_MAP=y" and in combination with "CONFIG_DISK_ACCESS_SDHC=y". With the aforementioned config, the program completes the MAKE execution but cannot enter raw REPL.

python3 pyboard.py --device /dev/ttyACM0 light.py
b'>>> \r\n>'
could not enter raw repl

Please advise.
Thanks in advance.

Regards

M.Ridwan
Posts: 9
Joined: Mon Aug 24, 2020 2:03 pm

Re: Zephyr port: can't access raw REPL

Post by M.Ridwan » Sun Aug 30, 2020 7:24 am

Dear madam @mhelm and sir Peter Hinch, I have tried all the combinations of the configurations as well as of the reel_board but I am getting the same following error.

python3 pyboard.py --device /dev/ttyACM0 light.py
b'>>> \r\n>'
could not enter raw repl


Note: I am able to directly program the board in REPL but I am unable to copy the Python Script to the board.

I have tested on five nrf52840 dk's with operating systems Ubuntu, Fedora by changing the PC's as well but I am getting the same error as mentioned above.

Requested to please help me in this regard as I am stuck with my work. I will be grateful for this favor.

Regards

M.Ridwan
Posts: 9
Joined: Mon Aug 24, 2020 2:03 pm

Re: Zephyr port: can't access raw REPL

Post by M.Ridwan » Sat Sep 05, 2020 2:18 am

Thank you @peter hinch sir and @mhelm mam, my problem is resolved. Thank you very much for your kind help.

Post Reply