at32f425_usb.h 54 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420
  1. /**
  2. **************************************************************************
  3. * @file at32f425_usb.h
  4. * @brief at32f425 usb header file
  5. **************************************************************************
  6. * Copyright notice & Disclaimer
  7. *
  8. * The software Board Support Package (BSP) that is made available to
  9. * download from Artery official website is the copyrighted work of Artery.
  10. * Artery authorizes customers to use, copy, and distribute the BSP
  11. * software and its related documentation for the purpose of design and
  12. * development in conjunction with Artery microcontrollers. Use of the
  13. * software is governed by this copyright notice and the following disclaimer.
  14. *
  15. * THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
  16. * GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS,
  17. * TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR
  18. * STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS,
  19. * INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
  20. * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
  21. *
  22. **************************************************************************
  23. */
  24. /* Define to prevent recursive inclusion -------------------------------------*/
  25. #ifndef __AT32F425_USB_H
  26. #define __AT32F425_USB_H
  27. #ifdef __cplusplus
  28. extern "C" {
  29. #endif
  30. /* Includes ------------------------------------------------------------------*/
  31. #include "at32f425.h"
  32. /** @addtogroup AT32F425_periph_driver
  33. * @{
  34. */
  35. /** @addtogroup USB
  36. * @{
  37. */
  38. /** @defgroup USB_global_interrupts_definition
  39. * @brief usb global interrupt mask
  40. * @{
  41. */
  42. #define USB_OTG_MODEMIS_INT ((uint32_t)0x00000002) /*!< usb otg mode mismatch interrupt */
  43. #define USB_OTG_OTGINT_INT ((uint32_t)0x00000004) /*!< usb otg interrupt */
  44. #define USB_OTG_SOF_INT ((uint32_t)0x00000008) /*!< usb otg sof interrupt */
  45. #define USB_OTG_RXFLVL_INT ((uint32_t)0x00000010) /*!< usb otg receive fifo non-empty interrupt */
  46. #define USB_OTG_NPTXFEMP_INT ((uint32_t)0x00000020) /*!< usb otg non-periodic tx fifo empty interrupt */
  47. #define USB_OTG_GINNAKEFF_INT ((uint32_t)0x00000040) /*!< usb otg global non-periodic in nak effective interrupt */
  48. #define USB_OTG_GOUTNAKEFF_INT ((uint32_t)0x00000080) /*!< usb otg global out nak effective interrupt */
  49. #define USB_OTG_ERLYSUSP_INT ((uint32_t)0x00000400) /*!< usb otg early suspend interrupt */
  50. #define USB_OTG_USBSUSP_INT ((uint32_t)0x00000800) /*!< usb otg suspend interrupt */
  51. #define USB_OTG_USBRST_INT ((uint32_t)0x00001000) /*!< usb otg reset interrupt */
  52. #define USB_OTG_ENUMDONE_INT ((uint32_t)0x00002000) /*!< usb otg enumeration done interrupt */
  53. #define USB_OTG_ISOOUTDROP_INT ((uint32_t)0x00004000) /*!< usb otg isochronous out packet dropped interrut */
  54. #define USB_OTG_EOPF_INT ((uint32_t)0x00008000) /*!< usb otg eop interrupt */
  55. #define USB_OTG_IEPT_INT ((uint32_t)0x00040000) /*!< usb otg in endpoint interrupt */
  56. #define USB_OTG_OEPT_INT ((uint32_t)0x00080000) /*!< usb otg out endpoint interrupt */
  57. #define USB_OTG_INCOMISOIN_INT ((uint32_t)0x00100000) /*!< usb otg incomplete isochronous in transfer interrupt */
  58. #define USB_OTG_INCOMPIP_INCOMPISOOUT_INT ((uint32_t)0x00200000) /*!< usb otg incomplete periodic transfer/isochronous out interrupt */
  59. #define USB_OTG_PRT_INT ((uint32_t)0x01000000) /*!< usb otg host port interrupt */
  60. #define USB_OTG_HCH_INT ((uint32_t)0x02000000) /*!< usb otg host channel interrupt */
  61. #define USB_OTG_PTXFEMP_INT ((uint32_t)0x04000000) /*!< usb otg periodic txfifo empty interrupt */
  62. #define USB_OTG_CONIDSCHG_INT ((uint32_t)0x10000000) /*!< usb otg connector id status change interrupt */
  63. #define USB_OTG_DISCON_INT ((uint32_t)0x20000000) /*!< usb otg disconnect detected interrupt */
  64. #define USB_OTG_WKUP_INT ((uint32_t)0x80000000) /*!< usb otg wakeup interrupt */
  65. /**
  66. * @}
  67. */
  68. /** @defgroup USB_global_interrupt_flags_definition
  69. * @brief usb global interrupt flag
  70. * @{
  71. */
  72. #define USB_OTG_CURMODE ((uint32_t)0x00000001) /*!< usb otg current mode */
  73. #define USB_OTG_MODEMIS_FLAG ((uint32_t)0x00000002) /*!< usb otg mode mismatch flag */
  74. #define USB_OTG_OTGINT_FLAG ((uint32_t)0x00000004) /*!< usb otg flag */
  75. #define USB_OTG_SOF_FLAG ((uint32_t)0x00000008) /*!< usb otg sof flag */
  76. #define USB_OTG_RXFLVL_FLAG ((uint32_t)0x00000010) /*!< usb otg receive fifo non-empty flag */
  77. #define USB_OTG_NPTXFEMP_FLAG ((uint32_t)0x00000020) /*!< usb otg non-periodic tx fifo empty flag */
  78. #define USB_OTG_GINNAKEFF_FLAG ((uint32_t)0x00000040) /*!< usb otg global non-periodic in nak effective flag */
  79. #define USB_OTG_GOUTNAKEFF_FLAG ((uint32_t)0x00000080) /*!< usb otg global out nak effective flag */
  80. #define USB_OTG_ERLYSUSP_FLAG ((uint32_t)0x00000400) /*!< usb otg early suspend flag */
  81. #define USB_OTG_USBSUSP_FLAG ((uint32_t)0x00000800) /*!< usb otg suspend flag */
  82. #define USB_OTG_USBRST_FLAG ((uint32_t)0x00001000) /*!< usb otg reset flag */
  83. #define USB_OTG_ENUMDONE_FLAG ((uint32_t)0x00002000) /*!< usb otg enumeration done flag */
  84. #define USB_OTG_ISOOUTDROP_FLAG ((uint32_t)0x00004000) /*!< usb otg isochronous out packet dropped flag */
  85. #define USB_OTG_EOPF_FLAG ((uint32_t)0x00008000) /*!< usb otg eop flag */
  86. #define USB_OTG_IEPT_FLAG ((uint32_t)0x00040000) /*!< usb otg in endpoint flag */
  87. #define USB_OTG_OEPT_FLAG ((uint32_t)0x00080000) /*!< usb otg out endpoint flag */
  88. #define USB_OTG_INCOMISOIN_FLAG ((uint32_t)0x00100000) /*!< usb otg incomplete isochronous in transfer flag */
  89. #define USB_OTG_INCOMPIP_INCOMPISOOUT_FLAG ((uint32_t)0x00200000) /*!< usb otg incomplete periodic transfer/isochronous out flag */
  90. #define USB_OTG_PRT_FLAG ((uint32_t)0x01000000) /*!< usb otg host port flag */
  91. #define USB_OTG_HCH_FLAG ((uint32_t)0x02000000) /*!< usb otg host channel flag */
  92. #define USB_OTG_PTXFEMP_FLAG ((uint32_t)0x04000000) /*!< usb otg periodic txfifo empty flag */
  93. #define USB_OTG_CONIDSCHG_FLAG ((uint32_t)0x10000000) /*!< usb otg connector id status change flag */
  94. #define USB_OTG_DISCON_FLAG ((uint32_t)0x20000000) /*!< usb otg disconnect detected flag */
  95. #define USB_OTG_WKUP_FLAG ((uint32_t)0x80000000) /*!< usb otg wakeup flag */
  96. /**
  97. * @}
  98. */
  99. /** @defgroup USB_global_setting_definition
  100. * @brief usb global setting
  101. * @{
  102. */
  103. /**
  104. * @brief usb turnaround time
  105. */
  106. #define USB_TRDTIM_8 0x9 /*!< usb turn around time 8 */
  107. #define USB_TRDTIM_16 0x5 /*!< usb turn around time 16 */
  108. /**
  109. * @brief usb receive status
  110. */
  111. #define USB_OTG_GRXSTSP_EPTNUM ((uint32_t)0x0000000F) /*!< usb device receive packet endpoint number*/
  112. #define USB_OTG_GRXSTSP_CHNUM ((uint32_t)0x0000000F) /*!< usb host receive packet channel number*/
  113. #define USB_OTG_GRXSTSP_BCNT ((uint32_t)0x00007FF0) /*!< usb receive packet byte count */
  114. #define USB_OTG_GRXSTSP_DPID ((uint32_t)0x00018000) /*!< usb receive packet pid */
  115. #define USB_OTG_GRXSTSP_PKTSTS ((uint32_t)0x001E0000) /*!< usb receive packet status */
  116. /**
  117. * @brief usb host packet status
  118. */
  119. #define PKTSTS_IN_DATA_PACKET_RECV 0x2 /*!< usb host in data packet received */
  120. #define PKTSTS_IN_TRANSFER_COMPLETE 0x3 /*!< usb host in transfer completed */
  121. #define PKTSTS_DATA_BIT_ERROR 0x5 /*!< usb host data toggle error */
  122. #define PKTSTS_CHANNEL_STOP 0x7 /*!< usb host channel halted */
  123. /**
  124. * @brief usb device packet status
  125. */
  126. #define USB_OUT_STS_NAK 0x1 /*!< usb device global out nak */
  127. #define USB_OUT_STS_DATA 0x2 /*!< usb device out data packet received */
  128. #define USB_OUT_STS_COMP 0x3 /*!< usb device out transfer completed */
  129. #define USB_SETUP_STS_COMP 0x4 /*!< usb device setup transcation completed */
  130. #define USB_SETUP_STS_DATA 0x6 /*!< usb device setup data packet received */
  131. /**
  132. * @}
  133. */
  134. /** @defgroup USB_host_config_definition
  135. * @{
  136. */
  137. /**
  138. * @brief usb host phy clock
  139. */
  140. #define USB_HCFG_CLK_60M 0 /*!< usb host phy clock 60mhz */
  141. #define USB_HCFG_CLK_48M 1 /*!< usb host phy clock 48mhz */
  142. #define USB_HCFG_CLK_6M 2 /*!< usb host phy clock 6mhz */
  143. /**
  144. * @brief usb host port status
  145. */
  146. #define USB_OTG_HPRT_PRTCONSTS ((uint32_t)0x00000001) /*!< usb host port connect status */
  147. #define USB_OTG_HPRT_PRTCONDET ((uint32_t)0x00000002) /*!< usb host port connect detected */
  148. #define USB_OTG_HPRT_PRTENA ((uint32_t)0x00000004) /*!< usb host port enable */
  149. #define USB_OTG_HPRT_PRTENCHNG ((uint32_t)0x00000008) /*!< usb host port enable/disable change */
  150. #define USB_OTG_HPRT_PRTOVRCACT ((uint32_t)0x00000010) /*!< usb host port overcurrent active */
  151. #define USB_OTG_HPRT_PRTOVRCCHNG ((uint32_t)0x00000020) /*!< usb host port overcurrent change */
  152. #define USB_OTG_HPRT_PRTRES ((uint32_t)0x00000040) /*!< usb host port resume */
  153. #define USB_OTG_HPRT_PRTSUSP ((uint32_t)0x00000080) /*!< usb host port suspend */
  154. #define USB_OTG_HPRT_PRTRST ((uint32_t)0x00000100) /*!< usb host port reset */
  155. #define USB_OTG_HPRT_PRTLNSTS ((uint32_t)0x00000C00) /*!< usb host port line status */
  156. #define USB_OTG_HPRT_PRTPWR ((uint32_t)0x00001000) /*!< usb host port power */
  157. #define USB_OTG_HPRT_PRTSPD ((uint32_t)0x00060000) /*!< usb host port speed */
  158. /**
  159. * @brief usb port speed
  160. */
  161. #define USB_PRTSPD_HIGH_SPEED 0 /*!< usb host port high speed */
  162. #define USB_PRTSPD_FULL_SPEED 1 /*!< usb host port full speed */
  163. #define USB_PRTSPD_LOW_SPEED 2 /*!< usb host port low speed */
  164. /**
  165. * @brief usb host register hcchar bit define
  166. */
  167. #define USB_OTG_HCCHAR_MPS ((uint32_t)0x000007FF) /*!< channel maximum packet size */
  168. #define USB_OTG_HCCHAR_EPTNUM ((uint32_t)0x00007800) /*!< endpoint number */
  169. #define USB_OTG_HCCHAR_EPTDIR ((uint32_t)0x00008000) /*!< endpoint direction */
  170. #define USB_OTG_HCCHAR_LSPDDEV ((uint32_t)0x00020000) /*!< low speed device */
  171. #define USB_OTG_HCCHAR_EPTYPE ((uint32_t)0x000C0000) /*!< endpoint type */
  172. #define USB_OTG_HCCHAR_MC ((uint32_t)0x00300000) /*!< multi count */
  173. #define USB_OTG_HCCHAR_DEVADDR ((uint32_t)0x1FC00000) /*!< device address */
  174. #define USB_OTG_HCCHAR_ODDFRM ((uint32_t)0x20000000) /*!< odd frame */
  175. #define USB_OTG_HCCHAR_CHDIS ((uint32_t)0x40000000) /*!< channel disable */
  176. #define USB_OTG_HCCHAR_CHENA ((uint32_t)0x80000000) /*!< channel enable */
  177. /**
  178. * @brief usb host register hctsiz bit define
  179. */
  180. #define USB_OTG_HCTSIZ_XFERSIZE ((uint32_t)0x0007FFFF) /*!< channel transfer size */
  181. #define USB_OTG_HCTSIZ_PKTCNT ((uint32_t)0x1FF80000) /*!< channel packet count */
  182. #define USB_OTG_HCTSIZ_PID ((uint32_t)0x60000000) /*!< channel pid */
  183. /**
  184. * @brief usb host channel interrupt mask
  185. */
  186. #define USB_OTG_HC_XFERCM_INT ((uint32_t)0x00000001) /*!< channel transfer complete interrupt */
  187. #define USB_OTG_HC_CHHLTDM_INT ((uint32_t)0x00000002) /*!< channel halted interrupt */
  188. #define USB_OTG_HC_STALLM_INT ((uint32_t)0x00000008) /*!< channel stall interrupt */
  189. #define USB_OTG_HC_NAKM_INT ((uint32_t)0x00000010) /*!< channel nak interrupt */
  190. #define USB_OTG_HC_ACKM_INT ((uint32_t)0x00000020) /*!< channel ack interrupt */
  191. #define USB_OTG_HC_NYETM_INT ((uint32_t)0x00000040) /*!< channel nyet interrupt */
  192. #define USB_OTG_HC_XACTERRM_INT ((uint32_t)0x00000080) /*!< channel transaction error interrupt */
  193. #define USB_OTG_HC_BBLERRM_INT ((uint32_t)0x00000100) /*!< channel babble error interrupt */
  194. #define USB_OTG_HC_FRMOVRRUN_INT ((uint32_t)0x00000200) /*!< channel frame overrun interrupt */
  195. #define USB_OTG_HC_DTGLERRM_INT ((uint32_t)0x00000400) /*!< channel data toggle interrupt */
  196. /**
  197. * @brief usb host channel interrupt flag
  198. */
  199. #define USB_OTG_HC_XFERC_FLAG ((uint32_t)0x00000001) /*!< channel transfer complete flag */
  200. #define USB_OTG_HC_CHHLTD_FLAG ((uint32_t)0x00000002) /*!< channel halted flag */
  201. #define USB_OTG_HC_STALL_FLAG ((uint32_t)0x00000008) /*!< channel stall flag */
  202. #define USB_OTG_HC_NAK_FLAG ((uint32_t)0x00000010) /*!< channel nak flag */
  203. #define USB_OTG_HC_ACK_FLAG ((uint32_t)0x00000020) /*!< channel ack flag */
  204. #define USB_OTG_HC_NYET_FLAG ((uint32_t)0x00000040) /*!< channel nyet flag */
  205. #define USB_OTG_HC_XACTERR_FLAG ((uint32_t)0x00000080) /*!< channel transaction error flag */
  206. #define USB_OTG_HC_BBLERR_FLAG ((uint32_t)0x00000100) /*!< channel babble error flag */
  207. #define USB_OTG_HC_FRMOVRRUN_FLAG ((uint32_t)0x00000200) /*!< channel frame overrun flag */
  208. #define USB_OTG_HC_DTGLERR_FLAG ((uint32_t)0x00000400) /*!< channel data toggle flag */
  209. /**
  210. * @}
  211. */
  212. /** @defgroup USB_device_config_definition
  213. * @{
  214. */
  215. /**
  216. * @brief usb device periodic frame interval
  217. */
  218. typedef enum
  219. {
  220. DCFG_PERFRINT_80 = 0x00, /*!< periodic frame interval 80% */
  221. DCFG_PERFRINT_85 = 0x01, /*!< periodic frame interval 85% */
  222. DCFG_PERFRINT_90 = 0x02, /*!< periodic frame interval 90% */
  223. DCFG_PERFRINT_95 = 0x03 /*!< periodic frame interval 95% */
  224. } dcfg_perfrint_type;
  225. /**
  226. * @brief usb device full speed
  227. */
  228. #define USB_DCFG_FULL_SPEED 3 /*!< device full speed */
  229. /**
  230. * @brief usb device ctrl define
  231. */
  232. #define USB_OTG_DCTL_RWKUPSIG ((uint32_t)0x00000001) /*!< usb device remote wakeup signaling */
  233. #define USB_OTG_DCTL_SFTDISCON ((uint32_t)0x00000002) /*!< usb device soft disconnect */
  234. #define USB_OTG_DCTL_GNPINNAKSTS ((uint32_t)0x00000004) /*!< usb device global non-periodic in nak status */
  235. #define USB_OTG_DCTL_GOUTNAKSTS ((uint32_t)0x00000008) /*!< usb device global out nak status */
  236. #define USB_OTG_DCTL_SGNPINNAK ((uint32_t)0x00000080) /*!< usb device set global non-periodic in nak */
  237. #define USB_OTG_DCTL_CGNPINNAK ((uint32_t)0x00000100) /*!< usb device clear global non-periodic in nak */
  238. #define USB_OTG_DCTL_SGOUTNAK ((uint32_t)0x00000200) /*!< usb device set global out nak status */
  239. #define USB_OTG_DCTL_CGOUTNAK ((uint32_t)0x00000400) /*!< usb device clear global out nak status */
  240. #define USB_OTG_DCTL_PWROPRGDNE ((uint32_t)0x00000800) /*!< usb device power on programming done */
  241. /**
  242. * @brief usb device in endpoint flag
  243. */
  244. #define USB_OTG_DIEPINT_XFERC_FLAG ((uint32_t)0x00000001) /*!< usb device in transfer completed flag */
  245. #define USB_OTG_DIEPINT_EPTDISD_FLAG ((uint32_t)0x00000002) /*!< usb device endpoint disable flag */
  246. #define USB_OTG_DIEPINT_TIMEOUT_FLAG ((uint32_t)0x00000008) /*!< usb device in timeout */
  247. #define USB_OTG_DIEPINT_INTKNTXFEMP_FLAG ((uint32_t)0x00000010) /*!< usb device in token received when tx fifo is empty flag */
  248. #define USB_OTG_DIEPINT_INEPTNAK_FLAG ((uint32_t)0x00000040) /*!< usb device in endpoint nak effective flag */
  249. #define USB_OTG_DIEPINT_TXFEMP_FLAG ((uint32_t)0x00000080) /*!< usb device transmit fifo empty flag */
  250. /**
  251. * @brief usb device out endpoint flag
  252. */
  253. #define USB_OTG_DOEPINT_XFERC_FLAG ((uint32_t)0x00000001) /*!< usb device out transfer completed flag */
  254. #define USB_OTG_DOEPINT_EPTDISD_FLAG ((uint32_t)0x00000002) /*!< usb device endpoint disable flag */
  255. #define USB_OTG_DOEPINT_SETUP_FLAG ((uint32_t)0x00000008) /*!< usb device setup flag */
  256. #define USB_OTG_DOEPINT_OUTTEPD_FLAG ((uint32_t)0x00000010) /*!< usb device out token recevied when endpoint disable flag */
  257. #define USB_OTG_DOEPINT_B2BSTUP_FLAG ((uint32_t)0x00000040) /*!< back-to-back setup packets received */
  258. /**
  259. * @brief usb device in endpoint fifo space mask
  260. */
  261. #define USB_OTG_DTXFSTS_INEPTFSAV ((uint32_t)0x0000FFFF) /*!< usb device in endpoint tx fifo space avail */
  262. /**
  263. * @brief endpoint0 maximum packet size
  264. */
  265. #define USB_EPT0_MPS_64 0 /*!< usb device endpoint 0 maximum packet size 64byte */
  266. #define USB_EPT0_MPS_32 1 /*!< usb device endpoint 0 maximum packet size 32byte */
  267. #define USB_EPT0_MPS_16 2 /*!< usb device endpoint 0 maximum packet size 16byte */
  268. #define USB_EPT0_MPS_8 3 /*!< usb device endpoint 0 maximum packet size 8byte */
  269. /**
  270. * @}
  271. */
  272. /**
  273. * @brief otg fifo size (word)
  274. */
  275. #define OTG_FIFO_SIZE 320 /*!< otg usb total fifo size */
  276. /**
  277. * @brief otg host max buffer length (byte)
  278. */
  279. #define USB_MAX_DATA_LENGTH 0x200 /*!< usb host maximum buffer size */
  280. #define OTGFS_USB_GLOBAL
  281. #define OTGFS_USB_DEVICE
  282. #define OTGFS_USB_HOST
  283. /** @defgroup USB_exported_enum_types
  284. * @{
  285. */
  286. /**
  287. * @brief usb mode define(device, host, drd)
  288. */
  289. typedef enum
  290. {
  291. OTG_DEVICE_MODE, /*!< usb device mode */
  292. OTG_HOST_MODE, /*!< usb host mode */
  293. OTG_DRD_MODE /*!< usb drd mode */
  294. } otg_mode_type;
  295. /**
  296. * @brief endpoint type define
  297. */
  298. typedef enum
  299. {
  300. EPT_CONTROL_TYPE = 0x00, /*!< usb endpoint type control */
  301. EPT_ISO_TYPE = 0x01, /*!< usb endpoint type iso */
  302. EPT_BULK_TYPE = 0x02, /*!< usb endpoint type bulk */
  303. EPT_INT_TYPE = 0x03 /*!< usb endpoint type interrupt */
  304. } endpoint_trans_type;
  305. /**
  306. * @brief usb endpoint number define type
  307. */
  308. typedef enum
  309. {
  310. USB_EPT0 = 0x00, /*!< usb endpoint 0 */
  311. USB_EPT1 = 0x01, /*!< usb endpoint 1 */
  312. USB_EPT2 = 0x02, /*!< usb endpoint 2 */
  313. USB_EPT3 = 0x03, /*!< usb endpoint 3 */
  314. USB_EPT4 = 0x04, /*!< usb endpoint 4 */
  315. USB_EPT5 = 0x05, /*!< usb endpoint 5 */
  316. USB_EPT6 = 0x06, /*!< usb endpoint 6 */
  317. USB_EPT7 = 0x07 /*!< usb endpoint 7 */
  318. } usb_endpoint_number_type;
  319. /**
  320. * @brief usb endpoint max num define
  321. */
  322. #ifndef USB_EPT_MAX_NUM
  323. #define USB_EPT_MAX_NUM 8 /*!< usb device support endpoint number */
  324. #endif
  325. /**
  326. * @brief usb channel max num define
  327. */
  328. #ifndef USB_HOST_CHANNEL_NUM
  329. #define USB_HOST_CHANNEL_NUM 16 /*!< usb host support channel number */
  330. #endif
  331. /**
  332. * @brief endpoint trans dir type
  333. */
  334. typedef enum
  335. {
  336. EPT_DIR_IN = 0x00, /*!< usb transfer direction in */
  337. EPT_DIR_OUT = 0x01 /*!< usb transfer direction out */
  338. } endpoint_dir_type;
  339. /**
  340. * @brief otgfs1 and otgfs2 select type
  341. */
  342. typedef enum
  343. {
  344. USB_OTG1_ID, /*!< usb otg 1 id */
  345. USB_OTG2_ID /*!< usb otg 2 id */
  346. } otg_id_type;
  347. /**
  348. * @brief usb clock select
  349. */
  350. typedef enum
  351. {
  352. USB_CLK_HICK, /*!< usb clock use hick */
  353. USB_CLK_HEXT /*!< usb clock use hext */
  354. }usb_clk48_s;
  355. /**
  356. * @}
  357. */
  358. /** @defgroup USB_exported_types
  359. * @{
  360. */
  361. /**
  362. * @brief usb endpoint infomation structure definition
  363. */
  364. typedef struct
  365. {
  366. uint8_t eptn; /*!< endpoint register number (0~7) */
  367. uint8_t ept_address; /*!< endpoint address */
  368. uint8_t inout; /*!< endpoint dir EPT_DIR_IN or EPT_DIR_OUT */
  369. uint8_t trans_type; /*!< endpoint type:
  370. EPT_CONTROL_TYPE, EPT_BULK_TYPE, EPT_INT_TYPE, EPT_ISO_TYPE*/
  371. uint16_t tx_addr; /*!< endpoint tx buffer offset address */
  372. uint16_t rx_addr; /*!< endpoint rx buffer offset address */
  373. uint32_t maxpacket; /*!< endpoint max packet*/
  374. uint8_t is_double_buffer; /*!< endpoint double buffer flag */
  375. uint8_t stall; /*!< endpoint is stall state */
  376. uint32_t status;
  377. /* transmission buffer and count */
  378. uint8_t *trans_buf; /*!< endpoint transmission buffer */
  379. uint32_t total_len; /*!< endpoint transmission lengtg */
  380. uint32_t trans_len; /*!< endpoint transmission length*/
  381. uint32_t last_len; /*!< last transfer length */
  382. uint32_t rem0_len; /*!< rem transfer length */
  383. uint32_t ept0_slen; /*!< endpoint 0 transfer sum length */
  384. } usb_ept_info;
  385. /**
  386. * @brief usb host channel infomation structure definition
  387. */
  388. typedef struct
  389. {
  390. uint8_t ch_num; /*!< host channel number */
  391. uint8_t address; /*!< device address */
  392. uint8_t dir; /*!< transmission direction */
  393. uint8_t ept_num; /*!< device endpoint number */
  394. uint8_t ept_type; /*!< channel transmission type */
  395. uint32_t maxpacket; /*!< support max packet size */
  396. uint8_t data_pid; /*!< data pid */
  397. uint8_t speed; /*!< usb speed */
  398. uint8_t stall; /*!< channel stall flag */
  399. uint32_t status; /*!< channel status */
  400. uint32_t state; /*!< channel state */
  401. uint32_t urb_sts; /*!< usb channel request block state */
  402. uint8_t toggle_in; /*!< channel in transfer toggle */
  403. uint8_t toggle_out; /*!< channel out transfer toggle */
  404. /* transmission buffer and count */
  405. uint8_t *trans_buf; /* host channel buffer */
  406. uint32_t trans_len; /* host channel transmission len */
  407. uint32_t trans_count; /* host channel transmission count*/
  408. } usb_hch_type;
  409. typedef struct
  410. {
  411. /**
  412. * @brief otgfs control and status register, offset:0x00
  413. */
  414. union
  415. {
  416. __IO uint32_t gotgctrl;
  417. struct
  418. {
  419. __IO uint32_t reserved1 : 16; /* [15:0] */
  420. __IO uint32_t cidsts : 1; /* [16] */
  421. __IO uint32_t reserved2 : 4; /* [20:17] */
  422. __IO uint32_t curmod : 1; /* [21] */
  423. __IO uint32_t reserved3 : 10; /* [31:22] */
  424. } gotgctrl_bit;
  425. };
  426. /**
  427. * @brief otgfs interrupt register, offset:0x04
  428. */
  429. union
  430. {
  431. __IO uint32_t gotgint;
  432. struct
  433. {
  434. __IO uint32_t reserved1 : 2; /* [1:0] */
  435. __IO uint32_t sesenddet : 1; /* [2] */
  436. __IO uint32_t reserved2 : 29; /* [31:3] */
  437. } gotgint_bit;
  438. };
  439. /**
  440. * @brief otgfs gahbcfg configuration register, offset:0x08
  441. */
  442. union
  443. {
  444. __IO uint32_t gahbcfg;
  445. struct
  446. {
  447. __IO uint32_t glbintmsk : 1; /* [0] */
  448. __IO uint32_t reserved1 : 6; /* [6:1] */
  449. __IO uint32_t nptxfemplvl : 1; /* [7] */
  450. __IO uint32_t ptxfemplvl : 1; /* [8] */
  451. __IO uint32_t reserved2 : 23; /* [31:9] */
  452. } gahbcfg_bit;
  453. };
  454. /**
  455. * @brief otgfs usb configuration register, offset:0x0C
  456. */
  457. union
  458. {
  459. __IO uint32_t gusbcfg;
  460. struct
  461. {
  462. __IO uint32_t toutcal : 3; /* [2:0] */
  463. __IO uint32_t reserved1 : 7; /* [9:3] */
  464. __IO uint32_t usbtrdtim : 4; /* [13:10] */
  465. __IO uint32_t reserved2 : 15; /* [28:14] */
  466. __IO uint32_t fhstmode : 1; /* [29] */
  467. __IO uint32_t fdevmode : 1; /* [30] */
  468. __IO uint32_t cotxpkt : 1; /* [31] */
  469. } gusbcfg_bit;
  470. };
  471. /**
  472. * @brief otgfs reset register, offset:0x10
  473. */
  474. union
  475. {
  476. __IO uint32_t grstctl;
  477. struct
  478. {
  479. __IO uint32_t csftrst : 1; /* [0] */
  480. __IO uint32_t piusftrst : 1; /* [1] */
  481. __IO uint32_t frmcntrst : 1; /* [2] */
  482. __IO uint32_t reserved1 : 1; /* [3] */
  483. __IO uint32_t rxfflsh : 1; /* [4] */
  484. __IO uint32_t txfflsh : 1; /* [5] */
  485. __IO uint32_t txfnum : 5; /* [10:6] */
  486. __IO uint32_t reserved2 : 20; /* [30:11] */
  487. __IO uint32_t ahbidle : 1; /* [31] */
  488. } grstctl_bit;
  489. };
  490. /**
  491. * @brief otgfs core interrupt register, offset:0x14
  492. */
  493. union
  494. {
  495. __IO uint32_t gintsts;
  496. struct
  497. {
  498. __IO uint32_t curmode : 1; /* [0] */
  499. __IO uint32_t modemis : 1; /* [1] */
  500. __IO uint32_t otgint : 1; /* [2] */
  501. __IO uint32_t sof : 1; /* [3] */
  502. __IO uint32_t rxflvl : 1; /* [4] */
  503. __IO uint32_t nptxfemp : 1; /* [5] */
  504. __IO uint32_t ginnakeff : 1; /* [6] */
  505. __IO uint32_t goutnakeff : 1; /* [7] */
  506. __IO uint32_t reserved1 : 2; /* [9:8]] */
  507. __IO uint32_t erlysusp : 1; /* [10] */
  508. __IO uint32_t usbsusp : 1; /* [11] */
  509. __IO uint32_t usbrst : 1; /* [12] */
  510. __IO uint32_t enumdone : 1; /* [13] */
  511. __IO uint32_t isooutdrop : 1; /* [14] */
  512. __IO uint32_t eopf : 1; /* [15] */
  513. __IO uint32_t reserved2 : 2; /* [17:16]] */
  514. __IO uint32_t ieptint : 1; /* [18] */
  515. __IO uint32_t oeptint : 1; /* [19] */
  516. __IO uint32_t incompisoin : 1; /* [20] */
  517. __IO uint32_t incompip_incompisoout : 1; /* [21] */
  518. __IO uint32_t reserved3 : 2; /* [23:22] */
  519. __IO uint32_t prtint : 1; /* [24] */
  520. __IO uint32_t hchint : 1; /* [25] */
  521. __IO uint32_t ptxfemp : 1; /* [26] */
  522. __IO uint32_t reserved4 : 1; /* [27] */
  523. __IO uint32_t conidschg : 1; /* [28] */
  524. __IO uint32_t disconint : 1; /* [29] */
  525. __IO uint32_t reserved5 : 1; /* [30] */
  526. __IO uint32_t wkupint : 1; /* [31] */
  527. } gintsts_bit;
  528. };
  529. /**
  530. * @brief otgfs interrupt mask register, offset:0x18
  531. */
  532. union
  533. {
  534. __IO uint32_t gintmsk;
  535. struct
  536. {
  537. __IO uint32_t reserved1 : 1; /* [0] */
  538. __IO uint32_t modemismsk : 1; /* [1] */
  539. __IO uint32_t otgintmsk : 1; /* [2] */
  540. __IO uint32_t sofmsk : 1; /* [3] */
  541. __IO uint32_t rxflvlmsk : 1; /* [4] */
  542. __IO uint32_t nptxfempmsk : 1; /* [5] */
  543. __IO uint32_t ginnakeffmsk : 1; /* [6] */
  544. __IO uint32_t goutnakeffmsk : 1; /* [7] */
  545. __IO uint32_t reserved2 : 2; /* [9:8]] */
  546. __IO uint32_t erlysuspmsk : 1; /* [10] */
  547. __IO uint32_t usbsuspmsk : 1; /* [11] */
  548. __IO uint32_t usbrstmsk : 1; /* [12] */
  549. __IO uint32_t enumdonemsk : 1; /* [13] */
  550. __IO uint32_t isooutdropmsk : 1; /* [14] */
  551. __IO uint32_t eopfmsk : 1; /* [15] */
  552. __IO uint32_t reserved3 : 2; /* [17:16]] */
  553. __IO uint32_t ieptintmsk : 1; /* [18] */
  554. __IO uint32_t oeptintmsk : 1; /* [19] */
  555. __IO uint32_t incompisoinmsk : 1; /* [20] */
  556. __IO uint32_t incompip_incompisooutmsk : 1; /* [21] */
  557. __IO uint32_t reserved4 : 2; /* [23:22] */
  558. __IO uint32_t prtintmsk : 1; /* [24] */
  559. __IO uint32_t hchintmsk : 1; /* [25] */
  560. __IO uint32_t ptxfempmsk : 1; /* [26] */
  561. __IO uint32_t reserved5 : 1; /* [27] */
  562. __IO uint32_t conidschgmsk : 1; /* [28] */
  563. __IO uint32_t disconintmsk : 1; /* [29] */
  564. __IO uint32_t reserved6 : 1; /* [30] */
  565. __IO uint32_t wkupintmsk : 1; /* [31] */
  566. } gintmsk_bit;
  567. };
  568. /**
  569. * @brief otgfs rx status debug read register, offset:0x1C
  570. */
  571. union
  572. {
  573. __IO uint32_t grxstsr;
  574. struct
  575. {
  576. __IO uint32_t eptnum : 4; /* [3:0] */
  577. __IO uint32_t bcnt : 11; /* [14:4] */
  578. __IO uint32_t dpid : 2; /* [16:15] */
  579. __IO uint32_t pktsts : 4; /* [20:17] */
  580. __IO uint32_t fn : 4; /* [24:21] */
  581. __IO uint32_t reserved1 : 7; /* [31:25] */
  582. } grxstsr_bit;
  583. };
  584. /**
  585. * @brief otgfs rx status read and pop register, offset:0x20
  586. */
  587. union
  588. {
  589. __IO uint32_t grxstsp;
  590. struct
  591. {
  592. __IO uint32_t chnum : 4; /* [3:0] */
  593. __IO uint32_t bcnt : 11; /* [14:4] */
  594. __IO uint32_t dpid : 2; /* [16:15] */
  595. __IO uint32_t pktsts : 4; /* [20:17] */
  596. __IO uint32_t reserved1 : 11; /* [31:21] */
  597. } grxstsp_bit;
  598. };
  599. /**
  600. * @brief otgfs rx fifo size register, offset:0x24
  601. */
  602. union
  603. {
  604. __IO uint32_t grxfsiz;
  605. struct
  606. {
  607. __IO uint32_t rxfdep : 16; /* [15:0] */
  608. __IO uint32_t reserved1 : 16; /* [31:16] */
  609. } grxfsiz_bit;
  610. };
  611. /**
  612. * @brief otgfs non-periodic and ept0 tx fifo size register, offset:0x28
  613. */
  614. union
  615. {
  616. __IO uint32_t gnptxfsiz_ept0tx;
  617. struct
  618. {
  619. __IO uint32_t nptxfstaddr : 16; /* [15:0] */
  620. __IO uint32_t nptxfdep : 16; /* [31:16] */
  621. } gnptxfsiz_ept0tx_bit;
  622. };
  623. /**
  624. * @brief otgfs non-periodic tx fifo request queue status register, offset:0x2C
  625. */
  626. union
  627. {
  628. __IO uint32_t gnptxsts;
  629. struct
  630. {
  631. __IO uint32_t nptxfspcavail : 16; /* [15:0] */
  632. __IO uint32_t nptxqspcavail : 8; /* [23:16] */
  633. __IO uint32_t nptxqtop : 7; /* [30:24] */
  634. } gnptxsts_bit;
  635. };
  636. __IO uint32_t reserved2[2];
  637. /**
  638. * @brief otgfs general core configuration register, offset:0x38
  639. */
  640. union
  641. {
  642. __IO uint32_t gccfg;
  643. struct
  644. {
  645. __IO uint32_t reserved1 : 16; /* [15:0] */
  646. __IO uint32_t pwrdown : 1; /* [16] */
  647. __IO uint32_t lp_mode : 1; /* [17] */
  648. __IO uint32_t reserved2 : 2; /* [19:18] */
  649. __IO uint32_t sofouten : 1; /* [20] */
  650. __IO uint32_t vbusig : 1; /* [21] */
  651. __IO uint32_t reserved3 : 10; /* [31:22] */
  652. } gccfg_bit;
  653. };
  654. /**
  655. * @brief otgfs core id register, offset:0x3C
  656. */
  657. union
  658. {
  659. __IO uint32_t guid;
  660. struct
  661. {
  662. __IO uint32_t userid : 32; /* [31:0] */
  663. } guid_bit;
  664. };
  665. __IO uint32_t reserved3[48];
  666. /**
  667. * @brief otgfs host periodic tx fifo size register, offset:0x100
  668. */
  669. union
  670. {
  671. __IO uint32_t hptxfsiz;
  672. struct
  673. {
  674. __IO uint32_t ptxfstaddr : 16; /* [15:0] */
  675. __IO uint32_t ptxfsize : 16; /* [31:16] */
  676. } hptxfsiz_bit;
  677. };
  678. /**
  679. * @brief otgfs host periodic tx fifo size register, offset:0x100
  680. */
  681. union
  682. {
  683. __IO uint32_t dieptxfn[7];
  684. struct
  685. {
  686. __IO uint32_t ineptxfstaddr : 16; /* [15:0] */
  687. __IO uint32_t ineptxfdep : 16; /* [31:16] */
  688. } dieptxfn_bit[7];
  689. };
  690. } otg_global_type;
  691. typedef struct
  692. {
  693. /**
  694. * @brief otgfs host mode configuration register, offset:0x400
  695. */
  696. union
  697. {
  698. __IO uint32_t hcfg;
  699. struct
  700. {
  701. __IO uint32_t fslspclksel : 2; /* [1:0] */
  702. __IO uint32_t fslssupp : 1; /* [2] */
  703. __IO uint32_t reserved1 : 29; /* [31:3] */
  704. } hcfg_bit;
  705. };
  706. /**
  707. * @brief otgfs host frame interval register, offset:0x404
  708. */
  709. union
  710. {
  711. __IO uint32_t hfir;
  712. struct
  713. {
  714. __IO uint32_t frint : 16; /* [15:0] */
  715. __IO uint32_t reserved1 : 16; /* [31:15] */
  716. } hfir_bit;
  717. };
  718. /**
  719. * @brief otgfs host frame number and time remaining register, offset:0x408
  720. */
  721. union
  722. {
  723. __IO uint32_t hfnum;
  724. struct
  725. {
  726. __IO uint32_t frnum : 16; /* [15:0] */
  727. __IO uint32_t ftrem : 16; /* [31:15] */
  728. } hfnum_bit;
  729. };
  730. __IO uint32_t reserved1;
  731. /**
  732. * @brief otgfs host periodic tx fifo request queue register, offset:0x410
  733. */
  734. union
  735. {
  736. __IO uint32_t hptxsts;
  737. struct
  738. {
  739. __IO uint32_t ptxfspcavil : 16; /* [15:0] */
  740. __IO uint32_t ptxqspcavil : 8; /* [23:16] */
  741. __IO uint32_t ptxqtop : 8; /* [31:24] */
  742. } hptxsts_bit;
  743. };
  744. /**
  745. * @brief otgfs host all channel interrupt register, offset:0x414
  746. */
  747. union
  748. {
  749. __IO uint32_t haint;
  750. struct
  751. {
  752. __IO uint32_t haint : 16; /* [15:0] */
  753. __IO uint32_t reserved1 : 16; /* [32:16] */
  754. } haint_bit;
  755. };
  756. /**
  757. * @brief otgfs host all channel interrupt mask register, offset:0x418
  758. */
  759. union
  760. {
  761. __IO uint32_t haintmsk;
  762. struct
  763. {
  764. __IO uint32_t haintmsk : 16; /* [15:0] */
  765. __IO uint32_t reserved1 : 16; /* [32:16] */
  766. } haintmsk_bit;
  767. };
  768. __IO uint32_t reserved2[9];
  769. /**
  770. * @brief otgfs host port control and status register, offset:0x440
  771. */
  772. union
  773. {
  774. __IO uint32_t hprt;
  775. struct
  776. {
  777. __IO uint32_t prtconsts : 1; /* [0] */
  778. __IO uint32_t prtcondet : 1; /* [1] */
  779. __IO uint32_t prtena : 1; /* [2] */
  780. __IO uint32_t prtenchng : 1; /* [3] */
  781. __IO uint32_t prtovrcact : 1; /* [4] */
  782. __IO uint32_t prtovrcchng : 1; /* [5] */
  783. __IO uint32_t prtres : 1; /* [6] */
  784. __IO uint32_t prtsusp : 1; /* [7] */
  785. __IO uint32_t prtrst : 1; /* [8] */
  786. __IO uint32_t reserved1 : 1; /* [9] */
  787. __IO uint32_t prtlnsts : 2; /* [11:10] */
  788. __IO uint32_t prtpwr : 1; /* [12] */
  789. __IO uint32_t prttsctl : 4; /* [16:13] */
  790. __IO uint32_t prtspd : 2; /* [18:17] */
  791. __IO uint32_t reserved2 : 13; /* [31:19] */
  792. } hprt_bit;
  793. };
  794. } otg_host_type;
  795. typedef struct
  796. {
  797. /**
  798. * @brief otgfs host channel x characterisic register, offset:0x500
  799. */
  800. union
  801. {
  802. __IO uint32_t hcchar;
  803. struct
  804. {
  805. __IO uint32_t mps : 11; /* [10:0] */
  806. __IO uint32_t eptnum : 4; /* [14:11] */
  807. __IO uint32_t eptdir : 1; /* [15] */
  808. __IO uint32_t reserved1 : 1; /* [16] */
  809. __IO uint32_t lspddev : 1; /* [17] */
  810. __IO uint32_t eptype : 2; /* [19:18] */
  811. __IO uint32_t mc : 2; /* [21:20] */
  812. __IO uint32_t devaddr : 7; /* [28:22] */
  813. __IO uint32_t oddfrm : 1; /* [29] */
  814. __IO uint32_t chdis : 1; /* [30] */
  815. __IO uint32_t chena : 1; /* [31] */
  816. } hcchar_bit;
  817. };
  818. /**
  819. * @brief otgfs host channel split control register, offset:0x504
  820. */
  821. union
  822. {
  823. __IO uint32_t hcsplt;
  824. struct
  825. {
  826. __IO uint32_t prtaddr : 7; /* [6:0] */
  827. __IO uint32_t hubaddr : 7; /* [13:7] */
  828. __IO uint32_t xactpos : 2; /* [15:14] */
  829. __IO uint32_t compsplt : 1; /* [16] */
  830. __IO uint32_t reserved1 : 14; /* [30:17] */
  831. __IO uint32_t spltena : 1; /* [31] */
  832. } hcsplt_bit;
  833. };
  834. /**
  835. * @brief otgfs host channel interrupt register, offset:0x508
  836. */
  837. union
  838. {
  839. __IO uint32_t hcint;
  840. struct
  841. {
  842. __IO uint32_t xferc : 1; /* [0] */
  843. __IO uint32_t chhltd : 1; /* [1] */
  844. __IO uint32_t reserved1 : 1; /* [2] */
  845. __IO uint32_t stall : 1; /* [3] */
  846. __IO uint32_t nak : 1; /* [4] */
  847. __IO uint32_t ack : 1; /* [5] */
  848. __IO uint32_t reserved2 : 1; /* [6] */
  849. __IO uint32_t xacterr : 1; /* [7] */
  850. __IO uint32_t bblerr : 1; /* [8] */
  851. __IO uint32_t frmovrun : 1; /* [9] */
  852. __IO uint32_t dtglerr : 1; /* [10] */
  853. __IO uint32_t reserved3 : 21; /* [31:11] */
  854. } hcint_bit;
  855. };
  856. /**
  857. * @brief otgfs host channel interrupt mask register, offset:0x50C
  858. */
  859. union
  860. {
  861. __IO uint32_t hcintmsk;
  862. struct
  863. {
  864. __IO uint32_t xfercmsk : 1; /* [0] */
  865. __IO uint32_t chhltdmsk : 1; /* [1] */
  866. __IO uint32_t reserved1 : 1; /* [2] */
  867. __IO uint32_t stallmsk : 1; /* [3] */
  868. __IO uint32_t nakmsk : 1; /* [4] */
  869. __IO uint32_t ackmsk : 1; /* [5] */
  870. __IO uint32_t reserved2 : 1; /* [6] */
  871. __IO uint32_t xacterrmsk : 1; /* [7] */
  872. __IO uint32_t bblerrmsk : 1; /* [8] */
  873. __IO uint32_t frmovrunmsk : 1; /* [9] */
  874. __IO uint32_t dtglerrmsk : 1; /* [10] */
  875. __IO uint32_t reserved3 : 21; /* [31:11] */
  876. } hcintmsk_bit;
  877. };
  878. /**
  879. * @brief otgfs host channel transfer size register, offset:0x510
  880. */
  881. union
  882. {
  883. __IO uint32_t hctsiz;
  884. struct
  885. {
  886. __IO uint32_t xfersize : 19; /* [18:0] */
  887. __IO uint32_t pktcnt : 10; /* [28:19] */
  888. __IO uint32_t pid : 2; /* [30:29] */
  889. __IO uint32_t reserved1 : 1; /* [31] */
  890. } hctsiz_bit;
  891. };
  892. __IO uint32_t reserved3[3];
  893. }otg_hchannel_type;
  894. typedef struct
  895. {
  896. /**
  897. * @brief otgfs device configuration register, offset:0x800
  898. */
  899. union
  900. {
  901. __IO uint32_t dcfg;
  902. struct
  903. {
  904. __IO uint32_t devspd : 2; /* [1:0] */
  905. __IO uint32_t nzstsouthshk : 1; /* [2] */
  906. __IO uint32_t reserved1 : 1; /* [3] */
  907. __IO uint32_t devaddr : 7; /* [10:4] */
  908. __IO uint32_t perfrint : 2; /* [12:11] */
  909. __IO uint32_t reserved2 : 19; /* [31:13] */
  910. } dcfg_bit;
  911. };
  912. /**
  913. * @brief otgfs device controls register, offset:0x804
  914. */
  915. union
  916. {
  917. __IO uint32_t dctl;
  918. struct
  919. {
  920. __IO uint32_t rwkupsig : 1; /* [0] */
  921. __IO uint32_t sftdiscon : 1; /* [1] */
  922. __IO uint32_t gnpinnaksts : 1; /* [2] */
  923. __IO uint32_t goutnaksts : 1; /* [3] */
  924. __IO uint32_t tstctl : 3; /* [6:4] */
  925. __IO uint32_t sgnpinak : 1; /* [7] */
  926. __IO uint32_t cgnpinak : 1; /* [8] */
  927. __IO uint32_t sgoutnak : 1; /* [9] */
  928. __IO uint32_t cgoutnak : 1; /* [10] */
  929. __IO uint32_t pwroprgdne : 1; /* [11] */
  930. __IO uint32_t reserved1 : 20; /* [31:12] */
  931. } dctl_bit;
  932. };
  933. /**
  934. * @brief otgfs device status register, offset:0x80C
  935. */
  936. union
  937. {
  938. __IO uint32_t dsts;
  939. struct
  940. {
  941. __IO uint32_t suspsts : 1; /* [0] */
  942. __IO uint32_t enumspd : 2; /* [2:1] */
  943. __IO uint32_t eticerr : 1; /* [3] */
  944. __IO uint32_t reserved1 : 4; /* [7:4] */
  945. __IO uint32_t soffn : 14; /* [21:8] */
  946. __IO uint32_t reserved2 : 10; /* [31:22] */
  947. } dsts_bit;
  948. };
  949. __IO uint32_t reserved1;
  950. /**
  951. * @brief otgfs device in endpoint general interrupt mask register, offset:0x810
  952. */
  953. union
  954. {
  955. __IO uint32_t diepmsk;
  956. struct
  957. {
  958. __IO uint32_t xfercmsk : 1; /* [0] */
  959. __IO uint32_t eptdismsk : 1; /* [1] */
  960. __IO uint32_t reserved1 : 1; /* [2] */
  961. __IO uint32_t timeoutmsk : 1; /* [3] */
  962. __IO uint32_t intkntxfempmsk : 1; /* [4] */
  963. __IO uint32_t intkneptmismsk : 1; /* [5] */
  964. __IO uint32_t ineptnakmsk : 1; /* [6] */
  965. __IO uint32_t reserved2 : 1; /* [7] */
  966. __IO uint32_t txfifoudrmsk : 1; /* [8] */
  967. __IO uint32_t bnainmsk : 1; /* [9] */
  968. __IO uint32_t reserved3 : 22; /* [31:10] */
  969. } diepmsk_bit;
  970. };
  971. /**
  972. * @brief otgfs device out endpoint general interrupt mask register, offset:0x814
  973. */
  974. union
  975. {
  976. __IO uint32_t doepmsk;
  977. struct
  978. {
  979. __IO uint32_t xfercmsk : 1; /* [0] */
  980. __IO uint32_t eptdismsk : 1; /* [1] */
  981. __IO uint32_t reserved1 : 1; /* [2] */
  982. __IO uint32_t setupmsk : 1; /* [3] */
  983. __IO uint32_t outtepdmsk : 1; /* [4] */
  984. __IO uint32_t reserved2 : 1; /* [5] */
  985. __IO uint32_t b2bsetupmsk : 1; /* [6] */
  986. __IO uint32_t reserved3 : 1; /* [7] */
  987. __IO uint32_t outperrmsk : 1; /* [8] */
  988. __IO uint32_t bnaoutmsk : 1; /* [9] */
  989. __IO uint32_t reserved4 : 22; /* [31:10] */
  990. } doepmsk_bit;
  991. };
  992. /**
  993. * @brief otgfs device all endpoint interrupt register, offset:0x818
  994. */
  995. union
  996. {
  997. __IO uint32_t daint;
  998. struct
  999. {
  1000. __IO uint32_t ineptint : 16; /* [15:0] */
  1001. __IO uint32_t outeptint : 16; /* [31:16] */
  1002. } daint_bit;
  1003. };
  1004. /**
  1005. * @brief otgfs device all endpoint interrupt mask register, offset:0x81C
  1006. */
  1007. union
  1008. {
  1009. __IO uint32_t daintmsk;
  1010. struct
  1011. {
  1012. __IO uint32_t ineptmsk : 16; /* [15:0] */
  1013. __IO uint32_t outeptmsk : 16; /* [31:16] */
  1014. } daintmsk_bit;
  1015. };
  1016. __IO uint32_t reserved2[5];
  1017. /**
  1018. * @brief otgfs device in endpoint fifo empty interrupt mask register, offset:0x834
  1019. */
  1020. union
  1021. {
  1022. __IO uint32_t diepempmsk;
  1023. struct
  1024. {
  1025. __IO uint32_t ineptxfemsk : 16; /* [15:0] */
  1026. __IO uint32_t reserved1 : 16; /* [31:16] */
  1027. } diepempmsk_bit;
  1028. };
  1029. } otg_device_type;
  1030. typedef struct
  1031. {
  1032. /**
  1033. * @brief otgfs device out endpoint control register, offset:0x900
  1034. */
  1035. union
  1036. {
  1037. __IO uint32_t diepctl;
  1038. struct
  1039. {
  1040. __IO uint32_t mps : 11; /* [10:0] */
  1041. __IO uint32_t reserved1 : 4; /* [14:11] */
  1042. __IO uint32_t usbacept : 1; /* [15] */
  1043. __IO uint32_t dpid : 1; /* [16] */
  1044. __IO uint32_t naksts : 1; /* [17] */
  1045. __IO uint32_t eptype : 2; /* [19:18] */
  1046. __IO uint32_t reserved2 : 1; /* [20] */
  1047. __IO uint32_t stall : 1; /* [21] */
  1048. __IO uint32_t txfnum : 4; /* [25:22] */
  1049. __IO uint32_t cnak : 1; /* [26] */
  1050. __IO uint32_t snak : 1; /* [27] */
  1051. __IO uint32_t setd0pid : 1; /* [28] */
  1052. __IO uint32_t setd1pid : 1; /* [29] */
  1053. __IO uint32_t eptdis : 1; /* [30] */
  1054. __IO uint32_t eptena : 1; /* [31] */
  1055. } diepctl_bit;
  1056. };
  1057. __IO uint32_t reserved1;
  1058. /**
  1059. * @brief otgfs device in endpoint interrupt register, offset:0x908
  1060. */
  1061. union
  1062. {
  1063. __IO uint32_t diepint;
  1064. struct
  1065. {
  1066. __IO uint32_t xferc : 1; /* [0] */
  1067. __IO uint32_t epdisd : 1; /* [1] */
  1068. __IO uint32_t reserved1 : 1; /* [2] */
  1069. __IO uint32_t timeout : 1; /* [3] */
  1070. __IO uint32_t intkntxfemp : 1; /* [4] */
  1071. __IO uint32_t reserved2 : 1; /* [5] */
  1072. __IO uint32_t ineptnak : 1; /* [6] */
  1073. __IO uint32_t txfemp : 1; /* [7] */
  1074. __IO uint32_t reserved3 : 24; /* [31:8] */
  1075. } diepint_bit;
  1076. };
  1077. __IO uint32_t reserved2;
  1078. /**
  1079. * @brief otgfs device in endpoint transfer size register, offset:0x910 + endpoint number * 0x20
  1080. */
  1081. union
  1082. {
  1083. __IO uint32_t dieptsiz;
  1084. struct
  1085. {
  1086. __IO uint32_t xfersize : 19; /* [18:0] */
  1087. __IO uint32_t pktcnt : 10; /* [28:19] */
  1088. __IO uint32_t mc : 2; /* [30:29] */
  1089. __IO uint32_t reserved1 : 1; /* [31] */
  1090. } dieptsiz_bit;
  1091. };
  1092. __IO uint32_t reserved3;
  1093. /**
  1094. * @brief otgfs device in endpoint tx fifo status register, offset:0x918 + endpoint number * 0x20
  1095. */
  1096. union
  1097. {
  1098. __IO uint32_t dtxfsts;
  1099. struct
  1100. {
  1101. __IO uint32_t ineptxfsav : 16; /* [15:0] */
  1102. __IO uint32_t reserved1 : 16; /* [31:16] */
  1103. } dtxfsts_bit;
  1104. };
  1105. } otg_eptin_type;
  1106. typedef struct
  1107. {
  1108. /**
  1109. * @brief otgfs device out endpoint control register, offset:0xb00 + endpoint number * 0x20
  1110. */
  1111. union
  1112. {
  1113. __IO uint32_t doepctl;
  1114. struct
  1115. {
  1116. __IO uint32_t mps : 11; /* [10:0] */
  1117. __IO uint32_t reserved1 : 4; /* [14:11] */
  1118. __IO uint32_t usbacept : 1; /* [15] */
  1119. __IO uint32_t dpid : 1; /* [16] */
  1120. __IO uint32_t naksts : 1; /* [17] */
  1121. __IO uint32_t eptype : 2; /* [19:18] */
  1122. __IO uint32_t snpm : 1; /* [20] */
  1123. __IO uint32_t stall : 1; /* [21] */
  1124. __IO uint32_t reserved2 : 4; /* [25:22] */
  1125. __IO uint32_t cnak : 1; /* [26] */
  1126. __IO uint32_t snak : 1; /* [27] */
  1127. __IO uint32_t setd0pid : 1; /* [28] */
  1128. __IO uint32_t setd1pid : 1; /* [29] */
  1129. __IO uint32_t eptdis : 1; /* [30] */
  1130. __IO uint32_t eptena : 1; /* [31] */
  1131. } doepctl_bit;
  1132. };
  1133. __IO uint32_t reserved1;
  1134. /**
  1135. * @brief otgfs device out endpoint interrupt register, offset:0xb08 + endpoint number * 0x20
  1136. */
  1137. union
  1138. {
  1139. __IO uint32_t doepint;
  1140. struct
  1141. {
  1142. __IO uint32_t xferc : 1; /* [0] */
  1143. __IO uint32_t epdisd : 1; /* [1] */
  1144. __IO uint32_t reserved1 : 1; /* [2] */
  1145. __IO uint32_t setup : 1; /* [3] */
  1146. __IO uint32_t outtepd : 1; /* [4] */
  1147. __IO uint32_t reserved2 : 1; /* [5] */
  1148. __IO uint32_t b2pstup : 1; /* [6] */
  1149. __IO uint32_t reserved3 : 25; /* [31:7] */
  1150. } doepint_bit;
  1151. };
  1152. __IO uint32_t reserved2;
  1153. /**
  1154. * @brief otgfs device out endpoint transfer size register, offset:0xb10 + endpoint number * 0x20
  1155. */
  1156. union
  1157. {
  1158. __IO uint32_t doeptsiz;
  1159. struct
  1160. {
  1161. __IO uint32_t xfersize : 19; /* [18:0] */
  1162. __IO uint32_t pktcnt : 10; /* [28:19] */
  1163. __IO uint32_t rxdpid_setupcnt : 2; /* [30:29] */
  1164. __IO uint32_t reserved1 : 1; /* [31] */
  1165. } doeptsiz_bit;
  1166. };
  1167. } otg_eptout_type;
  1168. typedef struct
  1169. {
  1170. /**
  1171. * @brief otgfs power and clock gating control registers, offset:0xe00
  1172. */
  1173. union
  1174. {
  1175. __IO uint32_t pcgcctl;
  1176. struct
  1177. {
  1178. __IO uint32_t stoppclk : 1; /* [0] */
  1179. __IO uint32_t reserved1 : 3; /* [3:1] */
  1180. __IO uint32_t suspendm : 1; /* [4] */
  1181. __IO uint32_t reserved2 : 27; /* [31:5] */
  1182. } pcgcctl_bit;
  1183. };
  1184. } otg_pcgcctl_type;
  1185. /**
  1186. * @}
  1187. */
  1188. /** @defgroup USB_exported_functions
  1189. * @{
  1190. */
  1191. /**
  1192. * @brief usb host and device offset address
  1193. */
  1194. #define OTG_HOST_ADDR_OFFSET 0x400 /*!< usb host register offset address */
  1195. #define OTG_HOST_CHANNEL_ADDR_OFFSET 0x500 /*!< usb host channel register offset address */
  1196. #define OTG_DEVICE_ADDR_OFFSET 0x800 /*!< usb device register offset address */
  1197. #define OTG_DEVICE_EPTIN_ADDR_OFFSET 0x900 /*!< usb device endpoint in register offset address */
  1198. #define OTG_DEVICE_EPTOUT_ADDR_OFFSET 0xB00 /*!< usb device endpoint out register offset address */
  1199. #define OTG_PCGCCTL_ADDR_OFFSET 0xE00 /*!< usb power and clock control register offset address */
  1200. #define OTG_FIFO_ADDR_OFFSET 0x1000 /*!< usb fifo offset address */
  1201. /**
  1202. * @brief usb host and device register define
  1203. */
  1204. #define OTG1_GLOBAL ((otg_global_type *)(OTGFS1_BASE)) /*!< usb otg1 global register */
  1205. #define OTG_PCGCCTL(usbx) ((otg_pcgcctl_type *)((uint32_t)usbx + OTG_PCGCCTL_ADDR_OFFSET)) /*!< usb power and clock control register */
  1206. #define OTG_DEVICE(usbx) ((otg_device_type *)((uint32_t)usbx + OTG_DEVICE_ADDR_OFFSET)) /*!< usb device register */
  1207. #define OTG_HOST(usbx) ((otg_host_type *)((uint32_t)usbx + OTG_HOST_ADDR_OFFSET)) /*!< usb host register */
  1208. #define USB_CHL(usbx, n) ((otg_hchannel_type *)((uint32_t)usbx + OTG_HOST_CHANNEL_ADDR_OFFSET + n * 0x20)) /*!< usb channel n register */
  1209. #define USB_INEPT(usbx, eptn) ((otg_eptin_type *)((uint32_t)usbx + OTG_DEVICE_EPTIN_ADDR_OFFSET + eptn * 0x20)) /*!< usb device endpoint in register */
  1210. #define USB_OUTEPT(usbx, eptn) ((otg_eptout_type *)((uint32_t)usbx + OTG_DEVICE_EPTOUT_ADDR_OFFSET + eptn * 0x20)) /*!< usb device endpoint out register */
  1211. #define USB_FIFO(usbx, eptn) *(__IO uint32_t *)((uint32_t)usbx + OTG_FIFO_ADDR_OFFSET + eptn * 0x1000) /*!< usb fifo address */
  1212. typedef otg_global_type usb_reg_type;
  1213. /** @defgroup USB_exported_functions
  1214. * @{
  1215. */
  1216. #ifdef OTGFS_USB_GLOBAL
  1217. error_status usb_global_reset(otg_global_type *usbx);
  1218. void usb_global_init(otg_global_type *usbx);
  1219. otg_global_type *usb_global_select_core(uint8_t usb_id);
  1220. void usb_flush_tx_fifo(otg_global_type *usbx, uint32_t fifo_num);
  1221. void usb_flush_rx_fifo(otg_global_type *usbx);
  1222. void usb_global_interrupt_enable(otg_global_type *usbx, uint16_t interrupt, confirm_state new_state);
  1223. uint32_t usb_global_get_all_interrupt(otg_global_type *usbx);
  1224. void usb_global_clear_interrupt(otg_global_type *usbx, uint32_t flag);
  1225. void usb_interrupt_enable(otg_global_type *usbx);
  1226. void usb_interrupt_disable(otg_global_type *usbx);
  1227. void usb_set_rx_fifo(otg_global_type *usbx, uint16_t size);
  1228. void usb_set_tx_fifo(otg_global_type *usbx, uint8_t txfifo, uint16_t size);
  1229. void usb_global_set_mode(otg_global_type *usbx, uint32_t mode);
  1230. void usb_global_power_on(otg_global_type *usbx);
  1231. void usb_write_packet(otg_global_type *usbx, uint8_t *pusr_buf, uint16_t num, uint16_t nbytes);
  1232. void usb_read_packet(otg_global_type *usbx, uint8_t *pusr_buf, uint16_t num, uint16_t nbytes);
  1233. void usb_stop_phy_clk(otg_global_type *usbx);
  1234. void usb_open_phy_clk(otg_global_type *usbx);
  1235. #endif
  1236. #ifdef OTGFS_USB_DEVICE
  1237. void usb_ept_open(otg_global_type *usbx, usb_ept_info *ept_info);
  1238. void usb_ept_close(otg_global_type *usbx, usb_ept_info *ept_info);
  1239. void usb_ept_stall(otg_global_type *usbx, usb_ept_info *ept_info);
  1240. void usb_ept_clear_stall(otg_global_type *usbx, usb_ept_info *ept_info);
  1241. uint32_t usb_get_all_out_interrupt(otg_global_type *usbx);
  1242. uint32_t usb_get_all_in_interrupt(otg_global_type *usbx);
  1243. uint32_t usb_ept_out_interrupt(otg_global_type *usbx, uint32_t eptn);
  1244. uint32_t usb_ept_in_interrupt(otg_global_type *usbx, uint32_t eptn);
  1245. void usb_ept_out_clear(otg_global_type *usbx, uint32_t eptn, uint32_t flag);
  1246. void usb_ept_in_clear(otg_global_type *usbx, uint32_t eptn, uint32_t flag);
  1247. void usb_set_address(otg_global_type *usbx, uint8_t address);
  1248. void usb_ept0_start(otg_global_type *usbx);
  1249. void usb_ept0_setup(otg_global_type *usbx);
  1250. void usb_connect(otg_global_type *usbx);
  1251. void usb_disconnect(otg_global_type *usbx);
  1252. void usb_remote_wkup_set(otg_global_type *usbx);
  1253. void usb_remote_wkup_clear(otg_global_type *usbx);
  1254. uint8_t usb_suspend_status_get(otg_global_type *usbx);
  1255. #endif
  1256. #ifdef OTGFS_USB_HOST
  1257. void usb_port_power_on(otg_global_type *usbx, confirm_state state);
  1258. uint32_t usbh_get_frame(otg_global_type *usbx);
  1259. void usb_hc_enable(otg_global_type *usbx,
  1260. uint8_t chn,
  1261. uint8_t ept_num,
  1262. uint8_t dev_address,
  1263. uint8_t type,
  1264. uint16_t maxpacket,
  1265. uint8_t speed);
  1266. uint32_t usb_hch_read_interrupt(otg_global_type *usbx);
  1267. void usb_host_disable(otg_global_type *usbx);
  1268. void usb_hch_halt(otg_global_type *usbx, uint8_t chn);
  1269. void usbh_fsls_clksel(otg_global_type *usbx, uint8_t clk);
  1270. #endif
  1271. /**
  1272. * @}
  1273. */
  1274. /**
  1275. * @}
  1276. */
  1277. /**
  1278. * @}
  1279. */
  1280. /**
  1281. * @}
  1282. */
  1283. #ifdef __cplusplus
  1284. }
  1285. #endif
  1286. #endif