From 42f9c16fd874df290faec644dbead8dbb30eb72d Mon Sep 17 00:00:00 2001 From: NIIBE Yutaka Date: Fri, 1 Jun 2012 09:34:28 +0900 Subject: [PATCH] Bug fixes for USB protocol stack. --- ChangeLog | 8 ++++++++ src/main.c | 2 +- src/usb_ctrl.c | 7 +++++-- src/usb_lld.c | 23 ++++++----------------- src/usb_lld.h | 2 +- 5 files changed, 21 insertions(+), 21 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2a4848a..d1f76ae 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2012-06-01 Niibe Yutaka + + USB bug fixes. + * src/usb_ctrl.c (gnuk_usb_event): Bug fix for handling + USB_EVENT_CONFIG. Do nothing when current_conf == value. + * src/usb_lld.c (std_clear_feature): Bug fix. Always clear DTOG. + (usb_lld_init): New argument for FEATURE. + 2012-05-31 Niibe Yutaka * polarssl-0.14.0/library/rsa.c (rsa_pkcs1_verify): BUF size is diff --git a/src/main.c b/src/main.c index d935fb0..33fe8e8 100644 --- a/src/main.c +++ b/src/main.c @@ -389,7 +389,7 @@ main (int argc, char *argv[]) flash_unlock (); device_initialize_once (); - usb_lld_init (); + usb_lld_init (Config_Descriptor.Descriptor[7]); random_init (); while (1) diff --git a/src/usb_ctrl.c b/src/usb_ctrl.c index c7ee886..9c80e78 100644 --- a/src/usb_ctrl.c +++ b/src/usb_ctrl.c @@ -347,6 +347,7 @@ gnuk_get_descriptor (uint8_t desc_type, uint16_t index, uint16_t value) static int gnuk_usb_event (uint8_t event_type, uint16_t value) { int i; + uint8_t current_conf; switch (event_type) { @@ -354,7 +355,8 @@ static int gnuk_usb_event (uint8_t event_type, uint16_t value) bDeviceState = ADDRESSED; return USB_SUCCESS; case USB_EVENT_CONFIG: - if (usb_lld_current_configuration () == 0) + current_conf = usb_lld_current_configuration (); + if (current_conf == 0) { if (value != 1) return USB_UNSUPPORT; @@ -365,7 +367,7 @@ static int gnuk_usb_event (uint8_t event_type, uint16_t value) bDeviceState = CONFIGURED; chEvtSignalI (main_thread, LED_STATUS_MODE); } - else + else if (current_conf != value) { if (value != 0) return USB_UNSUPPORT; @@ -375,6 +377,7 @@ static int gnuk_usb_event (uint8_t event_type, uint16_t value) gnuk_setup_endpoints_for_interface (i, 1); bDeviceState = ADDRESSED; } + /* Do nothing when current_conf == value */ return USB_SUCCESS; default: break; diff --git a/src/usb_lld.c b/src/usb_lld.c index 1c31a04..3827c32 100644 --- a/src/usb_lld.c +++ b/src/usb_lld.c @@ -358,13 +358,14 @@ static void st103_ep_clear_dtog_tx (uint8_t ep_num) } } -void usb_lld_init (void) +void usb_lld_init (uint8_t feature) { usb_lld_sys_init (); dev_p->state = IN_DATA; usb_lld_set_configuration (0); + usb_lld_set_feature (feature); /* Reset USB */ st103_set_cntr (CNTR_FRES); @@ -606,22 +607,10 @@ static int std_clear_feature (uint8_t req, uint16_t value, if (status == 0) /* Disabled */ return USB_UNSUPPORT; - if (index & 0x80) - { /* IN endpoint */ - if (st103_ep_get_tx_status (endpoint) == EP_TX_STALL) - { - st103_ep_clear_dtog_tx (endpoint); - st103_ep_set_tx_status (endpoint, EP_TX_VALID); - } - } - else - { /* OUT endpoint */ - if (st103_ep_get_rx_status (endpoint) == EP_RX_STALL) - { - st103_ep_clear_dtog_rx (endpoint); - st103_ep_set_rx_status (endpoint, EP_RX_VALID); - } - } + if (index & 0x80) /* IN endpoint */ + st103_ep_clear_dtog_tx (endpoint); + else /* OUT endpoint */ + st103_ep_clear_dtog_rx (endpoint); // event?? return USB_SUCCESS; diff --git a/src/usb_lld.h b/src/usb_lld.h index 78a35e3..481c7a7 100644 --- a/src/usb_lld.h +++ b/src/usb_lld.h @@ -109,7 +109,7 @@ extern uint32_t bDeviceState; #define STM32_USB_IRQ_PRIORITY 11 -extern void usb_lld_init (void); +extern void usb_lld_init (uint8_t feature); extern void usb_lld_to_pmabuf (const void *src, uint16_t addr, size_t n);