• Stars
    star
    414
  • Rank 104,550 (Top 3 %)
  • Language CMake
  • Created about 3 years ago
  • Updated about 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A "Hello, world!" template of a Rust binary crate for the ESP-IDF framework.

Rust on ESP-IDF "Hello, World" template

Cargo CI CMake CI Documentation Matrix Wokwi

A template for a "Hello, world!" Rust binary crate for the ESP-IDF framework. Based on cargo-generate.

This is the crate you get when running cargo new, but augmented with extra configuration so that it does build for the ESP32[XX] with ESP-IDF and (by default) with STD support.

Or if you rather

For more check out the links in the additional information seciton

Generate the project

Please make sure you have installed all prerequisites first!

cargo generate esp-rs/esp-idf-template cargo

The command will display a few prompts:

  • Project Name: Name of the crate.
  • Which MCU to target?: SoC model, e.g. esp32, esp32s2, esp32c3 etc.
  • Configure advanced template options?: If false, skips the rest of the prompts and uses their default value. If true, you will be prompted with:

Build

cd <your-project-name>
cargo build
  • Replace <your-project-name> with the name of the generated project

Flash

In the root of the generated project:

espflash /dev/ttyUSB0 target/[xtensa-esp32-espidf|xtensa-esp32s2-espidf|xtensa-esp32s3-espidf|riscv32imc-esp-espidf]/debug/<your-project-name>
  • Replace dev/ttyUSB0 above with the USB port where you've connected the board. If you do not specify any USB port, espflash will print a list of the recognized USB ports for you to select the desired port.
  • Replace <your-project-name> with the name of the generated project
  • You can include the --monitor argument to the espflash command to open a serial monitor after flashing the device.
  • For more details on espflash usage see the README

Monitor

espflash monitor /dev/ttyUSB0
  • Replace dev/ttyUSB0 above with the USB port where you've connected the board. If you do not specify any USB port, cargo-espflash/espflash will print a list of the recognized USB ports for you to select the desired port.

The monitor should output more or less the following:

Opening /dev/tty.usbserial-0001 with speed 115200
Resetting device... done
ets Jun  8 2016 00:22:57

rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0048,len:12
ho 0 tail 12 room 4
load:0x3fff0054,len:4800
load:0x40078000,len:17448
load:0x4007c428,len:4840
entry 0x4007c6a0
I (178) cpu_start: Pro cpu up.
I (178) cpu_start: Starting app cpu, entry point is 0x4008115c
I (0) cpu_start: App cpu up.
I (193) cpu_start: Pro cpu start user code
I (193) cpu_start: cpu freq: 160000000
I (193) cpu_start: Application information:
I (197) cpu_start: Project name:     esp-idf
I (202) cpu_start: App version:      f08dcd7
I (207) cpu_start: Compile time:     Oct 23 2021 14:48:03
I (213) cpu_start: ELF file SHA256:  0000000000000000...
I (219) cpu_start: ESP-IDF:          4.3.0
I (224) heap_init: Initializing. RAM available for dynamic allocation:
I (231) heap_init: At 3FFAE6E0 len 00001920 (6 KiB): DRAM
I (237) heap_init: At 3FFB3498 len 0002CB68 (178 KiB): DRAM
I (243) heap_init: At 3FFE0440 len 00003AE0 (14 KiB): D/IRAM
I (250) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
I (256) heap_init: At 4008C538 len 00013AC8 (78 KiB): IRAM
I (263) spi_flash: detected chip: generic
I (267) spi_flash: flash io: dio
I (272) cpu_start: Starting scheduler on PRO CPU.
I (0) cpu_start: Starting scheduler on APP CPU.
Hello, world!

Additional information

For more information, check out:

Prerequisites

Install Rust (with rustup)

If you don't have rustup installed yet, follow the instructions on the rustup.rs site

Install Cargo Sub-Commands

cargo install cargo-generate
cargo install ldproxy
cargo install espup
cargo install espflash
cargo install cargo-espflash # Optional

Note

If you are running macOS or Linux then libuv must also be installed for espflash and cargo-espflash; this is available via most popular package managers. If you are running Windows you can ignore this step.

# macOS
brew install libuv
# Debian/Ubuntu/etc.
apt-get install libuv-dev
# Fedora
dnf install systemd-devel

Also, the espflash and cargo-espflash commands shown below, assume that version 2.0 or greater.

Install Rust & Clang toolchains for Espressif SoCs (with espup)

espup install
# Unix
. $HOME/export-esp.sh
# Windows
%USERPROFILE%\export-esp.ps1

Warning

Make sure you source the generated export file, as shown above, in every terminal before building any application as it contains the required environment variables.

See the Installation chapter of The Rust on ESP Book for more details.

Alternative (for RISC-V Espressif SOCs only): install & use upstream nightly Rust and upstream stable Clang

While you can target the RISC-V Espressif SOCs (esp32-cXX and esp32-hXX) with the espup installer just fine, SOCs with this architecture are also supported by the nightly Rust compiler and by recent, stock Clang compilers (as in Clang 11+):

  • Install a recent Clang. See Clang Getting Started page as it contains useful guidelines on instalaltion. Recent Linux distros come with suitable Clang already.
  • Install the nightly Rust toolchain with the rust-src component included:
    rustup toolchain install nightly --component rust-src
  • Run any Cargo command with the nightly toolchain override, i.e. cargo +nightly ....

