feat: esp32 rust
This commit is contained in:
parent
d2e5bfc822
commit
ae24424cb5
|
@ -0,0 +1,32 @@
|
|||
# Setup
|
||||
|
||||
> [!NOTE]
|
||||
> Reference: https://docs.esp-rs.org/book/installation/riscv.html
|
||||
|
||||
|
||||
``` bash
|
||||
# For no_std(bare-metal)
|
||||
rustup toolchain install stable --component rust-src
|
||||
rustup target add riscv32imc-unknown-none-elf # For ESP32-C2 and ESP32-C3
|
||||
rustup target add riscv32imac-unknown-none-elf # For ESP32-C6 and ESP32-H2
|
||||
|
||||
# For std
|
||||
rustup toolchain install nightly --component rust-src
|
||||
cargo install ldproxy
|
||||
|
||||
cargo install cargo-generate
|
||||
cargo install espflash
|
||||
|
||||
# cargo generate esp-rs/esp-template
|
||||
cargo generate esp-rs/esp-idf-template cargo
|
||||
```
|
||||
|
||||
Run the `web` example to print `Hello, World`:
|
||||
|
||||
``` bash
|
||||
# Load ESP-IDF environment
|
||||
getidf
|
||||
cargo build
|
||||
cargo run
|
||||
```
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
[build]
|
||||
target = "riscv32imc-esp-espidf"
|
||||
|
||||
[target.riscv32imc-esp-espidf]
|
||||
linker = "ldproxy"
|
||||
runner = "espflash flash --monitor" # Select this runner for espflash v3.x.x
|
||||
rustflags = [ "--cfg", "espidf_time64"] # Extending time_t for ESP IDF 5: https://github.com/esp-rs/rust/issues/110
|
||||
|
||||
[unstable]
|
||||
build-std = ["std", "panic_abort"]
|
||||
|
||||
[env]
|
||||
MCU="esp32c3"
|
||||
# Note: this variable is not used by the pio builder (`cargo build --features pio`)
|
||||
ESP_IDF_VERSION = "v5.2.2"
|
||||
|
||||
# Workaround for https://github.com/esp-rs/esp-idf-template/issues/174
|
||||
CRATE_CC_NO_DEFAULTS = "1"
|
|
@ -0,0 +1,39 @@
|
|||
name: Continuous Integration
|
||||
|
||||
on:
|
||||
push:
|
||||
paths-ignore:
|
||||
- "**/README.md"
|
||||
pull_request:
|
||||
workflow_dispatch:
|
||||
|
||||
env:
|
||||
CARGO_TERM_COLOR: always
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
jobs:
|
||||
rust-checks:
|
||||
name: Rust Checks
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
action:
|
||||
- command: build
|
||||
args: --release
|
||||
- command: fmt
|
||||
args: --all -- --check --color always
|
||||
- command: clippy
|
||||
args: --all-targets --all-features --workspace -- -D warnings
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
- name: Setup Rust
|
||||
uses: dtolnay/rust-toolchain@v1
|
||||
with:
|
||||
toolchain: nightly
|
||||
components: rust-src
|
||||
- name: Enable caching
|
||||
uses: Swatinem/rust-cache@v2
|
||||
- name: Run command
|
||||
run: cargo ${{ matrix.action.command }} ${{ matrix.action.args }}
|
|
@ -0,0 +1,4 @@
|
|||
/.vscode
|
||||
/.embuild
|
||||
/target
|
||||
/Cargo.lock
|
|
@ -0,0 +1,35 @@
|
|||
[package]
|
||||
name = "web"
|
||||
version = "0.1.0"
|
||||
authors = ["anjingyu <anjingyu@navinfo.com>"]
|
||||
edition = "2021"
|
||||
resolver = "2"
|
||||
rust-version = "1.77"
|
||||
|
||||
[[bin]]
|
||||
name = "web"
|
||||
harness = false # do not use the built in cargo test harness -> resolve rust-analyzer errors
|
||||
|
||||
[profile.release]
|
||||
opt-level = "s"
|
||||
|
||||
[profile.dev]
|
||||
debug = true # Symbols are nice and they don't increase the size on Flash
|
||||
opt-level = "z"
|
||||
|
||||
[features]
|
||||
default = ["std", "embassy", "esp-idf-svc/native"]
|
||||
|
||||
pio = ["esp-idf-svc/pio"]
|
||||
std = ["alloc", "esp-idf-svc/binstart", "esp-idf-svc/std"]
|
||||
alloc = ["esp-idf-svc/alloc"]
|
||||
nightly = ["esp-idf-svc/nightly"]
|
||||
experimental = ["esp-idf-svc/experimental"]
|
||||
embassy = ["esp-idf-svc/embassy-sync", "esp-idf-svc/critical-section", "esp-idf-svc/embassy-time-driver"]
|
||||
|
||||
[dependencies]
|
||||
log = { version = "0.4", default-features = false }
|
||||
esp-idf-svc = { version = "0.49", default-features = false }
|
||||
|
||||
[build-dependencies]
|
||||
embuild = "0.32.0"
|
|
@ -0,0 +1,3 @@
|
|||
fn main() {
|
||||
embuild::espidf::sysenv::output();
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
[toolchain]
|
||||
channel = "nightly"
|
||||
components = ["rust-src"]
|
|
@ -0,0 +1,10 @@
|
|||
# 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=8000
|
||||
|
||||
# Use this to set FreeRTOS kernel tick frequency to 1000 Hz (100 Hz by default).
|
||||
# This allows to use 1 ms granularity 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
|
|
@ -0,0 +1,10 @@
|
|||
fn main() {
|
||||
// It is necessary to call this function once. Otherwise some patches to the runtime
|
||||
// implemented by esp-idf-sys might not link properly. See https://github.com/esp-rs/esp-idf-template/issues/71
|
||||
esp_idf_svc::sys::link_patches();
|
||||
|
||||
// Bind the log crate to the ESP Logging facilities
|
||||
esp_idf_svc::log::EspLogger::initialize_default();
|
||||
|
||||
log::info!("Hello, world!");
|
||||
}
|
Loading…
Reference in New Issue