Jump to main content

##

# 1.8 HID Basic Remote Wakeup Example (hid_basic_remote_wakeup)

This application demonstrates the ability of the MPLAB® Harmony USB Device Stack to support the Remote Wakeup feature using a custom HID device class example.

## Description

This application creates a USB HID Device that enumerates as a custom USB HID device on the USB host PC. The device allows the USB Host utility to control the LEDs on the board and query the status of a switch. This example demonstrates suspend/resume initiated by PC host and Remote Wakeup initiated by HID Device using a PC-based utility. The application will put the device to Standby sleep mode when it receives a suspend from PC host. The Push-button is used as wakeup source when the device goes to Standby sleep mode

## Downloading and building the application

To clone or download this application from Github, go to the main page of this repository and then click Clone button to clone this repository or download as zip file. This content can also be downloaded using the MPLAB® Harmony Content Manager by following these instructions.

Path of the application within the repository is usb_apps_device/apps/hid_basic_remote_wakeup.

Following table gives the details of project configurations, target device used, hardware and its IDE. Open the project using the respective IDE and build it.

Project Name | IDE | Target Device | Hardware / Configuration
--- | --- | --- | ---
sam_e54_xpro.X | MPLABX | ATSAME54P20A | SAM E54 Xplained Pro Board
sam_l21_xpro.X | MPLABX | ATSAML21J18B | SAML21 Xplained Pro Board
pic32cz_ca80_curiosity_ultra.X | MPLABX | PIC32CZ8110CA80208 | PIC32CZ CA80 Curiosity Ultra development board
pic32cm_gc_curiosity_pro.X | MPLABX | PIC32CM5112GC00100 | PIC32CM GC Curiosity Pro
pic32ck_gc01_curiosity_ultra.X | MPLABX | PIC32CK2051GC01144 | PIC32CK GC Curiosity Ultra Development Board

## Configuring the Hardware

PIC32CZ CA80 Curiosity Ultra development board

- Connect the USB device to the micro-B connector (J102) using a USB Type-A Female to micro-B male cable (This cable is not included in the kit).
- LED0 indicates USB Device Configuration Set Complete event (the USB device functionality has been activated by the USB Host).
- Press the switch SW0 to trigger communication from the USB Device to the USB Host.
- When the device is in Standby sleep, SW0 acts as wakeup source and brings the device to active mode. The device sends Remote wakeup to PC host and then goes back to Standby sleep mode to let the PC host drive the resume.

SAME54 Xplained Pro Board

- Use TARGET USB connector on the board to connect the USB Device to the USB Host PC.
- LED0 indicates USB Device Configuration Set Complete event (the USB device functionality has been activated by the USB Host).
- Press the switch SW0 to trigger communication from the USB Device to the USB Host.
- When the device is in Standby sleep, SW0 acts as wakeup source and brings the device to active mode. The device sends Remote wakeup to PC host and then goes back to Standby sleep mode to let the PC host drive the resume.
- To measure current consumed by the device in different Sleep modes, refer to Section Current Measurement Header in SAME54 Xplained Pro Hardware User Guide. Refer to Virtual COM Port section to know more on using EDBG to send runtime messages.

SAML21 Xplained Pro Board

- Use TARGET USB connector on the board to connect the USB Device to the USB Host PC.
- LED0 indicates USB Device Configuration Set Complete event (the USB device functionality has been activated by the USB Host).
- Press the switch SW0 to trigger communication from the USB Device to the USB Host.
- When the device is in Standby sleep, SW0 acts as wakeup source and brings the device to active mode. The device sends Remote wakeup to PC host and then goes back to Standby sleep mode to let the PC host drive the resume.

PIC32CM GC Curiosity Pro board

- Use TARGET USB connector (J200) on the board to connect the USB Device to the USB Host PC.
- LED1 indicates USB Device Configuration Set Complete event (the USB device functionality has been activated by the USB Host).
- Press the switch SW0 to trigger communication from the USB Device to the USB Host.
- When the device is in Standby sleep, SW0 acts as wakeup source and brings the device to active mode. The device sends Remote wakeup to PC host and then goes back to Standby sleep mode to let the PC host drive the resume.

PIC32CK GC Curiosity Ultra Development Board

