CI / Lint e auditorias (push) Successful in 1m10s
CI / Trivy (dependências e segredos) (push) Successful in 12s
CI / Imagem Docker (linux/arm64) (push) Successful in 2m39s
Release / Plano (reaproveitar a imagem?) (push) Successful in 6s
Release / ci (push) Skipped
Release / Publica a imagem (linux/arm64) (push) Successful in 18s
Release / Cria a release no Gitea (push) Successful in 5s
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
49 lines
1.3 KiB
Rust
49 lines
1.3 KiB
Rust
//! 使用 `esp-hal` 在 ESP32 上运行 Rust 的示例(裸机 / no_std 模式)
|
|
//! 闪烁 LED 并通过 UART 串口发送消息,同时提供内存安全保障。
|
|
//!
|
|
//! Cargo.toml:
|
|
//! esp-hal = { version = "0.22", features = ["esp32s3"] }
|
|
//! esp-println = { version = "0.12", features = ["esp32s3", "log"] }
|
|
|
|
#![no_std]
|
|
#![no_main]
|
|
|
|
use esp_backtrace as _;
|
|
use esp_hal::{
|
|
clock::ClockControl,
|
|
gpio::{Io, Level, Output},
|
|
peripherals::Peripherals,
|
|
system::SystemControl,
|
|
timer::timg::TimerGroup,
|
|
delay::Delay,
|
|
prelude::*,
|
|
};
|
|
use esp_println::println;
|
|
|
|
#[entry]
|
|
fn main() -> ! {
|
|
// 在编译期检查的前提下初始化 SoC 外设
|
|
let peripherals = Peripherals::take();
|
|
let system = SystemControl::new(peripherals.SYSTEM);
|
|
let clocks = ClockControl::boot_defaults(system.clock_control).freeze();
|
|
|
|
// 配置 I/O 引脚
|
|
let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
|
|
let mut led = Output::new(io.pins.gpio2, Level::Low);
|
|
|
|
let delay = Delay::new(&clocks);
|
|
|
|
println!("🦀 Rust bare-metal firmware initialized on ESP32!");
|
|
|
|
let mut counter: u32 = 0;
|
|
|
|
loop {
|
|
// 在保证互斥的前提下翻转 LED 状态
|
|
led.toggle();
|
|
counter += 1;
|
|
|
|
println!("Rust cycle #{}: LED is {:?}", counter, led.is_set_high());
|
|
delay.delay_millis(500);
|
|
}
|
|
}
|