rsiot::doc::dev_prepare

Module riscv32imc_esp_espidf

Source
Expand description

§riscv32imc-esp-espidf

§Подготовка среды разработки

toolchain

rustup toolchain install nightly-2024-02-01-x86_64-unknown-linux-gnu --component rust-src

TODO - обновить когда пофиксят

ESP-IDF

Зависимости для ESP-IDF https://docs.espressif.com/projects/esp-idf/en/latest/esp32/get-started/linux-macos-setup.html#for-linux-users:

sudo apt-get install git wget flex bison gperf python3 python3-pip python3-venv cmake ninja-build ccache libffi-dev libssl-dev dfu-util libusb-1.0-0

ldproxy

cargo install ldproxy

LLVM

sudo bash -c "$(wget -O - https://apt.llvm.org/llvm.sh)"

espflash

sudo usermod -a -G dialout $USER

sudo apt install libudev-dev

cargo install espflash

cargo generate

cargo install cargo-generate

§Создание проекта

cargo generate esp-rs/esp-idf-template cargo

.zed/settings.json

{
  "lsp": {
    "rust-analyzer": {
      "initialization_options": {
        "check": {
          "command": "clippy"
        },
        "cargo": {
          "target": "riscv32imc-esp-espidf"
        }
      }
    }
  }
}

.cargo/config.toml

[build]
target = "riscv32imc-esp-espidf"

[target.riscv32imc-esp-espidf]
linker = "ldproxy"
runner = "espflash flash --monitor"
rustflags = [
    "--cfg",
    "espidf_time64",
    "--cfg",
    "mio_unsupported_force_poll_poll", # https://github.com/tokio-rs/tokio/issues/5866
]

[unstable]
build-std = ["std", "panic_abort"]

[env]
MCU = "esp32c3"
# install all libraries globally, in folder ~/.espressif
ESP_IDF_TOOLS_INSTALL_DIR = "global"
# check current version on https://github.com/espressif/esp-idf/releases
ESP_IDF_VERSION = "v5.3.1"

build.rs

fn main() {
    embuild::espidf::sysenv::output();
}

rust-toolchain.toml

[toolchain]
# channel = "stable"
channel = "nightly"
# channel = "nightly-2024-10-01"
components = ["rust-src"]

sdkconfig.defaults

# Rust often needs a bit of an extra main task stack size compared to C (the default is 3K)
CONFIG_ESP_MAIN_TASK_STACK_SIZE=20000

# Use this to set FreeRTOS kernel tick frequency to 1000 Hz (100 Hz by default).
# This allows to use 1 ms granuality for thread sleeps (10 ms by default).
CONFIG_FREERTOS_HZ=1000

# Workaround for https://github.com/espressif/esp-idf/issues/7631
#CONFIG_MBEDTLS_CERTIFICATE_BUNDLE=n
#CONFIG_MBEDTLS_CERTIFICATE_BUNDLE_DEFAULT_FULL=n

CONFIG_HTTPD_WS_SUPPORT=y

# Настройка логгирования
CONFIG_LOG_DEFAULT_LEVEL_VERBOSE=y

CONFIG_MQTT_PROTOCOL_5=y
CONFIG_ESP_HTTPS_SERVER_ENABLE=y

# Вывод логов только в USB
CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG=y

Cargo.toml

[dependencies]
esp-idf-svc = { version = "*" }

[build-dependencies]
embuild = { version = "*", features = ["espidf"] }

main.rs

Первой строкой в функции main():

esp_idf_svc::sys::link_patches();