<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>[nRF52840][usbd_hid_composite] How to send data to Control EP in Linux?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/50970/nrf52840-usbd_hid_composite-how-to-send-data-to-control-ep-in-linux</link><description>Hello Nordic experts, 
 
 I am doing SDK 15.3.0 usbd_hid_composite example and this is where I am: https://devzone.nordicsemi.com/f/nordic-q-a/50447/nrf52840-usbd_hid_composite-how-does-windows-transmit-caps-lock-state-to-the-device-without-output-endpoint</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 30 Aug 2019 11:41:05 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/50970/nrf52840-usbd_hid_composite-how-to-send-data-to-control-ep-in-linux" /><item><title>RE: [nRF52840][usbd_hid_composite] How to send data to Control EP in Linux?</title><link>https://devzone.nordicsemi.com/thread/207123?ContentTypeID=1</link><pubDate>Fri, 30 Aug 2019 11:41:05 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:aca2f8ad-436d-4b6a-adfc-64554e291d14</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi Louis&lt;/p&gt;
&lt;p&gt;I am no Linux expert myself, but this post seems to have some good pointers on accessing CDC devices in Linux:&lt;br /&gt;&lt;a href="https://www.linuxquestions.org/questions/programming-9/talk-to-device-on-ttyacm0-using-c-programming-717210/"&gt;https://www.linuxquestions.org/questions/programming-9/talk-to-device-on-ttyacm0-using-c-programming-717210/&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Basically you access them just like you would a normal serial port.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;You shouldn&amp;#39;t have to change anything on the nRF52 side when moving from Windows to Linux.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards&lt;br /&gt;Torbjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: [nRF52840][usbd_hid_composite] How to send data to Control EP in Linux?</title><link>https://devzone.nordicsemi.com/thread/206988?ContentTypeID=1</link><pubDate>Fri, 30 Aug 2019 06:33:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:071e2da3-402c-4629-bc6d-983a65dd5ab4</guid><dc:creator>Haojz</dc:creator><description>&lt;p&gt;&lt;span&gt;Dear Torbj&amp;oslash;rn,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Sorry for my late reply. Thank you for your reply. I think you are right, but &lt;strong&gt;how do I use CDC example in Linux?&lt;/strong&gt; The infocenter only has tutorial for Windows. (And what commands do I use to send and receive data? In order to achieve the goal above, do I need to change anything in the SDK?)&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Kind regards,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Louis&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: [nRF52840][usbd_hid_composite] How to send data to Control EP in Linux?</title><link>https://devzone.nordicsemi.com/thread/205442?ContentTypeID=1</link><pubDate>Thu, 22 Aug 2019 06:49:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8bfc8145-a9e5-4132-867c-d8e2a94f4cee</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi Louis&lt;/p&gt;
&lt;p&gt;Sorry, for some reason I thought you were doing HID over BLE, not USB ;)&lt;/p&gt;
&lt;p&gt;In that case have you considered using the CDC USB class instead of HID?&lt;/p&gt;
&lt;p&gt;Then you can treat the connected device just like a comport, and send/receive any type of data that you want.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards&lt;br /&gt;Torbjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: [nRF52840][usbd_hid_composite] How to send data to Control EP in Linux?</title><link>https://devzone.nordicsemi.com/thread/205181?ContentTypeID=1</link><pubDate>Wed, 21 Aug 2019 07:02:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3aeb4e57-36cb-4c52-920c-a6bd24e851a7</guid><dc:creator>Haojz</dc:creator><description>&lt;p&gt;Hi Torbj&amp;oslash;rn,&lt;/p&gt;
[quote userid="2116" url="~/f/nordic-q-a/50970/nrf52840-usbd_hid_composite-how-to-send-data-to-control-ep-in-linux/204935"]If you don&amp;#39;t need any standard HID behavior, why don&amp;#39;t you just set up a normal BLE connection with a proprietary GATT service?[/quote]
&lt;p&gt;Is BLE using USB to communicate? I do not want to use Bluetooth to communicate. I want to use just USB to send and receive data between host and nRF board.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: [nRF52840][usbd_hid_composite] How to send data to Control EP in Linux?</title><link>https://devzone.nordicsemi.com/thread/204935?ContentTypeID=1</link><pubDate>Tue, 20 Aug 2019 08:12:41 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f749247f-e528-4d32-a9a3-7b80dde00bbe</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi Louis&lt;/p&gt;
&lt;p&gt;If you don&amp;#39;t need any standard HID behavior, why don&amp;#39;t you just set up a normal BLE connection with a proprietary GATT service?&lt;/p&gt;
&lt;p&gt;Then you have full control over the data that you can send, and can shape the service according to your requirements.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;It seems overkill to use HID over GATT if you don&amp;#39;t really need HID compatibility.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards&lt;br /&gt;Torbjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: [nRF52840][usbd_hid_composite] How to send data to Control EP in Linux?</title><link>https://devzone.nordicsemi.com/thread/204836?ContentTypeID=1</link><pubDate>Mon, 19 Aug 2019 14:55:26 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0eb14d13-9c1f-4810-bfd3-156eab2c603b</guid><dc:creator>Haojz</dc:creator><description>&lt;p&gt;Hello&amp;nbsp;&lt;span&gt;Torbj&amp;oslash;rn,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Thank you for your reply and kind support.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
[quote userid="2116" url="~/f/nordic-q-a/50970/nrf52840-usbd_hid_composite-how-to-send-data-to-control-ep-in-linux/204815"]First off, in the&amp;nbsp;APP_USBD_HID_USER_EVT_OUT_REPORT_READY handler you are reading out a single byte of data, yet you are assigning report[1] to the LED variable?[/quote][quote userid="2116" url="~/f/nordic-q-a/50970/nrf52840-usbd_hid_composite-how-to-send-data-to-control-ep-in-linux/204815"]report[1] returns the second byte in the &amp;#39;array&amp;#39;, I would expect report[0] to return the correct byte.&amp;nbsp;[/quote]
&lt;p&gt;I did this by following the suggestions in &lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/50447/nrf52840-usbd_hid_composite-how-does-windows-transmit-caps-lock-state-to-the-device-without-output-endpoint/201751"&gt;https://devzone.nordicsemi.com/f/nordic-q-a/50447/nrf52840-usbd_hid_composite-how-does-windows-transmit-caps-lock-state-to-the-device-without-output-endpoint/201751&lt;/a&gt;, and I verified this in Keil debug mode - it is correct: I do not know why but for CONTROL EP case(compare to OUT EP case), the data start from report[1] (whereas for OUT EP it indeed starts from report[0]).&lt;/p&gt;
[quote userid="2116" url="~/f/nordic-q-a/50970/nrf52840-usbd_hid_composite-how-to-send-data-to-control-ep-in-linux/204815"]Also, on the Linux side it appears you are sending 4 bytes rather than 1, this won&amp;#39;t work if the report descriptor sets up a 1 byte out report.&amp;nbsp;[/quote]
&lt;p&gt;Yes, you are right. After I changed the default descriptor to 4 bytes I can send the data to CONTROL EP successfully.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Now, I would like to remove mouse and keyboard functions, only leaving the communication tunnels(IN EP &amp;amp; CONTROL EP/OUT EP) to transmit some data and execute some control commands from linux side. However, after&amp;nbsp;I removed the mouse &amp;amp; keyboard things, the code stops to work(It is too complicated to modify it). Do you have any clear code only for HID USB communication via endpoints or any other suggestion to implement this target?&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Thank you for your kind support again and I look forward to hearing from you soon.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;/p&gt;
&lt;p&gt;Louis&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: [nRF52840][usbd_hid_composite] How to send data to Control EP in Linux?</title><link>https://devzone.nordicsemi.com/thread/204815?ContentTypeID=1</link><pubDate>Mon, 19 Aug 2019 14:20:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:76aa3b93-c847-494b-8e15-b57d8694d931</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;There are several odd things in your code.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;First off, in the&amp;nbsp;APP_USBD_HID_USER_EVT_OUT_REPORT_READY handler you are reading out a single byte of data, yet you are assigning report[1] to the LED variable?&lt;/p&gt;
&lt;p&gt;report[1] returns the second byte in the &amp;#39;array&amp;#39;, I would expect report[0] to return the correct byte.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Also, on the Linux side it appears you are sending 4 bytes rather than 1, this won&amp;#39;t work if the report descriptor sets up a 1 byte out report.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards&lt;br /&gt;Torbjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: [nRF52840][usbd_hid_composite] How to send data to Control EP in Linux?</title><link>https://devzone.nordicsemi.com/thread/204381?ContentTypeID=1</link><pubDate>Fri, 16 Aug 2019 03:20:55 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8e6c5f5c-e060-47c1-be74-a15fb00196f6</guid><dc:creator>Haojz</dc:creator><description>&lt;p&gt;I found some code online using LIBUSB(C++) to write data to control EP. Here is the code:&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;#include &amp;lt;iostream&amp;gt;
#include &amp;lt;string&amp;gt;
#include &amp;lt;libusb-1.0/libusb.h&amp;gt;

