Expand description
§Wireless support for Espressif ESP32 devices.
This documentation is built for the ESP32-H2 . Please ensure you are reading the correct documentation for your target device.
§Usage
§Importing
Enabling the unstable feature on esp-radio requires you to also enable
the unstable feature on esp-hal in the final binary crate.
Ensure that the right features are enabled for your chip. See Examples for more examples.
You will also need a dynamic memory allocator, and a preemptive task scheduler in your
application. For the dynamic allocator, we recommend using esp-alloc. For the task scheduler,
the simplest option that is supported by us is esp-rtos, but you may use Ariel
OS or other operating systems as well.
use esp_hal::interrupt::software::SoftwareInterruptControl;
use esp_hal::ram;
use esp_hal::timer::timg::TimerGroup;
esp_alloc::heap_allocator!(#[ram(reclaimed)] size: 64 * 1024);
esp_alloc::heap_allocator!(size: 36 * 1024);
let timg0 = TimerGroup::new(peripherals.TIMG0);
let sw_interrupt = SoftwareInterruptControl::new(peripherals.SW_INTERRUPT);
// THIS IS IMPORTANT FOR WIFI AND BLE: You MUST start the scheduler
// before initializing the radio!
esp_rtos::start(timg0.timer0, sw_interrupt.software_interrupt0);
if let Ok(controller) = BleConnector::new(peripherals.BT, Default::default()) {}[dependencies.esp-radio]
# A supported chip needs to be specified, as well as specific use-case features
features = ["esp32h2", "wifi", "esp-now", "esp-alloc"]
[dependencies.esp-rtos]
features = ["esp32h2", "esp-radio", "esp-alloc"]
[dependencies.esp-alloc]
features = ["esp32h2"]§Optimization Level
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-radio]
opt-level = 3§Globally disable logging
esp-radio contains a lot of trace-level logging statements.
For maximum performance you might want to disable logging via
a feature flag of the log crate. See documentation.
You should set it to release_max_level_off.
§Feature flags
Note that not all features are available on every MCU. For example, ble
(and thus, coex) is not available on ESP32-S2.
When using the dump_packets config you can use the extcap in
extras/esp-wifishark to analyze the frames in Wireshark.
For more information see
extras/esp-wifishark/README.md
-
esp-alloc(enabled by default) — Useesp-allocwith thecompatfeature for dynamic allocations.If you opt-out, you need to provide implementations for the following functions:
pub extern "C" fn malloc(size: usize) -> *mut u8pub extern "C" fn malloc_internal(size: usize) -> *mut u8pub extern "C" fn free(ptr: *mut u8)pub extern "C" fn free_internal(ptr: *mut u8)pub extern "C" fn calloc(number: u32, size: usize) -> *mut u8pub extern "C" fn calloc_internal(number: u32, size: usize) -> *mut u8pub extern "C" fn realloc(ptr: *mut u8, new_size: usize) -> *mut u8pub extern "C" fn get_free_internal_heap_size() -> usize;
Note that the untyped nature of the allocator functions means that esp-alloc is likely the more memory efficient option.
-
print-logs-from-driver— Outputs logs from the pre-compiled Wi-Fi and BLE driver blobs at info level.⚠️ This feature is considered unstable.
§Chip selection
One of the following features must be enabled to select the target chip:
esp32esp32c2esp32c3esp32c5esp32c6esp32c61esp32h2esp32s2esp32s3
§Wireless Feature Flags
-
ble— Enable BLE support.⚠️ This feature is considered unstable.
-
ieee802154— Enable IEEE 802.15.4. Cannot be used together with Wi-Fi.⚠️ This feature is considered unstable.
§Ecosystem Feature Flags
§Logging Feature Flags
log-04— Enable logging output using version 0.4 of thelogcrate.defmt— Enable logging output usingdefmtand implementdefmt::Formaton certain types.
§Unstable APIs
Unstable APIs are drivers and features that are not yet ready for general use. They may be incomplete, have bugs, or be subject to change without notice.
-
unstable— Enables APIs that are not stable and thus come with no stability guarantees. Never enable this feature in a library crate using esp-radio. -
requires-unstable— Libraries that depend onesp-radioshould enable this feature to indicate their use of unstable APIs. However, they must not enable theunstablefeature themselves.For development you can enable the
unstableand the chip feature by adding esp-radio as a dev-dependency.
§Additional configuration
We’ve exposed some configuration options that don’t fit into cargo
features. These can be set via environment variables, or via cargo’s [env]
section inside .cargo/config.toml. Below is a table of tunable parameters
for this crate:
| Option | Stability | Default value | Allowed values |
|---|---|---|---|
ESP_RADIO_CONFIG_WIFI_MAX_BURST_SIZE | ⚠️ Unstable | 3 | Positive integer or 0 |
ESP_RADIO_CONFIG_WIFI_MTU MTU, see embassy-net’s documentation | ⚠️ Unstable | 1492 | Positive integer |
ESP_RADIO_CONFIG_DUMP_PACKETS Dump packets via an info log statement | ⚠️ Unstable | false | |
ESP_RADIO_CONFIG_EVENT_CHANNEL_CAPACITY Capacity of the internal event channel | ⚠️ Unstable | 2 | Positive integer or 0 |
ESP_RADIO_CONFIG_EVENT_CHANNEL_SUBSCRIBERS Max subscriber count of the internal event channel | ⚠️ Unstable | 2 | Positive integer or 0 |
Modules§
- ble
bleandunstable - Bluetooth Low Energy HCI interface
- ieee802154
ieee802154andunstable - Low-level IEEE 802.15.4 driver
Enums§
- Calibration
Result unstable - Result of the PHY calibration.
Functions§
- last_
calibration_ result unstable - Get the last calibration result.
- phy_
calibration_ data unstable - Get calibration data.
- set_
phy_ calibration_ data unstable - Set calibration data.
- wifi_
set_ log_ verbose unstable - Enable verbose logging within the Wi-Fi driver
Does nothing unless the
print-logs-from-driverfeature is enabled.