Can't upload any sketch using visual code (Errno 16) Resource busy on Mac OS

I just cant upload any sketch (VS code, Mac OS). I’ve tried normal upload and verbose, changing ports, reboots, rebuilds, terminal command lsof | grep etc… I still can upload sketches using Arduino IDE, so I don’t know whats the problem with platformio…
Thank you kindly for your answers!

> Executing task in folder geek-watches-display: platformio run --target upload <

Processing nanoatmega328 (platform: atmelavr; board: nanoatmega328; framework: arduino)
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/atmelavr/nanoatmega328.html
PLATFORM: Atmel AVR > Arduino Nano ATmega328
HARDWARE: ATMEGA328P 16MHz 2KB RAM (30KB Flash)
Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF MODES: FINDER(chain) COMPATIBILITY(soft)
Collected 25 compatible libraries
Scanning dependencies...
Dependency Graph
|-- <ShiftDisplay> 3.6.1
Checking size .pioenvs/nanoatmega328/firmware.elf
Memory Usage -> http://bit.ly/pio-memory-usage
DATA:    [=         ]   6.7% (used 137 bytes from 2048 bytes)
PROGRAM: [=         ]   7.5% (used 2310 bytes from 30720 bytes)
Configuring upload protocol...
AVAILABLE: arduino
CURRENT: upload_protocol = arduino
Looking for upload port...
Auto-detected: /dev/cu.usbserial-1420
*** [upload] could not open port /dev/cu.usbserial-1420: [Errno 16] Resource busy: '/dev/cu.usbserial-1420'
=============================================================================================== [ERROR] Took 0.82 seconds ===============================================================================================
The terminal process terminated with exit code: 1

Terminal will be reused by tasks, press any key to close it.
1 Like

Do you have the serial monitor open when trying to upload the sketch? You must close the serial monitor then.

Does re-plugging the Nano help?

Thanks for reply! Of course I didn’t have the serial monitor open. And I tried to change usb ports, nothing helped yet

What does lsof /dev/cu.usbserial-1420 output before you try to upload? Is this also the same serial port you’re using with Arduino IDE? Does closing the Arduino IDE before trying to upload make a difference?

Guessing perhaps the auto-port detection doesn’t quite work for macOs. Edit your platformio.ini and add:
upload_port = /dev/cu.wchusbserial1420

While you’re there, you might also verify that you have the correct upload speed. For my ESP8266 board I had to use 115,200 baud, as the default was causing a timeout error.
upload_speed = 115200

2 Likes

Upgraded from MacOS 10.13: High Sierra to MacOS 10.14 and encountered this error. Specifying the upload port in my platform.io fixed the problem. Thanks @fenbranklin!

Glad to hear it worked for you! Happy to say that since I fixed this issue a year ago, my Arduino project has been sitting in a box outside, reporting in every hour through all four seasons!

Hi @samgozman

Did you get to solve your problem?

I have the same problem with a ESP32

--- Available filters and text transformations: colorize, debug, default, direct, esp32_exception_decoder, hexlify, log2file, nocontrol, printable, send_on_enter, time
--- More details at http://bit.ly/pio-monitor-filters
could not open port '/dev/cu.SLAB_USBtoUART': [Errno 16] could not open port /dev/cu.SLAB_USBtoUART: [Errno 16] Resource busy: '/dev/cu.SLAB_USBtoUART'
The terminal process "platformio 'device', 'monitor', '--environment', 'wemosbat'" terminated with exit code: 1.

I only use Visual Code with PlatformIO, tried many suggestions: disconnect and connect USB cable, close terminals, reset Visual Code, kextunload, googled at many sites and nothing.

Suddenly, I don’t know why, I got upload the bin or open the serial monitor. But when I need to connect to serial port again, the port is busy.

Isn’t there any way to reset the serial port?

All the best

See Mac USB port detected but won’t upload - #2 by manuelbl

@manuelbl, I will answer your question here, 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:

Very strange. According to this list, you don’t have a driver for your board. Does it still appear as /dev/cu.SLAB_USBtoUART when plugged in?

If so, show the output of:

ls -l /Library/Extensions

Hi @manuelbl,

After remove the library, as you suggested:

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

nothing happens when I plugged the board:

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

/dev/cu.SLAB_USBtoUART only appear if I install Silabs driver and plug the board.

