<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/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/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Question - USB EPDATA and EP0DATADONE Events</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/43285/question---usb-epdata-and-ep0datadone-events</link><description>Hi, 
 I&amp;#39;m working on the Mbed-OS USB HAL implementation for the nRF52840. I&amp;#39;m having a bit of difficulty getting the expectations of the USB stack to match up with the event information the hardware gives me. 
 
 Specifically, I&amp;#39;m wondering when exactly</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 05 Feb 2019 08:22:49 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/43285/question---usb-epdata-and-ep0datadone-events" /><item><title>RE: Question - USB EPDATA and EP0DATADONE Events</title><link>https://devzone.nordicsemi.com/thread/169425?ContentTypeID=1</link><pubDate>Tue, 05 Feb 2019 08:22:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5c35777b-28a8-4ec7-935f-329cefdcab3e</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;[quote user="aglass0fmilk"][/quote]&lt;/p&gt;
&lt;p&gt;So I have read through the datasheet a number of times. I understand that during the data stage of control transfers the EP0DATADONE event is generated after an ACK to/from the host. However, my question concerns cases that aren&amp;#39;t described in the diagrams. I have marked up the datasheet diagram to better explain where I&amp;#39;m confused:&lt;/p&gt;
&lt;p&gt;&lt;img style="cursor:zoom-in;" alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/1200x800/__key/communityserver-discussions-components-files/4/ep0datadone_2D00_question.jpg" /&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;The stages here are incomplete wrt. signalling in the Setup stage and Status stage, as it focuses on the data stage only.&lt;/p&gt;
&lt;p&gt;The EVENTS_EP0DATADONE shall fire for any ACK that is either delivered or received on the control endpoint, regardless of what state the enumeration is in, as stated in the documentation:&lt;/p&gt;
&lt;p&gt;[quote][/quote]&lt;/p&gt;
&lt;p&gt;&lt;span&gt;The EPDATA event indicates that a successful (acknowledged) data transaction has occurred on the data endpoint(s) flagged in register&amp;nbsp;&lt;/span&gt;&lt;a href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.nrf52840.ps/usbd.html?cp=2_0_0_5_34#register.EPDATASTATUS"&gt;EPDATASTATUS&lt;/a&gt;&lt;span&gt;. A successful (acknowledged) data transaction on endpoint 0 is signalled by the EP0DATADONE event.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;/p&gt;
&lt;p&gt;Håkon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Question - USB EPDATA and EP0DATADONE Events</title><link>https://devzone.nordicsemi.com/thread/169389?ContentTypeID=1</link><pubDate>Tue, 05 Feb 2019 00:43:14 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f83077b2-5a14-45d4-ac2b-285cd874b1a4</guid><dc:creator>George Beckstien</dc:creator><description>&lt;p&gt;Hi H&amp;aring;kon, thanks for your response&lt;/p&gt;
[quote userid="2115" url="~/f/nordic-q-a/43285/question---usb-epdata-and-ep0datadone-events/169345"]&amp;nbsp;EVENTS_EPDATA is generated for each successful transaction for EPs 1 to 7, while EP0DATADONE is signalling from the USBD that you have ACKed a payload on EP0.[/quote]
&lt;p&gt;Alright, that is clear enough for EVENTS_EPDATA.&lt;/p&gt;
[quote userid="2115" url="~/f/nordic-q-a/43285/question---usb-epdata-and-ep0datadone-events/169345"]Since you know the total size of your descriptor, the firmware should start the task EP0STATUS when the last EVENTS_EP0DATADONE has been issued to allow the STATUS stage to start.[/quote]
&lt;p&gt;As I am developing a HAL driver for Mbed-OS it is not the case that I know the total size of the descriptor. The upper layers of the Mbed stack handle breaking the transfers up into chunks of ep_max_packet_size. I have been able to detect when the last packet is being sent in the data stage because the last transfer is always less than ep_max_packet_size (even if the total payload is a multiple of that, USB requires the device to send a zero-length-packet to notify the host it is done sending). So this is not really a problem.&lt;/p&gt;
&lt;p&gt;[quote userid="2115" url="~/f/nordic-q-a/43285/question---usb-epdata-and-ep0datadone-events/169345"][/quote]&lt;/p&gt;
&lt;blockquote class="quote"&gt;
&lt;div class="quote-content"&gt;Is an EP0DATADONE event generated when the DATA token of the hardware-handled status stage ACK&amp;#39;d?&lt;/div&gt;
&lt;/blockquote&gt;
&lt;div class="quote-footer"&gt;&lt;/div&gt;
&lt;p&gt;It is generated when the host ACKs the EP0 DATA, yes.&lt;/p&gt;
&lt;div class="quote-header"&gt;&lt;/div&gt;
&lt;blockquote class="quote"&gt;
&lt;div class="quote-content"&gt;Similarly, is an EP0DATADONE event generated during the setup stage of a control transfer after the DATA token is ACK&amp;#39;d?&lt;/div&gt;
&lt;/blockquote&gt;
&lt;div class="quote-footer"&gt;&lt;/div&gt;
&lt;p&gt;&amp;nbsp;Yes. It&amp;#39;s generated after you either send an ACK (control read) or receive an ACK (control write) on EP0. The figures for control read/write in the PS might be easier to read than my explanation:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.nrf52840.ps/usbd.html?cp=2_0_0_5_34_8#concept_usb_ctrl_ep"&gt;http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.nrf52840.ps/usbd.html?cp=2_0_0_5_34_8#concept_usb_ctrl_ep&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;So I have read through the datasheet a number of times. I understand that during the data stage of control transfers the EP0DATADONE event is generated after an ACK to/from the host. However, my question concerns cases that aren&amp;#39;t described in the diagrams. I have marked up the datasheet diagram to better explain where I&amp;#39;m confused:&lt;/p&gt;
&lt;p&gt;&lt;img alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/1200x800/__key/communityserver-discussions-components-files/4/ep0datadone_2D00_question.jpg" /&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Question - USB EPDATA and EP0DATADONE Events</title><link>https://devzone.nordicsemi.com/thread/169345?ContentTypeID=1</link><pubDate>Mon, 04 Feb 2019 15:10:26 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d286220b-67a7-4228-86bb-2568f46f493d</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
[quote user=""]Under what circumstances will EPDATA and EP0DATADONE events be generated?[/quote]
&lt;p&gt;&amp;nbsp;EVENTS_EPDATA is generated for each successful transaction for EPs 1 to 7, while EP0DATADONE is signalling from the USBD that you have ACKed a payload on EP0.&lt;/p&gt;
&lt;p&gt;Since you know the total size of your descriptor, the firmware should start the task EP0STATUS when the last EVENTS_EP0DATADONE has been issued to allow the STATUS stage to start.&lt;/p&gt;
[quote user=""]Is an EP0DATADONE event generated when the DATA token of the hardware-handled status stage ACK&amp;#39;d?[/quote]
&lt;p&gt;It is generated when the host ACKs the EP0 DATA, yes.&lt;/p&gt;
[quote user=""]Similarly, is an EP0DATADONE event generated during the setup stage of a control transfer after the DATA token is ACK&amp;#39;d?[/quote]
&lt;p&gt;&amp;nbsp;Yes. It&amp;#39;s generated after you either send an ACK (control read) or receive an ACK (control write) on EP0. The figures for control read/write in the PS might be easier to read than my explanation:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.nrf52840.ps/usbd.html?cp=2_0_0_5_34_8#concept_usb_ctrl_ep"&gt;http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.nrf52840.ps/usbd.html?cp=2_0_0_5_34_8#concept_usb_ctrl_ep&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;/p&gt;
&lt;p&gt;Håkon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>