How to add Suspend and Resume support in USB device stack[KSDK 1.3]

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

How to add Suspend and Resume support in USB device stack[KSDK 1.3]

How to add Suspend and Resume support in USB device stack[KSDK 1.3]

The USB stack in ksdk 1.3 has provided a macro of “USBCFG_DEV_ADVANCED_SUSPEND_RESUME” , while the RM says “suspend/resume is not implemented yet.”, but if you looks into the source code, you may find APIs like USB_Suspend_Service() which is reserved for further implementation, so users may use these APIs as a starting point to add suspend and resume feature in ksdk 1.3.

The test is based on FRDM-KL27Z, dev_hid_mouse_bm demo. And before we modify the device stack, we have to clone a copy of this demo.

pastedImage_1.png

  1. Set USBCFG_DEV_ADVANCED_SUSPEND_RESUME to 1 to releases APIs related with suspend and resume features.

pastedImage_2.png

But we will have the following errors after compile, that is because remote resume function is not supported by KL27.

pastedImage_3.png

so we should disable it for this device, with the help of #if USBCFG_DEV_ADVANCED_SUSPEND_RESUME == 1 && FSL_FEATURE_USB_KHCI_HOST_ENABLED == 1. For example, like below:

pastedImage_4.png

2.Further implement USB_Suspend_Service() and USB_Resume_Service() to let them notify the upper layer application on the event of suspend/resume. With reference of USB_Error_Service()

pastedImage_6.png

pastedImage_7.png

and Don’t forget to add two more events for suspend and resume.

pastedImage_8.png

3.USB module has two types of resume interrupt , one is sync resume , issued by the bit of ISTAT[RESUME] bit, the other is async resume, issued by the bit of TRC0[USB_RESUME_INT], so we have to monitor these two interrupt status flag in the ISR, as below:

pastedImage_10.png

And so we have modify the resume and sleep interrupt services for supporting the async resume interrupt as below:

pastedImage_11.png

4.Modify application and add code to handle suspend and resume event, in this case, such kind of events are handled in USB_App_Device_Callback()

pastedImage_13.png

5.Verify the hid_mouse demo with USB 2 CV tool from usb.org

pastedImage_15.png

Select the FS device with VID 15a2 from the list.

pastedImage_16.png

Test passed!

pastedImage_17.png

if you print some messages on the event of suspend and resume, you will see something like below from the Terminal channel.

pastedImage_18.png

6. Now we can add low power mode switch function in the main application code to meet the suspend current limitation specified by USB spec, with reference of power_manager_hal_demo for frdmkl27z, and for this case, add code in USB_App_Device_Callback() of mouse.c to tell the main application when to enter low power mode.

Please also note Don’t enter low power mode in this callback function, as it is called by the interrupt service, so if the device enter low power mode during interrupt, that would prevent the following resume interrupt happen, so the device never wake up!

For more details on the implementation, please refer to the attached mouse.c

7.Test low power mode current:

  Before test, please do the following modification to the FRDM-KL27Z board:

pastedImage_24.png

Please note, if your board has the following jumpers, no need to remove R7,R21 and R83, just keep J19 and J22 open during the test.

pastedImage_26.png

Select the low power mode you are going to test from the Ternimal:

pastedImage_27.png

Leave KL27 USB port (J10) open and power the board with USB SDA port, that would make the device enter suspend interrupt out of reset. And you may also see the current vary with power mode switch with the help of USB 2 CV tool. I have tested wait, stop and vlps modes, the current measured under these modes are shown as below:

Wait:

pastedImage_28.png

Stop:

pastedImage_29.png

VLPS:

pastedImage_30.png

So it is recommend using VLPS mode during USB suspend mode as it far below the suspend current specified in USB spec (500uA).

8. Patch and demo code

Please replace the following files with the attached one, as well as the mouse.c in dev_hid_mouse_bm demo. Recompile the stack and application code.

C:\Freescale\KSDK_1.3.0\usb\usb_core\device\include\MKL27Z644

usb_device_config.h

C:\Freescale\KSDK_1.3.0\usb\usb_core\device\sources\controller

usb_dev.h

usb_dev.c

usb_framework.c

C:\Freescale\KSDK_1.3.0\usb\usb_core\device\sources\controller\khci

device_khci_interface.c

khci_dev.c

khci_dev.h

C:\Freescale\KSDK_1.3.0\usb\usb_core\device\include

usb_device_stack_interface.h

C:\Freescale\KSDK_1.3.0\examples\frdmkl27z\demo_apps\usb\device\hid\hid_mouse

mouse.c

标签 (1)
附件
无评分
版本历史
最后更新:
‎03-28-2016 10:17 PM
更新人: