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!");

}


还不太行,留坑

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/11812.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

tensorflow错误及解决办法

tf.graph 节点没有数据 tensorflow.python.framework.errors_impl.InvalidArgumentError: Retval[2] does not have value.通过TensorFlow Retval[0] does not have value启发&#xff0c;怀疑是通过tf.cond构建网络图的时候&#xff0c;一次只走一个分支&#xff0c;导致另一…

docker更新jenkins

下载文件 1、jenkins提示下载 2、官网下载jenkins官网 文件放服务器内 通过工具把jenkins.war放进服务器例如tmp 文件复制到docker的jenkins容器 docker cp 路径文件 容器id:/{后面不接内容为根路径} docker cp /tmp/jenkins.war 53dc1c71058a:/进入容器内 docker exec …

golang实现多态

Go 通过接口来实现多态。在 Go 语言中&#xff0c;我们是隐式地实现接口。一个类型如果定义了接口所声明的全部方法&#xff0c;那它就实现了该接口。现在我们来看看&#xff0c;利用接口&#xff0c;Go 是如何实现多态的。 package mainimport "fmt"type Income in…

实训笔记7.28

实训笔记7.28 7.28笔记一、Hive的基本使用1.1 Hive的命令行客户端的使用1.2 Hive的JDBC客户端的使用1.2.1 使用前提1.2.2 启动hiveserver21.2.3 使用方式 1.3 Hive的客户端中也支持操作HDFS和Linux本地文件 二、Hive中DDL语法2.1 数据库的管理2.1.1 创建语法2.1.2 修改语法2.1.…

日期清洗的sql函数

sql语言是postgressql。 函数只处理了 中国格式 &#xff1a; xxxx年-xx月-xx日 美国格式&#xff1a; mm/dd/yyyy&#xff0c; September 04,1991&#xff0c; September 1991&#xff0c; sept 04&#xff0c; 1991 uunix格式&#xff1a; yyyy/mm/dd&#xff0c; yyyy/mm&am…

python测试开发面试常考题:装饰器

目录 简介 应用 第一类对象 装饰器 描述器descriptor 资料获取方法 简介 Python 装饰器是一个可调用的(函数、方法或类)&#xff0c;它获得一个函数对象 func_in 作为输入&#xff0c;并返回另一函数对象 func_out。它用于扩展函数、方法或类的行为。 装饰器模式通常用…

【学习笔记】[ZJOI2019] 开关

之前没认真学 F W T FWT FWT可惜了&#x1f605; 首先要做过这道题 [AGC034F] RNG and XOR 。 考虑 I F W T IFWT IFWT算法的本质&#x1f914; 之前我们注意到将 k k k的顺序调换并不会影响结果&#xff0c;也就是说只要做一遍 F W T FWT FWT&#xff0c;然后再除以 2 n 2^…

【数据结构】实验十一:图

实验十一 图 一、实验目的与要求 1&#xff09;掌握图的存储表示与操作实现。 2&#xff09;掌握图的连通性及其应用。 二、 实验内容 1.用邻接表存储一个图形结构&#xff0c;并计算每个顶点的度。 2. 采用深度和广度优先搜索算法&#xff0c;遍历上述这张图&#xff0c;…

vue 实现拖拽效果

实现方式&#xff1a;使用自定义指令可以实现多个面板拖拽互不影响 1.自定义指令 js directives: {// 拖拽drag(el) {el.onmousedown function (e) {let x e.pageX - el.offsetLeftlet y e.pageY - el.offsetTopdocument.onmousemove function (e) {el.style.left e.pag…

placeholder样式自定义(uniapp 微信小程序、h5)

一、使用uniapp开发 ①第一种方式&#xff1a;&#xff08;写在行内&#xff09; <input type"text" placeholder"姓名" placeholder-style"font-size:28rpx;color:#999999;" />②第二种方式&#xff1a; &#xff08;给input加上placeho…

