esp-hal 1.2.0

Bare-metal HAL for Espressif devices
Documentation
[package]
name          = "esp-hal"
version       = "1.2.0"
edition       = "2024"
rust-version  = "1.95.0"
description   = "Bare-metal HAL for Espressif devices"
documentation = "https://docs.espressif.com/projects/rust/esp-hal/latest/"
keywords      = ["embedded", "embedded-hal", "esp32", "espressif", "hal"]
categories    = ["embedded", "hardware-support", "no-std"]
repository    = "https://github.com/esp-rs/esp-hal"
license       = "MIT OR Apache-2.0"
exclude = [ "api-baseline", "MIGRATING-*", "CHANGELOG.md" ]

[package.metadata.espressif]
semver-checked = true
chip-features-matter = true
doc-config = { features = ["unstable", "rt"], append = [
    { if = 'usb_otg_driver_supported', features = ["__usb_otg"] },
    { if = 'bt_driver_supported', features = ["__bluetooth"] },
    { if = 'sdmmc_driver_supported', features = ["__sdmmc"] },
] }
check-configs = [
    { features = [] },
    { features = ["rt"] },
    { features = ["unstable", "rt"] },
    { features = ["unstable", "rt"], env = { ESP_HAL_CONFIG_PLACE_ANON_IN_RAM = "true", ESP_HAL_CONFIG_PLACE_RMT_DRIVER_IN_RAM = "true", ESP_HAL_CONFIG_PLACE_SPI_MASTER_DRIVER_IN_RAM = "true", ESP_HAL_CONFIG_CLEAR_CRYPTO_SECRETS = "false" } },
    { features = ["unstable", "rt"], env = { ESP_HAL_CONFIG_ENABLE_PMP = "false" }, if = 'riscv && !esp32c2 && !esp32c3' },
    { features = ["unstable", "rt"], env = { ESP_HAL_CONFIG_INIT_STACK_PTR_RANGE_CHECK = "false" } },
    { features = ["unstable", "rt"], env = { ESP_HAL_CONFIG_USE_XTAL32K = "true" }, if = 'soc_has_clock_node_xtal32k_clk' },
    { features = ["unstable", "rt", "__usb_otg"],   if = 'usb_otg_driver_supported' },
    { features = ["unstable", "rt", "__bluetooth"], if = 'bt_driver_supported' },
    { features = ["unstable", "rt", "__sdmmc"],     if = 'sdmmc_driver_supported' },
]
# Prefer fewer, but more complex clippy rules. A clippy run should cover as much code as possible.
clippy-configs = [
    { features = ["unstable", "rt"], append = [
        { if = 'usb_otg_driver_supported', features = ["__usb_otg"] },
        { if = 'bt_driver_supported', features = ["__bluetooth"] },
        { if = 'sdmmc_driver_supported', features = ["__sdmmc"] },
    ] },
]

[package.metadata.docs.rs]
default-target = "riscv32imac-unknown-none-elf"
features       = ["esp32c6", "unstable"]
rustdoc-args   = ["--cfg", "docsrs"]

[lib]
bench = false
test  = false

[dependencies]
bytemuck                 = "1.24"
critical-section         = { version = "1", features = ["restore-state-u32"], optional = true }
embedded-hal             = "1.0.0"
embedded-hal-async       = "1.0.0"
enumset                  = "1.1"
paste                    = "1.0.15"
portable-atomic          = { version = "1.11", default-features = false }
static_cell              = "2"

esp-rom-sys              = { version = "~0.1", path = "../esp-rom-sys" }

# Unstable dependencies that are not (strictly) part of the public API
bitfield                 = "0.19"
delegate                 = "0.13"
document-features        = "0.2"
embassy-futures          = "0.1"
embassy-sync             = "0.8"
fugit                    = "0.5.0"
instability              = "0.3.12"
strum                    = { version = "0.27.1", default-features = false, features = ["derive"] }

