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).

Committer:
frq08711@LMECWL0871.LME.ST.COM
Date:
Tue Mar 28 11:00:57 2017 +0200
Branch:
master
Revision:
4:50ec00aa4515
Parent:
1:2a3ae13b45ef
update for 5.4.2

Who changed what in which revision?

UserRevisionLine numberNew contents of line
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 1 /**************************************************************************//**
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 2 * @file em_usbdint.c
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 3 * @brief USB protocol stack library, USB device peripheral interrupt handlers.
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 )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 28
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 29 #include "em_cmu.h"
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 30 #include "em_usbtypes.h"
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 31 #include "em_usbhal.h"
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 32 #include "em_usbd.h"
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 33
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 34 #ifdef __MBED__
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 35 extern void usbhal_allow_em2(bool em2_allow);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 36 #endif
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 37
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 38 /** @cond DO_NOT_INCLUDE_WITH_DOXYGEN */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 39
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 40 #define HANDLE_INT( x ) if ( status & x ) { Handle_##x(); status &= ~x; }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 41
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 42 static void Handle_USB_GINTSTS_ENUMDONE ( void );
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 43 static void Handle_USB_GINTSTS_IEPINT ( void );
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 44 static void Handle_USB_GINTSTS_OEPINT ( void );
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 45 static void Handle_USB_GINTSTS_RESETDET ( void );
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 46 static void Handle_USB_GINTSTS_SOF ( void );
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 47 static void Handle_USB_GINTSTS_USBRST ( void );
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 48 static void Handle_USB_GINTSTS_USBSUSP ( void );
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 49 static void Handle_USB_GINTSTS_WKUPINT ( void );
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 50 #if defined( USB_DOEP0INT_STUPPKTRCVD )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 51 static void HandleOutEpIntr( uint32_t status, USBD_Ep_TypeDef *ep );
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 52 #else
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 53 static void ProcessSetup ( void );
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 54 static void ProcessOepData ( USBD_Ep_TypeDef *ep );
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 55 #endif
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 56
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 57 #if ( USB_PWRSAVE_MODE )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 58 /* Variables and prototypes for USB powerdown (suspend) functionality. */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 59 static bool UsbPowerDown( void );
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 60 static bool UsbPowerUp( void );
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 61
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 62 volatile bool USBD_poweredDown = false;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 63
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 64 /* Storage for backing up USB core registers. */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 65 static uint32_t x_USB_GINTMSK;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 66 #if defined(_USB_GOTGCTL_MASK)
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 67 static uint32_t x_USB_GOTGCTL;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 68 #endif
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 69 static uint32_t x_USB_GAHBCFG;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 70 static uint32_t x_USB_GUSBCFG;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 71 static uint32_t x_USB_GRXFSIZ;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 72 static uint32_t x_USB_GNPTXFSIZ;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 73 static uint32_t x_USB_DCFG;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 74 static uint32_t x_USB_DCTL;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 75 static uint32_t x_USB_DAINTMSK;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 76 static uint32_t x_USB_DIEPMSK;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 77 static uint32_t x_USB_DOEPMSK;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 78 static uint32_t x_USB_PCGCCTL;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 79
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 80 #if ( NUM_EP_USED > 0 )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 81 static uint32_t x_USB_EP_CTL[ NUM_EP_USED ];
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 82 static uint32_t x_USB_EP_TSIZ[ NUM_EP_USED ];
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 83 static uint32_t x_USB_EP_DMAADDR[ NUM_EP_USED ];
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 84 #endif
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 85
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 86 #if ( NUM_EP_USED > MAX_NUM_TX_FIFOS )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 87 #define FIFO_CNT MAX_NUM_TX_FIFOS
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 88 #else
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 89 #define FIFO_CNT NUM_EP_USED
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 90 #endif
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 91
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 92 #if ( FIFO_CNT > 0 )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 93 static uint32_t x_USB_DIEPTXFS[ FIFO_CNT ];
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 94 #endif
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 95
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 96 #if ( USB_PWRSAVE_MODE )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 97 static uint32_t cmuStatus = 0;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 98 #endif
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 99
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 100 #endif /* if ( USB_PWRSAVE_MODE ) */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 101
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 102 /*
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 103 * USB_IRQHandler() is the first level handler for the USB peripheral interrupt.
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 104 */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 105 void USB_IRQHandler( void )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 106 {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 107 uint32_t status;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 108 bool servedVbusInterrupt = false;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 109
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 110 INT_Disable();
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 111
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 112 #if ( USB_PWRSAVE_MODE )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 113 if ( USBD_poweredDown )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 114 {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 115 /* Switch USBC clock from 32kHz to a 48MHz clock to be able to */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 116 /* read USB peripheral registers. */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 117 /* If we woke up from EM2, HFCLK is now HFRCO. */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 118
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 119 /* Restore clock oscillators.*/
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 120 #if defined( CMU_OSCENCMD_USHFRCOEN )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 121 if ( ( CMU->STATUS & CMU_STATUS_USHFRCOENS ) == 0 )/*Wakeup from EM2 ?*/
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 122 {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 123 CMU->OSCENCMD = ( cmuStatus
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 124 & ( CMU_STATUS_AUXHFRCOENS | CMU_STATUS_HFXOENS ) )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 125 | CMU_OSCENCMD_USHFRCOEN;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 126 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 127 #else
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 128 if ( ( CMU->STATUS & CMU_STATUS_HFXOENS ) == 0 ) /* Wakeup from EM2 ? */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 129 {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 130 CMU->OSCENCMD = cmuStatus
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 131 & ( CMU_STATUS_AUXHFRCOENS | CMU_STATUS_HFXOENS );
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 132 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 133 #endif
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 134
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 135 /* Select correct USBC clock.*/
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 136 #if defined( CMU_OSCENCMD_USHFRCOEN )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 137 CMU->CMD = CMU_CMD_USBCCLKSEL_USHFRCO;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 138 while ( ( CMU->STATUS & CMU_STATUS_USBCUSHFRCOSEL ) == 0 ){}
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 139 #else
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 140 CMU->CMD = CMU_CMD_USBCCLKSEL_HFCLKNODIV;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 141 while ( ( CMU->STATUS & CMU_STATUS_USBCHFCLKSEL ) == 0 ){}
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 142 #endif
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 143 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 144 #endif /* if ( USB_PWRSAVE_MODE ) */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 145
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 146 if ( USB->IF && ( USB->CTRL & USB_CTRL_VREGOSEN ) )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 147 {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 148 if ( USB->IF & USB_IF_VREGOSH )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 149 {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 150 USB->IFC = USB_IFC_VREGOSH;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 151
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 152 if ( USB->STATUS & USB_STATUS_VREGOS )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 153 {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 154 servedVbusInterrupt = true;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 155 DEBUG_USB_INT_LO_PUTS( "\nVboN" );
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 156
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 157 #if ( USB_PWRSAVE_MODE )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 158 if ( UsbPowerUp() )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 159 {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 160 USBDHAL_EnableUsbResetAndSuspendInt();
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 161 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 162 USBD_SetUsbState( USBD_STATE_POWERED );
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 163 #endif
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 164 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 165 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 166
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 167 if ( USB->IF & USB_IF_VREGOSL )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 168 {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 169 USB->IFC = USB_IFC_VREGOSL;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 170
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 171 if ( ( USB->STATUS & USB_STATUS_VREGOS ) == 0 )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 172 {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 173 servedVbusInterrupt = true;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 174 DEBUG_USB_INT_LO_PUTS( "\nVboF" );
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 175
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 176 #if ( USB_PWRSAVE_MODE )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 177 #if ( USB_PWRSAVE_MODE & USB_PWRSAVE_MODE_ONVBUSOFF )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 178 if ( !USBD_poweredDown )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 179 {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 180 USB->GINTMSK = 0;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 181 USB->GINTSTS = 0xFFFFFFFF;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 182 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 183
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 184 UsbPowerDown();
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 185 #endif
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 186 USBD_SetUsbState( USBD_STATE_NONE );
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 187 #endif
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 188 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 189 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 190 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 191
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 192 status = USBHAL_GetCoreInts();
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 193 if ( status == 0 )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 194 {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 195 INT_Enable();
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 196 if ( !servedVbusInterrupt )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 197 {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 198 DEBUG_USB_INT_LO_PUTS( "\nSinT" );
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 199 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 200 return;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 201 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 202
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 203 HANDLE_INT( USB_GINTSTS_RESETDET )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 204 HANDLE_INT( USB_GINTSTS_WKUPINT )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 205 HANDLE_INT( USB_GINTSTS_USBSUSP )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 206 HANDLE_INT( USB_GINTSTS_SOF )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 207 HANDLE_INT( USB_GINTSTS_ENUMDONE )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 208 HANDLE_INT( USB_GINTSTS_USBRST )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 209 HANDLE_INT( USB_GINTSTS_IEPINT )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 210 HANDLE_INT( USB_GINTSTS_OEPINT )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 211
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 212 INT_Enable();
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 213
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 214 if ( status != 0 )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 215 {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 216 DEBUG_USB_INT_LO_PUTS( "\nUinT" );
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 217 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 218 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 219
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 220 /*
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 221 * Handle port enumeration interrupt. This has nothing to do with normal
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 222 * device enumeration.
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 223 */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 224 static void Handle_USB_GINTSTS_ENUMDONE( void )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 225 {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 226 #if ( USB_PWRSAVE_MODE )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 227 UsbPowerUp();
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 228 #endif
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 229
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 230 USBDHAL_Ep0Activate( dev->ep0MpsCode );
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 231 dev->ep[ 0 ].state = D_EP_IDLE;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 232 USBDHAL_EnableInts( dev );
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 233 DEBUG_USB_INT_LO_PUTS( "EnumD" );
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 234 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 235
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 236 /*
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 237 * Handle IN endpoint transfer interrupt.
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 238 */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 239 static void Handle_USB_GINTSTS_IEPINT( void )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 240 {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 241 int epnum;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 242 uint16_t epint;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 243 uint16_t epmask;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 244 uint32_t status;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 245 USBD_Ep_TypeDef *ep;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 246
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 247 DEBUG_USB_INT_HI_PUTCHAR( 'i' );
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 248
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 249 epint = USBDHAL_GetAllInEpInts();
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 250 for ( epnum = 0, epmask = 1;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 251 epnum <= MAX_NUM_IN_EPS;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 252 epnum++, epmask <<= 1 )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 253 {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 254 if ( epint & epmask )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 255 {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 256 ep = USBD_GetEpFromAddr( USB_SETUP_DIR_MASK | epnum );
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 257 status = USBDHAL_GetInEpInts( ep );
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 258
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 259 if ( status & USB_DIEP_INT_XFERCOMPL )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 260 {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 261 USB_DINEPS[ epnum ].INT = USB_DIEP_INT_XFERCOMPL;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 262
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 263 DEBUG_USB_INT_HI_PUTCHAR( 'c' );
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 264
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 265 if ( epnum == 0 )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 266 {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 267 if ( ep->remaining > ep->packetSize )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 268 {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 269 ep->remaining -= ep->packetSize;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 270 ep->xferred += ep->packetSize;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 271 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 272 else
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 273 {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 274 ep->xferred += ep->remaining;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 275 ep->remaining = 0;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 276 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 277 USBDEP_Ep0Handler( dev );
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 278 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 279 else
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 280 {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 281 ep->xferred = ep->remaining -
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 282 ( ( USB_DINEPS[ epnum ].TSIZ &
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 283 _USB_DIEP_TSIZ_XFERSIZE_MASK ) >>
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 284 _USB_DIEP_TSIZ_XFERSIZE_SHIFT );
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 285 ep->remaining -= ep->xferred;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 286
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 287 USBDEP_EpHandler( ep->addr );
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 288 #if defined( USB_DOEP0INT_STUPPKTRCVD )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 289 if ( USB_DINEPS[ ep->num ].INT & USB_DIEP_INT_NAKINTRPT )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 290 {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 291 USB_DINEPS[ ep->num ].INT = USB_DIEP_INT_NAKINTRPT;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 292 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 293 #endif
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 294 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 295 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 296 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 297 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 298 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 299
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 300 /*
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 301 * Handle OUT endpoint transfer interrupt.
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 302 */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 303 static void Handle_USB_GINTSTS_OEPINT( void )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 304 {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 305 int epnum;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 306 uint16_t epint;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 307 uint16_t epmask;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 308 uint32_t status;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 309 USBD_Ep_TypeDef *ep;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 310
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 311 DEBUG_USB_INT_HI_PUTCHAR( 'o' );
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 312
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 313 epint = USBDHAL_GetAllOutEpInts();
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 314 for ( epnum = 0, epmask = 1;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 315 epnum <= MAX_NUM_OUT_EPS;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 316 epnum++, epmask <<= 1 )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 317 {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 318 if ( epint & epmask )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 319 {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 320 ep = USBD_GetEpFromAddr( epnum );
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 321 status = USBDHAL_GetOutEpInts( ep );
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 322
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 323 #if defined( USB_DOEP0INT_STUPPKTRCVD )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 324 HandleOutEpIntr( status, ep );
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 325 #else
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 326 if ( status & USB_DOEP_INT_XFERCOMPL )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 327 {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 328 USB_DOUTEPS[ epnum ].INT = USB_DOEP_INT_XFERCOMPL;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 329 DEBUG_USB_INT_HI_PUTCHAR( 'c' );
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 330 ProcessOepData( ep );
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 331 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 332
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 333 /* Setup Phase Done */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 334 if ( status & USB_DOEP0INT_SETUP )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 335 {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 336 ProcessSetup();
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 337 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 338 #endif
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
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 343 #if !defined( USB_DOEP0INT_STUPPKTRCVD )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 344 static void ProcessOepData( USBD_Ep_TypeDef *ep )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 345 {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 346 if ( ep->num == 0 )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 347 {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 348
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 349 #ifdef __MBED__
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 350 int xfer_size = ep->packetSize - (( USB->DOEP0TSIZ & _USB_DOEP0TSIZ_XFERSIZE_MASK )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 351 >> _USB_DOEP0TSIZ_XFERSIZE_SHIFT);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 352 int setup_pkt_received = USBDHAL_GetOutEpInts( ep ) & USB_DOEP0INT_SETUP;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 353
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 354 if ( (!setup_pkt_received && xfer_size == 0) ||
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 355 (setup_pkt_received && xfer_size == 8) )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 356 {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 357 /* Higher levels need to see the correct transfer amount for ZLPs */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 358 ep->remaining = 0;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 359 ep->xferred = 0;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 360 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 361 else
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 362 {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 363 /* FIXME - does not work if actual read size > 56 */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 364 if ( setup_pkt_received ) xfer_size -= 8;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 365
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 366 ep->xferred = xfer_size;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 367 ep->remaining -= xfer_size;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 368 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 369 #else
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 370 if ( ep->remaining > ep->packetSize )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 371 {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 372 ep->remaining -= ep->packetSize;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 373 ep->xferred += ep->packetSize;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 374 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 375 else
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 376 {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 377 ep->xferred += ep->remaining;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 378 ep->remaining = 0;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 379 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 380 #endif
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 381
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 382 USBDEP_Ep0Handler( dev );
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 383 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 384 else
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 385 {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 386 ep->xferred = ep->hwXferSize -
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 387 ( ( USB_DOUTEPS[ ep->num ].TSIZ & _USB_DOEP_TSIZ_XFERSIZE_MASK )>>
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 388 _USB_DOEP_TSIZ_XFERSIZE_SHIFT );
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 389 ep->remaining -= ep->xferred;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 390 USBDEP_EpHandler( ep->addr );
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 391 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 392 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 393 #endif
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 394
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 395 #if !defined( USB_DOEP0INT_STUPPKTRCVD )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 396 static void ProcessSetup( void )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 397 {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 398 DEBUG_USB_INT_LO_PUTS( "\nS" );
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 399
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 400 if ( USB->DOEP0INT & USB_DOEP0INT_BACK2BACKSETUP )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 401 { /* Back to back setup packets received */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 402 USB->DOEP0INT = USB_DOEP0INT_BACK2BACKSETUP;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 403 DEBUG_USB_INT_LO_PUTS( "B2B" );
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 404
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 405 dev->setup = (USB_Setup_TypeDef*)( USB->DOEP0DMAADDR - USB_SETUP_PKT_SIZE );
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 406 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 407 else
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 408 {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 409 /* Read SETUP packet counter from hw. */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 410 int supCnt = ( USB->DOEP0TSIZ & _USB_DOEP0TSIZ_SUPCNT_MASK )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 411 >> _USB_DOEP0TSIZ_SUPCNT_SHIFT;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 412
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 413 if ( supCnt == 3 )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 414 supCnt = 2;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 415
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 416 dev->setup = &dev->setupPkt[ 2 - supCnt ];
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 417 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 418 USB->DOEP0TSIZ |= 3 << _USB_DOEP0TSIZ_SUPCNT_SHIFT;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 419 USB->DOEP0DMAADDR = (uint32_t)dev->setupPkt;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 420 USB->DOEP0INT = USB_DOEP0INT_SETUP;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 421
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 422 USBDEP_Ep0Handler( dev ); /* Call the SETUP handler for EP0 */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 423 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 424 #endif
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 425
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 426 /*
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 427 * Handle USB reset detected interrupt in suspend mode.
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 428 */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 429 static void Handle_USB_GINTSTS_RESETDET ( void )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 430 {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 431 #if ( USB_PWRSAVE_MODE )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 432 if ( ! USBD_poweredDown )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 433 {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 434 USB->GINTSTS = USB_GINTSTS_RESETDET;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 435 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 436
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 437 if ( UsbPowerUp() )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 438 {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 439 USB->GINTSTS = USB_GINTSTS_RESETDET;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 440 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 441
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 442 #if ( USB_PWRSAVE_MODE & USB_PWRSAVE_MODE_ONVBUSOFF )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 443 /* Power down immediately if VBUS is off. */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 444 if ( ! ( USB->STATUS & USB_STATUS_VREGOS ) )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 445 {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 446 UsbPowerDown();
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 447 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 448 #endif
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 449
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 450 #else
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 451 USB->GINTSTS = USB_GINTSTS_RESETDET;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 452 #endif /* if ( USB_PWRSAVE_MODE ) */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 453
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 454 if ( USB->STATUS & USB_STATUS_VREGOS )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 455 {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 456 USBD_SetUsbState( USBD_STATE_DEFAULT );
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 457 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 458 else
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 459 {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 460 USBD_SetUsbState( USBD_STATE_NONE );
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 461 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 462 DEBUG_USB_INT_LO_PUTS( "RsuP\n" );
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 463 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 464
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 465 /*
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 466 * Handle Start Of Frame (SOF) interrupt.
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 467 */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 468 static void Handle_USB_GINTSTS_SOF( void )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 469 {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 470 USB->GINTSTS = USB_GINTSTS_SOF;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 471
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 472 if ( dev->callbacks->sofInt )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 473 {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 474 dev->callbacks->sofInt(
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 475 ( USB->DSTS & _USB_DSTS_SOFFN_MASK ) >> _USB_DSTS_SOFFN_SHIFT );
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 476 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 477 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 478
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 479 /*
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 480 * Handle USB port reset interrupt.
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 481 */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 482 static void Handle_USB_GINTSTS_USBRST( void )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 483 {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 484 int i;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 485
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 486 DEBUG_USB_INT_LO_PUTS( "ReseT" );
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 487
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 488 /* Clear Remote Wakeup Signalling */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 489 USB->DCTL &= ~( DCTL_WO_BITMASK | USB_DCTL_RMTWKUPSIG );
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 490 USBHAL_FlushTxFifo( 0 );
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 491
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 492 /* Clear pending interrupts */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 493 for ( i = 0; i <= MAX_NUM_IN_EPS; i++ )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 494 {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 495 USB_DINEPS[ i ].INT = 0xFFFFFFFF;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 496 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 497
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 498 for ( i = 0; i <= MAX_NUM_OUT_EPS; i++ )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 499 {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 500 USB_DOUTEPS[ i ].INT = 0xFFFFFFFF;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 501 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 502
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 503 USB->DAINTMSK = USB_DAINTMSK_INEPMSK0 | USB_DAINTMSK_OUTEPMSK0;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 504 #if defined( USB_DOEPMSK_STSPHSERCVDMSK )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 505 USB->DOEPMSK = USB_DOEPMSK_SETUPMSK | USB_DOEPMSK_XFERCOMPLMSK
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 506 | USB_DOEPMSK_STSPHSERCVDMSK;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 507 #else
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 508 USB->DOEPMSK = USB_DOEPMSK_SETUPMSK | USB_DOEPMSK_XFERCOMPLMSK;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 509 #endif
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 510 USB->DIEPMSK = USB_DIEPMSK_XFERCOMPLMSK;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 511
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 512 /* Reset Device Address */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 513 USB->DCFG &= ~_USB_DCFG_DEVADDR_MASK;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 514
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 515 /* Setup EP0 to receive SETUP packets */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 516 USBDHAL_StartEp0Setup( dev );
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 517 USBDHAL_EnableInts( dev );
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 518
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 519 if ( dev->callbacks->usbReset )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 520 {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 521 dev->callbacks->usbReset();
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 522 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 523
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 524 USBD_SetUsbState( USBD_STATE_DEFAULT );
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 525 USBDHAL_AbortAllTransfers( USB_STATUS_DEVICE_RESET );
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 526 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 527
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 528 /*
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 529 * Handle USB port suspend interrupt.
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 530 */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 531 static void Handle_USB_GINTSTS_USBSUSP( void )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 532 {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 533 USBD_State_TypeDef state;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 534
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 535 USB->GINTSTS = USB_GINTSTS_USBSUSP;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 536 USBDHAL_AbortAllTransfers( USB_STATUS_DEVICE_SUSPENDED );
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 537 DEBUG_USB_INT_LO_PUTS( "\nSusP" );
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 538
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 539 if ( USBD_GetUsbState() == USBD_STATE_NONE )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 540 {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 541 USBD_SetUsbState( USBD_STATE_POWERED );
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 542 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 543
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 544 state = USBD_GetUsbState();
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 545 if ( ( state == USBD_STATE_POWERED ) ||
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 546 ( state == USBD_STATE_DEFAULT ) ||
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 547 ( state == USBD_STATE_ADDRESSED ) ||
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 548 ( state == USBD_STATE_CONFIGURED ) )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 549 {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 550 #if ( USB_PWRSAVE_MODE )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 551 UsbPowerDown();
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 552 #endif
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 553 USBD_SetUsbState( USBD_STATE_SUSPENDED );
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 554 }
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 * Handle USB port wakeup interrupt.
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 559 */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 560 static void Handle_USB_GINTSTS_WKUPINT( void )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 561 {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 562 #if ( USB_PWRSAVE_MODE )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 563 if ( ! USBD_poweredDown )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 564 {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 565 USB->GINTSTS = USB_GINTSTS_WKUPINT;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 566 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 567
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 568 if ( UsbPowerUp() )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 569 {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 570 USB->GINTSTS = USB_GINTSTS_WKUPINT;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 571 USBDHAL_StartEp0Setup( dev );
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 572 USBDHAL_Ep0Activate( dev->ep0MpsCode );
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 573 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 574 #else
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 575 USB->GINTSTS = USB_GINTSTS_WKUPINT;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 576 #endif
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 577
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 578 USBD_SetUsbState( dev->savedState );
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 579 DEBUG_USB_INT_LO_PUTS( "WkuP\n" );
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 580 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 581
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 582 #if ( USB_PWRSAVE_MODE )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 583 /*
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 584 * Backup essential USB core registers, and set the core in partial powerdown
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 585 * mode. Optionally prepare entry into EM2.
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 586 */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 587 static bool UsbPowerDown( void )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 588 {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 589 #if ( NUM_EP_USED > 0 ) || ( FIFO_CNT > 0 )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 590 int i;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 591 #endif
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 592 #if ( NUM_EP_USED > 0 )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 593 int epNum;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 594 USBD_Ep_TypeDef *ep;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 595 #endif
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 596
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 597 if ( !USBD_poweredDown )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 598 {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 599 USBD_poweredDown = true;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 600 DEBUG_USB_INT_LO_PUTCHAR( '\\' );
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 601
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 602 /* Backup USB core registers. */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 603 x_USB_GINTMSK = USB->GINTMSK;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 604 #if defined(_USB_GOTGCTL_MASK)
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 605 x_USB_GOTGCTL = USB->GOTGCTL;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 606 #endif
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 607 x_USB_GAHBCFG = USB->GAHBCFG;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 608 x_USB_GUSBCFG = USB->GUSBCFG;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 609 x_USB_GRXFSIZ = USB->GRXFSIZ;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 610 x_USB_GNPTXFSIZ = USB->GNPTXFSIZ;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 611 x_USB_DCFG = USB->DCFG;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 612 x_USB_DCTL = USB->DCTL;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 613 x_USB_DAINTMSK = USB->DAINTMSK;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 614 x_USB_DIEPMSK = USB->DIEPMSK;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 615 x_USB_DOEPMSK = USB->DOEPMSK;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 616 x_USB_PCGCCTL = USB->PCGCCTL;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 617
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 618 #if ( NUM_EP_USED > 0 )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 619 for ( i = 0; i < NUM_EP_USED; i++ )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 620 {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 621 ep = &dev->ep[ i+1 ];
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 622 epNum = ep->num;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 623 if ( ep->in )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 624 {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 625 x_USB_EP_CTL[ i ] = USB_DINEPS[ epNum ].CTL;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 626 x_USB_EP_TSIZ[ i ] = USB_DINEPS[ epNum ].TSIZ;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 627 x_USB_EP_DMAADDR[ i ] = USB_DINEPS[ epNum ].DMAADDR;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 628 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 629 else
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 630 {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 631 x_USB_EP_CTL[ i ] = USB_DOUTEPS[ epNum ].CTL;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 632 x_USB_EP_TSIZ[ i ] = USB_DOUTEPS[ epNum ].TSIZ;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 633 x_USB_EP_DMAADDR[ i ] = USB_DOUTEPS[ epNum ].DMAADDR;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 634 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 635 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 636 #endif
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 637
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 638 #if ( FIFO_CNT > 0 )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 639 for ( i = 0; i < FIFO_CNT; i++ )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 640 {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 641 x_USB_DIEPTXFS[ i ] = USB_DIEPTXFS[ i ];
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 642 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 643 #endif
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 644
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 645 /* Prepare for wakeup on resume and reset. */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 646 USB->DCFG = (USB->DCFG & ~_USB_DCFG_RESVALID_MASK) |
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 647 (4 << _USB_DCFG_RESVALID_SHIFT);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 648 USB->DCFG |= USB_DCFG_ENA32KHZSUSP;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 649 USB->GINTMSK = USB_GINTMSK_RESETDETMSK | USB_GINTMSK_WKUPINTMSK;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 650
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 651 /* Enter partial powerdown mode. */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 652 USB->PCGCCTL |= USB_PCGCCTL_PWRCLMP;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 653 USB->PCGCCTL |= USB_PCGCCTL_RSTPDWNMODULE;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 654 USB->PCGCCTL |= USB_PCGCCTL_STOPPCLK;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 655
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 656 /* Record current clock settings. */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 657 cmuStatus = CMU->STATUS;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 658
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 659 #if ( USB_PWRSAVE_MODE & USB_PWRSAVE_MODE_ENTEREM2 )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 660 #ifndef __MBED__
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 661 /* Enter EM2 on interrupt exit. */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 662 SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk | SCB_SCR_SLEEPONEXIT_Msk;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 663 #else
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 664 usbhal_allow_em2(true);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 665 #endif
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 666 #endif
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 667
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 668 /* Switch USBC clock to 32 kHz. */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 669 #if ( USB_USBC_32kHz_CLK == USB_USBC_32kHz_CLK_LFXO )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 670 CMU->CMD = CMU_CMD_USBCCLKSEL_LFXO;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 671 while ( ( CMU->STATUS & CMU_STATUS_USBCLFXOSEL ) == 0 ){}
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 672 #else
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 673 CMU->CMD = CMU_CMD_USBCCLKSEL_LFRCO;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 674 while ( ( CMU->STATUS & CMU_STATUS_USBCLFRCOSEL ) == 0 ){}
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 675 #endif
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 676
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 677 return true;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 678 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 679 return false;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 680 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 681 #endif /* if ( USB_PWRSAVE_MODE ) */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 682
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 683 #if ( USB_PWRSAVE_MODE )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 684 /*
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 685 * Exit USB core partial powerdown mode, restore essential USB core registers.
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 686 * Will prevent re-entry back to EM2.
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 687 * Returns true if a powerup sequence was performed.
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 688 */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 689 static bool UsbPowerUp( void )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 690 {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 691 #if ( NUM_EP_USED > 0 ) || ( FIFO_CNT > 0 )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 692 int i;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 693 #endif
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 694 #if ( NUM_EP_USED > 0 )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 695 int epNum;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 696 uint32_t tmp;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 697 USBD_Ep_TypeDef *ep;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 698 #endif
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 699
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 700 if ( USBD_poweredDown )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 701 {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 702 USBD_poweredDown = false;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 703 DEBUG_USB_INT_LO_PUTCHAR( '/' );
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 704
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 705 #if !defined( USB_CORECLK_HFRCO ) || !defined( CMU_OSCENCMD_USHFRCOEN )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 706 /* Switch HFCLK from HFRCO to HFXO. */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 707 CMU_ClockSelectSet( cmuClock_HF, cmuSelect_HFXO );
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 708 #endif
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 709
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 710 /* Turn off HFRCO when not needed. */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 711 if ( ( cmuStatus & CMU_STATUS_HFRCOENS ) == 0 )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 712 {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 713 CMU->OSCENCMD = CMU_OSCENCMD_HFRCODIS;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 714 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 715
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 716 /* Exit partial powerdown mode. */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 717 USB->PCGCCTL &= ~USB_PCGCCTL_STOPPCLK;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 718 USB->PCGCCTL &= ~(USB_PCGCCTL_PWRCLMP | USB_PCGCCTL_RSTPDWNMODULE);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 719
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 720 if (( USB->GINTSTS & ( USB_GINTSTS_WKUPINT | USB_GINTSTS_RESETDET ) ) == 0)
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 721 {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 722 USB->DCTL = x_USB_DCTL | USB_DCTL_RMTWKUPSIG;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 723 USB->DCTL = x_USB_DCTL;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 724 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 725
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 726 /* Restore USB core registers. */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 727 USB->GUSBCFG = x_USB_GUSBCFG;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 728 USB->DCFG = x_USB_DCFG;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 729
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 730 #if ( FIFO_CNT > 0 )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 731 for ( i = 0; i < FIFO_CNT; i++ )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 732 {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 733 USB_DIEPTXFS[ i ] = x_USB_DIEPTXFS[ i ];
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 734 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 735 #endif
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 736
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 737 #if ( NUM_EP_USED > 0 )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 738 for ( i = 0; i < NUM_EP_USED; i++ )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 739 {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 740 ep = &dev->ep[ i+1 ];
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 741 epNum = ep->num;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 742
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 743 tmp = x_USB_EP_CTL[ i ] &
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 744 ~( USB_DIEP_CTL_CNAK | USB_DIEP_CTL_SNAK |
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 745 USB_DIEP_CTL_SETD0PIDEF | USB_DIEP_CTL_SETD1PIDOF );
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 746
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 747 if ( x_USB_EP_CTL[ i ] & USB_DIEP_CTL_DPIDEOF )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 748 tmp |= USB_DIEP_CTL_SETD1PIDOF;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 749 else
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 750 tmp |= USB_DIEP_CTL_SETD0PIDEF;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 751
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 752 if ( x_USB_EP_CTL[ i ] & USB_DIEP_CTL_NAKSTS )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 753 tmp |= USB_DIEP_CTL_SNAK;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 754 else
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 755 tmp |= USB_DIEP_CTL_CNAK;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 756
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 757 if ( ep->in )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 758 {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 759 USB_DINEPS[ epNum ].CTL = tmp;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 760 USB_DINEPS[ epNum ].TSIZ = x_USB_EP_TSIZ[ i ];
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 761 USB_DINEPS[ epNum ].DMAADDR = x_USB_EP_DMAADDR[ i ];
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 762 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 763 else
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 764 {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 765 USB_DOUTEPS[ epNum ].CTL = tmp;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 766 USB_DOUTEPS[ epNum ].TSIZ = x_USB_EP_TSIZ[ i ];
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 767 USB_DOUTEPS[ epNum ].DMAADDR = x_USB_EP_DMAADDR[ i ];
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 768 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 769 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 770 #endif
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 771
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 772 USB->PCGCCTL = x_USB_PCGCCTL;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 773 USB->DOEPMSK = x_USB_DOEPMSK;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 774 USB->DIEPMSK = x_USB_DIEPMSK;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 775 USB->DAINTMSK = x_USB_DAINTMSK;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 776 USB->DCTL = x_USB_DCTL;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 777 USB->GNPTXFSIZ = x_USB_GNPTXFSIZ;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 778 USB->GRXFSIZ = x_USB_GRXFSIZ;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 779 USB->GAHBCFG = x_USB_GAHBCFG;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 780 #if defined(_USB_GOTGCTL_MASK)
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 781 USB->GOTGCTL = x_USB_GOTGCTL;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 782 #endif
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 783 USB->GINTMSK = x_USB_GINTMSK;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 784
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 785 USB->DCTL |= USB_DCTL_PWRONPRGDONE;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 786
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 787 #if ( USB_PWRSAVE_MODE & USB_PWRSAVE_MODE_ENTEREM2 )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 788 #ifndef __MBED__
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 789 /* Do not reenter EM2 on interrupt exit. */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 790 SCB->SCR &= ~(SCB_SCR_SLEEPDEEP_Msk | SCB_SCR_SLEEPONEXIT_Msk);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 791 #else
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 792 usbhal_allow_em2(false);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 793 #endif
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 794 #endif
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 795
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 796 return true;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 797 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 798 return false;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 799 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 800 #endif /* if ( USB_PWRSAVE_MODE ) */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 801
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 802 #if defined( USB_DOEP0INT_STUPPKTRCVD )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 803 static void HandleOutEpIntr( uint32_t status, USBD_Ep_TypeDef *ep )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 804 {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 805 uint32_t doeptsiz;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 806
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 807 if ( ep->num == 0 )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 808 {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 809 if ( status & USB_DOEP0INT_XFERCOMPL )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 810 {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 811 USB->DOEP0INT = USB_DOEP0INT_XFERCOMPL;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 812 doeptsiz = USB->DOEP0TSIZ;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 813
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 814 if ( ep->state == D_EP_IDLE )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 815 {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 816 if ( status & USB_DOEP0INT_STUPPKTRCVD )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 817 {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 818 USB->DOEP0INT = USB_DOEP0INT_STUPPKTRCVD;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 819 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 820 status = USBDHAL_GetOutEpInts( ep );
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 821 doeptsiz = USB->DOEP0TSIZ;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 822
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 823 if ( status & USB_DOEP0INT_SETUP )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 824 {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 825 retry:
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 826 /* Already started data stage, clear setup */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 827 USB->DOEP0INT = USB_DOEP0INT_SETUP;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 828 status &= ~USB_DOEP0INT_SETUP;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 829 {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 830 int supCnt = ( doeptsiz & _USB_DOEP0TSIZ_SUPCNT_MASK )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 831 >> _USB_DOEP0TSIZ_SUPCNT_SHIFT;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 832
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 833 if ( supCnt == 3 )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 834 supCnt = 2;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 835
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 836 dev->setup = &dev->setupPkt[ 2 - supCnt ];
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 837 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 838 DEBUG_USB_INT_LO_PUTS( "\nS" );
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 839 USBDEP_Ep0Handler( dev );
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 840
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 841 /* Prepare for more setup packets */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 842 if ( ep->state == D_EP0_IN_STATUS || ep->state == D_EP_TRANSMITTING )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 843 {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 844 USBDHAL_StartEp0Setup( dev );
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 845 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 846 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 847 else /* xfercompl && idle && !setup */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 848 {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 849 status = USBDHAL_GetOutEpInts( ep );
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 850 if ( status & USB_DOEP0INT_SETUP )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 851 goto retry;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 852 USBDHAL_StartEp0Setup( dev );
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 853 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 854 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 855 else /* ep0state != EP0_IDLE */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 856 {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 857 #ifdef __MBED__
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 858 if ( ep->state == D_EP_RECEIVING )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 859 {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 860 int xfer_size = ep->packetSize - (( USB->DOEP0TSIZ & _USB_DOEP0TSIZ_XFERSIZE_MASK )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 861 >> _USB_DOEP0TSIZ_XFERSIZE_SHIFT);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 862 int setup_pkt_received = status & USB_DOEP0INT_SETUP;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 863
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 864 if ( (!setup_pkt_received && xfer_size == 0) ||
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 865 (setup_pkt_received && xfer_size == 8) )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 866 {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 867 /* Higher levels need to see the correct transfer amount for ZLPs */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 868 ep->remaining = 0;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 869 ep->xferred = 0;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 870 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 871 else
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 872 {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 873 /* FIXME - does not work if actual read size > 56 */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 874 if ( setup_pkt_received ) xfer_size -= 8;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 875
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 876 ep->xferred = xfer_size;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 877 ep->remaining -= xfer_size;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 878 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 879
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 880 USBDEP_Ep0Handler( dev );
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 881 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 882 #else
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 883 if ( ep->state == D_EP_RECEIVING )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 884 {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 885 if ( ep->remaining > ep->packetSize )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 886 {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 887 ep->remaining -= ep->packetSize;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 888 ep->xferred += ep->packetSize;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 889 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 890 else
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 891 {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 892 ep->xferred += ep->remaining;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 893 ep->remaining = 0;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 894 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 895 USBDEP_Ep0Handler( dev );
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 896 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 897 else if ( ep->state == D_EP0_OUT_STATUS )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 898 {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 899 USBDEP_Ep0Handler( dev );
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 900 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 901 #endif
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 902 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 903 } /* if ( status & USB_DOEP0INT_XFERCOMPL ) */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 904
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 905 if ( status & USB_DOEP0INT_STSPHSERCVD )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 906 {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 907 USB->DOEP0INT = USB_DOEP0INT_STSPHSERCVD;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 908 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 909
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 910 if ( status & USB_DOEP0INT_SETUP )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 911 {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 912 USB->DOEP0INT = USB_DOEP0INT_SETUP;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 913 {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 914 int supCnt = ( USB->DOEP0TSIZ & _USB_DOEP0TSIZ_SUPCNT_MASK )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 915 >> _USB_DOEP0TSIZ_SUPCNT_SHIFT;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 916
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 917 if ( supCnt == 3 )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 918 supCnt = 2;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 919
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 920 dev->setup = &dev->setupPkt[ 2 - supCnt ];
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 921 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 922 DEBUG_USB_INT_LO_PUTS( "\nS" );
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 923 USBDEP_Ep0Handler( dev );
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 924 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 925 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 926 else /* epnum != 0 */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 927 {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 928 if ( status & USB_DOEP_INT_XFERCOMPL )
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 929 {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 930 USB_DOUTEPS[ ep->num ].INT = USB_DOEP_INT_XFERCOMPL;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 931
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 932 ep->xferred = ep->hwXferSize -
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 933 ( ( USB_DOUTEPS[ ep->num ].TSIZ & _USB_DOEP_TSIZ_XFERSIZE_MASK )>>
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 934 _USB_DOEP_TSIZ_XFERSIZE_SHIFT );
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 935 ep->remaining -= ep->xferred;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 936
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 937 USBDEP_EpHandler( ep->addr );
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 938 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 939 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 940 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 941 #endif
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 942
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 943 /** @endcond */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 944
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 945 #endif /* defined( USB_DEVICE ) */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 946 #endif /* defined( USB_PRESENT ) && ( USB_COUNT == 1 ) */