#define LIBUSB_ENDPOINT_IN 0x81
#define LIBUSB_ENDPOINT_OUT 0x1
using namespace std;

int main() {
	libusb_device **devs; //pointer to pointer of device, used to retrieve a list of devices
	libusb_device_handle *dev_handle; //a device handle
	libusb_context *ctx = NULL; //a libusb session
	int r; //for return values
	ssize_t cnt; //holding number of devices in list
	r = libusb_init(&amp;amp;ctx); //initialize the library for the session we just declared
	if(r &amp;lt; 0) {
		cout&amp;lt;&amp;lt;&amp;quot;Init Error &amp;quot;&amp;lt;&amp;lt;r&amp;lt;&amp;lt;endl; //there was an error
		return 1;
	}
	libusb_set_debug(ctx, 3); //set verbosity level to 3, as suggested in the documentation

	cnt = libusb_get_device_list(ctx, &amp;amp;devs); //get the list of devices
	if(cnt &amp;lt; 0) {
		cout&amp;lt;&amp;lt;&amp;quot;Get Device Error&amp;quot;&amp;lt;&amp;lt;endl; //there was an error
		return 1;
	}
	cout&amp;lt;&amp;lt;cnt&amp;lt;&amp;lt;&amp;quot; Devices in list.&amp;quot;&amp;lt;&amp;lt;endl;

	dev_handle = libusb_open_device_with_vid_pid(ctx, 0x1915, 0x520B); //these are vendorID and productID I found for my usb device
	if(dev_handle == NULL)
		cout&amp;lt;&amp;lt;&amp;quot;Cannot open device&amp;quot;&amp;lt;&amp;lt;endl;
	else
		cout&amp;lt;&amp;lt;&amp;quot;Device Opened&amp;quot;&amp;lt;&amp;lt;endl;
	libusb_free_device_list(devs, 1); //free the list, unref the devices in it

	unsigned char *data = new unsigned char[4]; //data to write
	data[0]=&amp;#39;1&amp;#39;;data[1]=&amp;#39;1&amp;#39;;data[2]=&amp;#39;1&amp;#39;;data[3]=&amp;#39;1&amp;#39;; //some dummy values // &amp;#39;1&amp;#39;=0x31

	int actual; //used to find out how many bytes were written
	if(libusb_kernel_driver_active(dev_handle, 0) == 1) { //find out if kernel driver is attached
		cout&amp;lt;&amp;lt;&amp;quot;Kernel Driver Active&amp;quot;&amp;lt;&amp;lt;endl;
		if(libusb_detach_kernel_driver(dev_handle, 0) == 0) //detach it
			cout&amp;lt;&amp;lt;&amp;quot;Kernel Driver Detached!&amp;quot;&amp;lt;&amp;lt;endl;
	}
	r = libusb_claim_interface(dev_handle, 0); //claim interface 0 (the first) of device (mine had jsut 1)
  if(r &amp;lt; 0) {
		cout&amp;lt;&amp;lt;&amp;quot;Cannot Claim Interface&amp;quot;&amp;lt;&amp;lt;endl;
		return 1;
	}

	cout&amp;lt;&amp;lt;&amp;quot;Claimed Interface&amp;quot;&amp;lt;&amp;lt;endl;

	// cout&amp;lt;&amp;lt;&amp;quot;Data-&amp;gt;&amp;quot;&amp;lt;&amp;lt;data&amp;lt;&amp;lt;&amp;quot;&amp;lt;-&amp;quot;&amp;lt;&amp;lt;endl; //just to see the data we want to write : abcd
	cout&amp;lt;&amp;lt;&amp;quot;Writing Data...&amp;quot;&amp;lt;&amp;lt;endl;
	//r = libusb_bulk_transfer(dev_handle, LIBUSB_ENDPOINT_OUT, data, 4, &amp;amp;actual, 0); //write to OUT EP
	//r = libusb_bulk_transfer(dev_handle, LIBUSB_ENDPOINT_IN, data, 4, &amp;amp;actual, 0); //listen to IN EP
	actual = libusb_control_transfer(dev_handle, 0x21, 0x9, 0x200, 0, data, 4, 5000); //write to CONTROL EP

  cout&amp;lt;&amp;lt;&amp;quot;Data:&amp;quot;;
  for(unsigned int i = 0; i &amp;lt; 4; i++){
    cout&amp;lt;&amp;lt;data[i]&amp;lt;&amp;lt;endl;
  }
  cout&amp;lt;&amp;lt;&amp;quot;actual: &amp;quot;&amp;lt;&amp;lt;actual&amp;lt;&amp;lt;endl;


	if(r == 0 &amp;amp;&amp;amp; actual == 4) //we wrote the 4 bytes successfully
		cout&amp;lt;&amp;lt;&amp;quot;Writing Successful!&amp;quot;&amp;lt;&amp;lt;endl;
	else
		cout&amp;lt;&amp;lt;&amp;quot;Write Error&amp;quot;&amp;lt;&amp;lt;endl;

	r = libusb_release_interface(dev_handle, 0); //release the claimed interface
	if(r!=0) {
		cout&amp;lt;&amp;lt;&amp;quot;Cannot Release Interface&amp;quot;&amp;lt;&amp;lt;endl;
		return 1;
	}
	cout&amp;lt;&amp;lt;&amp;quot;Released Interface&amp;quot;&amp;lt;&amp;lt;endl;

	libusb_close(dev_handle); //close the device we opened
	libusb_exit(ctx); //needs to be called to end the

	delete[] data; //delete the allocated memory for data
	return 0;
}
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;However, when I write the data to CONTROL&amp;nbsp;EP, I got the return value of &amp;quot;actual&amp;quot; -9, which means&amp;nbsp;LIBUSB_PIPE_ERROR, and the writing is failed. Does anyone know how to fix this problem? or other way to write data to CONTROL EP?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>