Rust on ESP32 STD "Hello, World" app. A "Hello, world!" STD binary crate for the ESP32[XX] and ESP-IDF.

Overview

Rust on ESP32 STD "Hello, World" app

A "Hello, world!" STD binary crate for the ESP32[XX] and ESP-IDF.

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

Build

  • Install the Rust Espressif compiler fork and the Espressif LLVM Clang fork using either pre-built binaries or follow the directions to build your own;
    • This is necessary, because support for the Xtensa architecture (ESP32 / ESP32-S2 / ESP32-S3) is not upstreamed in LLVM yet
  • Switch to the esp toolchain from the pre-built binaries: rustup default esp
    • NOTE: For ESP32-C3 - which runs a RiscV32 chip - you can just use the stock nightly Rust compiler, and a recent, stock Clang (as in Clang 11+)
    • (You can do this by issuing rustup install nightly and then rustup default nightly instead of installing/building the Rust & Clang ESP forks and switching to their esp toolchain as advised above)
  • If using the custom Espressif Clang, make sure that you DON'T have a system Clang installed as well, because even if you have the Espressif one first on your $PATH, Bindgen will still pick the system one
    • A workaround that does not require uninstalling the system Clang is to do export LIBCLANG_PATH=<path to the Espressif Clang lib directory> prior to continuing the build process
  • cargo install ldproxy
  • Clone this repo: git clone https://github.com/ivmarkov/rust-esp32-std-mini
  • Enter it: cd rust-esp32-std-mini
  • To configure the demo for your particular board, please uncomment the relevant Rust target for your board and comment the others. Alternatively, just append the --target <target> flag to all cargo build lines below.
  • Build: cargo build or cargo build --release

Flash

  • cargo install espflash
  • espflash /dev/ttyUSB0 target/[xtensa-esp32-espidf|xtensa-esp32s2-espidf|xtensa-esp32s3-espidf|riscv32imc-esp-espidf]/debug/rust-esp32-std-mini
  • Replace dev/ttyUSB0 above with the USB port where you've connected the board

Monitor

  • cargo install espmonitor

  • espmonitor /dev/ttyUSB0

  • Replace dev/ttyUSB0 above with the USB port where you've connected the board

  • 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!
You might also like...
Convert character to binary using Rust.
Convert character to binary using Rust.

Character-to-Binary-Rust This is a simple operation that is used to convert character to binary using Rust. Installation and Requirements First instal

CBOR: Concise Binary Object Representation

CBOR 0x(4+4)9 0x49 β€œThe Concise Binary Object Representation (CBOR) is a data format whose design goals include the possibility of extremely small cod

Serialize & deserialize device tree binary using serde

serde_device_tree Use serde framework to deserialize Device Tree Blob binary files; no_std compatible. Use this library Run example: cargo run --examp

Convert PNG image files to binary for use with AgonLight (TM)

image2agon Converts PNG files to binary data for AgonLight (TM) usage. This document is for version V1.0 of the program. V1.0 - initial upload NOTE: T

Multi-platform desktop app to download and run Large Language Models(LLM) locally in your computer.
Multi-platform desktop app to download and run Large Language Models(LLM) locally in your computer.

Multi-platform desktop app to download and run Large Language Models(LLM) locally in your computer πŸ”— Download | Give it a Star ⭐ | Share it on Twitte

Rust app that creates cli quiz for you!

quizer rust app that creates cli quiz for you! Installation Download binary release or build from source using cargo Make binary executable chmod +x /

VoceChat is a superlight rust written social server. Easy integration to your site/app.

Re-decentralized the Internet through personal cloud computing. VoceChat is the lightest chat server prioritizes private hosting! Easy integratation t

Reverse-engineered Rust client for Instagram's Threads app.

Instagram Threads API Unofficial, Reverse-Engineered Rust client for Instagram's Threads. Usage use threads_api::Threads; let client = Threads::new()

