Raspberry Pi Port
Posted: Wed Apr 26, 2017 2:50 pm
Hello,
I started porting micropython to the Raspberry Pi. You can find the current state in [1]. I had to do the following: in lib/utils/printf.c there were several occurances of a output-function probably used by the stm-port directly. I found the macro MP_PLAT_PRINT_STRN to be of more use here, so I changed the output-functions puts and putchar to use this macro instead. The macro is defined in the mpconfigport.h of the port.
The code for the port itself began rather barebones at the moment. I initiated the micropython-interpreter, had a run at five very small scripts to run (the latter two fail), and then put the Pi into an infinite loop blinking its LED.
Now I started adding a module for RawPtr-access and started implementing a "driver" for the GPIO-Pins of the Raspberry Pi.
The port uses newlib as a libc-implementation, especially for free and malloc, but also for some other functions (mostly string.h). The port uses the UART-chip of the Pi to communicate to the PC (you can use an Adafruit TTL-USB cable, or any other cable, which provides the right voltages!). The code utilizing the UART was copied from dwelch67 on github; the linkerscript, Makefile and parts of the port are based on the BakingPi-Tutorial of Alex Chadwick.
At the moment the code crashes after running for a while. My guess is, that either the memory managment gives up, or the compiler optimizes some loops out. The current code (see main.c:105-152) runs as far as calling gpio_write once, returning normally, enters the second and seems to not "return" from some of the if-statements - a print-statement placed directly after it will not be executed. Removing some of the print-statements scattered throughout the script will result in the code not even managing to run until that place. Your guess for what may be wrong is very welcome.
One side note, if I may: it would be really nice if the micropython-code was actually documented better. Doxygen-documentations help people like me, who just want to get the code running on a different plattform, to get started and understand error messages. I got several failed assertions all over the place testing the code until now, and I cannot figure out what causes them, why these assertions are there and what I can do to prevent them from failing.
[1] https://github.com/naums/micropython
Kind Regards,
Stefan Naumann
I started porting micropython to the Raspberry Pi. You can find the current state in [1]. I had to do the following: in lib/utils/printf.c there were several occurances of a output-function probably used by the stm-port directly. I found the macro MP_PLAT_PRINT_STRN to be of more use here, so I changed the output-functions puts and putchar to use this macro instead. The macro is defined in the mpconfigport.h of the port.
The code for the port itself began rather barebones at the moment. I initiated the micropython-interpreter, had a run at five very small scripts to run (the latter two fail), and then put the Pi into an infinite loop blinking its LED.
Now I started adding a module for RawPtr-access and started implementing a "driver" for the GPIO-Pins of the Raspberry Pi.
The port uses newlib as a libc-implementation, especially for free and malloc, but also for some other functions (mostly string.h). The port uses the UART-chip of the Pi to communicate to the PC (you can use an Adafruit TTL-USB cable, or any other cable, which provides the right voltages!). The code utilizing the UART was copied from dwelch67 on github; the linkerscript, Makefile and parts of the port are based on the BakingPi-Tutorial of Alex Chadwick.
At the moment the code crashes after running for a while. My guess is, that either the memory managment gives up, or the compiler optimizes some loops out. The current code (see main.c:105-152) runs as far as calling gpio_write once, returning normally, enters the second and seems to not "return" from some of the if-statements - a print-statement placed directly after it will not be executed. Removing some of the print-statements scattered throughout the script will result in the code not even managing to run until that place. Your guess for what may be wrong is very welcome.
One side note, if I may: it would be really nice if the micropython-code was actually documented better. Doxygen-documentations help people like me, who just want to get the code running on a different plattform, to get started and understand error messages. I got several failed assertions all over the place testing the code until now, and I cannot figure out what causes them, why these assertions are there and what I can do to prevent them from failing.
[1] https://github.com/naums/micropython
Kind Regards,
Stefan Naumann