MCPcopy Index your code
hub / github.com/espressif/rust-esp32-example

github.com/espressif/rust-esp32-example @main

Chat with this repo
repository ↗ · DeepWiki ↗ · + Follow
8 symbols 14 edges 6 files 0 documented · 0%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Deprecation warning

The following example is suitable only for cases where the majority of logic is based on ESP-IDF. The example here uses so-called idf first approach.

We recommend cargo first approach described at https://github.com/esp-rs . The approach is simpler and available templates support Development Containers, GitPod, and CodeSpaces.

Rust ESP32 Example

An example project demonstrating integration with Rust for the ESP32-S2 and ESP32-C3 microcontrollers.

This example starts a FreeRTOS task to call a function in Rust and display the results in C.

Setup

First, install the ESP-IDF SDK as shown in the Get Started guides. For best support of the ESP32-C3, install the SDK from the master branch.

ESP32 and ESP32-S series

Installation instruction for Xtensa architecture is in project esp-rs/rust-build.

Podman/Docker image

Alternatively you might build the project in the container where image already contains pre-installed Rust and ESP-IDF.

Podman example with mapping multiple /dev/ttyUSB from host computer to the container:

podman run --device /dev/ttyUSB0 --device /dev/ttyUSB1 -it espressif/idf-rust-examples

Docker (does not support flashing from container):

docker run -it espressif/idf-rust-examples

Then follow instructions displayed on the screen.

ESP32-C3

Install the RISCV target for Rust:

rustup target add riscv32i-unknown-none-elf

Configure

First ensure that the environment variables for the ESP32 SDK are properly set up. If you have followed the instructions in the Getting Started guide, activate the environment with the get_idf alias:

get_idf

Next, configure the project for the desired MCU.

For the ESP32:

idf.py set-target esp32
idf.py menuconfig

For the ESP32-S2:

idf.py set-target esp32s2
idf.py menuconfig

For the ESP32-C3:

idf.py set-target esp32c3
idf.py menuconfig

Build

Build the project by running:

idf.py build

This also runs Cargo internally, building a static library out of Rust code.

Flash

Flash the compiled binary by running:

idf.py -p /dev/cu.SLAB_USBtoUART flash

Monitor

Connect to the UART over USB port to monitor the application console:

idf.py -p /dev/cu.SLABtoUART monitor

To exit the monitor, press Ctrl-].

Debugging on ESP32-WROVER-KIT

openocd -f board/esp32-wrover-kit-3.3v.cfg

Table of footprints

Print the memory statistics of the project:

idf.py size-files

or in json format:

$IDF_PATH/tools/idf_size.py --files --json build/esp32-hello-rust.map

Core symbols most depended-on inside this repo

validate_param_in_c
called by 4
components/clib/clib.c
run_cbindgen
called by 1
components/rustlib/build.rs
run_bindgen
called by 1
components/rustlib/build.rs
add_in_rust
called by 1
components/rustlib/src/lib.rs
add_in_rust_inline_asm
called by 1
components/rustlib/src/lib.rs
main
called by 0
components/rustlib/build.rs
panic
called by 0
components/rustlib/src/lib.rs
app_main
called by 0
main/main.c

Shape

Function 8

Languages

Rust75%
C25%

Modules by API surface

components/rustlib/src/lib.rs3 symbols
components/rustlib/build.rs3 symbols
main/main.c1 symbols
components/clib/clib.c1 symbols

For agents

$ claude mcp add rust-esp32-example \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact