PlatformIO Community

Erase flash on esp-01 always says Access Denied

Here is the output when I try to erase flash:

> Executing task in folder esp01-wifi-config: C:\Users\arun\.platformio\penv\Scripts\platformio.exe run --target erase <

Processing esp01_1m (platform: espressif8266; board: esp01_1m; framework: arduino)
----------------------------------------------------------------------------------------------------------------------------------------------------------

Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/espressif8266/esp01_1m.html
PLATFORM: Espressif 8266 2.5.3 > Espressif Generic ESP8266 ESP-01 1M
HARDWARE: ESP8266 80MHz, 80KB RAM, 1MB Flash
PACKAGES:
 - framework-arduinoespressif8266 3.20701.0 (2.7.1)
 - tool-esptool 1.413.0 (4.13)
 - tool-esptoolpy 1.20800.0 (2.8.0)
 - toolchain-xtensa 2.40802.200502 (4.8.2)
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 30 compatible libraries
Scanning dependencies...
Dependency Graph
|-- <WifiManager> 0.15.0
|   |-- <DNSServer> 1.1.1
|   |   |-- <ESP8266WiFi> 1.0
|   |-- <ESP8266WebServer> 1.0
|   |   |-- <ESP8266WiFi> 1.0
|   |-- <ESP8266WiFi> 1.0
|-- <DNSServer> 1.1.1
|   |-- <ESP8266WiFi> 1.0
|-- <ESP8266WebServer> 1.0
|   |-- <ESP8266WiFi> 1.0
|-- <ESP8266WiFi> 1.0
Building in release mode
Looking for serial port...
Auto-detected: COM5
Erasing...
esptool.py v2.8
Serial port COM5
Traceback (most recent call last):
  File "C:\Users\arun\.platformio\packages\tool-esptoolpy\esptool.py", line 3201, in <module>
    _main()
  File "C:\Users\arun\.platformio\packages\tool-esptoolpy\esptool.py", line 3194, in _main
    main()
  File "C:\Users\arun\.platformio\packages\tool-esptoolpy\esptool.py", line 2889, in main
    esp = chip_class(each_port, initial_baud, args.trace)
  File "C:\Users\arun\.platformio\packages\tool-esptoolpy\esptool.py", line 237, in __init__
    self._port = serial.serial_for_url(port)
  File "c:\users\arun\.platformio\penv\lib\site-packages\serial\__init__.py", line 88, in serial_for_url
    instance.open()
  File "c:\users\arun\.platformio\penv\lib\site-packages\serial\serialwin32.py", line 62, in open
    raise SerialException("could not open port {!r}: {!r}".format(self.portstr, ctypes.WinError()))
serial.serialutil.SerialException: could not open port 'COM5': PermissionError(13, 'Access is denied.', None, 5)
*** [erase] Error 1
=============================================================== [FAILED] Took 9.04 seconds ===============================================================
The terminal process terminated with exit code: 1

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

However, I am able to flash code onto it.