Main task ended - COM port not available

Jorgen
Posts: 40
Joined: Fri Dec 09, 2022 11:39 am

Main task ended - COM port not available

Postby Jorgen » Tue Mar 26, 2024 2:21 pm

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

ESP_bignacio
Posts: 214
Joined: Wed May 02, 2018 12:12 pm

Re: Main task ended - COM port not available

Postby ESP_bignacio » Wed Mar 27, 2024 6:05 am

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.

ESP_kondalkolipaka
Posts: 161
Joined: Wed Jul 17, 2019 5:26 pm

Re: Main task ended - COM port not available

Postby ESP_kondalkolipaka » Wed Mar 27, 2024 6:07 am

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

Jorgen
Posts: 40
Joined: Fri Dec 09, 2022 11:39 am

Re: Main task ended - COM port not available

Postby Jorgen » Wed Mar 27, 2024 2:25 pm

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

chegewara
Posts: 2240
Joined: Wed Jun 14, 2017 9:00 pm

Re: Main task ended - COM port not available

Postby chegewara » Thu Mar 28, 2024 3:54 am

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)?

Jorgen
Posts: 40
Joined: Fri Dec 09, 2022 11:39 am

Re: Main task ended - COM port not available

Postby Jorgen » Thu Mar 28, 2024 9:47 am

It is an ESP32-S3-DevKitC-1. I use the USB - UART port on the DevKitC.

Jorgen
Posts: 40
Joined: Fri Dec 09, 2022 11:39 am

Re: Main task ended - COM port not available

Postby Jorgen » Thu Mar 28, 2024 4:43 pm

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

chegewara
Posts: 2240
Joined: Wed Jun 14, 2017 9:00 pm

Re: Main task ended - COM port not available

Postby chegewara » Fri Mar 29, 2024 3:21 am

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.

Who is online

Users browsing this forum: No registered users and 82 guests