CuVoodoo STM32F1 firmware template
Functions | Variables
usb_dfu.c File Reference

library for USB DFU to write on internal flash (code) More...

Go to the source code of this file.

Functions

static void usb_disconnect (void)
 disconnect USB to force re-enumerate
 
static void usb_dfu_flash (usbd_device *usbd_dev, struct usb_setup_data *req)
 flash downloaded data block More...
 
static void usb_dfu_reset (usbd_device *usbd_dev, struct usb_setup_data *req)
 disconnect USB and perform system reset More...
 
static enum usbd_request_return_codes usb_dfu_control_request (usbd_device *usbd_dev, struct usb_setup_data *req, uint8_t **buf, uint16_t *len, void(**complete)(usbd_device *usbd_dev, struct usb_setup_data *req))
 handle incoming USB DFU control request More...
 
void usb_dfu_setup (void)
 setup USB DFU peripheral
 
void usb_dfu_start (void)
 start USB DFU handling
 

Variables

static uint8_t usbd_control_buffer [1024] = {0}
 buffer to be used for control requests (fit to flash page size)
 
static usbd_device * usb_device = NULL
 structure holding all the info related to the USB device
 
static enum dfu_state usb_dfu_state = STATE_DFU_IDLE
 current DFU state
 
static enum dfu_status usb_dfu_status = DFU_STATUS_OK
 current DFU status
 
static uint8_t download_data [sizeof(usbd_control_buffer)] = {0}
 downloaded data to be programmed in flash
 
static uint16_t download_length = 0
 length of downloaded data
 
static uint32_t flash_pointer = 0
 where the downloaded data should be flashed
 
static const struct usb_device_descriptor usb_dfu_device
 USB DFU device descriptor. More...
 
static const struct usb_dfu_descriptor usb_dfu_functional
 USB DFU functional descriptor. More...
 
static const struct usb_interface_descriptor usb_dfu_interface
 USB DFU interface descriptor. More...
 
static const struct usb_interface usb_dfu_interfaces []
 USB DFU interface descriptor list. More...
 
static const struct usb_config_descriptor usb_dfu_configuration
 USB DFU configuration descriptor. More...
 
static const char * usb_dfu_strings []
 USB string table. More...
 

Detailed Description

library for USB DFU to write on internal flash (code)

Author
King Kévin kingk.nosp@m.evin.nosp@m.@cuvo.nosp@m.odoo.nosp@m..info
Date
2017

Definition in file usb_dfu.c.

Function Documentation

◆ usb_dfu_control_request()

static enum usbd_request_return_codes usb_dfu_control_request ( usbd_device *  usbd_dev,
struct usb_setup_data *  req,
uint8_t **  buf,
uint16_t *  len,
void(**)(usbd_device *usbd_dev, struct usb_setup_data *req)  complete 
)
static

handle incoming USB DFU control request

Parameters
[in]usbd_devUSB device descriptor
[in]reqcontrol request information
[in]bufcontrol request data
[in]lencontrol request data length
[in]completenot used
Returns
USBD_REQ_HANDLED if handled correctly, USBD_REQ_NOTSUPP else
Note
resets device when configured with 5 bits

Definition at line 193 of file usb_dfu.c.

◆ usb_dfu_flash()

static void usb_dfu_flash ( usbd_device *  usbd_dev,
struct usb_setup_data *  req 
)
static

flash downloaded data block

Parameters
[in]usbd_devUSB device (unused)
[in]reqUSB request (unused)
Note
this function is called after the corresponding GETSTATUS request

Definition at line 155 of file usb_dfu.c.

◆ usb_dfu_reset()

static void usb_dfu_reset ( usbd_device *  usbd_dev,
struct usb_setup_data *  req 
)
static

disconnect USB and perform system reset

Parameters
[in]usbd_devUSB device (unused)
[in]reqUSB request (unused)
Note
this function is called after the corresponding GETSTATUS request

Definition at line 175 of file usb_dfu.c.

Variable Documentation

◆ usb_dfu_configuration

