(osx) device not automatically selected for lolin d32

Hi

I have the problem that my lolin d32 (esp32 based) is not detected from the devices.

When uploading I see the following error message:

Uploading .pioenvs/lolin_d32/firmware.bin
esptool.py v2.6
Traceback (most recent call last):
File “/Users/wkeller/.platformio/packages/tool-esptoolpy/esptool.py”, line 2959, in
Serial port /dev/cu.usbserial-1410
_main()
File “/Users/wkeller/.platformio/packages/tool-esptoolpy/esptool.py”, line 2952, in _main
main()
File “/Users/wkeller/.platformio/packages/tool-esptoolpy/esptool.py”, line 2652, in main
esp = chip_class(each_port, initial_baud, args.trace)
File “/Users/wkeller/.platformio/packages/tool-esptoolpy/esptool.py”, line 222, in init
self._port = serial.serial_for_url(port)
File “/Users/wkeller/.platformio/penv/lib/python2.7/site-packages/serial/init.py”, line 88, in serial_for_url
instance.open()
File “/Users/wkeller/.platformio/penv/lib/python2.7/site-packages/serial/serialposix.py”, line 268, in open
raise SerialException(msg.errno, “could not open port {}: {}”.format(self._port, msg))
serial.serialutil.SerialException: [Errno 16] could not open port /dev/cu.usbserial-1410: [Errno 16] Resource busy: ‘/dev/cu.usbserial-1410’
*** [upload] Error 1

As a workaround I have to specify the usb port inside platformio.ini:
upload_port = /dev/cu.wchusbserial1410

For monitoring I see this message:

Available ports:
1: /dev/cu.Bluetooth-Incoming-Port ‘n/a’
2: /dev/cu.usbserial-1410 u’USB2.0-Serial’
3: /dev/cu.wchusbserial1410 u’USB2.0-Serial’
Enter port index or full name:

and I have to select 3.
As workaround I have to specify:

monitor_port = /dev/cu.wchusbserial1410

Nevertheless some time ago this worked like a charm on osx.

For windows I do not see this problem.

The issue starts to be nasty when I have to use the same project on windows and osx, which means comment and uncomment the workarounds every time.

some more info:
pio device list
/dev/cu.Bluetooth-Incoming-Port

Hardware ID: n/a
Description: n/a

/dev/cu.wchusbserial1410

Hardware ID: USB VID:PID=1A86:7523 LOCATION=20-1
Description: USB2.0-Serial

/dev/cu.usbserial-1410

Hardware ID: USB VID:PID=1A86:7523 LOCATION=20-1
Description: USB2.0-Serial

pio update -c
Checking tool-scons @ 2.20501.7 [Up-to-date]
Checking tool-unity @ 1.20403.0 [Up-to-date]
Checking contrib-pysite @ 2.27.190418 [Up-to-date]
Checking contrib-piohome @ 2.2.0 [Up-to-date]
Checking tool-pioplus @ 2.5.2 [Up-to-date]

Platform Manager

Platform Espressif 32

Checking espressif32 @ 1.9.0 [Up-to-date]
Checking tool-esptoolpy @ 1.20600.0 [Up-to-date]
Checking toolchain-xtensa32 @ 2.50200.80 [Up-to-date]
Checking framework-arduinoespressif32 @ 2.10002.190628 [Up-to-date]
Checking tool-mkspiffs @ 2.230.0 [Up-to-date]

Platform Espressif 8266

Checking espressif8266 @ 2.2.2 [Up-to-date]
Checking tool-esptoolpy @ 1.20600.0 [Up-to-date]
Checking tool-mkspiffs @ 1.200.0 [Up-to-date]
Checking tool-esptool @ 1.413.0 [Up-to-date]
Checking framework-arduinoespressif8266 @ 2.20502.0 [Up-to-date]
Checking toolchain-xtensa @ 2.40802.190218 [Up-to-date]

Library Manager

Is it normal for the Mac OS CH340 driver to create two /dev/cu.(wch/usb)serial devices? Did you modify any your system’s drivers or replaced them? With what?

to use the lolin I have had to install: CH34X USB-SERIAL driver.

I think it is normal that two devices are available - at least I recall so…

I’d suggest it’s not (going by the install instructions here… the first three steps are unloading and deleting the old drivers… maybe you missed doing that?). Might be a good idea to go back and delete the /dev/cu.usbserial-1410 instance since it appears /dev/cu.wchusbserial1410 is the updated driver? Also, I’m pretty sure you can list both Linux/Windows serial paths for both monitor and uploading, and PlatformIO will work it out… so you should be able to do the same for platformIO. Just do a second entry for the other OS.

i.e. on Windows, the following works just fine… PlatformIO automatically uses the COM4 port.

upload_port = /dev/ttyUSB0
upload_port = COM4

HI

thanks for the hints.
To update the problem description:

  • It was working some time ago (2-3 months) - not sure how long ago, but the drivers on osx have not been changed since then.
  • all that was updated is platformio and the visual studio code together with the esp tool chain
  • I removed the /dev from osx to be sure that this is not the problem, no change in behavior, osx will detrect the lolin device and recreate them again
  • when specifying the port in .ini it works, which would indicate in my opinion that the driver is not the problem, but the auto detecting mechanism

when looking at the log I see that the esptool.py trys to connect using cu.usbserial-1410 but this is wrong and will never work. it should use the cu.wchusbserial1410. this can be overwriten by the ini file (which is the workaround so far)

thx for your interest

If you have the device being enumerated twice (or it seems, four times… two tty devices, two cu devices?!), is that not the drivers fault? It sounds like auto-detection is working just fine, just the first matching device it finds is somehow misconfigured or being kept in use by something.