《向量数据库指南》:向量数据库Pinecone如何集成数据湖

目录 为什么选择Databricks? 为什么选择Pinecone? 设置Spark集群 环境设置 将数据集加载到分区中 创建将文本转换为嵌入的函数 将UDF应用于数据 更新嵌入 摘要 使用Databricks和Pinecone在规模上创建和索引向量嵌入 建立在Apache Spark之上的Databricks是一个强大的…

【期末课程设计】学生成绩管理系统

因其独特&#xff0c;因其始终如一 文章目录 一、学生成绩管理系统介绍 二、学生成绩管理系统设计思路 三、源代码 1. test.c 2. Student Management System.c 3.Stu_System.c 4.Teacher.c 5.Student Management System.h 前言&#xff1a; 学生成绩管理系统含教师…

什么是Maven,Maven的概述及基本使用

MAVEN 一、Maven简介1.1、Maven概述1.2、Maven仓库1.3项目获取jar包过程 二、Maven使用2.1Maven安装配置2.1.1配置环境变量2.1.2配置本地仓库2.1.3配置阿里云私服 2.2Maven基本使用2.2.1Maven常用指令2.2.2Maven生命周期 总结 一、Maven简介 Apache Maven是一个项目管理和构建…

STM32 I2C OVR 错误

一、问题 STM32 I2C 用作从机时&#xff0c;开启如下中断并启用 callback 回调函数。 每一次复位后&#xff0c;从机都可以正常触发地址匹配中断ADDR&#xff0c;之后在该中断的回调函数中启用接收中断去收取数据时&#xff0c;却无法进入RXNE中断&#xff0c;而是触发了 OVR …

<C语言> 动态内存管理

1.动态内存函数 为什么存在动态内存分配&#xff1f; int main(){int num 10; //向栈空间申请4个字节int arr[10]; //向栈空间申请了40个字节return 0; }上述的开辟空间的方式有两个特点&#xff1a; 空间开辟大小是固定的。数组在申明的时候&#xff0c;必须指定数组的…

自然语言处理NLP介绍——NLP简介

目录 内容先进性说明内容大纲概要云服务器的使用 内容先进性说明 内容大纲概要 云服务器的使用

githack的安装步骤+一次错误体验

一.githack的安装步骤 1.要在Kali Linux上安装GitHack工具&#xff0c;您可以按照以下步骤操作&#xff1a; 打开终端并使用以下命令克隆GitHack存储库&#xff1a; git clone https://github.com/lijiejie/GitHack.git2.进入GitHack目录&#xff1a; cd GitHack3.安装依赖项…

一种分解多种信号模式非线性线性调频的方法研究(Matlab代码实现)

&#x1f4a5;&#x1f4a5;&#x1f49e;&#x1f49e;欢迎来到本博客❤️❤️&#x1f4a5;&#x1f4a5; &#x1f3c6;博主优势&#xff1a;&#x1f31e;&#x1f31e;&#x1f31e;博客内容尽量做到思维缜密&#xff0c;逻辑清晰&#xff0c;为了方便读者。 ⛳️座右铭&a…

JVM-Cpu飙升排查及解决

https://blog.csdn.net/m0_37542440/article/details/123679011 1. 问题情况 在服务器上执行某个任务时&#xff0c;系统突然运行缓慢&#xff0c;top 发现cpu飙升&#xff0c;一度接近100%&#xff0c;最终导致服务假死。 2. 问题排查 1. 执行 “top” 命令&#xff1a;查看所…

Elasticsearch

文章目录 分布式搜索引擎elasticsearch介绍elasticsearch作用ELK技术栈elasticsearch和lucene 倒排索引正向索引倒排索引正向和倒排比较 es的一些概念文档和字段索引和映射mysql与elasticsearch elasticsearch安装部署单点es部署kibana安装IK分词器扩展词词典停用词典 索引库操…