<p>Hoernchen has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.osmocom.org/c/osmo-ccid-firmware/+/20058">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">usb: reset the device on usb reset if it was previously running<br><br>Usb init order is desc read -> reset-> set addr -> use device.<br><br>DADD.ADDEN is automatically cleared upon receiving a reset from the<br>host, at least according to the SAMD51 manual, but DADD.DADD is zero as<br>well (?) so it can't be used to check if usb was previously running and<br>the cable was pulled out and plugged in again while the device was<br>externally powered.<br>This works around this and ensures a device reset from the host leads to<br>a proper device restart and reinitialization in this case, there is no<br>state we want to keep in this case anyway.<br><br>Change-Id: I692de3dd98cfc30a010b457be87331e482632fb7<br>Closes: SYS#4908<br>---<br>M sysmoOCTSIM/hpl/usb/hpl_usb.c<br>1 file changed, 17 insertions(+), 0 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.osmocom.org:29418/osmo-ccid-firmware refs/changes/58/20058/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/sysmoOCTSIM/hpl/usb/hpl_usb.c b/sysmoOCTSIM/hpl/usb/hpl_usb.c</span><br><span>index eec9728..99e4606 100644</span><br><span>--- a/sysmoOCTSIM/hpl/usb/hpl_usb.c</span><br><span>+++ b/sysmoOCTSIM/hpl/usb/hpl_usb.c</span><br><span>@@ -39,6 +39,11 @@</span><br><span> #include <hpl_usb_config.h></span><br><span> #include <string.h></span><br><span> #include <utils_assert.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include <hal_delay.h></span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/* save previous setup state to allow device reset when receving usb reset after the device</span><br><span style="color: hsl(120, 100%, 40%);">+ * was previously properly configured, i.e. when powered externally and usb is disconnected and reconnected */</span><br><span style="color: hsl(120, 100%, 40%);">+volatile bool address_was_set = false;</span><br><span> </span><br><span> /**</span><br><span>  * \brief Dummy callback function</span><br><span>@@ -974,6 +979,17 @@</span><br><span>     hri_usbdevice_set_INTEN_reg(USB, USB_D_SUSPEND_INT_FLAGS);</span><br><span> </span><br><span>       _usb_d_dev_reset_epts();</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+    if(address_was_set == true) {</span><br><span style="color: hsl(120, 100%, 40%);">+         _usb_d_dev_detach();</span><br><span style="color: hsl(120, 100%, 40%);">+          address_was_set = 0;</span><br><span style="color: hsl(120, 100%, 40%);">+          delay_ms(100);</span><br><span style="color: hsl(120, 100%, 40%);">+                __disable_irq();</span><br><span style="color: hsl(120, 100%, 40%);">+              __DMB();</span><br><span style="color: hsl(120, 100%, 40%);">+              __DSB();</span><br><span style="color: hsl(120, 100%, 40%);">+              NVIC_SystemReset();</span><br><span style="color: hsl(120, 100%, 40%);">+   }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span>  dev_inst.callbacks.event(USB_EV_RESET, 0);</span><br><span> }</span><br><span> </span><br><span>@@ -1579,6 +1595,7 @@</span><br><span> void _usb_d_dev_set_address(uint8_t addr)</span><br><span> {</span><br><span>        hri_usbdevice_write_DADD_reg(USB, USB_DEVICE_DADD_ADDEN | USB_DEVICE_DADD_DADD(addr));</span><br><span style="color: hsl(120, 100%, 40%);">+        address_was_set = true;</span><br><span> }</span><br><span> </span><br><span> uint8_t _usb_d_dev_get_address(void)</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.osmocom.org/c/osmo-ccid-firmware/+/20058">change 20058</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.osmocom.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.osmocom.org/c/osmo-ccid-firmware/+/20058"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: osmo-ccid-firmware </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-Change-Id: I692de3dd98cfc30a010b457be87331e482632fb7 </div>
<div style="display:none"> Gerrit-Change-Number: 20058 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Hoernchen <ewild@sysmocom.de> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>