Exemple #1
0
/**
* @brief  USB_OTG_BSP_mDelay
*          This function provides delay time in milli sec
* @param  msec : Value of delay required in milli sec
* @retval None
*/
void USB_OTG_BSP_mDelay (const uint32_t msec)
{
  USB_OTG_BSP_uDelay(msec * 1000);   
}
Exemple #2
0
void USB_OTG_BSP_Init(USB_OTG_CORE_HANDLE *pdev)
{
  GPIO_InitTypeDef GPIO_InitStructure;

#ifdef USE_USB_OTG_FS 
 
  RCC_AHB1PeriphClockCmd( RCC_AHB1Periph_GPIOA , ENABLE);  
  
  /* Configure SOF VBUS ID DM DP Pins */
  GPIO_InitStructure.GPIO_Pin = 
                                GPIO_Pin_11 | 
                                GPIO_Pin_12;
  
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;
  GPIO_Init(GPIOA, &GPIO_InitStructure);  
  
  GPIO_PinAFConfig(GPIOA,GPIO_PinSource11,GPIO_AF_OTG1_FS) ; 
  GPIO_PinAFConfig(GPIOA,GPIO_PinSource12,GPIO_AF_OTG1_FS) ;
  
  /* this for ID line debug */
  GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_10;
  GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP ;  
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
  GPIO_Init(GPIOA, &GPIO_InitStructure);  
  GPIO_PinAFConfig(GPIOA,GPIO_PinSource10,GPIO_AF_OTG1_FS) ;   


  RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
  RCC_AHB2PeriphClockCmd(RCC_AHB2Periph_OTG_FS, ENABLE) ; 
#else // USE_USB_OTG_HS 
  RCC_AHB1PeriphClockCmd( RCC_AHB1Periph_GPIOA | RCC_AHB1Periph_GPIOB | 
                         RCC_AHB1Periph_GPIOC, ENABLE);    
  
  
  GPIO_PinAFConfig(GPIOA,GPIO_PinSource3, GPIO_AF_OTG2_HS) ; // D0
  GPIO_PinAFConfig(GPIOA,GPIO_PinSource5, GPIO_AF_OTG2_HS) ; // CLK
  GPIO_PinAFConfig(GPIOB,GPIO_PinSource0, GPIO_AF_OTG2_HS) ; // D1
  GPIO_PinAFConfig(GPIOB,GPIO_PinSource1, GPIO_AF_OTG2_HS) ; // D2
  GPIO_PinAFConfig(GPIOB,GPIO_PinSource10,GPIO_AF_OTG2_HS) ; // D3
  GPIO_PinAFConfig(GPIOB,GPIO_PinSource11,GPIO_AF_OTG2_HS) ; // D4
  GPIO_PinAFConfig(GPIOB,GPIO_PinSource12,GPIO_AF_OTG2_HS) ; // D5
  GPIO_PinAFConfig(GPIOB,GPIO_PinSource13,GPIO_AF_OTG2_HS) ; // D6
  GPIO_PinAFConfig(GPIOB,GPIO_PinSource5, GPIO_AF_OTG2_HS) ; // D7
  GPIO_PinAFConfig(GPIOC,GPIO_PinSource3, GPIO_AF_OTG2_HS) ; // NXT
  GPIO_PinAFConfig(GPIOC,GPIO_PinSource2, GPIO_AF_OTG2_HS) ; // DIR
  GPIO_PinAFConfig(GPIOC,GPIO_PinSource0, GPIO_AF_OTG2_HS) ; // STP
  
  // CLK
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5 ; 
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
  GPIO_Init(GPIOA, &GPIO_InitStructure);  
  
  // D0
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3  ; 
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;
  GPIO_Init(GPIOA, &GPIO_InitStructure);  
  
  
  // D1 D2 D3 D4 D5 D6 D7
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1  |
                                GPIO_Pin_5 | GPIO_Pin_10 | 
                                GPIO_Pin_11| GPIO_Pin_12 | 
                                GPIO_Pin_13 ;
  
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;
  GPIO_Init(GPIOB, &GPIO_InitStructure);  
  
  
  // STP NXT DIR
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_2 | GPIO_Pin_3;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
  GPIO_Init(GPIOC, &GPIO_InitStructure); 
  
  /* Configure pin for OTG_HOST RST */
  RCC_AHB1PeriphClockCmd(OTG_HS_RST_PORT_RCC, ENABLE);

  //RST
  GPIO_InitStructure.GPIO_Pin = OTG_HS_RST_PIN ; 
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;
  GPIO_Init(OTG_HS_RST_PORT, &GPIO_InitStructure);   

  /* reset the ULPI_PHY */
  GPIO_ResetBits(OTG_HS_RST_PORT, OTG_HS_RST_PIN);
	
  USB_OTG_BSP_uDelay(4000);
	
  GPIO_SetBits(OTG_HS_RST_PORT, OTG_HS_RST_PIN); 

  RCC_AHB1PeriphClockCmd( RCC_AHB1Periph_OTG_HS | 
                         RCC_AHB1Periph_OTG_HS_ULPI, ENABLE); 
												 												    
#endif //USB_OTG_HS
}
Exemple #3
0
/**
 * @brief  USB_OTG_BSP_mDelay
 *          This function provides delay time in milli sec
 * @param  msec : Value of delay required in milli sec
 * @retval None
 */
