PlatformIO Community

Mac USB port detected but won’t upload

I’m referring to this topic: Mac USB port detected but won't upload - #12 by pfeerick

Same problem here: “Error message says resource busy”.
“sudo ls -l /System/Library/Extensions/usbserial.kext” reports no file there.

How can I see whether there’s :“Is a previous upload attempt still stuck in the background?”

This is my first attempt to use PIO. I closed down all Arduino stuff, where uploads were no problem at all.
Any help is very welcome!

Output from compiler:
Looking for upload port…
Auto-detected: /dev/cu.usbserial-0001
Uploading .pio/build/esp32doit-devkit-v1/firmware.bin
esptool.py v3.0
Traceback (most recent call last):
Serial port /dev/cu.usbserial-0001
File “/Users/janhkila/.platformio/penv/lib/python3.9/site-packages/serial/serialposix.py”, line 322, in open
self.fd = os.open(self.portstr, os.O_RDWR | os.O_NOCTTY | os.O_NONBLOCK)
OSError: [Errno 16] Resource busy: ‘/dev/cu.usbserial-0001’

Because this installation of PIO I also installed python3 and here seems to be “something rotten in the state of Denmark”.

In search for this: "File “/Users/janhkila/.platformio/penv/lib/python3.9/site-packages/serial/serialposix.py”, I discovered that the part: “site-packages/serial/serialposix.py”, is missing.

I re-installed python3 using brew, but no luck.

It has been a long and learned search, but the *.ini file did the trick!
upload_port = /dev/cu.SLAB_USBtoUART

I’m glad to see that you got it working. But you still have a problem with your installation and it will likely cause troubles in the future.

The problem is that you have two drivers for the same device, one from Apple and one from SiLabs. (I guess your board has a CP2102 USB-to-serial converter chip.) They create two devices under /dev/cu..., one working and one raising the resource busy error. PlatformIO happened to pick the wrong one.

The resolution is to uninstall the SiLabs driver. First find the location of the driver:

sudo ls -l /System/Library/Extensions/SiLabsUSBDriver.kext
sudo ls -l /Library/Extensions/SiLabsUSBDriver.kext

Then disable and remove it:

sudo kextunload /Library/Extensions/SiLabsUSBDriver.kext
sudo rm -rf /Library/Extensions/SiLabsUSBDriver.kext

This should solve the issue once and for all. And the upload_port line shouldn’t be needed anymore as PlatformIO will automatically detect the correct device.

Manuel,
Thank’s for responding.
In my original post you can see that I tried something similar.

Following you advice I did:
janhkila@imac-van-jan ~ % sudo ls -l /System/Library/Extensions/SiLabsUSBDriver.kext
Password:
ls: /System/Library/Extensions/SiLabsUSBDriver.kext: No such file or directory
janhkila@imac-van-jan ~ %

Well, that speaks for it selfs.
Are there other/more driver files that could cause this trouble?

In the original post I can see that you checked for usbserial.kext. That’s the driver for a WCH CH340G chip. But you seemt to have a board with an SiLabs chip.

And as proposed check in both /System/Library/Extensions and /Library/Extensions.

janhkila@imac-van-jan ~ % sudo ls -l /Library/Extensions
total 0

drwxr-xr-x 3 root wheel 96 17 mrt 2015 SiLabsUSBDriver.kext <== OK, THERE it is!
drwxr-xr-x 3 root wheel 96 21 apr 2020 SoftRAID.kext
janhkila@imac-van-jan ~ % sudo kextunload /Library/Extensions/SiLabsUSBDriver.kext
janhkila@imac-van-jan ~ % sudo rm -rf /Library/Extensions/SiLabsUSBDriver.kext
janhkila@imac-van-jan ~ % sudo ls -l /Library/Extensions
total 0

Now the file is gone, as expected.
drwxr-xr-x 3 root wheel 96 21 apr 2020 SoftRAID.kext
janhkila@imac-van-jan ~ %

Thank you for correcting me; I read only the first part of your instructions.

Hi @manuelbl,

I arrived here from the other thread about the same issue, through your suggestion to my question.

I’m using an ESP32 WeMos Bluetooth WiFi Battery Board (wemosbat) and sometimes I got upload or monitor the serial, sometimes I got the error:

Errno 16] could not open port /dev/cu.SLAB_USBtoUART: [Errno 16] Resource busy: '/dev/cu.SLAB_USBtoUART'

I tried to unload using kextunload, but it doesn’t work:

$ sudo kextunload /Library/Extensions/SiLabsUSBDriver.kext/
(kernel) Can't unload kext com.silabs.driver.CP210xVCPDriver; classes have instances:
(kernel)     Kext com.silabs.driver.CP210xVCPDriver class com_silabs_driver_CP210xVCPDriver has 4 instances.
Failed to unload com.silabs.driver.CP210xVCPDriver - (libkern/kext) kext is in use or retained (cannot unload).

I restarted the computer, and got unload and remove it

sudo kextunload /Library/Extensions/SiLabsUSBDriver.kext/
sudo rm -rf /Library/Extensions/SiLabsUSBDriver.kext/

But, when I try to upload or go to serial monitor:

