# Julia for microcontrollers (like Micropython)

**URL:** <https://discourse.julialang.org/t/julia-for-microcontrollers-like-micropython/15393>\
**Category:** Internals & Design\
**Tags:** proposal\
**Created:** [September 23, 2018, 5:13pm UTC](https://discourse.julialang.org/t/julia-for-microcontrollers-like-micropython/15393 "2018-09-23T17:13:36Z")\
**Posts on this page:** 6\
**Page:** 2

<div class="post-metadata">

**Author:** ![jpsamaroo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jpsamaroo/32/46804_2.png) [@jpsamaroo](https://discourse.julialang.org/u/jpsamaroo)\
**Post date:** [August 19, 2021, 10:05pm UTC](https://discourse.julialang.org/t/julia-for-microcontrollers-like-micropython/15393/21 "2021-08-19T22:05:05Z")

</div>

> [@znmeb](#):
>
> A host (most likely a BeagleBone Black or an NVIDIA Jetson) plus microcontroller is also a viable option.

If you wanted something architecture-agnostic, and you didn’t mind slightly worse performance, you could use a C toolchain to compile [ubpf](https://github.com/iovisor/ubpf) (stripped of certain features) directly for the microcontroller once, and then use [BPFnative.jl](https://github.com/jpsamaroo/BPFnative.jl) to emit BPF kernels to run on the ubpf interpreter. While it wasn’t originally designed for embedded use, I could see it being quite effective for hardware-agnostic event-driven programming.

---

<div class="post-metadata">

**Author:** ![dlakelan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dlakelan/32/8491_2.png) [@dlakelan](https://discourse.julialang.org/u/dlakelan)\
**Post date:** [August 19, 2021, 10:44pm UTC](https://discourse.julialang.org/t/julia-for-microcontrollers-like-micropython/15393/22 "2021-08-19T22:44:07Z")

</div>

Hi @jpsamaroo, can you describe what it is that BPFnative does exactly? it sounds awesome, and I’m imagining using it to program packet classifiers in Julia with eBPF emitted, but there don’t seem to be any docs? How do I use it, or at least where do I read about how to use it?

---

<div class="post-metadata">

**Author:** ![jpsamaroo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jpsamaroo/32/46804_2.png) [@jpsamaroo](https://discourse.julialang.org/u/jpsamaroo)\
**Post date:** [August 20, 2021, 2:13am UTC](https://discourse.julialang.org/t/julia-for-microcontrollers-like-micropython/15393/23 "2021-08-20T02:13:59Z")

</div>

BPFnative allows generating [eBPF](https://ebpf.io/) bytecode from simple Julia functions, using the same compilation infrastructure used by CUDA.jl and the other GPU frontends. Currently it just has bindings to support calling into libbpf (the Linux library for attaching BPF programs), but there’s no reason you can’t use `BPFnative.bpffunction` directly to emit bytecode to a file or stream and load it onto an MCU running ubpf.

I would recommend reading the tests in lieu of documentation right now; they’re pretty comprehensive and show how to do various kinds of fancy things, like modifying packets, printing kernel stacktraces, etc.

---

<div class="post-metadata">

**Author:** ![dlakelan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dlakelan/32/8491_2.png) [@dlakelan](https://discourse.julialang.org/u/dlakelan)\
**Post date:** [August 20, 2021, 2:17am UTC](https://discourse.julialang.org/t/julia-for-microcontrollers-like-micropython/15393/24 "2021-08-20T02:17:17Z")

</div>

Thanks, I’ve been wanting to use eBPF in some applications with OpenWrt but I don’t really want to get into compiling C to eBPF, so I’m excited to think that you could do it in Julia which is just substantially more friendly (and generally awesome).

I’ll post over at [forum.openwrt.org](http://forum.openwrt.org) to see if anyone wants to work on it and test it out. If you’re interested in this application I invite you to go over there and participate!

---

<div class="post-metadata">

**Author:** ![Alexander-Barth](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/alexander-barth/32/3692_2.png) [@Alexander-Barth](https://discourse.julialang.org/u/Alexander-Barth)\
**Post date:** [September 18, 2023, 10:09am UTC](https://discourse.julialang.org/t/julia-for-microcontrollers-like-micropython/15393/25 "2023-09-18T10:09:17Z")

</div>

As this post is now the top result for “julia xtensa” for me, I just want to add that LLVM has merged the patches for [xtensa support](https://github.com/search?q=repo%3Allvm%2Fllvm-project+Xtensa&type=commits) and support is available in LLVM 16 (maybe the support is still label as experimental). Julia 1.10 currently uses LLVM 15.

Here is a nice post on how to use julia on Arduino:  
[https://seelengrab.github.io/articles/Running%20Julia%20baremetal%20on%20an%20Arduino/](https://seelengrab.github.io/articles/Running%20Julia%20baremetal%20on%20an%20Arduino/)

Maybe this approach is similar to get julia on xtensa working (with a newer LLVM).

---

<div class="post-metadata">

**Author:** ![Alexander-Barth](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/alexander-barth/32/3692_2.png) [@Alexander-Barth](https://discourse.julialang.org/u/Alexander-Barth)\
**Post date:** [January 17, 2026, 10:06am UTC](https://discourse.julialang.org/t/julia-for-microcontrollers-like-micropython/15393/26 "2026-01-17T10:06:40Z")

</div>

I was not able to get xtensa to work but newer ESP32 devices use the RISC-V which has good LLVM support. Here are some experiments I did:

> [@Compiling Julia code for a RISC-V ESP32 microcontroller](https://discourse.julialang.org/t/compiling-julia-code-for-a-risc-v-esp32-microcontroller/135108):
>
> I wanted to share some experiments I did to run Julia on a ESP32 C3 using GPUCompiler and LLVM: This microcontrollers use the open RISC-V instruction set. The ESP32 family of microcontrollers are quite popular because they quite inexpensive and jet rather powerful (dual core processor, WiFi and Bluetooth). Once you have a Julia build with RISC-V enabled as LLVM target, GPUCompiler.jl can generate an object file with the compiled Julia code. I wrapped some functions from the Arduino API to ma…

[Previous page](https://discourse.julialang.org/t/julia-for-microcontrollers-like-micropython/15393.md?page=1)
