bare metal Raspberry Pi Zero port
bare metal Raspberry Pi Zero port
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
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
Re: bare metal Raspberry Pi Zero port
impressive. just out of curiosity, how kong does it take to boot to REPL?including Pin, SPI, I2C, Timer, SD(read-only), GPU.
-
- Posts: 847
- Joined: Mon Nov 20, 2017 10:18 am
Re: bare metal Raspberry Pi Zero port
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.
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.
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: bare metal Raspberry Pi Zero port
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
Index to my micropython libraries.
Index to my micropython libraries.
Re: bare metal Raspberry Pi Zero port
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.
>> 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.
Re: bare metal Raspberry Pi Zero port
I tried to use rshell but found that there are some problems.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.
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)
Re: bare metal Raspberry Pi Zero port
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.
-
- Posts: 847
- Joined: Mon Nov 20, 2017 10:18 am
Re: bare metal Raspberry Pi Zero port
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.
Re: bare metal Raspberry Pi Zero port
@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.
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.
Re: bare metal Raspberry Pi Zero port
So this us what I tried with my ESP32:
If I do the same thing on a pyboard, then the print(x) after the ls fails, because it did a soft-reset:
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.
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
>>>
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
>>>