Usb read

Dependencies:   FATFileSystem

Fork of F401RE-USBHost by Norimasa Okamoto

Committer:
va009039
Date:
Tue Jun 10 13:38:41 2014 +0900
Revision:
13:8774c07f12a5
Parent:
11:61843badd06e
Child:
18:61554f238584
add USBHostC270

Who changed what in which revision?

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