Install Python3

You need a Python 3.7 or later installed on your machine.

  • Linux, Mac OS X: if not preinstalled already, just install it with your package manager
  • Windows: install it e.g. from the official Python site.

More Repositories

1

awesome-esp-rust

Curated list of resources for ESP32 development in the Rust programming language
825
star
2

esp-hal

no_std Hardware Abstraction Layers for ESP32 microcontrollers
Rust
712
star
3

std-training

Embedded Rust on Espressif training material.
Rust
596
star
4

esp-rust-board

Open Hardware with ESP32-C3 compatible with Feather specification designed in KiCad
487
star
5

espflash

Serial flasher utility for Espressif SoCs and modules based on esptool.py
Rust
476
star
6

esp-idf-hal

embedded-hal implementation for Rust on ESP32 and ESP-IDF
Rust
449
star
7

esp-wifi-sys

Wi-Fi and BT drivers packaged for integration into bare-metal esp-wifi.
Rust
396
star
8

esp-idf-svc

Type-Safe Rust Wrappers for various ESP-IDF services (WiFi, Network, Httpd, Logging, etc.)
Rust
311
star
9

esp-idf-sys

Bindings for ESP-IDF (Espressif's IoT Development Framework)
Rust
270
star
10

rust-build

Installation tools and workflows for deploying/building Rust fork esp-rs/rust with Xtensa and RISC-V support
PowerShell
249
star
11

espup

Tool for installing and maintaining Espressif Rust ecosystem.
Rust
220
star
12

esp32-hal

A hardware abstraction layer for the esp32 written in Rust.
Rust
193
star
13

book

The Rust on ESP Book
JavaScript
171
star
14

esp8266-hal

A experimental hardware abstraction layer for the esp8266 written in Rust.
Rust
157
star
15

esp-template

A minimal esp-hal application template for use with cargo-generate
Dockerfile
141
star
16

embuild

Build support for embedded Rust: Cargo integration with other embedded build ecosystems & tools, like PlatformIO, CMake and kconfig.
Rust
137
star
17

rfc2217-rs

IETF RFC2217 implementation in Rust
Rust
133
star
18

esp32

Peripheral access crate for the ESP32
Rust
126
star
19

embedded-svc

Rust APIs and abstractions for various embedded services (WiFi, Network, Httpd, Logging, etc.)
Rust
122
star
20

esp-pacs

Peripheral Access Crates for Espressif SoCs and modules
Rust
105
star
21

esp32-wifi

Rust ESP32 WiFi Library
Rust
79
star
22

no_std-training

Getting-started guide on using the Rust with Espressif SoCs using no_std.
Rust
62
star
23

espmonitor

Cargo tool for monitoring ESP32/ESP8266 execution
Rust
48
star
24

esp-openthread

Rust
45
star
25

xtensa-lx-rt

Minimal runtime/startup for Xtensa LX processors
Rust
44
star
26

esp-ieee802154

Low-level IEEE802.15.4 driver for the ESP32-C6 and ESP32-H2
Rust
36
star
27

esp-web-flash-server

Starts a local server serving a web page to flash a given ELF file
Rust
34
star
28

esp-backtrace

backtrace for ESP32 bare-metal
Rust
29
star
29

esp32c3

Peripheral access crate for the ESP32-C3
Rust
28
star
30

xtensa-lx

Low-level access to Xtensa LX processors
Rust
26
star
31

esp-storage

implementation of embedded-storage traits to access unencrypted ESP32 flash
Rust
25
star
32

esp8266

Peripheral access crate for the ESP8266
Rust
22
star
33

esp-riscv-rt

Minimal runtime / startup for RISC-V CPUs from Espressif
Rust
20
star
34

esp-println

Provides print! and println! implementations various Espressif devices
Rust
20
star
35

esp-mbedtls

mbedtls for ESP32 bare-metal
Rust
19
star
36

esp-flasher-stub

Rust implementation of flasher stub located in esptool
Rust
18
star
37

esp-alloc

A simple `no_std` heap allocator for RISC-V and Xtensa processors from Espressif
Rust
15
star
38

esp-flash-loader

A probe-rs flash loader for Espressif chips.
RPC
15
star
39

xtensa-toolchain

A GitHub Action to install the Rust compiler fork targeting Xtensa devices
11
star
40

docker-rust-esp

Rust build environment for the ESP32 and ESP8266
Dockerfile
10
star
41

esp-idf-part

A library for parsing and generating ESP-IDF partition tables
Rust
8
star
42

riscv-atomic-emulation-trap

An atomic emulation trap handler for non atomic RISCV targets
Rust
8
star
43

esp-serial-dbg

esp-serial-dbg - debugging of esp-hal based applications via serial
Rust
7
star
44

esp-rust-board-bsp

A board support package for the ESP Rust Board
Rust
7
star
45

esp-hal-community

Rust
7
star
46

esp-generate

Template generation tool to create no_std applications targeting Espressif's chips.
Rust
6
star
47

xtensa-atomic-emulation-trap

An atomic emulation trap handler for non atomic Xtensa targets
Rust
4
star
48

docs

3
star
49

rfcs

2
star
50

esp32s3

Peripheral access crate for the ESP32-S3
Rust
1
star
51

esp32s2

Rust
1
star
52

repo-activity-digest

Python
1
star