---
title: "USB: Firmware upgrade"
canonical_url: https://developer.repebble.com/pebbleos/docs/samples/subsys/usb/dfu/
last_updated: 2026-11-24
sdk_version: 4.44
---
# USB: Firmware upgrade

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

This sample is a USB device in DFU mode: `dfu-util` downloads an image to a 1 MiB flash partition, labelled `dfu` in the sample’s board overlay, and uploads it back. The flash is erased and written by a work item while the host polls the device, not from the controller’s interrupt.

Connect the board’s USB device port to a computer, then:

```
dfu-util -l
head -c 300000 /dev/urandom > image.bin
dfu-util -d 1209:0001 -a 0 -D image.bin
dfu-util -d 1209:0001 -a 0 -U readback.bin -Z 300000cmp image.bin readback.bin
```

Run:

`pbl samples samples/subsys/usb/dfu`

Boards:

every board

## Sources

src/main.c

```
#include \<stdio.h\>#include \<pbl/board/partitions.h\>#include \<pbl/usb/dfu.h\>#include \<pbl/usb/usbd.h\>/\* The partition the host downloads to, from the board overlay of the sample. \*/PBL\_USB\_DFU\_REGION\_DEFINE(image, PART\_DFU);int main(void) {int ret;ret = pbl\_usbd\_enable();if (ret != 0) {fprintf(stderr, "dfu: USB failed (%d)\n", ret);return ret;}/\* The device now serves the host from the controller's interrupt and the system work queue. \*/printf("dfu: ready, partition of %d KiB at 0x%x\n", (int)(PART\_DFU\_SIZE / 1024U),(unsigned int)PART\_DFU\_OFFSET);return 0;}
```

## Output

```
dfu: ready, partition of \d+ KiB at 0x[0-9a-f]+
```

Generated from PebbleOS [12b6c531f](https://github.com/coredevices/pebbleos/commit/12b6c531f9e0c2f39fe4e9bb2886314697128f08). This page is maintained in the pebbleos repository: [docs/samples/subsys/usb/dfu.md](https://github.com/coredevices/pebbleos/blob/12b6c531f9e0c2f39fe4e9bb2886314697128f08/docs/samples/subsys/usb/dfu.md).
