<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>Kinetis MicrocontrollersのトピックMSD and CDC composite device with USB stack 4.1.1</title>
    <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/MSD-and-CDC-composite-device-with-USB-stack-4-1-1/m-p/644577#M39105</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm going to preface this by saying that I'm stuck for now (at least for some projects) on CodeWarrior 10.6, so using KSDK isn't an option. &amp;nbsp;I'm using the Freescale USB stack v4.1.1 because as far as I know it's the most recent version that's compatible with CW 10.6. &amp;nbsp;I've used it on HCS08, ColdFire, and Kinetis. &amp;nbsp;I have products with ColdFire and Kinetis versions that have to be maintained in parallel so I'm stuck with this stack. &amp;nbsp;I know it's no longer supported and I'm posting&amp;nbsp;this mainly to get a solution out there for anyone else in a similar situation.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I spent hours trying to get a simple MSD+CDC composite device running on a MK22FN1M0. &amp;nbsp;I started with the msd_and_cdc example under app_composite. &amp;nbsp;I ran into a couple of problems right way - first, if USE_CDC_CLASS is defined, then the DFU class is also included as well, for no apparent reason. &amp;nbsp;I think this was probably a case of someone cutting and pasting code without paying attention:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;#ifdef USE_CDC_CLASS&lt;BR /&gt;#include "usb_cdc.h"&lt;BR /&gt;#endif&lt;BR /&gt;#ifdef USE_CDC_CLASS&lt;BR /&gt;#include "usb_dfu.h"&lt;BR /&gt;#endif&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;I got rid of that and then found that there's no function declaration for USB_Class_CDC_Event() in scope. &amp;nbsp;Why the compiler allows implicit function declarations by default I'll never understand, but I fixed that as well.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The MSD function worked fine right off. &amp;nbsp;CDC, however, let me connect successfully once and maybe on one or two other occasions. &amp;nbsp;Every other time, with any terminal program (on both Windows and Ubuntu), it'd fail - on Windows, the error message was some variation of "the parameter is incorrect", depending on the program used.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;With a USB sniffer I could see that the GET_LINE_CODING setup packets were being sent from the host but no proper replies were ever being received. &amp;nbsp;I finally determined that the problem is&amp;nbsp;in&amp;nbsp;USB_Composite_Other_Requests(). It iterates through the list of classes and it's checking to see if the interface number matches, but it will&amp;nbsp;also match if the endpoint number is not 0xff:&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;if(itf_num == intf_arc_ptr-&amp;gt;value[index] || ep_num != 0xFF)&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Since ep_num is initialized to 0 at the start of the function and is only changed if the setup packet specified an endpoint as the destination and not an interface, this check always succeeds and&amp;nbsp;&lt;EM&gt;every&lt;/EM&gt; setup packet handler for any registered class receives every request. &amp;nbsp;For classes with more than one interface, the handler is called once for each interface. &amp;nbsp;This explains why I was seeing two GET_LINE_CODING requests for every connect attempt.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As far as I can tell, the only way this would have ever worked at all was just sheer luck. &amp;nbsp;The status result will be overwritten on the return of each handler so it would often return&amp;nbsp;USBERR_INVALID_REQ_TYPE. &amp;nbsp;I can't imagine what kind of trouble it might cause with other combinations of composite device.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The fix came down to just changing the initialization of ep_num to 0xff. &amp;nbsp;(After fixing the function declaration and the DFU ifdef.)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This code was written two mergers ago so I'm going to skip the rant, except to ask whoever's running the show now to please consider having a native (or at least very fluent) English speaker make at least a cursory pass through all English-language documentation and code comments. &amp;nbsp;I've got nothing against foreign programmers, but most programmers are bad enough at writing documentation in their native language. &amp;nbsp;"The funtion initializes composite endpoint" is not a good description of a function.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;A quick sanity check on anything copied and pasted would also be appreciated. &amp;nbsp;The very first line in usb_composite.c is this:&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;#include "usb_composite.h" &amp;nbsp;/* USB Video Class Header File */&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Ok, rant over. &amp;nbsp;I hope maybe this saves someone else some headaches.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Scott&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 03 Dec 2016 05:03:26 GMT</pubDate>
    <dc:creator>scottm</dc:creator>
    <dc:date>2016-12-03T05:03:26Z</dc:date>
    <item>
      <title>MSD and CDC composite device with USB stack 4.1.1</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/MSD-and-CDC-composite-device-with-USB-stack-4-1-1/m-p/644577#M39105</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm going to preface this by saying that I'm stuck for now (at least for some projects) on CodeWarrior 10.6, so using KSDK isn't an option. &amp;nbsp;I'm using the Freescale USB stack v4.1.1 because as far as I know it's the most recent version that's compatible with CW 10.6. &amp;nbsp;I've used it on HCS08, ColdFire, and Kinetis. &amp;nbsp;I have products with ColdFire and Kinetis versions that have to be maintained in parallel so I'm stuck with this stack. &amp;nbsp;I know it's no longer supported and I'm posting&amp;nbsp;this mainly to get a solution out there for anyone else in a similar situation.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I spent hours trying to get a simple MSD+CDC composite device running on a MK22FN1M0. &amp;nbsp;I started with the msd_and_cdc example under app_composite. &amp;nbsp;I ran into a couple of problems right way - first, if USE_CDC_CLASS is defined, then the DFU class is also included as well, for no apparent reason. &amp;nbsp;I think this was probably a case of someone cutting and pasting code without paying attention:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;#ifdef USE_CDC_CLASS&lt;BR /&gt;#include "usb_cdc.h"&lt;BR /&gt;#endif&lt;BR /&gt;#ifdef USE_CDC_CLASS&lt;BR /&gt;#include "usb_dfu.h"&lt;BR /&gt;#endif&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;I got rid of that and then found that there's no function declaration for USB_Class_CDC_Event() in scope. &amp;nbsp;Why the compiler allows implicit function declarations by default I'll never understand, but I fixed that as well.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The MSD function worked fine right off. &amp;nbsp;CDC, however, let me connect successfully once and maybe on one or two other occasions. &amp;nbsp;Every other time, with any terminal program (on both Windows and Ubuntu), it'd fail - on Windows, the error message was some variation of "the parameter is incorrect", depending on the program used.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;With a USB sniffer I could see that the GET_LINE_CODING setup packets were being sent from the host but no proper replies were ever being received. &amp;nbsp;I finally determined that the problem is&amp;nbsp;in&amp;nbsp;USB_Composite_Other_Requests(). It iterates through the list of classes and it's checking to see if the interface number matches, but it will&amp;nbsp;also match if the endpoint number is not 0xff:&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;if(itf_num == intf_arc_ptr-&amp;gt;value[index] || ep_num != 0xFF)&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Since ep_num is initialized to 0 at the start of the function and is only changed if the setup packet specified an endpoint as the destination and not an interface, this check always succeeds and&amp;nbsp;&lt;EM&gt;every&lt;/EM&gt; setup packet handler for any registered class receives every request. &amp;nbsp;For classes with more than one interface, the handler is called once for each interface. &amp;nbsp;This explains why I was seeing two GET_LINE_CODING requests for every connect attempt.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As far as I can tell, the only way this would have ever worked at all was just sheer luck. &amp;nbsp;The status result will be overwritten on the return of each handler so it would often return&amp;nbsp;USBERR_INVALID_REQ_TYPE. &amp;nbsp;I can't imagine what kind of trouble it might cause with other combinations of composite device.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The fix came down to just changing the initialization of ep_num to 0xff. &amp;nbsp;(After fixing the function declaration and the DFU ifdef.)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This code was written two mergers ago so I'm going to skip the rant, except to ask whoever's running the show now to please consider having a native (or at least very fluent) English speaker make at least a cursory pass through all English-language documentation and code comments. &amp;nbsp;I've got nothing against foreign programmers, but most programmers are bad enough at writing documentation in their native language. &amp;nbsp;"The funtion initializes composite endpoint" is not a good description of a function.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;A quick sanity check on anything copied and pasted would also be appreciated. &amp;nbsp;The very first line in usb_composite.c is this:&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;#include "usb_composite.h" &amp;nbsp;/* USB Video Class Header File */&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Ok, rant over. &amp;nbsp;I hope maybe this saves someone else some headaches.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Scott&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 03 Dec 2016 05:03:26 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/MSD-and-CDC-composite-device-with-USB-stack-4-1-1/m-p/644577#M39105</guid>
      <dc:creator>scottm</dc:creator>
      <dc:date>2016-12-03T05:03:26Z</dc:date>
    </item>
  </channel>
</rss>

