<?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>NRF_USB-&amp;gt;EVENTS_EPDATA fails to trigger</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/75111/nrf_usb--events_epdata-fails-to-trigger</link><description>Hiya! 
 
 I am writing code to add support for USB on the NRF58233/58240 to MakeCode. MakeCode relies upon WebUSB. At any point, a user can close the website which causes the web usb stack to stop reading from the device. When this happens, the synchronous</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 28 May 2021 12:10:18 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/75111/nrf_usb--events_epdata-fails-to-trigger" /><item><title>RE: NRF_USB-&gt;EVENTS_EPDATA fails to trigger</title><link>https://devzone.nordicsemi.com/thread/312360?ContentTypeID=1</link><pubDate>Fri, 28 May 2021 12:10:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:aaf4108d-9d39-4e06-abd8-2edd793bd44e</guid><dc:creator>Marjeris Romero</dc:creator><description>&lt;div&gt;
&lt;p&gt;Hi again,&lt;/p&gt;
&lt;div&gt;
&lt;p&gt;USBD automatically detects lack of activity on the USB bus for more than a defined amount of time. When no activity has been detected for longer than &lt;a title="http://projecttools.nordicsemi.no/nightly/topic/usbd/usbd.html?cp=3_72_0_12#unique_744012919" href="http://projecttools.nordicsemi.no/nightly/topic/usbd/usbd.html?cp=3_72_0_12#unique_744012919" rel="noopener noreferrer" target="_blank"&gt;tUSB,SUSPEND&lt;/a&gt;, USBD generates the USBEVENT event with SUSPEND bit set in register &lt;a title="http://projecttools.nordicsemi.no/nightly/topic/usbd/usbd.html?cp=3_72_0_12#register.eventcause" href="http://projecttools.nordicsemi.no/nightly/topic/usbd/usbd.html?cp=3_72_0_12#register.EVENTCAUSE" rel="noopener noreferrer" target="_blank"&gt;EVENTCAUSE&lt;/a&gt;.&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;So in your case it makes more sense to check if this SUSPEND bit is set or not in the device as no data is being transferred when the web browser is closed.&lt;/p&gt;
&lt;p&gt;Our developers also pointed out that developing a own USB stack is very time-consuming, and some parts of the USB protocol are best to do in a non-synchronous fashion, so they strongly recommend using the Zephy USB device stack as a based for interfacing with webUSB: &lt;a title="https://docs.zephyrproject.org/latest/reference/usb/index.html" href="https://docs.zephyrproject.org/latest/reference/usb/index.html" rel="noopener noreferrer" target="_blank"&gt;https://docs.zephyrproject.org/latest/reference/usb/index.html&lt;/a&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Marjeris&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF_USB-&gt;EVENTS_EPDATA fails to trigger</title><link>https://devzone.nordicsemi.com/thread/312171?ContentTypeID=1</link><pubDate>Thu, 27 May 2021 15:05:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9d33faf3-369f-404e-803c-007b188a4bb3</guid><dc:creator>Marjeris Romero</dc:creator><description>&lt;p&gt;Hi James,&lt;/p&gt;
&lt;p&gt;I forwarded your questions to our software team last week and I am still working on finding the answers to your latest questions as this is a bit out of my scope. I am sorry for the delays on this.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Marjeris&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF_USB-&gt;EVENTS_EPDATA fails to trigger</title><link>https://devzone.nordicsemi.com/thread/310873?ContentTypeID=1</link><pubDate>Thu, 20 May 2021 22:41:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0dbed7b7-7646-4e26-a35d-18c86bda55e4</guid><dc:creator>James Devine</dc:creator><description>&lt;p&gt;Hiya,&lt;/p&gt;
&lt;p&gt;Thanks for the detailed reply.&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&lt;span&gt;About the EVENTS_EPDATA not triggering, could it be that you haven&amp;#39;t flagged the right data endpoint in EPDATASTATUS?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;I mostly ignore&amp;nbsp;&lt;span&gt;EPDATASTATUS as the USB code is synchronous. From what I understand, the hardware uses this register to flag whether a transaction has completed and it is not up to me to set the flag... If the flag is being set by the hardware, surely the EPDATA event should trigger?&lt;/span&gt;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&lt;span&gt;Another question when using webUSB, do you know if the host will suspend the device just because it&amp;#39;s not used by the application anymore? If the USB device is suspended by the host you could use&amp;nbsp;&lt;a href="https://infocenter.nordicsemi.com/pdf/nRF52840_PS_v1.2.pdf#%5B%7B%22num%22%3A6741%2C%22gen%22%3A0%7D%2C%7B%22name%22%3A%22XYZ%22%7D%2C85.039%2C774.423%2Cnull%5D"&gt;USBEVENT event with SUSPEND bit in the EVENTCAUSE register&lt;/a&gt;.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;As you can see from the USB trace, it doesn&amp;#39;t look like the host issues a suspend command.&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&lt;span&gt;One of our developers recommended using EVENTS_ENDEPIN to check if the buffer was transferred instead of using EPDATA, together with a timeout as you have done. EVENTS_ENDEPIN[n] is described in 6.35.13.12.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;This could work, but presumably this wouldn&amp;#39;t work for EP0 which has a status stage? Is there a chronological dependency on EPDATA for the status stage for EP0? What happens if I trigger EP0STATUS before EPDATA has been triggered?&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Should I add a special case for EP0?&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF_USB-&gt;EVENTS_EPDATA fails to trigger</title><link>https://devzone.nordicsemi.com/thread/310843?ContentTypeID=1</link><pubDate>Thu, 20 May 2021 16:45:34 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e56aca4c-f873-434f-b6dd-1a6197131031</guid><dc:creator>Marjeris Romero</dc:creator><description>&lt;p&gt;Hello James,&lt;/p&gt;
&lt;p&gt;Please bear with me, as I am just starting to look into the USB peripheral. About the EVENTS_EPDATA not triggering, could it be that you haven&amp;#39;t flagged the right data endpoint in EPDATASTATUS?&lt;/p&gt;
&lt;p&gt;From the nRF52840 PS section 6.35.8: &lt;br /&gt;&amp;quot;&lt;span style="font-family:monospace;font-size:15.4px;left:124.724px;top:644.205px;" dir="ltr"&gt;The &lt;span&gt;EPDATA&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:monospace;font-size:15.4px;left:199.056px;top:644.205px;" dir="ltr"&gt; event indicates that a successful (acknowledged) data transaction has occurred on the data&lt;/span&gt;&lt;span style="font-family:monospace;font-size:15.4px;left:124.724px;top:663.272px;" dir="ltr"&gt;endpoint(s) flagged in register &lt;/span&gt;&lt;span style="font-family:monospace;font-size:15.4px;left:315.501px;top:663.272px;" dir="ltr"&gt;EPDATASTATUS&lt;/span&gt;&lt;span style="font-family:monospace;font-size:15.4px;left:408.527px;top:663.272px;" dir="ltr"&gt;. A successful (acknowledged) data transaction on endpoint&lt;/span&gt;&lt;span style="font-family:monospace;font-size:15.4px;left:124.724px;top:682.339px;" dir="ltr"&gt;0 is signalled by the &lt;/span&gt;&lt;span style="font-family:monospace;font-size:15.4px;left:250.363px;top:682.339px;" dir="ltr"&gt;EP0DATADONE&lt;/span&gt;&lt;span style="font-family:monospace;font-size:15.4px;left:342.883px;top:682.339px;" dir="ltr"&gt; event&lt;/span&gt;&amp;quot;&lt;/p&gt;
&lt;p&gt;Another question when using webUSB, do you know if the host will suspend the device just because it&amp;#39;s not used by the application anymore? If the USB device is suspended by the host you could use &lt;a href="https://infocenter.nordicsemi.com/pdf/nRF52840_PS_v1.2.pdf#%5B%7B%22num%22%3A6741%2C%22gen%22%3A0%7D%2C%7B%22name%22%3A%22XYZ%22%7D%2C85.039%2C774.423%2Cnull%5D"&gt;USBEVENT event with SUSPEND bit in the EVENTCAUSE register&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;In Zephyr and nRF connect SDK, USB classes purge buffer/cancel transfer on suspend event, but since webUSB is not really an USB class, and I do not know what the host will perform, so not suspend would help but it&amp;#39;s worth taking into account what the actual USB host respond will be when the browser is closed.&lt;/p&gt;
&lt;p&gt;One of our developers recommended using EVENTS_ENDEPIN to check if the buffer was transferred instead of using EPDATA, together with a timeout as you have done. EVENTS_ENDEPIN[n] is described in 6.35.13.12. and it indicates that &amp;quot;The whole EPIN[n] buffer has been consumed&amp;quot; which means the buffer has been transferred to the host. Can you try using this event instead of EPDATA in your loop together with the timeout?&lt;br /&gt;&lt;br /&gt;BTW in Zephyr there is a simple webUSB sample, I don&amp;#39;t know if it would be helpful for your project: &lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/zephyr/samples/subsys/usb/webusb/README.html"&gt;https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/zephyr/samples/subsys/usb/webusb/README.html&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Marjeris&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF_USB-&gt;EVENTS_EPDATA fails to trigger</title><link>https://devzone.nordicsemi.com/thread/309809?ContentTypeID=1</link><pubDate>Fri, 14 May 2021 13:51:42 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:390f8c9f-c278-4b03-8aca-1e74d7e1096f</guid><dc:creator>Albrecht Markus Schellenberger</dc:creator><description>&lt;p&gt;Hello James,&lt;/p&gt;
&lt;p&gt;Due to public holidays in Norway, our experts are out of office until Tuesday. We will come back to you as soon as possible.&lt;/p&gt;
&lt;p&gt;I apologise for any inconvenience caused.&lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt;Markus&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>