| USBD ROM Stack 2.0 ROM based USB device stack

Data Fields
USBD_DFU_INIT_PARAM_T Struct Reference
Device Firmware Upgrade (DFU) Class Function Driver

USB descriptors data structure. More...

`#include <C:/Data/nxp/GIT/lpcopen_v3/lpcopen_version3/LPC11u6x/lpc11u6x/LPC_USBD_Lib/mw_usbd/mw_usbd_dfuuser.h>`

## Data Fields
uint32_t | mem_base
uint32_t | mem_size
uint16_t | wTransferSize
uint16_t | pad
uint8_t * | intf_desc
uint8_t(* | DFU_Write )(uint32_t block_num, uint8_t **src, uint32_t length, uint8_t *bwPollTimeout)
uint32_t(* | DFU_Read )(uint32_t block_num, uint8_t **dst, uint32_t length)
void(* | DFU_Done )(void)
void(* | DFU_Detach )(USBD_HANDLE_T hUsb)
ErrorCode_t(* | DFU_Ep0_Hdlr )(USBD_HANDLE_T hUsb, void *data, uint32_t event)
uint32_t(* | DFU_GetStatus )(uint32_t *timeout, int32_t last)

## Detailed Description

USB descriptors data structure.

This module exposes functions which interact directly with USB device stack's core layer. The application layer uses this component when it has to implement custom class function driver or standard class function driver which is not part of the current USB device stack. The functions exposed by this interface are to register class specific EP0 handlers and corresponding utility functions to manipulate EP0 state machine of the stack. This interface also exposes function to register custom endpoint interrupt handler.

## Field Documentation

## ◆ mem_base

uint32_t USBD_DFU_INIT_PARAM_T::mem_base

Base memory location from where the stack can allocate data and buffers.

Note
  The memory address set in this field should be accessible by USB DMA controller. Also this value should be aligned on 4 byte boundary.

## ◆ mem_size

uint32_t USBD_DFU_INIT_PARAM_T::mem_size

The size of memory buffer which stack can use.

Note
  The mem_size should be greater than the size returned by USBD_DFU_API::GetMemSize() routine.

## ◆ wTransferSize

uint16_t USBD_DFU_INIT_PARAM_T::wTransferSize

DFU transfer block size in number of bytes. This value should match the value set in DFU descriptor provided as part of the descriptor array (high_speed_desc) passed to Init() through USB_CORE_DESCS_T structure.

## ◆ intf_desc

uint8_t* USBD_DFU_INIT_PARAM_T::intf_desc

Pointer to the DFU interface descriptor within the descriptor array (high_speed_desc) passed to Init() through USB_CORE_DESCS_T structure.

## ◆ DFU_Write

uint8_t(* USBD_DFU_INIT_PARAM_T::DFU_Write) (uint32_t block_num, uint8_t **src, uint32_t length, uint8_t *bwPollTimeout)

DFU Write callback function.

This function is provided by the application software. This function gets called when host sends a write command. For application using zero-copy buffer scheme this function is called for the first time with length parameter set to 0. The application code should update the buffer pointer.

Parameters

  [in] | block_num | Destination start address.
  [in,out] | src | Pointer to a pointer to the source of data. Pointer-to-pointer is used to implement zero-copy buffers. See Zero-Copy Data Transfer model for more details on zero-copy concept.
  [out] | bwPollTimeout | Pointer to a 3 byte buffer which the callback implementer should fill with the amount of minimum time, in milliseconds, that the host should wait before sending a subsequent DFU_GETSTATUS request.
  [in] | length | Number of bytes to be written.

Returns
  Returns DFU_STATUS_ values defined in mw_usbd_dfu.h.

## ◆ DFU_Read

uint32_t(* USBD_DFU_INIT_PARAM_T::DFU_Read) (uint32_t block_num, uint8_t **dst, uint32_t length)

DFU Read callback function.

This function is provided by the application software. This function gets called when host sends a read command.