$ ls -l /Library/Extensions/  # after remove Silabs Driver
total 0
drwxr-xr-x  3 root  wheel  102 Apr 24  2018 ACS6x.kext
drwxr-xr-x  3 root  wheel  102 May  8  2018 ATTOCelerityFC8.kext
drwxr-xr-x  3 root  wheel  102 May  7  2018 ATTOExpressSASHBA2.kext
drwxr-xr-x  3 root  wheel  102 May  7  2018 ATTOExpressSASRAID2.kext
drwxr-xr-x  3 root  wheel  102 Sep  6  2017 ArcMSR.kext
drwxr-xr-x  3 root  wheel  102 Apr 15 15:09 CP210xVCPDriver.app
drwxr-xr-x  3 root  wheel  102 Sep  1  2013 CalDigitHDProDrv.kext
drwxr-xr-x  3 root  wheel  102 May  3  2018 HighPointIOP.kext
drwxr-xr-x  3 root  wheel  102 Dec  5  2017 HighPointRR.kext
drwxr-xr-x  3 root  wheel  102 Mar 31  2017 PromiseSTEX.kext
drwxr-xr-x  3 root  wheel  102 Apr 24  2018 SoftRAID.kext
drwxr-xr-x  3 root  wheel  102 Nov  5  2015 SteamInput.kext
drwxr-xr-x  3 root  wheel  102 May  8  2015 TACC.kext
drwxr-xr-x  3 root  wheel  102 Aug 14  2013 hp_io_enabler_compound.kext
drwxr-xr-x  3 root  wheel  102 Jul  4  2018 usbserial.kext
$ ls -l /Library/Extensions/ # after reinstall Silabs driver
total 0
drwxr-xr-x  3 root  wheel  102 Apr 24  2018 ACS6x.kext
drwxr-xr-x  3 root  wheel  102 May  8  2018 ATTOCelerityFC8.kext
drwxr-xr-x  3 root  wheel  102 May  7  2018 ATTOExpressSASHBA2.kext
drwxr-xr-x  3 root  wheel  102 May  7  2018 ATTOExpressSASRAID2.kext
drwxr-xr-x  3 root  wheel  102 Sep  6  2017 ArcMSR.kext
drwxr-xr-x  3 root  wheel  102 Apr 15 15:09 CP210xVCPDriver.app
drwxr-xr-x  3 root  wheel  102 Sep  1  2013 CalDigitHDProDrv.kext
drwxr-xr-x  3 root  wheel  102 May  3  2018 HighPointIOP.kext
drwxr-xr-x  3 root  wheel  102 Dec  5  2017 HighPointRR.kext
drwxr-xr-x  3 root  wheel  102 Mar 31  2017 PromiseSTEX.kext
drwxr-xr-x@ 3 root  wheel  102 Mar 25 08:23 SiLabsUSBDriver.kext
drwxr-xr-x  3 root  wheel  102 Apr 24  2018 SoftRAID.kext
drwxr-xr-x  3 root  wheel  102 Nov  5  2015 SteamInput.kext
drwxr-xr-x  3 root  wheel  102 May  8  2015 TACC.kext
drwxr-xr-x  3 root  wheel  102 Aug 14  2013 hp_io_enabler_compound.kext
drwxr-xr-x  3 root  wheel  102 Jul  4  2018 usbserial.kext

It’s important to notice that I get upload and open serial monitor with SiLabs driver. The problem is if I try to upload or open monitor several times. Example: I upload the binary to the board, if I try to open serial monitor, I need to repeat the process: unplug, plug, until Error 16 (Resource Busy) disappear. And I cannot identify what exactly happens before I got the connection.

I’ve already tried to

# unplug the board
sudo kextunload /Library/Extensions/SiLabsUSBDriver.kext/
sudo kextload /Library/Extensions/SiLabsUSBDriver.kext/
# plug the board

But even with this procedure I got resource busy error (but as I said before, some times it works).

Doing more testes, in some times I cannot unload driver even with board disconnected

# unplug the board
$ 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 1 instance.
Failed to unload com.silabs.driver.CP210xVCPDriver - (libkern/kext) kext is in use or retained (cannot unload).

That’s valuable information and a new perspective. So it has been working but not consistently.

So my conclusion would be: You need the proprietary SiLabs drivers and they are working. The cause of the “Resource busy” problem is that a program does not properly release the serial port when it’s done. Possibly, the program is stuck.

Am I correct in assuming you are accessing the serial port with PlatformIO tools only: upload from PlatformIO, serial monitor of PlatformIO, possibly debugging from PlatformIO? Are you using PlatformIO from within Visual Studio Code?

If so: In a typical cycle of upload, monitor, upload, monitor: Is it always the upload action that fails? Or can it affect the serial monitor as well?

Hi @manuelbl

Yes I’m using Platform IO within Visual Studio Code.

Digging some solution, I found out a folder named Troubleshooting in dmg file downloaded form Silabs site.

Inside this folder there is another package. So before installing it, I removed all references to installed driver, and reboot the system.

I Installed it (the screen installations is bit different than other), and reboot the system again.

So far, it’s working well. I get upload, open serial monitor, several times in a row, without unplug the board.