Rust ESP32C3开发
Rust ESP32C3开发
系统开发逐步使用Rust语言,在嵌入式领域Rust也逐步完善,本着学习Rust和ESP32的目的,搭建了ESP32C3的环境,过程中遇到了不少问题,予以记录。
ESP-IDF开发ESP32
这一部分可跳过,是使用C开发ESP32。直接看Rust 与 ESP32C3
先使用ESP-IDF环境,跑一个Hello world
ESP-IDF安装,选择v5.1
克隆项目
git clone https://github.com/espressif/esp-idf.git
在get-started/hello-world
工程中,可以编译项目,编译前连接开发板,可以在设备管理里看到comx
,这里为com3
使用IDF-CMD命令行,进入hello-world
目录,设置目标
idf.py set-target esp32c3
打开配置界面,
idf.py menuconfig
hello-world项目不进行配置,编译
idf.py build
烧录
idf.py -p PORT flash
idf.py -p COM3 flash
烧录成功
Compressed 168688 bytes to 89398...
Writing at 0x00010000... (16 %)
Writing at 0x0001a548... (33 %)
Writing at 0x00020e66... (50 %)
Writing at 0x00028352... (66 %)
Writing at 0x0002ecae... (83 %)
Writing at 0x00035da9... (100 %)
Wrote 168688 bytes (89398 compressed) at 0x00010000 in 3.1 seconds (effective 441.4 kbit/s)...
Hash of data verified.
Compressed 3072 bytes to 103...
Writing at 0x00008000... (100 %)
Wrote 3072 bytes (103 compressed) at 0x00008000 in 0.1 seconds (effective 438.8 kbit/s)...
Hash of data verified.Leaving...
Hard resetting via RTS pin...
Done
监视输出
idf.py -p com3 monitor
Rust 与ESP32C3
参考资料
https://esp-rs.github.io/book/introduction.html
https://esp-rs.github.io/std-training/01_intro.html
https://doc.rust-lang.org/nightly/rustc/platform-support/esp-idf.html
https://esp-rs.github.io/book/overview/index.html
Rust工具链
安装
rustup toolchain install nightly-2023-02-28 --component rust-src
espressif 工具链
包含:
- cargo-espflash
- espflash
- ldproxy
安装
cargo install cargo-espflash espflash ldproxy
克隆仓库
克隆代码,并进入
git clone "https://github.com/esp-rs/std-training.git"
cd std-training
hello,board
连接开发板,
进入hardware-check
目录
cd intro/hardware-check
配置你的wifi名称与密码,cfg.toml
[hardware-check]
wifi_ssid = "111111"
wifi_psk = "123451111"
编译
cargo build
报错
error: failed to run custom build command for `esp-idf-sys v0.33.0`
CMake Error at C:/Users/Rao/.espressif/esp-idf/v4.4.4/tools/cmake/component.cmake:300 (message):Include directory'C:/Users/Rao/.espressif/esp-idf/v4.4.4/components/mbedtls/mbedtls/include'is not a directory.Call Stack (most recent call first):C:/Users/Rao/.espressif/esp-idf/v4.4.4/tools/cmake/component.cmake:473 (__component_add_include_dirs)C:/Users/Rao/.espressif/esp-idf/v4.4.4/components/mbedtls/CMakeLists.txt:18 (idf_component_register)
原因是
'C:/Users/Rao/.espressif/esp-idf/v4.4.4/components/mbedtls/mbedtls/include'is not a directory.
说明这个目录位于mbedtls的submodule中, 可能没有被checkout出来
解决方法,进入C:/Users/Rao/.espressif/esp-idf/v4.4.4/components/mbedtls/
git submodule update --init --recursive
cargo run
报错
D:/Workspace/Program/ESP32/std-training/intro/hardware-check/target/riscv32imc-esp-espidf/debug/build/esp-idf-sys-281d3f81b0a0f0ca/out/build/esp-idf/mbedtls/mbedtls/library/CMakeFiles/mbedcrypto.dir/./has 201 characters. The maximum full path to an object file is 250characters (see CMAKE_OBJECT_PATH_MAX). Object filed5fa956509b7db88e8eaa02d1680138d/esp_rsa_sign_alt.c.objcannot be safely placed under this directory. The build may not workcorrectly.
目录太长了,回到std-training
目录,将项目映射到r:
subst r: std-trainingcd r:
进入hardware-check
重新编译
cd intor/hardware-checkcargo run
成功
I (9229) wifi:set rx beacon pti, rx_bcn_pti: 0, bcn_timeout: 0, mt_pti: 25000, mt_time: 10000
I (9239) wifi: Waiting for DHCP lease...
I (9249) wifi:<ba-add>idx:0 (ifx:0, 62:1e:12:f4:12:61), tid:0, ssn:0, winSize:64
I (9319) wifi:AP's beacon interval = 102400 us, DTIM period = 2
I (10239) esp_netif_handlers: sta ip: 192.168.83.104, mask: 255.255.255.0, gw: 192.168.83.127
I (10239) wifi: Wifi DHCP info: IpInfo { ip: 192.168.83.104, subnet: Subnet { gateway: 192.168.83.127, mask: Mask(24) }, dns: Some(192.168.83.127), secondary_dns: Some(0.0.0.0) }
I (11249) hardware_check: Hello, world!
I (13249) hardware_check: Hello, world!
查看板子运行状态
espflash monitor
创建新项目
为了避免长路径问题,将一个空间映射为短路径
subst z: esp32
cd z:
由cargo-generate
配置新项目
安装
cargo install cargo-generate
生成
PS z:\> cargo generate https://github.com/esp-rs/esp-idf-template cargo
⚠️ Favorite `https://github.com/esp-rs/esp-idf-template` not found in config, using it as a git repository: https://github.com/esp-rs/esp-idf-template
🤷 Project Name: hello_world
⚠️ Renaming project called `hello_world` to `hello-world`...
🔧 Destination: z:\hello-world ...
🔧 project-name: hello-world ...
🔧 Generating template ...
✔ 🤷 Which MCU to target? · esp32c3
✔ 🤷 Configure advanced template options? · false
🔧 Moving generated files into: `z:\hello-world`...
Initializing a fresh Git repository
✨ Done! New project created z:\hello-world
用vscode打开项目
code .
加一个死循环
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/71esp_idf_sys::link_patches();// Bind the log crate to the ESP Logging facilitiesesp_idf_svc::log::EspLogger::initialize_default();info!("Hello, world!");loop {info!("loop ...!");std::thread::sleep(std::time::Duration::from_secs(1))}
}
编译
cargo run
一般时间会很长
运行起来
I (356) cpu_start: Starting scheduler.
I (362) hello_world: Hello, world!
I (362) hello_world: loop ...!
I (1362) hello_world: loop ...!
I (2362) hello_world: loop ...!
I (3362) hello_world: loop ...!
http客户端
进入espressif-trainnings/intro
中的http-client
项目,
修改wifi配置,
编译
cargo run --example http_client
完全可以自己写一个服务器,提供http服务,例如go
package mainimport "github.com/gin-gonic/gin"func main() {engine := gin.Default()engine.GET("/", func(context *gin.Context) {context.JSON(200, gin.H{"message": "Hello World",})})engine.Run("")
}
该服务端提供了get
请求,默认根目录,响应json
数据。
在http-client/examples/http_client.rs
中,
get("http://192.168.83.79/")?;
注意需要在一个局域网内,并且知道主机的ip地址。
运行
cargo run --example http_client
http服务器
提供get
服务
编写wifi配置
cd .\http-server\cargo run --example http_server
我的开发板获取温度有一些异常,注释掉获取温度的代码。
http://192.168.83.104/temperature
MQTT
搭建mqtt服务器,
wsl + ubuntu+docker
https://www.emqx.io/docs/zh/v5.1/deploy/install-docker.html
拉取镜像
docker pull emqx/emqx:5.1.0
启动容器
docker run -d --name emqx -p 1883:1883 -p 8083:8083 -p 8084:8084 -p 8883:8883 -p 18083:18083 emqx/emqx:5.1.0
http://wsl-ubuntu 地址 :18083/
默认用户名及密码
admin
public
通过MQTTfx测试mqtt服务器是否正常,
https://softblade.de/en/download-2/
创建连接
发送消息,需要往某个主题发送
所有订阅了hello
主题的客户端,都能收到消息。
cargo run --example solution_publ_rcv
后续局域网还有点问题,后面再做,
ssd1306
https://juejin.cn/post/7096077841023893511
初始化一个项目
cargo generate --git https://github.com/esp-rs/esp-idf-template cargo
PS R:\> cargo generate --git https://github.com/esp-rs/esp-idf-template cargoProject Name: ssd1306_esp32c3Renaming project called `ssd1306_esp32c3` to `ssd1306-esp32c3`...Destination: R:\ssd1306-esp32c3 ...project-name: ssd1306-esp32c3 ...Generating template ...
✔ Which MCU to target? · esp32c3
✔ Configure advanced template options? · falseMoving generated files into: `R:\ssd1306-esp32c3`...
Initializing a fresh Git repositoryDone! New project created R:\ssd1306-esp32c3
初始化外设
use esp_idf_sys as _; // If using the `binstart` feature of `esp-idf-sys`, always keep this module imported
use log::*;
use esp_idf_hal::{delay::FreeRtos,i2c::{I2cConfig, I2cDriver},peripherals::Peripherals,prelude::*,
};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/71esp_idf_sys::link_patches();// Bind the log crate to the ESP Logging facilitiesesp_idf_svc::log::EspLogger::initialize_default();let peripherals = Peripherals::take().unwrap();let sda = peripherals.pins.gpio10;let scl = peripherals.pins.gpio8;let config = I2cConfig::new().baudrate(400.kHz().into());let i2c = I2cDriver::new(peripherals.i2c0, sda, scl, &config).unwrap();info!("Hello, world!");
}
还不太行,留坑
esp_idf_sys::link_patches();
// Bind the log crate to the ESP Logging facilities
esp_idf_svc::log::EspLogger::initialize_default();
let peripherals = Peripherals::take().unwrap();let sda = peripherals.pins.gpio10;
let scl = peripherals.pins.gpio8;let config = I2cConfig::new().baudrate(400.kHz().into());
let i2c = I2cDriver::new(peripherals.i2c0, sda, scl, &config).unwrap();info!("Hello, world!");
}
还不太行,留坑
相关文章:

