Expand description
You might want to browse the esp-hal
documentation on the esp-rs website instead.
The documentation here on docs.rs is built for a single chip only (ESP32-C6, in particular), while on the esp-rs website you can select your exact chip from the list of supported devices. Available peripherals and their APIs change depending on the chip.
Bare-metal (no_std
) HAL for all Espressif ESP32 devices.
The HAL implements both blocking and async
APIs for many peripherals. Where applicable, driver implement
the embedded-hal and embedded-hal-async traits.
This documentation is built for the ESP32-C6 please ensure you are reading the correct documentation for your target device.
§Choosing a device
Depending on your target device, you need to enable the chip feature for that device. You may also need to do this on ancillary esp crates.
§Examples
We have a plethora of examples in the esp-hal repository. We use an xtask to automate the building, running, and testing of code and examples within esp-hal.
Invoke the following command in the root of the esp-hal repository to get started.
cargo xtask help
§Creating a project
We have a book that explains the full esp-rs ecosystem and how to get started, it’s advisable to give that a read before proceeding.
We have a template for quick starting bare-metal projects, esp-template. The template uses cargo-generate, so ensure that it is installed and run
cargo generate -a esp-rs/esp-template
§Feature Flags
debug
— Enable debug features in the HAL (used for development).log
— Enable logging output using thelog
crate.place-spi-driver-in-ram
— Configuration for placing device drivers in the IRAM for faster access.
§RISC-V Exclusive Feature Flags
flip-link
— Move the stack to start of RAM to get zero-cost stack overflow protection (ESP32-C6 and ESPS32-H2 only!).rv-init-data
— Initialize the.data
section of memory.rv-zero-rtc-bss
— Zero the.bss
section of low-power memory.rv-init-rtc-data
— Initialize the.data
section of low-power memory.
§Trait Implementation Feature Flags
async
— Enable support for asynchronous operation, with interfaces provided byembedded-hal-async
andembedded-io-async
.defmt
— Implementdefmt::Format
on certain types.embedded-hal
(enabled by default) — Implement the traits defined in the1.0.0
releases ofembedded-hal
andembedded-hal-nb
for the relevant peripherals.embedded-hal-02
— Implement the traits defined in the0.2.x
release ofembedded-hal
.embedded-io
— Implement the traits defined inembedded-io
for certain peripherals.ufmt
— Implement theufmt_write::uWrite
trait for certain peripherals.
§Embassy Feature Flags
embassy
— Enable support forembassy
, a modern asynchronous embedded framework.embassy-executor-interrupt
— Use the interrupt-mode embassy executor.embassy-executor-thread
— Use the thread-mode embassy executor.embassy-integrated-timers
— Uses hardware timers as alarms for the executors. Using this feature limits the number of executors to the number of hardware alarms provided by the time driver.embassy-time-systick-16mhz
— Enable the embassy time driver using theSYSTIMER
peripheral. TheSYSTIMER
peripheral has three alarams available for use. Do not use when targeting anesp32s2
.embassy-time-systick-80mhz
— Enable the embassy time driver using theSYSTIMER
peripheral. TheSYSTIMER
peripheral has three alarams available for use. Must only be used when targeting anesp32s2
.embassy-time-timg0
— Enable the embassy time driver using theTIMG0
peripheral. TheTIMG0
peripheral has two alarms available for use.
§PSRAM Feature Flags
psram-2m
— Use externally connected PSRAM (2MB).psram-4m
— Use externally connected PSRAM (4MB).psram-8m
— Use externally connected PSRAM (8MB).psram-80mhz
— PSRAM 80Mhz frequency support
§Octal RAM Feature Flags
opsram-2m
— Use externally connected Octal RAM (2MB).opsram-4m
— Use externally connected Octal RAM (4MB).opsram-8m
— Use externally connected Octal RAM (8MB).opsram-16m
— Use externally connected Octal RAM (16MB).
Re-exports§
pub use esp_riscv_rt;
pub use esp_riscv_rt::riscv;
pub use procmacros as macros;
Modules§
- Advanced Encryption Standard (AES) support.
- Analog Peripherals
- Debug Assistant
- Clock Control
- Delay driver
- Direct Memory Access Commons
- ECC Accelerator
- Reading of eFuses (ESP32-C6)
- Event Task Matrix (ETM)
- General Purpose I/Os
- HMAC Accelerator
- I2C Driver
- I2S Master
- Interrupt support
- LEDC (LED PWM Controller) peripheral control
- Control the LP core
- MCPWM (Motor Control Pulse Width Modulator) peripheral
- Parallel IO
- Pulse Counter peripheral driver
- Exclusive peripheral access
- Peripheral Instances
- The prelude
- Hardware and Software Reset
- Remote Control Peripheral (RMT)
- Random Number Generator
- ESP ROM libraries
- RSA Accelerator support.
- RTC_CNTL (Real-Time Clock Control) and Low-power Management
- Secure Hash Algorithm peripheral driver
- Serial Peripheral Interface
- System Control
- System Timer peripheral driver
- General-purpose timers
- RISCV Trace Encoder (TRACE)
- State of the CPU saved when entering exception or interrupt
- Two-wire Automotive Interface (TWAI)
- Universal Asynchronous Receiver/Transmitter (UART)
- USB Serial/JTAG Controller
Macros§
- Convenience macro to create DMA buffers and descriptors
- Convenience macro to create circular DMA buffers and descriptors
- Convenience macro to create circular DMA descriptors
- Convenience macro to create DMA descriptors
Structs§
- Driver initialized in async mode.
- Driver initialized in blocking mode.
- FlashSafeDma
Enums§
- Available CPU cores
Traits§
- A marker trait for intializing drivers in a specific mode.
Functions§
- Which core the application is currently executing on
Attribute Macros§
- Attribute to declare the entry point of the program