1

Introduction

I created a small project that uploads C++ code to an Attiny85, for this I used arduino.

Question

But I would have liked to know if it was possible to download and run rust code in Attiny85 or other Attiny. If we can, how do we do it?

Details

I found this GitHub repo to do this, but it is not explicit on how can export the rust code to Attiny. The GitHub repo in question: https://github.com/q231950/avr-attiny85-rust?ref=https://githubhelp.com

ThrowsError
  • 1,169
  • 1
  • 11
  • 43
  • 2
    You used your favorite web search engine with the keywords "cross compile rust for avr", didn't you? What have you found, and why does it not answer your questions? – the busybee Feb 13 '22 at 15:12
  • 1
    Thank you for your help, I did not find an article talking about the Attiny85 or another Attiny. The only lead I found is this GitHub repo: https://github.com/q231950/avr-attiny85-rust?ref=https://githubhelp.com – ThrowsError Feb 13 '22 at 19:49
  • You do not "export" Rust code. It is compiled, equally to C++, into a final "_hex_" file containing the machine code. And then you use Avrdude to flash this into the microcontroller. You might need to learn a lot about development with command line tools. Unfortunately this is too broad an issue to post here. – the busybee Feb 13 '22 at 20:39
  • It does not take much Google-fu to find exactly what you are looking for, but understanding the concepts of compiled languages and cross-compilation might result in a more fruitful search. That is to say; to find what you are looking for, you have to know what you are looking for _is_. – Clifford Feb 13 '22 at 22:41

1 Answers1

4

C++ is cross-compiled to AVR machine code on your development host. What you are loading is not C++ code; that is the source code used to generate the machine executable binary code, which is what you load..

You can develop for AVR using any language for which a cross compiler exists. Rust is certainly such a language. This article discusses using Rust on Arduino Uno hardware.

Whether ATTiny85 with only 8Kb of Flash and 512 bytes of SRAM will support a Rust runtime environment and any useful code I cannot tell; I am not familiar with Rust's runtime requirements, but it does not seem like an efficient use of limited resources to me, and I would treat it as an academic challenge rather than a practical development approach. I would expect Rust to have a considerably larger run-time footprint than C or even C++.

Clifford
  • 88,407
  • 13
  • 85
  • 165
  • 3
    Rust's "runtime" can be negligible, for simple applications. There's no particular reason it couldn't run on an 8K device. – Peter Hansen Apr 07 '22 at 18:17