• Stars
    star
    396
  • Rank 108,801 (Top 3 %)
  • Language
    Rust
  • License
    Apache License 2.0
  • Created over 2 years ago
  • Updated about 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Wi-Fi and BT drivers packaged for integration into bare-metal esp-wifi.

esp-wifi

Wi-Fi/BTLE coexistence is implemented but currently only works (to some extent) on ESP32-C3 and ESP32-S3. In general COEX shouldn't be used currently.

Minimum supported Rust compiler version: 1.65.0.0

This uses the WiFi drivers from https://github.com/esp-rs/esp-wireless-drivers-3rdparty

Version used

v5.1-rc2-4-gc570f67461 commit c570f674610479fc5e070c8db6d181b73ddf60a8

https://github.com/esp-rs/esp-wireless-drivers-3rdparty/ (commit 976e9cc6c0725e8325a7e3a362d113559238c45c)

Current support

If a cell contains am em dash (β€”) this means that the particular feature is not present for a chip. A check mark (βœ“) means that some driver implementation exists. An empty cell means that the feature is present in the chip but not implemented yet.

Wifi BLE Coex ESP-NOW
ESP32 βœ“ βœ“ βœ“
ESP32-S2 βœ“ β€” β€” βœ“
ESP32-S3 βœ“ βœ“ βœ“ βœ“
ESP32-C3 βœ“ βœ“ βœ“ βœ“
ESP32-C2 βœ“ βœ“ βœ“
ESP32-C6 βœ“ βœ“

Usage

Importing

For now this is not available on crates.io. Until then you need to import via git, cloning locally, etc.

[dependencies.esp-wifi]
git = "https://github.com/esp-rs/esp-wifi.git"

# `esp-wifi` is in active development. It is often a good idea to lock it to a specific commit
rev = "c7ca849274cf3d7a08b49c260bb46693c91c85c0"

# A supported chip needs to be specified, as well as specific use-case features 
features = ["esp32s3", "wifi", "esp-now"]

Link configuration

Important
Make sure to include the rom functions for your target:

# .cargo/config.toml
rustflags = [
    "-C", "link-arg=-Tlinkall.x",
    "-C", "link-arg=-Trom_functions.x",
]

Note
At time of writing, you will already have the linkall flag if you used cargo generate. Generating from a template does not include the rom_functions flag.

Optimization Level

Important
Link time optimization is not yet recommended for use, please ensure lto = "off" is in your Cargo.toml for both release and debug profiles.

It is necessary to build with optimization level 2 or 3 since otherwise it might not even be able to connect or advertise.

To make it work also for your debug builds add this to your Cargo.toml

[profile.dev.package.esp-wifi]
opt-level = 3

[profile.dev]
lto = "off"
[profile.release]
lto = "off"

Features

Feature Meaning
wifi-logs logs the WiFi logs from the driver at log level info
dump-packets dumps packet info at log level info
utils Provide utilities for smoltcp initialization, this is a default feature
embedded-svc Provides a (very limited) implementation of the embedded-svc WiFi trait, includes utils feature
ble Enable BLE support
wifi Enable WiFi support
esp-now Enable esp-now support
coex Enable coex support
mtu-XXX Set MTU to XXX, XXX can be 746, 1492, 1500, 1514. Defaults to 1492
big-heap Reserve more heap memory for the drivers
ipv6 IPv6 support
phy-enable-usb See Using Serial-JTAG below
ps-min-modem Enable modem sleep

When using the dump-packets feature you can use the extcap in extras/esp-wifishark to analyze the frames in Wireshark. For more information see extras/esp-wifishark/README.md

Serial-JTAG

Important
On ESP32-C3 / ESP32-S3 when using Serial-JTAG you have to activate the feature phy-enable-usb.

Don't use this feature if your are not using Serial-JTAG since it might reduce WiFi performance.

Tuning

The defaults used by esp-wifi and the examples are rather conservative. It is possible to change a few of the important settings.

See Tuning for details

What works?

  • scanning for WiFi access points
  • connect to WiFi access point
  • providing an HCI interface
  • create an open access point

Notes on ESP32-C2 / ESP32-C3 / ESP32-C6 support

  • uses SYSTIMER as the main timer
  • doesn't work in direct-boot mode

Notes on ESP32 / ESP32-S2 / ESP32-S3 support

  • The WiFi logs only print the format string - not the actual values.
  • The code runs on a single core and might currently not be multi-core safe!

On ESP32 / ESP32-S2 / ESP32-S3 currently TIMG1/TIMER0 is used as the main timer so you can't use it for anything else. Additionally it uses CCOMPARE0 - so don't touch that, too.

