bare metal Raspberry Pi Zero port

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
boochow
Posts: 13
Joined: Sat Dec 16, 2017 9:36 am

bare metal Raspberry Pi Zero port

Post by boochow » Wed Jul 25, 2018 3:54 pm

Hi all,

I have been working on Raspberry Pi port after @naums releases his PR (https://github.com/micropython/micropython/pull/3522) at the last year end.
Yes, I know the previous discussions about Raspberry Pi port (viewtopic.php?f=12&t=1192) but I do this to learn the inside of MicroPython, and just for my fun.

Currently, the port has some basic modules and Raspberry Pi specific modules/classes including Pin, SPI, I2C, Timer, SD(read-only), GPU.
It also has experimental (not stable) USB host controller support to use a USB keyboard for REPL input so you can make a standalone (no UART interface to host) MicroPython machine with a RPi and a keyboard and a HDMI monitor. (It is still a proof-of-concept level demo because USB IRQ is not implemented, thus you cannot stop your script by hitting Ctrl-C.)

If you are interested in, please visit my repo: https://github.com/boochow/micropython-raspberrypi
or watch this video. https://www.youtube.com/watch?v=aUXRWUTasrY

User avatar
marfis
Posts: 161
Joined: Fri Oct 31, 2014 10:29 am
Location: Zurich / Switzerland

Re: bare metal Raspberry Pi Zero port

Post by marfis » Wed Jul 25, 2018 6:27 pm

including Pin, SPI, I2C, Timer, SD(read-only), GPU.
impressive. just out of curiosity, how kong does it take to boot to REPL?

OutoftheBOTS_
Posts: 393
Joined: Mon Nov 20, 2017 10:18 am

Re: bare metal Raspberry Pi Zero port

Post by OutoftheBOTS_ » Wed Jul 25, 2018 9:56 pm

Considering the price of a RPi zero and the resources on it, it would be a pretty awesome Micro-Python MCU.

The main reason that I switched from RPi to Micro-python was because of the latency issues with running an OS on the RPi but this solves that problem.

Since the RPi is WiFi enabled then a FTP server could be added to edit/transfer scripts from PC wireless.

I have been using a 5" HDMI screen with my RPi zero projects for a display on the project but using my PC (screen) and my programming interface. The 5" screen that I use sources it's power from the power pin on the HDMI cable so only needs the 1 cable to run.

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

Re: bare metal Raspberry Pi Zero port

Post by pythoncoder » Thu Jul 26, 2018 4:50 am

boochow wrote:
Wed Jul 25, 2018 3:54 pm
...(It is still a proof-of-concept level demo because USB IRQ is not implemented, thus you cannot stop your script by hitting Ctrl-C.)...
This looks excellent, especially when you manage to fix this. I assume you can import modules from the SD card?

With write access to the SD card and raw REPL there would be scope for doing development using rshell.
Peter Hinch

User avatar
boochow
Posts: 13
Joined: Sat Dec 16, 2017 9:36 am

Re: bare metal Raspberry Pi Zero port

Post by boochow » Fri Jul 27, 2018 11:12 am

Hi, thank you all for your comments.

>> impressive. just out of curiosity, how kong does it take to boot to REPL?

It takes around 4 seconds to boot.

>> Since the RPi is WiFi enabled then a FTP server could be added to edit/transfer scripts from PC wireless.

Unfortunately, I think it is very hard to add WiFi ability to MicroPython because there is no technical resource available concerning the RPi Zero W's WiFi controller. If you want any network connectivity, the easiest way IMHO is to use Wiznet5K chip connected to the SPI.

>> This looks excellent, especially when you manage to fix this. I assume you can import modules from the SD card?
>> With write access to the SD card and raw REPL there would be scope for doing development using rshell.

Yes, you can import modules from SD card. And also, I had included a code as a frozen module which creates RAM disk and mount it on the root at boot time, so the root directory is writable already.
I have not tested rshell yet, but hope it is not difficult because uPyCraft already works well.

User avatar
boochow
Posts: 13
Joined: Sat Dec 16, 2017 9:36 am

Re: bare metal Raspberry Pi Zero port

Post by boochow » Tue Jul 31, 2018 3:11 pm

boochow wrote:
Fri Jul 27, 2018 11:12 am
>> With write access to the SD card and raw REPL there would be scope for doing development using rshell.
I had included a code as a frozen module which creates RAM disk and mounts it on the root at boot time, so the root directory is writable already.
I have not tested rshell yet, but hope it is not difficult because uPyCraft already works well.
I tried to use rshell but found that there are some problems.

1) rshell's method `enter_raw_repl()` sends Ctrl-D to soft-reboot the pyboard which causes re-initializing the RAM disk.
It means that every shell command execution on the pyboard erases all the files on the RAM disk. So, copying files between host and pyboard is almost impossible (entering repl mode just after copying file is the only way to use copied files).

