esp-wifi-sys

repository·main·Indexed 19 days ago

https://github.com/esp-rs/esp-wifi-sys

Low-level bindings and binaries for Espressif wireless drivers, providing the foundation for wireless capabilities in the ESP-RS ecosystem. It includes FFI bindings for various chips such as ESP32, ESP32C2, ESP32C3, ESP32C61, and ESP32S3, and provides a `sys-logs` feature to route radio-level logging from C drivers to the Rust `info!` macro via the `__esp_radio_printf` function.

Tokens
1.2K
Snippets
5
Records
8
Agent score
63%

What's inside esp-wifi-sys

  1. Understand the purpose of esp-wifi-sys

    main

    The esp-wifi-sys repository provides low-level bindings and binaries for wireless drivers.

    Note: If you are looking for the high-level Rust wireless driver implementation, you should use esp-wifi located in the esp-hal repository instead.

  2. Fix linker errors by stripping .eh_frame segments

    main

    Depending on the lld version used by your toolchain, you may encounter linker errors regarding relocation to a symbol in a discarded section (e.g., .L0) when using the provided libraries.

    To resolve this, you must strip the .eh_frame segment from the affected binaries using objcopy. Replace the path below with the actual path to your library file.

    riscv32-esp-elf-objcopy --remove-section=.eh_frame <path_to_library>.a
  3. Configure radio logging via sys-logs feature

    main

    The esp-wifi-sys crate provides a mechanism for the underlying C wireless drivers to output logs to the Rust environment. This is controlled by the sys-logs feature flag.

    • When sys-logs is enabled: The crate implements __esp_radio_printf, which captures C-level log calls and routes them through the Rust info! macro. This allows you to see wireless driver logs in your Rust application's logging output.
    • When sys-logs is disabled: __esp_radio_printf is implemented as a no-op, preventing any overhead from logging calls made by the driver.
    # Example Cargo.toml configuration to enable radio logging
    [dependencies]
    esp-wifi-sys-esp32c61 = {
        version = "0.8.1",
        features = ["sys-logs"]
    }
  4. Use the `sys-logs` feature for radio logging

    main

    The esp-wifi-sys-esp32c3 crate provides a hook for radio-level logging via the __esp_radio_printf function.

    • If the sys-logs feature is enabled, __esp_radio_printf is implemented to route logs through the system's info! macro, allowing you to see radio driver messages in your application logs.
    • If the sys-logs feature is disabled, __esp_radio_printf is a no-op stub.
  5. Configure logging via the sys-logs feature

    main

    The esp-wifi-sys-esp32s3 crate provides a hook for wireless driver logging through the __esp_radio_printf function.

    • If the sys-logs feature is enabled, __esp_radio_printf is implemented to route driver logs to the system's info! macro.
    • If the sys-logs feature is disabled, __esp_radio_printf is a no-op, effectively silencing driver logs.

    This allows developers to control whether low-level wireless driver messages are visible in their application logs by toggling the feature flag in their Cargo.toml.

    # To enable driver logging
    [dependencies]
    esp-wifi-sys-esp32s3 = { version = "0.8.1", features = ["sys-logs"] }
  6. Access ESP32C2 wireless driver bindings via include module

    main

    The esp-wifi-sys-esp32c2 crate provides low-level FFI bindings for the ESP32C2 wireless drivers. The primary interface for accessing the underlying C functions and types is through the include module. This module contains the bindgen-generated bindings that map directly to the ESP-IDF/ESP-Wi-Fi C headers.

    // Accessing the generated bindings
    use esp_wifi_sys_esp32c2::include::*;
  7. Use the __esp_radio_printf FFI function for logging

    main

    The __esp_radio_printf function is an exported C-compatible function used to bridge radio-level logging from the underlying C drivers to the Rust environment.

    • If the sys-logs feature is enabled, this function routes logs to the info! macro.
    • If the sys-logs feature is disabled, the function is a no-op.

    This function is typically called by the underlying C wireless drivers to output tagged messages.

    // Note: This is an extern "C" function intended to be called by the C driver.
    // It is not typically called directly by the Rust user, but its behavior 
    // depends on the 'sys-logs' feature.
    extern "C" {
        fn __esp_radio_printf(tag: *const core::ffi::c_char, msg: *const core::ffi::c_char);
    }