Checking size .pio/build/wemosbat/firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [=         ]   9.8% (used 32180 bytes from 327680 bytes)
Flash: [======    ]  62.4% (used 654300 bytes from 1048576 bytes)
Configuring upload protocol...
AVAILABLE: esp-prog, espota, esptool, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa
CURRENT: upload_protocol = esptool
Looking for upload port...
Error: Please specify `upload_port` for environment or use global `--upload-port` option.
For some development platforms it can be a USB flash drive (i.e. /media/<user>/<device name>)
*** [upload] Explicit exit, status 1
================================================================================================== [FAILED] Took 19.17 seconds ==================================================================================================
The terminal process "platformio 'run', '--target', 'upload', '--environment', 'wemosbat'" terminated with exit code: 1.

It’s not possible find the device. But, if I go to System Information, I can see CP2102 USB to UART there:

Snap 2021-04-15 at 14.49.25

My question: when I got the error classes have instances in kextunload command, Can’t find out what the instances are and unload them one by one?

Thanks

According to your original error message and according to the system report screenshot, you have an MCU board with a SiLabs CP2102 USB-to-serial chip. And macOS can at least talk to the chip and read its description. However, PlatformIO cannot detect an appropriate serial device.

Can you check if macOS has created the serial device?

ls -l /dev/cu.usb*

It should display a device similar to:

crw-rw-rw-  1 root  wheel   22,   7 Apr 15 20:40 /dev/cu.usbserial-0001

Can you also check that you don’t have upload_port specified in platformio.ini. If you have, removed it.

Hi @manuelbl

No, after connect the board I got this:

ls -l /dev/cu.*
crw-rw-rw-  1 root  wheel   21,   1 Apr 15 15:19 /dev/cu.Bluetooth-Incoming-Port
crw-rw-rw-  1 root  wheel   21,  35 Apr 15 15:25 /dev/cu.SLAB_USBtoUART

When I disconnect the board, only /dev/cu.Bluetooth-Incoming-Port is displayed.

I don’t have upload_port in platform.io

[env:wemosbat]
platform = espressif32
board = wemosbat
framework = espidf
monitor_speed = 115200

You haven’t got rid of the outdated SiLabs drivers. Can you check both locations for drivers:

sudo ls -l /Library/Extensions/SiLabsUSB*
sudo ls -l /System/Library/Extensions/SiLabsUSB*

If one of the directories is present, unplug any boards and try again to remove them (after modifying the path as necessary):

sudo kextunload /Library/Extensions/SiLabsUSBDriver.kext/
sudo rm -rf /Library/Extensions/SiLabsUSBDriver.kext/

No reboot should be necessary, neither before the commands or after.

Hi @manuelbl

I’ve already tried this. When I remove the SiLabs, I cannot find the board:

$ ls -la /dev/cu*
crw-rw-rw-  1 root  wheel   21,   1 Apr 15 15:19 /dev/cu.Bluetooth-Incoming-Port

By the way, I’m using Mac OS High Sierra Version 10.13.6

EDITED

@manuelbl, I will answer your question (posted in the next reply) in this reply, due as new user I cannot post more than three replies in the same topic.

$ ls -l /Library/Extensions/*USB*
ls: /Library/Extensions/*USB*: No such file or directory

$ ls -l /System/Library/Extensions/*USB*
/System/Library/Extensions/AppleMIDIUSBDriver.plugin:
/System/Library/Extensions/AppleOSXUSBNCM.kext:
/System/Library/Extensions/AppleUSBACM.kext:
/System/Library/Extensions/AppleUSBAudio.kext:
/System/Library/Extensions/AppleUSBCDC.kext:
/System/Library/Extensions/AppleUSBCommon.kext:
/System/Library/Extensions/AppleUSBDMM.kext:
/System/Library/Extensions/AppleUSBDisplays.kext:
/System/Library/Extensions/AppleUSBECM.kext:
/System/Library/Extensions/AppleUSBEEM.kext:
/System/Library/Extensions/AppleUSBEthernet.kext:
/System/Library/Extensions/AppleUSBEthernetHost.kext:
/System/Library/Extensions/AppleUSBFTDI.kext:
/System/Library/Extensions/AppleUSBMultitouch.kext:
/System/Library/Extensions/AppleUSBNCM.kext:
/System/Library/Extensions/AppleUSBNetworking.kext:
/System/Library/Extensions/AppleUSBSerial.kext:
/System/Library/Extensions/AppleUSBTopCase.kext:
/System/Library/Extensions/AppleUSBWCM.kext:
/System/Library/Extensions/AppleUSBiBridge.kext:
/System/Library/Extensions/IOUSBAttachedSCSI.kext:
/System/Library/Extensions/IOUSBFamily.kext:
/System/Library/Extensions/IOUSBHostFamily.kext:
/System/Library/Extensions/IOUSBMassStorageClass.kext:
/System/Library/Extensions/IOUSBMassStorageDriver.kext:

What is the output of these commands:

ls -l /Library/Extensions/*USB*
ls -l /System/Library/Extensions/*USB*

macOS High Sierra isn’t exactly the latest version. I’m not sure the Apple driver for CP2102 was already included in that version. “Resource busy” usually indicates that two drivers (from Apple and SiLabs) are fighting for the same driver. But it might also be that the device is still open from another application like a serial monitor. Check that it is not the case.