esp-config               = { version = "0.8.0", path = "../esp-config" }
esp-metadata-generated   = { version = "0.5.1", path = "../esp-metadata-generated" }
esp-sync                 = { version = "0.3.0", path = "../esp-sync" }
procmacros               = { version = "0.23.0", package = "esp-hal-procmacros", path = "../esp-hal-procmacros" }

# Dependencies that are optional because they are used by unstable drivers.
# They are needed when using the `unstable` feature.
digest-010               = { package = "digest", version = "0.10.7", default-features = false, features = ["core-api"],  optional = true }
digest-011               = { package = "digest", version = "0.11",   default-features = false, features = ["block-api"], optional = true }
embassy-usb-driver       = { version = "0.2", optional = true }
embassy-usb-synopsys-otg = { version = "0.4.0", optional = true, features = ["host"] }
embassy-net-driver-02    = { package = "embassy-net-driver", version = "0.2", optional = true }
embedded-can             = { version = "0.4.1", optional = true }
nb                       = { version = "1.1", optional = true }
sdio                     = { version = "0.5", optional = true }

# Logging interfaces, they are mutually exclusive so they need to be behind separate features.
defmt                    = { version = "1.1", optional = true }
log-04                   = { package = "log", version = "0.4", optional = true }

# ESP32-only fallback SHA algorithms
sha1                     = { version = "0.11", default-features = false, optional = true }
sha2                     = { version = "0.11", default-features = false, optional = true }

# Optional dependencies that enable ecosystem support.
# We could support individually enabling them, but there is no big downside to just
# enabling them all via the `unstable` feature.
embassy-embedded-hal     = { version = "0.6", optional = true }
embedded-io-06           = { package = "embedded-io", version = "0.6", optional = true }
embedded-io-async-06     = { package = "embedded-io-async", version = "0.6", optional = true }
embedded-io-07           = { package = "embedded-io", version = "0.7", optional = true }
embedded-io-async-07     = { package = "embedded-io-async", version = "0.7", optional = true }
rand_core-06             = { package = "rand_core", version = "0.6", optional = true }
rand_core-09             = { package = "rand_core", version = "0.9", optional = true }
rand_core-010            = { package = "rand_core", version = "0.10", optional = true }
ufmt-write               = { version = "0.1", optional = true }

# IMPORTANT:
# Each supported device MUST have its PAC included below along with a
# corresponding feature.
esp32   = { version = "0.41", features = ["critical-section"], optional = true }
esp32c2 = { version = "0.30", features = ["critical-section"], optional = true }
esp32c3 = { version = "0.33", features = ["critical-section"], optional = true }
esp32c5 = { version = "0.3",  features = ["critical-section"], optional = true }
esp32c6 = { version = "0.24", features = ["critical-section"], optional = true }
esp32c61 = { version = "0.4", features = ["critical-section"], optional = true }
esp32h2 = { version = "0.20", features = ["critical-section"], optional = true }
esp32s2 = { version = "0.32", features = ["critical-section"], optional = true }
esp32s3 = { version = "0.36", features = ["critical-section"], optional = true }
esp32s31 = { version = "0.2", features = ["critical-section"], optional = true }
esp32p4 = { version = "0.3",  features = ["critical-section"], optional = true }

[target.'cfg(target_arch = "riscv32")'.dependencies]
riscv            = { version = "0.15.0" }
esp-riscv-rt     = { version = "0.15.0", path = "../esp-riscv-rt", optional = true }

[target.'cfg(target_arch = "xtensa")'.dependencies]
xtensa-lx        = { version = "0.13.0", path = "../xtensa-lx" }
xtensa-lx-rt     = { version = "0.23.0", path = "../xtensa-lx-rt", optional = true }

[build-dependencies]
esp-metadata-generated = { version = "0.5.1", path = "../esp-metadata-generated", features = ["build-script"] }
esp-config   = { version = "0.8.0", path = "../esp-config", features = ["build"] }
somni-template = "0.3.1"

