Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ESPEFUSE fails to free the COM port after operations (ESPTOOL-321) #671

Closed
javipelopi opened this issue Oct 6, 2021 · 3 comments
Closed

Comments

@javipelopi
Copy link

Hi,

When using a custom script on Python 3 to use both ESPEFUSE and ESPTOOL, once I burn a custom MAC using ESPEFUSE, I want to flash the ESP32 using ESPTOOL.

The issue is ESPEFUSE doesn't release the COM port, so when I call ESPTOOL, it raises:

Unexpected error: could not open port 'COM5': PermissionError(13, 'Access is denied.', None, 5)

I believe, puting this line on the end of ESPEFUSE would solve the issue, however, I don't know if there is another way of doing this.

esp._port.close()

If there is a proper way of doing this without editing ESPEFUSE, please, let me know. Otherwise, could you fix it?

Thanks in advance,

@github-actions github-actions bot changed the title ESPEFUSE fails to free the COM port after operations ESPEFUSE fails to free the COM port after operations (ESPTOOL-321) Oct 6, 2021
@radimkarnis
Copy link
Collaborator

Hello @javipelopi,
both espefuse and esptool are designed to be primarily run as command-line applications, so accessing their functions directly in a custom python script may result in the port not being released.

Is it possible to add esp._port.close() directly to your script or to pass an existing esp object so the port doesn't have to be closed and reopen?

By the way, there is a new option to execute espefuse operations in a custom python script, it may be suitable for your use case.

@javipelopi
Copy link
Author

Hi @radimkarnis

espefuse doesn't accept an existing esp object as I am calling it like this:

espefuse.main(['--port', com_port, '-c', 'esp32', 'burn_custom_mac', mac_number, '--do-not-confirm'])

I believe, that executing espefuse operations in a custom script can be done manually step by step and pass an esp object, however, it still makes no sense that the main doesn't close the COM port.

If you check on esptool, you can see the esp._port.close() at the very end of the main() function. I believe this would be the correct way of doing it. Once there are no more commands to be executed, why leave the port open?

Thanks!

@reykada
Copy link

reykada commented Nov 30, 2022

Hi

I have the same issue as OP but in my case I call ESPEFUSE:

    command = ['--port', comport, 'burn_key', 'flash_encryption', path_to_flash_enc_key, '--do-not-confirm']
    try:
        espefuse.main(command)
    except BaseException as error:
        print(f'An exception occurred: {format(error)}')

When I get an exception from the code above (as example):

An exception occurred: BLOCK2 is read-protected. Burn in this case may damage an already written value.(use '--force-write-always' option to ignore it)

and try to call ESPEFUSE further in my Python script I get the following error:

An exception occurred: Could not open COM3, the port doesn't exist
Please make sure that you have specified the right port with the --port argument

So looks like ESPEFUSE doesn't release the COM port when throw an exception.

ESPTOOL version: 4.3

Are there any workaround?
Regards

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants