microsoft / WSL

Issues found on WSL
https://docs.microsoft.com/windows/wsl
MIT License
17.42k stars 823 forks source link

Issue access an ESP32 from WSL #3795

Closed apuder closed 9 months ago

apuder commented 5 years ago

In the past I was able to access an ESP32 from WSL. I haven't done it in a while but now I'm having issues flashing. I'm using Window 10 pro, version 1809, OS build 17763.253. I have Silicon Labs CP210x USB to UART Bridge installed (driver version 10.1.4.2290). Windows reports the device to be working on COM11. I have an ESP32 connected and I can use putty to successfully connect to it via COM11. However, I cannot access it from WSL:

ls -l /dev/ttyS11
crw-rw-rw- 1 root dialout 4, 75 Jan 21 09:57 /dev/ttyS11

python
Python 2.7.12 (default, Nov 12 2018, 14:36:49)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import serial
>>> ser = serial.Serial('/dev/ttyS11')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/dist-packages/serial/serialutil.py", line 180, in __init__
self.open()
File "/usr/lib/python2.7/dist-packages/serial/serialposix.py", line 294, in open
raise SerialException(msg.errno, "could not open port %s: %s" % (self._port, msg))
serial.serialutil.SerialException: [Errno 5] could not open port /dev/ttyS11: [Errno 5] Input/output error: '/dev/ttyS11'

