Avrdude: ser_open(): can't set com-state for "\\.\COM5" - Possible solution

Having experienced the above error and trying all sorts of solutions offered, to no avail, I stumbled across a possible solution.

Open a program in IDE, turn Serial plotter on and off, try to upload again. It seemed to have worked for me.

Thanks for sharing your finding @t0ny. That is very interesting!

Many users have reported encountering this problem when using cheap Chinese derivative boards from sketchy sellers. Pretty much all of them have reported it was fixed by rolling the CH340 driver back to version 3.7.2022.1:

  1. Click the following link to download the previous version of the driver from an archive of the chip manufacturer's website:
    https://web.archive.org/web/20220519153932/https://www.wch-ic.com/downloads/file/65.html
  2. Wait for the download to finish.
  3. Run the downloaded CH341SER.EXE file.
  4. A "User Account Control" dialog may now appear asking "Do you want to allow this app to make changes to your device?". Click the "Yes" button.
  5. A "DriverSetup(X64)" dialog will open. Click the "INSTALL" button in the dialog.
  6. Wait for the driver installation to finish, as indicated by the appearance of a "Driver install success!" dialog.
  7. Click the "OK" button in the "Driver install success!" dialog.
    The dialog will close.
  8. Click the X icon at the top right of the "DriverSetup(X64)" dialog
    The dialog will close.
  9. Close Arduino IDE if it is running.
  10. Connect the Arduino board to your computer with a USB cable.
  11. Open the Windows Device Manager.
  12. Select View > Devices by type from the Device Manager menus.
  13. Open the "View" menu.
  14. If there is a to the left of the "Show hidden devices" menu item, click on "Show hidden devices" to disable it.
  15. Open the "Ports (COM & LPT)" section of the Device Manager tree.
  16. You should see a port identified as "USB-SERIAL CH340 (COMn)" under the "Ports (COM & LPT)" section (where "COMn" is some serial port e.g., COM4). Double click on that item.
    The "USB-SERIAL CH340 (COMn) Properties" dialog will open.
  17. Select the "Driver" tab of the "USB-SERIAL CH340 (COMn) Properties" dialog.
  18. You will see a "Roll Back Driver" button in the dialog. If it is not clickable, perform the following instructions:
    1. Click the "Update driver" button.
      An "Update Drivers Device - USB-SERIAL CH340 (COMn)" dialog will open.
    2. Click on "Search automatically for drivers" in the "Update Drivers Device - USB-SERIAL CH340 (COMn)" dialog.
    3. You should now see the driver installation wizard update the driver. Wait for the update to finish, as indicated by the message "Windows has successfully updated your drivers" in the dialog.
      :red_exclamation_mark: It is possible you will instead see the message "The best drivers are already installed". If so, please stop following the instructions here and reply on this forum topic to let us know. I'll provide alternative instructions you can follow.
    4. Click the "Close" button in the "Update Drivers Device - USB-SERIAL CH340 (COMn)" dialog.
      The dialog will close.
  19. Click the "Roll Back Driver" button in the "USB-SERIAL CH340 (COMn) Properties" dialog.
    The "Driver Package rollback" dialog will open.
  20. Click the radio button next to "My apps don't work with this driver" in the "Driver Package rollback" dialog .
  21. Click the "Yes" button.
    The "Driver Package rollback" dialog will close.
  22. Click the "Close" button in the "USB-SERIAL CH340 (COMn) Properties" dialog.

Now start Arduino IDE again and repeat whatever you were doing before when you encountered that error before. Hopefully this time everything will work as expected.

1 Like

I had done all that, except the Rollback command was greyed out, and it didn’t make any difference. I just experimented with the plotter after I saw some mention of it, and it seemed to work.

I have found that when the driver installation gets into this state, it can be solved by uninstalling and then reinstalling the drivers. After that, the "roll back" option should be enabled.

