<?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>NRF5340 USB SIZE.EPOUT[n] value not stable</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/88301/nrf5340-usb-size-epout-n-value-not-stable</link><description>Hi All, 
 
 I observed strange anomaly on NRF5340 (PCA10095 0.11.0 2020.52.xxxxxxxxx). 
 Same behavior seen on NRF52840 (PCA10056). 
 Value of register SIZE.EPOUT[n] does not reflect data that was received in endpoint. 
 Several consecutive reads from</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 02 Jun 2022 13:59:24 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/88301/nrf5340-usb-size-epout-n-value-not-stable" /><item><title>RE: NRF5340 USB SIZE.EPOUT[n] value not stable</title><link>https://devzone.nordicsemi.com/thread/370731?ContentTypeID=1</link><pubDate>Thu, 02 Jun 2022 13:59:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b320b01a-cbe2-446b-87b8-5dee9baa0f1b</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Hi Jerzy,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I agree that it is not stated explicitly, but it is mentioned that triggering tasks within the usbd peripheral will limit access to&amp;nbsp;this set of registers:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://infocenter.nordicsemi.com/topic/ps_nrf5340/chapters/usbd/doc/usbd.html?cp=3_0_0_6_38_11#unique_1203114361"&gt;https://infocenter.nordicsemi.com/topic/ps_nrf5340/chapters/usbd/doc/usbd.html?cp=3_0_0_6_38_11#unique_1203114361&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Other registers than the one&amp;#39;s listed shall be safe to read.&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: NRF5340 USB SIZE.EPOUT[n] value not stable</title><link>https://devzone.nordicsemi.com/thread/370496?ContentTypeID=1</link><pubDate>Wed, 01 Jun 2022 14:56:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:691ea7e5-e85f-4e9f-a21b-f5136b68a412</guid><dc:creator>kasjer</dc:creator><description>&lt;p&gt;Thanks &lt;span&gt;H&amp;aring;kon&lt;/span&gt;,&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;NRFX version indeed prepares whole DMA transaction (including read from SIZE.EPOUT) after previous DMA&amp;nbsp;has finished.&lt;/p&gt;
