<?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/3458" />

	<title>Objective Development Forums</title>
	
	<link href="https://forums.obdev.at/index.php" />
	<updated>2013-11-25T23:20:43+02:00</updated>

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

		<entry>
		<author><name><![CDATA[blargg]]></name></author>
		<updated>2013-11-25T23:20:43+02:00</updated>

		<published>2013-11-25T23:20:43+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=3458&amp;p=26252#p26252</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=3458&amp;p=26252#p26252"/>
		<title type="html"><![CDATA[Re: How Do You Check CRC16 From Application?]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=3458&amp;p=26252#p26252"><![CDATA[
Or, if wasting a few cycles isn't a problem (and you know that len &lt; 256-2),<br /><br /><div class="codebox"><p>Code: </p><pre><code>uchar usbFunctionWrite( uchar* data, uchar len )<br />{<br />    if ( usbCrc16( data, len + 2 ) != 0x4FFE )<br />    {<br />        // CRC error<br />    }<br />    ...<br />}<br /></code></pre></div><br />This relies on the property that the checksum of some data with its usb CRC appended is 0x4FFE, which is just the CRC of two zero bytes alone. This occurs because the appended CRC XORs itself and the previous data out of the CRC, leaving the equivalent of two zero bytes and no data.<br /><br />OK, and to check the CRC of normal incoming requests:<br /><div class="codebox"><p>Code: </p><pre><code>uchar usbFunctionSetup( uchar data &#91;8&#93; )<br />{<br />    if ( usbCrc16( data, 8 + 2 ) != 0x4FFE )<br />    {<br />        // report error to host somehow, perhaps returning a zero-length reply (return 0;)<br />    }<br />    ...<br />}<br /></code></pre></div><br />Though this still doesn't check ones handled internally by V-USB, like descriptor reading.<br /><br /><a href="http://vusb.wikidot.com/examples#toc10" class="postlink">Added to V-USB Wiki</a><br /><br />EDIT: And if you just want to ignore any packets with an invalid CRC (including those handled by V-USB internally), just add this to usbconfig.h:<br /><div class="codebox"><p>Code: </p><pre><code>/* Check CRC of all received data */<br />#define USB_RX_USER_HOOK( data, len ) { \<br />    if ( usbCrc16( data, len + 2 ) != 0x4FFE )\<br />        return;\<br />}<br /></code></pre></div><br />This gets inserted into usbProcessRx() at the beginning, which is called from usbPoll(). The downside is that you don't get to take any application-specific action. I'm not sure how well this works, ignoring packets. The host might not notice, thus leaving the CRC error still harmful to reliable functioning.<p>Statistics: Posted by <a href="https://forums.obdev.at/memberlist.php?mode=viewprofile&amp;u=20076">blargg</a> — Mon Nov 25, 2013 11:20 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[christian]]></name></author>
		<updated>2009-11-01T10:54:59+02:00</updated>

		<published>2009-11-01T10:54:59+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=3458&amp;p=11722#p11722</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=3458&amp;p=11722#p11722"/>
		<title type="html"><![CDATA[Re: How Do You Check CRC16 From Application?]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=3458&amp;p=11722#p11722"><![CDATA[
The function call in the comment is somewhat outdated now...<br /><br />You would call usbCrc16(data, len) and compare the result to data[len] and data[len + 1].<p>Statistics: Posted by <a href="https://forums.obdev.at/memberlist.php?mode=viewprofile&amp;u=8">christian</a> — Sun Nov 01, 2009 10:54 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[rjburke377]]></name></author>
		<updated>2009-10-29T07:27:45+02:00</updated>

		<published>2009-10-29T07:27:45+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=3458&amp;p=11657#p11657</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=3458&amp;p=11657#p11657"/>
		<title type="html"><![CDATA[How Do You Check CRC16 From Application?]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=3458&amp;p=11657#p11657"><![CDATA[
Is there an example that shows how to verify CRC16 from uchar usbFunctionWrite( uchar *data, uchar len ) ?<br /><br />What parms do you pass to usbCrc16() and what do you compare? usbdrv.s seems to suggest unsigned crc = usbCrc16(buffer + 1, usbRxLen - 3) but I don't know how this relates to usbFunctionWrite().<br /><br />/RJ<p>Statistics: Posted by <a href="https://forums.obdev.at/memberlist.php?mode=viewprofile&amp;u=2913">rjburke377</a> — Thu Oct 29, 2009 7:27 am</p><hr />
]]></content>
	</entry>
	</feed>
