Code Monkey home page Code Monkey logo

esp32s2-starter's Introduction

Rust ESP32-S2 Starter

A starter for ESP32-S2 projects, including tooling to build the "Cargo-first" way with embuild.

This is the result of some work over the past few weeks getting into both Rust development, and working with the ESP32-S2 MCU. The end-goal is to build a few WiFi-connected air quality sensors to place around my house. That project aims to use 3,000mAh Li-Ion 18650 batteries and (hopefully!) year-plus operation, so ultra-low power usage is critical.

This project includes a buildable example that can be flashed to your ESP32-S2, including some boilerplate code to interact with the ULP coprocessor.

Please note that I am new to Cargo Workspaces, Rust, and the ESP32. Please open an issue if you notice anything wrong!


Todo

  • Build both main and ULP binaries from one workspace
  • Build the main binary using embuild's native features (e.g. no PlatformIO)
  • Allow flashing from the WSL2 environment
  • Example ULP code to sleep for a specified interval, then wake-up the main processor
  • Example code to comminicate between main and ULP processors
  • Allow building via native cargo build

Getting Started

  • Install rustup from https://rustup.rs/
  • Install the custom Rust ESP32 toolchain and LLVM Clang forks
    • You probably want to do the following in ~/.espressif-rust or /opt/rustup-esp or similar
    • curl -sSL -o install-rust-toolchain.sh https://github.com/esp-rs/rust-build/releases/download/v1.57.0.2/install-rust-toolchain.sh
    • sudo chmod u+x install-rust-toolchain.sh
    • ./install-rust-toolchain.sh --export-file ./rustup-export.sh
    • source ./rustup-export.sh (this needs to be done for each bash session where you're building the ESP32-S2 project)
  • Download the starter
    • git clone https://github.com/ryanc-me/esp32s2-starter

For WSL2 users

Some extra setup is required to allow flashing the chip from the WSL2 environment.


Building

Because of some Cargo limitations (or lack of understanding on my part) the native cargo build does not work from the workspace root. From what I can gather, Rust is trying to use the same toolchain for both main and ULP crates.

As a workaround, you can build each crate separately, from within the crate directory:

  • cd ulp && cargo build
  • cd main && cargo build --features native

Alternatively, there is a build.sh script which does the above for you.


Flashing

For Linux users

Follow the standard flashing procedure, e.g.:

  • Ensure tools are installed
    • cargo install espflash
    • cargo install espmonitor
  • espflash --monitor /dev/ttyUSB1 target/xtensa-esp32s2-espidf/debug/main
  • espmonitor /dev/ttyUSB1

For Windows/WSL2 users

  • Make sure both espflash and espmonitor are installed in the Windows environment.
    • Install Rust
    • cargo install espflash
    • cargo install espmonitor
  • Then, from your WSL2 Linux environment:
    • powershell.exe -Command "espflash --monitor COM1 target/xtensa-esp32s2-espidf/debug/main
    • powershell.exe -Command "espmonitor COM1"
    • Note that powershell.exe will only be available in your Linux env if you open your WSL2 target e.g. via Windows Terminal, or VSCode's Remote WSL extension (the latter is a very good option). Some info here if, for some reason, you need to do this via SSH.
  • Or, alternatively, the flash.sh script runs the flash+monitor command for you.

Credits


License

esp32s2-starter's People

Contributors

ryanc-me avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.