book
esp-idf-template
book | esp-idf-template | |
---|---|---|
7 | 14 | |
158 | 353 | |
10.1% | 8.2% | |
7.6 | 8.6 | |
7 days ago | 6 days ago | |
JavaScript | CMake | |
Apache License 2.0 | - |
Stars - the number of stars that a project has on GitHub. Growth - month over month growth in stars.
Activity is a relative number indicating how actively a project is being developed. Recent commits have higher weight than older ones.
For example, an activity of 9.0 indicates that a project is amongst the top 10% of the most actively developed projects that we are tracking.
book
- Building an occupancy sensor with a $5 ESP32 and a serverless DB
-
Safety vs. Performance. A case study of C, C++ and Rust sort implementations
It actually does. You can modify Rust to run without stdlib, reducing its size significantly. There are also tons of tricks to make this work really well so it's very close to C performance.
https://esp-rs.github.io/book/
-
ESP32 Standard Library Embedded Rust: GPIO Control
To get started with environments and hardware the Rust on ESP Book provides a great starting point. However, if using Wokwi, much of that is not needed.
-
Unlocking Possibilities: 4 Reasons Why ESP32 and Rust Make a Winning Combination
Good places to get started with std Rust on ESP include the Rust on ESP book, Embedded Rust on Espressif by Ferrous Systems. There's also the Awesome ESP Rust GitHub repository that contains a lot of useful material and project examples.
-
Embedded Rust on ESP32: compatibility issue with esp_idf_hal and embedded_hal?
I'm not new to microcontrollers or Rust, but I am new to trying Rust on an ESP32. I have followed the Rust on ESP book, and I have everything compiling and flashing fine, at least with a very basic "Hello, World!" printed to the serial console.
-
ESP32 Embedded Rust at the HAL: Button-Controlled Blinking by Timer Polling
Familiarity with the basic template for creating embedded applications in Rust for the ESP32 (The Rust on ESP Book is a good resource).
-
Embedded Rust tutorials on the ESP32-C3
For environment setup guidelines it would be better to reference the book, although we are working on a great improvement of it: https://github.com/esp-rs/book/issues/59
esp-idf-template
- Mabez Rust on Espressif chips – update
-
Edge IoT with Rust on ESP: MQTT Subscriber
use anyhow; use embedded_svc::mqtt::client::Event; use embedded_svc::mqtt::client::QoS; use embedded_svc::wifi::{AuthMethod, ClientConfiguration, Configuration}; use esp_idf_hal::peripherals::Peripherals; use esp_idf_svc::eventloop::EspSystemEventLoop; use esp_idf_svc::mqtt::client::{EspMqttClient, MqttClientConfiguration}; use esp_idf_svc::nvs::EspDefaultNvsPartition; use esp_idf_svc::wifi::{BlockingWifi, EspWifi}; use std::{thread::sleep, time::Duration}; fn main() -> anyhow::Result<()> { // It is necessary to call this function once. Otherwise some patches to the runtime // implemented by esp-idf-sys might not link properly. See https://github.com/esp-rs/esp-idf-template/issues/71 esp_idf_sys::link_patches(); let peripherals = Peripherals::take().unwrap(); let sysloop = EspSystemEventLoop::take()?; let nvs = EspDefaultNvsPartition::take()?; let mut wifi = BlockingWifi::wrap( EspWifi::new(peripherals.modem, sysloop.clone(), Some(nvs))?, sysloop, )?; wifi.set_configuration(&Configuration::Client(ClientConfiguration { ssid: "SSID".into(), bssid: None, auth_method: AuthMethod::None, password: "PASSWORD".into(), channel: None, }))?; // Start Wifi wifi.start()?; // Connect Wifi wifi.connect()?; // Wait until the network interface is up wifi.wait_netif_up()?; // Print Out Wifi Connection Configuration while !wifi.is_connected().unwrap() { // Get and print connection configuration let config = wifi.get_configuration().unwrap(); println!("Waiting for station {:?}", config); } println!("Wifi Connected"); // Set up handle for MQTT Config let mqtt_config = MqttClientConfiguration::default(); // Create Client Instance and Define Behaviour on Event let mut client = EspMqttClient::new( "mqtt://broker.mqttdashboard.com", &mqtt_config, move |message_event| { match message_event.as_ref().unwrap() { Event::Connected(_) => println!("Connected"), Event::Subscribed(id) => println!("Subscribed to {} id", id), Event::Received(msg) => { if msg.data() != [] { println!("Recieved {}", std::str::from_utf8(msg.data()).unwrap()) } } _ => println!("{:?}", message_event.as_ref().unwrap()), }; }, )?; // Subscribe to MQTT Topic client.subscribe("testtopic/1", QoS::AtLeastOnce)?; loop { // Keep waking up device to avoid watchdog reset sleep(Duration::from_millis(1000)); } }
-
Edge IoT with Rust on ESP: NTP
use anyhow; use chrono::{DateTime, Utc}; use embedded_svc::wifi::{AuthMethod, ClientConfiguration, Configuration}; use esp_idf_hal::delay::FreeRtos; use esp_idf_hal::peripherals::Peripherals; use esp_idf_svc::eventloop::EspSystemEventLoop; use esp_idf_svc::nvs::EspDefaultNvsPartition; use esp_idf_svc::sntp::{EspSntp, SyncStatus}; use esp_idf_svc::wifi::{BlockingWifi, EspWifi}; use std::time::SystemTime; fn main() -> anyhow::Result<()> { // It is necessary to call this function once. Otherwise some patches to the runtime // implemented by esp-idf-sys might not link properly. See https://github.com/esp-rs/esp-idf-template/issues/71 esp_idf_sys::link_patches(); let peripherals = Peripherals::take().unwrap(); let sysloop = EspSystemEventLoop::take()?; let nvs = EspDefaultNvsPartition::take()?; let mut wifi = BlockingWifi::wrap( EspWifi::new(peripherals.modem, sysloop.clone(), Some(nvs))?, sysloop, )?; wifi.set_configuration(&Configuration::Client(ClientConfiguration { ssid: "Wokwi-GUEST".into(), bssid: None, auth_method: AuthMethod::None, password: "".into(), channel: None, }))?; // Start Wifi wifi.start()?; // Connect Wifi wifi.connect()?; // Wait until the network interface is up wifi.wait_netif_up()?; // Print Out Wifi Connection Configuration while !wifi.is_connected().unwrap() { // Get and print connection configuration let config = wifi.get_configuration().unwrap(); println!("Waiting for station {:?}", config); } println!("Wifi Connected"); // Create Handle and Configure SNTP let ntp = EspSntp::new_default().unwrap(); // Synchronize NTP println!("Synchronizing with NTP Server"); while ntp.get_sync_status() != SyncStatus::Completed {} println!("Time Sync Completed"); loop { // Obtain System Time let st_now = SystemTime::now(); // Convert to UTC Time let dt_now_utc: DateTime = st_now.clone().into(); // Format Time String let formatted = format!("{}", dt_now_utc.format("%d/%m/%Y %H:%M:%S")); // Print Time println!("{}", formatted); // Delay FreeRtos::delay_ms(1000); } }
-
ESP32 Standard Library Embedded Rust: GPIO Interrupts
use std::sync::atomic::AtomicBool; use std::sync::atomic::Ordering; use esp_idf_hal::gpio::*; use esp_idf_hal::peripherals::Peripherals; use esp_idf_sys::{self as _}; static FLAG: AtomicBool = AtomicBool::new(false); fn gpio_int_callback() { // Assert FLAG indicating a press button happened FLAG.store(true, Ordering::Relaxed); } fn main() -> ! { // It is necessary to call this function once. Otherwise some patches to the runtime // implemented by esp-idf-sys might not link properly. See https://github.com/esp-rs/esp-idf-template/issues/71 esp_idf_sys::link_patches(); // Take Peripherals let dp = Peripherals::take().unwrap(); // Configure button pin as input let mut button = PinDriver::input(dp.pins.gpio0).unwrap(); // Configure button pin with internal pull up button.set_pull(Pull::Up).unwrap(); // Configure button pin to detect interrupts on a positive edge button.set_interrupt_type(InterruptType::PosEdge).unwrap(); // Attach the ISR to the button interrupt unsafe { button.subscribe(gpio_int_callback).unwrap() } // Enable interrupts button.enable_interrupt().unwrap(); // Set up a variable that keeps track of press button count let mut count = 0_u32; loop { // Check if global flag is asserted if FLAG.load(Ordering::Relaxed) { // Reset global flag FLAG.store(false, Ordering::Relaxed); // Update Press count and print count = count.wrapping_add(1); println!("Press Count {}", count); } } }
-
ESP32 Standard Library Embedded Rust: GPIO Control
use esp_idf_sys as _; // If using the `binstart` feature of `esp-idf-sys`, always keep this module imported use esp_idf_hal::delay::FreeRtos; use esp_idf_hal::gpio::*; use esp_idf_hal::peripherals::Peripherals; fn main() { // It is necessary to call this function once. Otherwise some patches to the runtime // implemented by esp-idf-sys might not link properly. See https://github.com/esp-rs/esp-idf-template/issues/71 esp_idf_sys::link_patches(); // Take Peripherals let dp = Peripherals::take().unwrap(); // Configure all LED pins to digital outputs let mut led1 = PinDriver::output(dp.pins.gpio1).unwrap(); let mut led2 = PinDriver::output(dp.pins.gpio10).unwrap(); let mut led3 = PinDriver::output(dp.pins.gpio19).unwrap(); let mut led4 = PinDriver::output(dp.pins.gpio18).unwrap(); let mut led5 = PinDriver::output(dp.pins.gpio4).unwrap(); let mut led6 = PinDriver::output(dp.pins.gpio5).unwrap(); let mut led7 = PinDriver::output(dp.pins.gpio6).unwrap(); let mut led8 = PinDriver::output(dp.pins.gpio7).unwrap(); let mut led9 = PinDriver::output(dp.pins.gpio8).unwrap(); let mut led10 = PinDriver::output(dp.pins.gpio9).unwrap(); // Configure Button pin to input with Pull Up let mut button = PinDriver::input(dp.pins.gpio3).unwrap(); button.set_pull(Pull::Up).unwrap(); // Initialize variable with starting delay let mut blinkdelay = 200_u32; loop { // Algo: // Starting with first LED in sequence // 1. Turn on LED // 2. Retrieve adjusted delay based on button press // 3. Delay with adjusted value // 4. Turn off LED // 5. Delay for 100ms (to make sure LED is turned off) // 6. Repeat steps 1-5 for next LED in sequence // 7. Once all LEDs are done loop back to first LED in sequence // LED 1 led1.set_high().unwrap(); blinkdelay = button_pressed(&button, &blinkdelay); FreeRtos::delay_ms(blinkdelay); led1.set_low().unwrap(); FreeRtos::delay_ms(100_u32); // LED 2 led2.set_high().unwrap(); blinkdelay = button_pressed(&button, &blinkdelay); FreeRtos::delay_ms(blinkdelay); led2.set_low().unwrap(); FreeRtos::delay_ms(100_u32); // LED 3 led3.set_high().unwrap(); blinkdelay = button_pressed(&button, &blinkdelay); FreeRtos::delay_ms(blinkdelay); led3.set_low().unwrap(); FreeRtos::delay_ms(100_u32); // LED 4 led4.set_high().unwrap(); blinkdelay = button_pressed(&button, &blinkdelay); FreeRtos::delay_ms(blinkdelay); led4.set_low().unwrap(); FreeRtos::delay_ms(100_u32); // LED 5 led5.set_high().unwrap(); blinkdelay = button_pressed(&button, &blinkdelay); FreeRtos::delay_ms(blinkdelay); led5.set_low().unwrap(); FreeRtos::delay_ms(100_u32); // LED 6 led6.set_high().unwrap(); blinkdelay = button_pressed(&button, &blinkdelay); FreeRtos::delay_ms(blinkdelay); led6.set_low().unwrap(); FreeRtos::delay_ms(100_u32); // LED 7 led7.set_high().unwrap(); blinkdelay = button_pressed(&button, &blinkdelay); FreeRtos::delay_ms(blinkdelay); led7.set_low().unwrap(); FreeRtos::delay_ms(100_u32); // LED 8 led8.set_high().unwrap(); blinkdelay = button_pressed(&button, &blinkdelay); FreeRtos::delay_ms(blinkdelay); led8.set_low().unwrap(); FreeRtos::delay_ms(100_u32); // LED 9 led9.set_high().unwrap(); blinkdelay = button_pressed(&button, &blinkdelay); FreeRtos::delay_ms(blinkdelay); led9.set_low().unwrap(); FreeRtos::delay_ms(100_u32); // LED 10 led10.set_high().unwrap(); blinkdelay = button_pressed(&button, &blinkdelay); FreeRtos::delay_ms(blinkdelay); led10.set_low().unwrap(); FreeRtos::delay_ms(100_u32); } } fn button_pressed(but: &PinDriver<'_, Gpio3, Input>, del: &u32) -> u32 { // Check if Button has been pressed // If not pressed, return the delay value unchanged if but.is_low() { // if the value of the delay passed is less of equal to 50 then reset it to initial value // else subtract 50 from the passed delay println!("Button Pressed!"); if del <= &50_u32 { return 200_u32; } else { return del - 50_u32; } } else { return *del; } }
-
Embedded Rust on ESP32: compatibility issue with esp_idf_hal and embedded_hal?
fn main() -> anyhow::Result<()> { // It is necessary to call this function once. Otherwise some patches to the runtime // implemented by esp-idf-sys might not link properly. See https://github.com/esp-rs/esp-idf-template/issues/71 esp_idf_sys::link_patches(); println!("Hello, world!");
-
Rust on Esp32
There is a template for how to use Rust from an idf.py cmake project where you can incrementally add Rust to your project by calling to from C. Instructions for it are at https://github.com/esp-rs/esp-idf-template/blob/master/README-cmake.md
-
ESP32 example project
Sorry for the poor way of supporting you, I am currently at the embedded world and I can't try much to reproduce your issue. I just merged: https://github.com/esp-rs/esp-idf-template/pull/84. Which can be what you were facing, can you use the latest template and see if the issue still persists? Let me know how it goes
-
Embedded Rust on ESP32C3 Board, a Hands-on Quickstart Guide
The awesome ESP IDF Template will save us the pain of configuring a fully functional project ourselves, use it like so:
-
Accessing embedded peripherals from state machine
fn main() { // It is necessary to call this function once. Otherwise some patches to the runtime // implemented by esp-idf-sys might not link properly. See https://github.com/esp-rs/esp-idf-template/issues/71 esp_idf_sys::link_patches();
What are some alternatives?
rustzx-esp32 - ESP32 implementation of RustZX Spectrum emulator
rust-esp32-std-demo - Rust on ESP32 STD demo app. A demo STD binary crate for the ESP32[XX] and ESP-IDF, which connects to WiFi, Ethernet, drives a small HTTP server and draws on a LED screen.
ruduino - Reusable components for the Arduino Uno.
espup - Tool for installing and maintaining Espressif Rust ecosystem.
esp-rust-board - Open Hardware with ESP32-C3 compatible with Feather specification designed in KiCad
esp-template - A minimal esp-hal application template for use with cargo-generate
avr-hal-template - cargo-generate template for avr-hal projects
sort-research-rs - Test and benchmark suite for sort implementations.
template - Template for a generic rust project hosted on GitHub
wokwi-features - Wokwi Feature requests & Bug Reports
std-training - Embedded Rust on Espressif training material.