[dev-dependencies]
crypto-bigint = { version = "0.7.5", default-features = false }
jiff = { version = "0.2", default-features = false, features = ["static"] }

[features]
default = ["rt", "exception-handler", "float-save-restore"]

# These features are considered private and unstable. They are not covered by
# semver guarantees and may change or be removed without notice.
__bluetooth = []
__sdmmc = ["dep:sdio"]
__usb_otg = [
    "dep:embassy-usb-driver",
    "dep:embassy-usb-synopsys-otg",
]

#! ### Runtime support
#! These features are meant to be enabled by firmware projects. If you are writing a library that
#! depends on `esp-hal`, you should *not* enable these features under any circumstance.

## Enable code necessary to run the firmware.
rt = [
    "dep:xtensa-lx-rt",
    "dep:esp-riscv-rt",
    "esp32?/rt",
    "esp32c2?/rt",
    "esp32c3?/rt",
    "esp32c5?/rt",
    "esp32c6?/rt",
    "esp32c61?/rt",
    "esp32p4?/rt",
    "esp32h2?/rt",
    "esp32s2?/rt",
    "esp32s3?/rt",
    "esp32s31?/rt",
    "critical-section",
]

## Enable a simple exception handler turning exceptions into panics.
exception-handler = []

## Save and restore the floating point co-processor context.
##
## This feature enables the floating-point coprocessor in interrupt contexts, and adds code to save and restore the relevant registers.
##
## <section class="warning">
## If you intend to do floating-point calculations in multiple contexts, or in interrupt/exception handlers, you will need to enable this feature.
## </section>
##
## Note that this feature is only effective on ESP32 and ESP32-S3. Other chips don't have a hardware floating-point coprocessor.
##
## ⚠️ This feature is considered unstable.
float-save-restore = ["xtensa-lx-rt/float-save-restore"]

#! ### Chip selection
#! One of the following features must be enabled to select the target chip:

