Discussion about programs, libraries and tools that work with MicroPython. Mostly these are provided by a third party.
Target audience: All users and developers of MicroPython.
I am trying to connect a USB device that requires libusb to a STM32 board running micropython.
What is the best approach - using FFI?
This is all I have found so far:
https://github.com/pfalcon/micropython- ... /libusb.py
Just to confirm I understand your question -- you have some other device, that normally plugs into a PC host and some software (using libusb) communicates with it. You'd like to instead plug it into your STM32, i.e. the STM32 running MicroPython is the USB host? (Maybe via an OTG cable if your STM32 board has only a micro-B connector?)
Using an STM32 as a USB host from MicroPython is technically possible of course. I looked into this once before and found
https://github.com/micropython/micropython/issues/212
but I don't know anything about the current state or if any of this got merged.
Libusb is a convenient (and very frequently-used) API for working with the OS's USB stack (ported to many platforms). So it's unlikely that your device actually needs libusb, rather that your existing PC software happens to use it. (That said, you can imagine that if someone did write a USB host controller library for MicroPython, making it look like libusb's Python bindings would probably be sensible).
The thing you've linked to is a FFI wrapper to the libusb, based on modffi. modffi is specific to the unix port, it allows you to write MicroPython bindings to a C API in a shared library (like libusb). None of these things exist on other ports.
[quote=jimmo post_id=36895 time=1558788738 user_id=3071]
Just to confirm I understand your question -- you have some other device, that normally plugs into a PC host and some software (using libusb) communicates with it. You'd like to instead plug it into your STM32, i.e. the STM32 running MicroPython is the USB host? (Maybe via an OTG cable if your STM32 board has only a micro-B connector?)
[/quote]
Yes, the other device normally plugs into a PC or Android device via OTG and from what I understand from the manufacturer, their drivers require libusb.