const struct usb_config_descriptor usb_dfu_configuration
static
Initial value:
= {
.bLength = USB_DT_CONFIGURATION_SIZE,
.bDescriptorType = USB_DT_CONFIGURATION,
.wTotalLength = 0,
.bNumInterfaces = LENGTH(usb_dfu_interfaces),
.bConfigurationValue = 1,
.iConfiguration = 0,
.bmAttributes = 0x80,
.bMaxPower = 0x32,
.interface = usb_dfu_interfaces,
}
#define LENGTH(x)
get the length of an array
Definition: global.h:26
static const struct usb_interface usb_dfu_interfaces[]
USB DFU interface descriptor list.
Definition: usb_dfu.c:97

USB DFU configuration descriptor.

Note
as defined in USB Device Firmware Upgrade specification section 4.2.2

Definition at line 105 of file usb_dfu.c.

◆ usb_dfu_device

const struct usb_device_descriptor usb_dfu_device
static
Initial value:
= {
.bLength = USB_DT_DEVICE_SIZE,
.bDescriptorType = USB_DT_DEVICE,
.bcdUSB = 0x0200,
.bDeviceClass = 0,
.bDeviceSubClass = 0,
.bDeviceProtocol = 0,
.bMaxPacketSize0 = 64,
.idVendor = 0x1209,
.idProduct = 0x4256,
.bcdDevice = 0x0000,
.iManufacturer = 1,
.iProduct = 2,
.iSerialNumber = 0,
.bNumConfigurations = 1,
}

USB DFU device descriptor.

Note
as defined in USB Device Firmware Upgrade specification section 4.2.1

Definition at line 50 of file usb_dfu.c.

◆ usb_dfu_functional

const struct usb_dfu_descriptor usb_dfu_functional
static
Initial value:
= {
.bLength = sizeof(struct usb_dfu_descriptor),
.bDescriptorType = DFU_FUNCTIONAL,
.bmAttributes = USB_DFU_CAN_DOWNLOAD | USB_DFU_WILL_DETACH,
.wDetachTimeout = 200,
.wTransferSize = sizeof(usbd_control_buffer),
.bcdDFUVersion = 0x0110,
}
static uint8_t usbd_control_buffer[1024]
buffer to be used for control requests (fit to flash page size)
Definition: usb_dfu.c:38

USB DFU functional descriptor.

Note
as defined in USB Device Firmware Upgrade specification section 4.2.4

Definition at line 70 of file usb_dfu.c.

◆ usb_dfu_interface

const struct usb_interface_descriptor usb_dfu_interface
static
Initial value:
= {
.bLength = USB_DT_INTERFACE_SIZE,
.bDescriptorType = USB_DT_INTERFACE,
.bInterfaceNumber = 0,
.bAlternateSetting = 0,
.bNumEndpoints = 0,
.bInterfaceClass = 0xFE,
.bInterfaceSubClass = 1,
.bInterfaceProtocol = 2,
.iInterface = 3,
.extra = &usb_dfu_functional,
.extralen = sizeof(usb_dfu_functional),
}
static const struct usb_dfu_descriptor usb_dfu_functional
USB DFU functional descriptor.
Definition: usb_dfu.c:70

USB DFU interface descriptor.

Note
as defined in USB Device Firmware Upgrade specification section 4.2.3

Definition at line 82 of file usb_dfu.c.

◆ usb_dfu_interfaces

const struct usb_interface usb_dfu_interfaces[]
static
Initial value:
= {{
.num_altsetting = 1,
.altsetting = &usb_dfu_interface,
}}
static const struct usb_interface_descriptor usb_dfu_interface
USB DFU interface descriptor.
Definition: usb_dfu.c:82

USB DFU interface descriptor list.

Definition at line 97 of file usb_dfu.c.

◆ usb_dfu_strings

const char* usb_dfu_strings[]
static
Initial value:
= {
"CuVoodoo",
"BusVoodoo multi-protocol debugging adapter ",
"DFU bootloader (DFU mode)",
}

USB string table.

Note
starts with index 1

Definition at line 121 of file usb_dfu.c.