communicating with a LPC1768 as a HID via python

Background: I am evaluating replacing an FTDI+FPGA+RAM with a Cortex chip and I am playing around with a LPC1768 dev card.

flashing LED? [x]
communications via a virtual comms port [x]

Now I am looking at communicating via libUSB (either CDC or HID… evaluating)

I started by trying this example: https://developer.mbed.org/cookbook/USBHID-bindings- & the USBHID_TestCase program compiles and runs.

The issue is on the python side (using the linux example & libUSB).

The 1st issue was the py script has:

mbed_vendor_id = 0x1234 
mbed_product_id = 0x0006

equally the mbed USBDevice:USBHID has:

USBHID(uint8_t output_report_length = 64, uint8_t input_report_length = 64, uint16_t vendor_id = 0x1234, uint16_t product_id = 0x0006, uint16_t product_release = 0x0001, bool connect = true);

ie the same product and vendor ID. However… lsusb lists the NXP chipset at a different location.

Bus 003 Device 008: ID 0d28:0204 NXP LPC1768

issuing: lsusb -vvv -d 0x0d28:0204 I can see 4 devices that this card exposes (good) and this is matched by a simple python testcase

import usb
mbed_vendor_id = 0x0d28
mbed_product_id = 0x0204
dev = usb.core.find(idVendor=mbed_vendor_id,idProduct=mbed_product_id)

checking what dev is now populated with:

dev[0]
<CONFIGURATION 1: 500 mA>


dev[0][(0,0)]
<INTERFACE 0: Mass Storage>
[0] <ENDPOINT 0x82: Bulk IN>
[1] <ENDPOINT 0x2: Bulk OUT>
[2] <ENDPOINT 0x0: Control OUT>


dev[0][(1,0)]
<INTERFACE 1: CDC Communication>
[0] <ENDPOINT 0x83: Interrupt IN>
[1] <ENDPOINT 0x0: Control OUT>

dev[0][(2,0)]
<INTERFACE 2: CDC Data>
[0] <ENDPOINT 0x4: Bulk OUT>
[1] <ENDPOINT 0x84: Bulk IN>
[2] <ENDPOINT 0x0: Control OUT>


dev[0][(3,0)]
<INTERFACE 3: Human Interface Device>
[0] <ENDPOINT 0x81: Interrupt IN>
[1] <ENDPOINT 0x1: Interrupt OUT>
[2] <ENDPOINT 0x0: Control OUT>

so 0 is mass storage -> the python script from the example wouldn’t work. I have been trying to communicate via dev[0][3,0] and by specifying an endpoint as dev[0][3,0][0] I can write but reads from dev[0][3,0][1] always return 0’s even though the mbed code is meant to provide a random data.

Any idea’s ?


Source: python

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.