USBDevice for STM support
Dependents: Nucleo_Usb_JoyMouse Nucleo_usbmouse ELEC350_1-referral-2018-usb-hid USBJoystick_HelloWorld2_wip ... more
This library contains all mbed usb device library (mbed-os\features\unsupported\USBDevice).
USBDevice/TARGET_Silicon_Labs/src/em_usbhal.c@1:2a3ae13b45ef, 2016-12-15 (annotated)
- Committer:
- frq08711@LMECWL0871.LME.ST.COM
- Date:
- Thu Dec 15 17:40:59 2016 +0100
- Revision:
- 1:2a3ae13b45ef
copy of git hub directory unsupported/USBDevice
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 1 | /**************************************************************************//** |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 2 | * @file em_usbhal.c |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 3 | * @brief USB protocol stack library, low level USB peripheral access. |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 4 | * @version 3.20.14 |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 5 | ****************************************************************************** |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 6 | * @section License |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 7 | * <b>(C) Copyright 2014 Silicon Labs, http://www.silabs.com</b> |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 8 | ******************************************************************************* |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 9 | * |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 10 | * Licensed under the Apache License, Version 2.0 (the "License"); |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 11 | * you may not use this file except in compliance with the License. |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 12 | * You may obtain a copy of the License at |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 13 | * |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 14 | * http://www.apache.org/licenses/LICENSE-2.0 |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 15 | * |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 16 | * Unless required by applicable law or agreed to in writing, software |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 17 | * distributed under the License is distributed on an "AS IS" BASIS, |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 19 | * See the License for the specific language governing permissions and |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 20 | * limitations under the License. |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 21 | * |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 22 | ******************************************************************************/ |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 23 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 24 | #include "em_device.h" |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 25 | #if defined( USB_PRESENT ) && ( USB_COUNT == 1 ) |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 26 | #include "em_usb.h" |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 27 | #if defined( USB_DEVICE ) || defined( USB_HOST ) |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 28 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 29 | #include "em_usbtypes.h" |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 30 | #include "em_usbhal.h" |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 31 | #if defined( USB_DEVICE ) |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 32 | #include "em_usbd.h" |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 33 | #endif |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 34 | #if defined( USB_HOST ) |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 35 | #include "em_usbh.h" |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 36 | #endif |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 37 | #include "em_cmu.h" |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 38 | #include "em_gpio.h" |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 39 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 40 | /** @cond DO_NOT_INCLUDE_WITH_DOXYGEN */ |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 41 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 42 | #define EPABORT_BREAK_LOOP_COUNT 15000 /* Approx. 100 ms */ |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 43 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 44 | /* NOTE: The sequence of error message strings must agree with the */ |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 45 | /* definition of USB_Status_TypeDef enum. */ |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 46 | static const char * const errMsg[] = |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 47 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 48 | [ USB_STATUS_OK ] = "No errors", |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 49 | [ -USB_STATUS_REQ_ERR ] = "Setup request error", |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 50 | [ -USB_STATUS_EP_BUSY ] = "Endpoint is busy", |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 51 | [ -USB_STATUS_REQ_UNHANDLED ] = "Setup request not handled", |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 52 | [ -USB_STATUS_ILLEGAL ] = "Illegal operation attempted", |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 53 | [ -USB_STATUS_EP_STALLED ] = "Endpoint is stalled", |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 54 | [ -USB_STATUS_EP_ABORTED ] = "Transfer aborted", |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 55 | [ -USB_STATUS_EP_ERROR ] = "Transfer error", |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 56 | [ -USB_STATUS_EP_NAK ] = "Endpoint NAK", |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 57 | [ -USB_STATUS_DEVICE_UNCONFIGURED ] = "Device is not configured", |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 58 | [ -USB_STATUS_DEVICE_SUSPENDED ] = "Device is suspended", |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 59 | [ -USB_STATUS_DEVICE_RESET ] = "Device has been reset", |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 60 | [ -USB_STATUS_TIMEOUT ] = "Transfer timeout", |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 61 | [ -USB_STATUS_DEVICE_REMOVED ] = "Device removed", |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 62 | [ -USB_STATUS_HC_BUSY ] = "Host channel is busy", |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 63 | [ -USB_STATUS_DEVICE_MALFUNCTION ] = "Device malfunction", |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 64 | [ -USB_STATUS_PORT_OVERCURRENT ] = "VBUS overcurrent", |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 65 | }; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 66 | /** @endcond */ |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 67 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 68 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 69 | /***************************************************************************//** |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 70 | * @brief |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 71 | * Return an error message string for a given error code. |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 72 | * |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 73 | * @param[in] error |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 74 | * Error code, see \ref USB_Status_TypeDef. |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 75 | * |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 76 | * @return |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 77 | * Error message string pointer. |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 78 | ******************************************************************************/ |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 79 | char *USB_GetErrorMsgString( int error ) |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 80 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 81 | if ( error >= 0 ) |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 82 | return (char*)errMsg[ 0 ]; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 83 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 84 | return (char*)errMsg[ -error ]; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 85 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 86 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 87 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 88 | #if defined( USB_USE_PRINTF ) |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 89 | /***************************************************************************//** |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 90 | * @brief |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 91 | * Format and print a text string given an error code, prepends an optional user |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 92 | * supplied leader string. |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 93 | * |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 94 | * @param[in] pre |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 95 | * Optional leader string to prepend to error message string. |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 96 | * |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 97 | * @param[in] error |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 98 | * Error code, see \ref USB_Status_TypeDef. |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 99 | ******************************************************************************/ |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 100 | void USB_PrintErrorMsgString( char *pre, int error ) |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 101 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 102 | if ( pre ) |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 103 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 104 | USB_PRINTF( "%s", pre ); |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 105 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 106 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 107 | if ( error > USB_STATUS_OK ) |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 108 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 109 | USB_PRINTF( "%d", error ); |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 110 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 111 | else |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 112 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 113 | USB_PRINTF( "%s", USB_GetErrorMsgString( error ) ); |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 114 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 115 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 116 | #endif /* defined( USB_USE_PRINTF ) */ |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 117 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 118 | /** @cond DO_NOT_INCLUDE_WITH_DOXYGEN */ |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 119 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 120 | #if defined( DEBUG_EFM_USER ) |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 121 | static void PrintI( int i ) |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 122 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 123 | #if !defined ( USER_PUTCHAR ) |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 124 | (void)i; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 125 | #else |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 126 | if ( i >= 10 ) |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 127 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 128 | PrintI( i / 10 ); |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 129 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 130 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 131 | DEBUG_USB_API_PUTCHAR( ( i % 10 ) + '0' ); |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 132 | #endif |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 133 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 134 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 135 | void assertEFM( const char *file, int line ) |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 136 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 137 | #if !defined ( USER_PUTCHAR ) |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 138 | (void)file; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 139 | #endif |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 140 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 141 | DEBUG_USB_API_PUTS( "\nASSERT " ); |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 142 | DEBUG_USB_API_PUTS( file ); |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 143 | DEBUG_USB_API_PUTCHAR( ' ' ); |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 144 | PrintI( line ); |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 145 | for(;;){} |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 146 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 147 | #endif /* defined( DEBUG_EFM_USER ) */ |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 148 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 149 | #if defined ( USER_PUTCHAR ) |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 150 | void USB_Puts( const char *p ) |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 151 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 152 | while( *p ) |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 153 | USB_PUTCHAR( *p++ ); |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 154 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 155 | #endif /* defined ( USER_PUTCHAR ) */ |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 156 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 157 | void USBHAL_CoreReset( void ) |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 158 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 159 | USB->PCGCCTL &= ~USB_PCGCCTL_STOPPCLK; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 160 | USB->PCGCCTL &= ~(USB_PCGCCTL_PWRCLMP | USB_PCGCCTL_RSTPDWNMODULE); |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 161 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 162 | /* Core Soft Reset */ |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 163 | USB->GRSTCTL |= USB_GRSTCTL_CSFTRST; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 164 | while ( USB->GRSTCTL & USB_GRSTCTL_CSFTRST ) {} |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 165 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 166 | USBTIMER_DelayUs( 1 ); |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 167 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 168 | /* Wait for AHB master IDLE state. */ |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 169 | while ( !( USB->GRSTCTL & USB_GRSTCTL_AHBIDLE ) ) {} |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 170 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 171 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 172 | #ifdef USB_DEVICE |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 173 | void USBDHAL_Connect( void ) |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 174 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 175 | USB->DCTL &= ~( DCTL_WO_BITMASK | USB_DCTL_SFTDISCON ); |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 176 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 177 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 178 | USB_Status_TypeDef USBDHAL_CoreInit( uint32_t totalRxFifoSize, |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 179 | uint32_t totalTxFifoSize ) |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 180 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 181 | uint8_t i, j; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 182 | uint16_t start, depth; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 183 | USBD_Ep_TypeDef *ep; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 184 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 185 | #if !defined( USB_VBUS_SWITCH_NOT_PRESENT ) |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 186 | CMU_ClockEnable( cmuClock_GPIO, true ); |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 187 | GPIO_PinModeSet( gpioPortF, 5, gpioModePushPull, 0 ); /* Enable VBUSEN pin */ |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 188 | USB->ROUTE = USB_ROUTE_PHYPEN | USB_ROUTE_VBUSENPEN; /* Enable PHY pins. */ |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 189 | #else |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 190 | USB->ROUTE = USB_ROUTE_PHYPEN; /* Enable PHY pins. */ |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 191 | #endif |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 192 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 193 | USBHAL_CoreReset(); /* Reset USB core */ |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 194 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 195 | #if defined( USB_GUSBCFG_FORCEHSTMODE ) |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 196 | /* Force Device Mode */ |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 197 | USB->GUSBCFG = ( USB->GUSBCFG & |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 198 | ~(GUSBCFG_WO_BITMASK | USB_GUSBCFG_FORCEHSTMODE ) ) | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 199 | USB_GUSBCFG_FORCEDEVMODE; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 200 | #endif |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 201 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 202 | INT_Enable(); |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 203 | USBTIMER_DelayMs( 50 ); |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 204 | INT_Disable(); |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 205 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 206 | /* Set device speed */ |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 207 | USB->DCFG = ( USB->DCFG & ~_USB_DCFG_DEVSPD_MASK ) | 3; /* Full speed PHY */ |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 208 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 209 | /* Stall on non-zero len status OUT packets (ctrl transfers). */ |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 210 | USB->DCFG |= USB_DCFG_NZSTSOUTHSHK; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 211 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 212 | /* Set periodic frame interval to 80% */ |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 213 | USB->DCFG &= ~_USB_DCFG_PERFRINT_MASK; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 214 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 215 | USB->GAHBCFG = ( USB->GAHBCFG & ~_USB_GAHBCFG_HBSTLEN_MASK ) | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 216 | USB_GAHBCFG_DMAEN | USB_GAHBCFG_HBSTLEN_INCR; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 217 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 218 | /* Ignore frame numbers on ISO transfers. */ |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 219 | USB->DCTL = ( USB->DCTL & ~DCTL_WO_BITMASK ) | USB_DCTL_IGNRFRMNUM; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 220 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 221 | /* Set Rx FIFO size */ |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 222 | start = EFM32_MAX( totalRxFifoSize, MIN_EP_FIFO_SIZE_INWORDS ); |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 223 | USB->GRXFSIZ = ( start << _USB_GRXFSIZ_RXFDEP_SHIFT ) & |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 224 | _USB_GRXFSIZ_RXFDEP_MASK; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 225 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 226 | /* Set Tx EP0 FIFO size */ |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 227 | depth = EFM32_MAX( dev->ep[ 0 ].fifoSize, MIN_EP_FIFO_SIZE_INWORDS ); |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 228 | USB->GNPTXFSIZ = ( ( depth << _USB_GNPTXFSIZ_NPTXFINEPTXF0DEP_SHIFT ) & |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 229 | _USB_GNPTXFSIZ_NPTXFINEPTXF0DEP_MASK ) | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 230 | ( ( start << _USB_GNPTXFSIZ_NPTXFSTADDR_SHIFT ) & |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 231 | _USB_GNPTXFSIZ_NPTXFSTADDR_MASK ); |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 232 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 233 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 234 | /* Set Tx EP FIFO sizes for all IN ep's */ |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 235 | for ( j = 1; j <= MAX_NUM_TX_FIFOS; j++ ) |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 236 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 237 | for ( i = 1; i <= MAX_NUM_IN_EPS; i++ ) |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 238 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 239 | ep = USBD_GetEpFromAddr( USB_SETUP_DIR_MASK | i ); |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 240 | if ( ep ) /* Is EP in use ? */ |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 241 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 242 | if ( ep->txFifoNum == j ) /* Is it correct FIFO number ? */ |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 243 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 244 | start += depth; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 245 | depth = EFM32_MAX( ep->fifoSize, MIN_EP_FIFO_SIZE_INWORDS ); |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 246 | USB_DIEPTXFS[ ep->txFifoNum - 1 ] = |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 247 | ( depth << _USB_DIEPTXF1_INEPNTXFDEP_SHIFT ) | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 248 | ( start & _USB_DIEPTXF1_INEPNTXFSTADDR_MASK ); |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 249 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 250 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 251 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 252 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 253 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 254 | if ( totalRxFifoSize + totalTxFifoSize > MAX_DEVICE_FIFO_SIZE_INWORDS ) |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 255 | return USB_STATUS_ILLEGAL; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 256 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 257 | if ( start > MAX_DEVICE_FIFO_SIZE_INWORDS ) |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 258 | return USB_STATUS_ILLEGAL; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 259 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 260 | /* Flush the FIFO's */ |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 261 | USBHAL_FlushTxFifo( 0x10 ); /* All Tx FIFO's */ |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 262 | USBHAL_FlushRxFifo(); /* The Rx FIFO */ |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 263 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 264 | /* Disable all device interrupts */ |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 265 | USB->DIEPMSK = 0; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 266 | USB->DOEPMSK = 0; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 267 | USB->DAINTMSK = 0; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 268 | USB->DIEPEMPMSK = 0; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 269 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 270 | /* Disable all EP's, clear all EP ints. */ |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 271 | for ( i = 0; i <= MAX_NUM_IN_EPS; i++ ) |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 272 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 273 | USB_DINEPS[ i ].CTL = 0; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 274 | USB_DINEPS[ i ].TSIZ = 0; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 275 | USB_DINEPS[ i ].INT = 0xFFFFFFFF; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 276 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 277 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 278 | for ( i = 0; i <= MAX_NUM_OUT_EPS; i++ ) |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 279 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 280 | USB_DOUTEPS[ i ].CTL = 0; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 281 | USB_DOUTEPS[ i ].TSIZ = 0; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 282 | USB_DOUTEPS[ i ].INT = 0xFFFFFFFF; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 283 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 284 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 285 | #if ( USB_DCTL_SFTDISCON_DEFAULT != 0 ) |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 286 | USBD_Connect(); |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 287 | #endif |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 288 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 289 | /* Enable VREGO sense. */ |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 290 | USB->CTRL |= USB_CTRL_VREGOSEN; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 291 | USB->IFC = USB_IFC_VREGOSH | USB_IFC_VREGOSL; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 292 | USB->IEN = USB_IFC_VREGOSH | USB_IFC_VREGOSL; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 293 | /* Force a VREGO interrupt. */ |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 294 | if ( USB->STATUS & USB_STATUS_VREGOS) |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 295 | USB->IFS = USB_IFS_VREGOSH; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 296 | else |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 297 | USB->IFS = USB_IFS_VREGOSL; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 298 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 299 | return USB_STATUS_OK; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 300 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 301 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 302 | USB_Status_TypeDef USBDHAL_ReconfigureFifos( uint32_t totalRxFifoSize, |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 303 | uint32_t totalTxFifoSize ) |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 304 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 305 | uint8_t i, j; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 306 | uint16_t start, depth; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 307 | USBD_Ep_TypeDef *ep; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 308 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 309 | /* Set Rx FIFO size */ |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 310 | start = EFM32_MAX( totalRxFifoSize, MIN_EP_FIFO_SIZE_INWORDS ); |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 311 | USB->GRXFSIZ = ( start << _USB_GRXFSIZ_RXFDEP_SHIFT ) & |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 312 | _USB_GRXFSIZ_RXFDEP_MASK; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 313 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 314 | /* Set Tx EP0 FIFO size */ |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 315 | depth = EFM32_MAX( dev->ep[ 0 ].fifoSize, MIN_EP_FIFO_SIZE_INWORDS ); |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 316 | USB->GNPTXFSIZ = ( ( depth << _USB_GNPTXFSIZ_NPTXFINEPTXF0DEP_SHIFT ) & |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 317 | _USB_GNPTXFSIZ_NPTXFINEPTXF0DEP_MASK ) | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 318 | ( ( start << _USB_GNPTXFSIZ_NPTXFSTADDR_SHIFT ) & |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 319 | _USB_GNPTXFSIZ_NPTXFSTADDR_MASK ); |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 320 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 321 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 322 | /* Set Tx EP FIFO sizes for all IN ep's */ |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 323 | for ( j = 1; j <= MAX_NUM_TX_FIFOS; j++ ) |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 324 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 325 | for ( i = 1; i <= MAX_NUM_IN_EPS; i++ ) |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 326 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 327 | ep = USBD_GetEpFromAddr( USB_SETUP_DIR_MASK | i ); |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 328 | if ( ep ) /* Is EP in use ? */ |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 329 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 330 | if ( ep->txFifoNum == j ) /* Is it correct FIFO number ? */ |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 331 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 332 | start += depth; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 333 | depth = EFM32_MAX( ep->fifoSize, MIN_EP_FIFO_SIZE_INWORDS ); |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 334 | USB_DIEPTXFS[ ep->txFifoNum - 1 ] = |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 335 | ( depth << _USB_DIEPTXF1_INEPNTXFDEP_SHIFT ) | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 336 | ( start & _USB_DIEPTXF1_INEPNTXFSTADDR_MASK ); |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 337 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 338 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 339 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 340 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 341 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 342 | if ( totalRxFifoSize + totalTxFifoSize > MAX_DEVICE_FIFO_SIZE_INWORDS ) |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 343 | return USB_STATUS_ILLEGAL; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 344 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 345 | if ( start > MAX_DEVICE_FIFO_SIZE_INWORDS ) |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 346 | return USB_STATUS_ILLEGAL; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 347 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 348 | /* Flush the FIFO's */ |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 349 | USBHAL_FlushTxFifo( 0x10 ); /* All Tx FIFO's */ |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 350 | USBHAL_FlushRxFifo(); /* The Rx FIFO */ |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 351 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 352 | return USB_STATUS_OK; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 353 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 354 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 355 | void USBDHAL_Disconnect( void ) |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 356 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 357 | USB->DCTL = ( USB->DCTL & ~DCTL_WO_BITMASK ) | USB_DCTL_SFTDISCON; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 358 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 359 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 360 | void USBDHAL_AbortEpIn( USBD_Ep_TypeDef *ep ) |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 361 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 362 | /* Clear epdis & inepnakeff INT's */ |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 363 | USB_DINEPS[ ep->num ].INT |= USB_DIEP_INT_EPDISBLD | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 364 | USB_DIEP_INT_INEPNAKEFF; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 365 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 366 | /* Enable epdis & inepnakeff INT's */ |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 367 | USB->DIEPMSK |= USB_DIEPMSK_EPDISBLDMSK | USB_DIEPMSK_INEPNAKEFFMSK; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 368 | USB_DINEPS[ ep->num ].CTL = ( USB_DINEPS[ ep->num ].CTL & |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 369 | ~DEPCTL_WO_BITMASK ) | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 370 | USB_DIEP_CTL_SNAK; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 371 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 372 | /* Wait for inepnakeff INT */ |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 373 | while ( !( USBDHAL_GetInEpInts( ep ) & USB_DIEP_INT_INEPNAKEFF ) ) {} |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 374 | USB_DINEPS[ ep->num ].INT = USB_DIEP_INT_INEPNAKEFF; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 375 | USB->DIEPMSK &= ~USB_DIEPMSK_INEPNAKEFFMSK; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 376 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 377 | DEBUG_USB_INT_LO_PUTCHAR( '.' ); |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 378 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 379 | USBDHAL_SetEPDISNAK( ep ); |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 380 | /* Wait for epdis INT */ |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 381 | while ( !( USBDHAL_GetInEpInts( ep ) & USB_DIEP_INT_EPDISBLD ) ) {} |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 382 | USB_DINEPS[ ep->num ].INT = USB_DIEP_INT_EPDISBLD; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 383 | USB->DIEPMSK &= ~USB_DIEPMSK_EPDISBLDMSK; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 384 | USBHAL_FlushTxFifo( ep->txFifoNum ); |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 385 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 386 | /* Clear any interrupts generated by the abort sequence. */ |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 387 | NVIC_ClearPendingIRQ( USB_IRQn ); |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 388 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 389 | DEBUG_USB_INT_LO_PUTCHAR( '.' ); |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 390 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 391 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 392 | void USBDHAL_AbortEpOut( USBD_Ep_TypeDef *ep ) |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 393 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 394 | int cnt; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 395 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 396 | /* Clear epdis INT's */ |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 397 | USB_DOUTEPS[ ep->num ].INT |= USB_DOEP_INT_EPDISBLD; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 398 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 399 | /* Clear Global OUT NAK if already set */ |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 400 | USB->DCTL = ( USB->DCTL & ~DCTL_WO_BITMASK ) | USB_DCTL_CGOUTNAK; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 401 | USB->GINTMSK |= USB_GINTMSK_GOUTNAKEFFMSK; /* Enable GOUTNAKEFF int */ |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 402 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 403 | /* Set Global OUT NAK */ |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 404 | USB->DCTL = ( USB->DCTL & ~DCTL_WO_BITMASK ) | USB_DCTL_SGOUTNAK; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 405 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 406 | /* Wait for goutnakeff */ |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 407 | cnt = EPABORT_BREAK_LOOP_COUNT; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 408 | while ( !( USB->GINTSTS & USB_GINTSTS_GOUTNAKEFF ) && cnt ) |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 409 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 410 | cnt--; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 411 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 412 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 413 | USB->GINTMSK &= ~USB_GINTMSK_GOUTNAKEFFMSK; /* Disable GOUTNAKEFF int */ |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 414 | USB->DOEPMSK |= USB_DOEPMSK_EPDISBLDMSK; /* Enable EPDIS interrupt */ |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 415 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 416 | DEBUG_USB_INT_LO_PUTCHAR( ',' ); |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 417 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 418 | USBDHAL_SetEPDISNAK( ep ); /* Disable ep */ |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 419 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 420 | /* Wait for epdis INT */ |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 421 | cnt = EPABORT_BREAK_LOOP_COUNT; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 422 | while ( !( USBDHAL_GetOutEpInts( ep ) & USB_DOEP_INT_EPDISBLD ) && cnt ) |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 423 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 424 | cnt--; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 425 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 426 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 427 | USB_DOUTEPS[ ep->num ].INT = USB_DOEP_INT_EPDISBLD; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 428 | USB->DOEPMSK &= ~USB_DOEPMSK_EPDISBLDMSK; /* Disable EPDIS interrupt */ |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 429 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 430 | /* Clear Global OUT NAK */ |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 431 | USB->DCTL = ( USB->DCTL & ~DCTL_WO_BITMASK ) | USB_DCTL_CGOUTNAK; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 432 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 433 | /* Clear any interrupts generated by the abort sequence. */ |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 434 | NVIC_ClearPendingIRQ( USB_IRQn ); |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 435 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 436 | DEBUG_USB_INT_LO_PUTCHAR( ',' ); |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 437 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 438 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 439 | void USBDHAL_AbortAllEps( void ) |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 440 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 441 | int i, cnt; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 442 | USBD_Ep_TypeDef *ep; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 443 | uint16_t im, om, inmask=0, outmask=0; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 444 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 445 | /* Clear epdis & inepnakeff INT's */ |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 446 | for ( i = 1; i <= NUM_EP_USED; i++ ) |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 447 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 448 | ep = &dev->ep[i]; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 449 | if ( ep->state != D_EP_IDLE ) |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 450 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 451 | if ( ep->in ) |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 452 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 453 | inmask |= ep->mask; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 454 | USB_DINEPS[ ep->num ].INT |= USB_DIEP_INT_EPDISBLD | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 455 | USB_DIEP_INT_INEPNAKEFF; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 456 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 457 | else |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 458 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 459 | outmask |= ep->mask; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 460 | USB_DOUTEPS[ ep->num ].INT |= USB_DOEP_INT_EPDISBLD; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 461 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 462 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 463 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 464 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 465 | if ( inmask ) |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 466 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 467 | /* Enable epdis & inepnakeff INT's */ |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 468 | USB->DIEPMSK |= USB_DIEPMSK_EPDISBLDMSK | USB_DIEPMSK_INEPNAKEFFMSK; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 469 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 470 | /* Set NAK on all IN ep's */ |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 471 | im = inmask; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 472 | for ( i = 1; i <= NUM_EP_USED; i++ ) |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 473 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 474 | ep = &dev->ep[i]; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 475 | if ( im & ep->mask ) |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 476 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 477 | USB_DINEPS[ ep->num ].CTL = ( USB_DINEPS[ ep->num ].CTL & |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 478 | ~DEPCTL_WO_BITMASK ) | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 479 | USB_DIEP_CTL_SNAK; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 480 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 481 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 482 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 483 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 484 | if ( outmask ) |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 485 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 486 | /* Clear Global OUT NAK if already set */ |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 487 | USB->DCTL = ( USB->DCTL & ~DCTL_WO_BITMASK ) | USB_DCTL_CGOUTNAK; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 488 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 489 | USB->GINTMSK |= USB_GINTMSK_GOUTNAKEFFMSK; /* Enable GOUTNAKEFF int */ |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 490 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 491 | /* Set Global OUT NAK */ |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 492 | USB->DCTL = ( USB->DCTL & ~DCTL_WO_BITMASK ) | USB_DCTL_SGOUTNAK; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 493 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 494 | /* Wait for goutnakeff */ |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 495 | cnt = EPABORT_BREAK_LOOP_COUNT; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 496 | while ( !( USB->GINTSTS & USB_GINTSTS_GOUTNAKEFF ) && cnt ) |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 497 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 498 | cnt--; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 499 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 500 | USB->GINTMSK &= ~USB_GINTMSK_GOUTNAKEFFMSK; /* Disable GOUTNAKEFF int */ |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 501 | USB->DOEPMSK |= USB_DOEPMSK_EPDISBLDMSK; /* Enable EPDIS interrupt */ |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 502 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 503 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 504 | if ( inmask ) |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 505 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 506 | /* Wait for inepnakeff INT on all IN ep's */ |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 507 | im = inmask; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 508 | cnt = EPABORT_BREAK_LOOP_COUNT; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 509 | do |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 510 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 511 | for ( i = 1; i <= NUM_EP_USED; i++ ) |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 512 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 513 | ep = &dev->ep[i]; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 514 | if ( im & ep->mask ) |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 515 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 516 | if ( USBDHAL_GetInEpInts( ep ) & USB_DIEP_INT_INEPNAKEFF ) |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 517 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 518 | USB_DINEPS[ ep->num ].INT = USB_DIEP_INT_INEPNAKEFF; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 519 | im &= ~ep->mask; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 520 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 521 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 522 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 523 | cnt--; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 524 | } while ( im && cnt ); |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 525 | USB->DIEPMSK &= ~USB_DIEPMSK_INEPNAKEFFMSK; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 526 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 527 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 528 | DEBUG_USB_INT_LO_PUTCHAR( '\'' ); |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 529 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 530 | /* Disable ep's */ |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 531 | for ( i = 1; i <= NUM_EP_USED; i++ ) |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 532 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 533 | ep = &dev->ep[i]; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 534 | if ( ep->state != D_EP_IDLE ) |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 535 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 536 | USBDHAL_SetEPDISNAK( ep ); |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 537 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 538 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 539 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 540 | /* Wait for epdis INT */ |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 541 | im = inmask; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 542 | om = outmask; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 543 | cnt = EPABORT_BREAK_LOOP_COUNT; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 544 | do |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 545 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 546 | for ( i = 1; i <= NUM_EP_USED; i++ ) |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 547 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 548 | ep = &dev->ep[i]; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 549 | if ( ep->in && ( im & ep->mask ) ) |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 550 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 551 | if ( USBDHAL_GetInEpInts( ep ) & USB_DIEP_INT_EPDISBLD ) |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 552 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 553 | USB_DINEPS[ ep->num ].INT = USB_DIEP_INT_EPDISBLD; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 554 | im &= ~ep->mask; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 555 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 556 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 557 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 558 | if ( !ep->in && ( om & ep->mask ) ) |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 559 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 560 | if ( USBDHAL_GetOutEpInts( ep ) & USB_DOEP_INT_EPDISBLD ) |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 561 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 562 | USB_DOUTEPS[ ep->num ].INT = USB_DOEP_INT_EPDISBLD; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 563 | om &= ~ep->mask; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 564 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 565 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 566 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 567 | cnt--; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 568 | } while ( ( im || om ) && cnt ); |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 569 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 570 | if ( inmask ) |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 571 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 572 | USB->DIEPMSK &= ~USB_DIEPMSK_EPDISBLDMSK; /* Disable EPDIS interrupt */ |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 573 | USBHAL_FlushTxFifo( 0x10 ); /* Flush all Tx FIFO's */ |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 574 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 575 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 576 | if ( outmask ) |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 577 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 578 | USB->DOEPMSK &= ~USB_DOEPMSK_EPDISBLDMSK; /* Disable EPDIS interrupt */ |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 579 | /* Clear Global OUT NAK */ |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 580 | USB->DCTL = ( USB->DCTL & ~DCTL_WO_BITMASK ) | USB_DCTL_CGOUTNAK; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 581 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 582 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 583 | DEBUG_USB_INT_LO_PUTCHAR( '\'' ); |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 584 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 585 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 586 | void USBDHAL_AbortAllTransfers( USB_Status_TypeDef reason ) |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 587 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 588 | int i; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 589 | USBD_Ep_TypeDef *ep; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 590 | USB_XferCompleteCb_TypeDef callback; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 591 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 592 | if ( reason != USB_STATUS_DEVICE_RESET ) |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 593 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 594 | USBDHAL_AbortAllEps(); |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 595 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 596 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 597 | for ( i = 1; i <= NUM_EP_USED; i++ ) |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 598 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 599 | ep = &(dev->ep[i]); |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 600 | if ( ep->state != D_EP_IDLE ) |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 601 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 602 | ep->state = D_EP_IDLE; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 603 | if ( ep->xferCompleteCb ) |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 604 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 605 | callback = ep->xferCompleteCb; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 606 | ep->xferCompleteCb = NULL; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 607 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 608 | if ( ( dev->lastState == USBD_STATE_CONFIGURED ) && |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 609 | ( dev->state == USBD_STATE_ADDRESSED ) ) |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 610 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 611 | USBDHAL_DeactivateEp( ep ); |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 612 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 613 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 614 | DEBUG_TRACE_ABORT( reason ); |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 615 | callback( reason, ep->xferred, ep->remaining ); |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 616 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 617 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 618 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 619 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 620 | /* Clear any interrupts generated by the abort sequence. */ |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 621 | NVIC_ClearPendingIRQ( USB_IRQn ); |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 622 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 623 | #endif /* defined( USB_DEVICE ) */ |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 624 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 625 | #if defined( USB_HOST ) |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 626 | USB_Status_TypeDef USBHHAL_CoreInit( uint32_t rxFifoSize, |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 627 | uint32_t nptxFifoSize, |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 628 | uint32_t ptxFifoSize ) |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 629 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 630 | uint8_t i; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 631 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 632 | rxFifoSize /= 4; /* Convert from byte count to word count. */ |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 633 | nptxFifoSize /= 4; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 634 | ptxFifoSize /= 4; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 635 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 636 | CMU_ClockEnable( cmuClock_GPIO, true ); |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 637 | GPIO_PinModeSet( gpioPortF, 5, gpioModePushPull, 0 ); /* Enable VBUSEN pin */ |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 638 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 639 | #if ( USB_VBUSOVRCUR_PORT != USB_VBUSOVRCUR_PORT_NONE ) |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 640 | /* Enable VBUS overcurrent flag pin. */ |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 641 | GPIO_PinModeSet( USB_VBUSOVRCUR_PORT, USB_VBUSOVRCUR_PIN, gpioModeInput, 0 ); |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 642 | #endif |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 643 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 644 | USB->ROUTE = USB_ROUTE_PHYPEN | USB_ROUTE_VBUSENPEN; /* Enable PHY pins. */ |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 645 | USBHAL_CoreReset(); /* Reset USB core */ |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 646 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 647 | /* Force Host Mode */ |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 648 | USB->GUSBCFG = ( USB->GUSBCFG & |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 649 | ~(GUSBCFG_WO_BITMASK | USB_GUSBCFG_FORCEDEVMODE ) ) | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 650 | USB_GUSBCFG_FORCEHSTMODE; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 651 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 652 | INT_Enable(); |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 653 | USBTIMER_DelayMs( 100 ); |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 654 | INT_Disable(); |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 655 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 656 | /* Set 48 MHz PHY clock, FS/LS mode */ |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 657 | USB->HCFG = ( USB->HCFG & ~_USB_HCFG_FSLSPCLKSEL_MASK ) | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 658 | ( 1 << _USB_HCFG_FSLSPCLKSEL_SHIFT ) | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 659 | ( USB_HCFG_FSLSSUPP ); |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 660 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 661 | USB->GAHBCFG = ( USB->GAHBCFG & ~_USB_GAHBCFG_HBSTLEN_MASK ) | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 662 | USB_GAHBCFG_DMAEN | USB_GAHBCFG_HBSTLEN_INCR; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 663 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 664 | /* Set Rx FIFO size */ |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 665 | USB->GRXFSIZ = ( rxFifoSize << _USB_GRXFSIZ_RXFDEP_SHIFT ) & |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 666 | _USB_GRXFSIZ_RXFDEP_MASK; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 667 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 668 | /* Set Tx FIFO sizes */ |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 669 | USB->GNPTXFSIZ = ( ( nptxFifoSize << |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 670 | _USB_GNPTXFSIZ_NPTXFINEPTXF0DEP_SHIFT ) & |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 671 | _USB_GNPTXFSIZ_NPTXFINEPTXF0DEP_MASK ) | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 672 | ( ( rxFifoSize << |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 673 | _USB_GNPTXFSIZ_NPTXFSTADDR_SHIFT ) & |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 674 | _USB_GNPTXFSIZ_NPTXFSTADDR_MASK ); |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 675 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 676 | USB->HPTXFSIZ = ( ( ptxFifoSize << _USB_HPTXFSIZ_PTXFSIZE_SHIFT ) & |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 677 | _USB_HPTXFSIZ_PTXFSIZE_MASK ) | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 678 | ( ( ( rxFifoSize + nptxFifoSize ) |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 679 | << _USB_HPTXFSIZ_PTXFSTADDR_SHIFT ) & |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 680 | _USB_HPTXFSIZ_PTXFSTADDR_MASK ); |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 681 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 682 | /* Flush Tx and Rx FIFO's */ |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 683 | USBHAL_FlushTxFifo( 0x10 ); |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 684 | USBHAL_FlushRxFifo(); |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 685 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 686 | for ( i = 0; i < MAX_NUM_HOSTCHANNELS; i++ ) |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 687 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 688 | USB->HC[ i ].CHAR = USB_HC_CHAR_CHDIS; /* Disable channel */ |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 689 | USB->HC[ i ].INT = 0xFFFFFFFF; /* Clear pending interrupts */ |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 690 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 691 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 692 | /* Enable and halt all channels */ |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 693 | for ( i = 0; i < MAX_NUM_HOSTCHANNELS; i++ ) |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 694 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 695 | USB->HC[ i ].CHAR |= USB_HC_CHAR_CHDIS | USB_HC_CHAR_CHENA; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 696 | do |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 697 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 698 | __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 699 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 700 | while ( USB->HC[ i ].CHAR & USB_HC_CHAR_CHENA ); |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 701 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 702 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 703 | /* Disable all interrupts */ |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 704 | for ( i = 0; i < MAX_NUM_HOSTCHANNELS; i++ ) |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 705 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 706 | USB->HC[ i ].INTMSK = 0; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 707 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 708 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 709 | USB->HAINTMSK = 0; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 710 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 711 | return USB_STATUS_OK; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 712 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 713 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 714 | void USBHHAL_HCHalt( int hcnum, uint32_t hcchar ) |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 715 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 716 | hcchar |= USB_HC_CHAR_CHENA | USB_HC_CHAR_CHDIS; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 717 | USB->HC[ hcnum ].CHAR = hcchar; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 718 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 719 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 720 | void USBHHAL_HCInit( int hcnum ) |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 721 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 722 | USBH_Ep_TypeDef *ep; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 723 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 724 | ep = hcs[ hcnum ].ep; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 725 | USB->HC[ hcnum ].INT = 0xFFFFFFFF; /* Clear all interrupt flags */ |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 726 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 727 | switch ( ep->type ) /* Enable host channel int. types */ |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 728 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 729 | case USB_EPTYPE_CTRL: |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 730 | case USB_EPTYPE_BULK: |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 731 | case USB_EPTYPE_INTR: |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 732 | USB->HC[ hcnum ].INTMSK = USB_HC_INT_CHHLTD; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 733 | break; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 734 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 735 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 736 | hcs[ hcnum ].errorCnt = 0; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 737 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 738 | USB->HAINTMSK |= 1 << hcnum; /* Enable host channel interrupt */ |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 739 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 740 | USB->HC[ hcnum ].CHAR = /* Program HCCHAR register */ |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 741 | ( ep->parentDevice->addr << _USB_HC_CHAR_DEVADDR_SHIFT ) | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 742 | ( ( ep->addr & USB_EPNUM_MASK ) << _USB_HC_CHAR_EPNUM_SHIFT ) | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 743 | ( ep->type << _USB_HC_CHAR_EPTYPE_SHIFT ) | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 744 | ( ep->packetSize << _USB_HC_CHAR_MPS_SHIFT ) | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 745 | ( ep->in ? USB_HC_CHAR_EPDIR : 0 ) | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 746 | ( ep->parentDevice->speed == |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 747 | HPRT_L_SPEED >> _USB_HPRT_PRTSPD_SHIFT |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 748 | ? USB_HC_CHAR_LSPDDEV : 0 ); |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 749 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 750 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 751 | void USBHHAL_HCStart( int hcnum ) |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 752 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 753 | USBH_Hc_TypeDef *hc; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 754 | uint16_t packets, len; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 755 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 756 | hc = &hcs[ hcnum ]; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 757 | hc->status = 0; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 758 | hc->idle = false; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 759 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 760 | if ( hc->remaining > 0 ) |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 761 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 762 | packets = ( hc->remaining + hc->ep->packetSize - 1 ) / hc->ep->packetSize; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 763 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 764 | else |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 765 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 766 | packets = 1; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 767 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 768 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 769 | if ( hc->ep->in ) |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 770 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 771 | len = packets * hc->ep->packetSize; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 772 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 773 | else |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 774 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 775 | len = hc->remaining; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 776 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 777 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 778 | /* Initialize the HCTSIZn register */ |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 779 | hc->hwXferSize = len; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 780 | USB->HC[ hcnum ].TSIZ = |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 781 | ( ( len << _USB_HC_TSIZ_XFERSIZE_SHIFT ) & |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 782 | _USB_HC_TSIZ_XFERSIZE_MASK ) | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 783 | ( ( packets << _USB_HC_TSIZ_PKTCNT_SHIFT ) & |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 784 | _USB_HC_TSIZ_PKTCNT_MASK ) | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 785 | ( ( hc->ep->toggle << _USB_HC_TSIZ_PID_SHIFT ) & |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 786 | _USB_HC_TSIZ_PID_MASK ); |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 787 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 788 | USB->HC[ hcnum ].DMAADDR = (uint32_t)hc->buf; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 789 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 790 | USBHHAL_HCActivate( hcnum, |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 791 | USB->HC[ hcnum ].CHAR, |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 792 | hc->ep->type == USB_EPTYPE_INTR ); |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 793 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 794 | #endif /* defined( USB_HOST ) */ |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 795 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 796 | /** @endcond */ |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 797 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 798 | #endif /* defined( USB_DEVICE ) || defined( USB_HOST ) */ |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 799 | #endif /* defined( USB_PRESENT ) && ( USB_COUNT == 1 ) */ |