Page 1 of 1

Main task ended - COM port not available

Posted: Tue Mar 26, 2024 2:21 pm
by Jorgen
Dear,
I use VS Code + esp-idf extension on a Windows 11 PC.

I start the VS Code. Then I run "idf.py fullclean", "idf.py build" and "idf.py flash monitor". This is successful and the last line on the terminal shows the project has completed and returned from app_main(). COM5 was used.

Then I edit the project and save it. I run again "idf.py fullclean" and "idf.py build" successfully. The I run "idf.py flash monitor" which fails. The output on the terminal is:
===
Executing action: flash
Serial port COM5
COM5 failed to connect: Could not open COM5, the port is busy or doesn't exist.
(could not open port 'COM5': PermissionError(13, 'Access is denied.', None, 5))

Hint: Check if the port is not used by another task

No serial ports found. Connect a device, or use '-p PORT' option to set a specific port.
===
Why is COM5 not available?
I believe, I by accident have made a key combination, that has set something such that COM5 is not freed at the end of the execution. Shortly after installing VS Code and esp-idf extension, the COM port was freed at the end of the execution of a project. The COM port is freed when I close VS-Code and re-start it, but that is a clumsy way of working.

How do I get the development environment to free the COM port at the end of execution of a project?

Regards,
Jorgen

Re: Main task ended - COM port not available

Posted: Wed Mar 27, 2024 6:05 am
by ESP_bignacio
Probably because you are not ending the monitor session properly and COM5 is still in use. Make sure to close the monitor before (like running

Code: Select all

CTRL + ]
) for example.

Re: Main task ended - COM port not available

Posted: Wed Mar 27, 2024 6:07 am
by ESP_kondalkolipaka
Hi Jorgen,

As `idf.py flash monitor `command will flash it to the target and run the serial monitor. Please make sure you to close the processs/terminal before you run again

Thanks

Re: Main task ended - COM port not available

Posted: Wed Mar 27, 2024 2:25 pm
by Jorgen
Thanks for the suggestions.

I have tried Ctrl + ] and also Ctrl+T and Ctrl+X, but the COM is still occupied.

I use a Scandinavian keyboard on which the ] is the key combination Alt gr+9.

How can I stop the monitor except for Ctrl+] ?

How can I verify that the monitor is not running?

Regards,
Jorgen

Re: Main task ended - COM port not available

Posted: Thu Mar 28, 2024 3:54 am
by chegewara
You didnt say anything about hardware.
Is it devkit or custom PCB, is it esp32 or esp32S2/S3?
If S2/S3, is it connected to UART or USB port on devkit (assuming its devkit)?

Re: Main task ended - COM port not available

Posted: Thu Mar 28, 2024 9:47 am
by Jorgen
It is an ESP32-S3-DevKitC-1. I use the USB - UART port on the DevKitC.

Re: Main task ended - COM port not available

Posted: Thu Mar 28, 2024 4:43 pm
by Jorgen
I have found a workable solution.

When the project completes execution, then as the first thing press Ctrl+T followed by Ctrl+X. The word Done appears in the terminal window.

Still, the esp-idf closed down the monitor automatically earlier. A setting or something has changed its behavior such that the monitor keeps on running after the project completes execution.

What, where and how?

Regards,
Jorgen

Re: Main task ended - COM port not available

Posted: Fri Mar 29, 2024 3:21 am
by chegewara
With S3 i would say it is USB port, which disappears after flashing or at least change COMx, but you are using UART port, so its not the case.

Maybe try CTRL+T and CTRL+R after flashing, which should reboots esp32 and start fresh new logs.