<?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>USB device  suspend/resume issue when requesting HFCLK</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/59738/usb-device-suspend-resume-issue-when-requesting-hfclk</link><description>Hello, 
 I&amp;#39;m having problems with resuming usbdevice from susspend state. I&amp;#39;m working on SDK 15.2 with SD140 (6.1.0). on custom board with nRF52840 IC rev. 2. 
 My application runs usbd with HID generic profile and Softdevice. SoftDevice is enabled, than</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 26 May 2020 10:06:46 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/59738/usb-device-suspend-resume-issue-when-requesting-hfclk" /><item><title>RE: USB device  suspend/resume issue when requesting HFCLK</title><link>https://devzone.nordicsemi.com/thread/251672?ContentTypeID=1</link><pubDate>Tue, 26 May 2020 10:06:46 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:016ac520-c35e-494c-89a9-ce505b13d129</guid><dc:creator>KrystianL</dc:creator><description>&lt;p&gt;Hello Hakon,&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thank you for detailed answer.&lt;/p&gt;
&lt;p&gt;Currently I&amp;#39;m using event queue for usb device in my application, but because of that there are many events handled in thread mode and it has influence on RTOS&amp;nbsp;tasks load/context switching.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;So if you develop a fix for this bug please let me know - maybe in this ticket?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: USB device  suspend/resume issue when requesting HFCLK</title><link>https://devzone.nordicsemi.com/thread/251427?ContentTypeID=1</link><pubDate>Mon, 25 May 2020 09:24:50 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:94d4e0a3-8dc2-40f4-86c0-6e5814d4ee0f</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Hi Krystian,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;My apologies, I have been out-of-the-office for some days.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Background of the issue: when RESET event arrives, the HFCLK is requested and HFCLK_READY handler is called right away as the clock is already running.&lt;/span&gt;&lt;br /&gt;&lt;span&gt;When queue is enabled, the HFCLK_READY handler adds an event to the queue and this is handled safely after RESUME event (which changed state from SUSPEND to RESUMING), changing state from RESUMING to ACTIVE.&lt;/span&gt;&lt;br /&gt;&lt;span&gt;On the other hand, if queue is disabled, HFCLK_READY handler is called before RESUME event arrives. This is unhandled state change and later when RESUME event arrives, there is no HFCLK_READY event to change state from RESUMING to ACTIVE.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;R&amp;amp;D has been exploring this issue, and observed that when&amp;nbsp;&lt;span&gt;disabling the event queue in USB stack (setting APP_USBD_CONFIG_EVENT_QUEUE_ENABLE to 0), this causes an ordering issue per how the app_usbd expects things to occur, as shown in the diagram here:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/support-attachments/beef5d1b77644c448dabff31668f3a47-2718db6f7ab6470faa92f847e43bc486/pastedimage1590397989687v2.png" alt=" " /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;This is unfortunately a fundamental issue with how app_usbd handles SUSPEND and WUREQ events, and providing a bug fix will take some time. Is it possible for you to use the event queue (APP_USBD_CONFIG_EVENT_QUEUE_ENABLE&amp;nbsp;set to &amp;#39;1&amp;#39;) for working around this in your application?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Kind regards,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Håkon&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: USB device  suspend/resume issue when requesting HFCLK</title><link>https://devzone.nordicsemi.com/thread/250575?ContentTypeID=1</link><pubDate>Tue, 19 May 2020 06:49:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c3812198-5d5b-41ec-aeab-8be8d944b969</guid><dc:creator>KrystianL</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Should I expect any news in this subject from Nordic team or should I just forget about it?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: USB device  suspend/resume issue when requesting HFCLK</title><link>https://devzone.nordicsemi.com/thread/246097?ContentTypeID=1</link><pubDate>Wed, 22 Apr 2020 15:18:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:071c82ae-cd7e-4715-9f12-a8e49c037aed</guid><dc:creator>KrystianL</dc:creator><description>&lt;p&gt;Hi Hakon,&lt;/p&gt;
&lt;p&gt;Thanks for this feedback -&amp;nbsp;so I&amp;#39;m patiently waiting for new inputs from you guys:)&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;BR,&lt;/p&gt;
&lt;p&gt;Krystian&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: USB device  suspend/resume issue when requesting HFCLK</title><link>https://devzone.nordicsemi.com/thread/246095?ContentTypeID=1</link><pubDate>Wed, 22 Apr 2020 15:07:57 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:611929dc-297f-4b85-8567-18042a0bfb97</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Hi Krystian,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;My apologies for the late response.&amp;nbsp;It is reported it to the SDK team, and they are currently investigating. Unfortunately, at this point; I do not have an more in-depth update.&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: USB device  suspend/resume issue when requesting HFCLK</title><link>https://devzone.nordicsemi.com/thread/245962?ContentTypeID=1</link><pubDate>Wed, 22 Apr 2020 07:53:51 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:56d3edfa-a6a3-4eac-a386-bc54f8fdea01</guid><dc:creator>KrystianL</dc:creator><description>&lt;p&gt;Hello Nordic Team,&lt;/p&gt;
&lt;p&gt;could you please update status of this issue?&lt;/p&gt;
&lt;p&gt;Is anyone investigating case with modified&amp;nbsp;&lt;span&gt;nrf_sdk example&amp;nbsp;&lt;/span&gt;&lt;em&gt;peripheral/usbd_hid_generic&lt;/em&gt;, which I&amp;#39;ve descibed in my post above and Hakon have reproduced at his desk(see his answer above)?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;BR,&lt;/p&gt;
&lt;p&gt;Krystian&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: USB device  suspend/resume issue when requesting HFCLK</title><link>https://devzone.nordicsemi.com/thread/245603?ContentTypeID=1</link><pubDate>Mon, 20 Apr 2020 14:25:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:107010dc-eb66-4b18-a513-582c3902c0d4</guid><dc:creator>KrystianL</dc:creator><description>&lt;p&gt;Hello Hakon,&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I&amp;#39;m back from holidays - any news regarding this issue?&lt;/p&gt;
&lt;p&gt;BR,&lt;/p&gt;
&lt;p&gt;Krystian&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: USB device  suspend/resume issue when requesting HFCLK</title><link>https://devzone.nordicsemi.com/thread/243439?ContentTypeID=1</link><pubDate>Fri, 03 Apr 2020 15:26:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c6af820a-aef7-4134-8a20-5e3e9560cdf9</guid><dc:creator>KrystianL</dc:creator><description>&lt;p&gt;Hi Hakon,&lt;/p&gt;
&lt;p&gt;Thank you for investigating this issue and forwarding it to other developers.&lt;/p&gt;
&lt;p&gt;I&amp;#39;ll wait for response from them, but because at Monday (06.04) I start 2 weeks vacation period it could happen that I&amp;#39;ll be not responsive within this time. In such a case I&amp;#39;ll respond to any eventual questions after I get be back to work (@ 20.04).&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Best Regards,&lt;/p&gt;
&lt;p&gt;Krystian&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: USB device  suspend/resume issue when requesting HFCLK</title><link>https://devzone.nordicsemi.com/thread/243430?ContentTypeID=1</link><pubDate>Fri, 03 Apr 2020 14:26:46 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7bdd4620-852f-4af8-ad0b-635a8482ec38</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Hi Krystian,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I have tested this in SDK v16, and found that the issue is also present there.&lt;/p&gt;
&lt;p&gt;I can confirm that I see this issue, but at my end it takes approx. 7 to 8 seconds, then the mouse movement starts working as it should, until it is suspended again.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Ordering, meaning requesting the hfclk after usbd init, does not seem to have any effect. As long as there&amp;#39;s more than one requesting it, it seems to give a delay before properly waking up.&lt;/p&gt;
&lt;p&gt;Changing irq priorities doesn&amp;#39;t give any change in this behavior.&lt;/p&gt;
&lt;p&gt;I haven&amp;#39;t been able to find a solution to this problem, and I&amp;#39;ll report this internally to the developers.&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: USB device  suspend/resume issue when requesting HFCLK</title><link>https://devzone.nordicsemi.com/thread/242961?ContentTypeID=1</link><pubDate>Wed, 01 Apr 2020 12:47:57 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4e53c7c2-41a9-4cdb-bf36-6173e376ce40</guid><dc:creator>KrystianL</dc:creator><description>&lt;p&gt;In meantime I&amp;#39;ve modified usbd configuration for nrf_sdk example&amp;nbsp;&lt;em&gt;peripheral/usbd_hid_generic.&lt;br /&gt;I&amp;#39;ve disabled usbd events queue and changed SOF handling mode to interrupt - below relevant sdk_config defines:&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;&lt;pre class="ui-code" data-mode="text"&gt;#define APP_USBD_CONFIG_EVENT_QUEUE_ENABLE 0

