---
title: "USB: Vendor interface echo"
canonical_url: https://developer.repebble.com/pebbleos/docs/samples/subsys/usb/webusb/
last_updated: 2026-11-26
sdk_version: 4.44
---
# USB: Vendor interface echo

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

This sample is a vendor interface over USB, with a bulk endpoint in each direction, that sends back each transfer the host sends, for a minute. A transfer ends with a short packet or at 512 bytes.

The interface gives a device interface GUID, so Windows binds it to WinUSB from the Microsoft OS 2.0 descriptors, and the device has the WebUSB platform capability, with a landing page. Other hosts reach it through libusb, as with pyusb:

```
import usb.coredev=usb.core.find(idVendor=0x1209,idProduct=0x0001)ep\_out,ep\_in=dev.get\_active\_configuration()[(0,0)]ep\_out.write(b"hello")print(bytes(ep\_in.read(512)))
```

The stack picks the endpoints of the device, so the script takes them from the descriptors of the interface.

Run:

`pbl samples samples/subsys/usb/webusb`

Boards:

every board

## Sources

src/main.c

```
#include \<stdatomic.h\>#include \<stdint.h\>#include \<stdio.h\>#include \<pbl/drivers/udc.h\>#include \<pbl/kernel/compiler.h\>#include \<pbl/kernel/delay.h\>#include \<pbl/usb/usbd.h\>#include \<pbl/util/byteorder.h\>#define ECHO\_S 60#define BUF\_LEN 512U#define IFACE 0U#define EP\_OUT 1U#define EP\_IN (PBL\_UDC\_EP\_IN | 1U)#define VENDOR\_CLASS 0xffUstatic const struct PBL\_PACKED {struct pbl\_usb\_desc\_iface iface;struct pbl\_usb\_desc\_ep out;struct pbl\_usb\_desc\_ep in;} s\_desc = {.iface ={.bLength = sizeof(struct pbl\_usb\_desc\_iface),.bDescriptorType = PBL\_USB\_DESC\_INTERFACE,.bInterfaceNumber = IFACE,.bNumEndpoints = 2U,.bInterfaceClass = VENDOR\_CLASS,},.out ={.bLength = sizeof(struct pbl\_usb\_desc\_ep),.bDescriptorType = PBL\_USB\_DESC\_ENDPOINT,.bEndpointAddress = EP\_OUT,.bmAttributes = PBL\_UDC\_EP\_BULK,.wMaxPacketSize = PBL\_CPU\_TO\_LE16(64U),},.in = {.bLength = sizeof(struct pbl\_usb\_desc\_ep),.bDescriptorType = PBL\_USB\_DESC\_ENDPOINT,.bEndpointAddress = EP\_IN,.bmAttributes = PBL\_UDC\_EP\_BULK,.wMaxPacketSize = PBL\_CPU\_TO\_LE16(64U),},};PBL\_USBD\_FUNCTION\_DECLARE(webusb);static atomic\_bool s\_configured;static atomic\_uint s\_count;static uint8\_t s\_buf[BUF\_LEN] PBL\_ALIGNED(PBL\_UDC\_BUF\_ALIGN);static uint8\_t prv\_ep(uint8\_t ep) {return pbl\_usbd\_ep(PBL\_USBD\_FUNCTION(webusb), ep);}/\* A transfer ends with a short packet or a full buffer, and goes back as it came. \*/static void prv\_rx\_start(void) {(void)pbl\_udc\_ep\_queue(UDC, prv\_ep(EP\_OUT), s\_buf, sizeof(s\_buf));}static void prv\_configured(bool on) {atomic\_store(&s\_configured, on);if (on) {prv\_rx\_start();}}static void prv\_xfer\_done(uint8\_t ep, int ret) {if (ret \< 0 || !atomic\_load(&s\_configured)) {return;}if (ep == EP\_OUT && ret \> 0) {atomic\_fetch\_add(&s\_count, (unsigned int)ret);(void)pbl\_udc\_ep\_queue(UDC, prv\_ep(EP\_IN), s\_buf, (size\_t)ret);return;}prv\_rx\_start();}PBL\_USBD\_FUNCTION\_DEFINE(webusb) = {.desc = &s\_desc,.desc\_len = sizeof(s\_desc),.configured = prv\_configured,.xfer\_done = prv\_xfer\_done,.winusb\_guid = "{DE07B10A-24B5-440C-A638-F3855BEB7979}",};int main(void) {int ret;ret = pbl\_usbd\_enable();if (ret != 0) {fprintf(stderr, "usb: device failed (%d)\n", ret);return ret;}printf("usb: vendor interface up, echoing for %d s\n", ECHO\_S);pbl\_sleep\_ms(ECHO\_S \* 1000U);printf("usb: echoed %u bytes\n", atomic\_load(&s\_count));printf("Sample done\n");return 0;}
```

## Output

```
usb: vendor interface up
```

Generated from PebbleOS [9fa910d13](https://github.com/coredevices/pebbleos/commit/9fa910d13ea42053dff926754a25c68090e963dc). This page is maintained in the pebbleos repository: [docs/samples/subsys/usb/webusb.md](https://github.com/coredevices/pebbleos/blob/9fa910d13ea42053dff926754a25c68090e963dc/docs/samples/subsys/usb/webusb.md).
