Monitor port autodetection based on VID:PID
See original GitHub issueConfiguration
Operating system: WIN10 Pro/64
PlatformIO Version Platformio IDE 1.10.0 installed on VSCode Platform is espressif32 V1.11.1 lolin_d32_pro board USB is assigned to COM4
PIO Home=>Devices:
COM1 Communications Port (COM1) ACPI\PNP0501\0
COM2 High-Speed USB Serial Port (COM2) QUADPORT\QUAD_SERIAL_INTERFACE\7&29C3DB4D&0&0000
COM3 High-Speed USB Serial Port (COM3) QUADPORT\QUAD_SERIAL_INTERFACE\7&29C3DB4D&0&0001
COM4 USB-SERIAL CH340 (COM4) USB VID:PID=1A86:7523 SER=5 LOCATION=1-9
COM5 USB Serial Port (COM5) USB VID:PID=0403:6001 SER=PXF3PKCPA
Description of problem
Serial port Auto detection chooses the wrong USB COMx port. Success can occur too, but it depends on the USB serial devices that are currently installed.
I originally thought that only the Monitor port was affected. But after some experimentation (noted further below) I found that Upload can also choose the wrong COMx port.
Initially I found that the Upload Port auto-detect was working correctly (ESP32 Upload flash worked normally). But Serial Monitor would not auto-detect. Instead it lists the available ports and waits for me to enter the COMx port name. As expected, typing “COM4” (or “4”) launches the serial monitor.
This is the list I see in the terminal window when Serial Monitor is launched from the IDE:
--- Available ports:
--- 1: COM1 'Communications Port (COM1)'
--- 2: COM2 'High-Speed USB Serial Port (COM2)'
--- 3: COM3 'High-Speed USB Serial Port (COM3)'
--- 4: COM4 'USB-SERIAL CH340 (COM4)'
--- 5: COM5 'USB Serial Port (COM5)'
--- Enter port index or full name:
Steps to Reproduce
No. 1 I tried specifying the COM port with a wildcard in platformio.ini. Like this: monitor_port = COM*
The good news is that this automatically launches the monitor terminal after the flash Upload, but it chooses the wrong port for the serial monitor. For example, the ESP32 board is on COM4, but the monitor_port wildcard is picking COM5.
No. 2 I found that specifying the monitor_port COM4 value in platformio.ini works correctly. Like this: monitor_port = COM4 After a flash Upload this automatically opens the serial monitor for my serial debugging. But specifying a fixed COMx is problematic since port usage can vary with the other project members.
No. 3 I removed the COM5 USB adapter and everything works perfectly; Both upload and serial monitor are correctly auto-detected. I wondered if it could it be a bad USB device.
So I installed a randomly chosen FT232RL USB adapter. It was assigned COM10. I rebooted the PC and got back into the Platformio IDE. As before, when I launched the Serial Monitor it did not auto-detect. The available COM ports list appeared, like this:
— Available ports: — 1: COM1 ‘Communications Port (COM1)’ — 2: COM2 ‘High-Speed USB Serial Port (COM2)’ — 3: COM3 ‘High-Speed USB Serial Port (COM3)’ — 4: COM4 ‘USB-SERIAL CH340 (COM4)’ — 5: COM10 ‘USB Serial Port (COM10)’ — Enter port index or full name:
Choosing COM4 enables the ESP32’s serial monitor. So at this point the behavior follows what I saw when the COM5 device was present.
But now when I do a flash upload it auto-detects COM10! I removed the COM10 USB device and flash Upload correctly auto-detects COM4.
No. 4 The Lolin D32 Pro uses a CH340 that has VID=1A86 and PID=7523. As an experiment, I edited the build section of the d32_pro board.json file and added the USB ID’s as follows:
"hwids": [
[
"0x1A86",
"0x7523"
]
],
"ldscript": "esp32_out.ld",
This did not change anything, all observed symptoms remained the same.
No. 5
As an alternate method to what was described in No. 4 (see above), I also tried using scripting to override the board configuration. In platformio.ini I added this line to the [env:lolin_d32_pro] section:
extra_scripts = pre:custom_hwids.py
I also added the custom_hwids.py file to the project’s main folder. The file contained this code:
Import("env")
board_config = env.BoardConfig()
board_config.update("build.hwids", [
"0x1A86", #VIDS
"0x7523" #PIDS
])
Results were the same as No. 4, all observed symptoms remained the same.
Expected Results
The intended action is that Upload and Serial Monitor should auto-detect the COMx. {For convenience, a properly working auto-detection would avoid keyboard entry to choose the port. And my use case involves an open source project that is intended to be shared; So requiring special user edits to the platformio.ini to workaround the issue should be avoided.}
Issue Analytics
- State:
- Created 4 years ago
- Comments:22 (10 by maintainers)
Thanks for the heads-up!
@thomastech You don’t have to wait long… it’s already been released! 😉 https://community.platformio.org/t/platformio-core-4-2/11980