moefear85 / esptool

Espressif SoC serial bootloader utility

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Reason of Fork:

A udp socket has been added to the ESPLoader class of esptool.py. Now, when the port is "socket://...", an additional udp socket will connect to that address:port. Then whenever an rts/dtr/baudrate change happens, it will be forwarded using a very simple packet format, over udp, to the same address:port. This can be for example localhost, allowing the user to repackage those messages into any other socket or more reliable form. Or one can choose the address:port such that esptool connects directly to a remote listening server that then uses the udp messages to reconfigure the uart interface that programs the esp chip. I will upload such a remote server tool at a later date, which can run on any esp-12F or esp32 intermediary chip acting as a programmer, which recieves the data stream over wireless from the pc running esptool.

Rationale: Documentation for rfc2217 is difficult to find and sparse. The protocol itself is also unnecessarily complicated. Using out-of-band udp rts/dtr/baud signalling as done here in combination with a raw data tcp socket, is much simpler. The server can then run any custom handler, which can be much simpler than the rf2217 server. No Telnet involved.

The benefit of this solution over others, is that it retains full automatic remote flashing capability without any manual pressing of buttons, toggling of switches, or dis-/connecting of jumper cables. It is even superior to esp OTA, in that it can always definately regain control of the target chip no matter how badly the flashed image misbehaves, and one doesn't have to integrate any ota logic into the app. Ofcourse it assumes ability to attach the remote programming server over uart to the target chip.

I have tested this change with the following hardware & software combinations: VSCode, Ubuntu 20.04 x64, ESP-12F & ESP32.

UDP Packet Formats:

There are only 2 different types of messages, "bootmode" (3 bytes long) and "baudrate" (5 bytes long). The first byte indicates message type. 0: bootmode, 1: baudrate.

For Bootmode: the 2nd byte represents the current state of RTS. The 3rd byte represents the current state of DTR. Note here 0 represents 0V and 1 represents 1V on the wire. In PySerial however, 1V corresponds to False whereas 0V corresponds to True. For Baudrate: The 4 bytes after the message type, is a big-endian packed integer value (See python's to_bytes() and from_bytes() documentation). It represents the currently chosen baudrate.

Every time esptool sets/changes the baudrate and/or rts/dtr pins, a corresponding packet is sent out.

About

Espressif SoC serial bootloader utility

License:GNU General Public License v2.0


Languages

Language:Python 64.7%Language:C 34.1%Language:Makefile 0.8%Language:Shell 0.3%Language:PowerShell 0.1%