summaryrefslogtreecommitdiff
path: root/tinyusb/device
diff options
context:
space:
mode:
authorhathach <[email protected]>2013-11-13 14:00:39 +0700
committerhathach <[email protected]>2013-11-13 14:00:39 +0700
commit7d84139bd4e69e0b4cb42fb638a7a6d52afe93de (patch)
tree66247225ca9ced6cf01b3e5135a53ab0625f307a /tinyusb/device
parent92d9c36dbcfd933f872c91ad061e2e5ab184b020 (diff)
fix potential issue with stall endpoints
NOTE: cannot able to STALL control OUT endpoints --> unsupported with data out request may got to an issue. clean up configure, add max string descriptor configure as windows sometimes ask for string @ index 238 !!!
Diffstat (limited to 'tinyusb/device')
-rw-r--r--tinyusb/device/dcd.c113
-rw-r--r--tinyusb/device/dcd_lpc_11uxx_13uxx.c14
-rw-r--r--tinyusb/device/dcd_nxp_romdriver.c170
-rw-r--r--tinyusb/device/dcd_nxp_romdriver.h78
-rw-r--r--tinyusb/device/usbd.c2
5 files changed, 13 insertions, 364 deletions
diff --git a/tinyusb/device/dcd.c b/tinyusb/device/dcd.c
index dfc0947b6..9ff5803b0 100644
--- a/tinyusb/device/dcd.c
+++ b/tinyusb/device/dcd.c
@@ -38,118 +38,7 @@
#include "dcd.h"
-#if 0
+#if MODE_DEVICE_SUPPORTED
-#include "descriptors.h" // TODO refractor later
-
-#define USB_ROM_SIZE (1024*2) // TODO dcd abstract later
-uint8_t usb_RomDriver_buffer[USB_ROM_SIZE] ATTR_ALIGNED(2048) TUSB_CFG_ATTR_USBRAM;
-USBD_HANDLE_T romdriver_hdl;
-static volatile bool isConfigured = false;
-
-/**************************************************************************/
-/*!
- @brief Handler for the USB Configure Event
-*/
-/**************************************************************************/
-ErrorCode_t USB_Configure_Event (USBD_HANDLE_T hUsb)
-{
- USB_CORE_CTRL_T* pCtrl = (USB_CORE_CTRL_T*)hUsb;
- if (pCtrl->config_value)
- {
- #if defined(DEVICE_CLASS_HID)
- ASSERT( TUSB_ERROR_NONE == tusb_hid_configured(hUsb), ERR_FAILED );
- #endif
-
- #ifdef TUSB_CFG_DEVICE_CDC
- ASSERT( TUSB_ERROR_NONE == tusb_cdc_configured(hUsb), ERR_FAILED );
- #endif
- }
-
- isConfigured = true;
-
- return LPC_OK;
-}
-
-/**************************************************************************/
-/*!
- @brief Handler for the USB Reset Event
-*/
-/**************************************************************************/
-ErrorCode_t USB_Reset_Event (USBD_HANDLE_T hUsb)
-{
- isConfigured = false;
- return LPC_OK;
-}
-
-tusb_error_t dcd_init(uint8_t coreid)
-{
-#ifdef DEVICE_ROMDRIVER // TODO refractor later
- /* ROM DRIVER INIT */
- uint32_t membase = (uint32_t) usb_RomDriver_buffer;
- uint32_t memsize = USB_ROM_SIZE;
-
- USBD_API_INIT_PARAM_T usb_param =
- {
- .usb_reg_base = NXP_ROMDRIVER_REG_BASE,
- .max_num_ep = USB_MAX_EP_NUM,
- .mem_base = membase,
- .mem_size = memsize,
-
- .USB_Configure_Event = USB_Configure_Event,
- .USB_Reset_Event = USB_Reset_Event
- };
-
- USB_CORE_DESCS_T DeviceDes =
- {
- .device_desc = (uint8_t*) &USB_DeviceDescriptor,
- .string_desc = (uint8_t*) &USB_StringDescriptor,
- .full_speed_desc = (uint8_t*) &USB_FsConfigDescriptor,
- .high_speed_desc = (uint8_t*) &USB_FsConfigDescriptor,
- .device_qualifier = NULL
- };
-
- /* USB hardware core initialization */
- ASSERT(LPC_OK == ROM_API->hw->Init(&romdriver_hdl, &DeviceDes, &usb_param), TUSB_ERROR_FAILED);
-
- membase += (memsize - usb_param.mem_size);
- memsize = usb_param.mem_size;
-
- /* Initialise the class driver(s) */
- #ifdef TUSB_CFG_DEVICE_CDC
- ASSERT_STATUS( tusb_cdc_init(romdriver_hdl, &USB_FsConfigDescriptor.CDC_CCI_Interface,
- &USB_FsConfigDescriptor.CDC_DCI_Interface, &membase, &memsize) );
- #endif
-
- #ifdef TUSB_CFG_DEVICE_HID_KEYBOARD
- ASSERT_STATUS( tusb_hid_init(romdriver_hdl , &USB_FsConfigDescriptor.HID_KeyboardInterface ,
- HID_KeyboardReportDescriptor, USB_FsConfigDescriptor.HID_KeyboardHID.DescriptorList[0].wDescriptorLength,
- &membase , &memsize) );
- #endif
-
- #ifdef TUSB_CFG_DEVICE_HID_MOUSE
- ASSERT_STATUS( tusb_hid_init(romdriver_hdl , &USB_FsConfigDescriptor.HID_MouseInterface ,
- HID_MouseReportDescriptor, USB_FsConfigDescriptor.HID_MouseHID.DescriptorList[0].wDescriptorLength,
- &membase , &memsize) );
- #endif
-
- hal_interrupt_enable(); /* Enable the USB interrupt */
-
- /* Perform USB soft connect */
- ROM_API->hw->Connect(romdriver_hdl, 1);
-#endif
-
- return TUSB_ERROR_NONE;
-}
-
-/**************************************************************************/
-/*!
- @brief Indicates whether USB is configured or not
-*/
-/**************************************************************************/
-bool usb_isConfigured(void)
-{
- return isConfigured;
-}
#endif
diff --git a/tinyusb/device/dcd_lpc_11uxx_13uxx.c b/tinyusb/device/dcd_lpc_11uxx_13uxx.c
index 73d2f759a..e4ea615ff 100644
--- a/tinyusb/device/dcd_lpc_11uxx_13uxx.c
+++ b/tinyusb/device/dcd_lpc_11uxx_13uxx.c
@@ -234,6 +234,10 @@ void dcd_isr(uint8_t coreid)
{ // received control request from host
// copy setup request & acknowledge so that the next setup can be received by hw
tusb_control_request_t control_request = dcd_data.setup_request;
+
+ // NXP control flowchart clear Active & Stall on both Control IN/OUT endpoints
+ dcd_data.qhd[0][0].stall = dcd_data.qhd[1][0].stall = 0;
+
LPC_USB->DEVCMDSTAT |= CMDSTAT_MASK_SETUP_RECEIVED;
dcd_data.qhd[0][1].buff_addr_offset = addr_offset(&dcd_data.setup_request);
@@ -264,9 +268,10 @@ void dcd_isr(uint8_t coreid)
// CONTROL PIPE API
//--------------------------------------------------------------------+
void dcd_pipe_control_stall(uint8_t coreid)
-{ // only need to stall IN Control endpoint
+{ // TODO cannot able to STALL Control OUT endpoint !!!!!
(void) coreid;
- dcd_data.qhd[1][0].stall = 1;
+
+ dcd_data.qhd[0][0].stall = dcd_data.qhd[1][0].stall = 1;
}
// control transfer does not need to use qtd find function
@@ -338,8 +343,9 @@ tusb_error_t dcd_pipe_clear_stall(uint8_t coreid, uint8_t edpt_addr)
{
uint8_t ep_id = edpt_addr2phy(edpt_addr);
- dcd_data.qhd[ep_id][0].stall = 0;
- dcd_data.qhd[ep_id][0].toggle_reset = 1;
+ dcd_data.qhd[ep_id][0].stall = 0;
+ dcd_data.qhd[ep_id][0].toggle_reset = 1;
+ dcd_data.qhd[ep_id][0].feedback_toggle = 0;
return TUSB_ERROR_NONE;
}
diff --git a/tinyusb/device/dcd_nxp_romdriver.c b/tinyusb/device/dcd_nxp_romdriver.c
deleted file mode 100644
index ccb69cf3c..000000000
--- a/tinyusb/device/dcd_nxp_romdriver.c
+++ /dev/null
@@ -1,170 +0,0 @@
-/**************************************************************************/
-/*!
- @file dcd_nxp_romdriver.c
- @author hathach (tinyusb.org)
-
- @section LICENSE
-
- Software License Agreement (BSD License)
-
- Copyright (c) 2013, hathach (tinyusb.org)
- All rights reserved.
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions are met:
- 1. Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in the
- documentation and/or other materials provided with the distribution.
- 3. Neither the name of the copyright holders nor the
- names of its contributors may be used to endorse or promote products
- derived from this software without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
- EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
- DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
- This file is part of the tinyusb stack.
-*/
-/**************************************************************************/
-
-#include "tusb_option.h"
-
-#if MODE_DEVICE_SUPPORTED && (defined(CAP_DEVICE_ROMDRIVER) && TUSB_CFG_DEVICE_USE_ROM_DRIVER)
-
-#define _TINY_USB_SOURCE_FILE_
-
-//--------------------------------------------------------------------+
-// INCLUDE
-//--------------------------------------------------------------------+
-#include "dcd.h"
-#include "dcd_nxp_romdriver.h"
-#include "tusb_descriptors.h"
-
-#define USB_ROM_SIZE (1024*2) // TODO dcd abstract later
-uint8_t usb_RomDriver_buffer[USB_ROM_SIZE] ATTR_ALIGNED(2048) TUSB_CFG_ATTR_USBRAM;
-
-USBD_HANDLE_T romdriver_hdl;
-
-typedef struct {
- volatile uint8_t state;
-}usbd_info_t; // TODO rename
-
-usbd_info_t usbd_info; // TODO rename
-
-//--------------------------------------------------------------------+
-// MACRO CONSTANT TYPEDEF
-//--------------------------------------------------------------------+
-
-
-//--------------------------------------------------------------------+
-// INTERNAL OBJECT & FUNCTION DECLARATION
-//--------------------------------------------------------------------+
-
-
-//--------------------------------------------------------------------+
-// IMPLEMENTATION
-//--------------------------------------------------------------------+
-ErrorCode_t USB_Configure_Event (USBD_HANDLE_T hUsb)
-{
- USB_CORE_CTRL_T* pCtrl = (USB_CORE_CTRL_T*)hUsb;
-
- if (pCtrl->config_value)
- {
- usbd_info.state = TUSB_DEVICE_STATE_CONFIGURED;
-
- #if DEVICE_CLASS_HID
- ASSERT( TUSB_ERROR_NONE == hidd_configured(), ERR_FAILED );
- #endif
-
- #if TUSB_CFG_DEVICE_CDC
- ASSERT( TUSB_ERROR_NONE == tusb_cdc_configured(hUsb), ERR_FAILED );
- #endif
- }
-
- return LPC_OK;
-}
-
-ErrorCode_t USB_Reset_Event (USBD_HANDLE_T hUsb)
-{
- usbd_info.state = TUSB_DEVICE_STATE_UNPLUG;
- return LPC_OK;
-}
-
-ErrorCode_t USB_Interface_Event (USBD_HANDLE_T hUsb)
-{
- return LPC_OK;
-}
-
-ErrorCode_t USB_Error_Event (USBD_HANDLE_T hUsb, uint32_t param1)
-{
- (void) param1;
- return LPC_OK;
-}
-
-tusb_error_t dcd_init(void)
-{
- USBD_API_INIT_PARAM_T usb_param =
- {
- .usb_reg_base = NXP_ROMDRIVER_REG_BASE,
- .max_num_ep = USB_MAX_EP_NUM,
- .mem_base = (uint32_t) usb_RomDriver_buffer,
- .mem_size = USB_ROM_SIZE,
-
- .USB_Configure_Event = USB_Configure_Event,
- .USB_Reset_Event = USB_Reset_Event,
- .USB_Error_Event = USB_Error_Event,
- .USB_Interface_Event = USB_Interface_Event
- };
-
- USB_CORE_DESCS_T desc_core =
- {
- .device_desc = (uint8_t*) &app_tusb_desc_device,
- .string_desc = (uint8_t*) &app_tusb_desc_strings,
- .full_speed_desc = (uint8_t*) &app_tusb_desc_configuration,
- .high_speed_desc = (uint8_t*) &app_tusb_desc_configuration,
- .device_qualifier = NULL
- };
-
- /* USB hardware core initialization */
- ASSERT_INT(LPC_OK, ROM_API->hw->Init(&romdriver_hdl, &desc_core, &usb_param), TUSB_ERROR_FAILED);
-
- // TODO need to confirm the mem_size is reduced by the number of byte used
-// membase += (memsize - usb_param.mem_size);
-// memsize = usb_param.mem_size;
-
- return TUSB_ERROR_NONE;
-}
-
-bool tusb_device_is_configured(void)
-{
- return usbd_info.state == TUSB_DEVICE_STATE_CONFIGURED;
-}
-
-tusb_error_t dcd_controller_reset(uint8_t coreid)
-{
-//TODO merge with hcd_controller_reset
-// default mode is device ?
- return TUSB_ERROR_NONE;
-}
-
-void dcd_controller_connect(uint8_t coreid)
-{
- ROM_API->hw->Connect(romdriver_hdl, 1);
-}
-
-void dcd_isr(uint8_t coreid)
-{
- ROM_API->hw->ISR(romdriver_hdl);
-}
-
-#endif
-
diff --git a/tinyusb/device/dcd_nxp_romdriver.h b/tinyusb/device/dcd_nxp_romdriver.h
deleted file mode 100644
index f6f12686a..000000000
--- a/tinyusb/device/dcd_nxp_romdriver.h
+++ /dev/null
@@ -1,78 +0,0 @@
-/**************************************************************************/
-/*!
- @file dcd_nxp_romdriver.h
- @author hathach (tinyusb.org)
-
- @section LICENSE
-
- Software License Agreement (BSD License)
-
- Copyright (c) 2013, hathach (tinyusb.org)
- All rights reserved.
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions are met:
- 1. Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in the
- documentation and/or other materials provided with the distribution.
- 3. Neither the name of the copyright holders nor the
- names of its contributors may be used to endorse or promote products
- derived from this software without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
- EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
- DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
- This file is part of the tinyusb stack.
-*/
-/**************************************************************************/
-
-/** \ingroup TBD
- * \defgroup TBD
- * \brief TBD
- *
- * @{
- */
-
-#ifndef _TUSB_DCD_NXP_ROMDRIVER_H_
-#define _TUSB_DCD_NXP_ROMDRIVER_H_
-
-#include "common/common.h"
-
-#ifdef __cplusplus
- extern "C" {
-#endif
-
-
-#define USB_MAX_IF_NUM 8 // maximum interface number supported, should be fixed to 8
-
-#if (MCU == MCU_LPC18XX) || (MCU == MCU_LPC43XX)
- #define ROM_API ( * ((USBD_API_T**) NXP_ROMDRIVER_FUNCTION_ADDR) )
- #define USB_MAX_EP_NUM 6
-#elif (MCU == MCU_LPC13UXX) || (MCU == MCU_LPC11UXX)
- #define ROM_API ( * (*((USBD_API_T***) NXP_ROMDRIVER_FUNCTION_ADDR)) )
- #define USB_MAX_EP_NUM 5
-#else
- #error forgot something, thach ?
-#endif
-
-#include "romdriver/mw_usbd_rom_api.h"
-
-extern USBD_HANDLE_T romdriver_hdl;
-
-#ifdef __cplusplus
- }
-#endif
-
-#endif /* _TUSB_DCD_NXP_ROMDRIVER_H_ */
-
-/** @} */
diff --git a/tinyusb/device/usbd.c b/tinyusb/device/usbd.c
index d3480b370..9d7d23c07 100644
--- a/tinyusb/device/usbd.c
+++ b/tinyusb/device/usbd.c
@@ -199,6 +199,8 @@ tusb_error_t std_get_descriptor(uint8_t coreid, tusb_control_request_t * p_reque
break;
case TUSB_DESC_TYPE_STRING:
+ if ( ! (desc_index < TUSB_CFG_DEVICE_STRING_DESCRIPTOR_COUNT) ) return TUSB_ERROR_DCD_CONTROL_REQUEST_NOT_SUPPORT;
+
dcd_pipe_control_xfer(coreid, TUSB_DIR_DEV_TO_HOST, desc_str_table[desc_index], desc_str_table[desc_index]->bLength);
break;