test
Dependencies: SDFileSystem mbed-dev
Fork of Nucleo_Ex06_EMU by
USBHost/USBHALHost2_F401RE.cpp@4:53ef91c87d74, 2017-05-27 (annotated)
- Committer:
- charliex
- Date:
- Sat May 27 02:17:37 2017 +0000
- Revision:
- 4:53ef91c87d74
- Parent:
- 0:3dac1f1bc9e0
test
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
beaglescout007 | 0:3dac1f1bc9e0 | 1 | #if defined(TARGET_NUCLEO_F401RE)||defined(TARGET_NUCLEO_F411RE)||defined(TARGET_NUCLEO_F446RE) |
beaglescout007 | 0:3dac1f1bc9e0 | 2 | #include "USBHALHost.h" |
beaglescout007 | 0:3dac1f1bc9e0 | 3 | |
beaglescout007 | 0:3dac1f1bc9e0 | 4 | // usbh_conf.c |
beaglescout007 | 0:3dac1f1bc9e0 | 5 | HCD_HandleTypeDef hhcd_USB_OTG_FS; |
beaglescout007 | 0:3dac1f1bc9e0 | 6 | |
beaglescout007 | 0:3dac1f1bc9e0 | 7 | static void HAL_HCD_IRQHandler(HCD_HandleTypeDef *hhcd); |
beaglescout007 | 0:3dac1f1bc9e0 | 8 | |
beaglescout007 | 0:3dac1f1bc9e0 | 9 | // stm32f4xx_it.c |
beaglescout007 | 0:3dac1f1bc9e0 | 10 | extern "C" { |
beaglescout007 | 0:3dac1f1bc9e0 | 11 | void OTG_FS_IRQHandler(void) |
beaglescout007 | 0:3dac1f1bc9e0 | 12 | { |
beaglescout007 | 0:3dac1f1bc9e0 | 13 | HAL_NVIC_ClearPendingIRQ(OTG_FS_IRQn); |
beaglescout007 | 0:3dac1f1bc9e0 | 14 | HAL_HCD_IRQHandler(&hhcd_USB_OTG_FS); |
beaglescout007 | 0:3dac1f1bc9e0 | 15 | } |
beaglescout007 | 0:3dac1f1bc9e0 | 16 | } |
beaglescout007 | 0:3dac1f1bc9e0 | 17 | |
beaglescout007 | 0:3dac1f1bc9e0 | 18 | // stm32f4xx_hal_hcd.c |
beaglescout007 | 0:3dac1f1bc9e0 | 19 | static void HCD_HC_IN_IRQHandler(HCD_HandleTypeDef *hhcd, uint8_t chnum); |
beaglescout007 | 0:3dac1f1bc9e0 | 20 | static void HCD_HC_OUT_IRQHandler(HCD_HandleTypeDef *hhcd, uint8_t chnum); |
beaglescout007 | 0:3dac1f1bc9e0 | 21 | static void HCD_RXQLVL_IRQHandler(HCD_HandleTypeDef *hhcd); |
beaglescout007 | 0:3dac1f1bc9e0 | 22 | static void HCD_Port_IRQHandler(HCD_HandleTypeDef *hhcd); |
beaglescout007 | 0:3dac1f1bc9e0 | 23 | |
beaglescout007 | 0:3dac1f1bc9e0 | 24 | /** |
beaglescout007 | 0:3dac1f1bc9e0 | 25 | * @brief This function handles HCD interrupt request. |
beaglescout007 | 0:3dac1f1bc9e0 | 26 | * @param hhcd: HCD handle |
beaglescout007 | 0:3dac1f1bc9e0 | 27 | * @retval none |
beaglescout007 | 0:3dac1f1bc9e0 | 28 | */ |
beaglescout007 | 0:3dac1f1bc9e0 | 29 | static void HAL_HCD_IRQHandler(HCD_HandleTypeDef *hhcd) |
beaglescout007 | 0:3dac1f1bc9e0 | 30 | { |
beaglescout007 | 0:3dac1f1bc9e0 | 31 | USB_OTG_GlobalTypeDef *USBx = hhcd->Instance; |
beaglescout007 | 0:3dac1f1bc9e0 | 32 | uint32_t i = 0 , interrupt = 0; |
beaglescout007 | 0:3dac1f1bc9e0 | 33 | |
beaglescout007 | 0:3dac1f1bc9e0 | 34 | /* ensure that we are in device mode */ |
beaglescout007 | 0:3dac1f1bc9e0 | 35 | if (USB_GetMode(hhcd->Instance) == USB_OTG_MODE_HOST) |
beaglescout007 | 0:3dac1f1bc9e0 | 36 | { |
beaglescout007 | 0:3dac1f1bc9e0 | 37 | /* avoid spurious interrupt */ |
beaglescout007 | 0:3dac1f1bc9e0 | 38 | if(__HAL_HCD_IS_INVALID_INTERRUPT(hhcd)) |
beaglescout007 | 0:3dac1f1bc9e0 | 39 | { |
beaglescout007 | 0:3dac1f1bc9e0 | 40 | return; |
beaglescout007 | 0:3dac1f1bc9e0 | 41 | } |
beaglescout007 | 0:3dac1f1bc9e0 | 42 | |
beaglescout007 | 0:3dac1f1bc9e0 | 43 | if(__HAL_HCD_GET_FLAG(hhcd, USB_OTG_GINTSTS_PXFR_INCOMPISOOUT)) |
beaglescout007 | 0:3dac1f1bc9e0 | 44 | { |
beaglescout007 | 0:3dac1f1bc9e0 | 45 | /* incorrect mode, acknowledge the interrupt */ |
beaglescout007 | 0:3dac1f1bc9e0 | 46 | __HAL_HCD_CLEAR_FLAG(hhcd, USB_OTG_GINTSTS_PXFR_INCOMPISOOUT); |
beaglescout007 | 0:3dac1f1bc9e0 | 47 | } |
beaglescout007 | 0:3dac1f1bc9e0 | 48 | |
beaglescout007 | 0:3dac1f1bc9e0 | 49 | if(__HAL_HCD_GET_FLAG(hhcd, USB_OTG_GINTSTS_IISOIXFR)) |
beaglescout007 | 0:3dac1f1bc9e0 | 50 | { |
beaglescout007 | 0:3dac1f1bc9e0 | 51 | /* incorrect mode, acknowledge the interrupt */ |
beaglescout007 | 0:3dac1f1bc9e0 | 52 | __HAL_HCD_CLEAR_FLAG(hhcd, USB_OTG_GINTSTS_IISOIXFR); |
beaglescout007 | 0:3dac1f1bc9e0 | 53 | } |
beaglescout007 | 0:3dac1f1bc9e0 | 54 | |
beaglescout007 | 0:3dac1f1bc9e0 | 55 | if(__HAL_HCD_GET_FLAG(hhcd, USB_OTG_GINTSTS_PTXFE)) |
beaglescout007 | 0:3dac1f1bc9e0 | 56 | { |
beaglescout007 | 0:3dac1f1bc9e0 | 57 | /* incorrect mode, acknowledge the interrupt */ |
beaglescout007 | 0:3dac1f1bc9e0 | 58 | __HAL_HCD_CLEAR_FLAG(hhcd, USB_OTG_GINTSTS_PTXFE); |
beaglescout007 | 0:3dac1f1bc9e0 | 59 | } |
beaglescout007 | 0:3dac1f1bc9e0 | 60 | |
beaglescout007 | 0:3dac1f1bc9e0 | 61 | if(__HAL_HCD_GET_FLAG(hhcd, USB_OTG_GINTSTS_MMIS)) |
beaglescout007 | 0:3dac1f1bc9e0 | 62 | { |
beaglescout007 | 0:3dac1f1bc9e0 | 63 | /* incorrect mode, acknowledge the interrupt */ |
beaglescout007 | 0:3dac1f1bc9e0 | 64 | __HAL_HCD_CLEAR_FLAG(hhcd, USB_OTG_GINTSTS_MMIS); |
beaglescout007 | 0:3dac1f1bc9e0 | 65 | } |
beaglescout007 | 0:3dac1f1bc9e0 | 66 | |
beaglescout007 | 0:3dac1f1bc9e0 | 67 | /* Handle Host Disconnect Interrupts */ |
beaglescout007 | 0:3dac1f1bc9e0 | 68 | if(__HAL_HCD_GET_FLAG(hhcd, USB_OTG_GINTSTS_DISCINT)) |
beaglescout007 | 0:3dac1f1bc9e0 | 69 | { |
beaglescout007 | 0:3dac1f1bc9e0 | 70 | |
beaglescout007 | 0:3dac1f1bc9e0 | 71 | /* Cleanup HPRT */ |
beaglescout007 | 0:3dac1f1bc9e0 | 72 | USBx_HPRT0 &= ~(USB_OTG_HPRT_PENA | USB_OTG_HPRT_PCDET |\ |
beaglescout007 | 0:3dac1f1bc9e0 | 73 | USB_OTG_HPRT_PENCHNG | USB_OTG_HPRT_POCCHNG ); |
beaglescout007 | 0:3dac1f1bc9e0 | 74 | |
beaglescout007 | 0:3dac1f1bc9e0 | 75 | /* Handle Host Port Interrupts */ |
beaglescout007 | 0:3dac1f1bc9e0 | 76 | HAL_HCD_Disconnect_Callback(hhcd); |
beaglescout007 | 0:3dac1f1bc9e0 | 77 | USB_InitFSLSPClkSel(hhcd->Instance ,HCFG_48_MHZ ); |
beaglescout007 | 0:3dac1f1bc9e0 | 78 | __HAL_HCD_CLEAR_FLAG(hhcd, USB_OTG_GINTSTS_DISCINT); |
beaglescout007 | 0:3dac1f1bc9e0 | 79 | } |
beaglescout007 | 0:3dac1f1bc9e0 | 80 | |
beaglescout007 | 0:3dac1f1bc9e0 | 81 | /* Handle Host Port Interrupts */ |
beaglescout007 | 0:3dac1f1bc9e0 | 82 | if(__HAL_HCD_GET_FLAG(hhcd, USB_OTG_GINTSTS_HPRTINT)) |
beaglescout007 | 0:3dac1f1bc9e0 | 83 | { |
beaglescout007 | 0:3dac1f1bc9e0 | 84 | HCD_Port_IRQHandler (hhcd); |
beaglescout007 | 0:3dac1f1bc9e0 | 85 | } |
beaglescout007 | 0:3dac1f1bc9e0 | 86 | |
beaglescout007 | 0:3dac1f1bc9e0 | 87 | /* Handle Host SOF Interrupts */ |
beaglescout007 | 0:3dac1f1bc9e0 | 88 | if(__HAL_HCD_GET_FLAG(hhcd, USB_OTG_GINTSTS_SOF)) |
beaglescout007 | 0:3dac1f1bc9e0 | 89 | { |
beaglescout007 | 0:3dac1f1bc9e0 | 90 | HAL_HCD_SOF_Callback(hhcd); |
beaglescout007 | 0:3dac1f1bc9e0 | 91 | __HAL_HCD_CLEAR_FLAG(hhcd, USB_OTG_GINTSTS_SOF); |
beaglescout007 | 0:3dac1f1bc9e0 | 92 | } |
beaglescout007 | 0:3dac1f1bc9e0 | 93 | |
beaglescout007 | 0:3dac1f1bc9e0 | 94 | /* Handle Host channel Interrupts */ |
beaglescout007 | 0:3dac1f1bc9e0 | 95 | if(__HAL_HCD_GET_FLAG(hhcd, USB_OTG_GINTSTS_HCINT)) |
beaglescout007 | 0:3dac1f1bc9e0 | 96 | { |
beaglescout007 | 0:3dac1f1bc9e0 | 97 | |
beaglescout007 | 0:3dac1f1bc9e0 | 98 | interrupt = USB_HC_ReadInterrupt(hhcd->Instance); |
beaglescout007 | 0:3dac1f1bc9e0 | 99 | for (i = 0; i < hhcd->Init.Host_channels ; i++) |
beaglescout007 | 0:3dac1f1bc9e0 | 100 | { |
beaglescout007 | 0:3dac1f1bc9e0 | 101 | if (interrupt & (1 << i)) |
beaglescout007 | 0:3dac1f1bc9e0 | 102 | { |
beaglescout007 | 0:3dac1f1bc9e0 | 103 | if ((USBx_HC(i)->HCCHAR) & USB_OTG_HCCHAR_EPDIR) |
beaglescout007 | 0:3dac1f1bc9e0 | 104 | { |
beaglescout007 | 0:3dac1f1bc9e0 | 105 | HCD_HC_IN_IRQHandler (hhcd, i); |
beaglescout007 | 0:3dac1f1bc9e0 | 106 | } |
beaglescout007 | 0:3dac1f1bc9e0 | 107 | else |
beaglescout007 | 0:3dac1f1bc9e0 | 108 | { |
beaglescout007 | 0:3dac1f1bc9e0 | 109 | HCD_HC_OUT_IRQHandler (hhcd, i); |
beaglescout007 | 0:3dac1f1bc9e0 | 110 | } |
beaglescout007 | 0:3dac1f1bc9e0 | 111 | } |
beaglescout007 | 0:3dac1f1bc9e0 | 112 | } |
beaglescout007 | 0:3dac1f1bc9e0 | 113 | __HAL_HCD_CLEAR_FLAG(hhcd, USB_OTG_GINTSTS_HCINT); |
beaglescout007 | 0:3dac1f1bc9e0 | 114 | } |
beaglescout007 | 0:3dac1f1bc9e0 | 115 | |
beaglescout007 | 0:3dac1f1bc9e0 | 116 | /* Handle Rx Queue Level Interrupts */ |
beaglescout007 | 0:3dac1f1bc9e0 | 117 | if(__HAL_HCD_GET_FLAG(hhcd, USB_OTG_GINTSTS_RXFLVL)) |
beaglescout007 | 0:3dac1f1bc9e0 | 118 | { |
beaglescout007 | 0:3dac1f1bc9e0 | 119 | USB_MASK_INTERRUPT(hhcd->Instance, USB_OTG_GINTSTS_RXFLVL); |
beaglescout007 | 0:3dac1f1bc9e0 | 120 | |
beaglescout007 | 0:3dac1f1bc9e0 | 121 | HCD_RXQLVL_IRQHandler (hhcd); |
beaglescout007 | 0:3dac1f1bc9e0 | 122 | |
beaglescout007 | 0:3dac1f1bc9e0 | 123 | USB_UNMASK_INTERRUPT(hhcd->Instance, USB_OTG_GINTSTS_RXFLVL); |
beaglescout007 | 0:3dac1f1bc9e0 | 124 | } |
beaglescout007 | 0:3dac1f1bc9e0 | 125 | |
beaglescout007 | 0:3dac1f1bc9e0 | 126 | } |
beaglescout007 | 0:3dac1f1bc9e0 | 127 | } |
beaglescout007 | 0:3dac1f1bc9e0 | 128 | /** |
beaglescout007 | 0:3dac1f1bc9e0 | 129 | * @brief This function handles Host Channel IN interrupt requests. |
beaglescout007 | 0:3dac1f1bc9e0 | 130 | * @param hhcd: HCD handle |
beaglescout007 | 0:3dac1f1bc9e0 | 131 | * @param chnum : Channel number |
beaglescout007 | 0:3dac1f1bc9e0 | 132 | * This parameter can be a value from 1 to 15 |
beaglescout007 | 0:3dac1f1bc9e0 | 133 | * @retval none |
beaglescout007 | 0:3dac1f1bc9e0 | 134 | */ |
beaglescout007 | 0:3dac1f1bc9e0 | 135 | static void HCD_HC_IN_IRQHandler (HCD_HandleTypeDef *hhcd, uint8_t chnum) |
beaglescout007 | 0:3dac1f1bc9e0 | 136 | { |
beaglescout007 | 0:3dac1f1bc9e0 | 137 | USB_OTG_GlobalTypeDef *USBx = hhcd->Instance; |
beaglescout007 | 0:3dac1f1bc9e0 | 138 | |
beaglescout007 | 0:3dac1f1bc9e0 | 139 | if ((USBx_HC(chnum)->HCINT) & USB_OTG_HCINT_AHBERR) |
beaglescout007 | 0:3dac1f1bc9e0 | 140 | { |
beaglescout007 | 0:3dac1f1bc9e0 | 141 | __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_AHBERR); |
beaglescout007 | 0:3dac1f1bc9e0 | 142 | __HAL_HCD_UNMASK_HALT_HC_INT(chnum); |
beaglescout007 | 0:3dac1f1bc9e0 | 143 | } |
beaglescout007 | 0:3dac1f1bc9e0 | 144 | else if ((USBx_HC(chnum)->HCINT) & USB_OTG_HCINT_ACK) |
beaglescout007 | 0:3dac1f1bc9e0 | 145 | { |
beaglescout007 | 0:3dac1f1bc9e0 | 146 | __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_ACK); |
beaglescout007 | 0:3dac1f1bc9e0 | 147 | } |
beaglescout007 | 0:3dac1f1bc9e0 | 148 | |
beaglescout007 | 0:3dac1f1bc9e0 | 149 | else if ((USBx_HC(chnum)->HCINT) & USB_OTG_HCINT_STALL) |
beaglescout007 | 0:3dac1f1bc9e0 | 150 | { |
beaglescout007 | 0:3dac1f1bc9e0 | 151 | __HAL_HCD_UNMASK_HALT_HC_INT(chnum); |
beaglescout007 | 0:3dac1f1bc9e0 | 152 | hhcd->hc[chnum].state = HC_STALL; |
beaglescout007 | 0:3dac1f1bc9e0 | 153 | __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_NAK); |
beaglescout007 | 0:3dac1f1bc9e0 | 154 | __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_STALL); |
beaglescout007 | 0:3dac1f1bc9e0 | 155 | USB_HC_Halt(hhcd->Instance, chnum); |
beaglescout007 | 0:3dac1f1bc9e0 | 156 | } |
beaglescout007 | 0:3dac1f1bc9e0 | 157 | else if ((USBx_HC(chnum)->HCINT) & USB_OTG_HCINT_DTERR) |
beaglescout007 | 0:3dac1f1bc9e0 | 158 | { |
beaglescout007 | 0:3dac1f1bc9e0 | 159 | __HAL_HCD_UNMASK_HALT_HC_INT(chnum); |
beaglescout007 | 0:3dac1f1bc9e0 | 160 | USB_HC_Halt(hhcd->Instance, chnum); |
beaglescout007 | 0:3dac1f1bc9e0 | 161 | __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_NAK); |
beaglescout007 | 0:3dac1f1bc9e0 | 162 | hhcd->hc[chnum].state = HC_DATATGLERR; |
beaglescout007 | 0:3dac1f1bc9e0 | 163 | __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_DTERR); |
beaglescout007 | 0:3dac1f1bc9e0 | 164 | } |
beaglescout007 | 0:3dac1f1bc9e0 | 165 | |
beaglescout007 | 0:3dac1f1bc9e0 | 166 | if ((USBx_HC(chnum)->HCINT) & USB_OTG_HCINT_FRMOR) |
beaglescout007 | 0:3dac1f1bc9e0 | 167 | { |
beaglescout007 | 0:3dac1f1bc9e0 | 168 | __HAL_HCD_UNMASK_HALT_HC_INT(chnum); |
beaglescout007 | 0:3dac1f1bc9e0 | 169 | USB_HC_Halt(hhcd->Instance, chnum); |
beaglescout007 | 0:3dac1f1bc9e0 | 170 | __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_FRMOR); |
beaglescout007 | 0:3dac1f1bc9e0 | 171 | } |
beaglescout007 | 0:3dac1f1bc9e0 | 172 | |
beaglescout007 | 0:3dac1f1bc9e0 | 173 | else if ((USBx_HC(chnum)->HCINT) & USB_OTG_HCINT_XFRC) |
beaglescout007 | 0:3dac1f1bc9e0 | 174 | { |
beaglescout007 | 0:3dac1f1bc9e0 | 175 | |
beaglescout007 | 0:3dac1f1bc9e0 | 176 | if (hhcd->Init.dma_enable) |
beaglescout007 | 0:3dac1f1bc9e0 | 177 | { |
beaglescout007 | 0:3dac1f1bc9e0 | 178 | hhcd->hc[chnum].xfer_count = hhcd->hc[chnum].xfer_len - \ |
beaglescout007 | 0:3dac1f1bc9e0 | 179 | (USBx_HC(chnum)->HCTSIZ & USB_OTG_HCTSIZ_XFRSIZ); |
beaglescout007 | 0:3dac1f1bc9e0 | 180 | } |
beaglescout007 | 0:3dac1f1bc9e0 | 181 | |
beaglescout007 | 0:3dac1f1bc9e0 | 182 | hhcd->hc[chnum].state = HC_XFRC; |
beaglescout007 | 0:3dac1f1bc9e0 | 183 | __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_XFRC); |
beaglescout007 | 0:3dac1f1bc9e0 | 184 | |
beaglescout007 | 0:3dac1f1bc9e0 | 185 | |
beaglescout007 | 0:3dac1f1bc9e0 | 186 | if ((hhcd->hc[chnum].ep_type == EP_TYPE_CTRL)|| |
beaglescout007 | 0:3dac1f1bc9e0 | 187 | (hhcd->hc[chnum].ep_type == EP_TYPE_BULK)) |
beaglescout007 | 0:3dac1f1bc9e0 | 188 | { |
beaglescout007 | 0:3dac1f1bc9e0 | 189 | __HAL_HCD_UNMASK_HALT_HC_INT(chnum); |
beaglescout007 | 0:3dac1f1bc9e0 | 190 | USB_HC_Halt(hhcd->Instance, chnum); |
beaglescout007 | 0:3dac1f1bc9e0 | 191 | __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_NAK); |
beaglescout007 | 0:3dac1f1bc9e0 | 192 | |
beaglescout007 | 0:3dac1f1bc9e0 | 193 | } |
beaglescout007 | 0:3dac1f1bc9e0 | 194 | else if(hhcd->hc[chnum].ep_type == EP_TYPE_INTR) |
beaglescout007 | 0:3dac1f1bc9e0 | 195 | { |
beaglescout007 | 0:3dac1f1bc9e0 | 196 | USBx_HC(chnum)->HCCHAR |= USB_OTG_HCCHAR_ODDFRM; |
beaglescout007 | 0:3dac1f1bc9e0 | 197 | __HAL_HCD_UNMASK_HALT_HC_INT(chnum); |
beaglescout007 | 0:3dac1f1bc9e0 | 198 | USB_HC_Halt(hhcd->Instance, chnum); |
beaglescout007 | 0:3dac1f1bc9e0 | 199 | __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_NAK); |
beaglescout007 | 0:3dac1f1bc9e0 | 200 | } |
beaglescout007 | 0:3dac1f1bc9e0 | 201 | else if(hhcd->hc[chnum].ep_type == EP_TYPE_ISOC) |
beaglescout007 | 0:3dac1f1bc9e0 | 202 | { |
beaglescout007 | 0:3dac1f1bc9e0 | 203 | USBx_HC(chnum)->HCCHAR |= USB_OTG_HCCHAR_ODDFRM; |
beaglescout007 | 0:3dac1f1bc9e0 | 204 | hhcd->hc[chnum].urb_state = URB_DONE; |
beaglescout007 | 0:3dac1f1bc9e0 | 205 | HAL_HCD_HC_NotifyURBChange_Callback(hhcd, chnum, hhcd->hc[chnum].urb_state); |
beaglescout007 | 0:3dac1f1bc9e0 | 206 | } |
beaglescout007 | 0:3dac1f1bc9e0 | 207 | hhcd->hc[chnum].toggle_in ^= 1; |
beaglescout007 | 0:3dac1f1bc9e0 | 208 | |
beaglescout007 | 0:3dac1f1bc9e0 | 209 | } |
beaglescout007 | 0:3dac1f1bc9e0 | 210 | else if ((USBx_HC(chnum)->HCINT) & USB_OTG_HCINT_CHH) |
beaglescout007 | 0:3dac1f1bc9e0 | 211 | { |
beaglescout007 | 0:3dac1f1bc9e0 | 212 | __HAL_HCD_MASK_HALT_HC_INT(chnum); |
beaglescout007 | 0:3dac1f1bc9e0 | 213 | |
beaglescout007 | 0:3dac1f1bc9e0 | 214 | if(hhcd->hc[chnum].state == HC_XFRC) |
beaglescout007 | 0:3dac1f1bc9e0 | 215 | { |
beaglescout007 | 0:3dac1f1bc9e0 | 216 | hhcd->hc[chnum].urb_state = URB_DONE; |
beaglescout007 | 0:3dac1f1bc9e0 | 217 | } |
beaglescout007 | 0:3dac1f1bc9e0 | 218 | |
beaglescout007 | 0:3dac1f1bc9e0 | 219 | else if (hhcd->hc[chnum].state == HC_NAK) |
beaglescout007 | 0:3dac1f1bc9e0 | 220 | { |
beaglescout007 | 0:3dac1f1bc9e0 | 221 | hhcd->hc[chnum].urb_state = URB_DONE; |
beaglescout007 | 0:3dac1f1bc9e0 | 222 | } |
beaglescout007 | 0:3dac1f1bc9e0 | 223 | |
beaglescout007 | 0:3dac1f1bc9e0 | 224 | else if (hhcd->hc[chnum].state == HC_STALL) |
beaglescout007 | 0:3dac1f1bc9e0 | 225 | { |
beaglescout007 | 0:3dac1f1bc9e0 | 226 | hhcd->hc[chnum].urb_state = URB_STALL; |
beaglescout007 | 0:3dac1f1bc9e0 | 227 | } |
beaglescout007 | 0:3dac1f1bc9e0 | 228 | |
beaglescout007 | 0:3dac1f1bc9e0 | 229 | else if (hhcd->hc[chnum].state == HC_XACTERR) |
beaglescout007 | 0:3dac1f1bc9e0 | 230 | { |
beaglescout007 | 0:3dac1f1bc9e0 | 231 | hhcd->hc[chnum].urb_state = URB_NOTREADY; |
beaglescout007 | 0:3dac1f1bc9e0 | 232 | } |
beaglescout007 | 0:3dac1f1bc9e0 | 233 | |
beaglescout007 | 0:3dac1f1bc9e0 | 234 | else if (hhcd->hc[chnum].state == HC_DATATGLERR) |
beaglescout007 | 0:3dac1f1bc9e0 | 235 | { |
beaglescout007 | 0:3dac1f1bc9e0 | 236 | hhcd->hc[chnum].urb_state = URB_ERROR; |
beaglescout007 | 0:3dac1f1bc9e0 | 237 | } |
beaglescout007 | 0:3dac1f1bc9e0 | 238 | |
beaglescout007 | 0:3dac1f1bc9e0 | 239 | __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_CHH); |
beaglescout007 | 0:3dac1f1bc9e0 | 240 | HAL_HCD_HC_NotifyURBChange_Callback(hhcd, chnum, hhcd->hc[chnum].urb_state); |
beaglescout007 | 0:3dac1f1bc9e0 | 241 | } |
beaglescout007 | 0:3dac1f1bc9e0 | 242 | |
beaglescout007 | 0:3dac1f1bc9e0 | 243 | else if ((USBx_HC(chnum)->HCINT) & USB_OTG_HCINT_TXERR) |
beaglescout007 | 0:3dac1f1bc9e0 | 244 | { |
beaglescout007 | 0:3dac1f1bc9e0 | 245 | __HAL_HCD_UNMASK_HALT_HC_INT(chnum); |
beaglescout007 | 0:3dac1f1bc9e0 | 246 | hhcd->hc[chnum].state = HC_XACTERR; |
beaglescout007 | 0:3dac1f1bc9e0 | 247 | USB_HC_Halt(hhcd->Instance, chnum); |
beaglescout007 | 0:3dac1f1bc9e0 | 248 | __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_TXERR); |
beaglescout007 | 0:3dac1f1bc9e0 | 249 | } |
beaglescout007 | 0:3dac1f1bc9e0 | 250 | else if ((USBx_HC(chnum)->HCINT) & USB_OTG_HCINT_NAK) |
beaglescout007 | 0:3dac1f1bc9e0 | 251 | { |
beaglescout007 | 0:3dac1f1bc9e0 | 252 | if(hhcd->hc[chnum].ep_type == EP_TYPE_INTR) |
beaglescout007 | 0:3dac1f1bc9e0 | 253 | { |
beaglescout007 | 0:3dac1f1bc9e0 | 254 | __HAL_HCD_UNMASK_HALT_HC_INT(chnum); |
beaglescout007 | 0:3dac1f1bc9e0 | 255 | USB_HC_Halt(hhcd->Instance, chnum); |
beaglescout007 | 0:3dac1f1bc9e0 | 256 | } |
beaglescout007 | 0:3dac1f1bc9e0 | 257 | else if (hhcd->hc[chnum].ep_type == EP_TYPE_CTRL) |
beaglescout007 | 0:3dac1f1bc9e0 | 258 | { |
beaglescout007 | 0:3dac1f1bc9e0 | 259 | /* re-activate the channel */ |
beaglescout007 | 0:3dac1f1bc9e0 | 260 | USBx_HC(chnum)->HCCHAR &= ~USB_OTG_HCCHAR_CHDIS; |
beaglescout007 | 0:3dac1f1bc9e0 | 261 | USBx_HC(chnum)->HCCHAR |= USB_OTG_HCCHAR_CHENA; |
beaglescout007 | 0:3dac1f1bc9e0 | 262 | |
beaglescout007 | 0:3dac1f1bc9e0 | 263 | } |
beaglescout007 | 0:3dac1f1bc9e0 | 264 | |
beaglescout007 | 0:3dac1f1bc9e0 | 265 | else if (hhcd->hc[chnum].ep_type == EP_TYPE_BULK) |
beaglescout007 | 0:3dac1f1bc9e0 | 266 | { |
beaglescout007 | 0:3dac1f1bc9e0 | 267 | __HAL_HCD_UNMASK_HALT_HC_INT(chnum); |
beaglescout007 | 0:3dac1f1bc9e0 | 268 | USB_HC_Halt(hhcd->Instance, chnum); |
beaglescout007 | 0:3dac1f1bc9e0 | 269 | } |
beaglescout007 | 0:3dac1f1bc9e0 | 270 | |
beaglescout007 | 0:3dac1f1bc9e0 | 271 | hhcd->hc[chnum].state = HC_NAK; |
beaglescout007 | 0:3dac1f1bc9e0 | 272 | __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_NAK); |
beaglescout007 | 0:3dac1f1bc9e0 | 273 | } |
beaglescout007 | 0:3dac1f1bc9e0 | 274 | } |
beaglescout007 | 0:3dac1f1bc9e0 | 275 | |
beaglescout007 | 0:3dac1f1bc9e0 | 276 | /** |
beaglescout007 | 0:3dac1f1bc9e0 | 277 | * @brief This function handles Host Channel OUT interrupt requests. |
beaglescout007 | 0:3dac1f1bc9e0 | 278 | * @param hhcd: HCD handle |
beaglescout007 | 0:3dac1f1bc9e0 | 279 | * @param chnum : Channel number |
beaglescout007 | 0:3dac1f1bc9e0 | 280 | * This parameter can be a value from 1 to 15 |
beaglescout007 | 0:3dac1f1bc9e0 | 281 | * @retval none |
beaglescout007 | 0:3dac1f1bc9e0 | 282 | */ |
beaglescout007 | 0:3dac1f1bc9e0 | 283 | static void HCD_HC_OUT_IRQHandler (HCD_HandleTypeDef *hhcd, uint8_t chnum) |
beaglescout007 | 0:3dac1f1bc9e0 | 284 | { |
beaglescout007 | 0:3dac1f1bc9e0 | 285 | USB_OTG_GlobalTypeDef *USBx = hhcd->Instance; |
beaglescout007 | 0:3dac1f1bc9e0 | 286 | |
beaglescout007 | 0:3dac1f1bc9e0 | 287 | if ((USBx_HC(chnum)->HCINT) & USB_OTG_HCINT_AHBERR) |
beaglescout007 | 0:3dac1f1bc9e0 | 288 | { |
beaglescout007 | 0:3dac1f1bc9e0 | 289 | __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_AHBERR); |
beaglescout007 | 0:3dac1f1bc9e0 | 290 | __HAL_HCD_UNMASK_HALT_HC_INT(chnum); |
beaglescout007 | 0:3dac1f1bc9e0 | 291 | } |
beaglescout007 | 0:3dac1f1bc9e0 | 292 | else if ((USBx_HC(chnum)->HCINT) & USB_OTG_HCINT_ACK) |
beaglescout007 | 0:3dac1f1bc9e0 | 293 | { |
beaglescout007 | 0:3dac1f1bc9e0 | 294 | __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_ACK); |
beaglescout007 | 0:3dac1f1bc9e0 | 295 | |
beaglescout007 | 0:3dac1f1bc9e0 | 296 | if( hhcd->hc[chnum].do_ping == 1) |
beaglescout007 | 0:3dac1f1bc9e0 | 297 | { |
beaglescout007 | 0:3dac1f1bc9e0 | 298 | hhcd->hc[chnum].state = HC_NYET; |
beaglescout007 | 0:3dac1f1bc9e0 | 299 | __HAL_HCD_UNMASK_HALT_HC_INT(chnum); |
beaglescout007 | 0:3dac1f1bc9e0 | 300 | USB_HC_Halt(hhcd->Instance, chnum); |
beaglescout007 | 0:3dac1f1bc9e0 | 301 | hhcd->hc[chnum].urb_state = URB_NOTREADY; |
beaglescout007 | 0:3dac1f1bc9e0 | 302 | } |
beaglescout007 | 0:3dac1f1bc9e0 | 303 | } |
beaglescout007 | 0:3dac1f1bc9e0 | 304 | |
beaglescout007 | 0:3dac1f1bc9e0 | 305 | else if ((USBx_HC(chnum)->HCINT) & USB_OTG_HCINT_NYET) |
beaglescout007 | 0:3dac1f1bc9e0 | 306 | { |
beaglescout007 | 0:3dac1f1bc9e0 | 307 | hhcd->hc[chnum].state = HC_NYET; |
beaglescout007 | 0:3dac1f1bc9e0 | 308 | __HAL_HCD_UNMASK_HALT_HC_INT(chnum); |
beaglescout007 | 0:3dac1f1bc9e0 | 309 | USB_HC_Halt(hhcd->Instance, chnum); |
beaglescout007 | 0:3dac1f1bc9e0 | 310 | __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_NYET); |
beaglescout007 | 0:3dac1f1bc9e0 | 311 | |
beaglescout007 | 0:3dac1f1bc9e0 | 312 | } |
beaglescout007 | 0:3dac1f1bc9e0 | 313 | |
beaglescout007 | 0:3dac1f1bc9e0 | 314 | else if ((USBx_HC(chnum)->HCINT) & USB_OTG_HCINT_FRMOR) |
beaglescout007 | 0:3dac1f1bc9e0 | 315 | { |
beaglescout007 | 0:3dac1f1bc9e0 | 316 | __HAL_HCD_UNMASK_HALT_HC_INT(chnum); |
beaglescout007 | 0:3dac1f1bc9e0 | 317 | USB_HC_Halt(hhcd->Instance, chnum); |
beaglescout007 | 0:3dac1f1bc9e0 | 318 | __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_FRMOR); |
beaglescout007 | 0:3dac1f1bc9e0 | 319 | } |
beaglescout007 | 0:3dac1f1bc9e0 | 320 | |
beaglescout007 | 0:3dac1f1bc9e0 | 321 | else if ((USBx_HC(chnum)->HCINT) & USB_OTG_HCINT_XFRC) |
beaglescout007 | 0:3dac1f1bc9e0 | 322 | { |
beaglescout007 | 0:3dac1f1bc9e0 | 323 | __HAL_HCD_UNMASK_HALT_HC_INT(chnum); |
beaglescout007 | 0:3dac1f1bc9e0 | 324 | USB_HC_Halt(hhcd->Instance, chnum); |
beaglescout007 | 0:3dac1f1bc9e0 | 325 | __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_XFRC); |
beaglescout007 | 0:3dac1f1bc9e0 | 326 | hhcd->hc[chnum].state = HC_XFRC; |
beaglescout007 | 0:3dac1f1bc9e0 | 327 | |
beaglescout007 | 0:3dac1f1bc9e0 | 328 | } |
beaglescout007 | 0:3dac1f1bc9e0 | 329 | |
beaglescout007 | 0:3dac1f1bc9e0 | 330 | else if ((USBx_HC(chnum)->HCINT) & USB_OTG_HCINT_STALL) |
beaglescout007 | 0:3dac1f1bc9e0 | 331 | { |
beaglescout007 | 0:3dac1f1bc9e0 | 332 | __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_STALL); |
beaglescout007 | 0:3dac1f1bc9e0 | 333 | __HAL_HCD_UNMASK_HALT_HC_INT(chnum); |
beaglescout007 | 0:3dac1f1bc9e0 | 334 | USB_HC_Halt(hhcd->Instance, chnum); |
beaglescout007 | 0:3dac1f1bc9e0 | 335 | hhcd->hc[chnum].state = HC_STALL; |
beaglescout007 | 0:3dac1f1bc9e0 | 336 | } |
beaglescout007 | 0:3dac1f1bc9e0 | 337 | |
beaglescout007 | 0:3dac1f1bc9e0 | 338 | else if ((USBx_HC(chnum)->HCINT) & USB_OTG_HCINT_NAK) |
beaglescout007 | 0:3dac1f1bc9e0 | 339 | { |
beaglescout007 | 0:3dac1f1bc9e0 | 340 | __HAL_HCD_UNMASK_HALT_HC_INT(chnum); |
beaglescout007 | 0:3dac1f1bc9e0 | 341 | USB_HC_Halt(hhcd->Instance, chnum); |
beaglescout007 | 0:3dac1f1bc9e0 | 342 | hhcd->hc[chnum].state = HC_NAK; |
beaglescout007 | 0:3dac1f1bc9e0 | 343 | __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_NAK); |
beaglescout007 | 0:3dac1f1bc9e0 | 344 | } |
beaglescout007 | 0:3dac1f1bc9e0 | 345 | |
beaglescout007 | 0:3dac1f1bc9e0 | 346 | else if ((USBx_HC(chnum)->HCINT) & USB_OTG_HCINT_TXERR) |
beaglescout007 | 0:3dac1f1bc9e0 | 347 | { |
beaglescout007 | 0:3dac1f1bc9e0 | 348 | __HAL_HCD_UNMASK_HALT_HC_INT(chnum); |
beaglescout007 | 0:3dac1f1bc9e0 | 349 | USB_HC_Halt(hhcd->Instance, chnum); |
beaglescout007 | 0:3dac1f1bc9e0 | 350 | hhcd->hc[chnum].state = HC_XACTERR; |
beaglescout007 | 0:3dac1f1bc9e0 | 351 | __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_TXERR); |
beaglescout007 | 0:3dac1f1bc9e0 | 352 | } |
beaglescout007 | 0:3dac1f1bc9e0 | 353 | |
beaglescout007 | 0:3dac1f1bc9e0 | 354 | else if ((USBx_HC(chnum)->HCINT) & USB_OTG_HCINT_DTERR) |
beaglescout007 | 0:3dac1f1bc9e0 | 355 | { |
beaglescout007 | 0:3dac1f1bc9e0 | 356 | __HAL_HCD_UNMASK_HALT_HC_INT(chnum); |
beaglescout007 | 0:3dac1f1bc9e0 | 357 | USB_HC_Halt(hhcd->Instance, chnum); |
beaglescout007 | 0:3dac1f1bc9e0 | 358 | __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_NAK); |
beaglescout007 | 0:3dac1f1bc9e0 | 359 | __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_DTERR); |
beaglescout007 | 0:3dac1f1bc9e0 | 360 | hhcd->hc[chnum].state = HC_DATATGLERR; |
beaglescout007 | 0:3dac1f1bc9e0 | 361 | } |
beaglescout007 | 0:3dac1f1bc9e0 | 362 | |
beaglescout007 | 0:3dac1f1bc9e0 | 363 | |
beaglescout007 | 0:3dac1f1bc9e0 | 364 | else if ((USBx_HC(chnum)->HCINT) & USB_OTG_HCINT_CHH) |
beaglescout007 | 0:3dac1f1bc9e0 | 365 | { |
beaglescout007 | 0:3dac1f1bc9e0 | 366 | __HAL_HCD_MASK_HALT_HC_INT(chnum); |
beaglescout007 | 0:3dac1f1bc9e0 | 367 | |
beaglescout007 | 0:3dac1f1bc9e0 | 368 | if(hhcd->hc[chnum].state == HC_XFRC) |
beaglescout007 | 0:3dac1f1bc9e0 | 369 | { |
beaglescout007 | 0:3dac1f1bc9e0 | 370 | hhcd->hc[chnum].urb_state = URB_DONE; |
beaglescout007 | 0:3dac1f1bc9e0 | 371 | if (hhcd->hc[chnum].ep_type == EP_TYPE_BULK) |
beaglescout007 | 0:3dac1f1bc9e0 | 372 | { |
beaglescout007 | 0:3dac1f1bc9e0 | 373 | hhcd->hc[chnum].toggle_out ^= 1; |
beaglescout007 | 0:3dac1f1bc9e0 | 374 | } |
beaglescout007 | 0:3dac1f1bc9e0 | 375 | } |
beaglescout007 | 0:3dac1f1bc9e0 | 376 | else if (hhcd->hc[chnum].state == HC_NAK) |
beaglescout007 | 0:3dac1f1bc9e0 | 377 | { |
beaglescout007 | 0:3dac1f1bc9e0 | 378 | hhcd->hc[chnum].urb_state = URB_NOTREADY; |
beaglescout007 | 0:3dac1f1bc9e0 | 379 | } |
beaglescout007 | 0:3dac1f1bc9e0 | 380 | |
beaglescout007 | 0:3dac1f1bc9e0 | 381 | else if (hhcd->hc[chnum].state == HC_NYET) |
beaglescout007 | 0:3dac1f1bc9e0 | 382 | { |
beaglescout007 | 0:3dac1f1bc9e0 | 383 | hhcd->hc[chnum].urb_state = URB_NOTREADY; |
beaglescout007 | 0:3dac1f1bc9e0 | 384 | hhcd->hc[chnum].do_ping = 0; |
beaglescout007 | 0:3dac1f1bc9e0 | 385 | } |
beaglescout007 | 0:3dac1f1bc9e0 | 386 | |
beaglescout007 | 0:3dac1f1bc9e0 | 387 | else if (hhcd->hc[chnum].state == HC_STALL) |
beaglescout007 | 0:3dac1f1bc9e0 | 388 | { |
beaglescout007 | 0:3dac1f1bc9e0 | 389 | hhcd->hc[chnum].urb_state = URB_STALL; |
beaglescout007 | 0:3dac1f1bc9e0 | 390 | } |
beaglescout007 | 0:3dac1f1bc9e0 | 391 | |
beaglescout007 | 0:3dac1f1bc9e0 | 392 | else if(hhcd->hc[chnum].state == HC_XACTERR) |
beaglescout007 | 0:3dac1f1bc9e0 | 393 | { |
beaglescout007 | 0:3dac1f1bc9e0 | 394 | hhcd->hc[chnum].urb_state = URB_NOTREADY; |
beaglescout007 | 0:3dac1f1bc9e0 | 395 | } |
beaglescout007 | 0:3dac1f1bc9e0 | 396 | |
beaglescout007 | 0:3dac1f1bc9e0 | 397 | else if (hhcd->hc[chnum].state == HC_DATATGLERR) |
beaglescout007 | 0:3dac1f1bc9e0 | 398 | { |
beaglescout007 | 0:3dac1f1bc9e0 | 399 | hhcd->hc[chnum].urb_state = URB_ERROR; |
beaglescout007 | 0:3dac1f1bc9e0 | 400 | } |
beaglescout007 | 0:3dac1f1bc9e0 | 401 | |
beaglescout007 | 0:3dac1f1bc9e0 | 402 | __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_CHH); |
beaglescout007 | 0:3dac1f1bc9e0 | 403 | HAL_HCD_HC_NotifyURBChange_Callback(hhcd, chnum, hhcd->hc[chnum].urb_state); |
beaglescout007 | 0:3dac1f1bc9e0 | 404 | } |
beaglescout007 | 0:3dac1f1bc9e0 | 405 | } |
beaglescout007 | 0:3dac1f1bc9e0 | 406 | |
beaglescout007 | 0:3dac1f1bc9e0 | 407 | /** |
beaglescout007 | 0:3dac1f1bc9e0 | 408 | * @brief This function handles Rx Queue Level interrupt requests. |
beaglescout007 | 0:3dac1f1bc9e0 | 409 | * @param hhcd: HCD handle |
beaglescout007 | 0:3dac1f1bc9e0 | 410 | * @retval none |
beaglescout007 | 0:3dac1f1bc9e0 | 411 | */ |
beaglescout007 | 0:3dac1f1bc9e0 | 412 | static void HCD_RXQLVL_IRQHandler (HCD_HandleTypeDef *hhcd) |
beaglescout007 | 0:3dac1f1bc9e0 | 413 | { |
beaglescout007 | 0:3dac1f1bc9e0 | 414 | USB_OTG_GlobalTypeDef *USBx = hhcd->Instance; |
beaglescout007 | 0:3dac1f1bc9e0 | 415 | uint8_t channelnum =0; |
beaglescout007 | 0:3dac1f1bc9e0 | 416 | uint32_t pktsts; |
beaglescout007 | 0:3dac1f1bc9e0 | 417 | uint32_t pktcnt; |
beaglescout007 | 0:3dac1f1bc9e0 | 418 | uint32_t temp = 0; |
beaglescout007 | 0:3dac1f1bc9e0 | 419 | |
beaglescout007 | 0:3dac1f1bc9e0 | 420 | temp = hhcd->Instance->GRXSTSP ; |
beaglescout007 | 0:3dac1f1bc9e0 | 421 | channelnum = temp & USB_OTG_GRXSTSP_EPNUM; |
beaglescout007 | 0:3dac1f1bc9e0 | 422 | pktsts = (temp & USB_OTG_GRXSTSP_PKTSTS) >> 17; |
beaglescout007 | 0:3dac1f1bc9e0 | 423 | pktcnt = (temp & USB_OTG_GRXSTSP_BCNT) >> 4; |
beaglescout007 | 0:3dac1f1bc9e0 | 424 | |
beaglescout007 | 0:3dac1f1bc9e0 | 425 | switch (pktsts) |
beaglescout007 | 0:3dac1f1bc9e0 | 426 | { |
beaglescout007 | 0:3dac1f1bc9e0 | 427 | case GRXSTS_PKTSTS_IN: |
beaglescout007 | 0:3dac1f1bc9e0 | 428 | /* Read the data into the host buffer. */ |
beaglescout007 | 0:3dac1f1bc9e0 | 429 | if ((pktcnt > 0) && (hhcd->hc[channelnum].xfer_buff != (void *)0)) |
beaglescout007 | 0:3dac1f1bc9e0 | 430 | { |
beaglescout007 | 0:3dac1f1bc9e0 | 431 | |
beaglescout007 | 0:3dac1f1bc9e0 | 432 | USB_ReadPacket(hhcd->Instance, hhcd->hc[channelnum].xfer_buff, pktcnt); |
beaglescout007 | 0:3dac1f1bc9e0 | 433 | |
beaglescout007 | 0:3dac1f1bc9e0 | 434 | /*manage multiple Xfer */ |
beaglescout007 | 0:3dac1f1bc9e0 | 435 | hhcd->hc[channelnum].xfer_buff += pktcnt; |
beaglescout007 | 0:3dac1f1bc9e0 | 436 | hhcd->hc[channelnum].xfer_count += pktcnt; |
beaglescout007 | 0:3dac1f1bc9e0 | 437 | |
beaglescout007 | 0:3dac1f1bc9e0 | 438 | if((USBx_HC(channelnum)->HCTSIZ & USB_OTG_HCTSIZ_PKTCNT) > 0) |
beaglescout007 | 0:3dac1f1bc9e0 | 439 | { |
beaglescout007 | 0:3dac1f1bc9e0 | 440 | /* re-activate the channel when more packets are expected */ |
beaglescout007 | 0:3dac1f1bc9e0 | 441 | USBx_HC(channelnum)->HCCHAR &= ~USB_OTG_HCCHAR_CHDIS; |
beaglescout007 | 0:3dac1f1bc9e0 | 442 | USBx_HC(channelnum)->HCCHAR |= USB_OTG_HCCHAR_CHENA; |
beaglescout007 | 0:3dac1f1bc9e0 | 443 | hhcd->hc[channelnum].toggle_in ^= 1; |
beaglescout007 | 0:3dac1f1bc9e0 | 444 | } |
beaglescout007 | 0:3dac1f1bc9e0 | 445 | } |
beaglescout007 | 0:3dac1f1bc9e0 | 446 | break; |
beaglescout007 | 0:3dac1f1bc9e0 | 447 | |
beaglescout007 | 0:3dac1f1bc9e0 | 448 | case GRXSTS_PKTSTS_DATA_TOGGLE_ERR: |
beaglescout007 | 0:3dac1f1bc9e0 | 449 | break; |
beaglescout007 | 0:3dac1f1bc9e0 | 450 | case GRXSTS_PKTSTS_IN_XFER_COMP: |
beaglescout007 | 0:3dac1f1bc9e0 | 451 | case GRXSTS_PKTSTS_CH_HALTED: |
beaglescout007 | 0:3dac1f1bc9e0 | 452 | default: |
beaglescout007 | 0:3dac1f1bc9e0 | 453 | break; |
beaglescout007 | 0:3dac1f1bc9e0 | 454 | } |
beaglescout007 | 0:3dac1f1bc9e0 | 455 | } |
beaglescout007 | 0:3dac1f1bc9e0 | 456 | |
beaglescout007 | 0:3dac1f1bc9e0 | 457 | /** |
beaglescout007 | 0:3dac1f1bc9e0 | 458 | * @brief This function handles Host Port interrupt requests. |
beaglescout007 | 0:3dac1f1bc9e0 | 459 | * @param hhcd: HCD handle |
beaglescout007 | 0:3dac1f1bc9e0 | 460 | * @retval none |
beaglescout007 | 0:3dac1f1bc9e0 | 461 | */ |
beaglescout007 | 0:3dac1f1bc9e0 | 462 | static void HCD_Port_IRQHandler (HCD_HandleTypeDef *hhcd) |
beaglescout007 | 0:3dac1f1bc9e0 | 463 | { |
beaglescout007 | 0:3dac1f1bc9e0 | 464 | USB_OTG_GlobalTypeDef *USBx = hhcd->Instance; |
beaglescout007 | 0:3dac1f1bc9e0 | 465 | __IO uint32_t hprt0, hprt0_dup; |
beaglescout007 | 0:3dac1f1bc9e0 | 466 | |
beaglescout007 | 0:3dac1f1bc9e0 | 467 | /* Handle Host Port Interrupts */ |
beaglescout007 | 0:3dac1f1bc9e0 | 468 | hprt0 = USBx_HPRT0; |
beaglescout007 | 0:3dac1f1bc9e0 | 469 | hprt0_dup = USBx_HPRT0; |
beaglescout007 | 0:3dac1f1bc9e0 | 470 | |
beaglescout007 | 0:3dac1f1bc9e0 | 471 | hprt0_dup &= ~(USB_OTG_HPRT_PENA | USB_OTG_HPRT_PCDET |\ |
beaglescout007 | 0:3dac1f1bc9e0 | 472 | USB_OTG_HPRT_PENCHNG | USB_OTG_HPRT_POCCHNG ); |
beaglescout007 | 0:3dac1f1bc9e0 | 473 | |
beaglescout007 | 0:3dac1f1bc9e0 | 474 | /* Check wether Port Connect Detected */ |
beaglescout007 | 0:3dac1f1bc9e0 | 475 | if((hprt0 & USB_OTG_HPRT_PCDET) == USB_OTG_HPRT_PCDET) |
beaglescout007 | 0:3dac1f1bc9e0 | 476 | { |
beaglescout007 | 0:3dac1f1bc9e0 | 477 | if((hprt0 & USB_OTG_HPRT_PCSTS) == USB_OTG_HPRT_PCSTS) |
beaglescout007 | 0:3dac1f1bc9e0 | 478 | { |
beaglescout007 | 0:3dac1f1bc9e0 | 479 | USB_MASK_INTERRUPT(hhcd->Instance, USB_OTG_GINTSTS_DISCINT); |
beaglescout007 | 0:3dac1f1bc9e0 | 480 | HAL_HCD_Connect_Callback(hhcd); |
beaglescout007 | 0:3dac1f1bc9e0 | 481 | } |
beaglescout007 | 0:3dac1f1bc9e0 | 482 | hprt0_dup |= USB_OTG_HPRT_PCDET; |
beaglescout007 | 0:3dac1f1bc9e0 | 483 | |
beaglescout007 | 0:3dac1f1bc9e0 | 484 | } |
beaglescout007 | 0:3dac1f1bc9e0 | 485 | |
beaglescout007 | 0:3dac1f1bc9e0 | 486 | /* Check whether Port Enable Changed */ |
beaglescout007 | 0:3dac1f1bc9e0 | 487 | if((hprt0 & USB_OTG_HPRT_PENCHNG) == USB_OTG_HPRT_PENCHNG) |
beaglescout007 | 0:3dac1f1bc9e0 | 488 | { |
beaglescout007 | 0:3dac1f1bc9e0 | 489 | hprt0_dup |= USB_OTG_HPRT_PENCHNG; |
beaglescout007 | 0:3dac1f1bc9e0 | 490 | |
beaglescout007 | 0:3dac1f1bc9e0 | 491 | if((hprt0 & USB_OTG_HPRT_PENA) == USB_OTG_HPRT_PENA) |
beaglescout007 | 0:3dac1f1bc9e0 | 492 | { |
beaglescout007 | 0:3dac1f1bc9e0 | 493 | if(hhcd->Init.phy_itface == USB_OTG_EMBEDDED_PHY) |
beaglescout007 | 0:3dac1f1bc9e0 | 494 | { |
beaglescout007 | 0:3dac1f1bc9e0 | 495 | if ((hprt0 & USB_OTG_HPRT_PSPD) == (HPRT0_PRTSPD_LOW_SPEED << 17)) |
beaglescout007 | 0:3dac1f1bc9e0 | 496 | { |
beaglescout007 | 0:3dac1f1bc9e0 | 497 | USB_InitFSLSPClkSel(hhcd->Instance ,HCFG_6_MHZ ); |
beaglescout007 | 0:3dac1f1bc9e0 | 498 | } |
beaglescout007 | 0:3dac1f1bc9e0 | 499 | else |
beaglescout007 | 0:3dac1f1bc9e0 | 500 | { |
beaglescout007 | 0:3dac1f1bc9e0 | 501 | USB_InitFSLSPClkSel(hhcd->Instance ,HCFG_48_MHZ ); |
beaglescout007 | 0:3dac1f1bc9e0 | 502 | } |
beaglescout007 | 0:3dac1f1bc9e0 | 503 | } |
beaglescout007 | 0:3dac1f1bc9e0 | 504 | else |
beaglescout007 | 0:3dac1f1bc9e0 | 505 | { |
beaglescout007 | 0:3dac1f1bc9e0 | 506 | if(hhcd->Init.speed == HCD_SPEED_FULL) |
beaglescout007 | 0:3dac1f1bc9e0 | 507 | { |
beaglescout007 | 0:3dac1f1bc9e0 | 508 | USBx_HOST->HFIR = (uint32_t)60000; |
beaglescout007 | 0:3dac1f1bc9e0 | 509 | } |
beaglescout007 | 0:3dac1f1bc9e0 | 510 | } |
beaglescout007 | 0:3dac1f1bc9e0 | 511 | HAL_HCD_Connect_Callback(hhcd); |
beaglescout007 | 0:3dac1f1bc9e0 | 512 | |
beaglescout007 | 0:3dac1f1bc9e0 | 513 | if(hhcd->Init.speed == HCD_SPEED_HIGH) |
beaglescout007 | 0:3dac1f1bc9e0 | 514 | { |
beaglescout007 | 0:3dac1f1bc9e0 | 515 | USB_UNMASK_INTERRUPT(hhcd->Instance, USB_OTG_GINTSTS_DISCINT); |
beaglescout007 | 0:3dac1f1bc9e0 | 516 | } |
beaglescout007 | 0:3dac1f1bc9e0 | 517 | } |
beaglescout007 | 0:3dac1f1bc9e0 | 518 | else |
beaglescout007 | 0:3dac1f1bc9e0 | 519 | { |
beaglescout007 | 0:3dac1f1bc9e0 | 520 | /* Cleanup HPRT */ |
beaglescout007 | 0:3dac1f1bc9e0 | 521 | USBx_HPRT0 &= ~(USB_OTG_HPRT_PENA | USB_OTG_HPRT_PCDET |\ |
beaglescout007 | 0:3dac1f1bc9e0 | 522 | USB_OTG_HPRT_PENCHNG | USB_OTG_HPRT_POCCHNG ); |
beaglescout007 | 0:3dac1f1bc9e0 | 523 | |
beaglescout007 | 0:3dac1f1bc9e0 | 524 | USB_UNMASK_INTERRUPT(hhcd->Instance, USB_OTG_GINTSTS_DISCINT); |
beaglescout007 | 0:3dac1f1bc9e0 | 525 | } |
beaglescout007 | 0:3dac1f1bc9e0 | 526 | } |
beaglescout007 | 0:3dac1f1bc9e0 | 527 | |
beaglescout007 | 0:3dac1f1bc9e0 | 528 | /* Check For an overcurrent */ |
beaglescout007 | 0:3dac1f1bc9e0 | 529 | if((hprt0 & USB_OTG_HPRT_POCCHNG) == USB_OTG_HPRT_POCCHNG) |
beaglescout007 | 0:3dac1f1bc9e0 | 530 | { |
beaglescout007 | 0:3dac1f1bc9e0 | 531 | hprt0_dup |= USB_OTG_HPRT_POCCHNG; |
beaglescout007 | 0:3dac1f1bc9e0 | 532 | } |
beaglescout007 | 0:3dac1f1bc9e0 | 533 | |
beaglescout007 | 0:3dac1f1bc9e0 | 534 | /* Clear Port Interrupts */ |
beaglescout007 | 0:3dac1f1bc9e0 | 535 | USBx_HPRT0 = hprt0_dup; |
beaglescout007 | 0:3dac1f1bc9e0 | 536 | } |
beaglescout007 | 0:3dac1f1bc9e0 | 537 | |
beaglescout007 | 0:3dac1f1bc9e0 | 538 | #endif |
beaglescout007 | 0:3dac1f1bc9e0 | 539 | |
beaglescout007 | 0:3dac1f1bc9e0 | 540 |