rust 嵌入式esp23 《hello word》

学习rust嵌入式之esp32单片机,从打印hello word开发。 rust 嵌入式 ESP23

搭建环境:

相关连接:docs.espressif.com/projects/ru...

安装rust www.rust-lang.org/zh-CN/tools... 验证是否安装成功:

shell 复制代码
cargo -V

安装espup

shell 复制代码
cargo install espup --locked

espup 安装相关依赖

shell 复制代码
espup install

安装ldproxy 相关配置

shell 复制代码
cargo install ldproxy

安装esp-generate项目生成工具:

shell 复制代码
cargo install esp-generate

运行项目:

构建项目代码 (your-project)自定义项目名称

js 复制代码
esp-generate --chip=esp32c6 your-project

项目结构

file 复制代码
├── build.rs
├── .cargo
│   └── config.toml
├── Cargo.toml
├── .gitignore
├── rust-toolchain.toml
├── src
│   ├── bin
│   │   └── main.rs
│   └── lib.rs
└── .vscode
    └── settings.json

修改src/bin/main.rs的代码

rs 复制代码
#![no_std]
#![no_main]
#![deny(
    clippy::mem_forget,
    reason = "mem::forget is generally not safe to do with esp_hal types, especially those \
    holding buffers for the duration of a data transfer."
)]

use esp_hal::{
    clock::CpuClock,
    main,
    time::{Duration, Instant},
};
use esp_println::println;

#[panic_handler]
fn panic(_: &core::panic::PanicInfo) -> ! {
    loop {
        println!("111 world!");
        println!("Panic!");
    }
}

// This creates a default app-descriptor required by the esp-idf bootloader.
// For more information see: <https://docs.espressif.com/projects/esp-idf/en/stable/esp32/api-reference/system/app_image_format.html#application-description>
esp_bootloader_esp_idf::esp_app_desc!();

#[main]
fn main() -> ! {
    // generator version: 0.5.0
    let config = esp_hal::Config::default().with_cpu_clock(CpuClock::max());
    let _peripherals = esp_hal::init(config);

    loop {
        println!("hello world!");
        let delay_start = Instant::now();
        while delay_start.elapsed() < Duration::from_millis(500) {}
    }

    // for inspiration have a look at the examples at https://github.com/esp-rs/esp-hal/tree/esp-hal-v1.0.0-rc.0/examples/src/bin
}

插入esp32设备连接电脑usb

运行项目

shell 复制代码
cargo run

结果成功

!如果未插入设备标识运行成功但是没有烧录

相关推荐
不悔哥1 天前
开源OV-Watch:怎么做一个智能手表
单片机·开源·嵌入式
优信电子2 天前
AIT1001 非接触式红外测温模块 STM32 驱动开发实战:从引脚到代码全解析
stm32·嵌入式·温度传感器·红外测温·非接触式测温·ait1001
youcans_2 天前
【嵌入式软件AI编程】16. Claude Code 与 VS Code 的协同开发
stm32·mcu·嵌入式·ai编程·claude code
阿钱真强道2 天前
06 嵌入式操作系统 | vim 与软件管理:apt / 源码编译
ubuntu·vim·嵌入式·apt·源码编译
G.E.M.小白2 天前
【IMX6ULL ARM内核启动与时钟系统超详解】PLL/PFD/分频/根时钟配置
嵌入式·arm·时钟·imx6ull
嵌入式阿蔡2 天前
嵌入式DevOps 2026:AI驱动工具链与CI/CD闭环
嵌入式
嵌入式阿蔡2 天前
嵌入式虚拟化2026:Hypervisor从数据中心走进MCU
嵌入式
嵌入式阿蔡3 天前
RISC-V工具链生态2026:从GCC命令到VS Code插件
嵌入式
金士顿3 天前
ASP.NET Core Native AOT + systemd 实战:把 Linux ARM64 程序变成可靠的设备服务
linux·嵌入式·asp.net core·arm64
金士顿3 天前
ASP.NET Core Native AOT 到底是什么?从 C#、IL、JIT 一直讲到 Linux ARM64 ELF
嵌入式·asp.net core