22

I would like to build a gateway device which will use the ESP32. This should connect to the ModBus TCP port of a Sensor. For this purpose, I would like to use the Modbus Rust implementation, which already exists. But there is very little information on how I could get Rust code running on the ESP32.

Can anyone shed some light on this topic?

anonymous2
  • 4,902
  • 3
  • 22
  • 49
joesan
  • 323
  • 1
  • 3
  • 7

3 Answers3

15

Xtensa have just released an official ESP32/Espressif LLVM backend and clang front end. See their announcement here: https://esp32.com/viewtopic.php?p=38466 Repos: https://github.com/espressif/llvm-xtensa & https://github.com/espressif/clang-xtensa As rust is based on LLVM, this new ESP32 LLVM backend should help make Rust support for the ESP32 more likely. The announcement even hints at this future Rust support.

NickBroon
  • 251
  • 2
  • 3
13

Rust uses the LLVM toolchain, which is a a set of programs used to compile LLVM's intermediate representation (IR) into platform-specific code. The process works a little like this:

Rust Code -> Rust Compiler -> LLVM IR -> Back-end -> Platform-specific code
             (Front-end)

Currently, there is no backend for the Xtensa architecture used by the ESP32. This, unfortunately, means that you cannot compile Rust code for the ESP32. You did say install in your question, but I assume you didn't mean that — rather, you want to run Rust code on the ESP32, not install the Rust compiler there.

If you're really desperate to use Rust, you could, in theory, use the LLVM C Backend, which converts LLVM IR -> C, then use the toolchain provided by Espressif to compile to ESP32 machine code. However, this will be difficult, and might not even work at all. You will find it a lot easier to bite the bullet and use C in this case, which is a shame, because Rust is a great language, but its embedded support is not as good as C's at the moment.

Aurora0001
  • 18,520
  • 13
  • 55
  • 169
8

Like Aurora0001 said, you can't run Rust on an ESP32 currently (or the older ESP8266).

There's a very similar chip, the RTL8710, that is recommended for use in situations where you'd use an ESP32, but want to use Rust.

Here is a website where someone walks through their setup.