Hello,
I've been using https://github.com/NordicSemiconductor/pc-nrfutil for few years now as a library of my own application to do DFU of a device. Everything worked and works well, I've locked the dependency to commit a586220 and everything is golden for Linux and OSX. Windows was ok too until recently I was rebuilding a small change in the application and found out that DFU process fails with an error:
Traceback (most recent call last): File "src\main.py", line 285, in <module> run_main() File "lib\site-packages\click\core.py", line 764, in __call__ File "lib\site-packages\click\core.py", line 717, in main File "lib\site-packages\click\core.py", line 956, in invoke File "lib\site-packages\click\core.py", line 555, in invoke File "lib\site-packages\click\decorators.py", line 17, in new_func File "src\main.py", line 222, in run_main ping = ping, File "src\dfu.py", line 54, in perform_dfu dfu.dfu_send_images() File "src\nrfutil\nordicsemi\dfu\dfu.py", line 129, in dfu_send_images File "src\nrfutil\nordicsemi\dfu\dfu.py", line 89, in _dfu_send_image File "src\nrfutil\nordicsemi\dfu\dfu_transport_serial.py", line 217, in open File "src\nrfutil\nordicsemi\dfu\dfu_transport_serial.py", line 367, in __get_mtu TypeError: 'NoneType' object is not iterable [12716] Failed to execute script main
So this got me by surprise as nothing in the dependencies, especially in pc-nrfutil has changed on my side. I'm using pipenv environment and lock on all dependencies so it's unlikely that there was a breaking change anywhere there. The changes in my app also didn't involve anything DFU related, just some params for talking with our device. I started digging further...
My thinking was that the only thing that could change was Windows with it's unbearable automatic updates which always get you by surprise. So it seems that it might be related as even building an application from old checkout of my sources now failed. The funny thing is that I use the Windows installation solely for building my app wrapping around pc-nrfutil so it's quite clean and not used very frequently.
I went deeper and deeper until I've found that what fails is the https://github.com/NordicSemiconductor/pc-nrfutil/blob/master/nordicsemi/lister/windows/lister_win32.py#L153 function which returns 0 devices even though I have one FT232 serial monitor which works very fine. More above that, I'm listing serial ports in my application using pyserial's mechanism and the correct COM port always get's detected. As a side note I know about the horrible need to escape COM port >9 with "\\.\", eg. \\.\COM10 - Initially I was suspecting this. But not my case unfortunately.
So after inspecting the list_all_com_ports function which should in principle return all devices to later be filtered I've found that it indeed checks all of my registry keys under SYSTEM\CurrentControlSet\Enum\USB\VID_0403&PID_6001\AU016M75 but all of them fail.
SYSTEM\CurrentControlSet\Enum\USB\VID_0403&PID_6001\AU016M75 err [WinError 2] The system cannot find the file specified
The thing is that using regedit I get pretty much the same problem, that is I can access "Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\USB\VID_0403&PID_6001\AU016M75\Device Parameters" but for "Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\USB\VID_0403&PID_6001\AU016M75\Properties" I get an "Properties cannot be opened. An error is preventing this key from being opened. Details: Access is denied". But wait, I'm running regedit as admin?! Also tried to run my app as admin.
So then I thought that my windows installation is broken from not using it frequently enough and did two things:
- Tried to look up how to repair registry and other system errors. But no errors were found so I assume it's ok
- Switched to another Windows PC which is not used very much but works ok, never had any problems with it as well as with the one used for building my app
And in both cases the result is the same - the list_all_com_ports fails to enumerate devices though it sees all of them. I've added some print statements and I can clearly see that it tries to enumerate what is see in regedit.
Is there a possibility to validate if the function works well with latest windows 10 or just a way to skip detecting the port as it's already been passed to https://github.com/NordicSemiconductor/pc-nrfutil/blob/master/nordicsemi/dfu/dfu.py#L55 and I know what port to use, don't need to re-detect it again? For me it seems that something with latest Windows update which broke things on 2 PCs. It seems that I'm on recent versions of Windows 10 Home:
- Version 2004, OS build 20H2 updated on 2021-03-25
- Version 20H2, Os build 19042.867 updated on 2021-03-30
The versions doesn't really say much to me but overall it seems to me that it's latest Windows and somehow broke discovering serial ports based on registry entries. On the other hand https://github.com/pyserial/pyserial/blob/0e7634747568547b8a7f9fd0c48ed74f16af4b23/serial/tools/list_ports_windows.py#L238 works perfectly fine and seems to does that also by looking through the registry.
My problem is that this cannot be skipped so I'm pretty much stuck with a not working build and no way to disable that without forking pc-nrfutil. This is of course possible but would want to avoid that at all costs because pc-nrfutil is great! Hence my question, is it possible that anyone could help with this anyhow?
Best regards,
PB