Parameters

  [in] | block_num | Destination start address.
  [in,out] | dst | Pointer to a pointer to the source of data. Pointer-to-pointer is used to implement zero-copy buffers. See Zero-Copy Data Transfer model for more details on zero-copy concept.
  [in] | length | Amount of data copied to destination buffer.

Returns
  Returns
  - DFU_STATUS_ values defined in mw_usbd_dfu.h to return error conditions.
  - 0 if there is no more data to be read. Stack will send EOF frame and set DFU state-machine to dfuIdle state.
  - length of the data copied, should be greater than or equal to 16. If the data copied is less than DFU wTransferSize the stack will send EOF frame and goes to dfuIdle state.

## ◆ DFU_Done

void(* USBD_DFU_INIT_PARAM_T::DFU_Done) (void)

DFU done callback function.

This function is provided by the application software. This function gets called after firmware download completes.

Returns
  Nothing.

## ◆ DFU_Detach

void(* USBD_DFU_INIT_PARAM_T::DFU_Detach) (USBD_HANDLE_T hUsb)

DFU detach callback function.

This function is provided by the application software. This function gets called after USB_REQ_DFU_DETACH is received. Applications which set USB_DFU_WILL_DETACH bit in DFU descriptor should define this function. As part of this function application can call Connect() routine to disconnect and then connect back with host. For application which rely on WinUSB based host application should use this feature since USB reset can be invoked only by kernel drivers on Windows host. By implementing this feature host doen't have to issue reset instead the device has to do it automatically by disconnect and connect procedure.

Parameters

  [in] | hUsb | Handle DFU control structure.

Returns
  Nothing.

## ◆ DFU_Ep0_Hdlr

ErrorCode_t(* USBD_DFU_INIT_PARAM_T::DFU_Ep0_Hdlr) (USBD_HANDLE_T hUsb, void *data, uint32_t event)

Optional user override-able function to replace the default DFU class handler.

The application software could override the default EP0 class handler with their own by providing the handler function address as this data member of the parameter structure. Application which like the default handler should set this data member to zero before calling the USBD_DFU_API::Init().

Note

Parameters

  [in] | hUsb | Handle to the USB device stack.
  [in] | data | Pointer to the data which will be passed when callback function is called by the stack.
  [in] | event | Type of endpoint event. See USBD_EVENT_T for more details.

Returns
  The call back should returns ErrorCode_t type to indicate success or error condition.

Return values

  LPC_OK | On success.
  ERR_USBD_UNHANDLED | Event is not handled hence pass the event to next in line.
  ERR_USBD_xxx | For other error conditions.

## ◆ DFU_GetStatus

uint32_t(* USBD_DFU_INIT_PARAM_T::DFU_GetStatus) (uint32_t *timeout, int32_t last)

Optional callback function to get the status of the previous write(download) transfer.

This function will be called when the stack needs to know the status of the current transfer. the last param when 1 it indicates that the transfer on going is the last download packet.

Note
  This function will not be called when USB_REQ_DFU_GETSTATE requests from Host.

Parameters

  [out] | timeout | : If non zero then DFU device will send dfuDNBUSY status when last = 0 or will send dfuMANIFEST when last = 1.
  [in] | last | : When 1 indicates that the download is complete, 0 otherwise.

Returns
  Should return the 'bstatus' value to be sent to host as part DFU_GETSTATUS request.

Return values

  DFU_STATUS_OK | on Success.
  DFU_STATUS_errXXXXXX | on DFU standard error (example: #DFU_STATUS_errTARGET)
  DFU_STATUS_errVENDOR | on Vendor specific error (lower 8 bits Bit0-7), set the upper 8 bits (bit15:bit8) with corresponding index to descriptive string supported by the application.

The documentation for this struct was generated from the following file:

- C:/Data/nxp/GIT/lpcopen_v3/lpcopen_version3/LPC11u6x/lpc11u6x/LPC_USBD_Lib/mw_usbd/mw_usbd_dfuuser.h