PlatformIO Community

Access defined when programming ESP32 over serial port

I seem to always have issues from the second time of programming my ESP32 onwards. This first time I click the PlatformIO:Upload button in VSCODE it programs the device without problems but if I change and recompile the code and hit the button again I invariably get this error:

Linking .pio\build\view\firmware.elf
Retrieving maximum program size .pio\build\view\firmware.elf
Checking size .pio\build\view\firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [=         ]   5.2% (used 16960 bytes from 327680 bytes)
Flash: [===       ]  26.4% (used 345818 bytes from 1310720 bytes)
Building .pio\build\view\firmware.bin v3.1
Merged 1 ELF section
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...
Auto-detected: COM3
Uploading .pio\build\view\firmware.bin v3.1
Serial port COM3
Traceback (most recent call last):
  File "C:\Users\mail\.platformio\packages\tool-esptoolpy@1.30100.210531\", line 4582, in <module>
  File "C:\Users\mail\.platformio\packages\tool-esptoolpy@1.30100.210531\", line 4575, in _main
  File "C:\Users\mail\.platformio\packages\tool-esptoolpy@1.30100.210531\", line 4074, in main
    esp = esp or get_default_connected_device(ser_list, port=args.port, connect_attempts=args.connect_attempts,
  File "C:\Users\mail\.platformio\packages\tool-esptoolpy@1.30100.210531\", line 120, in get_default_connected_device
    _esp = chip_class(each_port, initial_baud, trace)
  File "C:\Users\mail\.platformio\packages\tool-esptoolpy@1.30100.210531\", line 313, in __init__
    self._port = serial.serial_for_url(port)
  File "C:\Users\mail\.platformio\penv\lib\site-packages\serial\", line 90, in serial_for_url
  File "C:\Users\mail\.platformio\penv\lib\site-packages\serial\", line 64, in open
    raise SerialException("could not open port {!r}: {!r}".format(self.portstr, ctypes.WinError()))
serial.serialutil.SerialException: could not open port 'COM3': PermissionError(13, 'Access is denied.', None, 5)
*** [upload] Error 1
========================================================================================= [FAILED] Took 9.38 seconds =========================================================================================
Environment    Status    Duration
-------------  --------  ------------
view           FAILED    00:00:09.384

If I keep clicking the Upload button it will eventually work.

Any thoughts on what might be happening?


I have come across another thread where the poster talked about changing the port to a higher number and that has fixed this issue for me - I changed COM3 to COM20 in device manager and have not seen this issue again.