2) Raspberry Pi port has 128MB heap space. Since it is much larger than other platforms, `gc_init()` takes a few seconds. Every rshell command invokes this process and from the user's point of view, rshell commands respond very slow.

I do understand that soft-rebooting pyboard for each command execution is necessary to keep each command execution environment being independent of effects from previously executed commands.
There seems to be no explicit solution to this problem IMHO. (excepting implementing write method for SD card, of course)

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

Re: bare metal Raspberry Pi Zero port

Post by dhylands » Tue Jul 31, 2018 7:05 pm

I noticed that on the ESP32 that using rshell doesn't seem to do a soft-reset at the repl, while pressing Control-D does. I haven't investigated this to see exactly how it was done, but it's probably worth looking at.

OutoftheBOTS_
Posts: 393
Joined: Mon Nov 20, 2017 10:18 am

Re: bare metal Raspberry Pi Zero port

Post by OutoftheBOTS_ » Tue Jul 31, 2018 9:55 pm

Unfortunately, I think it is very hard to add WiFi ability to MicroPython because there is no technical resource available concerning the RPi Zero W's WiFi controller.
:(
That's a little sad.

User avatar
boochow
Posts: 13
Joined: Sat Dec 16, 2017 9:36 am

Re: bare metal Raspberry Pi Zero port

Post by boochow » Wed Aug 01, 2018 12:51 pm

@dhylands Thank you for the information. I'm sorry my comment was not clear.
What I mean is that all rshell commands that execute a script on the pyboard (ls, cp, cat, etc.) do a soft-reboot at the beginning of execution.
MicroPython on ESP32 does a soft-reboot in the same manner.

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

Re: bare metal Raspberry Pi Zero port

Post by dhylands » Wed Aug 01, 2018 10:50 pm

So this us what I tried with my ESP32:

Code: Select all

503 >rshell -p /dev/ttyUSB1 -a --buffer-size=32
Connecting to /dev/ttyUSB1 ...
Welcome to rshell. Use Control-D to exit.
/home/dhylands> repl
Entering REPL. Use Control-X to exit.
>
MicroPython ESP32_LoBo_v3.2.12 - 2018-04-18 on ESP32 board with ESP32
Type "help()" for more information.
>>> 
>>> x = 3
>>>  
/home/dhylands> repl
Entering REPL. Use Control-X to exit.

>>> print(x)
3
>>>  
/home/dhylands> ls /flash
example/        webthing/       config.py       main2.py        LICENSE         rshell.txt     
upy/            boot.py         connect.py      start.py        README.md       usb-ser-mon.log
/home/dhylands> repl
Entering REPL. Use Control-X to exit.
>
MicroPython ESP32_LoBo_v3.2.12 - 2018-04-18 on ESP32 board with ESP32
Type "help()" for more information.
>>> 
>>> print(x)
3
>>> 
If I do the same thing on a pyboard, then the print(x) after the ls fails, because it did a soft-reset:

Code: Select all

506 >rshell
Connecting to /dev/ttyACM0 ...
Welcome to rshell. Use Control-D to exit.
/home/dhylands> repl
Entering REPL. Use Control-X to exit.
>
MicroPython v1.9.3-521-gd6cf5c674 on 2018-05-22; PYBv1.1 with STM32F405RG
Type "help()" for more information.
>>> 
>>> x = 3
>>>  
/home/dhylands> repl
Entering REPL. Use Control-X to exit.

>>> print(x)
3
>>>  
/home/dhylands> ls /flash
boot.py          extint_test.py   main.py          pyb_test.py      songs.py         t.py             delme1.txt       delme3.del      
cmd.py           extint_toggle.py memvw.py         rtttl.py         sss.py           README.txt       delme2.del       foo             
consume.py       foo.py           pc_test.py       shell.py         sw.py            all-bytes.dat    delme2.txt       pybcdc.inf      
/home/dhylands> repl
Entering REPL. Use Control-X to exit.
>
MicroPython v1.9.3-521-gd6cf5c674 on 2018-05-22; PYBv1.1 with STM32F405RG
Type "help()" for more information.
>>> 
>>> print(x)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'x' is not defined
>>> 
The fact that x remains defined tell me that the repl isn't being soft-reset when doing the ls command. (this esp32 has the loboris port on it) If I press Control-D on the esp32 repl, and then try print(x) it fails to find x.

Post Reply