Rust ESP32C3开发

news2024/9/28 3:28:15

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 250
    characters (see CMAKE_OBJECT_PATH_MAX).  Object file

      d5fa956509b7db88e8eaa02d1680138d/esp_rsa_sign_alt.c.obj

    cannot be safely placed under this directory.  The build may not work
    correctly.

目录太长了,回到std-training目录,将项目映射到r:

 subst r: std-training
 cd r:

进入hardware-check重新编译

 cd intor/hardware-check
 cargo 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/71
    esp_idf_sys::link_patches();
    // Bind the log crate to the ESP Logging facilities
    esp_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 main

import "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 cargo
 Project Name: ssd1306_esp32c3
 Renaming 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? · false
 Moving generated files into: `R:\ssd1306-esp32c3`...
Initializing a fresh Git repository
 Done! 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/71
    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!");
}

还不太行,留坑
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.coloradmin.cn/o/805033.html

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

相关文章

浏览器中的Markdown编辑器StackEdit

目前博客的 Pageviews 大约是之前的 10%&#xff0c;而 Uniques 则大约是 15% 左右。看来很多同学已经彻底迷路了 大家可以关注CSDN&#xff0c;地址&#xff1a; https://blog.csdn.net/wbsu2004 微信公众号也可以关注起来 什么是 StackEdit &#xff1f; StackEdit 是基于 P…

pyspark 笔记 cast 转换列的类型

1 不借助 pyspark.sql.types from pyspark.sql.functions import coldata [("Alice", "28"), ("Bob", "22"), ("Charlie", "30")] columns ["name", "age_str"] df spark.createDataFram…

如何使用vscode连接远程服务器

1、安装remote-ssh 在应用商店搜索remote-ssh&#xff0c;安装remote-ssh 2、安装完成后会出现远程资源管理器 3、点击远程资源管理器 --ssh的➕号&#xff0c;在输出框内输入要连接的服务器ip及账户名 如&#xff1a;ssh 账户名ip地址 4、输入后回车保存 5、保存后刷新一下 6…

SOLIDWORKS磁力配合工具

在我们平常的工作中&#xff0c;很多人都会面临大型装配体相互配合的问题。有很多用户&#xff0c;由于设计的产品体积很大&#xff0c;零件数量非常多。即使将设备分成不同的部件进行组装&#xff0c;不同的部件之间进行配合也非常困难。因为这种时候软件运行的速度会变得非常…

【UE5 多人联机教程】06-显示玩家名称

效果 可以看到玩家输入各自的名称&#xff0c;会显示到自己控制的角色头上。但是目前有一个BUG就是&#xff0c;当客户端加入游戏时会多创建一个服务端的角色。 步骤 1. 打开“BP_ThirdPersonCharacter”&#xff0c;添加一个控件组件&#xff0c;用于显示玩家名称 作为网格体…

国产内存惹人爱,光威的价格战太凶猛,海外品牌已无力招架

现阶段&#xff0c;真的很适合升级内存条和SSD&#xff01;当然了&#xff0c;我说的是国产的品牌&#xff0c;经过这几年的发展&#xff0c;国产内存和SSD的表现都有了质的飞跃&#xff0c;像是光威之类的品牌&#xff0c;更是成功在玩家群体中获得了良好的口碑&#xff0c;而…

数据库的介绍

无处不在的数据库 信息化社会&#xff0c;无处不在的就是数据。 编程语言可以归纳为&#xff0c;数据的计算一类。 那数据的存储呢? 数据库就是存储数据的库&#xff0c;那么它是如何组织数据并存储的呢? 数据库如何存储数据 我们先来看看&#xff0c;生活中&#xff0c;…

通过社区参与解锁早期增长:Maven 远程医疗平台概览

Maven通过用户导向的渐进式验证&#xff0c;找到了一个被忽视的巨大女性医疗服务市场&#xff0c;作为女性医疗保健的先行者&#xff0c;已服务超过1500万用户&#xff0c;目前估值已达$14亿。本文将深入探索Maven实现产品市场匹配的三个阶段&#xff0c;从如何验证初始的市场机…

Junit5 + YAML 轻松实现参数化和数据驱动(一)