strace stty -F /dev/ttyS11 -a
execve("/bin/stty", ["stty", "-F", "/dev/ttyS11", "-a"], [/* 22 vars */]) = 0
brk(NULL)                               = 0xdb6000
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
access("/etc/ld.so.preload", R_OK)      = -1 ENOENT (No such file or directory)
open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=81878, ...}) = 0
mmap(NULL, 81878, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f025a1c0000
close(3)                                = 0
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
open("/lib/x86_64-linux-gnu/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\3\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0P\t\2\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0755, st_size=1868984, ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f025a1b0000
mmap(NULL, 3971488, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f0259a30000
mprotect(0x7f0259bf0000, 2097152, PROT_NONE) = 0
mmap(0x7f0259df0000, 24576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1c0000) = 0x7f0259df0000
mmap(0x7f0259df6000, 14752, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f0259df6000
close(3)                                = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f025a1a0000
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f025a190000
arch_prctl(ARCH_SET_FS, 0x7f025a1a0700) = 0
mprotect(0x7f0259df0000, 16384, PROT_READ) = 0
mprotect(0x610000, 4096, PROT_READ)     = 0
mprotect(0x7f025a025000, 4096, PROT_READ) = 0
munmap(0x7f025a1c0000, 81878)           = 0
brk(NULL)                               = 0xdb6000
brk(0xdd7000)                           = 0xdd7000
open("/usr/lib/locale/locale-archive", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=1668976, ...}) = 0
mmap(NULL, 1668976, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f0259e8d000
close(3)                                = 0
open("/dev/ttyS11", O_RDONLY|O_NONBLOCK) = -1 EIO (Input/output error)
write(2, "stty: ", 6stty: )                   = 6
write(2, "/dev/ttyS11", 11/dev/ttyS11)             = 11
open("/usr/share/locale/locale.alias", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=2995, ...}) = 0
read(3, "# Locale name alias data base.\n#"..., 4096) = 2995
read(3, "", 4096)                       = 0
close(3)                                = 0
open("/usr/share/locale/en_US.UTF-8/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale/en_US.utf8/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale/en_US/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale/en.UTF-8/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale/en.utf8/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale/en/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale-langpack/en_US.UTF-8/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale-langpack/en_US.utf8/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale-langpack/en_US/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale-langpack/en.UTF-8/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale-langpack/en.utf8/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale-langpack/en/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
write(2, ": Input/output error", 20: Input/output error)    = 20
write(2, "\n", 1
)                       = 1
close(1)                                = 0
close(2)                                = 0
exit_group(1)                           = ?
+++ exited with 1 +++

Any suggestions?

kammce commented 5 years ago

:+1: I have the same problem with a board that uses CP2102n chip. Works flawlessly in Windows 10, but isn't detected in WSL.

varunmadhavam commented 5 years ago

Hi, i am also facing the same issue. Can connect using putty from windows to esp32 but from wsl it gives IO error.

varun@DESKTOP-SRI1M21:/dev$ sudo cu -l /dev/ttyS6 -s 115200
cu: open (/dev/ttyS6): Input/output error
cu: /dev/ttyS6: Line in use
oouti commented 5 years ago

Hi Silicon Labs Virtual COM Port (VCP) Universal Driver for Windows 10 version 10.1.4 does not work. But Silicon Labs Virtual COM Port (VCP) driver for Windows version: 6.7.6 works on windows 10.

formus14 commented 5 years ago

Same issue, its could not open the port ... its shows that the port is always busy !

i tried flashing the code on the same port using Visual GDB instead of WSL and it worked pretty fine though ;)

Serial port /dev/ttyS11
Traceback (most recent call last):
File "/mnt/c/temp/IDFS/IDF-3.2/esp-idf/components/esptool_py/esptool/esptool.py", line 2959, in
_main() File "/mnt/c/temp/IDFS/IDF-3.2/esp-idf/components/esptool_py/esptool/esptool.py", line 2952, in _main
main() File "/mnt/c/temp/IDFS/IDF-3.2/esp-idf/components/esptool_py/esptool/esptool.py", line 2652, in main esp = chip_class(each_port, initial_baud, args.trace)
File "/mnt/c/temp/IDFS/IDF-3.2/esp-idf/components/esptool_py/esptool/esptool.py", line 222, in init self._port = serial.serial_for_url(port)
File "/usr/lib/python2.7/dist-packages/serial/init.py", line 85, in serial_for_url
instance.open()
File "/usr/lib/python2.7/dist-packages/serial/serialposix.py", line 294, in open
raise SerialException(msg.errno, "could not open port %s: %s" % (self._port, msg))
serial.serialutil.SerialException: [Errno 5] could not open port /dev/ttyS11: [Errno 5] Input/output error: '/dev/ttyS11'

/mnt/c/temp/IDFS/IDF-3.2/esp-idf/components/esptool_py/Makefile.projbuild:62: recipe for target 'flash' failed make: *** [flash] Error 1

oouti commented 5 years ago

I think it's a problem of cp210x driver. Please refer https://www.silabs.com/community/interface/forum.topic.html/cp210x_registry_entr-11Kf. or use pololu's CP2102 USB-to-Serial Bridge Driver

USPR commented 5 years ago

Solution with my ESP32 dev board: The older Windows 7/8/8.1 drivers from Silabs work. I can cat /dev/ttyS5 now and see the messages on RxD.

Problem with cu: How can I tell cu to leave RTS and CTS alone? These pins are connected to the RST and BOOT buttons and are used to initiate flashing the device. As soon as I start cu, the ESP32 LED stops, when I exit cu, the LED resumes blinking (a demo program that outputs a hello message and flashes the LED every second).

benluxford commented 5 years ago

CONFIRMED: CP210x Driver issue, rollback to v6.7.6 resolves the issue.

Also - for good measure sudo chmod 0666 /dev/ttyS11 or your port number

mrwiora commented 4 years ago

great work thanks! older driver version works perfectly for me. In case you get something like:

$ idf.py -p /dev/ttyS11 flash
...
[100%] Built target app
esptool.py --chip esp32 -p /dev/ttyS11 -b 460800 --before=default_reset --after=hard_reset write_flash --flash_mode dio --flash_freq 40m --flash_size 2MB 0x8000 partition_table/partition-table.bin 0x1000 bootloader/bootloader.bin 0x10000 hello-world.bin
esptool.py v3.0-dev
Serial port /dev/ttyS11
Connecting....
Chip is ESP32D0WDQ5 (revision 1)
Features: WiFi, BT, Dual Core, 240MHz, VRef calibration in efuse, Coding Scheme None
Crystal is 40MHz
MAC: c4:4f:33:17:0b:39
Uploading stub...
Running stub...
Stub running...
Changing baud rate to 460800
Changed.
Configuring flash size...

A fatal error occurred: Timed out waiting for packet header
CMake Error at run_cmd.cmake:14 (message):
  esptool.py failed
Call Stack (most recent call first):
  run_esptool.cmake:21 (include)

make[3]: *** [CMakeFiles/flash.dir/build.make:57: CMakeFiles/flash] Error 1
make[2]: *** [CMakeFiles/Makefile2:1892: CMakeFiles/flash.dir/all] Error 2
make[1]: *** [CMakeFiles/Makefile2:1899: CMakeFiles/flash.dir/rule] Error 2
make: *** [Makefile:190: flash] Error 2
make failed with exit code 2

like I did - try to reduce the baudrate: $ idf.py -p /dev/ttyS11 -b 115200 flash Referencing unresolved topic https://github.com/espressif/esp-idf/issues/4936

therealkenc commented 3 years ago

RS-232 on WSL2 is LZ #4322

jeronimonunes commented 3 years ago

I've got the same problem using CH340 drivers

microsoft-github-policy-service[bot] commented 9 months ago

This issue has been automatically closed since it has not had any activity for the past year. If you're still experiencing this issue please re-file this as a new issue or feature request.

Thank you!