Usb read

Dependencies:   FATFileSystem

Fork of F401RE-USBHost by Norimasa Okamoto

Committer:
va009039
Date:
Mon Jun 09 09:00:49 2014 +0000
Revision:
11:61843badd06e
Child:
13:8774c07f12a5
Simple USBHost for Nucleo F401RE

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 11:61843badd06e 202 hhcd->hc[chnum].toggle_in ^= 1;
va009039 11:61843badd06e 203
va009039 11:61843badd06e 204 }
va009039 11:61843badd06e 205 else if ((USBx_HC(chnum)->HCINT) & USB_OTG_HCINT_CHH)
va009039 11:61843badd06e 206 {
va009039 11:61843badd06e 207 __HAL_HCD_MASK_HALT_HC_INT(chnum);
va009039 11:61843badd06e 208
va009039 11:61843badd06e 209 if(hhcd->hc[chnum].state == HC_XFRC)
va009039 11:61843badd06e 210 {
va009039 11:61843badd06e 211 hhcd->hc[chnum].urb_state = URB_DONE;
va009039 11:61843badd06e 212 }
va009039 11:61843badd06e 213
va009039 11:61843badd06e 214 else if (hhcd->hc[chnum].state == HC_NAK)
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_STALL)
va009039 11:61843badd06e 220 {
va009039 11:61843badd06e 221 hhcd->hc[chnum].urb_state = URB_STALL;
va009039 11:61843badd06e 222 }
va009039 11:61843badd06e 223
va009039 11:61843badd06e 224 else if (hhcd->hc[chnum].state == HC_XACTERR)
va009039 11:61843badd06e 225 {
va009039 11:61843badd06e 226 hhcd->hc[chnum].urb_state = URB_NOTREADY;
va009039 11:61843badd06e 227 }
va009039 11:61843badd06e 228
va009039 11:61843badd06e 229 else if (hhcd->hc[chnum].state == HC_DATATGLERR)
va009039 11:61843badd06e 230 {
va009039 11:61843badd06e 231 hhcd->hc[chnum].urb_state = URB_ERROR;
va009039 11:61843badd06e 232 }
va009039 11:61843badd06e 233
va009039 11:61843badd06e 234 __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_CHH);
va009039 11:61843badd06e 235 HAL_HCD_HC_NotifyURBChange_Callback(hhcd, chnum, hhcd->hc[chnum].urb_state);
va009039 11:61843badd06e 236 }
va009039 11:61843badd06e 237
va009039 11:61843badd06e 238 else if ((USBx_HC(chnum)->HCINT) & USB_OTG_HCINT_TXERR)
va009039 11:61843badd06e 239 {
va009039 11:61843badd06e 240 __HAL_HCD_UNMASK_HALT_HC_INT(chnum);
va009039 11:61843badd06e 241 hhcd->hc[chnum].state = HC_XACTERR;
va009039 11:61843badd06e 242 USB_HC_Halt(hhcd->Instance, chnum);
va009039 11:61843badd06e 243 __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_TXERR);
va009039 11:61843badd06e 244 }
va009039 11:61843badd06e 245 else if ((USBx_HC(chnum)->HCINT) & USB_OTG_HCINT_NAK)
va009039 11:61843badd06e 246 {
va009039 11:61843badd06e 247 if(hhcd->hc[chnum].ep_type == EP_TYPE_INTR)
va009039 11:61843badd06e 248 {
va009039 11:61843badd06e 249 __HAL_HCD_UNMASK_HALT_HC_INT(chnum);
va009039 11:61843badd06e 250 USB_HC_Halt(hhcd->Instance, chnum);
va009039 11:61843badd06e 251 }
va009039 11:61843badd06e 252 else if (hhcd->hc[chnum].ep_type == EP_TYPE_CTRL)
va009039 11:61843badd06e 253 {
va009039 11:61843badd06e 254 /* re-activate the channel */
va009039 11:61843badd06e 255 USBx_HC(chnum)->HCCHAR &= ~USB_OTG_HCCHAR_CHDIS;
va009039 11:61843badd06e 256 USBx_HC(chnum)->HCCHAR |= USB_OTG_HCCHAR_CHENA;
va009039 11:61843badd06e 257
va009039 11:61843badd06e 258 }
va009039 11:61843badd06e 259
va009039 11:61843badd06e 260 else if (hhcd->hc[chnum].ep_type == EP_TYPE_BULK)
va009039 11:61843badd06e 261 {
va009039 11:61843badd06e 262 __HAL_HCD_UNMASK_HALT_HC_INT(chnum);
va009039 11:61843badd06e 263 USB_HC_Halt(hhcd->Instance, chnum);
va009039 11:61843badd06e 264 }
va009039 11:61843badd06e 265
va009039 11:61843badd06e 266 hhcd->hc[chnum].state = HC_NAK;
va009039 11:61843badd06e 267 __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_NAK);
va009039 11:61843badd06e 268 }
va009039 11:61843badd06e 269 }
va009039 11:61843badd06e 270
va009039 11:61843badd06e 271 /**
va009039 11:61843badd06e 272 * @brief This function handles Host Channel OUT interrupt requests.
va009039 11:61843badd06e 273 * @param hhcd: HCD handle
va009039 11:61843badd06e 274 * @param chnum : Channel number
va009039 11:61843badd06e 275 * This parameter can be a value from 1 to 15
va009039 11:61843badd06e 276 * @retval none
va009039 11:61843badd06e 277 */
va009039 11:61843badd06e 278 static void HCD_HC_OUT_IRQHandler (HCD_HandleTypeDef *hhcd, uint8_t chnum)
va009039 11:61843badd06e 279 {
va009039 11:61843badd06e 280 USB_OTG_GlobalTypeDef *USBx = hhcd->Instance;
va009039 11:61843badd06e 281
va009039 11:61843badd06e 282 if ((USBx_HC(chnum)->HCINT) & USB_OTG_HCINT_AHBERR)
va009039 11:61843badd06e 283 {
va009039 11:61843badd06e 284 __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_AHBERR);
va009039 11:61843badd06e 285 __HAL_HCD_UNMASK_HALT_HC_INT(chnum);
va009039 11:61843badd06e 286 }
va009039 11:61843badd06e 287 else if ((USBx_HC(chnum)->HCINT) & USB_OTG_HCINT_ACK)
va009039 11:61843badd06e 288 {
va009039 11:61843badd06e 289 __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_ACK);
va009039 11:61843badd06e 290
va009039 11:61843badd06e 291 if( hhcd->hc[chnum].do_ping == 1)
va009039 11:61843badd06e 292 {
va009039 11:61843badd06e 293 hhcd->hc[chnum].state = HC_NYET;
va009039 11:61843badd06e 294 __HAL_HCD_UNMASK_HALT_HC_INT(chnum);
va009039 11:61843badd06e 295 USB_HC_Halt(hhcd->Instance, chnum);
va009039 11:61843badd06e 296 hhcd->hc[chnum].urb_state = URB_NOTREADY;
va009039 11:61843badd06e 297 }
va009039 11:61843badd06e 298 }
va009039 11:61843badd06e 299
va009039 11:61843badd06e 300 else if ((USBx_HC(chnum)->HCINT) & USB_OTG_HCINT_NYET)
va009039 11:61843badd06e 301 {
va009039 11:61843badd06e 302 hhcd->hc[chnum].state = HC_NYET;
va009039 11:61843badd06e 303 __HAL_HCD_UNMASK_HALT_HC_INT(chnum);
va009039 11:61843badd06e 304 USB_HC_Halt(hhcd->Instance, chnum);
va009039 11:61843badd06e 305 __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_NYET);
va009039 11:61843badd06e 306
va009039 11:61843badd06e 307 }
va009039 11:61843badd06e 308
va009039 11:61843badd06e 309 else if ((USBx_HC(chnum)->HCINT) & USB_OTG_HCINT_FRMOR)
va009039 11:61843badd06e 310 {
va009039 11:61843badd06e 311 __HAL_HCD_UNMASK_HALT_HC_INT(chnum);
va009039 11:61843badd06e 312 USB_HC_Halt(hhcd->Instance, chnum);
va009039 11:61843badd06e 313 __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_FRMOR);
va009039 11:61843badd06e 314 }
va009039 11:61843badd06e 315
va009039 11:61843badd06e 316 else if ((USBx_HC(chnum)->HCINT) & USB_OTG_HCINT_XFRC)
va009039 11:61843badd06e 317 {
va009039 11:61843badd06e 318 __HAL_HCD_UNMASK_HALT_HC_INT(chnum);
va009039 11:61843badd06e 319 USB_HC_Halt(hhcd->Instance, chnum);
va009039 11:61843badd06e 320 __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_XFRC);
va009039 11:61843badd06e 321 hhcd->hc[chnum].state = HC_XFRC;
va009039 11:61843badd06e 322
va009039 11:61843badd06e 323 }
va009039 11:61843badd06e 324
va009039 11:61843badd06e 325 else if ((USBx_HC(chnum)->HCINT) & USB_OTG_HCINT_STALL)
va009039 11:61843badd06e 326 {
va009039 11:61843badd06e 327 __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_STALL);
va009039 11:61843badd06e 328 __HAL_HCD_UNMASK_HALT_HC_INT(chnum);
va009039 11:61843badd06e 329 USB_HC_Halt(hhcd->Instance, chnum);
va009039 11:61843badd06e 330 hhcd->hc[chnum].state = HC_STALL;
va009039 11:61843badd06e 331 }
va009039 11:61843badd06e 332
va009039 11:61843badd06e 333 else if ((USBx_HC(chnum)->HCINT) & USB_OTG_HCINT_NAK)
va009039 11:61843badd06e 334 {
va009039 11:61843badd06e 335 __HAL_HCD_UNMASK_HALT_HC_INT(chnum);
va009039 11:61843badd06e 336 USB_HC_Halt(hhcd->Instance, chnum);
va009039 11:61843badd06e 337 hhcd->hc[chnum].state = HC_NAK;
va009039 11:61843badd06e 338 __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_NAK);
va009039 11:61843badd06e 339 }
va009039 11:61843badd06e 340
va009039 11:61843badd06e 341 else if ((USBx_HC(chnum)->HCINT) & USB_OTG_HCINT_TXERR)
va009039 11:61843badd06e 342 {
va009039 11:61843badd06e 343 __HAL_HCD_UNMASK_HALT_HC_INT(chnum);
va009039 11:61843badd06e 344 USB_HC_Halt(hhcd->Instance, chnum);
va009039 11:61843badd06e 345 hhcd->hc[chnum].state = HC_XACTERR;
va009039 11:61843badd06e 346 __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_TXERR);
va009039 11:61843badd06e 347 }
va009039 11:61843badd06e 348
va009039 11:61843badd06e 349 else if ((USBx_HC(chnum)->HCINT) & USB_OTG_HCINT_DTERR)
va009039 11:61843badd06e 350 {
va009039 11:61843badd06e 351 __HAL_HCD_UNMASK_HALT_HC_INT(chnum);
va009039 11:61843badd06e 352 USB_HC_Halt(hhcd->Instance, chnum);
va009039 11:61843badd06e 353 __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_NAK);
va009039 11:61843badd06e 354 __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_DTERR);
va009039 11:61843badd06e 355 hhcd->hc[chnum].state = HC_DATATGLERR;
va009039 11:61843badd06e 356 }
va009039 11:61843badd06e 357
va009039 11:61843badd06e 358
va009039 11:61843badd06e 359 else if ((USBx_HC(chnum)->HCINT) & USB_OTG_HCINT_CHH)
va009039 11:61843badd06e 360 {
va009039 11:61843badd06e 361 __HAL_HCD_MASK_HALT_HC_INT(chnum);
va009039 11:61843badd06e 362
va009039 11:61843badd06e 363 if(hhcd->hc[chnum].state == HC_XFRC)
va009039 11:61843badd06e 364 {
va009039 11:61843badd06e 365 hhcd->hc[chnum].urb_state = URB_DONE;
va009039 11:61843badd06e 366 if (hhcd->hc[chnum].ep_type == EP_TYPE_BULK)
va009039 11:61843badd06e 367 {
va009039 11:61843badd06e 368 hhcd->hc[chnum].toggle_out ^= 1;
va009039 11:61843badd06e 369 }
va009039 11:61843badd06e 370 }
va009039 11:61843badd06e 371 else if (hhcd->hc[chnum].state == HC_NAK)
va009039 11:61843badd06e 372 {
va009039 11:61843badd06e 373 hhcd->hc[chnum].urb_state = URB_NOTREADY;
va009039 11:61843badd06e 374 }
va009039 11:61843badd06e 375
va009039 11:61843badd06e 376 else if (hhcd->hc[chnum].state == HC_NYET)
va009039 11:61843badd06e 377 {
va009039 11:61843badd06e 378 hhcd->hc[chnum].urb_state = URB_NOTREADY;
va009039 11:61843badd06e 379 hhcd->hc[chnum].do_ping = 0;
va009039 11:61843badd06e 380 }
va009039 11:61843badd06e 381
va009039 11:61843badd06e 382 else if (hhcd->hc[chnum].state == HC_STALL)
va009039 11:61843badd06e 383 {
va009039 11:61843badd06e 384 hhcd->hc[chnum].urb_state = URB_STALL;
va009039 11:61843badd06e 385 }
va009039 11:61843badd06e 386
va009039 11:61843badd06e 387 else if(hhcd->hc[chnum].state == HC_XACTERR)
va009039 11:61843badd06e 388 {
va009039 11:61843badd06e 389 hhcd->hc[chnum].urb_state = URB_NOTREADY;
va009039 11:61843badd06e 390 }
va009039 11:61843badd06e 391
va009039 11:61843badd06e 392 else if (hhcd->hc[chnum].state == HC_DATATGLERR)
va009039 11:61843badd06e 393 {
va009039 11:61843badd06e 394 hhcd->hc[chnum].urb_state = URB_ERROR;
va009039 11:61843badd06e 395 }
va009039 11:61843badd06e 396
va009039 11:61843badd06e 397 __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_CHH);
va009039 11:61843badd06e 398 HAL_HCD_HC_NotifyURBChange_Callback(hhcd, chnum, hhcd->hc[chnum].urb_state);
va009039 11:61843badd06e 399 }
va009039 11:61843badd06e 400 }
va009039 11:61843badd06e 401
va009039 11:61843badd06e 402 /**
va009039 11:61843badd06e 403 * @brief This function handles Rx Queue Level interrupt requests.
va009039 11:61843badd06e 404 * @param hhcd: HCD handle
va009039 11:61843badd06e 405 * @retval none
va009039 11:61843badd06e 406 */
va009039 11:61843badd06e 407 static void HCD_RXQLVL_IRQHandler (HCD_HandleTypeDef *hhcd)
va009039 11:61843badd06e 408 {
va009039 11:61843badd06e 409 USB_OTG_GlobalTypeDef *USBx = hhcd->Instance;
va009039 11:61843badd06e 410 uint8_t channelnum =0;
va009039 11:61843badd06e 411 uint32_t pktsts;
va009039 11:61843badd06e 412 uint32_t pktcnt;
va009039 11:61843badd06e 413 uint32_t temp = 0;
va009039 11:61843badd06e 414
va009039 11:61843badd06e 415 temp = hhcd->Instance->GRXSTSP ;
va009039 11:61843badd06e 416 channelnum = temp & USB_OTG_GRXSTSP_EPNUM;
va009039 11:61843badd06e 417 pktsts = (temp & USB_OTG_GRXSTSP_PKTSTS) >> 17;
va009039 11:61843badd06e 418 pktcnt = (temp & USB_OTG_GRXSTSP_BCNT) >> 4;
va009039 11:61843badd06e 419
va009039 11:61843badd06e 420 switch (pktsts)
va009039 11:61843badd06e 421 {
va009039 11:61843badd06e 422 case GRXSTS_PKTSTS_IN:
va009039 11:61843badd06e 423 /* Read the data into the host buffer. */
va009039 11:61843badd06e 424 if ((pktcnt > 0) && (hhcd->hc[channelnum].xfer_buff != (void *)0))
va009039 11:61843badd06e 425 {
va009039 11:61843badd06e 426
va009039 11:61843badd06e 427 USB_ReadPacket(hhcd->Instance, hhcd->hc[channelnum].xfer_buff, pktcnt);
va009039 11:61843badd06e 428
va009039 11:61843badd06e 429 /*manage multiple Xfer */
va009039 11:61843badd06e 430 hhcd->hc[channelnum].xfer_buff += pktcnt;
va009039 11:61843badd06e 431 hhcd->hc[channelnum].xfer_count += pktcnt;
va009039 11:61843badd06e 432
va009039 11:61843badd06e 433 if((USBx_HC(channelnum)->HCTSIZ & USB_OTG_HCTSIZ_PKTCNT) > 0)
va009039 11:61843badd06e 434 {
va009039 11:61843badd06e 435 /* re-activate the channel when more packets are expected */
va009039 11:61843badd06e 436 USBx_HC(channelnum)->HCCHAR &= ~USB_OTG_HCCHAR_CHDIS;
va009039 11:61843badd06e 437 USBx_HC(channelnum)->HCCHAR |= USB_OTG_HCCHAR_CHENA;
va009039 11:61843badd06e 438 hhcd->hc[channelnum].toggle_in ^= 1;
va009039 11:61843badd06e 439 }
va009039 11:61843badd06e 440 }
va009039 11:61843badd06e 441 break;
va009039 11:61843badd06e 442
va009039 11:61843badd06e 443 case GRXSTS_PKTSTS_DATA_TOGGLE_ERR:
va009039 11:61843badd06e 444 break;
va009039 11:61843badd06e 445 case GRXSTS_PKTSTS_IN_XFER_COMP:
va009039 11:61843badd06e 446 case GRXSTS_PKTSTS_CH_HALTED:
va009039 11:61843badd06e 447 default:
va009039 11:61843badd06e 448 break;
va009039 11:61843badd06e 449 }
va009039 11:61843badd06e 450 }
va009039 11:61843badd06e 451
va009039 11:61843badd06e 452 /**
va009039 11:61843badd06e 453 * @brief This function handles Host Port interrupt requests.
va009039 11:61843badd06e 454 * @param hhcd: HCD handle
va009039 11:61843badd06e 455 * @retval none
va009039 11:61843badd06e 456 */
va009039 11:61843badd06e 457 static void HCD_Port_IRQHandler (HCD_HandleTypeDef *hhcd)
va009039 11:61843badd06e 458 {
va009039 11:61843badd06e 459 USB_OTG_GlobalTypeDef *USBx = hhcd->Instance;
va009039 11:61843badd06e 460 __IO uint32_t hprt0, hprt0_dup;
va009039 11:61843badd06e 461
va009039 11:61843badd06e 462 /* Handle Host Port Interrupts */
va009039 11:61843badd06e 463 hprt0 = USBx_HPRT0;
va009039 11:61843badd06e 464 hprt0_dup = USBx_HPRT0;
va009039 11:61843badd06e 465
va009039 11:61843badd06e 466 hprt0_dup &= ~(USB_OTG_HPRT_PENA | USB_OTG_HPRT_PCDET |\
va009039 11:61843badd06e 467 USB_OTG_HPRT_PENCHNG | USB_OTG_HPRT_POCCHNG );
va009039 11:61843badd06e 468
va009039 11:61843badd06e 469 /* Check wether Port Connect Detected */
va009039 11:61843badd06e 470 if((hprt0 & USB_OTG_HPRT_PCDET) == USB_OTG_HPRT_PCDET)
va009039 11:61843badd06e 471 {
va009039 11:61843badd06e 472 if((hprt0 & USB_OTG_HPRT_PCSTS) == USB_OTG_HPRT_PCSTS)
va009039 11:61843badd06e 473 {
va009039 11:61843badd06e 474 USB_MASK_INTERRUPT(hhcd->Instance, USB_OTG_GINTSTS_DISCINT);
va009039 11:61843badd06e 475 HAL_HCD_Connect_Callback(hhcd);
va009039 11:61843badd06e 476 }
va009039 11:61843badd06e 477 hprt0_dup |= USB_OTG_HPRT_PCDET;
va009039 11:61843badd06e 478
va009039 11:61843badd06e 479 }
va009039 11:61843badd06e 480
va009039 11:61843badd06e 481 /* Check whether Port Enable Changed */
va009039 11:61843badd06e 482 if((hprt0 & USB_OTG_HPRT_PENCHNG) == USB_OTG_HPRT_PENCHNG)
va009039 11:61843badd06e 483 {
va009039 11:61843badd06e 484 hprt0_dup |= USB_OTG_HPRT_PENCHNG;
va009039 11:61843badd06e 485
va009039 11:61843badd06e 486 if((hprt0 & USB_OTG_HPRT_PENA) == USB_OTG_HPRT_PENA)
va009039 11:61843badd06e 487 {
va009039 11:61843badd06e 488 if(hhcd->Init.phy_itface == USB_OTG_EMBEDDED_PHY)
va009039 11:61843badd06e 489 {
va009039 11:61843badd06e 490 if ((hprt0 & USB_OTG_HPRT_PSPD) == (HPRT0_PRTSPD_LOW_SPEED << 17))
va009039 11:61843badd06e 491 {
va009039 11:61843badd06e 492 USB_InitFSLSPClkSel(hhcd->Instance ,HCFG_6_MHZ );
va009039 11:61843badd06e 493 }
va009039 11:61843badd06e 494 else
va009039 11:61843badd06e 495 {
va009039 11:61843badd06e 496 USB_InitFSLSPClkSel(hhcd->Instance ,HCFG_48_MHZ );
va009039 11:61843badd06e 497 }
va009039 11:61843badd06e 498 }
va009039 11:61843badd06e 499 else
va009039 11:61843badd06e 500 {
va009039 11:61843badd06e 501 if(hhcd->Init.speed == HCD_SPEED_FULL)
va009039 11:61843badd06e 502 {
va009039 11:61843badd06e 503 USBx_HOST->HFIR = (uint32_t)60000;
va009039 11:61843badd06e 504 }
va009039 11:61843badd06e 505 }
va009039 11:61843badd06e 506 HAL_HCD_Connect_Callback(hhcd);
va009039 11:61843badd06e 507
va009039 11:61843badd06e 508 if(hhcd->Init.speed == HCD_SPEED_HIGH)
va009039 11:61843badd06e 509 {
va009039 11:61843badd06e 510 USB_UNMASK_INTERRUPT(hhcd->Instance, USB_OTG_GINTSTS_DISCINT);
va009039 11:61843badd06e 511 }
va009039 11:61843badd06e 512 }
va009039 11:61843badd06e 513 else
va009039 11:61843badd06e 514 {
va009039 11:61843badd06e 515 /* Cleanup HPRT */
va009039 11:61843badd06e 516 USBx_HPRT0 &= ~(USB_OTG_HPRT_PENA | USB_OTG_HPRT_PCDET |\
va009039 11:61843badd06e 517 USB_OTG_HPRT_PENCHNG | USB_OTG_HPRT_POCCHNG );
va009039 11:61843badd06e 518
va009039 11:61843badd06e 519 USB_UNMASK_INTERRUPT(hhcd->Instance, USB_OTG_GINTSTS_DISCINT);
va009039 11:61843badd06e 520 }
va009039 11:61843badd06e 521 }
va009039 11:61843badd06e 522
va009039 11:61843badd06e 523 /* Check For an overcurrent */
va009039 11:61843badd06e 524 if((hprt0 & USB_OTG_HPRT_POCCHNG) == USB_OTG_HPRT_POCCHNG)
va009039 11:61843badd06e 525 {
va009039 11:61843badd06e 526 hprt0_dup |= USB_OTG_HPRT_POCCHNG;
va009039 11:61843badd06e 527 }
va009039 11:61843badd06e 528
va009039 11:61843badd06e 529 /* Clear Port Interrupts */
va009039 11:61843badd06e 530 USBx_HPRT0 = hprt0_dup;
va009039 11:61843badd06e 531 }
va009039 11:61843badd06e 532
va009039 11:61843badd06e 533 #endif
va009039 11:61843badd06e 534