I'll provide instructions you can follow to do that:

  1. Close Arduino IDE if it is running.
  2. Connect the Arduino board to your computer with a USB cable.
  3. Open the Windows Device Manager.
  4. Select View > Devices by type from the Device Manager menus.
  5. Open the "View" menu.
  6. If there is a to the left of the "Show hidden devices" menu item, click on "Show hidden devices" to disable it.
  7. Open the "Ports (COM & LPT)" section of the Device Manager tree.
  8. You should see a port identified as "USB-SERIAL CH340 (COMn)" under the "Ports (COM & LPT)" section (where "COMn" is some serial port e.g., COM4). Double click on that item.
    The "USB-SERIAL CH340 (COMn) Properties" dialog will open.
  9. Select the "Driver" tab of the "USB-SERIAL CH340 (COMn) Properties" dialog.
  10. Click the "Uninstall Device" button.
    The "Uninstall Device" dialog will open.
  11. Check the box next to "☐ Attempt to remove the driver for this device.".
  12. Click the "Uninstall" button.
    The "Uninstall Device" and "USB-SERIAL CH340 (COMn) Properties" dialogs will close.
  13. Disconnect the USB cable of the Arduino board from your computer.
  14. Reconnect the USB cable of the Arduino board to your computer.
  15. Wait for the "USB-SERIAL CH340 (COMn)" device to appear under the "Ports (COM & LPT)" section of the Device Manager tree.
    :red_exclamation_mark: This will take a couple of minutes as Windows must first automatically reinstall the driver.
    :red_exclamation_mark: It might appear first as a "USB2.0-Serial" device under the "Other devices section of the tree. Just wait for a little longer and it will appear in its final place under the "Ports (COM & LPT)" section.
  16. Click the following link to download the previous version of the driver from an archive of the chip manufacturer's website:
    https://web.archive.org/web/20220519153932/https://www.wch-ic.com/downloads/file/65.html
  17. Wait for the download to finish.
  18. Run the downloaded CH341SER.EXE file.
  19. A "User Account Control" dialog may now appear asking "Do you want to allow this app to make changes to your device?". Click the "Yes" button.
  20. A "DriverSetup(X64)" dialog will open. Click the "INSTALL" button in the dialog.
  21. Wait for the driver installation to finish, as indicated by the appearance of a "Driver install success!" dialog.
  22. Click the "OK" button in the "Driver install success!" dialog.
    The dialog will close.
  23. Click the X icon at the top right of the "DriverSetup(X64)" dialog.
    The dialog will close.
  24. Switch back to the Windows "Device Manager".
  25. Double click on the "USB-SERIAL CH340 (COMn)" device under the "Ports (COM & LPT)" section.
    The "USB-SERIAL CH340 (COMn) Properties" dialog will open.
  26. Select the "Driver" tab of the "USB-SERIAL CH340 (COMn) Properties" dialog.
  27. Click the "Update driver" button.
    An "Update Drivers Device - USB-SERIAL CH340 (COMn)" dialog will open.
  28. Click on "Search automatically for drivers" in the "Update Drivers Device - USB-SERIAL CH340 (COMn)" dialog.
  29. You should now see the driver installation wizard update the driver. Wait for the update to finish, as indicated by the message "Windows has successfully updated your drivers" in the dialog.
  30. Click the "Close" button in the "Update Drivers Device - USB-SERIAL CH340 (COMn)" dialog.
    The dialog will close.
  31. Click the "Roll Back Driver" button in the "USB-SERIAL CH340 (COMn) Properties" dialog.
    The "Driver Package rollback" dialog will open.
  32. Click the radio button next to "My apps don't work with this driver" in the "Driver Package rollback" dialog .
  33. Click the "Yes" button.
    The "Driver Package rollback" dialog will close.
  34. Click the "Close" button in the "USB-SERIAL CH340 (COMn) Properties" dialog.

Now start Arduino IDE again and repeat whatever you were doing before when you encountered that error before. Hopefully this time everything will work as expected.

Thank you for all that. I’ll give it a try.

I’ve just tested it again. When initially loading I get the error “Avrude: ser open()” etc but when I open and close the plotter, it loads properly.

Open IDE and attempt to upload sketch

avrdude: Version 6.3-20190619
Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
Copyright (c) 2007-2014 Joerg Wunsch

     System wide configuration file is "C:\Users\admin\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17/etc/avrdude.conf"

     Using Port                    : COM5
     Using Programmer              : arduino
     Overriding Baud Rate          : 57600

avrdude: ser_open(): can't set com-state for "\.\COM5"

avrdude done. Thank you.

Failed uploading: uploading error: exit status 1

Open and close plotter

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.00s

avrdude: Device signature = 0x1e950f (probably m328p)
avrdude: reading input file "C:\Users\admin\AppData\Local\arduino\sketches\83772851F47F36FAA74A5C34FD29D3A4/HallTest.ino.hex"
avrdude: writing flash (1062 bytes):

Writing | ################################################## | 100% 0.35s

avrdude: 1062 bytes of flash written

avrdude done. Thank you.

Thanks for taking the time to share your findings. I'm sorry to hear the driver "roll back" didn't fix the problem.

It would be a good idea to verify that the intended version 3.7.2022.1 of the driver is truly being used now. You can do that by the following procedure:

  1. Connect the Arduino board to your computer with a USB cable.
  2. Open the Windows Device Manager.
  3. Select View > Devices by type from the Device Manager menus.
  4. Open the "View" menu.
  5. If there is a to the left of the "Show hidden devices" menu item, click on "Show hidden devices" to disable it.
  6. Open the "Ports (COM & LPT)" section of the Device Manager tree.
  7. You should see a port identified as "USB-SERIAL CH340 (COMn)" under the "Ports (COM & LPT)" section (where "COMn" is some serial port e.g., COM4). Double click on that item.
    The "USB-SERIAL CH340 (COMn) Properties" dialog will open.
  8. Select the "Drivers" tab of the "USB-SERIAL CH340 (COMn) Properties" dialog.

If the "roll back" worked correctly, you should see "3.7.2022.1" in "Driver Version" field in that "USB-SERIAL CH340 (COMn) Properties" dialog.

And …

OK, that explains why you are still encountering the "can't set com-state" error. You have version 3.9.2024.9 of the CH340 driver. This means you have not managed to install the version 3.7.2022.1 of the driver, or if you installed it, the installation was not persistent (e.g., Windows immediately updated the installation back to the latest version 3.9.2024.9. The "roll back" instructions I provided are expected to install version 3.7.2022.1 in a persistent manner.

It is possible this problem is caused by not correctly following the instructions I provided. I suggest you try following the instructions again, being very careful to follow them exactly. When I follow those instructions, they do result in the persistent installation of version 3.7.2022.1 of the driver.

Thanks for you time and attention. Yours is obviously the best solution, but I am still wondering why opening and closing the plotter solves the problem.

Same here! It is very interesting.

I am unfortunate in my fortune to not have acquired one of the boards with the sketchy "CH340" chips that have this problem, so I have not been able to do any direct investigations. Everything I know about the situation (including the fact that the "roll back" solves it) comes from the reports from the community members who shared their findings here.

There was a somewhat similar prior report here:

and another here: