- Home
- Discussion Forum
- AROS FORUMS
- Development General
- Port of micropython to Rasberry Pi AROS (WIP)
Port of micropython to Rasberry Pi AROS (WIP)
Last updated on 2 minutes ago
tennis74Newbie
Posted 1 day agoHi,
I have a Work in Progress port of micropython for Rasberry Pi AROS and supports
the hardware peripherals as GPIO, UART, I2C, SPI, PWM.
Link : https://github.co...icropython
WIP release : https://github.co...es/tag/WIP
Micropython is very close to the full Python 3 language, but with
some smaller differences : https://docs.micr...index.html
This was tested on a Pi400 and GPIO + UART is confirmed to work.
When the peripherals are working a huge amount of device drivers
already available for micropython should then work out of the box.
If you have any device with the standard ports, there is a good chance
to find a ready drive on the internet.
Documentation for using the peripherals are found in the official
micropython site : https://docs.micr...chine.html
Open issues:
- Open with icon not handled. Probably can be copied from lua port.
- Currently the input echo each line to the output (raw input fix with termios or maybe Dos?)
- Ctrl+C signal is not implemented. To exit : "import sys; sys.exit(0)"
- Raw 1MHz clock access used. ("timer.device" with UNIT_MICROHZ only seem to give 100Hz frequency)
1MHz clock needed for onewire bit banging and other accurate timing purposes.
- Enable/Disable used for critical timing sections. Not sure this is the right solution.
- GPIO interrupts seems to be available, but not implemented. Useful for buttons, encoders etc.
- Direct use of peripherals probably should be use the AROS api where available.
- Threading not enabled.
- Soft timer device is missing. Can probably be copied from the SDL3 port with separate running thread.
- Networking not enabled (socket module needed)
I was hoping someone with more in-depth knowledge of AROS could take a look at
this port and give some advice how to sanitize and improve the code for general
consumption.
Edit : Link to WIP release added. Missing patch and updated build instructions added to Github
I have a Work in Progress port of micropython for Rasberry Pi AROS and supports
the hardware peripherals as GPIO, UART, I2C, SPI, PWM.
Link : https://github.co...icropython
WIP release : https://github.co...es/tag/WIP
Micropython is very close to the full Python 3 language, but with
some smaller differences : https://docs.micr...index.html
This was tested on a Pi400 and GPIO + UART is confirmed to work.
When the peripherals are working a huge amount of device drivers
already available for micropython should then work out of the box.
If you have any device with the standard ports, there is a good chance
to find a ready drive on the internet.
Documentation for using the peripherals are found in the official
micropython site : https://docs.micr...chine.html
Open issues:
- Open with icon not handled. Probably can be copied from lua port.
- Currently the input echo each line to the output (raw input fix with termios or maybe Dos?)
- Ctrl+C signal is not implemented. To exit : "import sys; sys.exit(0)"
- Raw 1MHz clock access used. ("timer.device" with UNIT_MICROHZ only seem to give 100Hz frequency)
1MHz clock needed for onewire bit banging and other accurate timing purposes.
- Enable/Disable used for critical timing sections. Not sure this is the right solution.
- GPIO interrupts seems to be available, but not implemented. Useful for buttons, encoders etc.
- Direct use of peripherals probably should be use the AROS api where available.
- Threading not enabled.
- Soft timer device is missing. Can probably be copied from the SDL3 port with separate running thread.
- Networking not enabled (socket module needed)
I was hoping someone with more in-depth knowledge of AROS could take a look at
this port and give some advice how to sanitize and improve the code for general
consumption.
Edit : Link to WIP release added. Missing patch and updated build instructions added to Github
Edited by tennis74 on 17-11-2026 06:04, 12 hours ago
2 users reacted to this post
Argo, Bohun
BohunDistro Maintainer
Posted 6 hours agoVery interesting! I'll keep my fingers crossed and advertise on the Raspberry Pi forum.
coffeecatSoftware Dev
Posted 3 hours agoNice work, and good to see real peripherals working on a Pi 400.
I maintain a CPython 3.14 port for AROS (https://github.com/tomaszstaniak/aros-cpython, x86_64 so far, Rspi in progress but I believe both ports are complementary), and I read through your sources. Several of your open issues are ones I ran into as well, so here is what I know.
Timer
The 100 Hz limit of timer.device on the Pi should be gone in current mainline. Since 2026-09-21 the tick compare is armed for the head UNIT_MICROHZ request, and since 2026-11-16 (#2287) ReadEClock() reads the 1 MHz system timer directly. With a recent nightly you should be able to use ReadEClock() for ticks_us() and a timer.device request for sleeping. I have not measured this on a Pi myself.
Delays
mp_hal_delay_ms() and time.sleep() are busy loops at the moment, so a sleeping script takes a whole core. A timer.device request (or Delay() for coarse waits) lets other tasks run. Keep the busy loop only for the short microsecond delays that bit-banging needs.
Disable()/Enable()
This stops task switching and interrupts for the whole system, so it should stay limited to very short sections such as a one-wire time slot. Forbid()/Permit() is enough when you only need to keep other tasks out.
Peripherals
Mainline has gpio.resource with GPIOSet, GPIOSetFunc, GPIOGet and GPIOSetPull, and an I2C driver (i2c-bcm2708). Using them instead of writing the registers from the program avoids conflicts with system drivers that use the same pins. There is nothing comparable for SPI and PWM as far as I can see, so direct access is the only option there for now.
Ctrl+C
There are two cases. While a script runs, poll the task's break signal with SetSignal(0, SIGBREAKF_CTRL_C) from the VM hook and call mp_sched_keyboard_interrupt() when the bit is set. While the REPL reads input in raw mode, the console does not raise the signal: Ctrl+C arrives as byte 0x03 and you handle it yourself.
My terminal, Limpet (https://github.com/tomaszstaniak/limpet), has small working examples of both: tests/break_probe.c shows the signal poll and the raw-mode byte side by side, sdk/examples/progress.c is a work loop stopped by Ctrl+C, and examples/ssh/stream.c combines SetMode(Input(), 1) with the signal poll in a real program. They use plain DOS calls, so they behave the same under the system console.
Raw input and echo
Use dos.library: SetMode(Input(), 1) switches the console to raw mode, and SetMode(Input(), 0) restores it on exit. WaitForChar() gives you a non-blocking poll. Note that in raw mode special keys arrive as CSI sequences starting with 0x9b, not ESC [.
Start from an icon
When argc is 0, argv is the WBStartup message. Open your own CON: window for stdin and stdout, and take the script from the message arguments or ToolTypes.
Things that cost me time in CPython
- Stack: the Shell default is small. I set it explicitly (Stack command, or a stack cookie in the binary). Your stack check assumes 80 KB, so it is worth confirming what the process really gets.
- Requesters: a path such as "foo:bar" on a volume that does not exist opens a DOS requester and the program waits. Setting pr_WindowPtr to -1 in the process at startup avoids that.
- Sockets: a bsdsocket.library base belongs to the task that opened it. Sockets created in one thread do not work in another, and the failing calls return -1 without setting errno. Plan for one library base per thread when you enable both threads and the socket module.
- Threads: AROS libpthread gives the main thread the id 0, which collides with code that uses 0 as "no owner".
Small things in the code
- uart_core.c, mp_hal_stdout_tx_strn(): the condition is inverted. It returns 0 bytes written when write() succeeds.
- rpi.c: rpi_freq_cpu() returns the core clock, not the CPU clock.
- rpi_init() prints periiobase and the core clock on every start.
- The peripheral base is stored in a uint32_t. An IPTR is safer.
I'm not a hardcore AROS dev just do a thing here and there so happy if anyone corrects my notes
I maintain a CPython 3.14 port for AROS (https://github.com/tomaszstaniak/aros-cpython, x86_64 so far, Rspi in progress but I believe both ports are complementary), and I read through your sources. Several of your open issues are ones I ran into as well, so here is what I know.
Timer
The 100 Hz limit of timer.device on the Pi should be gone in current mainline. Since 2026-09-21 the tick compare is armed for the head UNIT_MICROHZ request, and since 2026-11-16 (#2287) ReadEClock() reads the 1 MHz system timer directly. With a recent nightly you should be able to use ReadEClock() for ticks_us() and a timer.device request for sleeping. I have not measured this on a Pi myself.
Delays
mp_hal_delay_ms() and time.sleep() are busy loops at the moment, so a sleeping script takes a whole core. A timer.device request (or Delay() for coarse waits) lets other tasks run. Keep the busy loop only for the short microsecond delays that bit-banging needs.
Disable()/Enable()
This stops task switching and interrupts for the whole system, so it should stay limited to very short sections such as a one-wire time slot. Forbid()/Permit() is enough when you only need to keep other tasks out.
Peripherals
Mainline has gpio.resource with GPIOSet, GPIOSetFunc, GPIOGet and GPIOSetPull, and an I2C driver (i2c-bcm2708). Using them instead of writing the registers from the program avoids conflicts with system drivers that use the same pins. There is nothing comparable for SPI and PWM as far as I can see, so direct access is the only option there for now.
Ctrl+C
There are two cases. While a script runs, poll the task's break signal with SetSignal(0, SIGBREAKF_CTRL_C) from the VM hook and call mp_sched_keyboard_interrupt() when the bit is set. While the REPL reads input in raw mode, the console does not raise the signal: Ctrl+C arrives as byte 0x03 and you handle it yourself.
My terminal, Limpet (https://github.com/tomaszstaniak/limpet), has small working examples of both: tests/break_probe.c shows the signal poll and the raw-mode byte side by side, sdk/examples/progress.c is a work loop stopped by Ctrl+C, and examples/ssh/stream.c combines SetMode(Input(), 1) with the signal poll in a real program. They use plain DOS calls, so they behave the same under the system console.
Raw input and echo
Use dos.library: SetMode(Input(), 1) switches the console to raw mode, and SetMode(Input(), 0) restores it on exit. WaitForChar() gives you a non-blocking poll. Note that in raw mode special keys arrive as CSI sequences starting with 0x9b, not ESC [.
Start from an icon
When argc is 0, argv is the WBStartup message. Open your own CON: window for stdin and stdout, and take the script from the message arguments or ToolTypes.
Things that cost me time in CPython
- Stack: the Shell default is small. I set it explicitly (Stack command, or a stack cookie in the binary). Your stack check assumes 80 KB, so it is worth confirming what the process really gets.
- Requesters: a path such as "foo:bar" on a volume that does not exist opens a DOS requester and the program waits. Setting pr_WindowPtr to -1 in the process at startup avoids that.
- Sockets: a bsdsocket.library base belongs to the task that opened it. Sockets created in one thread do not work in another, and the failing calls return -1 without setting errno. Plan for one library base per thread when you enable both threads and the socket module.
- Threads: AROS libpthread gives the main thread the id 0, which collides with code that uses 0 as "no owner".
Small things in the code
- uart_core.c, mp_hal_stdout_tx_strn(): the condition is inverted. It returns 0 bytes written when write() succeeds.
- rpi.c: rpi_freq_cpu() returns the core clock, not the CPU clock.
- rpi_init() prints periiobase and the core clock on every start.
- The peripheral base is stored in a uint32_t. An IPTR is safer.
I'm not a hardcore AROS dev just do a thing here and there so happy if anyone corrects my notes
tennis74Newbie
Posted 2 minutes agoThanks for the excellent reply here @coffeecat.
First I plan to setup a test rig where I can test the hardware peripherals and
then I have a basis for doing more sweeping changes.
With your comments I know where to start and fix the outstanding issues.
I will update this post later with the progress on this.
First I plan to setup a test rig where I can test the hardware peripherals and
then I have a basis for doing more sweeping changes.
With your comments I know where to start and fix the outstanding issues.
I will update this post later with the progress on this.
You can view all discussion threads in this forum.
You cannot start a new discussion thread in this forum.
You cannot reply in this discussion thread.
You cannot start on a poll in this forum.
You cannot upload attachments in this forum.
You cannot download attachments in this forum.
You cannot start a new discussion thread in this forum.
You cannot reply in this discussion thread.
You cannot start on a poll in this forum.
You cannot upload attachments in this forum.
You cannot download attachments in this forum.
Moderator: Administrator, Moderators
