---
title: "USB: Remote wakeup"
canonical_url: https://developer.repebble.com/pebbleos/docs/samples/subsys/usb/remote_wakeup/
last_updated: 2026-11-27
sdk_version: 4.44
---
# USB: Remote wakeup

Source: https://developer.repebble.com/pebbleos/docs/samples/subsys/usb/remote_wakeup/

This sample follows the state of the USB bus for a minute, printing each change: connected, reset, suspended, resumed. When the host has kept the bus suspended for 5 s, it wakes the host up with `pbl_usbd_wakeup()`. The device advertises remote wakeup with `CONFIG_USB_DEVICE_REMOTE_WAKEUP`, and has a serial port for the host to drive, as [USB: Serial port echo](https://developer.repebble.com/pebbleos/docs/samples/subsys/usb/cdc_acm.md).

Connect the board’s USB device port to a computer, then let the computer suspend the bus, as it does when it goes to sleep. A host only allows remote wakeup on the bus it suspends: without that, `pbl_usbd_wakeup()` returns `-EACCES`.

Run:

`pbl samples samples/subsys/usb/remote_wakeup`

Boards:

every board

## Sources

src/main.c

```
#include \<stdbool.h\>#include \<stdint.h\>#include \<stdio.h\>#include \<pbl/kernel/msgq.h\>#include \<pbl/kernel/time.h\>#include \<pbl/usb/usbd.h\>#define RUN\_S 60#define WAKE\_AFTER\_MS 5000Ustatic const char \*const s\_names[] = {[PBL\_USBD\_EVENT\_CONNECTED] = "connected", [PBL\_USBD\_EVENT\_DISCONNECTED] = "disconnected",[PBL\_USBD\_EVENT\_RESET] = "reset",[PBL\_USBD\_EVENT\_SUSPENDED] = "suspended",[PBL\_USBD\_EVENT\_RESUMED] = "resumed",};/\* The listener runs in the controller's interrupt: it queues, the main thread reports. \*/static PBL\_MSGQ\_DEFINE(s\_events, sizeof(uint8\_t), 16);static void prv\_event(enum pbl\_usbd\_event evt) {uint8\_t e = (uint8\_t)evt;(void)pbl\_msgq\_put(&s\_events, &e, PBL\_NO\_WAIT);}PBL\_USBD\_LISTENER\_DEFINE(sample) = {.event = prv\_event,};int main(void) {uint64\_t end = pbl\_uptime\_ms() + RUN\_S \* 1000U;uint64\_t suspended\_at = 0U;bool suspended = false;uint8\_t e;int ret;/\* The serial port, the device's function, enabled it at boot: the events since are queued. \*/ret = pbl\_usbd\_enable();if (ret != 0) {fprintf(stderr, "usb: enable failed (%d)\n", ret);return ret;}while (pbl\_uptime\_ms() \< end) {if (pbl\_msgq\_get(&s\_events, &e, PBL\_MSEC(100)) == 0) {printf("usb: %s\n", s\_names[e]);suspended = e == PBL\_USBD\_EVENT\_SUSPENDED;suspended\_at = pbl\_uptime\_ms();continue;}if (suspended && pbl\_uptime\_ms() - suspended\_at \>= WAKE\_AFTER\_MS) {ret = pbl\_usbd\_wakeup();printf("usb: remote wakeup (%d)\n", ret);suspended = false;}}printf("Sample done\n");return 0;}
```

## Output

```
usb: connected
```

Generated from PebbleOS [013613c8a](https://github.com/coredevices/pebbleos/commit/013613c8a001fe075e5e247c4a6fe8db8f920099). This page is maintained in the pebbleos repository: [docs/samples/subsys/usb/remote\_wakeup.md](https://github.com/coredevices/pebbleos/blob/013613c8a001fe075e5e247c4a6fe8db8f920099/docs/samples/subsys/usb/remote_wakeup.md).