#define APP_USBD_CONFIG_SOF_HANDLING_MODE 2&lt;/pre&gt;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;I&amp;#39;ve builded and flashed such application on PCA10056 and&amp;nbsp;everything works fine - I can move &amp;quot;mouse pointer&amp;quot; with PCA buttons.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;If device goes to suspend and I press any of 4 PCA buttons, hid device is resumed succesfully and I can see on host that communication works (mouse pointer is moving, etc.).&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;But if I request HFCLK clock in main application and flash PCA again than after device will go suspend it can not resume successfully&amp;nbsp;when PCA buttons are pressed.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;In details I can see PCA debugtraces on UART&amp;nbsp; &lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;(&lt;/em&gt;&lt;em&gt;APP_USBD_EVT_DRV_RESUME/APP_USBD_EVT_DRV_SUSPEND -I&amp;#39;ve added NRF_LOG_INFO to usbd_user_ev_handler for such events), &lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;but communication with host in broken - no mouse pointer is moving etc.&amp;nbsp;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;So this behavior&amp;nbsp;is similar to one I&amp;#39;ve described in post above (for my custom board).&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Below relevant changes in main.c:&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;//...

static void usbd_user_ev_handler(app_usbd_event_type_t event)
{
    switch (event)
    {
//...
        case APP_USBD_EVT_DRV_SUSPEND:
            NRF_LOG_INFO(&amp;quot;APP_USBD_EVT_DRV_SUSPEND&amp;quot;);   //ADDED DEBUG TRACE
            m_report_pending = false;
            app_usbd_suspend_req(); // Allow the library to put the peripheral into sleep mode
            bsp_board_leds_off();
            break;
        case APP_USBD_EVT_DRV_RESUME:
            NRF_LOG_INFO(&amp;quot;APP_USBD_EVT_DRV_RESUME&amp;quot;);    //ADDED DEBUG TRACE
            m_report_pending = false;
            bsp_board_led_on(LED_USB_START);
            break;
//...

int main(void)
{
    ret_code_t ret;
    static const app_usbd_config_t usbd_config = {
        .ev_state_proc = usbd_user_ev_handler
    };

    ret = NRF_LOG_INIT(NULL);
    APP_ERROR_CHECK(ret);

    ret = nrf_drv_clock_init();
    APP_ERROR_CHECK(ret);

    nrf_drv_clock_lfclk_request(NULL);
    nrf_drv_clock_hfclk_request(NULL);   //ADDITIONAL HFCLK REQUEST added by me

    while(!(nrf_drv_clock_lfclk_is_running() &amp;amp;&amp;amp; nrf_drv_clock_hfclk_is_running()))
    {
        /* Just waiting */
    }

    ret = app_timer_init();
    APP_ERROR_CHECK(ret);

    //...
    
    while (true)
    {
//POLLING of usb events removed because they are processed now in Interrupt mode    
//        while (app_usbd_event_queue_process())
//        {
//            /* Nothing to do */
//        }
        hid_generic_mouse_process_state();
        nrf_cli_process(&amp;amp;m_cli_uart);

        UNUSED_RETURN_VALUE(NRF_LOG_PROCESS());
        /* Sleep CPU only if there was no interrupt since last loop processing */
        __WFE();
    }
//...    &lt;/pre&gt;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;If host is not sending SUSPEND requests to hid device after a few seconds than probably registers settings for Enhanced Power Management must be changed in windows register like below:&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/pastedimage1585744828490v2.png" alt=" " /&gt;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/pastedimage1585744804943v1.png" alt=" " /&gt;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/pastedimage1585744920952v3.png" alt=" " /&gt;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;This modified example shows that hid device is not correctly resuming from suspend state if SOF handling mode is set to interrupt.&lt;br /&gt;Please advice.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;BR,&lt;/p&gt;
&lt;p&gt;Krystian&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>