Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calling set_configuration from Ftdi.open_from_device()? #268

Closed
janakj opened this issue Aug 26, 2021 · 4 comments
Closed

Calling set_configuration from Ftdi.open_from_device()? #268

janakj opened this issue Aug 26, 2021 · 4 comments

Comments

@janakj
Copy link

janakj commented Aug 26, 2021

When I open an Ftdi device using open(), the method invokes open_from_device() which internally invokes self._usb_dev.set_configuration()

Calling set_configuration() on the USB device causes the Linux kernel to unbind the ftdi_sio driver from the device:

[223183.116264] usb 1-1.1.4.1: usbfs: interface 0 claimed by ftdi_sio while 'bcf' sets config #1

I was wondering: is it really necessary to call set_configuration() from open_from_device() even if I only use the device in read-only mode (i.e., I don't perform any updates or modifications to it)?

@eblot
Copy link
Owner

eblot commented Aug 26, 2021

What kind of read only request can you make, I'm not sure to understand the question?

@janakj
Copy link
Author

janakj commented Aug 26, 2021

Essentially, I just need to open an Ftdi device and read some values from the EEPROM, for example, something like this:

ftdi = Ftdi()
eeprom = FtdiEeprom()
ftdi.open(vid, pid, serial=sn)
eeprom.connect(ftdi)
print(eeprom.product)

The above sequence triggers the ftdi_sio unbind.

@eblot
Copy link
Owner

eblot commented Aug 26, 2021

To "read" from the EEPROM, it is required to write commands to one of the FTDI interface. In order to access the interface, the interface should be granted exclusive access. As the kernel is already using the interface for serial purpose, PyFtdi first needs to get exclusive access so there could not be concurrent access between the user space application and the kernel usb serial driver.

You may be able to hack PyFtdi to bypass any protection - although I'm not sure the Linux kernel can let a user application access the same USB device interface as the one it already managed, but I would certainly not recommend to do so, as it would lead to unmanaged concurrent access to the same HW, as there's no sync between the app and the kernel driver. Claiming and releasing the interface is the equivalent of a global synchronisation point.

@janakj
Copy link
Author

janakj commented Aug 26, 2021

I see. That makes sense. Thanks for such detailed explanation!

@janakj janakj closed this as completed Aug 26, 2021
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

No branches or pull requests

2 participants