pebble
  • Tutorials
  • Get the SDK
  • Guides
  • Documentation
  • PebbleOS
  • Mobile App
  • Examples
  • Index 01
  • Community
  • Blog
  • More
Privacy
Cookies
Publish

PebbleOS

  • Overview
  • Start here
    • Getting started guide
  • Pebble Firmware
    • Overview
    • Playground
    • Application SDK
  • Development
    • The pbl CLI
    • Build system
    • Samples
      • Kernel
      • Subsystems
      • Drivers
      • Third-party
      • Rust
      • Benchmarks
    • Emulator and simulator
    • Testing
    • Debugging
    • Conventions
  • System
    • Architecture overview
    • Kernel
    • Drivers
    • Subsystems
    • Libraries
    • Third-party
  • Hardware
    • Boards
    • Board Add-ons
    • Programmers
  • Community
    • Contribution Guidelines
  • Reference
    • Reference
    • Kconfig options

USB: Firmware upgrade

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
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. This page is maintained in the pebbleos repository: docs/samples/subsys/usb/dfu.md.

Overview

  • Sources
  • Output