Skip to content

Conversation

@eugene-bright
Copy link
Contributor

Closes #1395

@eugene-bright
Copy link
Contributor Author

Should I also include VID:PID of the WCH-Link to the KNOWN_CMSIS_DAP_IDS?

@flit
Copy link
Member

flit commented May 29, 2022

Hi @eugene-bright! Please take a look at commit a926e94 that adds support for another non-compliant CMSIS-DAP probe. (Man, I wish people would properly implement the spec… 😩) Those changes match solely against the VID/PID, so you won't need the accepted names change. (It also works on all supported OSes/backends.)

The only change needed should be adding the WCH-Link VID/PID to KNOWN_CMSIS_DAP_IDS in pyocd/probe/pydapaccess/interface/common.py.

You'll also need to rebase your changes onto the develop branch and update this PR to target develop.

Finally, please add your copyright below the existing copyrights in the file(s) you edit.

If you're quick, you can get it in before the 0.34 release coming late today or tomorrow! 😉 Thanks!

@eugene-bright
Copy link
Contributor Author

@flit Thank you for the valuable advice. In the related issue I was instructed otherwise (to not try to use matching by VID:PID).
I'm worried about the commit a926e94. Will it ever come to main from develop?

@flit
Copy link
Member

flit commented May 29, 2022

Lol! 😄 Sorry, I'm behind on issues lately since I've been focusing on preparing for the upcoming release, so I hadn't seen the comments from @elfmimi.

Imo, there's are arguments to be made both for matching by name and ID pair.

develop will be merged to main shortly, right before the upcoming v0.34 release is made. Standard development process. It keeps main free of potential new bugs and regressions until code on develop is ready.

# Now read the product name string.
device_string = dev.product
if (device_string is None) or ("CMSIS-DAP" not in device_string):
if (device_string is None) or not any(map(lambda s: s in device_string, ACCEPTED_DEVICE_NAMES)):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quick Python note: any() is the right idea! However, you can simply the inner expression using a comprehension as any(s in device_string for s in ACCEPTED_DEVICE_NAMES). It's faster, too. 😄

@flit
Copy link
Member

flit commented May 29, 2022

At the minimum, please include the VID/PID in the list in common.py.

It's up to you if you want to add a generalised device name matching mechanism like your initial commit for this PR. However, it will need to work with all USB backends for CMSIS-DAP (hidapi, pyusb, pyusb_v2, pywinusb). So if you decide to implement this, please move ACCEPTED_DEVICE_NAMES to common.py and add a device name matching function there that is imported and used in the backends. (Hrrmm… possibly even a single matching function that takes the device name, vid, and pid…)

@elfmimi
Copy link

elfmimi commented May 29, 2022

I think I need to leave a comment on that VID(0x2a86) , which my instinct tells me is not officially approved.

@flit
Copy link
Member

flit commented May 30, 2022

@elfmimi Very good point. According to the official USB-IF vendor IDs list, VID 0x2a86 (decimal 10886) is registered to "KITRIS AG". Ummm…

(Aside: Why is the world would the USB-IF list vendor IDs in decimal? Have you ever heard of someone reference a VID in decimal? Of course not. 🤣 )

@flit
Copy link
Member

flit commented May 30, 2022

Fwiw, Patrick Yang, the CTO of WCH, is on twitter. Someone might ask him publicly why the WCH USB VID is assigned to Kitris AG. 😜

@flit
Copy link
Member

flit commented May 30, 2022

There's more to this VID story! Apparently another version (?) of the WCH-Link has the VID 0x1A86. (See #1121) This value is correctly registered to Nanjing Qinheng Microelectronics Co., Ltd., aka WCH-IC.

So either someone made a stupid typo in the code? Or something more nefarious is going on. 🤨 Is this 2a86 variant a clone of the real WCH-Link?

@eugene-bright
Copy link
Contributor Author

Probably 0x2a86 is a clone. When I disassembled it I saw marking on the MCU erased. Probably that's done to make the tracking of the producer harder.

@eugene-bright eugene-bright changed the base branch from main to develop May 30, 2022 18:20
@eugene-bright
Copy link
Contributor Author

The develop branch lacks some commits from main. That's strange...

@eugene-bright
Copy link
Contributor Author

It works for me

$ python3.10 -m pyocd list 
  #   Probe/Board       Unique ID      Target  
-----------------------------------------------
  0   wch.cn WCH-Link   0001A0000001   n/a

Copy link
Member

@flit flit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Requested changes
Would you mind adding your copyright below existing in modified files?
Please move the version script to scripts/.

Next steps

👉🏽 Do you mind if I push some additional changes to your branch? (GitHub permissions allow project owners to push to PR source branches, but I always ask first.)

There are actually some further issues I've found in pyusb_backend.py and pyusb_v2_backend.py. The latter should be checking the device name in addition to interface name (either should be accepted). And the interface name checks for both should use your is_known_device_string() function.

Also, use of is_known_device_string() needs to be integrated into hidapi_backend.py and pywinusb_backend.py.

My plan is to go ahead and release v0.34 today while we finish this PR. Then I'll cherry pick the changes over to main and release v0.34.1.

@eugene-bright
Copy link
Contributor Author

eugene-bright commented May 30, 2022

I'm in Ukraine and have to go to sleep to not die from exhaustion. I'm not interested in having any copyrights (and recommend to follow Linux kernel sign-off practice). Please do whatever you see profitable with the code.
See you tomorrow

@flit
Copy link
Member

flit commented May 30, 2022

'Night! Take care.

@eugene-bright
Copy link
Contributor Author

I moved the script, but the rest is outside of the scope of this ticket. My adapter doesn't have bInterfaceClass == 0xff and thus it's not DAP-Linkv2.
I think of how to unify pyusb_backend.py and pyusb_v2_backend.py. This files are way too similar. The inheritance could be appropirate in this case.

@eugene-bright eugene-bright requested a review from flit June 5, 2022 12:10
@flit
Copy link
Member

flit commented Jun 6, 2022

Right, the pyusb v1 and v2 files are very similar and need to be refactored.

@flit
Copy link
Member

flit commented Jun 6, 2022

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@flit flit merged commit 74c4f21 into pyocd:develop Jun 7, 2022
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

Successfully merging this pull request may close these issues.

Probe wch.cn WCH-Link (2a86:8011) support

3 participants