AM261x MCU+ SDK: USB DFU Example

| AM261x MCU+ SDK 26.00.00 |

USB DFU Example

# Introduction

- This example demonstrates the use of TinyUSB DFU DEV Class driver. Its implements all the necessary callbacks that are required by TinyUSB DFU (Device Firmware Upgrade) DEV class driver.
- When user issues DFU download command then the application receives the data in a static buffer via USB DFU. Once the manifest state is completed the application sends the received data back to UART0.
- When user issues DFU Upload command it sends the Hello world from AM261x DFU! - Partition 0 string back to the HOST PC.
- refer USB2.0 DFU specs to know more about USB 2.0 DFU class.

Note
  The max buffer size is 4 KB thus, as far as this example is concerned user can send at max 4 KB of data.

- To enable USB Logging for this example refer USB CDC Echo Example

# Supported Combinations

Parameter | Value
--- | ---
CPU + OS | r5fss0-0_nortos
Toolchain | ti-arm-clang
iar-arm
Boards | am261x-lp, am261x-som
Example folder | examples/usb/device/dfu

# Steps to Run the Example

## Build the example

- When using CCS projects to build, import the CCS project for the required combination and build it using the CCS project menu (see Using SDK with CCS Projects).
- When using IAR EW projects to build, import the IAR EW workspace for the required combination and build it using the IAR EW project menu (see Using SDK with IAR Embedded Workbench Projects).
- When using makefiles to build, note the required combination and build using make command (see Using SDK with Makefiles)

## HW Setup

### AM261x-LP

- To test the application, one can use a Windows/Linux PC as a USB host.
- Connect the J10 on AM261x-LP to the USB host.

USB Micro B Device Connector

### AM261X-SOM

- To test the application, one can use a Windows/Linux PC as a USB host
- Connect the J7 on AM261x SOM to the USB host

USB Micro B Device Connector

## Run the example

- Launch a CCS or IAR EW debug session and run the executable, see CCS Launch, Load and Run or IAR Launch, Load and Run
- When the application is running. Observer DFU device detected on HOST PC.

- Open cmd in windows and terminal in case of Linux. Run the following command to detect whether a DFU device has been enumerated or not.

  Windows

      dfu-util -l

  Linux

      sudo dfu-util -l

- If the enumeration is successful the following should be displayed on console.

AM64x-AM243x DFU Device detected.

- If the DFU device is not detected then most probably the WinUSB driver is not installed.
- Refer "Install steps for dfu-util tools(windows)" in Download, Install and Setup SDK and Tools

#### DFU Download

- Open COM port in windows and /dev/ttyUSBx in Linux which opens console for UART0.

- Once the DFU device is enumerated run the following command.

  Windows

      dfu-util -a 0 -i 0 -D test_data.txt

  Linux

      sudo dfu-util -a 0 -i 0 -D test_data.txt

- The test_data.txt file contains a string data that is to be transferred.
- Once the DFU transfer is completed following will be displayed on the terminal.

DFU Download command successful

- Open UART0 serial port to observe the content of `test_data.txt` file displayed on same serial port.

Content of received file displayed on serial port.

#### DFU Upload

- Run the following command to read the data from DFU device.

  Windows

      dfu-util -a 0 -i 0 -U upload_data.txt

  Linux

      sudo dfu-util -a 0 -i 0 -U upload_data.txt

- Once the DFU Upload transaction is successful , open `upload_data.txt` file to see the contents

Data sent by DFU device to DFU host.

# See Also

USB