&lt;p&gt;Code could be written that way even if only restriction was: &amp;#39;single EasyDMA transfer at a time&amp;#39;.&lt;/p&gt;
&lt;p&gt;Currently I&amp;#39;m just seeking confirmation about which registers can&amp;#39;t be accessed while DMA is in progress.&lt;/p&gt;
&lt;p&gt;Surely some registers are not affected by running DMA but which ones can be read without problem?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;best regards&lt;/p&gt;
&lt;p&gt;Jerzy&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF5340 USB SIZE.EPOUT[n] value not stable</title><link>https://devzone.nordicsemi.com/thread/370482?ContentTypeID=1</link><pubDate>Wed, 01 Jun 2022 13:57:52 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:28773b84-fd4a-41e8-9946-43380d8fcb55</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Hi Jerzy,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;If you look at the nrfx_usbd driver, it has similar comments as you describe, due to the restriction in the datasheet.&lt;/p&gt;
&lt;p&gt;If you look at the handling of this specific variable (and following functions), you&amp;#39;ll see that its only read after a transaction is completed:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://github.com/zephyrproject-rtos/hal_nordic/blob/master/nrfx/drivers/src/nrfx_usbd.c#L718"&gt;https://github.com/zephyrproject-rtos/hal_nordic/blob/master/nrfx/drivers/src/nrfx_usbd.c#L718&lt;/a&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: NRF5340 USB SIZE.EPOUT[n] value not stable</title><link>https://devzone.nordicsemi.com/thread/370104?ContentTypeID=1</link><pubDate>Tue, 31 May 2022 07:06:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:594fa783-9cb8-4ff9-a8d7-77bff686b345</guid><dc:creator>kasjer</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Code that fails is opensource TinyUSB.&lt;/p&gt;
&lt;p&gt;Line that read invalid value is here&lt;/p&gt;
&lt;p&gt;&lt;a href="https://github.com/hathach/tinyusb/blob/f4efb51fe2b7f4fee38c28ff80d03904d0b5b73e/src/portable/nordic/nrf5x/dcd_nrf5x.c#L220"&gt;https://github.com/hathach/tinyusb/blob/f4efb51fe2b7f4fee38c28ff80d03904d0b5b73e/src/portable/nordic/nrf5x/dcd_nrf5x.c#L220&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;xact_len = tu_min16((uint16_t) NRF_USBD-&amp;gt;SIZE.EPOUT[epnum], xfer-&amp;gt;total_len - xfer-&amp;gt;actual_len);
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;While this code have tu_min16 macro that potentially could read register value twice. I tried extracting register read to separate line from tu_min16 and result was the same.&lt;/p&gt;
&lt;p&gt;As visible in code SIZE.EPOUT is first read in function from USBD registers. In case when this read fails, previous access to any register was stating DMA on some other OUT endpoint.&lt;/p&gt;
&lt;p&gt;During investigation process I tried dumping all SIZE.EPOUT registers before DMA is started and just after is starts.&lt;/p&gt;
&lt;p&gt;When reading all register in a loop and storing them in RAM reveled&amp;nbsp;that registers had expected values before DMA was started. Specifically endpoint that had new data had correct value.&lt;/p&gt;
&lt;p&gt;Then DMA for other endpoint was stated.&lt;/p&gt;
&lt;p&gt;Then 8 times I read all SIZE.EPOUT registers again.&lt;/p&gt;
&lt;p&gt;This time read content of the registers were incorrect for one or more loop, then it was correct again.&lt;/p&gt;
&lt;p&gt;I did not verify that this loop start yielding correct values after DMA finished but that is my assumption.&lt;/p&gt;
&lt;p&gt;TinyUSB project is open source testing code is also opensource so I could help&amp;nbsp;with setup if needed.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;br&lt;/p&gt;
&lt;p&gt;Jerzy&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF5340 USB SIZE.EPOUT[n] value not stable</title><link>https://devzone.nordicsemi.com/thread/370033?ContentTypeID=1</link><pubDate>Mon, 30 May 2022 14:49:26 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6bbf6be5-83bf-4f04-8c7d-a62c58471114</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;Could you share the output that you&amp;#39;re getting, and your routine for reading the register?&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: NRF5340 USB SIZE.EPOUT[n] value not stable</title><link>https://devzone.nordicsemi.com/thread/369933?ContentTypeID=1</link><pubDate>Mon, 30 May 2022 09:35:17 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b0147c04-1fdd-45ca-880b-40c37c4da27e</guid><dc:creator>kasjer</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;&lt;span&gt;H&amp;aring;kon, thanks for reply&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Register SIZE.EPOUT is mentioned in&amp;nbsp;&lt;/span&gt;&lt;strong&gt;USB register access limitations&lt;/strong&gt; section, but what I observe is that read of this register is in the middle of heavy USB traffic. USB is not disabled, nor suspended, it is transmitting in both direction prior to failure.&lt;/p&gt;
&lt;p&gt;I added dummy read of from EVENTS_STARTED register before read from SIZE.EPOUT and read is still incorrect.&lt;/p&gt;
&lt;p&gt;Code that accessed SIZE.EPOUT register did not&amp;nbsp;try to read any other USBD registers just before read that failed.&lt;/p&gt;
&lt;p&gt;Document you mentioned state that only&amp;nbsp;single EasyDMA can be started at a time at that is enforced in my case but&lt;/p&gt;
&lt;p&gt;I could not find any confirmation that while DMA is running certain registers can&amp;#39;t be read.&lt;/p&gt;
&lt;p&gt;Maybe it should be added to USB register access limitation section if it is really the case.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Jerzy&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF5340 USB SIZE.EPOUT[n] value not stable</title><link>https://devzone.nordicsemi.com/thread/369900?ContentTypeID=1</link><pubDate>Mon, 30 May 2022 08:20:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:702a8b25-6fc1-4daf-a78d-5eccd79c8b26</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;In certain states, a group of registers shall not be accessed, as described here:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://infocenter.nordicsemi.com/topic/ps_nrf5340/chapters/usbd/doc/usbd.html?cp=3_0_0_6_38_11"&gt;https://infocenter.nordicsemi.com/topic/ps_nrf5340/chapters/usbd/doc/usbd.html?cp=3_0_0_6_38_11&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I do not know how your read-routine looks,&amp;nbsp;but please keep this in mind:&lt;/p&gt;
&lt;p&gt;When reading registers directly from the CPU, it is important that you add a wait-state between each read. This is because the peripheral bus runs on a lower clock speed compared to the CPU.&lt;/p&gt;
&lt;p&gt;Pseudo code:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;uint32_t reg = NRF_USBD-&amp;gt;SOME_REG;
// Dummy read of any EVENTS_ register to generate wait-state
(void)NRF_USBD-&amp;gt;EVENTS_STARTED;&lt;/pre&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;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>