Instructions for OCaml on ESP32

Hi,

I recently got an ESP32 board and I’d like to put OCaml on it. It has 16MB of flash so it should be plentiful. I know there’s a GitHub - well-typed-lightbulbs/ocaml-esp32 at 4.11.1-esp32 but there aren’t many instructions and the ones there seem to favor the old 4.06 compiler while there’s a 4.11 branch. Is it possible to use the 4.11 support along with the opam stuff? If so, does someone has a few commands example for the ocaml-specific parts?

Thanks.

Hi adrien,

I’m the one behind the ocaml ESP32 work. The 4.06 compiler branch is the original one that I implemented during my internship at OCaml Labs. Most of the documentation you can find online thus refers to that branch, the most up to date article being this one. However as it’s been a while it might not work out of the box, and is not very extensible (only a small subset of the opam universe is available as esp32-specific packages). I just found some errors, for example you need to use the 0.2 tag of opam-cross-esp32 instead of the master branch and the command to install the correct version mirage is opam install mirage.3.0.8b+esp32. I’ll update the article but I don’t garantee that it’ll work even with the corrections. If you really want to try ocaml on esp32 right now, this is the way to go.

In the meantime I’ve been working on porting the ESP32 backend to ocaml 4.11.1, as you have noticed. This is a work in progress, and a lot of changes are also happening in Mirage which will make ESP32 support much easier and more integrated.
After the release of Mirage 4, I plan to update the documentation on how to put ocaml on esp32 boards with modern tools and the 4.11 compiler. I don’t have very precise deadlines but in a few months the work should be fairly documented and ready to experiment with ! :slight_smile:

5 Likes

Thanks for your answer!

I’ve started again using 4.06.0 (*) and opam-cross-esp32#v0.2

  • opam switch create 4.06.0+32bit 4.06.0+32bit
  • eval $(opam env)
  • opam repo add opam-cross-esp32 'https://github.com/well-typed-lightbulbs/opam-cross-esp32.git#v0.2'

Then I try opam install mirage and it doesn’t try to pull any esp32-specific package. I tried opam install mirage.3.0.8b+esp32 but again, it doesn’t try to pull any (other) esp32-specific package. For instance, opam selects ipaddr-5.0.1 while your repo shows there’s only ipadrr-esp32.2.8.0. If I try to install ipaddr-esp32, it pulls many many esp32-specific packages, including gcc-toolchain-esp32 and ocaml-esp32. Do you remember why there’s only mirage and not mirage-esp32 in the opam repo?

My initial issue was that I was not able to run mirage config -t esp32 because -t did not exist in whatever was installed then.

(*) well, first using 4.06.1 but cross compilers need a native compiler of the exact same version so I had to start again; I think I’m the one who made it that way but I had completely forgotten about that. :smiley: