visual-studio-codeesp-idf

How to automatically close the Monitor terminal in VSC before programming the target


Visual Studio Code v1.91.1 with ESP-IDF v1.8.0 extension. The user can Build, Flash and Monitor the current code click on the "flame" icon on the bottom bar:

Build Flash and Monitor

If the Monitor terminal is already open (i.e. from the previous run) the flashing fails because the serial port is busy:

[Flash]
Failed to flash because of some unusual error. Check Terminal for more details

Normally I have to remember to manually close the Monitor terminal before asking for a new Build/Flash/Monitor action.

Is there a way to tell the extension to close the Monitor terminal (or the serial port) before programming the target automatically?


Solution

  • I was also dealing with this issue and just figured out a solution!

    Fix: Add this to your settings.json file:

    "idf.preFlashTask": "echo \"Flashing...\""
    

    The build, flash monitor button tries to close the monitor before flashing, but is too slow so the serial port doesn't close in time. Adding the echo adds a tiny delay before flashing so the monitor serial connection can properly close before the flashing starts.