micropython / micropython/micropython-lib

Distinguishing CDCInterface UART

Open
#1,041 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
2.9k
Forks
1.1k
Avg merge
7d 6h
Merged PRs (30d)
3

Description

The cdc.CDCInterface works great for my use case of having a single RP2040 host a REPL for active interaction as well as a metrics endpoint for me to be able to gather data from my device while interacting with it.

The issue I've run into is being able to programmatically distinguish between the two interfaces. Typically the REPL comes in as the lower /dev/ttyACM* number and the virtual serial port as the higher in the pair. With multiple RP2040's plugged into my PC though it becomes a lot of guess work to distinguish who is the metrics interface and who is the REPL per device.

I've tried a few things:

  • Setting args like configuration_str in _Device.init like so: core.get().init(uart, configuration_str="Pico Query", builtin_driver=True)
  • Modifying desc_cfg within CDCInterface to try and an entry to the strs variable and then set that as the iInterface value:
def desc_cfg(self, desc, itf_num, ep_num, strs):

    # ...
    if "Pico Query" not in strs:
        strs.append("Pico Query")
    i_data = desc._get_str_index("Pico Query")  # should now return nonzero

    # Now add the data interface
    desc.interface(
        itf_num + 1,
        _CDC_DATA_EP_NUM,
        _CDC_ITF_DATA_CLASS,
        _CDC_ITF_DATA_SUBCLASS,
        _CDC_ITF_DATA_PROT,
        iInterface=i_data
    )
    # ...

But I'm never able to see a distinguishing value in lsusb -v to tell the two interfaces apart.

I'm probably missing something -- I'd love to contribute an example if someone can point me in the right direction.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with micropython/usb/usb-device-cdc/usb/device/cdc.py, especially CDCInterface.desc_cfg, and review how _Device.init passes configuration_str into the USB descriptors. Use lsusb -v with one or more RP2040 devices to inspect the generated interface descriptors; done when the REPL and metrics interfaces expose reliable distinguishing information and the usage is documented or demonstrated.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
embedded-iot
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.