opt-level for Xtensa targets

Currently your mileage might vary a lot for different opt-levels on Xtensa targets! If something doesn't work as expected try a different opt-level.

Examples

To build these ensure you are in the examples-esp32XXX directory matching your target as othewise the config.toml will not apply

dhcp

  • set SSID and PASSWORD env variable
  • gets an ip address via DHCP
  • performs an HTTP get request to some "random" server

cargo run --example dhcp --release --features "embedded-svc,wifi"

static_ip

  • set SSID and PASSWORD env variable
  • set STATIC_IP and GATEWAY_IP env variable (e.g. "192.168.2.191" / "192.168.2.1")
  • might be necessary to configure your WiFi access point accordingly
  • uses the given static IP
  • responds with some HTML content when connecting to port 8080

cargo run --example static_ip --release --features "embedded-svc,wifi"

ble

  • starts Bluetooth advertising
  • offers one service with three characteristics (one is read/write, one is write only, one is read/write/notify)
  • pressing the boot-button on a dev-board will send a notification if it is subscribed
  • this uses a toy level BLE stack - might not work with every BLE central device (tested with Android and Windows Bluetooth LE Explorer)

cargo run --example ble --release --features "ble"

NOTE: ESP32-S2 doesn't support bluetooth, for ESP32-C6 bluetooth support isn't implemented yet

async_ble

  • same as ble but async

cargo run --example async_ble --release --features "async,ble"

NOTE: ESP32-S2 doesn't support bluetooth, for ESP32-C6 bluetooth support isn't implemented yet

coex

  • set SSID and PASSWORD env variable
  • gets an ip address via DHCP
  • performs an HTTP get request to some "random" server
  • does BLE advertising
  • coex support is still somewhat flaky

cargo run --example coex --release --features "embedded-svc,wifi,ble"

NOTE: Not currently available for the ESP32, ESP32-C2, ESP32-C6 or ESP32-S2

esp_now

  • broadcasts, receives and sends messages via esp-now

cargo run --example esp_now --release --features "esp-now"

embassy_esp_now

  • broadcasts, receives and sends messages via esp-now in an async way

cargo run --example embassy_esp_now --release --features "async,esp-now"

embassy_dhcp

  • Read and Write to sockets over WiFi asyncronously using embassy-executor.

cargo run --example embassy_dhcp --release --features "async,embedded-svc,wifi,embassy-net"

access_point

  • creates an open access-point with SSID esp-wifi
  • you can connect to it using a static IP in range 192.168.2.2 .. 192.168.2.255, gateway 192.168.2.1
  • open http://192.168.2.1:8080/ in your browser
  • on Android you might need to choose Keep Accesspoint when it tells you the WiFi has no internet connection, Chrome might not want to load the URL - you can use a shell and try curl and ping

cargo run --example access_point --release --features "embedded-svc,wifi"

embassy_access_point

  • creates an open access-point with SSID esp-wifi
  • you can connect to it using a static IP in range 192.168.2.2 .. 192.168.2.255, gateway 192.168.2.1
  • open http://192.168.2.1:8080/ in your browser
  • on Android you might need to choose Keep Accesspoint when it tells you the WiFi has no internet connection, Chrome might not want to load the URL - you can use a shell and try curl and ping

cargo run --example embassy_access_point --release --features "async,embedded-svc,wifi,embassy-net"