Using iced-rs library for YT monitoring app
Using iced-rs library for YT monitoring app

YouTube Monitoring App (using Rust) Description This app is built on the top of iced library. If you're curious what this is about, check out the YT m

Comments
  • sdkconfig.defaults ignored

    sdkconfig.defaults ignored

    Hi. I'm having issues changing the SDK configuration. I'd like to disable logging in the bootloader and HAL as well as a few other things, which can be done by adding the following lines to sdkconfig.defaults:

    CONFIG_BOOTLOADER_LOG_LEVEL=0
    CONFIG_BOOTLOADER_WDT_ENABLE=n
    CONFIG_HAL_LOG_LEVEL=0
    CONFIG_LOG_DEFAULT_LEVEL=0
    CONFIG_ESP_SYSTEM_PANIC=ESP_SYSTEM_PANIC_PRINT_HALT
    

    After adding these lines to sdkconfig.defaults and running cargo build (with or without --release) I noticed that none of these changes were applied. My ESP32 was still displaying boot logs and calling panic!() would make the chip reboot instead of halting as specified above.

    I tried:

    • Adding ESP_IDF_SDKCONFIG_DEFAULTS = "sdkconfig.defaults" to the [env] section in .cargo/config.toml
    • Adding ESP_IDF_SDKCONFIG = "sdkconfig.defaults" to the [env] section in .cargo/config.toml
    • cargo clean; cargo build

    None of these helped. Is there extra configuration needed to make this work?

    ESP-IDF version: release/v4.4 Board: Generic ESP32 dev board Project generated using: cargo generate https://github.com/esp-rs/esp-idf-template cargo STD support: yes, Dev container support: no

    opened by br0kenpixel 0
  • Rust-analyzer errors when opening a project generated with the cargo template

    Rust-analyzer errors when opening a project generated with the cargo template

    Rust-analyzer generates this error when opening a project:

    LSP[rust_analyzer] rust-analyzer failed to load workspace: Failed to read Cargo metadata from Cargo.toml file /home/jtcf/rustworks/esp-test/Cargo.toml, Some(Version { major: 1, minor: 66, patch: 0 }): Fail
    ed to run `"cargo" "metadata" "--format-version" "1" "--manifest-path" "/home/jtcf/rustworks/esp-test/Cargo.toml" "--filter-platform" "xtensa-esp32-espidf"`: `cargo metadata` exited with an error: error: f
    ailed to run `rustc` to learn about target-specific information                                                                                                                                              
    Caused by:                                                                                                                                                                                                   
      process didn't exit successfully: `rustc - --crate-name ___ --print=file-names --cfg espidf_time64 --target xtensa-esp32-espidf --crate-type bin --crate-type rlib --crate-type dylib --crate-type cdylib -
    -crate-type staticlib --crate-type proc-macro --print=sysroot --print=cfg` (exit status: 1)                                                                                                                  
      --- stderr                                                                                                                                                                                                 
      error: Error loading target specification: Could not find specification for target "xtensa-esp32-espidf". Run `rustc --print target-list` for a list of built-in targets
    

    This is in neovim

    opened by JohnTheCoolingFan 0
  • cmake template: remove panic_immediate_abort for new idf versions

    cmake template: remove panic_immediate_abort for new idf versions

    build-std-features=panic_immediate_abort causes panics to not print their error messages which is a bad developer experience. Similar to the Cargo template, do not set this flag for newer espidf versions.

    opened by benhansen-io 3
  • Compiling hello world - esp-idf-sys - stderr Build configuration: BuildConfig

    Compiling hello world - esp-idf-sys - stderr Build configuration: BuildConfig

    Hey,

    I am quite excited to get this to work. I have had quite a bit of trouble.

    What I am trying to do is to get something compiled and onto my ESP32.

    Might be more related to esp-idf-sys.

    Here is one of the things that I have tried to do.

    ➜ Git cargo generate --vcs none --git https://github.com/esp-rs/esp-idf-template cargo 🀷 Project Name : project πŸ”§ Destination: /home/richard/Git/project ... πŸ”§ Generating template ... ? 🀷 Configure project to use Dev Containers (VS Code, GitHub Codespaces and Gitpod)? (beware: Dev Containers not avβœ” 🀷 Configure project to use Dev Containers (VS Code, GitHub Codespaces and Gitpod)? (beware: Dev Containers not available for esp-idf v4.3.2) Β· true βœ” 🀷 MCU Β· esp32 βœ” 🀷 ESP-IDF native build version (v4.3.2 = previous stable, v4.4 = stable, mainline = UNSTABLE) Β· v4.4 βœ” 🀷 STD support Β· true [ 1/24] Done: .cargo/config.toml [ 2/24] Done: .cargo [ 3/24] Done: .devcontainer/Dockerfile [ 4/24] Done: .devcontainer/devcontainer.json [ 5/24] Done: .devcontainer [ 6/24] Done: .dockerignore [ 7/24] Done: .gitignore [ 8/24] Done: .gitpod.Dockerfile [ 9/24] Done: .gitpod.yml [10/24] Done: .vscode/launch.json [11/24] Done: .vscode/tasks.json [12/24] Done: .vscode [13/24] Done: Cargo.toml [14/24] Done: build.rs [15/24] Done: docs/README.md [16/24] Done: docs [17/24] Done: rust-toolchain.toml [18/24] Done: scripts/build.sh [19/24] Done: scripts/flash.sh [20/24] Done: scripts/run-wokwi.sh [21/24] Done: scripts [22/24] Done: sdkconfig.defaults [23/24] Done: src/main.rs [24/24] Done: src πŸ”§ Moving generated files into: /home/richard/Git/project... ✨ Done! New project created /home/richard/Git/project ➜ Git cd /home/richard/Git/project

    ➜ esp-idf git:(release/v4.4) βœ— git checkout release/v4.4 M components/bt/host/nimble/nimble M components/esp_phy/lib M components/esp_wifi/lib M components/esptool_py/esptool M components/ieee802154/lib M components/lwip/lwip M components/mbedtls/mbedtls M components/mqtt/esp-mqtt M components/openthread/lib M components/openthread/openthread M components/tinyusb/tinyusb M examples/peripherals/secure_element/atecc608_ecdsa/components/esp-cryptoauthlib Already on 'release/v4.4' Your branch is up to date with 'origin/release/v4.4'. ➜ esp-idf git:(release/v4.4) βœ— pwd /home/richard/esp/esp-idf ➜ esp-idf git:(release/v4.4) βœ— git submodule update --init --recursive Submodule path 'components/bt/host/nimble/nimble': checked out 'dac3a2a0f54589b10a4cff2a99526804747089df' Submodule path 'components/esp_phy/lib': checked out 'ff0d771b8e33e320e11634567ee53b9cd78e6be1' Submodule path 'components/esp_wifi/lib': checked out '85d6197b8f4271f51a409c0cd7e293ae2694145c' Submodule path 'components/ieee802154/lib': checked out 'f7b5e8059a3bb6f321e79ac3bf2aa4d2a9b93326' Submodule path 'components/lwip/lwip': checked out '76303df2386902e0d7873be4217f1d9d1b50f982' Submodule path 'components/mbedtls/mbedtls': checked out '89da85968417ce4a163b7275cb22f159995c271d' Submodule path 'components/mqtt/esp-mqtt': checked out '27eb4726067465c5c67d4ecdca5ddccd26f02580' Submodule path 'components/openthread/lib': checked out '9a8d34d8f698cad2c9468468b473e26a3dda51b9' Submodule path 'components/openthread/openthread': checked out 'c36c0e77a2465355bcf13bd7dc718d8c9aa6ff64' Submodule path 'components/tinyusb/tinyusb': checked out 'c4badd394eda18199c0196ed0be1e2d635f0a5f6' Submodule path 'examples/peripherals/secure_element/atecc608_ecdsa/components/esp-cryptoauthlib': checked out '36d0642e66ff5b1c7a291873f24c498ca6ffedef'

    ➜ project ./scripts/build.sh
    Compiling esp-idf-sys v0.31.7 The following warnings were emitted during compilation:

    warning: Ignoring configuration setting ESP_IDF_VERSION (Tag v5.0): custom esp-idf repository detected via $IDF_PATH

    error: failed to run custom build command for esp-idf-sys v0.31.7

    Caused by: process didn't exit successfully: /home/richard/Git/project/target/release/build/esp-idf-sys-590e438e9fb453c2/build-script-build (exit status: 101) --- stdout cargo:rerun-if-env-changed=ESP_IDF_TOOLS_INSTALL_DIR cargo:rerun-if-env-changed=ESP_IDF_SDKCONFIG cargo:rerun-if-env-changed=ESP_IDF_SDKCONFIG_DEFAULTS cargo:rerun-if-env-changed=MCU cargo:rerun-if-env-changed=ESP_IDF_SYS_ROOT_CRATE cargo:rerun-if-env-changed=ESP_IDF_VERSION cargo:rerun-if-env-changed=ESP_IDF_REPOSITORY cargo:rerun-if-env-changed=ESP_IDF_CMAKE_GENERATOR cargo:rerun-if-env-changed=IDF_PATH cargo:rerun-if-env-changed=ESP_IDF_COMPONENTS The following Python requirements are not satisfied: pyparsing>=2.0.3,<2.4.0 gdbgui==0.13.2.0 python-socketio<5 jinja2<3.1 # See https://github.com/espressif/esp-idf/issues/8760 itsdangerous<2.1 kconfiglib==13.7.1 construct==2.10.54 To install the missing packages, please run "/home/richard/esp/esp-idf/install.sh" Diagnostic information: IDF_PYTHON_ENV_PATH: /home/richard/.espressif/python_env/idf5.0_py3.8_env Python interpreter used: /home/richard/.espressif/python_env/idf5.0_py3.8_env/bin/python cargo:warning=Ignoring configuration setting ESP_IDF_VERSION (Tag v5.0): custom esp-idf repository detected via $IDF_PATH PATH=/home/richard/Git/project/.embuild/espressif/tools/xtensa-esp32-elf/esp-2021r2-patch3-8.4.0/xtensa-esp32-elf/bin:/home/richard/Git/project/.embuild/espressif/tools/cmake/3.23.1/bin:/home/richard/Git/project/.embuild/espressif/tools/ninja/1.10.2/:$PATH Current system platform: linux-amd64 Skipping [email protected] (already installed) Skipping [email protected] (already installed) Skipping [email protected] (already installed) Skipping [email protected] (already installed) PATH=/home/richard/Git/project/.embuild/espressif/tools/xtensa-esp32-elf/esp-2021r2-patch3-8.4.0/xtensa-esp32-elf/bin:/home/richard/Git/project/.embuild/espressif/tools/cmake/3.23.1/bin:/home/richard/Git/project/.embuild/espressif/tools/ninja/1.10.2/:$PATH cargo:rerun-if-changed=/home/richard/Git/project/sdkconfig.defaults CMAKE_PREFIX_PATH_xtensa-esp32-espidf = None CMAKE_PREFIX_PATH_xtensa_esp32_espidf = None TARGET_CMAKE_PREFIX_PATH = None CMAKE_PREFIX_PATH = None CMAKE_xtensa-esp32-espidf = None CMAKE_xtensa_esp32_espidf = None TARGET_CMAKE = None CMAKE = None running: "cmake" "/home/richard/Git/project/target/xtensa-esp32-espidf/release/build/esp-idf-sys-beed0b193df20ab5/out" "-G" "Ninja" "-DCMAKE_TOOLCHAIN_FILE=/home/richard/esp/esp-idf/tools/cmake/toolchain-esp32.cmake" "-DCMAKE_BUILD_TYPE=" "-DPYTHON=/home/richard/.espressif/python_env/idf5.0_py3.8_env/bin/python" "-DCMAKE_INSTALL_PREFIX=/home/richard/Git/project/target/xtensa-esp32-espidf/release/build/esp-idf-sys-beed0b193df20ab5/out" "-DCMAKE_C_FLAGS= -mlongcalls -Wno-frame-address -ffunction-sections -fdata-sections" "-DCMAKE_CXX_FLAGS= -mlongcalls -Wno-frame-address -ffunction-sections -fdata-sections" "-DCMAKE_ASM_FLAGS= -mlongcalls -ffunction-sections -fdata-sections" -- Checking Python dependencies... The following Python requirements are not satisfied: pyparsing>=2.0.3,<2.4.0 gdbgui==0.13.2.0 python-socketio<5 jinja2<3.1 # See https://github.com/espressif/esp-idf/issues/8760 itsdangerous<2.1 kconfiglib==13.7.1 construct==2.10.54 To install the missing packages, please run "/home/richard/esp/esp-idf/install.sh" Diagnostic information: IDF_PYTHON_ENV_PATH: /home/richard/.espressif/python_env/idf5.0_py3.8_env Python interpreter used: /home/richard/.espressif/python_env/idf5.0_py3.8_env/bin/python -- Configuring incomplete, errors occurred! See also "/home/richard/Git/project/target/xtensa-esp32-espidf/release/build/esp-idf-sys-beed0b193df20ab5/out/build/CMakeFiles/CMakeOutput.log".

    --- stderr Build configuration: BuildConfig { esp_idf_tools_install_dir: None, esp_idf_sdkconfig: None, esp_idf_sdkconfig_defaults: None, mcu: None, native: NativeConfig { esp_idf_version: Some( Tag( "v5.0", ), ), esp_idf_repository: None, esp_idf_cmake_generator: None, idf_path: Some( "/home/richard/esp/esp-idf", ), extra_components: [], esp_idf_components: None, }, esp_idf_sys_root_crate: None, } Using custom user-supplied esp-idf repository at '/home/richard/esp/esp-idf' (detected from env variable IDF_PATH) Using esp-idf v4.4.1 at '/home/richard/esp/esp-idf' CMake Error at /home/richard/esp/esp-idf/tools/cmake/build.cmake:287 (message): Some Python dependencies must be installed. Check above message for details. Call Stack (most recent call first): /home/richard/esp/esp-idf/tools/cmake/build.cmake:416 (__build_check_python) CMakeLists.txt:14 (idf_build_process)

    thread 'main' panicked at ' command did not execute successfully, got: exit status: 1

    build script failed, must exit now', /home/richard/.cargo/registry/src/github.com-1ecc6299db9ec823/cmake-0.1.48/src/lib.rs:975:5 stack backtrace: 0: 0x5592d7191ccc - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h1791ff2e87a4a949 1: 0x5592d71b059e - core::fmt::write::hd3936cb33cf524d4 2: 0x5592d716ddd1 - std::io::Write::write_fmt::hdd80ac53afad4740 3: 0x5592d7173375 - std::panicking::default_hook::{{closure}}::ha1fd9d555c583f5d 4: 0x5592d7172ffa - std::panicking::default_hook::hc37a1a17cf5ce086 5: 0x5592d717387c - std::panicking::rust_panic_with_hook::h818296db12e1c172 6: 0x5592d7192bb7 - std::panicking::begin_panic_handler::{{closure}}::hcb2048160d2bd008 7: 0x5592d7191f64 - std::sys_common::backtrace::__rust_end_short_backtrace::h8106bfaf0dca55fa 8: 0x5592d7173542 - rust_begin_unwind 9: 0x5592d698fbe3 - core::panicking::panic_fmt::ha8187868327e1820 10: 0x5592d6c1e9fd - cmake::fail::hf8ea13342af4ecc2 11: 0x5592d6c1e43e - cmake::run::hdc82ba4860964bbd 12: 0x5592d6c1b01c - cmake::Config::build::h309f8b6a3bf11c84 13: 0x5592d69ec84d - build_script_build::native::cargo_driver::build::h0928d80ad948051d 14: 0x5592d69e0dfc - build_script_build::native::build::h9ed16d7a30efc811 15: 0x5592d69b7492 - build_script_build::main::h662f52b46fdc2986 16: 0x5592d6a04d06 - core::ops::function::FnOnce::call_once::h8ab18b3a7e586893 17: 0x5592d69b1e59 - std::sys_common::backtrace::__rust_begin_short_backtrace::h51be1fe5382073af 18: 0x5592d69e326c - std::rt::lang_start::{{closure}}::hb40aa8284739eabc 19: 0x5592d716d751 - std::rt::lang_start_internal::h4f59c50d5a45d217 20: 0x5592d69e3251 - std::rt::lang_start::h35ae57f21736ef18 21: 0x5592d69ba423 - main 22: 0x7f4495708083 - __libc_start_main at /build/glibc-SzIz7B/glibc-2.31/csu/../csu/libc-start.c:308:16 23: 0x5592d698fe8e - _start 24: 0x0 -

    opened by carlin54 3
Owner
Ivan Markov
Ivan Markov
A no-std esp32 Wifi Lamp

Nostd-wifi-lamp A Wi-Fi controllable lamp written in Rust for the ESP32 using esp-hal. This was created for a blog post you can read here. Usage Sadly

null 9 Apr 30, 2023
This crate allows to generate a flat binary with the memory representation of an ELF.

flatelf Library This crate allows to generate a flat binary with the memory representation of an ELF. It also allows to generate a FLATELF with the fo

Roi Martin 3 Sep 29, 2022
A tiny Rust std-lib for Linux x86_64 and aarch64

Tiny std Like a bad, probably buggy, tiny standard library for Linux. When it's appropriate If you are actually trying to do something solid, checkout

null 4 Dec 17, 2022
Zero-copy, no-std proquint encoding and decoding

proqnt A pronounceable quintuplet, or proquint, is a pronounceable 5-letter string encoding a unique 16-bit integer. Proquints may be used to encode b

Jad Ghalayini 11 May 9, 2023
An extension to Rust std for beginner exercises

note: this is for practicing rust only, do not use this in actual production programs! really, don't. [dependencies] simple-std = "0.1.1" simple-std i

nils 2 Jan 2, 2022
A Rust no-std (de)compressor based on PAQ

MASHI まし A 100% no-std compatible Rust implementation of a PAQ style arithmetic coding, context mixing compressor. Its intended use case is compressin

null 7 Dec 14, 2022
Additional Rust collections not found in std::collections

More collections Rust crate with additional collections not found in std::collections. Multimaps Completion Name Behaves like ?? ?? ?? ⬜️ ⬜️ HashSetMu

Rinde van Lon 4 Dec 21, 2022
It's a library AND a binary, but at what cost?

aria-of-borrow It's a library AND a binary, but at what cost? This is a simple toy project that demonstrates the various failure modes of trying to ma

Aria Beingessner 5 Apr 2, 2024
Base Garry's Mod binary module (Rust)

gmod-module-base-rs A base for developing Garry's Mod binary modules in Rust. Getting Started Install Rust Download or git clone this repository Open

William 7 Jul 30, 2022
Safe Rust bindings to the DynamoRIO dynamic binary instrumentation framework.

Introduction The dynamorio-rs crate provides safe Rust bindings to the DynamoRIO dynamic binary instrumentation framework, essentially allowing you to

S.J.R. van Schaik 17 Nov 21, 2022