esp-idf-template
std-training
esp-idf-template | std-training | |
---|---|---|
14 | 11 | |
353 | 553 | |
8.2% | 3.4% | |
8.6 | 7.5 | |
6 days ago | about 1 month ago | |
CMake | Rust | |
- | 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.
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();
std-training
-
ESP32 Standard Library Embedded Rust: GPIO Interrupts
It's well established that interrupts are a tough concept to grasp for the embedded beginner. Add to that when doing it in Rust the complexity of dealing with mutable static variables. This is because working with shared variables and interrupts is inherently unsafe if proper measures are not taken. When looking at how to do interrupts using the esp-idf-hal I first resorted to the Embedded Rust on Espressif book. Interrupts are covered under the Advanced Workshop in section 4.3, and to be honest, I was taken aback a little at what could be an additional level of complexity for a beginner. Without too much detail, this is because the book resorts to using lower-level implementations. For those interested, by that, I mean FFI interfaces to FreeRTOS which I will be creating a separate post about later.
- The Nano ESP32
-
ESP32 Standard Library Embedded Rust: GPIO Control
Relative to the esp-idf-hal , as far as material goes, there exists training material that is open sourced by Ferrous systems. The training material takes a bit of a different approach where it starts with high-level IoT exercises followed by low-level control. Additionally, the training is based on the awesome Rust ESP board hardware.
-
Espressif advances with Rust – 30-06-2023
Yes! The training developed with Ferrous Systems (https://esp-rs.github.io/std-training/) contains several examples, and you can find many community projects in https://github.com/esp-rs/awesome-esp-rust#projects
-
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 ESP32C3 Board, a Hands-on Quickstart Guide
Embedded Rust on Espressif (Ferrous Systems training)
- Some experience with IoT
-
Why do I constantly feel like I'm doing something wrong by continuing using C++?
I must admit I've never used it for anything but tutorials yet (kids resulted in a lot of personal projects shelved), but Rust has an amazing and rapidly developing embedded ecosystem. A good starting point to get an impression of it might be training materials from Ferrous Systems 1, 2 (feel free to pay for the training itself if you feel like it's worth it for you of course). There is an embedded working group for Rust, Knurling project to improve tooling and even an attempt of Rust standard certified for safety-critical application.
- noob question, Whats the point of interfacing arduino uno and ESP32?
-
Ask HN: Has any Rust developer moved to embedded device programming?
I’ve been super curious about both Rust and ESP. It seems like Espressif is interested enough to commission a Rust dev board (ESP32-C3-DevKit-RUST-1) and training using it.
https://github.com/esp-rs/esp-rust-board/
https://github.com/ferrous-systems/espressif-trainings
What are some alternatives?
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.
solo2 - Solo 2 firmware in Rust
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
rp2040-mandel-pico - A small Mandelbrot demonstrator for the LILYGO T-Display RT2040 written in Rust
avr-hal-template - cargo-generate template for avr-hal projects
espflash - Serial flasher utility for Espressif SoCs and modules based on esptool.py
template - Template for a generic rust project hosted on GitHub
wokwi-features - Wokwi Feature requests & Bug Reports
templates - Templates for bootstrapping a Rust TUI application with Ratatui
awesome-esp-rust - Curated list of resources for ESP32 development in the Rust programming language