Directory Structure

  • src/timer-espXXX.rs: systimer code used for timing and task switching
  • src/preemt/: a bare minimum RISCV and Xtensa round-robin task scheduler
  • src/compat/: code needed to emulate enough of an (RT)OS to use the driver
    • common.rs: basics like semaphores and recursive mutexes
    • timer_compat.rs: code to emulate timer related functionality
  • examples/*.rs: examples

Missing / To be done

  • lots of refactoring
  • make CoEx work on ESP32 (it kind of works when commenting out setting the country in wifi_start, probably some mis-compilation since it then crashes in a totally different code path)
  • combined SoftAP/STA mode
  • support for non-open SoftAP

License

Licensed under either of:

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

More Repositories

1

awesome-esp-rust

Curated list of resources for ESP32 development in the Rust programming language
825
star
2

esp-hal

no_std Hardware Abstraction Layers for ESP32 microcontrollers
Rust
712
star
3

std-training

Embedded Rust on Espressif training material.
Rust
596
star
4

esp-rust-board

Open Hardware with ESP32-C3 compatible with Feather specification designed in KiCad
487
star
5

espflash

Serial flasher utility for Espressif SoCs and modules based on esptool.py
Rust
476
star
6

esp-idf-hal

embedded-hal implementation for Rust on ESP32 and ESP-IDF
Rust
449
star
7

esp-idf-template

A "Hello, world!" template of a Rust binary crate for the ESP-IDF framework.
CMake
414
star
8

esp-idf-svc

Type-Safe Rust Wrappers for various ESP-IDF services (WiFi, Network, Httpd, Logging, etc.)
Rust
311
star
9

esp-idf-sys

Bindings for ESP-IDF (Espressif's IoT Development Framework)
Rust
270
star
10

rust-build

Installation tools and workflows for deploying/building Rust fork esp-rs/rust with Xtensa and RISC-V support
PowerShell
249
star
11

espup

Tool for installing and maintaining Espressif Rust ecosystem.
Rust
220
star
12

esp32-hal

A hardware abstraction layer for the esp32 written in Rust.
Rust
193
star
13

book

The Rust on ESP Book
JavaScript
171
star
14

esp8266-hal

A experimental hardware abstraction layer for the esp8266 written in Rust.
Rust
157
star
15

esp-template

A minimal esp-hal application template for use with cargo-generate
Dockerfile
141
star
16

embuild

Build support for embedded Rust: Cargo integration with other embedded build ecosystems & tools, like PlatformIO, CMake and kconfig.
Rust
137
star
17

rfc2217-rs

IETF RFC2217 implementation in Rust
Rust
133
star
18

esp32

Peripheral access crate for the ESP32
Rust
126
star
19

embedded-svc

Rust APIs and abstractions for various embedded services (WiFi, Network, Httpd, Logging, etc.)
Rust
122
star
20

esp-pacs

Peripheral Access Crates for Espressif SoCs and modules
Rust
105
star
21

esp32-wifi

Rust ESP32 WiFi Library
Rust
79
star
22

no_std-training

Getting-started guide on using the Rust with Espressif SoCs using no_std.
Rust
62
star
23

espmonitor

Cargo tool for monitoring ESP32/ESP8266 execution
Rust
48
star
24

esp-openthread

Rust
45
star
25

xtensa-lx-rt

Minimal runtime/startup for Xtensa LX processors
Rust
44
star
26

esp-ieee802154

Low-level IEEE802.15.4 driver for the ESP32-C6 and ESP32-H2
Rust
36
star
27

esp-web-flash-server

Starts a local server serving a web page to flash a given ELF file
Rust
34
star
28

esp-backtrace

backtrace for ESP32 bare-metal
Rust
29
star
29

esp32c3

Peripheral access crate for the ESP32-C3
Rust
28
star
30

xtensa-lx

Low-level access to Xtensa LX processors
Rust
26
star
31

esp-storage

implementation of embedded-storage traits to access unencrypted ESP32 flash
Rust
25
star
32

esp8266

Peripheral access crate for the ESP8266
Rust
22
star
33

esp-riscv-rt

Minimal runtime / startup for RISC-V CPUs from Espressif
Rust
20
star
34

esp-println

Provides print! and println! implementations various Espressif devices
Rust
20
star
35

esp-mbedtls

mbedtls for ESP32 bare-metal
Rust
19
star
36

esp-flasher-stub

Rust implementation of flasher stub located in esptool
Rust
18
star
37

esp-alloc

A simple `no_std` heap allocator for RISC-V and Xtensa processors from Espressif
Rust
15
star
38

esp-flash-loader

A probe-rs flash loader for Espressif chips.
RPC
15
star
39

xtensa-toolchain

A GitHub Action to install the Rust compiler fork targeting Xtensa devices
11
star
40

docker-rust-esp

Rust build environment for the ESP32 and ESP8266
Dockerfile
10
star
41

esp-idf-part

A library for parsing and generating ESP-IDF partition tables
Rust
8
star
42

riscv-atomic-emulation-trap

An atomic emulation trap handler for non atomic RISCV targets
Rust
8
star
43

esp-serial-dbg

esp-serial-dbg - debugging of esp-hal based applications via serial
Rust
7
star
44

esp-rust-board-bsp

A board support package for the ESP Rust Board
Rust
7
star
45

esp-hal-community

Rust
7
star
46

esp-generate

Template generation tool to create no_std applications targeting Espressif's chips.
Rust
6
star
47

xtensa-atomic-emulation-trap

An atomic emulation trap handler for non atomic Xtensa targets
Rust
4
star
48

docs

3
star
49

rfcs

2
star
50

esp32s3

Peripheral access crate for the ESP32-S3
Rust
1
star
51

esp32s2

Rust
1
star
52

repo-activity-digest

Python
1
star