This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

USB device suspend/resume issue when requesting HFCLK

Hello,

I'm having problems with resuming usbdevice from susspend state.
I'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 usb is initialized and device is connected to PC usb port.

When host(PC) is requesting suspend to usbdevice, it enters to suspend state, but can not resume when host requests it.
I can see on debug traces that device is reporitng USB_RESUME events, but communication with hosts ends with error (host usb driver can not connect to the device).

After some investigations I've found that requesting of High Frequency Clock is somehow indirectly causing suspend/resume issue.
In my application I'm requesting HFCLK and later on usb device is initialized and opened.
If I remove HFCLK request than device is succesfully resuming from suspend state and there is no connection error on usb bus.

Below sequence of initialization code for my application:

	//... 
    clock_init();
    err_code = nrf_sdh_enable_request();
	ASSERT(err_code == NRF_SUCCESS);
	while (!nrf_sdh_is_enabled())
	{
		;
	}
	
	//... 
	
    nrf_drv_clock_hfclk_request(NULL);
	while (!nrf_drv_clock_hfclk_is_running()) 
	{
		;
	}
	
	//...
	
	ret_code_t err_code;

    err_code = app_usbd_init(&usbd_config);
    SYS_ASSERT(err_code == NRF_SUCCESS);

    app_usbd_class_inst_t const * class_inst_generic;
    class_inst_generic = app_usbd_hid_generic_class_inst_get(&m_app_hid_generic);

    err_code = app_usbd_class_append(class_inst_generic);
    SYS_ASSERT(err_code == NRF_SUCCESS);

    err_code = app_usbd_power_events_enable();
    SYS_ASSERT(err_code == NRF_SUCCESS);
	
	//...

And some of usbd configurations from sdk_config:

#define USBD_ENABLED 1
#define USBD_CONFIG_IRQ_PRIORITY 6
#define USBD_CONFIG_DMASCHEDULER_MODE 0
#define USBD_CONFIG_DMASCHEDULER_ISO_BOOST 1
#define USBD_CONFIG_ISO_IN_ZLP 0

#define APP_USBD_ENABLED 1
#define APP_USBD_CONFIG_SELF_POWERED 0
#define APP_USBD_CONFIG_MAX_POWER 500
#define APP_USBD_CONFIG_POWER_EVENTS_PROCESS 1
#define APP_USBD_CONFIG_EVENT_QUEUE_ENABLE 0
#define APP_USBD_CONFIG_SOF_HANDLING_MODE 2

#define APP_USBD_HID_ENABLED 1
#define APP_USBD_HID_DEFAULT_IDLE_RATE 0
#define APP_USBD_HID_REPORT_IDLE_TABLE_SIZE 4
#define APP_USBD_HID_GENERIC_ENABLED 1
#define APP_USBD_HID_KBD_ENABLED 0
#define APP_USBD_HID_MOUSE_ENABLED 0

My question is - why requesting HFCLK by application(outside of app_usbd) is causing issues with resuming from suspend state (it seems that internal app_usbd fsm for suspend mode is not working properly)?
Are there any restrictions for using nrf_drv_clock_hfclk_request() when usbdevice is running?
Please advice,

Best Regards,
Krystian

Related