void USB_OTG_BSP_mDelay (const uint32_t msec)
{
//        BSP_Delay (msec, TIM_MSEC_DELAY);
        USB_OTG_BSP_uDelay (msec * 1000);
}
static int _usb_ctrl_request_handle(USB_OTG_CORE_HANDLE *pdev , 
                                    USBH_HOST *phost, 
                                    wifi_usb_adapter_t *adapter)
{
    wifi_usb_ctrl_request_t *ctl_req = &adapter->usb_ctrl_req;
    unsigned char direction;  
    static unsigned short timeout = 0;
    URB_STATE URB_Status = URB_IDLE;
    int status = 1;

    phost->Control.status = CTRL_START;

    switch (ctl_req->state) {
    case CTRL_IDLE:
        status = 0; /* indicate the state machine could be blocked */
        break;
        
    case CTRL_SETUP:
        /* Send a SETUP packet. */
        pdev->host.hc[ctl_req->hc_num_out].toggle_out = 0; 
        USBH_CtlSendSetup(pdev, ctl_req->ctrlreq.d8, ctl_req->hc_num_out);  
        ctl_req->state = CTRL_SETUP_WAIT;  
        break; 

    case CTRL_SETUP_WAIT:
        URB_Status = HCD_GetURB_State(pdev , ctl_req->hc_num_out); 
        ctl_req->status = URB_Status;
        if (URB_Status == URB_DONE) { 
            direction = (ctl_req->ctrlreq.b.bmRequestType & USB_REQ_DIR_MASK);

            /* check if there is a data stage. */
            if (ctl_req->ctrlreq.b.wLength.w != 0) {        
                timeout = CTRL_DATA_STAGE_TIMEOUT;
                if (direction == USB_D2H) {
                    /* Data Direction is IN. */
                    ctl_req->state = CTRL_DATA_IN;
                }
                else {
                    /* Data Direction is OUT. */
                    ctl_req->state = CTRL_DATA_OUT;

                } 
            }
            /* No DATA stage. */
            else {
                timeout = CTRL_NODATA_STAGE_TIMEOUT;

                /* If there is No Data Transfer Stage. */
                if (direction == USB_D2H) {
                    /* Data Direction is IN. */
                    ctl_req->state = CTRL_STATUS_OUT;

                }
                else {
                    /* Data Direction is OUT. */
                    ctl_req->state = CTRL_STATUS_IN;
                } 
            }
            
            /* Set the delay timer to enable timeout for data stage completion. */
            ctl_req->timer = HCD_GetCurrentFrame(pdev);
        }
        else if (URB_Status == URB_ERROR) {
            ctl_req->state = CTRL_ERROR;  
            /* To be add. */
        }    
        break;

    case CTRL_DATA_IN:  
        /* Issue an IN token. */ 
        USBH_CtlReceiveData(pdev,
                            ctl_req->buffer, 
                            ctl_req->length,
                            ctl_req->hc_num_in);

        ctl_req->state = CTRL_DATA_IN_WAIT;
        break;    

    case CTRL_DATA_IN_WAIT:
        USB_OTG_BSP_uDelay(200);

        URB_Status = HCD_GetURB_State(pdev , ctl_req->hc_num_in); 
        ctl_req->status = URB_Status;

        /* check is DATA packet transfered successfully. */
        if (URB_Status == URB_DONE) { 
            ctl_req->state = CTRL_STATUS_OUT;
        }
        
        /* manage error cases. */
        else if (URB_Status == URB_STALL) { 
            ctl_req->state =  CTRL_ERROR;
        }   
        else if (URB_Status == URB_ERROR) {
            /* Device error. */
            ctl_req->state = CTRL_ERROR;    
        }

        break;

    case CTRL_DATA_OUT:
        /* Start DATA out transfer (only one DATA packet). */
        USB_OTG_BSP_uDelay(200);
        pdev->host.hc[ctl_req->hc_num_out].toggle_out ^= 1; 

        USBH_CtlSendData(pdev,
                        ctl_req->buffer, 
                        ctl_req->length , 
                        ctl_req->hc_num_out);

        ctl_req->state = CTRL_DATA_OUT_WAIT;
        break;

    case CTRL_DATA_OUT_WAIT:
        URB_Status = HCD_GetURB_State(pdev, ctl_req->hc_num_out);
        ctl_req->status = URB_Status;
        
        if (URB_Status == URB_DONE) { 
            /* If the Setup Pkt is sent successful, then change the state. */
            ctl_req->state = CTRL_STATUS_IN;
        }

        /* handle error cases. */
        else if (URB_Status == URB_STALL) { 
            ctl_req->state = CTRL_ERROR;
        } 
        else if (URB_Status == URB_NOTREADY) { 
            /* Nack received from device. */
            ctl_req->state = CTRL_DATA_OUT;
        }    
        else if (URB_Status == URB_ERROR) {
            /* device error */
            ctl_req->state = CTRL_ERROR;   
        } 
        break;


    case CTRL_STATUS_IN:
        /* Send 0 bytes out packet. */
        USB_OTG_BSP_uDelay(200);
        USBH_CtlReceiveData(pdev,
                            0,
                            0,
                            ctl_req->hc_num_in);

        ctl_req->state = CTRL_STATUS_IN_WAIT;

        break;

    case CTRL_STATUS_IN_WAIT:
        URB_Status = HCD_GetURB_State(pdev, ctl_req->hc_num_in); 
        ctl_req->status = URB_Status;

        if (URB_Status == URB_DONE) { 
            /* Control transfers completed, Exit the State Machine */
            ctl_req->state = CTRL_IDLE;
            _usb_control_complete(adapter);
        }

        else if (URB_Status == URB_ERROR) {
            ctl_req->state = CTRL_ERROR;  
        }
        else if (URB_Status == URB_STALL) {
            ctl_req->state = URB_STALL;  /* NOTICE: here maybe a error to be fixed!!! */
        }
        
        break;

    case CTRL_STATUS_OUT:
        USB_OTG_BSP_uDelay(200);
        pdev->host.hc[ctl_req->hc_num_out].toggle_out ^= 1; 
        USBH_CtlSendData(pdev,
                        0,
                        0,
                        ctl_req->hc_num_out);

        ctl_req->state = CTRL_STATUS_OUT_WAIT;
        break;

    case CTRL_STATUS_OUT_WAIT: 
        URB_Status = HCD_GetURB_State(pdev, ctl_req->hc_num_out);
        ctl_req->status = URB_Status;
        
        if (URB_Status == URB_DONE) { 
            ctl_req->state = CTRL_IDLE;
            _usb_control_complete(adapter);
        }
        else if (URB_Status == URB_NOTREADY) { 
            ctl_req->state = CTRL_STATUS_OUT;
        }      
        else if (URB_Status == URB_ERROR) {
            ctl_req->state = CTRL_ERROR; 
        }
        break;

    case CTRL_ERROR:
        DBGPRINT(WHED_DEBUG_ERROR, "PANIC(%s - %d): %s - control urb failed(%d), bRequestType = 0x%x, bRequest = 0x%x, wValue = 0x%x, wIndex = 0x%x, wLength = 0x%x.\n", 
                __FILE__, __LINE__, __FUNCTION__, 
                ctl_req->status,
                ctl_req->ctrlreq.b.bmRequestType,
                ctl_req->ctrlreq.b.bRequest,
                ctl_req->ctrlreq.b.wValue.w,
                ctl_req->ctrlreq.b.wIndex.w,
                ctl_req->ctrlreq.b.wLength.w);
        if (ctl_req->retry) {
            ctl_req->retry--;
            /* Do the transmission again, starting from SETUP Packet. */
            ctl_req->state = CTRL_SETUP; 
        }
        else {
            ctl_req->state = CTRL_IDLE;
            _usb_control_complete(adapter);
        }
        break;

    default:
        break;
    }
    
    timeout = timeout; /* avoid compiler's warning */

    return status;
}
static int _usb_bulkin_request_handle(USB_OTG_CORE_HANDLE * pdev , 
                                      USBH_HOST * phost, 
                                      wifi_usb_adapter_t *adapter)
{
    wifi_usb_bulkin_request_t *rx_req = &adapter->usb_rx_req;
    static unsigned short timeout = 0;
    URB_STATE URB_Status = URB_IDLE;
    unsigned int actual_len = 0;
    int status = 1;

    switch (rx_req->state) {
    case USB_BULK_STATE_IDLE:
        status = 0; /* indicate the state machine could be blocked */
        break;

    case USB_BULK_STATE_REQUEST:
        rx_req->packet_buffer = &rx_req->buffer[0];
        rx_req->packet_len = pdev->host.hc[adapter->hc_num_in].max_packet;
        
        USBH_BulkReceiveData(pdev, rx_req->packet_buffer, rx_req->packet_len, adapter->hc_num_in);

        rx_req->retry = 3;
        rx_req->state = USB_BULK_STATE_REQUEST_WAIT;
        status = 0; /* indicate the state machine could be blocked */
        timeout = BULK_DATA_STAGE_TIMEOUT;
        /* Set the delay timer to enable timeout for data stage completion. */
        rx_req->timer = HCD_GetCurrentFrame(pdev);
        break;

    case USB_BULK_STATE_REQUEST_WAIT:
        URB_Status = HCD_GetURB_State(pdev , adapter->hc_num_in);
        rx_req->status = URB_Status;
  
        if (URB_Status == URB_DONE) { 
            rx_req->state = USB_BULK_STATE_IDLE;
            actual_len = pdev->host.hc[adapter->hc_num_in].xfer_count;
            rx_req->len += actual_len;
            rx_req->packet_buffer = (unsigned char *)(rx_req->packet_buffer) + actual_len;

            if (actual_len < pdev->host.hc[adapter->hc_num_in].max_packet) {
                _usb_bulkin_complete(adapter);
            }
            else {
                if ((rx_req->len + pdev->host.hc[adapter->hc_num_in].max_packet) <= NOSWIFI_USB_RX_BUFFER_MAX_LEN) {
                    rx_req->packet_len = pdev->host.hc[adapter->hc_num_in].max_packet;
                    USBH_BulkReceiveData(pdev, rx_req->packet_buffer, rx_req->packet_len, adapter->hc_num_in);

                    rx_req->retry = 3;
                    rx_req->state = USB_BULK_STATE_REQUEST_WAIT;
                    status = 0; /* indicate the state machine could be blocked */
                    timeout = BULK_DATA_STAGE_TIMEOUT;
                    /* Set the delay timer to enable timeout for data stage completion. */
                    rx_req->timer = HCD_GetCurrentFrame(pdev);
                }
                else {
                    rx_req->len = 0;
                    _usb_bulkin_complete(adapter);
                }
            }
        }
        else if (URB_Status == URB_ERROR) {
            rx_req->state = USB_BULK_STATE_ERROR;
        }    
        else if (URB_Status == URB_STALL) {
            rx_req->state = USB_BULK_STATE_ERROR;
        }
        break;

    case USB_BULK_STATE_ERROR:
        DBGPRINT(WHED_DEBUG_ERROR, "PANIC(%s - %d): %s - rx urb failed(%d).\n", __FILE__, __LINE__, __FUNCTION__, rx_req->status);
        if (rx_req->retry) {
            USB_OTG_BSP_uDelay(600);
            rx_req->retry--;
            rx_req->state = USB_BULK_STATE_REQUEST; 
        }
        else {
            rx_req->state = USB_BULK_STATE_REQUEST;
            rx_req->state = USB_BULK_STATE_IDLE;
            rx_req->len = 0;
            _usb_bulkin_complete(adapter);
        }
        break;

    default:
        break;
    }

    timeout = timeout; /* avoid compiler's warning */

    return status;
}
void USB_OTG_BSP_Init(USB_OTG_CORE_HANDLE *pdev)
{
#ifndef USE_STM3210C_EVAL
    GPIO_InitTypeDef GPIO_InitStructure;
#endif
#ifndef USE_ULPI_PHY
#ifdef USB_OTG_FS_LOW_PWR_MGMT_SUPPORT
    EXTI_InitTypeDef EXTI_InitStructure;
    NVIC_InitTypeDef NVIC_InitStructure;
#endif
#endif

#ifdef USE_STM3210C_EVAL

    RCC_OTGFSCLKConfig(RCC_OTGFSCLKSource_PLLVCO_Div3);
    RCC_AHBPeriphClockCmd(RCC_AHBPeriph_OTG_FS, ENABLE) ;

#else // USE_STM322xG_EVAL  

#ifdef USE_USB_OTG_FS

    RCC_AHB1PeriphClockCmd( RCC_AHB1Periph_GPIOA , ENABLE);

    /* Configure SOF VBUS ID DM DP Pins */
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8  |
                                  GPIO_Pin_9  |
                                  GPIO_Pin_11 |
                                  GPIO_Pin_12;

    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
    GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;
    GPIO_Init(GPIOA, &GPIO_InitStructure);

    GPIO_PinAFConfig(GPIOA,GPIO_PinSource8,GPIO_AF_OTG1_FS) ;
    GPIO_PinAFConfig(GPIOA,GPIO_PinSource9,GPIO_AF_OTG1_FS) ;
    GPIO_PinAFConfig(GPIOA,GPIO_PinSource11,GPIO_AF_OTG1_FS) ;
    GPIO_PinAFConfig(GPIOA,GPIO_PinSource12,GPIO_AF_OTG1_FS) ;

    /* this for ID line debug */


    GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_10;
    GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP ;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
    GPIO_Init(GPIOA, &GPIO_InitStructure);
    GPIO_PinAFConfig(GPIOA,GPIO_PinSource10,GPIO_AF_OTG1_FS) ;

    RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
    RCC_AHB2PeriphClockCmd(RCC_AHB2Periph_OTG_FS, ENABLE) ;
#else // USE_USB_OTG_HS 

#ifdef USE_ULPI_PHY // ULPI
    RCC_AHB1PeriphClockCmd( RCC_AHB1Periph_GPIOA | RCC_AHB1Periph_GPIOB |
                            RCC_AHB1Periph_GPIOC | RCC_AHB1Periph_GPIOH |
                            RCC_AHB1Periph_GPIOE | RCC_AHB1Periph_GPIOI, ENABLE);


    GPIO_PinAFConfig(GPIOA,GPIO_PinSource3, GPIO_AF_OTG2_HS) ; // D0
    GPIO_PinAFConfig(GPIOA,GPIO_PinSource5, GPIO_AF_OTG2_HS) ; // CLK
    GPIO_PinAFConfig(GPIOB,GPIO_PinSource0, GPIO_AF_OTG2_HS) ; // D1
    GPIO_PinAFConfig(GPIOB,GPIO_PinSource1, GPIO_AF_OTG2_HS) ; // D2
    GPIO_PinAFConfig(GPIOB,GPIO_PinSource5, GPIO_AF_OTG2_HS) ; // D7
    GPIO_PinAFConfig(GPIOB,GPIO_PinSource10,GPIO_AF_OTG2_HS) ; // D3
    GPIO_PinAFConfig(GPIOB,GPIO_PinSource11,GPIO_AF_OTG2_HS) ; // D4
    GPIO_PinAFConfig(GPIOB,GPIO_PinSource12,GPIO_AF_OTG2_HS) ; // D5
    GPIO_PinAFConfig(GPIOB,GPIO_PinSource13,GPIO_AF_OTG2_HS) ; // D6
    GPIO_PinAFConfig(GPIOH,GPIO_PinSource4, GPIO_AF_OTG2_HS) ; // NXT
    GPIO_PinAFConfig(GPIOI,GPIO_PinSource11,GPIO_AF_OTG2_HS) ; // DIR
    GPIO_PinAFConfig(GPIOC,GPIO_PinSource0, GPIO_AF_OTG2_HS) ; // STP

    // CLK
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5 ;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
    GPIO_Init(GPIOA, &GPIO_InitStructure);

    // D0
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3  ;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
    GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;
    GPIO_Init(GPIOA, &GPIO_InitStructure);

    // D1 D2 D3 D4 D5 D6 D7
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1  |
                                  GPIO_Pin_5 | GPIO_Pin_10 |
                                  GPIO_Pin_11| GPIO_Pin_12 |
                                  GPIO_Pin_13 ;

    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
    GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;
    GPIO_Init(GPIOB, &GPIO_InitStructure);

    // STP
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0  ;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
    GPIO_Init(GPIOC, &GPIO_InitStructure);

    //NXT
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
    GPIO_Init(GPIOH, &GPIO_InitStructure);


    //DIR
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11 ;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
    GPIO_Init(GPIOI, &GPIO_InitStructure);

    //RST
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2 ;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
    GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;
    GPIO_Init(GPIOE, &GPIO_InitStructure);

    RCC_AHB1PeriphClockCmd( RCC_AHB1Periph_OTG_HS |
                            RCC_AHB1Periph_OTG_HS_ULPI, ENABLE) ;

    /* reset the ULPI_PHY */
    GPIO_ResetBits(GPIOE, GPIO_Pin_2);

    USB_OTG_BSP_uDelay(2000);

    GPIO_SetBits(GPIOE, GPIO_Pin_2);

#else
#ifdef USE_I2C_PHY
    RCC_AHB1PeriphClockCmd( RCC_AHB1Periph_GPIOB , ENABLE);
    /* Configure RESET INTN SCL SDA (Phy/I2C) Pins */
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 |
                                  GPIO_Pin_1 |
                                  GPIO_Pin_10 |
                                  GPIO_Pin_11;

    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
    GPIO_Init(GPIOB, &GPIO_InitStructure);

    GPIO_PinAFConfig(GPIOB,GPIO_PinSource0,GPIO_AF_OTG2_FS) ;
    GPIO_PinAFConfig(GPIOB,GPIO_PinSource1,GPIO_AF_OTG2_FS) ;
    GPIO_PinAFConfig(GPIOB,GPIO_PinSource10,GPIO_AF_OTG2_FS) ;
    GPIO_PinAFConfig(GPIOB,GPIO_PinSource11,GPIO_AF_OTG2_FS);
    RCC_AHB1PeriphClockCmd( RCC_AHB1Periph_OTG_HS, ENABLE) ;

#else

    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB , ENABLE);

    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12  |
                                  GPIO_Pin_13 |
                                  GPIO_Pin_14 |
                                  GPIO_Pin_15;

    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
    GPIO_Init(GPIOB, &GPIO_InitStructure);

    GPIO_PinAFConfig(GPIOB,GPIO_PinSource12, GPIO_AF_OTG2_FS) ;
    GPIO_PinAFConfig(GPIOB,GPIO_PinSource13,GPIO_AF_OTG2_FS) ;
    GPIO_PinAFConfig(GPIOB,GPIO_PinSource14,GPIO_AF_OTG2_FS) ;
    GPIO_PinAFConfig(GPIOB,GPIO_PinSource15,GPIO_AF_OTG2_FS) ;
    RCC_AHB1PeriphClockCmd( RCC_AHB1Periph_OTG_HS, ENABLE) ;
