From 121df700447fe16cec4445749a37511cbd609408 Mon Sep 17 00:00:00 2001 From: NIIBE Yutaka Date: Wed, 28 Dec 2011 22:16:14 +0900 Subject: [PATCH] fix long standing bug of RxCount setting for buffer bound (was bug in STmicro's software) --- ChangeLog | 7 +++++++ STM32_USB-FS-Device_Driver/src/usb_core.c | 3 --- src/usb_msc.c | 4 ---- src/usb_prop.c | 20 +++++++++++++++++--- 4 files changed, 24 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2a5d7f3..f01793c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,12 @@ 2011-12-28 Niibe Yutaka + * src/usb_prop.c (SetEPRxCount_allocated_size): New. + (gnuk_device_reset): Use SetEPRxCount_allocated_size. + * src/usb_msc.c (usb_start_receive): Don't set RxCount register + here. + * STM32_USB-FS-Device_Driver/src/usb_core.c (Standard_ClearFeature) + (Post0_Process): Don't need to set RxCount register. + * src/usb_prop.c (msc_lun_info) [PINPAD_DND_SUPPORT]: ifdef-out. * src/usb-icc.c (EP2_OUT_Callback): Fix apdu size == 49 bug, diff --git a/STM32_USB-FS-Device_Driver/src/usb_core.c b/STM32_USB-FS-Device_Driver/src/usb_core.c index 8fc2963..8220ef3 100644 --- a/STM32_USB-FS-Device_Driver/src/usb_core.c +++ b/STM32_USB-FS-Device_Driver/src/usb_core.c @@ -308,7 +308,6 @@ RESULT Standard_ClearFeature(void) if (Related_Endpoint == ENDP0) { /* After clear the STALL, enable the default endpoint receiver */ - SetEPRxCount(Related_Endpoint, Device_Property.MaxPacketSize); _SetEPRxStatus(Related_Endpoint, EP_RX_VALID); } else @@ -1019,8 +1018,6 @@ uint8_t Post0_Process(void) USB_OTG_EP *ep; #endif /* STM32F10X_CL */ - SetEPRxCount(ENDP0, Device_Property.MaxPacketSize); - if (pInformation->ControlState == STALLED) { vSetEPRxStatus(EP_RX_STALL); diff --git a/src/usb_msc.c b/src/usb_msc.c index 77836b9..1e8bded 100644 --- a/src/usb_msc.c +++ b/src/usb_msc.c @@ -118,10 +118,6 @@ static void usb_start_receive (uint8_t *p, size_t n) ep7_out.rxbuf = p; ep7_out.rxsize = n; ep7_out.rxcnt = 0; - if (n < ENDP_MAX_SIZE) - SetEPRxCount (ENDP7, n); - else - SetEPRxCount (ENDP7, ENDP_MAX_SIZE); SetEPRxValid (ENDP7); } diff --git a/src/usb_prop.c b/src/usb_prop.c index 454ee0b..a0067bb 100644 --- a/src/usb_prop.c +++ b/src/usb_prop.c @@ -41,6 +41,19 @@ #endif +void +SetEPRxCount_allocated_size (uint8_t bEpNum, uint16_t wCount) +{ /* Assume wCount is even */ + uint16_t value; + + if (wCount < 62) + value = (wCount & 0x3e) << 9; + else + value = 0x8000 | (((wCount >> 5) - 1) << 10); + + SetEPRxCount (bEpNum, value); +} + static void gnuk_device_init (void) { @@ -75,7 +88,7 @@ gnuk_device_reset (void) SetEPRxAddr (ENDP0, ENDP0_RXADDR); SetEPTxAddr (ENDP0, ENDP0_TXADDR); Clear_Status_Out (ENDP0); - SetEPRxCount (ENDP0, GNUK_MAX_PACKET_SIZE); + SetEPRxCount_allocated_size (ENDP0, GNUK_MAX_PACKET_SIZE); SetEPRxValid (ENDP0); /* Initialize Endpoint 1 */ @@ -87,7 +100,7 @@ gnuk_device_reset (void) /* Initialize Endpoint 2 */ SetEPType (ENDP2, EP_BULK); SetEPRxAddr (ENDP2, ENDP2_RXADDR); - SetEPRxCount (ENDP2, GNUK_MAX_PACKET_SIZE); + SetEPRxCount_allocated_size (ENDP2, GNUK_MAX_PACKET_SIZE); SetEPRxStatus (ENDP2, EP_RX_VALID); SetEPTxStatus (ENDP2, EP_TX_DIS); @@ -107,7 +120,7 @@ gnuk_device_reset (void) /* Initialize Endpoint 5 */ SetEPType (ENDP5, EP_BULK); SetEPRxAddr (ENDP5, ENDP5_RXADDR); - SetEPRxCount (ENDP5, VIRTUAL_COM_PORT_DATA_SIZE); + SetEPRxCount_allocated_size (ENDP5, VIRTUAL_COM_PORT_DATA_SIZE); SetEPRxStatus (ENDP5, EP_RX_VALID); SetEPTxStatus (ENDP5, EP_TX_DIS); #endif @@ -122,6 +135,7 @@ gnuk_device_reset (void) /* Initialize Endpoint 7 */ SetEPType (ENDP7, EP_BULK); SetEPRxAddr (ENDP7, ENDP7_RXADDR); + SetEPRxCount_allocated_size (ENDP7, 64); SetEPRxStatus (ENDP7, EP_RX_STALL); SetEPTxStatus (ENDP7, EP_TX_DIS); #endif