<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-gb">
	<link rel="self" type="application/atom+xml" href="https://forums.obdev.at/app.php/feed/topic/10460" />

	<title>Objective Development Forums</title>
	
	<link href="https://forums.obdev.at/index.php" />
	<updated>2016-06-07T01:20:40+02:00</updated>

	<author><name><![CDATA[Objective Development Forums]]></name></author>
	<id>https://forums.obdev.at/app.php/feed/topic/10460</id>

		<entry>
		<author><name><![CDATA[dode]]></name></author>
		<updated>2016-06-07T01:20:40+02:00</updated>

		<published>2016-06-07T01:20:40+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=10460&amp;p=31238#p31238</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=10460&amp;p=31238#p31238"/>
		<title type="html"><![CDATA[Re: usbFunctionRead() not getting called]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=10460&amp;p=31238#p31238"><![CDATA[
Argh.<br /><br />Finally I figured out that bRequestType is not just i.e. USB_TYPE_VENDOR but three fields.<br /><br />From linux/usb/ch9.h:<br /><br /><div class="codebox"><p>Code: </p><pre><code>/*<br /> * USB directions<br /> *<br /> * This bit flag is used in endpoint descriptors' bEndpointAddress field.<br /> * It's also one of three fields in control requests bRequestType.<br /> */<br />#define USB_DIR_OUT         0      /* to device */<br />#define USB_DIR_IN         0x80      /* to host */<br /><br />/*<br /> * USB types, the second of three bRequestType fields<br /> */<br />#define USB_TYPE_MASK         (0x03 &lt;&lt; 5)<br />#define USB_TYPE_STANDARD      (0x00 &lt;&lt; 5)<br />#define USB_TYPE_CLASS         (0x01 &lt;&lt; 5)<br />#define USB_TYPE_VENDOR         (0x02 &lt;&lt; 5)<br />#define USB_TYPE_RESERVED      (0x03 &lt;&lt; 5)<br /><br />/*<br /> * USB recipients, the third of three bRequestType fields<br /> */<br />#define USB_RECIP_MASK         0x1f<br />#define USB_RECIP_DEVICE      0x00<br />#define USB_RECIP_INTERFACE      0x01<br />#define USB_RECIP_ENDPOINT      0x02<br />#define USB_RECIP_OTHER         0x03<br />/* From Wireless USB 1.0 */<br />#define USB_RECIP_PORT         0x04<br />#define USB_RECIP_RPIPE      0x05</code></pre></div><br /><br />So the request now looks like this:<br /><br /><div class="codebox"><p>Code: </p><pre><code>usb_control_msg(dev-&gt;usbdev, usb_rcvctrlpipe(dev-&gt;usbdev, USB_DIR_OUT),<br />         USB_REQ_GET_STATUS, USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,<br />         0, 0, data, sizeof(data), 1000);</code></pre></div><br /><br />And it works just fine. And it's just right there in the examples...  <img class="smilies" src="./../../../images/smilies/icon_redface.gif" alt=":oops:" title="Embarassed" /><p>Statistics: Posted by <a href="https://forums.obdev.at/memberlist.php?mode=viewprofile&amp;u=22058">dode</a> — Tue Jun 07, 2016 1:20 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[dode]]></name></author>
		<updated>2016-06-06T14:09:10+02:00</updated>

		<published>2016-06-06T14:09:10+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=10460&amp;p=31237#p31237</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=10460&amp;p=31237#p31237"/>
		<title type="html"><![CDATA[usbFunctionRead() not getting called]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=10460&amp;p=31237#p31237"><![CDATA[
Hello!<br /><br />I've build a simple USB device with an ATmega328p running at 12 MHz with a crystal, following the &quot;typical circuit&quot; on the V-USB homepage, but running at 5V with the two zener diodes at D+ and D-.<br /><br />It is running fine; it is detected very reliably on a Linux PC and my kernel USB driver module is loaded when the device connects:<br /><br /><div class="codebox"><p>Code: </p><pre><code>&#91;56524.707406&#93; usb 2-1.1: new low-speed USB device number 64 using ehci-pci<br />&#91;56524.807554&#93; usb 2-1.1: New USB device found, idVendor=d0de, idProduct=0001<br />&#91;56524.807563&#93; usb 2-1.1: New USB device strings: Mfr=1, Product=2, SerialNumber=0<br />&#91;56524.807569&#93; usb 2-1.1: Product: USBTherm<br />&#91;56524.807574&#93; usb 2-1.1: Manufacturer: Dode<br />&#91;56525.387240&#93; usbtherm: USB device was connected<br />&#91;56525.387817&#93; usbcore: registered new interface driver usbtherm<br /></code></pre></div><br /><br />Getting the descriptor from the kernel driver like that works fine:<br /><br /><div class="codebox"><p>Code: </p><pre><code>usb_get_descriptor(dev-&gt;usbdev, USB_DT_DEVICE, 0x00,<br />         &amp;usb_dev_desc, sizeof(usb_dev_desc));</code></pre></div><br /><br />Now I'd like to send a custom &quot;vendor&quot; request and have the driver send back a temperature value (max 8 bytes) read &quot;on the fly&quot;. For that I have:<br /><ul><li> Set USB_CFG_IMPLEMENT_FN_READ to 1</li><li> make clean...</li><li> Implemented the function usbFunctionRead()</li><li> Return USB_NO_MSG from usbFunctionSetup()</li></ul><br />From the kernel driver I am calling:<br /><br /><div class="codebox"><p>Code: </p><pre><code>unsigned char data&#91;8&#93;;<br />usb_control_msg(dev-&gt;usbdev, usb_rcvctrlpipe(dev-&gt;usbdev, 0),<br />         0, USB_TYPE_VENDOR, 0, 0, data, sizeof(data), 1000);</code></pre></div><br /><br />In the device, usbFunctionSetup() is entered and USB_NO_MSG is returned, but usbFunctionRead() is never called and the timeout of 1 second is hit.<br /><br />In Wireshark, I can see the &quot;URB CONTROL out&quot; request and the response when the timeout occurs and the response contains a strange URB status:<br /><br /><div class="codebox"><p>Code: </p><pre><code>URB status: No such file or directory (-ENOENT) (-2)</code></pre></div><br /><br />What could I be doing wrong?<p>Statistics: Posted by <a href="https://forums.obdev.at/memberlist.php?mode=viewprofile&amp;u=22058">dode</a> — Mon Jun 06, 2016 2:09 pm</p><hr />
]]></content>
	</entry>
	</feed>