#endif
#endif // USE_ULPI_PHY

#endif //USB_OTG_HS
#endif //USE_STM3210C_EVAL 

#if 0  /**/
    /* enable the PWR clock */
    RCC_APB1PeriphResetCmd(RCC_APB1Periph_PWR, ENABLE);

    /* Configure the Key button in EXTI mode */
    STM_EVAL_PBInit(BUTTON_USER1, Mode_EXTI);
#ifdef USB_OTG_FS_LOW_PWR_MGMT_SUPPORT
    EXTI_ClearITPendingBit(EXTI_Line18);

    EXTI_InitStructure.EXTI_Line = EXTI_Line18;
    EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
    EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
    EXTI_InitStructure.EXTI_LineCmd = ENABLE;
    EXTI_Init(&EXTI_InitStructure);

    EXTI_ClearITPendingBit(EXTI_Line18);

    NVIC_InitStructure.NVIC_IRQChannel = OTG_FS_WKUP_IRQn;
    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
    NVIC_Init(&NVIC_InitStructure);

    EXTI_ClearITPendingBit(EXTI_Line18);
#endif

#ifdef USB_OTG_HS_LOW_PWR_MGMT_SUPPORT
    EXTI_ClearITPendingBit(EXTI_Line20);

    EXTI_InitStructure.EXTI_Line = EXTI_Line20;
    EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
    EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
    EXTI_InitStructure.EXTI_LineCmd = ENABLE;
    EXTI_Init(&EXTI_InitStructure);

    EXTI_ClearITPendingBit(EXTI_Line20);

    NVIC_InitStructure.NVIC_IRQChannel = OTG_HS_WKUP_IRQn;
    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;
    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;
    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
    NVIC_Init(&NVIC_InitStructure);

    EXTI_ClearITPendingBit(EXTI_Line20);
#endif

    EXTI_ClearITPendingBit(USER1_BUTTON_EXTI_LINE);
#endif
}