Fix KL25Z connect problem with some USB 3.0 hosts
Fix KL25Z connect problem with some USB 3.0 hosts

This change fixes a problem I've encountered using the Freescale KL25Z as a USB client device when attaching to a USB 3.0 port on a host PC.  I've personally observed the problem on two PCs, one a Dell running Windows 8.1 and the other a custom-built Windows 7 machine with a Gigabyte mobo.  Several other people on the Web have reported what appears to be the same problem.  It even appears to happen with some Macs - so it's apparently not Windows-specific or Windows-version-specific.  But it does seem to be USB 3.0 specific, and one report speculated that the common element is the Intel Haswell chip set on the host side.

The problem can be worked around by using USB 2.1 ports (many PCs have a mix of 2.1 and 3.0 port hardware) or by connecting a USB 2.1 hub between the device and host.  I have USB 2.1 ports on both of my testing machines, and this solution does work for me.  But I wanted to fix it at the software level if possible, so that my project would work for people who might only have USB 3.0 ports available.

I tracked down the problem to a timing issue that seems to cause the device and host to get out of sync with respect to flow direction on the USB connection during the initial handshake. It seems that the host can issue a CONTROL OUT token at a point where the client is trying to send the response for a previous CONTROL IN token. I found a note in some USB 3.0 reference material that this situation can occur, and that the client can resolve it by sending a zero-length ACK, which tells the host that the client isn't ready and that the host request should be repeated. 

My fix sends a zero-length reply in USBDevice::controlOut() when the control flow error is detected, and also explicitly sends the pending CONTROL_IN packet.  This appears to fix it reliably on my machine.  I'm not entirely confident about the fix, though, since I don't feel I understand the USB protocol or the mbed code in enough depth.  I'm submitting the change here in the hope that someone with a deeper knowledge of the mbed code can determine if this is a good fix, and if not can hopefully use it as the starting point for a better solution.  