Rust ESP32C3开发
Rust ESP32C3开发 系统开发逐步使用Rust语言,在嵌入式领域Rust也逐步完善,本着学习Rust和ESP32的目的,搭建了ESP32C3的环境,过程中遇到了不少问题,予以记录。 ESP-IDF开发ESP32 这一部分可跳过,是使用C开…...

【Spring Cloud Gateway 新一代网关】—— 每天一点小知识
💧 S p r i n g C l o u d G a t e w a y 新一代网关 \color{#FF1493}{Spring Cloud Gateway 新一代网关} SpringCloudGateway新一代网关💧 🌷 仰望天空,妳我亦是行人.✨ 🦄 个人主页——微风撞见云的博客&a…...
Java 中的关键字 final 和 static
一、关键字 final final 修饰符可以用来修饰类、方法和变量,final 修饰的类不能够被继承,修饰的方法不能被继承类重新定义,修饰的变量为常量,是不可修改的。 1.1 final 变量 final 有"最后的、最终的"的含义…...
Spring Cloud OpenFeign 全教程
1. 声明式 REST 客户端: Feign Feign 是一个声明式的 Web Service 客户端。它使编写 Web Service 客户端更容易。要使用 Feign,需要创建一个接口并对其进行注解。它有可插拔的注解支持,包括 Feign 注解和 JAX-RS 注解。Feign 还支持可插拔的…...

LLaMA模型论文《LLaMA: Open and Efficient Foundation Language Models》阅读笔记
文章目录 1. 简介2.方法2.1 预训练数据2.2 网络架构2.3 优化器2.4 高效的实现 3.论文其余部分4. 参考资料 1. 简介 LLaMA是meta在2023年2月开源的大模型,在这之后,很多开源模型都是基于LLaMA的,比如斯坦福大学的羊驼模型。 LLaMA的重点是比…...

了解Unity编辑器 之组件篇Effects(十一)
一、Halo:是一个可用于游戏对象的特效组件,它可以在对象周围添加一个光晕效果 Color属性: 用于设置Halo的颜色。你可以通过选择颜色面板中的颜色来指定光晕的外观。选择适当的颜色可以使光晕与游戏场景中的其他元素相匹配或突出显示。 Size属性: 用于设…...
笔记整理-SpringBoot中的扩展点
SpringBoot有哪些扩展点 aware 感知类接口 aware系列的扩展接口,允许spring应用感知/获取特定的上下文环境或对象。bean生命周期控制类接口 bean生命周期类的接口,可以控制spring容器对bean的处理。app生命周期控制类接口 app生命周期控制类接口…...
各系统的目录信息路径
Windows系统: 查看系统版本——C:\boot.ini IIS配置文件——C:\windows\system32\inetsrv\MetaBase.xml 存储Windows系统初次安装的密码——C:\windows\repair\sam Mysql配置——C:\ProgramFiles\mysql\my.ini MySQL root密码——C:\P…...
Asp.Net 使用Log4Net (封装帮助类)
Asp.Net 使用Log4Net (封装帮助类) 1. 创建Log4Net帮助类 首先,在你的项目中创建一个Log4Net帮助类,用于封装Log4Net的配置和日志记录逻辑。 using log4net; using log4net.Config;public class LogHelper {private static readonly ILog log LogMan…...

全志F1C200S嵌入式驱动开发(lcd屏幕驱动)
【 声明:版权所有,欢迎转载,请勿用于商业用途。 联系信箱:feixiaoxing @163.com】 lcd RGB屏幕作为比较经济、实用的显示工具,在实际场景中使用较多。它的信号来说,一般也比较简单,除了常规的数据信号,剩下来就是行同步、场同步、数据使能和时钟信号了。数据信…...

dubbo原理框架设计
dubbo原理框架设计 (1)config 配置层:对外配置接口,以 ServiceConfig, ReferenceConfig 为中心,可以直接初始化配置类,也可以通过 spring 解析配置生成配置类。 (2)proxy 服务代理…...

【数据挖掘】使用 LSTM 进行时间和序列预测
一、说明 每天,人类在执行诸如过马路之类的任务时都会做出被动预测,他们估计汽车的速度和与汽车的距离,或者通过猜测球的速度并相应地定位手来接球。这些技能是通过经验和实践获得的。然而,由于涉及众多变量,预测天气或…...
Typescript第四章 函数(声明和调用,注解参数类型,多态,类型别名,泛型)
第四章 函数 ts中声明和调用函数的不同方式签名重载多态函数多态类型声明 4.1 声明和调用函数 在js中函数是一等对象,我们可以像对象那样使用函数,可以复制给变量,可以作为参数传递,返回值,赋值给对象的原型&#x…...

大数据-Spark批处理实用广播Broadcast构建一个全局缓存Cache
1、broadcast广播 在Spark中,broadcast是一种优化技术,它可以将一个只读变量缓存到每个节点上,以便在执行任务时使用。这样可以避免在每个任务中重复传输数据。 2、构建缓存 import org.apache.spark.sql.SparkSession import org.apache.s…...
Android Service的生命周期,两种启动方法,有什么区别
Android Service的生命周期,两种启动方法,有什么区别 Android Service是一种后台组件,用于在后台执行长时间运行的任务,而无需与用户界面进行交互。Service具有自己的生命周期,其主要包含以下几个状态:创建…...

测试开源C#人脸识别模块ViewFaceCore(5:质量检测和眼睛状态检测)
ViewFaceCore模块中的FaceQuality支持预测人脸质量,最初以为是预测人体体重,实际测试过程中才发现是评估人脸图片质量,主要调用Detect函数执行图片质量检测操作,其函数原型如下所示: //// 摘要:// 人脸质量评估///…...
Go语言网络库net/http
Go语言网络库net/http Http 协议(Hyper Text Transfer Protocol,超文本传输协议)是一个简单的请求-响应协议,它通常运行在 TCP 之 上。超文本传输协议是互联网上应用最为广泛的一种网络传输协议,所有的WWW文件都必须遵守这个标准。 Http 协…...

Acwing.91 最短Hamilton路径(动态规划)
题目 给定一张n个点的带权无向图,点从0~n-1标号,求起点0到终点n-1的最短Hamilton路径。Hamilton路径的定义是从0到n-1不重不漏地经过每个点恰好一次。 输入格式 第—行输入整数n。 接下来n行每行n个整数,其中第i行第j个整数表示点i到j的距…...
[hfut] [important] v4l2 vedio使用总结/opevx/ffpeg/v4l2/opencv/cuda
(158条消息) linux驱动camera//test ok_感知算法工程师的博客-CSDN博客 (158条消息) linux V4L2子系统——v4l2架构(1)之整体架构_感知算法工程师的博客-CSDN博客 (158条消息) linux V4L2子系统——v4l2的结构体(2)之video_devi…...

2023年深圳杯数学建模A题影响城市居民身体健康的因素分析
2023年深圳杯数学建模 A题 影响城市居民身体健康的因素分析 原题再现: 以心脑血管疾病、糖尿病、恶性肿瘤以及慢性阻塞性肺病为代表的慢性非传染性疾病(以下简称慢性病)已经成为影响我国居民身体健康的重要问题。随着人们生活方式的改变&am…...

AI-调查研究-01-正念冥想有用吗?对健康的影响及科学指南
点一下关注吧!!!非常感谢!!持续更新!!! 🚀 AI篇持续更新中!(长期更新) 目前2025年06月05日更新到: AI炼丹日志-28 - Aud…...
java_网络服务相关_gateway_nacos_feign区别联系
1. spring-cloud-starter-gateway 作用:作为微服务架构的网关,统一入口,处理所有外部请求。 核心能力: 路由转发(基于路径、服务名等)过滤器(鉴权、限流、日志、Header 处理)支持负…...

无法与IP建立连接,未能下载VSCode服务器
如题,在远程连接服务器的时候突然遇到了这个提示。 查阅了一圈,发现是VSCode版本自动更新惹的祸!!! 在VSCode的帮助->关于这里发现前几天VSCode自动更新了,我的版本号变成了1.100.3 才导致了远程连接出…...
在 Nginx Stream 层“改写”MQTT ngx_stream_mqtt_filter_module
1、为什么要修改 CONNECT 报文? 多租户隔离:自动为接入设备追加租户前缀,后端按 ClientID 拆分队列。零代码鉴权:将入站用户名替换为 OAuth Access-Token,后端 Broker 统一校验。灰度发布:根据 IP/地理位写…...

高等数学(下)题型笔记(八)空间解析几何与向量代数
目录 0 前言 1 向量的点乘 1.1 基本公式 1.2 例题 2 向量的叉乘 2.1 基础知识 2.2 例题 3 空间平面方程 3.1 基础知识 3.2 例题 4 空间直线方程 4.1 基础知识 4.2 例题 5 旋转曲面及其方程 5.1 基础知识 5.2 例题 6 空间曲面的法线与切平面 6.1 基础知识 6.2…...

P3 QT项目----记事本(3.8)
3.8 记事本项目总结 项目源码 1.main.cpp #include "widget.h" #include <QApplication> int main(int argc, char *argv[]) {QApplication a(argc, argv);Widget w;w.show();return a.exec(); } 2.widget.cpp #include "widget.h" #include &q…...

MODBUS TCP转CANopen 技术赋能高效协同作业
在现代工业自动化领域,MODBUS TCP和CANopen两种通讯协议因其稳定性和高效性被广泛应用于各种设备和系统中。而随着科技的不断进步,这两种通讯协议也正在被逐步融合,形成了一种新型的通讯方式——开疆智能MODBUS TCP转CANopen网关KJ-TCPC-CANP…...

自然语言处理——循环神经网络
自然语言处理——循环神经网络 循环神经网络应用到基于机器学习的自然语言处理任务序列到类别同步的序列到序列模式异步的序列到序列模式 参数学习和长程依赖问题基于门控的循环神经网络门控循环单元(GRU)长短期记忆神经网络(LSTM)…...

C++ Visual Studio 2017厂商给的源码没有.sln文件 易兆微芯片下载工具加开机动画下载。
1.先用Visual Studio 2017打开Yichip YC31xx loader.vcxproj,再用Visual Studio 2022打开。再保侟就有.sln文件了。 易兆微芯片下载工具加开机动画下载 ExtraDownloadFile1Info.\logo.bin|0|0|10D2000|0 MFC应用兼容CMD 在BOOL CYichipYC31xxloaderDlg::OnIni…...
Rapidio门铃消息FIFO溢出机制
关于RapidIO门铃消息FIFO的溢出机制及其与中断抖动的关系,以下是深入解析: 门铃FIFO溢出的本质 在RapidIO系统中,门铃消息FIFO是硬件控制器内部的缓冲区,用于临时存储接收到的门铃消息(Doorbell Message)。…...