Running Julia bare-metal on an Arduino

  • This is really impressive, and a great write up. I’ve been following the work on static compiling Julia to x86 libraries from the GPUCompiler.jl folks but I didn’t expect to see Julia working on an Arduino any time soon. With some kind of basic GC support (even if just using a bump allocator) it seems like a good fraction of the language could actually be available. Most tight loops hopefully don’t allocate so it would mostly just be necessary for creating initial arrays and mutable structs.

  • This is very promising for embedded control applications. Bootstrapping this with a simple allocator and even something as basic as FreeRTOS [1] combined with CBinding.jl [2] for portability would be game-changing for many applications, and directly compete with e.g. MathWorks' Arduino Simulink target [3]. ESP8266/32 next, once LLVM support [4] lands?

    [1]: https://microcontrollerslab.com/use-freertos-arduino/

    [2]: https://github.com/analytech-solutions/CBinding.jl

    [3]: https://www.mathworks.com/help/supportpkg/arduino/run-on-tar...

    [4]: https://github.com/espressif/llvm-project

  • I use Julia as my main programming language and I learned so much from reading this. I never knew Julia had Base.llvmcall, good to know!

    Just goes to show how important it can be to read code in completely different fields than the one you're working in. Some problems are common for others so they've already been solved. Knowing that a solution exists is half the battle.

  • LLVM is one of those truly awesome projects. LLVM gets a new backend and then for the most part many of the languages are able to generate code for it.

    Want to see Rust on that new m68k backend or 6502 backend mostly out of morbid curiosity.

  • Off topic but related: I played around with getting Nim running on an Arduino.

    1. I found a critical bug almost immediately, but Andreas fixed it within 24 hours, and was super helpful.

    2. Once the issue was resolved, it was surprisingly straight forward to get it running. I started by wrapping the arduino libs, and quickly shifted to wrapping the AVR libraries directly.

    One take away was: Nim (and Julia) are likely really nice languages to run in these sort of low-level environments.

    Another take away: there's an opportunity to develop a low-level C-based library to better support efforts like this. Both AVR and Arduino libraries weren't designed to be wrapped in something like Nim. And the Arduino codebase could use a healthy refactoring.

  • The default arduino toolchain, which is a g++ wrapper, supports C++, even though the whole system only has only 1 kilobyte of RAM.

    The C++ 'new' operator does seem to be supported, so I assume it has some kind of heap allocator - although I imagine that when you've only got 1 kilobyte to play with it gets quickly eaten by the allocators datastructures and C++ vtable pointers, not to mention the impact of fragmentation if you allocate any objects more than a few tens of bytes.