使用SAMD21模拟CP210X USB-FTDI芯片
ESP32 MCU家族的开发板使用CP210X(或类似)的“ FTDI”芯片在闪烁时与MCU通信。 CP210X将COM端口呈现到主机计算机,该计算机运行Esptool.py,该脚本实现了Esressif通信协议。然后,我想使用CP210X,而是在其位置使用SAMD21。
我设法通过USB接收了来自ESP32的日志,通过SAMD21上的计算机上的串行显示器。 SAMD21通过UART连接到ESP32,标准ESP配置为115200 8N1。我可以通过将正确的引脚保持在启动时手动输入引导加载程序模式,然后将日志退回确认正确的引导加载程序模式。
但是,当我运行esptool.py时,连接失败了,我会超时。同样,Esptool“监视器”也无法确认我的终端模拟器可以轻松检测到的相同日志。
运行Esptool.py的主机计算机,CP210X FTDI芯片和ESP32之间的通信协议是什么,如何使用SAMD21模拟CP210X?据我在网上的研究中确定,“ FTDI”,“ TTL”和“ RS232”的定义都有些模糊,因此,如果有人在这个领域中有经验,我会很好奇听到您的建议。
我在SAMD21上的代码仅是:
#include <Arduino.h>
void setup()
{
Serial.begin(115200);
Serial1.begin(115200);
}
void loop()
{
if(Serial.available())
{
Serial1.write(Serial.read());
}
if(Serial1.available())
{
Serial.write(Serial1.read());
}
}
其中serial1
是UART,serial
是USB序列连接。
The dev boards for the ESP32 family of MCU use CP210x (or similar) "FTDI" chips to communicate with the MCU when flashing. CP210x presents a COM port to the host computer which runs esptool.py, a script which implements the Esressif communication protocol. Rather then use a CP210x, I would like to utilize a SAMD21 in its place.
I have managed to receive logs from my ESP32, to a serial monitor on my computer, via the SAMD21, over USB. The SAMD21 connects to the ESP32 via UART, with the standard ESP configuration of 115200 8N1. I can manually enter bootloader mode by holding the correct pins low at boot, and I get the log back confirming the correct bootloader mode.
When I run esptool.py, however, the connection fails, and I get a timeout. Likewise the esptool "monitor" fails to acknowledge the same logs which my terminal emulator easily detects.
What is the communication protocol between the host computer running esptool.py, the CP210x FTDI chip, and the ESP32, and how can I emulate the CP210x with a SAMD21? The definition of "FTDI", "TTL" and "RS232" are all a bit fuzzy, as far as I can determine with research online, so if anyone has experience in this arena, I would be very curious to hear your advice.
The code I have on my SAMD21 is just:
#include <Arduino.h>
void setup()
{
Serial.begin(115200);
Serial1.begin(115200);
}
void loop()
{
if(Serial.available())
{
Serial1.write(Serial.read());
}
if(Serial1.available())
{
Serial.write(Serial1.read());
}
}
Where Serial1
is the UART and Serial
is the USB Serial connection.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
esptool.py 期望串行端口(在Windows上称为COM端口)与ESP32通信。它不在乎计算机是否具有旧式的串行端口,使用具有专有协议的USB到Serial桥梁(FTDI,CP210X等),或者正在使用标准化的UBS协议进行串行通信(USB CDC ACM)。这留给了操作系统和已安装的驱动程序。
但是, esptool.py 修改了波特率,并使用RTS和DTR信号重置ESP32。关于重置的时间问题也很容易受到定时问题的影响。如果您手动以启动模式设置ESP32,则应该可以在没有这些的情况下逃脱。
但是,最有可能的原因是Arduino CDC实施不实施流控制。如果 esptool.py 将数据多于拟合到内部缓冲区,则可能被丢弃,而不是将NAK寄回,以便主机以后可以重试。
我不完全了解SAMD21 Arduino核心来验证它。如果是这样,我看不到如何通过Arduino程序使其使用。您需要诉诸其他一些框架来编程SAMD21。
更新
在进行了更多测试之后,事实证明,SAMD21 Arduino Core的USB CDC实现正确地实现了流量控制。因此不会丢失数据。
实际上,我能够成功地将代码上传到ESP32模块。设置为:
serialusb
而不是serial
,因为我不确定如何控制常规Arduino IDE中可用的项目设置。esptool.py expects a serial port (known as COM port on Windows) to communicate with the ESP32. It doesn't care if the computer has an old-style serial port, is using a USB-to-serial bridge with a proprietary protocol (FTDI, CP210x and the like) or is using the standardized UBS protocol for serial communication (USB CDC ACM). This is left to the operating system and the installed drivers.
However, esptool.py modifies the baud rate and uses the RTS and DTR signals to reset the ESP32. It is also rather susceptible to timing issues with regards to the reset. If you set the ESP32 in boot mode manually, you should be able to get away without these.
However, the most likely cause is that the Arduino CDC implementation does not implement flow control. If esptool.py sends more data than fit into the internal buffer, it is likely discarded, instead of sending a NAK back so the host computer can retry later.
I don't fully understand the SAMD21 Arduino core to verify it. If so, I don't see how you can make it work with an Arduino program. You would need to resort to some other framework for programming the SAMD21.
Update
After more tests, it turns out the USB CDC implementation of the SAMD21 Arduino core correctly implements flow control. So no data will be lost.
In fact, I was able to successfully upload code to an ESP32 module. The setup was:
Serial
, I've usedSerialUSB
as I'm unsure how to control the project settings available in the regular Arduino IDE.Arduino有多个板,其中ESP32作为WiFi适配器。为了刷新ESP32,有一个工具草图,称为 serialninapassthrough 在WiFi库的示例中,应将其上传到董事会的主要MCU(在两个官方董事会上的SAMD21)。
SerialNinaPassThrough草图处理了Esptool发送的DTR和RTS信号,以将板重置为闪烁模式。
Arduino has multiple boards where the esp32 is on-board as WiFi adapter. To flash the esp32, there is a tool sketch called SerialNINAPassthrough in examples of the WiFi library, which should be uploaded into the main MCU of the board (SAMD21 on two of the official boards).
The SerialNINAPassthrough sketch handles the DTR and RTS signals sent by the esptool to reset the board into the flashing mode.