Skip to content

USB HOST implementation on teensy 4.1 #6527

Description

@fadh3r

I can't get data through endpoint of usb host implementation
Where is my mistake?

this is my code:

import usb_host
import usb.core
import sys
import board
import digitalio
import microcontroller
import time
import array

#INIT USB WITH POSITIVE AND NEGATIVE PINS
if hasattr(board, "USB_HOST_POWER"):
    d = digitalio.DigitalInOut(board.USB_HOST_POWER)
    d.switch_to_output(value=True)
    print("USB power on")


h = usb_host.Port(board.USB_HOST_DP, board.USB_HOST_DM)

#FIND VMETER
vmeter = usb.core.find(idVendor=0x16d0, idProduct=0x0668)
print(vmeter.manufacturer, vmeter.product)

if vmeter.is_kernel_driver_active(0):
    vmeter.detach_kernel_driver(0)


buf = array.array('b', [0] * 64)

while True:
    try:
        count = vmeter.read(0x82, buf)
        # bEndpointAddress 0x82 IN Endpoint 2
        # bEndpointAddress 0x01 OUT Endpoint 1
    except usb.core.USBTimeoutError:
        continue

    print(buf)
    print(count)
    time.sleep(.01)

I'm getting right device manufacturer and product names,
but my "buf" is always empty and "count" of read bytes is always 14...

array("b", [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
14

I also tried 7 and 8 version of CircuitPython and different usb devices...

Activity

  1. changed the title [-]add ability to get "USB-MIDI Event Packets" for USB HOST implementation[/-] [+]problem with USB HOST implementation[/+] on Jun 28, 2022
  2. changed the title [-]problem with USB HOST implementation[/-] [+]problem with USB HOST implementation on teensy 4.1[/+] on Jun 28, 2022
  3. changed the title [-]problem with USB HOST implementation on teensy 4.1[/-] [+]USB HOST implementation on teensy 4.1[/+] on Jun 28, 2022
  4. tannewt commented on Jun 28, 2022

    @tannewt
    Member

    read isn't implemented yet. :-) I mentioned it here: #6125

    I should have had it raise an error. Sorry!

    I thought I'd get back to it quickly but didn't. I switched off of it while waiting for a TinyUSB API to call.

    Would you like to try and add it? It shouldn't be too hard now that TinyUSB has an API for it. (I haven't looked at specifics though.)

  5. added this to the Long term milestone on Jun 28, 2022
  6. fadh3r commented on Jun 29, 2022

    @fadh3r
    Author

    Thanks for answer, Scott!
    Sure, I want to try to add it. But can you give me brief insight into right direction, please?
    Do I need build new circuitpython for my teensy, or I can just add TinyUSB library to my project and write some glue?

  7. tannewt commented on Jun 29, 2022

    @tannewt
    Member

    Sure, I want to try to add it. But can you give me brief insight into right direction, please?

    Yup! Happy to. Join us on discord if you haven't yet too. There is a #circuitpython-dev channel where we can help you get over any bumps. https://adafru.it/discord

    Do I need build new circuitpython for my teensy, or I can just add TinyUSB library to my project and write some glue?
    Yes, you'll need to build your own CircuitPython. I think the steps are:

    1. Upgrade the lib/tinyusb submodule to the latest commit to get the newest USB Host API. You may need to update the existing calls too.
    2. Add calls into the TinyUSB API into the shared-module/usb/core/Device.c source file. It is in shared-module because it'll work on all ports that have the usb_host module and use TinyUSB.

    If you hit any snags, jump on Discord and we'd be happy to try and help.

  8. fadh3r commented on Jun 30, 2022

    @fadh3r
    Author

    Thanks, Scott!
    I'm done with successful build of custom CircuitPython and now I'm trying to understand architecture of api calls for required changes, and this looks like few sleepless nights))

  9. added a commit that references this issue on Jul 8, 2023
    64e4145
  10. added a commit that references this issue on Jul 11, 2023
    2686bea
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions