<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://community.arm.com/utility/feedstylesheets/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/"><channel><title>compiling mcb2300 usb examples in GCC</title><link>https://community.arm.com/developer/tools-software/tools/f/keil-forum/22325/compiling-mcb2300-usb-examples-in-gcc</link><description> 
Hi All, 

 
I downloaded the Keil USB Examples for the MCB2300 board on the
website. All examples worked well (except USBMem, because of the 16
kb limit for the evaluation version) when with the default
compiler. 

 
I adapted the code to work with</description><dc:language>en-US</dc:language><generator>Telligent Community 10</generator><item><title>RE: compiling mcb2300 usb examples in GCC</title><link>https://community.arm.com/thread/75438?ContentTypeID=1</link><pubDate>Thu, 20 Sep 2007 06:45:31 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:8f9643e6-e513-4e4e-84f2-427b27fc68c0</guid><dc:creator>Sergio Sider</dc:creator><description>&lt;p&gt;&lt;p&gt;
Akshat, you&amp;#39;re welcome...&lt;/p&gt;

&lt;p&gt;
Martin, thanks.. good idea!&lt;/p&gt;

&lt;p&gt;
Regards,&lt;br /&gt;
Sergio.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: compiling mcb2300 usb examples in GCC</title><link>https://community.arm.com/thread/48516?ContentTypeID=1</link><pubDate>Thu, 20 Sep 2007 06:14:20 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:f8e65edf-4e4e-4ae4-a048-4c9bce64242e</guid><dc:creator>Martin G&amp;#195;&amp;#188;nther</dc:creator><description>&lt;p&gt;&lt;p&gt;
Hello Sergio,&lt;/p&gt;

&lt;p&gt;
If you change the USBMEM example in such a way that it uses
allocated memory (heap) instead of static memory (byte array) than it
should be possible to use the default compiler in evaluation
version.&lt;/p&gt;

&lt;p&gt;
Best Regards,&lt;br /&gt;
Martin&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: compiling mcb2300 usb examples in GCC</title><link>https://community.arm.com/thread/75443?ContentTypeID=1</link><pubDate>Thu, 20 Sep 2007 04:39:50 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:c2df6ad1-6ec6-4350-8be9-3c8827098b78</guid><dc:creator>Akshat Mehra</dc:creator><description>&lt;p&gt;&lt;p&gt;
I would like to thank Sergio Sider you as your efforts also helped
to solve this USB issue.&lt;/p&gt;

&lt;p&gt;
Akshat&lt;br /&gt;
mehra.akshat@rediffmail.cim&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: compiling mcb2300 usb examples in GCC</title><link>https://community.arm.com/thread/124061?ContentTypeID=1</link><pubDate>Sun, 02 Sep 2007 06:22:31 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:0c7f43d2-7aca-4f29-9bcd-0939bd6a5912</guid><dc:creator>Sergio Sider</dc:creator><description>&lt;p&gt;&lt;p&gt;
Hi again,&lt;/p&gt;

&lt;p&gt;
Just to clarify: When I said &amp;quot;GCC does not correctly handle
unaligned packed pointers&amp;quot;. I was saying that the keyword
&amp;quot;__attribute__((__packed__))&amp;quot; was not doing what it was intended to
do.&lt;/p&gt;

&lt;p&gt;
About portable code, I did not mention it originally.&lt;br /&gt;
If the code is portable or not, I really don&amp;#39;t care. I am not a
believer in &amp;#39;portable code&amp;#39; for embedded systems anyway. ;-)&lt;/p&gt;

&lt;p&gt;
IMHO the code was supplied as sample code for the Keil product
(not just the compiler, as it claims to work with GCC also) and the
MCB2300 board that they sell (and I bought, so I am not stealing
code). I was trying to make it work in one of its available
configurations.&lt;/p&gt;

&lt;p&gt;
Regards,&lt;br /&gt;
Sergio.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: compiling mcb2300 usb examples in GCC</title><link>https://community.arm.com/thread/113151?ContentTypeID=1</link><pubDate>Sun, 02 Sep 2007 06:03:24 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:9060239a-1897-4351-9179-67d8d0664063</guid><dc:creator>Andy Neil</dc:creator><description>&lt;p&gt;&lt;p&gt;
&lt;i&gt;&amp;quot;the code is far from portable&amp;quot;&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
Did it ever claim to be?&lt;/p&gt;

&lt;p&gt;
It was, presumably, supplied as sample code for the Keil
compiler?&lt;/p&gt;

&lt;p&gt;
Therefore, one would expect it do demonstrate the particular
features of that compiler - and this would naturally make it
non-portable, wouldn&amp;#39;t it...?&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: compiling mcb2300 usb examples in GCC</title><link>https://community.arm.com/thread/99590?ContentTypeID=1</link><pubDate>Sun, 02 Sep 2007 05:48:22 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:a392f9bd-5f7a-4ae5-94a2-341766133fd9</guid><dc:creator>Sergio Sider</dc:creator><description>&lt;p&gt;&lt;p&gt;
Hi Andy,&lt;/p&gt;

