Julia for microcontrollers (like Micropython)

Dear Julia community members,

I wish to develop a fork of Julia that can run on low memory low ram microcontrollers .

Similar to Micropython (python for microcontrollers)

Micropython website

I’m working on low cost wifi module ESP8266 with micropython.

I’m working on developing RTOS for Internet of things.

Kindly shed some light on my path to reach my goal…

6 Likes

Welcome! I’m not sure how to help you, but I suspect you will have better luck with others if you follow some of these suggestions with your question.

The project you describe sounds like a big one, and when you just ask “what path should I take?” I’m guessing it’s a bit too vague, and very few people will have any sense of how to help you. Maybe tell us what you’ve done already, and what problems you’ve encountered that you need help solving.

2 Likes

This is a great idea! I’ve been hoping one of the chip manufacturers would pick up on how great Julia is and integrate it themselves. I saw that the university of Malta is working on an LLVM for the 16 bit MSP430, so you might get some information there.
This does sound like a monumental task, and I can’t wait to see you succeed!

In theory something like Micropython could be replicated for Julia, (while it would be even more work for e.g. that MCU; I wasn’t even sure MicroPython supported any non-ARM ones). ARM (or x86) MCU would be the best bet.

Since you can call Python with PyCall.jl, or should I say, call Julia from Pyhon using PyJulia package (that’s based on PyCall.jl), it might be helpful to look into if PyJulia would work with MicroPython. It likely doesn’t because MicroPython is baremetal non-standard variant. Julia however requires an OS (currently at least) and a filesystem. I’m not sure you have any filesystem [access] with MicroPython. MicroPython also has changed garbage collection from regular Python. That it supports real-time use is interesting (and I recall based on fixed amount of memory and knowing the exact hardware/size). Getting the same GC guarantees with Julia should be possible, but I wouldn’t rely on it happening just by change.

Julia would not work directly on ESP8266 given that it uses “L106 32-bit RISC microprocessor core based on the Tensilica Xtensa”; and neither for any 16-bit despite it working on an LLVM:

E.g. even with 8/16-bit AVR having LLVM support (and working with Rust language, or getting there), that CPU, or any non-32-bit (or 64-bit), such as MSP430, will not work with Julia (see my thread in it; ans answers on how difficult and unlikely adding 26-bit support is; long term I see 8- and 16-bit CPUs as dead anyway, and would concentrate on ARM).

Only possibly workaround might be Julia2C (see other microcontroller thread where I wrote about that).

2 Likes

Just FYI, Espressif released a work in progress LLVM version for Xtensa last week. I don’t think it is ready for prime time quite yet, but the ESP32 is a 32-bit architecture, and while this development was likely aimed at Rust, seems as though Julia could piggy-back as well some day?

https://esp32.com/viewtopic.php?t=9226

1 Like

This still runs into the problem of requiring a Julia runtime + large shared libraries to get a fully-functional system, but at least with a working LLVM backend we could do something like CUDAnative and launch “kernels” on the ESP32 as an accelerator of sorts. I’d be open to contributing to something like that once my free time becomes less finite :smile:

2 Likes

Forgive my ignorance, but what I personally would favor is a sort of Julia API for programming microcontrollers such as the ESP32, etc. I wouldn’t care so much if it’s actually C running the chip as long as I don’t need to learn C and just use Julia.

I feel like it would be much less work to write a Julia API/wrapper for microcontroller programming than it would be to write a “microJulia” that runs on MCUs. But again I point you to my ignorance here.

2 Likes

ESP32/Xtensa is not supported by Julia language, and likely never will. It’s not theoretically impossible however, it seems: GitHub - espressif/llvm-project: Fork of LLVM with Xtensa specific patches. To be upstreamed.

You can of course interface with any microcontroller somehow with Julia, but the best bet to get Julia code running on one would be on ARM and nothing else really viable. Long-term I don’t even see the point of any non-ARM for any embedded system, Julia or not. Is ESP32 better or cheaper for anything?

The ESP32 is fast, it is cheap and provides WiFi and Bluetooth out of the box but the analog inputs are terrible. I have been using it frequently.

The new Pi Pico doesn’t run Linux, but possibly Julia could be made to work on that Unix/microcontroller (or similar):

“Dual-core Arm Cortex-M0+ @ 133MHz” is not a lot, and 264KB RAM certainly limiting, and (at least currently):

The Fuzix port only uses one of the Pico’s cores

http://cowlark.com/2021-02-09-esp8266-fuzix/

Again, I would suggest a Julia API to write and compile Lua or C++ or Assembly code to program any particular MCU, not try to have the MCU run Julia. This is given my all too many hobbies and the likelihood of picking up a lower-level language is slim despite the desire. So it would be nice to just learn an API in a language I already know and use (i.e. Julia) to do more exciting things (i.e. program MCUs).

Maybe not the best solution, but I can’t be the only one that doesn’t know C/C++ but would enjoy programming MCUs.

1 Like