libusb

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.
Post Reply
IAmCoder
Posts: 2
Joined: Fri May 24, 2019 7:21 am

libusb

Post by IAmCoder » Fri May 24, 2019 7:32 am

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

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: libusb

Post by jimmo » Sat May 25, 2019 12:52 pm

Hi,

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.

IAmCoder
Posts: 2
Joined: Fri May 24, 2019 7:21 am

Re: libusb

Post by IAmCoder » Mon May 27, 2019 12:31 pm

[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.

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: libusb

Post by jimmo » Mon May 27, 2019 1:00 pm

IAmCoder wrote:
Mon May 27, 2019 12:31 pm
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.
OK, cool. Hope what I said makes sense then, let me know if you have any questions.

Post Reply