&lt;p&gt;
You are right. Although the &amp;quot;__attribute__((__packed__))&amp;quot; keyword
was supposed to do the &amp;#39;trick&amp;#39;.&lt;br /&gt;
And the code is far from portable... ;-)&lt;/p&gt;

&lt;p&gt;
Regards,&lt;br /&gt;
Sergio.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: compiling mcb2300 usb examples in GCC</title><link>https://community.arm.com/thread/88494?ContentTypeID=1</link><pubDate>Sat, 01 Sep 2007 22:00:09 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:6f35431c-eb97-4b94-8bc4-1aa150e3c728</guid><dc:creator>Andy Neil</dc:creator><description>&lt;p&gt;&lt;p&gt;
&lt;i&gt;&amp;quot;GCC does not correctly&lt;/i&gt; (sic?) &lt;i&gt;handle unaligned packed
pointers&amp;quot;&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
I suspect that the handling of unaligned packed pointers is, at
best, &lt;i&gt;implementation defined&lt;/i&gt;; so you cannot say that GCC is
&amp;quot;incorrect&amp;quot; - only that it is &amp;quot;different&amp;quot;.&lt;/p&gt;

&lt;p&gt;
Portable software must &lt;i&gt;&lt;b&gt;never&lt;/b&gt;&lt;/i&gt; rely upon
implementation-defined behaviour!&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: compiling mcb2300 usb examples in GCC</title><link>https://community.arm.com/thread/48515?ContentTypeID=1</link><pubDate>Sat, 01 Sep 2007 17:17:38 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:d1589641-f34e-400b-899e-79a5bfb8c1a9</guid><dc:creator>Sergio Sider</dc:creator><description>&lt;p&gt;&lt;p&gt;
Hi All,&lt;/p&gt;

&lt;p&gt;
After some substantive hair loss, I found the solution to my
problem...&lt;/p&gt;

&lt;p&gt;
GCC does not correctly handles unaligned packed pointers, as found
on the USB_ReadEP and USB_WriteEP functions&lt;/p&gt;

&lt;p&gt;
In Keil C:&lt;/p&gt;

&lt;p&gt;
*((__packed DWORD *)pData) = RX_DATA;&lt;br /&gt;
pData += 4;&lt;/p&gt;

&lt;p&gt;
In GCC, converting to the pack attribute was not enough:&lt;/p&gt;

&lt;p&gt;
*((DWORD __attribute__((__packed__)) *)pData) = RX_DATA;&lt;br /&gt;
pData += 4;&lt;/p&gt;

&lt;p&gt;
I had to change the code to handle it one byte at time:&lt;/p&gt;

&lt;p&gt;
DWORD x = RX_DATA;&lt;br /&gt;
*pData++ = x; x &amp;gt;&amp;gt;= 8;&lt;br /&gt;
*pData++ = x; x &amp;gt;&amp;gt;= 8;&lt;br /&gt;
*pData++ = x; x &amp;gt;&amp;gt;= 8;&lt;br /&gt;
*pData++ = x; x &amp;gt;&amp;gt;= 8;&lt;/p&gt;

&lt;p&gt;
and in the USB_WriteEP function, instead of:&lt;/p&gt;

&lt;p&gt;
TX_DATA = *((DWORD __attribute__((__packed__)) *)pData);&lt;/p&gt;

&lt;p&gt;
I used:&lt;/p&gt;

&lt;p&gt;
TX_DATA = (pData[3] &amp;lt;&amp;lt; 24) | (pData[2] &amp;lt;&amp;lt; 16) |
(pData[1] &amp;lt;&amp;lt; 8) | pData[0];&lt;/p&gt;

&lt;p&gt;
And, just to make sure, in the USB_GetStatus, I changed:&lt;/p&gt;

&lt;p&gt;
*((__packed WORD *)EP0Buf) = 0;&lt;/p&gt;

&lt;p&gt;
to:&lt;/p&gt;

&lt;p&gt;
EP0Buf[0]=0;&lt;br /&gt;
EP0Nuf[1]=0;&lt;/p&gt;

&lt;p&gt;
and changed:&lt;/p&gt;

&lt;p&gt;
*((__packed WORD *)EP0Buf) = (USB_EndPointHalt &amp;amp; m) ? 1 :
0;&lt;/p&gt;

&lt;p&gt;
to:&lt;/p&gt;

&lt;p&gt;
EP0Buf[1]=0;&lt;br /&gt;
EP0Buf[0]=(USB_EndPointHalt &amp;amp; m) ? 1 : 0;&lt;/p&gt;

&lt;p&gt;
Finally, just to be on the safe side, I used the
__attribute__((__packed__)) on ALL structs and unions, even when not
done on the original code for Keil C.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>