当前位置: 首页 > news >正文

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

【Spring Cloud Gateway 新一代网关】—— 每天一点小知识

&#x1f4a7; S p r i n g C l o u d G a t e w a y 新一代网关 \color{#FF1493}{Spring Cloud Gateway 新一代网关} SpringCloudGateway新一代网关&#x1f4a7; &#x1f337; 仰望天空&#xff0c;妳我亦是行人.✨ &#x1f984; 个人主页——微风撞见云的博客&a…...

Java 中的关键字 final 和 static

一、关键字 final final 修饰符可以用来修饰类、方法和变量&#xff0c;final 修饰的类不能够被继承&#xff0c;修饰的方法不能被继承类重新定义&#xff0c;修饰的变量为常量&#xff0c;是不可修改的。 1.1 final 变量 final 有"最后的、最终的"的含义&#xf…...

Spring Cloud OpenFeign 全教程

1. 声明式 REST 客户端&#xff1a; Feign Feign 是一个声明式的 Web Service 客户端。它使编写 Web Service 客户端更容易。要使用 Feign&#xff0c;需要创建一个接口并对其进行注解。它有可插拔的注解支持&#xff0c;包括 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月开源的大模型&#xff0c;在这之后&#xff0c;很多开源模型都是基于LLaMA的&#xff0c;比如斯坦福大学的羊驼模型。 LLaMA的重点是比…...

了解Unity编辑器 之组件篇Effects(十一)

一、Halo&#xff1a;是一个可用于游戏对象的特效组件&#xff0c;它可以在对象周围添加一个光晕效果 Color属性: 用于设置Halo的颜色。你可以通过选择颜色面板中的颜色来指定光晕的外观。选择适当的颜色可以使光晕与游戏场景中的其他元素相匹配或突出显示。 Size属性: 用于设…...

笔记整理-SpringBoot中的扩展点

SpringBoot有哪些扩展点 aware 感知类接口 aware系列的扩展接口&#xff0c;允许spring应用感知/获取特定的上下文环境或对象。bean生命周期控制类接口 bean生命周期类的接口&#xff0c;可以控制spring容器对bean的处理。app生命周期控制类接口 app生命周期控制类接口&#xf…...

各系统的目录信息路径

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帮助类 首先&#xff0c;在你的项目中创建一个Log4Net帮助类&#xff0c;用于封装Log4Net的配置和日志记录逻辑。 using log4net; using log4net.Config;public class LogHelper {private static readonly ILog log LogMan…...

全志F1C200S嵌入式驱动开发(lcd屏幕驱动)

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

dubbo原理框架设计

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

【数据挖掘】使用 LSTM 进行时间和序列预测

一、说明 每天&#xff0c;人类在执行诸如过马路之类的任务时都会做出被动预测&#xff0c;他们估计汽车的速度和与汽车的距离&#xff0c;或者通过猜测球的速度并相应地定位手来接球。这些技能是通过经验和实践获得的。然而&#xff0c;由于涉及众多变量&#xff0c;预测天气或…...

Typescript第四章 函数(声明和调用,注解参数类型,多态,类型别名,泛型)

第四章 函数 ts中声明和调用函数的不同方式签名重载多态函数多态类型声明 4.1 声明和调用函数 在js中函数是一等对象&#xff0c;我们可以像对象那样使用函数&#xff0c;可以复制给变量&#xff0c;可以作为参数传递&#xff0c;返回值&#xff0c;赋值给对象的原型&#x…...

大数据-Spark批处理实用广播Broadcast构建一个全局缓存Cache

1、broadcast广播 在Spark中&#xff0c;broadcast是一种优化技术&#xff0c;它可以将一个只读变量缓存到每个节点上&#xff0c;以便在执行任务时使用。这样可以避免在每个任务中重复传输数据。 2、构建缓存 import org.apache.spark.sql.SparkSession import org.apache.s…...

Android Service的生命周期,两种启动方法,有什么区别

Android Service的生命周期&#xff0c;两种启动方法&#xff0c;有什么区别 Android Service是一种后台组件&#xff0c;用于在后台执行长时间运行的任务&#xff0c;而无需与用户界面进行交互。Service具有自己的生命周期&#xff0c;其主要包含以下几个状态&#xff1a;创建…...

测试开源C#人脸识别模块ViewFaceCore(5:质量检测和眼睛状态检测)

ViewFaceCore模块中的FaceQuality支持预测人脸质量&#xff0c;最初以为是预测人体体重&#xff0c;实际测试过程中才发现是评估人脸图片质量&#xff0c;主要调用Detect函数执行图片质量检测操作&#xff0c;其函数原型如下所示&#xff1a; //// 摘要:// 人脸质量评估///…...

Go语言网络库net/http

