野火指南者通过RT-Thread的AT组件连接板载ESP8266

先按照RTT官网的AT组件连接esp8266的教程,准备连接esp8266

开发板平台:野火 指南者开发版

CPU:STM32F103VE

RT-Thread版本:4.0.2

一、安装并配置ENV

安装env软件的方法请参考RTT的官方教程

安装完env后在野火的RTT项目中右键Con Emu Here

 在命令行中运行menuconfig

 

 进入到控制台界面

-配置串口支持(野火版上默认esp8266接uart3):进入到Hardware Drivers Config –>On-chip Peripheral Drivers –>Enable UART –>Enable UART3

-开启AT组件功能:进入到RT-Thread Components–>Network–>AT commands

AT Client 配置选项介绍如下:

  • Enable debug log output:配置开启调试日志;
  • Enable AT commands client:配置开启 AT 客户端;
  • The muxinum number of supported clients: 配置最大同时支持的客户端数量,该例程使用单客户端连接,配置为 1 即可。
  • Enable BSD Socket API support by AT commands: 配置开启 BSD Socket API 支持。
  • Enable CLI(Command-Line Interface) for AT commands: 配置开启 AT 命令行交互模式。

 

Enable print RAW format AT command communication data: 配置开启收发数据实时打印功能。

-开启SAL组件:
进入到RT-Thread Components–>Network–>Socket abstraction layer

打开Enable socket abstraction layer 和 Enable BSD socket operated by file system API

-开启AT-decive:进入到RT-Thread online packages –> IoT – internet of things –> AT DEVICE

打开后进入Espressif ESP8266

在WIFI ssid与WIFI password中填写开发板要连接的wifi网络

把AT client device name修改成uart3

-配置完成,将光标移向env下方的Save,回车保存后退出到命令行界面

在命令行中输入:pkg –update

再输入:scons –target=mdk5 来重新生成项目

二、编译调试项目

打开项目文件.uvprojx

将项目编译后,通过下载器烧录进野火指南者开发板,打开sscom观察串口内的信息:

 

 \ | /
- RT -     Thread Operating System
 / | \     4.0.2 build Aug 16 2019
 2006 - 2019 Copyright by rt-thread team
[I/sal.skt] Socket Abstraction Layer initialize success.
[I/at.clnt] AT client(V1.3.0) on device uart3 initialize success.
[D/at.dev] the network interface device(esp0) set up status
[D/at.dev] esp8266 device(esp0) initialize start.
[E/at.clnt] Read response buffer failed. The Response buffer size is out of buffer size(256)!
[D/at.clnt] execute command (ATE0) timeout (5000 ticks)!
[I/at.dev] esp8266 device(esp0) initialize retry...
[D/at.clnt] execute command (ATE0) timeout (5000 ticks)!
[I/at.dev] esp8266 device(esp0) initialize retry...
[D/at.clnt] execute command (ATE0) timeout (5000 ticks)!
[I/at.dev] esp8266 device(esp0) initialize retry...
[D/at.clnt] execute command (ATE0) timeout (5000 ticks)!
[I/at.dev] esp8266 device(esp0) initialize retry...
[D/at.clnt] execute command (ATE0) timeout (5000 ticks)!
[I/at.dev] esp8266 device(esp0) initialize retry...
[E/at.dev] esp8266 device(esp0) network initialize failed(-1).

我们发现串口报告的错误信息有两个

一个是Read response buffer failed. 缓冲区内存过小,那我们就直接增大就好了

一个是command (ATE0)运行超时,ATE0是AT指令中的关闭回显,出现这个问题的原因可能是AT组件初始化时间过短

-解决缓冲区内存过小

打开项目文件,定位到AT/at_client.c

将第364行修改成

resp = at_create_resp(512, 0, rt_tick_from_millisecond(300));

即可解决问题

-解决ATE0运行超时

 

打开项目文件,定位到at_device/at_device_esp8266.c

我们在第632行看到了相关的ATE0的代码

AT_SEND_CMD(client, resp, "AT+RST");
/* reset waiting delay */
rt_thread_mdelay(2000);
/* disable echo */
AT_SEND_CMD(client, resp, "ATE0");

将rt_thread_mdelay函数的延迟时间修改成2000ms,让AT+RST有足够时间来运行

即可解决问题

-将项目重新编译后,烧录进开发板,继续观察串口内容
 \ | /
- RT -     Thread Operating System
 / | \     4.0.2 build Aug 16 2019
 2006 - 2019 Copyright by rt-thread team
[I/sal.skt] Socket Abstraction Layer initialize success.
[I/at.clnt] AT client(V1.3.0) on device uart3 initialize success.
[D/at.dev] the network interface device(esp0) set up status
[D/at.dev] esp8266 device(esp0) initialize start.
[D/at.dev] AT version:0.22.0.0(Mar 20 2015 10:04:26)
[D/at.dev] SDK version:1.0.0
[D/at.dev] compile time:Mar 20 2015 11:00:56
[D/at.dev] 
[I/at.dev] esp8266 device(esp0) network initialize successfully.
[E/at.clnt] execute command (AT+CIPDNS_CUR?) failed!
[W/at.dev] please check and update device(esp0) firmware to support the "AT+CIPDNS_CUR?" command.
[E/at.clnt] execute command (AT+CIPDOMAIN="link.rt-thread.org") failed!

又发现了两个错误

[E/at.clnt] execute command (AT+CIPDNS_CUR?) failed! [W/at.dev] please check and update device(esp0) firmware to support the “AT+CIPDNS_CUR?” command. [E/at.clnt] execute command (AT+CIPDOMAIN=”link.rt-thread.org”) failed!

这些错误的原因是由于野火板载的ESP8266的固件版本太低造成的,可以通过刷最新的安信可ESP8266固件来解决,本文不做过多展开。

我们在串口中输入 at client 命令,并输入 AT+RST与AT+PING=”www.baidu.com”

来测试AT组件是否安装完善

msh />at client
======== Welcome to using RT-Thread AT command client cli ========
Cli will forward your command to server port(uart3). Press 'ESC' to exit.
AT+RST

OK

 ets Jan  8 2013,rst cause:4, boot mode:(3,6)

wdt reset
load 0x40100000, len 1320, room 16 
tail 8
chksum 0xb8
load 0x3ffe8000, len 776, room 0 
tail 8
chksum 0xd9
load 0x3ffe8308, len 412, room 0 
tail 12
chksum 0xb9
csum 0xb9

2nd boot version : 1.3(b3)
  SPI Speed      : 40MHz
  SPI Mode       : QIO
  SPI Flash Size : 4Mbit
jump to run user2

sl??
ready

AT+PING="www.baidu.com"
AT+PING="www.baidu.com"
+12

OK

输入输出结果如上,可以看到,AT组件正常运行了!

 

发表评论

电子邮件地址不会被公开。 必填项已用*标注

13 + 3 =