Note that I submitted the same pull request via the mbed source control system, but I was advised by another mbed user that I should also submit it directly on github.  Apologies for any confusion caused by the redundant submissions.
hwfwgrp/mbed,rgrover/mbed,jrjang/mbed,devanlai/mbed,masaohamanaka/mbed,xcrespo/mbed,Marcomissyou/mbed,nvlsianpu/mbed,FranklyDev/mbed,kpurusho/mbed,K4zuki/mbed,bcostm/mbed-os,c1728p9/mbed-os,ryankurte/mbed-os,sg-/mbed-drivers,maximmbed/mbed,mnlipp/mbed,tung7970/mbed-os,Timmmm/mbed,kjbracey-arm/mbed,jferreir/mbed,theotherjimmy/mbed,radhika-raghavendran/mbed-os5.1-onsemi,nRFMesh/mbed-os,hwfwgrp/mbed,bentwire/mbed,tung7970/mbed-os-1,fahhem/mbed-os,cvtsi2sd/mbed-os,jpbrucker/mbed,adamgreen/mbed,cvtsi2sd/mbed-os,DanKupiniak/mbed,Willem23/mbed,autopulated/mbed,hwfwgrp/mbed,Sweet-Peas/mbed,bulislaw/mbed-os,arostm/mbed-os,xcrespo/mbed,screamerbg/mbed,devanlai/mbed,Archcady/mbed-os,andreaslarssonublox/mbed,fanghuaqi/mbed,bentwire/mbed,geky/mbed,mbedmicro/mbed,HeadsUpDisplayInc/mbed,autopulated/mbed,mikaleppanen/mbed-os,netzimme/mbed-os,mnlipp/mbed,nvlsianpu/mbed,dbestm/mbed,fanghuaqi/mbed,bulislaw/mbed-os,RonEld/mbed,wodji/mbed,logost/mbed,mikaleppanen/mbed-os,ban4jp/mbed,infinnovation/mbed-os,brstew/MBED-BUILD,catiedev/mbed-os,svogl/mbed-os,tung7970/mbed-os-1,maximmbed/mbed,adustm/mbed,0xc0170/mbed-drivers,bremoran/mbed-drivers,fahhem/mbed-os,radhika-raghavendran/mbed-os5.1-onsemi,brstew/MBED-BUILD,jpbrucker/mbed,pbrook/mbed,kpurusho/mbed,kjbracey-arm/mbed,mikaleppanen/mbed-os,svastm/mbed,jrjang/mbed,sg-/mbed-drivers,sam-geek/mbed,jferreir/mbed,rgrover/mbed,bikeNomad/mbed,mnlipp/mbed,netzimme/mbed-os,mikaleppanen/mbed-os,monkiineko/mbed-os,theotherjimmy/mbed,arostm/mbed-os,arostm/mbed-os,ryankurte/mbed-os,j-greffe/mbed-os,wodji/mbed,kl-cruz/mbed-os,andreaslarssonublox/mbed,j-greffe/mbed-os,JasonHow44/mbed,maximmbed/mbed,masaohamanaka/mbed,fanghuaqi/mbed,cvtsi2sd/mbed-os,radhika-raghavendran/mbed-os5.1-onsemi,YarivCol/mbed-os,logost/mbed,Willem23/mbed,Timmmm/mbed,adamgreen/mbed,ban4jp/mbed,fanghuaqi/mbed,svogl/mbed-os,0xc0170/mbed-drivers,jpbrucker/mbed,kl-cruz/mbed-os,jamesadevine/mbed,rosterloh/mbed,pi19404/mbed,JasonHow44/mbed,brstew/MBED-BUILD,maximmbed/mbed,adamgreen/mbed,screamerbg/mbed,YarivCol/mbed-os,masaohamanaka/mbed,infinnovation/mbed-os,NXPmicro/mbed,Tiryoh/mbed,Shengliang/mbed,getopenmono/mbed,adustm/mbed,alertby/mbed,masaohamanaka/mbed,infinnovation/mbed-os,bcostm/mbed-os,pbrook/mbed,pradeep-gr/mbed-os5-onsemi,c1728p9/mbed-os,kpurusho/mbed,fpiot/mbed-ats,bikeNomad/mbed,hwfwgrp/mbed,karsev/mbed-os,tung7970/mbed-os-1,naves-thiago/mbed-midi,pi19404/mbed,mnlipp/mbed,alertby/mbed,catiedev/mbed-os,autopulated/mbed,adustm/mbed,jeremybrodt/mbed,Willem23/mbed,tung7970/mbed-os-1,CalSol/mbed,getopenmono/mbed,bikeNomad/mbed,jamesadevine/mbed,maximmbed/mbed,Archcady/mbed-os,getopenmono/mbed,NitinBhaskar/mbed,j-greffe/mbed-os,nRFMesh/mbed-os,alertby/mbed,mmorenobarm/mbed-os,jeremybrodt/mbed,arostm/mbed-os,DanKupiniak/mbed,Tiryoh/mbed,bcostm/mbed-os,kpurusho/mbed,sam-geek/mbed,pi19404/mbed,fahhem/mbed-os,rosterloh/mbed,andreaslarssonublox/mbed,kpurusho/mbed,K4zuki/mbed,fanghuaqi/mbed,jeremybrodt/mbed,jamesadevine/mbed,jamesadevine/mbed,kl-cruz/mbed-os,logost/mbed,mazimkhan/mbed-os,Timmmm/mbed,Tiryoh/mbed,c1728p9/mbed-os,masaohamanaka/mbed,YarivCol/mbed-os,jamesadevine/mbed,bremoran/mbed-drivers,HeadsUpDisplayInc/mbed,getopenmono/mbed,mazimkhan/mbed-os,mazimkhan/mbed-os,jferreir/mbed,GustavWi/mbed,svogl/mbed-os,Shengliang/mbed,jeremybrodt/mbed,fvincenzo/mbed-os,bikeNomad/mbed,infinnovation/mbed-os,theotherjimmy/mbed,c1728p9/mbed-os,struempelix/mbed,pedromes/mbed,struempelix/mbed,pbrook/mbed,DanKupiniak/mbed,infinnovation/mbed-os,RonEld/mbed,naves-thiago/mbed-midi,kjbracey-arm/mbed,larks/mbed,andreaslarssonublox/mbed,Archcady/mbed-os,RonEld/mbed,nabilbendafi/mbed,c1728p9/mbed-os,fpiot/mbed-ats,HeadsUpDisplayInc/mbed,svogl/mbed-os,naves-thiago/mbed-midi,brstew/MBED-BUILD,naves-thiago/mbed-midi,Shengliang/mbed,adustm/mbed,Archcady/mbed-os,tung7970/mbed-os,geky/mbed,nabilbendafi/mbed,monkiineko/mbed-os,andcor02/mbed-os,monkiineko/mbed-os,catiedev/mbed-os,NXPmicro/mbed,wodji/mbed,bcostm/mbed-os,RonEld/mbed,pbrook/mbed,rgrover/mbed,mbedmicro/mbed,ARM-software/mbed-beetle,j-greffe/mbed-os,Marcomissyou/mbed,CalSol/mbed,ban4jp/mbed,catiedev/mbed-os,dbestm/mbed,getopenmono/mbed,jrjang/mbed,netzimme/mbed-os,pedromes/mbed,theotherjimmy/mbed,kjbracey-arm/mbed,bikeNomad/mbed,betzw/mbed-os,catiedev/mbed-os,pradeep-gr/mbed-os5-onsemi,EmuxEvans/mbed,mazimkhan/mbed-os,NXPmicro/mbed,HeadsUpDisplayInc/mbed,karsev/mbed-os,Tiryoh/mbed,svastm/mbed,nabilbendafi/mbed,FranklyDev/mbed,al177/mbed,mazimkhan/mbed-os,wodji/mbed,jpbrucker/mbed,wodji/mbed,alertby/mbed,monkiineko/mbed-os,logost/mbed,struempelix/mbed,HeadsUpDisplayInc/mbed,GustavWi/mbed,jpbrucker/mbed,devanlai/mbed,K4zuki/mbed,RonEld/mbed,NitinBhaskar/mbed,nabilbendafi/mbed,bulislaw/mbed-os,mmorenobarm/mbed-os,svastm/mbed,fvincenzo/mbed-os,pi19404/mbed,svastm/mbed,cvtsi2sd/mbed-os,jferreir/mbed,monkiineko/mbed-os,cvtsi2sd/mbed-os,YarivCol/mbed-os,FranklyDev/mbed,pedromes/mbed,arostm/mbed-os,xcrespo/mbed,hwfwgrp/mbed,dbestm/mbed,rosterloh/mbed,FranklyDev/mbed,al177/mbed,bcostm/mbed-os,tung7970/mbed-os,ban4jp/mbed,naves-thiago/mbed-midi,YarivCol/mbed-os,mbedmicro/mbed,alertby/mbed,bentwire/mbed,nvlsianpu/mbed,Sweet-Peas/mbed,jpbrucker/mbed,andcor02/mbed-os,Shengliang/mbed,fvincenzo/mbed-os,karsev/mbed-os,adamgreen/mbed,svogl/mbed-os,rosterloh/mbed,RonEld/mbed,mbedmicro/mbed,CalSol/mbed,ban4jp/mbed,fpiot/mbed-ats,NXPmicro/mbed,autopulated/mbed,geky/mbed,jferreir/mbed,autopulated/mbed,mikaleppanen/mbed-os,nRFMesh/mbed-os,netzimme/mbed-os,screamerbg/mbed,Archcady/mbed-os,fahhem/mbed-os,mmorenobarm/mbed-os,K4zuki/mbed,Tiryoh/mbed,nvlsianpu/mbed,maximmbed/mbed,adustm/mbed,catiedev/mbed-os,andcor02/mbed-os,GustavWi/mbed,al177/mbed,netzimme/mbed-os,jrjang/mbed,Sweet-Peas/mbed,iriark01/mbed-drivers,CalSol/mbed,nRFMesh/mbed-os,NXPmicro/mbed,dbestm/mbed,karsev/mbed-os,bentwire/mbed,devanlai/mbed,sam-geek/mbed,ARM-software/mbed-beetle,sam-geek/mbed,al177/mbed,cvtsi2sd/mbed-os,fahhem/mbed-os,radhika-raghavendran/mbed-os5.1-onsemi,mbedmicro/mbed,JasonHow44/mbed,logost/mbed,GustavWi/mbed,fvincenzo/mbed-os,nabilbendafi/mbed,Timmmm/mbed,alertby/mbed,adustm/mbed,brstew/MBED-BUILD,geky/mbed,andcor02/mbed-os,Timmmm/mbed,pbrook/mbed,CalSol/mbed,dbestm/mbed,Marcomissyou/mbed,radhika-raghavendran/mbed-os5.1-onsemi,ban4jp/mbed,Shengliang/mbed,naves-thiago/mbed-midi,betzw/mbed-os,bcostm/mbed-os,bulislaw/mbed-os,brstew/MBED-BUILD,pedromes/mbed,mmorenobarm/mbed-os,mnlipp/mbed,ryankurte/mbed-os,bulislaw/mbed-os,NitinBhaskar/mbed,ryankurte/mbed-os,andcor02/mbed-os,larks/mbed,pi19404/mbed,rosterloh/mbed,ryankurte/mbed-os,tung7970/mbed-os-1,infinnovation/mbed-os,kpurusho/mbed,mazimkhan/mbed-os,pbrook/mbed,HeadsUpDisplayInc/mbed,NitinBhaskar/mbed,Sweet-Peas/mbed,NitinBhaskar/mbed,xcrespo/mbed,svastm/mbed,mikaleppanen/mbed-os,devanlai/mbed,struempelix/mbed,devanlai/mbed,Marcomissyou/mbed,andreaslarssonublox/mbed,jferreir/mbed,struempelix/mbed,monkiineko/mbed-os,xcrespo/mbed,sam-geek/mbed,FranklyDev/mbed,adamgreen/mbed,betzw/mbed-os,theotherjimmy/mbed,nRFMesh/mbed-os,jrjang/mbed,theotherjimmy/mbed,EmuxEvans/mbed,larks/mbed,nRFMesh/mbed-os,EmuxEvans/mbed,andcor02/mbed-os,betzw/mbed-os,iriark01/mbed-drivers,hwfwgrp/mbed,c1728p9/mbed-os,wodji/mbed,ryankurte/mbed-os,dbestm/mbed,screamerbg/mbed,tung7970/mbed-os,masaohamanaka/mbed,kl-cruz/mbed-os,arostm/mbed-os,svogl/mbed-os,Sweet-Peas/mbed,JasonHow44/mbed,mnlipp/mbed,al177/mbed,xcrespo/mbed,tung7970/mbed-os,EmuxEvans/mbed,GustavWi/mbed,JasonHow44/mbed,logost/mbed,Shengliang/mbed,screamerbg/mbed,getopenmono/mbed,JasonHow44/mbed,bentwire/mbed,mmorenobarm/mbed-os,betzw/mbed-os,mmorenobarm/mbed-os,karsev/mbed-os,nabilbendafi/mbed,fahhem/mbed-os,netzimme/mbed-os,pi19404/mbed,autopulated/mbed,pradeep-gr/mbed-os5-onsemi,j-greffe/mbed-os,Sweet-Peas/mbed,fvincenzo/mbed-os,pradeep-gr/mbed-os5-onsemi,NXPmicro/mbed,radhika-raghavendran/mbed-os5.1-onsemi,screamerbg/mbed,jrjang/mbed,fpiot/mbed-ats,K4zuki/mbed,karsev/mbed-os,Marcomissyou/mbed,Tiryoh/mbed,K4zuki/mbed,CalSol/mbed,jeremybrodt/mbed,nvlsianpu/mbed,j-greffe/mbed-os,larks/mbed,fpiot/mbed-ats,larks/mbed,DanKupiniak/mbed,EmuxEvans/mbed,rgrover/mbed,jamesadevine/mbed,Willem23/mbed,Archcady/mbed-os,struempelix/mbed,EmuxEvans/mbed,pedromes/mbed,kl-cruz/mbed-os,rgrover/mbed,ARM-software/mbed-beetle,Marcomissyou/mbed,adamgreen/mbed,pradeep-gr/mbed-os5-onsemi,geky/mbed,bentwire/mbed,fpiot/mbed-ats,pedromes/mbed,Willem23/mbed,ARM-software/mbed-beetle,betzw/mbed-os,al177/mbed,rosterloh/mbed,Timmmm/mbed,pradeep-gr/mbed-os5-onsemi,YarivCol/mbed-os,kl-cruz/mbed-os,bulislaw/mbed-os,nvlsianpu/mbed,larks/mbed