登录&#xff1a;不同的用户名&#xff0c;不同的密码&#xff0c;不同的组合都需要做登录场景的测试&#xff0c;正常的排列组合下可能会产生多个用例 搜索&#xff1a;不同的搜索条件产生不同的搜索结果&#xff0c;搜索也是常见的测试项&#xff0c;单个搜索参数或者多种搜…

手动搭建gateway,项目集成gateway实现Token效果

目录 背景步骤1、首先创建springboot项目2、引入依赖3、配置文件&#xff01;&#xff01;&#xff01;&#xff01;&#xff01;&#xff08;超级重要&#xff01;&#xff01;&#xff01;根据自己的需要进行配置&#xff09;4、相关类我们在服务中进行的白名单中接口的操作如…

Java8 LocalDate、Date、LocalDateTime、时间戳的转换

文章目录 LocalDateplusminus比较日期 LocalDate、Date、LocalDateTime、时间戳的转换 LocalDate plus LocalDate localDate2 localDate1.plus(15, ChronoUnit.DAYS);LocalDate localDate2 localDate1.plus(Period.ofDays(15));minus LocalDate localDate2 localDate1.minu…

电缆振荡波局部放电检测定位技术

电缆振荡波检测技术主要用于交联聚乙烯电力电缆检测&#xff0c;是属于离线检测的一种有效形式 。该技术基于LCR阻尼振荡原理&#xff0c;在完成电缆直流充电的基础上&#xff0c;通过内置的高压电抗器、高压实时固态开关与试品电缆形成阻尼振荡电压波&#xff0c;在试品电缆上…

新品发布| PPS Tester同步精度测试仪

产品简介 Product introduction 产品概述 PPS 同步精度测试仪&#xff0c;即PPS Tester&#xff0c;是怿星科技开发的一款基于1PPS测量方法的系统时钟同步精度测试设备。它由硬件模块ETS2110、上位机软件ePPSTester以及相关附件组成。PPS Tester支持24路*24小时PPS信号的持续…

NodeJs后端项目使用docker打包部署

docker安装看之前的文章 默认已经安装好docker并且配置没有问题 拉取项目 https://gitee.com/coder-msc/docker-node 本地跑一个看看 pnpm install pnpm start 本地访问 http://localhost:1301/getname?name%E5%93%88%E5%88%A9%E6%B3%A2%E7%89%B9项目整个上传服务器 查看…

8.10 PowerBI系列之DAX函数专题-TopN中实现动态指标

需求 实现 建立一个辅助表供切片器选择 2 建立条件判断度量值top_measure swich(true(),selectedvalue(table[tope_type])"按数量top",sum(order_2[产品数量]),selectedvalue(table[tope_type])"按金额top",sum(order_2[订单金额]),selectedvalue(table…

字符指针和常量字符指针

用来存放字符的地址的指针 还有一种比较特殊的字符指针 有这样一道题&#xff1a;

最小时间差(力扣)排序 + 思维 JAVA

给定一个 24 小时制&#xff08;小时:分钟 “HH:MM”&#xff09;的时间列表&#xff0c;找出列表中任意两个时间的最小时间差并以分钟数表示。 示例 1&#xff1a; 输入&#xff1a;timePoints [“23:59”,“00:00”] 输出&#xff1a;1 示例 2&#xff1a; 输入&#xff1a;…

css实现有缺口的border

css实现有缺口的border 1.问题回溯2.css实现有缺口的border 1.问题回溯 通常会有那种两个div都有border重叠在一起就会有种加粗的效果。 div1,div2,div3都有个1px的border&#xff0c;箭头标记的地方是没有处理解决的&#xff0c;很明显看着是有加粗效果的。其实这种感觉把di…

python爬虫-加速乐cookie混淆解析实例小记

注意&#xff01;&#xff01;&#xff01;&#xff01;某XX网站逆向实例仅作为学习案例&#xff0c;禁止其他个人以及团体做谋利用途&#xff01;&#xff01;&#xff01; 第一步&#xff1a;抓包工具第一次请求页面&#xff0c;得到响应。本次我使用的fiddle进行抓包&#…

如何利用Requestly提升前端开发与测试的效率

痛点 B站最牛的Python接口自动化测试进阶教程合集&#xff08;真实企业项目实战&#xff09; 前端测试 在进行前端页面开发或者测试的时候&#xff0c;我们会遇到这一类场景&#xff1a; 在开发阶段&#xff0c;前端想通过调用真实的接口返回响应在开发或者生产阶段需要验证前…