- Use the Barrel jack connector(J200) to connect an external power supply to the board.
- Use the USB Type-C connector (J202) to connect the USB Device to the USB Host PC.
- LED1 indicates USB Device Configuration Set Complete event (the USB device functionality has been activated by the USB Host).
- Press the switch SW0 to trigger communication from the USB Device to the USB Host.
- When the device is in Standby sleep, SW0 acts as wakeup source and brings the device to active mode. The device sends Remote wakeup to PC host and then goes back to Standby sleep mode to let the PC host drive the resume.

## Running the Application

Runtime messages are sent through UART, which is received by EDBG and sent to PC terminal as USB CDC data. Follow the below steps to see the runtime messages.

1. When the debug USB port is connected to the PC, it should be visible as a virtual COM port.
2. Open up a terminal program, such as HyperTerminal and select the appropriate COM port. Set the serial port settings as follows:
   - Baud : 115200
   - Data : 8 Bits
   - Parity : None
   - Stop : 1 Bit
   - Flow Control : None
3. When the programming is complete and the application starts running, the title message will be seen.
4. Connect the Upstream USB port to the PC and when the enumeration is successful, Device Configured message is seen. Since this is a HID device, PC host will suspend the device, unless an application is accessing it. The terminal window would look like this.

## HID Basic operation

The HID Basic operation is same as hid_basic demo. Refer to local documentation from usb_apps_device/apps/hid_basic. The documentation is also available in the github path usb_apps_device/apps/hid_basic.

## Remote Wakeup, Suspend and Resume operation

1. To demonstrate the Remote wakeup capabilities along with the debug messages, the Upstream ports of target USB and debug USB should be connected to two different PC Hosts. This is shown below.
2. When the PC utility is connected to the USB device, USB Device Resumed message is seen. Closing the application would suspend the USB device and the respective message will be seen.
3. The suspend due to closure of PC utility will not enable the Remote Wakeup of USB device. Therefore the message USB host Suspend device or Remote wakeup is not enabled would be seen. The device will be put to Standby Sleep mode.
4. A resume from PC host can wake up the device and continue with HID operation. This is when USB Device Resumed message is shown.
5. Put the PC host connected to Target USB port to sleep to test Remote wakeup. If the device is allowed to wake up PC host, then the Remote Wakeup will be enabled in the USB device by PC host before suspending the bus. This is shown through USB host in Sleep mode - Remote wakeup enabled. Press Button to wakeup Host. message.
6. If the message USB host Suspend device or Remote wakeup is not enabled is seen when PC host is put to sleep, it means the USB device is not allowed to do Remote Wakeup. Go to the power settings of the USB device in PC host and enable Remote wakeup feature. This can be done in a Windows machine through device manager or command prompt.

    *** USB Device Remote Wakeup Demonstration ***

    Device Configured
    USB Device
          Suspended
    USB host Suspend device or Remote wakeup is not enabled
    MCU on Standby
          Sleep mode

- On "PC Host 2",

  - launch in a command console with administrator privilege: powercfg -devicequery wake_from_any

  - displays all devices that are connected to the PC.

  - search in the answer the ligne "HID-compliant vendor-defined device"

  - launch: powercfg -deviceenablewake "HID-compliant vendor-defined device (002)"

  It can be different. - Then - powercfg -devicequery wake_armed - will return : "HID-compliant vendor-defined device (002)"

- Put the "PC Host 2" on sleep

    USB Device Resumed
    USB Device Suspended
    USB host in Sleep mode - Remote wakeup
          enabled. Press Button to wakeup Host.
    MCU on Standby Sleep mode

- Press SW0

    Remote Wakeup Start Sent
    USB Device Resumed
    USB Device Suspended
    USB host
          Suspend device or Remote wakeup is not enabled
    MCU on Standby Sleep mode
    USB Device
          Resumed
    USB Device Suspended
    USB host Suspend device or Remote wakeup is not
          enabled
    MCU on Standby Sleep mode

- The "PC Host 2" is resumed.
  If the Remote Wakeup is enabled and the device is put to sleep, press the switch to initiate a Remote Wakeup. The PC host will respond back with a resume and device will continue with its HID operation. The screenshot showing suspend, resume and remote wakeup operations are shown below.