##
esp32   = [
    "dep:esp32",
    "__sdmmc",
    "procmacros/rtc-slow",
    "procmacros/rtc-fast",
    "esp-rom-sys/esp32",
    "esp-sync/esp32",
    "esp-metadata-generated/esp32",
    "dep:sha1",
    "dep:sha2",
    "dep:embassy-net-driver-02",
]
##
esp32c2 = [
    "dep:esp32c2",
    "esp-riscv-rt/no-mie-mip",
    "portable-atomic/unsafe-assume-single-core",
    "esp-rom-sys/esp32c2",
    "esp-sync/esp32c2",
    "esp-metadata-generated/esp32c2",
]
##
esp32c3 = [
    "dep:esp32c3",
    "esp-riscv-rt/no-mie-mip",
    "esp-riscv-rt/rtc-ram",
    "procmacros/rtc-fast",
    "portable-atomic/unsafe-assume-single-core",
    "esp-rom-sys/esp32c3",
    "esp-sync/esp32c3",
    "esp-metadata-generated/esp32c3",
]
##
esp32c5 = [
    "dep:esp32c5",
    "esp-riscv-rt/rtc-ram",
    "esp-riscv-rt/clic-48",
    "procmacros/rtc-fast",
    "procmacros/has-lp-core",
    "esp-rom-sys/esp32c5",
    "esp-sync/esp32c5",
    "esp-metadata-generated/esp32c5",
]
##
esp32c6 = [
    "dep:esp32c6",
    "esp-riscv-rt/rtc-ram",
    "procmacros/rtc-fast",
    "procmacros/has-lp-core",
    "esp-rom-sys/esp32c6",
    "esp-sync/esp32c6",
    "esp-metadata-generated/esp32c6",
]
## ESP32-P4 (chip revision >= v3.x)
esp32p4 = [
    "dep:esp32p4",
    "__sdmmc",
    "__usb_otg",
    "esp-riscv-rt/rtc-ram",
    "esp-riscv-rt/clic-48",
    "procmacros/rtc-fast",
    "procmacros/has-lp-core",
    "esp-rom-sys/esp32p4",
    "esp-sync/esp32p4",
    "esp-metadata-generated/esp32p4",
    "dep:embassy-net-driver-02",
]
##
esp32c61 = [
    "dep:esp32c61",
    "esp-riscv-rt/clic-48",
    "procmacros/has-lp-core",
    "esp-rom-sys/esp32c61",
    "esp-sync/esp32c61",
    "esp-metadata-generated/esp32c61",
]
##
esp32h2 = [
    "dep:esp32h2",
    "esp-riscv-rt/rtc-ram",
    "procmacros/rtc-fast",
    "esp-rom-sys/esp32h2",
    "esp-sync/esp32h2",
    "esp-metadata-generated/esp32h2",
]
##
esp32s2 = [
    "dep:esp32s2",
    "portable-atomic/unsafe-assume-single-core",
    "procmacros/has-ulp-core",
    "procmacros/rtc-slow",
    "procmacros/rtc-fast",
    "__usb_otg",
    "esp-rom-sys/esp32s2",
    "esp-sync/esp32s2",
    "esp-metadata-generated/esp32s2",
]
##
esp32s3 = [
    "dep:esp32s3",
    "__sdmmc",
    "procmacros/has-ulp-core",
    "procmacros/rtc-slow",
    "procmacros/rtc-fast",
    "procmacros/dcache-reclaimed",
    "__usb_otg",
    "esp-rom-sys/esp32s3",
    "esp-sync/esp32s3",
    "esp-metadata-generated/esp32s3",
]
##
esp32s31 = [
    "__sdmmc",
    "dep:esp32s31",
    "esp-riscv-rt/rtc-ram",
    "esp-riscv-rt/clic-48",
    "procmacros/rtc-fast",
    "__usb_otg",
    "esp-rom-sys/esp32s31",
    "esp-sync/esp32s31",
    "esp-metadata-generated/esp32s31",
]
#! ### Logging Feature Flags
## Enable logging output using version 0.4 of the `log` crate.
log-04 = ["dep:log-04"]

## Enable logging output using `defmt` and implement `defmt::Format` on certain types.
defmt = [
    "dep:defmt",
    "embassy-futures/defmt",
    "embassy-sync/defmt",
    "embedded-io-06?/defmt-03",
    "embedded-io-async-06?/defmt-03",
    "embedded-io-07?/defmt",
    "embedded-io-async-07?/defmt",
    "enumset/defmt",
    "esp32?/defmt",
    "esp32c2?/defmt",
    "esp32c3?/defmt",
    "esp32c5?/defmt",
    "esp32c6?/defmt",
    "esp32c61?/defmt",
    "esp32h2?/defmt",
    "esp32s2?/defmt",
    "esp32s3?/defmt",
    "fugit/defmt",
    "esp-riscv-rt?/defmt",
    "xtensa-lx-rt?/defmt",
    "esp-sync/defmt"
]

#! ### 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 APIs are not covered by semver guarantees.

## Enables APIs that are not stable and thus come with no stability guarantees.
## Never enable this feature in a library crate using esp-hal.
unstable = [
    "dep:digest-010",
    "dep:digest-011",
    "dep:embassy-embedded-hal",
    "dep:embedded-can",
    "dep:embedded-io-06",
    "dep:embedded-io-async-06",
    "dep:embedded-io-07",
    "dep:embedded-io-async-07",
    "dep:rand_core-06",
    "dep:rand_core-09",
    "dep:rand_core-010",
    "dep:nb",
    "dep:ufmt-write",
]

## Libraries that depend on `esp-hal` should enable this feature to indicate their use of unstable APIs.
## However, they must **not** enable the `unstable` feature themselves.
##
## For development you can enable the `unstable` and the chip feature by adding esp-hal as a dev-dependency.
requires-unstable = []

[lints.clippy]
mixed_attributes_style = "allow"

[lints.rust]
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(host_os, values("windows"))'] }