Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions samples/subsys/usb/cdc_acm/overlay-composite-cdc-dfu.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Overlay file for composite configuration
# CDC ACM + USB DFU

CONFIG_USB_COMPOSITE_DEVICE=y

CONFIG_USB_DFU_CLASS=y
CONFIG_FLASH=y
CONFIG_IMG_MANAGER=y
CONFIG_FLASH_PAGE_LAYOUT=y
CONFIG_BOOTLOADER_MCUBOOT=y
18 changes: 18 additions & 0 deletions subsys/usb/class/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,21 @@ config USB_DFU_DETACH_TIMEOUT
int
depends on USB_DFU_CLASS
default 1000

config USB_DFU_DEFAULT_POLLTIMEOUT
prompt "Default value for bwPollTimeout"
int
depends on USB_DFU_CLASS
default 256
range 0 1000
help
Default value for bwPollTimeout (in ms)

config USB_DFU_DNLOAD_POLLTIMEOUT
prompt "Value of bwPollTimeout during DNLOAD stage"
int
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a prompt so it will be user-configurable in case this is needed to be changed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry, the prompt should be there, will fix

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Qbicz fixed

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great. For me PR is fine

depends on USB_DFU_CLASS
default 10000
range 0 65535
help
Value of bwPollTimeout (in ms) during DNLOAD stage
18 changes: 15 additions & 3 deletions subsys/usb/class/usb_dfu.c
Original file line number Diff line number Diff line change
Expand Up @@ -300,13 +300,15 @@ struct dfu_data_t {
enum dfu_state state; /* State of the DFU device */
enum dfu_status status; /* Status of the DFU device */
u16_t block_nr; /* DFU block number */
u16_t bwPollTimeout;
};

static struct dfu_data_t dfu_data = {
.state = appIDLE,
.status = statusOK,
.flash_area_id = DT_FLASH_AREA_IMAGE_1_ID,
.alt_setting = 0,
.bwPollTimeout = CONFIG_USB_DFU_DEFAULT_POLLTIMEOUT,
};

/**
Expand Down Expand Up @@ -392,13 +394,19 @@ static int dfu_class_handle_req(struct usb_setup_packet *pSetup,
dfu_data.state = dfuIDLE;
}

/* bStatus */
(*data)[0] = dfu_data.status;
(*data)[1] = 0U;
(*data)[2] = 1U;
/* bwPollTimeout */
sys_put_le16(dfu_data.bwPollTimeout, &(*data)[1]);
(*data)[3] = 0U;
/* bState */
(*data)[4] = dfu_data.state;
/* iString */
(*data)[5] = 0U;
*data_len = 6;
if (dfu_data.state == dfuDNBUSY) {
k_work_submit(&dfu_work);
}
break;

case DFU_GETSTATE:
Expand Down Expand Up @@ -441,6 +449,8 @@ static int dfu_class_handle_req(struct usb_setup_packet *pSetup,
switch (dfu_data.state) {
case dfuIDLE:
LOG_DBG("DFU_DNLOAD start");
dfu_data.bwPollTimeout =
CONFIG_USB_DFU_DNLOAD_POLLTIMEOUT;
dfu_reset_counters();
k_poll_signal_reset(&dfu_signal);

Expand All @@ -456,13 +466,15 @@ static int dfu_class_handle_req(struct usb_setup_packet *pSetup,
dfu_data_worker.worker_state = dfuIDLE;
dfu_data_worker.worker_len = pSetup->wLength;
memcpy(dfu_data_worker.buf, *data, pSetup->wLength);
k_work_submit(&dfu_work);
/* do not submit dfu_work now, wait for DFU_GETSTATUS */
break;
case dfuDNLOAD_IDLE:
dfu_data.state = dfuDNBUSY;
dfu_data_worker.worker_state = dfuDNLOAD_IDLE;
dfu_data_worker.worker_len = pSetup->wLength;
if (dfu_data_worker.worker_len == 0U) {
dfu_data.bwPollTimeout =
CONFIG_USB_DFU_DEFAULT_POLLTIMEOUT;
dfu_data.state = dfuMANIFEST_SYNC;
k_poll_signal_raise(&dfu_signal, 0);
}
Expand Down