76 lines
2.4 KiB
Plaintext
76 lines
2.4 KiB
Plaintext
|
|
|
|||
|
|
This directory is intended for project specific (private) libraries.
|
|||
|
|
PlatformIO will compile them to static libraries and link into the executable file.
|
|||
|
|
|
|||
|
|
The source code of each library should be placed in a separate directory
|
|||
|
|
("lib/your_library_name/[Code]").
|
|||
|
|
|
|||
|
|
For example, see the structure of the following example libraries `Foo` and `Bar`:
|
|||
|
|
|
|||
|
|
|--lib
|
|||
|
|
| |
|
|||
|
|
| |--Bar
|
|||
|
|
| | |--docs
|
|||
|
|
| | |--examples
|
|||
|
|
| | |--src
|
|||
|
|
| | |- Bar.c
|
|||
|
|
| | |- Bar.h
|
|||
|
|
| | |- library.json (optional. for custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html
|
|||
|
|
| |
|
|||
|
|
| |--Foo
|
|||
|
|
| | |- Foo.c
|
|||
|
|
| | |- Foo.h
|
|||
|
|
| |
|
|||
|
|
| |- README --> THIS FILE
|
|||
|
|
|
|
|||
|
|
|- platformio.ini
|
|||
|
|
|--src
|
|||
|
|
|- main.c
|
|||
|
|
|
|||
|
|
Example contents of `src/main.c` using Foo and Bar:
|
|||
|
|
```
|
|||
|
|
#include <Foo.h>
|
|||
|
|
#include <Bar.h>
|
|||
|
|
|
|||
|
|
int main (void)
|
|||
|
|
{
|
|||
|
|
...
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
The PlatformIO Library Dependency Finder will find automatically dependent
|
|||
|
|
libraries by scanning project source files.
|
|||
|
|
|
|||
|
|
More information about PlatformIO Library Dependency Finder
|
|||
|
|
- https://docs.platformio.org/page/librarymanager/ldf.html
|
|||
|
|
|
|||
|
|
|
|||
|
|
在使用 ESP32 通过 USB 转串口芯片(如 CH340、CP2102、FTDI)与上位机通信控制舵机时,常见一个现象:
|
|||
|
|
1.ESP32 刚上电或复位后,上位机发送串口指令无响应;
|
|||
|
|
2.加入串口 RTS/DTR 信号线的“唤醒操作”后,通信恢复正常,舵机动作也变得可靠。
|
|||
|
|
|
|||
|
|
产生原因:
|
|||
|
|
ESP32 芯片的启动和复位机制依赖两个硬件引脚:
|
|||
|
|
引脚 功能
|
|||
|
|
EN 低电平复位芯片
|
|||
|
|
IO0 低电平进入固件下载模式
|
|||
|
|
USB 转串口芯片通过 RTS 和 DTR 两条信号线控制 ESP32 的这两个引脚:
|
|||
|
|
RTS(Request To Send) 通常控制 EN(复位);
|
|||
|
|
DTR(Data Terminal Ready) 通常控制 IO0;
|
|||
|
|
当 RTS 和 DTR 信号都为低电平时,ESP32 进入下载模式(等待烧录固件),而非正常运行模式。
|
|||
|
|
|
|||
|
|
|
|||
|
|
问题的本质
|
|||
|
|
上位机打开串口时,如果没有正确的 RTS/DTR 信号跳变,ESP32 可能卡在下载模式;
|
|||
|
|
此时,ESP32 不会运行主程序,导致串口指令无法被响应;
|
|||
|
|
唤醒操作即是人为让 RTS/DTR 先拉低(复位 ESP32),再拉高(启动运行),让 ESP32 正常启动。
|
|||
|
|
|
|||
|
|
解决方案总结
|
|||
|
|
在上位机串口打开时主动唤醒 在 openSerialPort() 后设置 RTS/DTR,模拟复位流程。
|
|||
|
|
|
|||
|
|
|
|||
|
|
代码烧写
|
|||
|
|
1.使用vscode内的platformIO插件,安装后点击该软件
|
|||
|
|
2.使用build进行编译
|
|||
|
|
3.使用upload进行烧录
|