In the last few months, the platformio ESP32 package has updated to use the esptool.py included with the Arduino core… So ultimately, the question should perhaps be “does PlatformIO actually specify the serial port esptool.py uses (if not manually configured in your platformio.ini)?” If it does (which it does on Windows - can be verified by doing a verbose upload and checking if the port is specified for the upload command), perhaps something better could be done for Mac with CH340s… or it doesn’t… you’ll need to take that up with the Arduino ESP32 devs…

@ivankravets or someone else, does anyone have a Mac OS for reference with a working CH340 driver? Is there one created device or two? I somehow doubt that it’s two…

1 Like

did some more testing:

removed the serial kernel driver (according to manual: rm -rf …) and back to system default:

  • device list

pio device list
/dev/cu.Bluetooth-Incoming-Port

Hardware ID: n/a
Description: n/a

/dev/cu.usbserial-1410

Hardware ID: USB VID:PID=1A86:7523 LOCATION=20-1
Description: USB2.0-Serial

  • upload attempt:

Uploading .pioenvs/lolin_d32/firmware.bin
esptool.py v2.6
Serial port /dev/cu.usbserial-1410
Connecting…
Chip is ESP32D0WDQ6 (revision 1)
Features: WiFi, BT, Dual Core, 240MHz, VRef calibration in efuse, Coding Scheme None
MAC: 3c:71:bf:0c:f7:68
Uploading stub…
Running stub…
Stub running…
Changing baud rate to 921600
Changed.
Configuring flash size…

A fatal error occurred: Timed out waiting for packet header
*** [upload] Error 2

  • installing v1.5 of the ch340 driver
  • device list

pio device list
/dev/cu.Bluetooth-Incoming-Port

Hardware ID: n/a
Description: n/a

/dev/cu.wchusbserial1410

Hardware ID: USB VID:PID=1A86:7523 LOCATION=20-1
Description: USB2.0-Serial

/dev/cu.usbserial-1410

Hardware ID: USB VID:PID=1A86:7523 LOCATION=20-1
Description: USB2.0-Serial

  • upload attempt:

Serial port /dev/cu.usbserial-1410
Traceback (most recent call last):
File “/Users/wkeller/.platformio/packages/tool-esptoolpy/esptool.py”, line 2959, in
_main()
File “/Users/wkeller/.platformio/packages/tool-esptoolpy/esptool.py”, line 2952, in _main
main()
File “/Users/wkeller/.platformio/packages/tool-esptoolpy/esptool.py”, line 2652, in main
esp = chip_class(each_port, initial_baud, args.trace)
File “/Users/wkeller/.platformio/packages/tool-esptoolpy/esptool.py”, line 222, in init
self._port = serial.serial_for_url(port)
File “/Users/wkeller/.platformio/penv/lib/python2.7/site-packages/serial/init.py”, line 88, in serial_for_url
instance.open()
File “/Users/wkeller/.platformio/penv/lib/python2.7/site-packages/serial/serialposix.py”, line 268, in open
raise SerialException(msg.errno, “could not open port {}: {}”.format(self._port, msg))
serial.serialutil.SerialException: [Errno 16] could not open port /dev/cu.usbserial-1410: [Errno 16] Resource busy: ‘/dev/cu.usbserial-1410’
*** [upload] Error 1

my conclusion out of this would be

  • the instructions remove the old driver is refering to the old ch340 driver installed before and not any osx apple driver
  • osx is installing one device and the ch340 driver is installing the other
  • platformio or the esptool seems to choose the first one (which is the one from plain osx) and this one is the not working one

question would be from my side where to dig deeper, checking the esptool.py changes?

That’s pretty much what my research was indicating… that two (or even four) instances of the device were present… 2x cu. and 2x tty.… and as you say… one from the Apple drivers, and one from the CH340 driver.

I think the issue here is on the Mac, PlatformIO needs to do more than a simple VID/PID check, but also look at the device name… i.e. usbserial vs wchusbserial, and pick the latter, not the former.

what makes me wonder is that it has been working some month ago.

also what makes things complicated:

  • I have to specify a separate port per usb port on my laptop (either cu.wchusbserial1410 or cu.wchusbserial1420 - and for the PC COM4)
  • also here only the first will be chosen, the order matters

as a consequence I have to joggle a little around with the platform.ini depending on which port I use and which OS.

I don’t have any ideas :frowning: All my boards are SiLab based.

I got CH34X based board. This official driver works well http://www.wch.cn/download/CH341SER_MAC_ZIP.html

And you only see one /dev/cu.wchusbserial1410 device and no /dev/cu.usbserial-1410 device?

this is the same I have installed.
removing the driver I get one serial device, installing it again I got two

Yes, it only /dev/cu.wchusbserialfa140. Should I see 2?

No, but OP sees two and one and the other one doesn’t work. Then I’m sure there’s a problem with the combination of installed drivers / kernel extension @jipp, can you try again from scratch to just the get the chinese CH34X driver to work without the broken Mac driver.

Did you remove default Serial driver?

sudo rm -rf /System/Library/Extensions/usbserial.kext

Hi

running osx 10.14.5 Mojave.
the driver is installed in /Library/Extensions/ (this is not the apple driver, but the CH34x)
when removing is I only see the following device:

/dev/cu.usbserial-1410

(the ch-one is missing now)

when installing the driver you liked to I see the old situation again.

which osx are you running on?

Again: Did you remove default Serial driver?

Tried to figure out how to remove the apple native driver, but did not find any hint.
Remove command listed above only removed the 3rd party one.