使用SAMD21模拟CP210X USB-FTDI芯片

发布于 2025-01-23 15:27:44 字数 899 浏览 4 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

七分※倦醒 2025-01-30 15:27:45

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模块。设置为:

  • 使用Platformio构建的Arduino代码。我使用serialusb而不是serial,因为我不确定如何控制常规Arduino IDE中可用的项目设置。
  • 对于ESP32,我在最小板上使用了ESP32-Wroom-32模块(重置和启动按钮,2个上拉电阻)。
  • 我已经通过GND,3.3V,TX,RX将板连接到SAMD21开发板。
  • 我已经证实,我可以在普通运行模式下看到ESP32日志输出,并在Bootloader模式下(按下启动和重置后)的“等待下载”提示。

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:

  • Arduino code built with PlatformIO. Instead of Serial, I've used SerialUSB as I'm unsure how to control the project settings available in the regular Arduino IDE.
  • For the ESP32, I've used a ESP32-WROOM-32 module on a minimal board (reset and boot button, 2 pull-up resistors).
  • I've connected the board via GND, 3.3V, TX, RX directly to the SAMD21 dev board.
  • I've verified that I can see the ESP32 log output in normal run mode and the "waiting for download" prompt in bootloader mode (after pressing BOOT and RESET).
始终不够 2025-01-30 15:27:45

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文