Rust for embedded development: Where we are and what's missing

Thanks for trying! I'd love to use LLDB.

This problem is now fixed in LLDB master. I've published a new Windows build.

3 Likes

Wow Vadim, I didn't expect this.

I installed the download and installed Python 3.5 afterwards. Sadly it did not find the MSBuild tools. No desktop icon too. Later on I'll try the configuration you gave, to see if anything works despite the error, because MSBuild definitely is present and Rust Windows programs compile and run normally. Stay tuned.

Which step produced this error?
Note that the installation package actually contains LLVM+Clang+LLDB, just because that's how LLVM project is set up, but you only care about the LLDB part. I am guessing that Clang might have been the one looking for MSBuild tools, so you can ignore that.

The error occurs in a CMD.exe window showing:

Installing MSVC integration...
Failed to find MSBuild toolsets directory.
MSVC integration install failed.
Press any key to continue. . .

This occurs while executing step "C:\Program Files\LLVM/tools/msbuild/install.bat", which seems to be the absolute last step.

How and to what do I connect (https://github.com/vadimcn/vscode-lldb/blob/master/MANUAL.md#remote-debugging)?

Absolute newbie here when it comes to GDB/LLDB/remote debugging (and I might include VSCode up to a degree).

Set up your launch configuration as if connecting to gdbserver, but give it the port that OpenOCD is listening on.
If you have more questions please ask on gitter.

1 Like

I would like to use the Blue Gecko Dev Kit for profiling energy consumption while using Rust. However, I cannot seem to find out any information on how whether Blue Gecko Dev Kit supports Rust or vice versa and whether the IDE "Simplicity" supports the Rust toolchain. Some information on this would be nice. Some information on using Rust for other embedded arm platforms would be nice. I would like to develop a rust framework for a few arm cortex boards I'm designing. However, the process that I should follow in how to integrate rust into a project like this is not clear to me.

I have gone briefly through the thread and I don't think anyone has mentioned getting information about the stack usage at compile time. I think something in the line of gcc's -fstack-usage would come handy for MCU developers.

For example (not mine): How to measure a functions stack usage in Rust? - Stack Overflow

3 Likes

Even something like -fstack-usage is only a rough guide. It won't include ISR stack usage.

Another technique I've used is to initialize from the current stack pointer to the end/beginning of the stack with some value like 0xEE and then later after a while scan from the end of the stack looking for the first non 0xEE

With the above scheme its still possible to overflow the stack and not detect anything ,expecially if a large unused buffer happens to straddle the end of the stack.

But if you don't overflow the stack then you can get a sense for your worst case stack usage for a particular run.

1 Like

Yes indeed, but this technique only works at runtime, I had the feeling the rust compiler could provide more insight into this problem at compilation time. A stack usage on a by-function basis (vs with recursive usage based on call-graph) would probably already help.

1 Like

I am in desperate need of a good tutorial on writing a linker script and registry def files that may serve as a good example/template for developing in Rust on a few other embedded architectures. Most of these tutorials won't go into detail on how to build a linker script which seems like the most important part when getting Rust working on other embedded architectures. Perhaps a few more tutorials on this might allow others to help out in getting other architectures up and running with Rust.

Could Philipp Oppermann's "Writing an OS in Rust" be of any use to you? It starts with a guided tour on how to build a bare bones OS kernel on x86, including how to set up a complete xargo + compiler + linker toolchain, and it feels like many parts of it could be adapted to other hardware architectures.

For example, the use of GNU ld means that the existing literature on linker scripts for embedded software in C can be largely reused.

2 Likes

Hackaday showed me that someone has managed to bring up basic Rust on the rtl8710 wifi module.

They used a Rust-wrapper around FreeRTOS: FreeRTOS.rs, compiled with some ARM mbed libraries.
Then they link in a rust lib.rs containing an fn main_entry()

All in all, it is far from "pure Rust", but still :smiley:

Hi chromebin,

at the moment for me the best solution regarding embedded debugging with rust is the Eclipse IDE with 2 important plugins:

  • GNU MCU Ecplise
  • RustDT

When you have the right SVD-File for your Controller you can also monitor the peripheral registers.

For this setup you will also need OpenOCD and the GNU ARM Embedded Toolchain. I think with this setup your requirements will be fulfilled up to 90%.

Maybe when more users will use this setup, we can improve and continue the work on the RustDT-Plugin

@Malex92
I'm only aware of one fairly extension tutorial out there which covers Rust development on a STM... MCU I believe. Is there a Rust blog on current available tutorials to help some of us "fairly" new Rust people out. Setting up IDEs in a Linux environment have always been this ritual decree for me. I worked with the KL25Z from freescale and just recently the Blue Gecko from Silicon labs all of which use a eclipse based IDE. Having more tutorials on setting up Rust embedded development for various architectures would really help boost its transparency to the public.

1 Like

I'd love to use rust instead of c++ for my ESP32 - but for some obscure reason, there is still no Xtensa support in llvm.
Is someone working on a llvm backend for Xtensa? Is there a way to contribute?

2 Likes

There is a project of Xtensa backend : https://github.com/afonso360/llvm-xtensa
I'm trying to get an idea of what's left to do. For the moment I can output some assembly code from a very simple sequence of LLVM-IR instructions. However, the obtained code is in 'CALL0' calling convention, so I don't know how to try it on a ESP32. The ESP-IDF use the (more efficient) 'windowed register' calling convention. Mixing the two obviously doesn't work, and I also don't know how to make a complete ESP32 image without the ESP-IDF.

3 Likes

@mgb could you push a copy of llvm-xtensa to a public repo? The original is gone.

My apologies if I'm repeating prior sentiments but the most glaring omission of Rust's embedded story isn't on the embedded side: writing an application to communicate to an embedded device over USB requires dipping into C libraries like libusb and HIDAPI. Both of these libraries were written with assumptions that require unsupported patches to work on mobile platforms (see Android where native code cannot open a USB device, but it can be handed an open file descriptor to a USB device and interact with it via normal Linux facilities). Cross-platform USB (...and BT, and BLE, etc.) is a largely unaddressed point of pain in all languages.

In my ideal world I'd be able to write HID descriptors that are shared between the embedded device and host, decoupled from the transport (USB, BLE, etc.). The transport setup would also be handled in Rust. Such a library would strongly benefit from the semi-standardized mio/tokio environment which is useful for setting up a device server on the host.

Host-side embedded communication libraries are a significant source of pain that has largely been ignored; like CLI I think this is an strong contender for Rust establishing a foothold. I also believe that the surrounding environment of async libraries and module system would be force multipliers for ease of use.

4 Likes