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