Go语言网络库net/http Http 协议(Hyper Text Transfer Protocol&#xff0c;超文本传输协议)是一个简单的请求-响应协议&#xff0c;它通常运行在 TCP 之 上。超文本传输协议是互联网上应用最为广泛的一种网络传输协议&#xff0c;所有的WWW文件都必须遵守这个标准。 Http 协…...

Acwing.91 最短Hamilton路径(动态规划)

题目 给定一张n个点的带权无向图&#xff0c;点从0~n-1标号&#xff0c;求起点0到终点n-1的最短Hamilton路径。Hamilton路径的定义是从0到n-1不重不漏地经过每个点恰好一次。 输入格式 第—行输入整数n。 接下来n行每行n个整数&#xff0c;其中第i行第j个整数表示点i到j的距…...

[hfut] [important] v4l2 vedio使用总结/opevx/ffpeg/v4l2/opencv/cuda

(158条消息) linux驱动camera//test ok_感知算法工程师的博客-CSDN博客 (158条消息) linux V4L2子系统——v4l2架构&#xff08;1&#xff09;之整体架构_感知算法工程师的博客-CSDN博客 (158条消息) linux V4L2子系统——v4l2的结构体&#xff08;2&#xff09;之video_devi…...

2023年深圳杯数学建模A题影响城市居民身体健康的因素分析

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

网络六边形受到攻击

大家读完觉得有帮助记得关注和点赞&#xff01;&#xff01;&#xff01; 抽象 现代智能交通系统 &#xff08;ITS&#xff09; 的一个关键要求是能够以安全、可靠和匿名的方式从互联车辆和移动设备收集地理参考数据。Nexagon 协议建立在 IETF 定位器/ID 分离协议 &#xff08;…...

多云管理“拦路虎”:深入解析网络互联、身份同步与成本可视化的技术复杂度​

一、引言&#xff1a;多云环境的技术复杂性本质​​ 企业采用多云策略已从技术选型升维至生存刚需。当业务系统分散部署在多个云平台时&#xff0c;​​基础设施的技术债呈现指数级积累​​。网络连接、身份认证、成本管理这三大核心挑战相互嵌套&#xff1a;跨云网络构建数据…...

地震勘探——干扰波识别、井中地震时距曲线特点

目录 干扰波识别反射波地震勘探的干扰波 井中地震时距曲线特点 干扰波识别 有效波&#xff1a;可以用来解决所提出的地质任务的波&#xff1b;干扰波&#xff1a;所有妨碍辨认、追踪有效波的其他波。 地震勘探中&#xff0c;有效波和干扰波是相对的。例如&#xff0c;在反射波…...

脑机新手指南(八):OpenBCI_GUI:从环境搭建到数据可视化(下)

一、数据处理与分析实战 &#xff08;一&#xff09;实时滤波与参数调整 基础滤波操作 60Hz 工频滤波&#xff1a;勾选界面右侧 “60Hz” 复选框&#xff0c;可有效抑制电网干扰&#xff08;适用于北美地区&#xff0c;欧洲用户可调整为 50Hz&#xff09;。 平滑处理&…...

工业安全零事故的智能守护者:一体化AI智能安防平台

前言&#xff1a; 通过AI视觉技术&#xff0c;为船厂提供全面的安全监控解决方案&#xff0c;涵盖交通违规检测、起重机轨道安全、非法入侵检测、盗窃防范、安全规范执行监控等多个方面&#xff0c;能够实现对应负责人反馈机制&#xff0c;并最终实现数据的统计报表。提升船厂…...

Vue3 + Element Plus + TypeScript中el-transfer穿梭框组件使用详解及示例

使用详解 Element Plus 的 el-transfer 组件是一个强大的穿梭框组件&#xff0c;常用于在两个集合之间进行数据转移&#xff0c;如权限分配、数据选择等场景。下面我将详细介绍其用法并提供一个完整示例。 核心特性与用法 基本属性 v-model&#xff1a;绑定右侧列表的值&…...

解决Ubuntu22.04 VMware失败的问题 ubuntu入门之二十八

现象1 打开VMware失败 Ubuntu升级之后打开VMware上报需要安装vmmon和vmnet&#xff0c;点击确认后如下提示 最终上报fail 解决方法 内核升级导致&#xff0c;需要在新内核下重新下载编译安装 查看版本 $ vmware -v VMware Workstation 17.5.1 build-23298084$ lsb_release…...

使用van-uploader 的UI组件,结合vue2如何实现图片上传组件的封装

以下是基于 vant-ui&#xff08;适配 Vue2 版本 &#xff09;实现截图中照片上传预览、删除功能&#xff0c;并封装成可复用组件的完整代码&#xff0c;包含样式和逻辑实现&#xff0c;可直接在 Vue2 项目中使用&#xff1a; 1. 封装的图片上传组件 ImageUploader.vue <te…...

【android bluetooth 框架分析 04】【bt-framework 层详解 1】【BluetoothProperties介绍】

1. BluetoothProperties介绍 libsysprop/srcs/android/sysprop/BluetoothProperties.sysprop BluetoothProperties.sysprop 是 Android AOSP 中的一种 系统属性定义文件&#xff08;System Property Definition File&#xff09;&#xff0c;用于声明和管理 Bluetooth 模块相…...

【JVM】Java虚拟机(二)——垃圾回收

目录 一、如何判断对象可以回收 &#xff08;一&#xff09;引用计数法 &#xff08;二&#xff09;可达性分析算法 二、垃圾回收算法 &#xff08;一&#xff09;标记清除 &#xff08;二&#xff09;标记整理 &#xff08;三&#xff09;复制 &#xff08;四&#xff…...