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 300000
cmp image.bin readback.bin
pbl samples samples/subsys/usb/dfu
every board
#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;
}
dfu: ready, partition of \d+ KiB at 0x[0-9a-f]+
Generated from PebbleOS 12b6c531f. This page is maintained in the pebbleos repository: docs/samples/subsys/usb/dfu.md.