libopencm3
A free/libre/open-source firmware library for various ARM Cortex-M3 microcontrollers.
usb_common.h
Go to the documentation of this file.
1/** @addtogroup usb_defines
2 */
3/*
4 * This file is part of the libopencm3 project.
5 *
6 * Copyright (C) 2015 Kuldeep Singh Dhaka <kuldeepdhaka9@gmail.com>
7 *
8 * This library is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU Lesser General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with this library. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22#pragma once
23
25#include <libopencm3/usb/usbd.h>
26
27/**@{*/
28
29#define USB_CTRL MMIO32(USB_BASE + 0x000)
30#define USB_STATUS MMIO32(USB_BASE + 0x004)
31#define USB_IF MMIO32(USB_BASE + 0x008)
32#define USB_IFS MMIO32(USB_BASE + 0x00C)
33#define USB_IFC MMIO32(USB_BASE + 0x010)
34#define USB_IEN MMIO32(USB_BASE + 0x014)
35#define USB_ROUTE MMIO32(USB_BASE + 0x018)
36
37/* USB_CTRL */
38#define USB_CTRL_DMPUAP (1 << 1)
39
40/* USB_ROUTE */
41#define USB_ROUTE_DMPUPEN (1 << 2)
42#define USB_ROUTE_VBUSENPEN (1 << 1)
43#define USB_ROUTE_PHYPEN (1 << 0)
44
45/* Core Global Control and Status Registers */
46#define USB_OTG_BASE (USB_BASE + 0x3C000)
47#define USB_GOTGCTL MMIO32(USB_OTG_BASE + 0x000)
48#define USB_GOTGINT MMIO32(USB_OTG_BASE + 0x004)
49#define USB_GAHBCFG MMIO32(USB_OTG_BASE + 0x008)
50#define USB_GUSBCFG MMIO32(USB_OTG_BASE + 0x00C)
51#define USB_GRSTCTL MMIO32(USB_OTG_BASE + 0x010)
52#define USB_GINTSTS MMIO32(USB_OTG_BASE + 0x014)
53#define USB_GINTMSK MMIO32(USB_OTG_BASE + 0x018)
54#define USB_GRXSTSR MMIO32(USB_OTG_BASE + 0x01C)
55#define USB_GRXSTSP MMIO32(USB_OTG_BASE + 0x020)
56#define USB_GRXFSIZ MMIO32(USB_OTG_BASE + 0x024)
57#define USB_GNPTXFSIZ MMIO32(USB_OTG_BASE + 0x028)
58#define USB_GNPTXSTS MMIO32(USB_OTG_BASE + 0x02C)
59#define USB_GDFIFOCFG MMIO32(USB_OTG_BASE + 0x05C)
60#define USB_HPTXFSIZ MMIO32(USB_OTG_BASE + 0x100)
61#define USB_DIEPTXF(x) \
62 MMIO32(USB_OTG_BASE + 0x104 + (4 * ((x) - 1)))
63
64/* Host-mode Control and Status Registers */
65#define USB_HCFG MMIO32(USB_OTG_BASE + 0x400)
66#define USB_HFIR MMIO32(USB_OTG_BASE + 0x404)
67#define USB_HFNUM MMIO32(USB_OTG_BASE + 0x408)
68#define USB_HPTXSTS MMIO32(USB_OTG_BASE + 0x410)
69#define USB_HAINT MMIO32(USB_OTG_BASE + 0x414)
70#define USB_HAINTMSK MMIO32(USB_OTG_BASE + 0x418)
71#define USB_HPRT MMIO32(USB_OTG_BASE + 0x440)
72#define USB_HCx_CHAR(x) \
73 MMIO32(USB_OTG_BASE + 0x500 + ((x) * 0x20))
74#define USB_HCx_INT(x) \
75 MMIO32(USB_OTG_BASE + 0x508 + ((x) * 0x20))
76#define USB_HCx_INTMSK(x) \
77 MMIO32(USB_OTG_BASE + 0x50C + ((x) * 0x20))
78#define USB_HCx_TSIZ(x) \
79 MMIO32(USB_OTG_BASE + 0x510 + ((x) * 0x20))
80#define USB_HCx_DMAADDR(x) \
81 MMIO32(USB_OTG_BASE + 0x514 + ((x) * 0x20))
82
83/* Device-mode Control and Status Registers */
84#define USB_DCFG MMIO32(USB_OTG_BASE + 0x800)
85#define USB_DCTL MMIO32(USB_OTG_BASE + 0x804)
86#define USB_DSTS MMIO32(USB_OTG_BASE + 0x808)
87#define USB_DIEPMSK MMIO32(USB_OTG_BASE + 0x810)
88#define USB_DOEPMSK MMIO32(USB_OTG_BASE + 0x814)
89#define USB_DAINT MMIO32(USB_OTG_BASE + 0x818)
90#define USB_DAINTMSK MMIO32(USB_OTG_BASE + 0x81C)
91#define USB_DVBUSDIS MMIO32(USB_OTG_BASE + 0x828)
92#define USB_DVBUSPULSE MMIO32(USB_OTG_BASE + 0x82C)
93#define USB_DIEPEMPMSK MMIO32(USB_OTG_BASE + 0x834)
94
95#define USB_DIEPx_CTL(x) \
96 MMIO32(USB_OTG_BASE + 0x900 + ((x) * 0x20))
97#define USB_DIEPx_INT(x) \
98 MMIO32(USB_OTG_BASE + 0x908 + ((x) * 0x20))
99#define USB_DIEPx_TSIZ(x) \
100 MMIO32(USB_OTG_BASE + 0x910 + ((x) * 0x20))
101#define USB_DIEP0CTL USB_DIEPx_CTL(0)
102#define USB_DIEP0TSIZ USB_DIEPx_TSIZ(0)
103#define USB_DIEP0INT USB_DIEPx_INT(0)
104
105#define USB_DOEPx_CTL(x) \
106 MMIO32(USB_OTG_BASE + 0xB00 + ((x) * 0x20))
107#define USB_DOEPx_INT(x) \
108 MMIO32(USB_OTG_BASE + 0xB08 + ((x) * 0x20))
109#define USB_DOEPx_TSIZ(x) \
110 MMIO32(USB_OTG_BASE + 0xB10 + ((x) * 0x20))
111#define USB_DOEP0CTL USB_DOEPx_CTL(0)
112#define USB_DOEP0TSIZ USB_DOEPx_TSIZ(0)
113#define USB_DOEP0INT USB_DOEPx_INT(0)
114
115/* Power and clock gating control and status register */
116#define USB_PCGCCTL MMIO32(USB_OTG_BASE + 0xE00)
117
118/* Data FIFO */
119#define USB_FIFOxD(x) \
120 (&MMIO32(USB_OTG_BASE + (((x) + 1) << 12)))
121
122/* Global CSRs */
123/* USB control registers (OTG_HS_GOTGCTL) */
124#define USB_GOTGCTL_BSVLD (1 << 19)
125#define USB_GOTGCTL_ASVLD (1 << 18)
126#define USB_GOTGCTL_DBCT (1 << 17)
127#define USB_GOTGCTL_CIDSTS (1 << 16)
128#define USB_GOTGCTL_DHNPEN (1 << 11)
129#define USB_GOTGCTL_HSHNPEN (1 << 10)
130#define USB_GOTGCTL_HNPRQ (1 << 9)
131#define USB_GOTGCTL_HNGSCS (1 << 8)
132#define USB_GOTGCTL_SRQ (1 << 1)
133#define USB_GOTGCTL_SRQSCS (1 << 0)
134
135/* AHB configuration register (USB_GAHBCFG) */
136#define USB_GAHBCFG_GLBLINTRMSK 0x0001
137#define USB_GAHBCFG_TXFELVL 0x0080
138#define USB_GAHBCFG_PTXFELVL 0x0100
139
140/* USB configuration register (USB_GUSBCFG) */
141#define USB_GUSBCFG_TOCAL 0x00000003
142#define USB_GUSBCFG_SRPCAP 0x00000100
143#define USB_GUSBCFG_HNPCAP 0x00000200
144#define USB_GUSBCFG_TRDT_MASK (0xf << 10)
145#define USB_GUSBCFG_TRDT_16BIT (0x5 << 10)
146#define USB_GUSBCFG_TRDT_8BIT (0x9 << 10)
147#define USB_GUSBCFG_NPTXRWEN 0x00004000
148#define USB_GUSBCFG_FHMOD 0x20000000
149#define USB_GUSBCFG_FDMOD 0x40000000
150#define USB_GUSBCFG_CTXPKT 0x80000000
151#define USB_GUSBCFG_PHYSEL (1 << 7)
152
153/* reset register (USB_GRSTCTL) */
154#define USB_GRSTCTL_AHBIDL (1 << 31)
155/* Bits 30:11 - Reserved */
156#define USB_GRSTCTL_TXFNUM_MASK (0x1f << 6)
157#define USB_GRSTCTL_TXFFLSH (1 << 5)
158#define USB_GRSTCTL_RXFFLSH (1 << 4)
159/* Bit 3 - Reserved */
160#define USB_GRSTCTL_FCRST (1 << 2)
161#define USB_GRSTCTL_HSRST (1 << 1)
162#define USB_GRSTCTL_CSRST (1 << 0)
163
164/* interrupt status register (USB_GINTSTS) */
165#define USB_GINTSTS_WKUPINT (1 << 31)
166#define USB_GINTSTS_SRQINT (1 << 30)
167#define USB_GINTSTS_DISCINT (1 << 29)
168#define USB_GINTSTS_CIDSCHG (1 << 28)
169/* Bit 27 - Reserved */
170#define USB_GINTSTS_PTXFE (1 << 26)
171#define USB_GINTSTS_HCINT (1 << 25)
172#define USB_GINTSTS_HPRTINT (1 << 24)
173/* Bits 23:22 - Reserved */
174#define USB_GINTSTS_IPXFR (1 << 21)
175#define USB_GINTSTS_INCOMPISOOUT (1 << 21)
176#define USB_GINTSTS_IISOIXFR (1 << 20)
177#define USB_GINTSTS_OEPINT (1 << 19)
178#define USB_GINTSTS_IEPINT (1 << 18)
179/* Bits 17:16 - Reserved */
180#define USB_GINTSTS_EOPF (1 << 15)
181#define USB_GINTSTS_ISOODRP (1 << 14)
182#define USB_GINTSTS_ENUMDNE (1 << 13)
183#define USB_GINTSTS_USBRST (1 << 12)
184#define USB_GINTSTS_USBSUSP (1 << 11)
185#define USB_GINTSTS_ESUSP (1 << 10)
186/* Bits 9:8 - Reserved */
187#define USB_GINTSTS_GONAKEFF (1 << 7)
188#define USB_GINTSTS_GINAKEFF (1 << 6)
189#define USB_GINTSTS_NPTXFE (1 << 5)
190#define USB_GINTSTS_RXFLVL (1 << 4)
191#define USB_GINTSTS_SOF (1 << 3)
192#define USB_GINTSTS_OTGINT (1 << 2)
193#define USB_GINTSTS_MMIS (1 << 1)
194#define USB_GINTSTS_CMOD (1 << 0)
195
196/* interrupt mask register (USB_GINTMSK) */
197#define USB_GINTMSK_MMISM 0x00000002
198#define USB_GINTMSK_OTGINT 0x00000004
199#define USB_GINTMSK_SOFM 0x00000008
200#define USB_GINTMSK_RXFLVLM 0x00000010
201#define USB_GINTMSK_NPTXFEM 0x00000020
202#define USB_GINTMSK_GINAKEFFM 0x00000040
203#define USB_GINTMSK_GONAKEFFM 0x00000080
204#define USB_GINTMSK_ESUSPM 0x00000400
205#define USB_GINTMSK_USBSUSPM 0x00000800
206#define USB_GINTMSK_USBRST 0x00001000
207#define USB_GINTMSK_ENUMDNEM 0x00002000
208#define USB_GINTMSK_ISOODRPM 0x00004000
209#define USB_GINTMSK_EOPFM 0x00008000
210#define USB_GINTMSK_EPMISM 0x00020000
211#define USB_GINTMSK_IEPINT 0x00040000
212#define USB_GINTMSK_OEPINT 0x00080000
213#define USB_GINTMSK_IISOIXFRM 0x00100000
214#define USB_GINTMSK_IISOOXFRM 0x00200000
215#define USB_GINTMSK_IPXFRM 0x00200000
216#define USB_GINTMSK_PRTIM 0x01000000
217#define USB_GINTMSK_HCIM 0x02000000
218#define USB_GINTMSK_PTXFEM 0x04000000
219#define USB_GINTMSK_CIDSCHGM 0x10000000
220#define USB_GINTMSK_DISCINT 0x20000000
221#define USB_GINTMSK_SRQIM 0x40000000
222#define USB_GINTMSK_WUIM 0x80000000
223
224/* Receive Status Pop Register (USB_GRXSTSP) */
225/* Bits 31:25 - Reserved */
226#define USB_GRXSTSP_FRMNUM_MASK (0xf << 21)
227#define USB_GRXSTSP_PKTSTS_MASK (0xf << 17)
228#define USB_GRXSTSP_PKTSTS_GOUTNAK (0x1 << 17)
229#define USB_GRXSTSP_PKTSTS_OUT (0x2 << 17)
230#define USB_GRXSTSP_PKTSTS_OUT_COMP (0x3 << 17)
231#define USB_GRXSTSP_PKTSTS_SETUP_COMP (0x4 << 17)
232#define USB_GRXSTSP_PKTSTS_SETUP (0x6 << 17)
233#define USB_GRXSTSP_DPID_MASK (0x3 << 15)
234#define USB_GRXSTSP_DPID_DATA0 (0x0 << 15)
235#define USB_GRXSTSP_DPID_DATA1 (0x2 << 15)
236#define USB_GRXSTSP_DPID_DATA2 (0x1 << 15)
237#define USB_GRXSTSP_DPID_MDATA (0x3 << 15)
238#define USB_GRXSTSP_BCNT_MASK (0x7ff << 4)
239#define USB_GRXSTSP_EPNUM_MASK (0xf << 0)
240
241/* general core configuration register (USB_GCCFG) */
242/* Bits 31:22 - Reserved */
243#define USB_GCCFG_NOVBUSSENS (1 << 21)
244#define USB_GCCFG_SOFOUTEN (1 << 20)
245#define USB_GCCFG_VBUSBSEN (1 << 19)
246#define USB_GCCFG_VBUSASEN (1 << 18)
247/* Bit 17 - Reserved */
248#define USB_GCCFG_PWRDWN (1 << 16)
249/* Bits 15:0 - Reserved */
250
251
252/* Device-mode CSRs */
253/* device control register (USB_DCTL) */
254/* Bits 31:12 - Reserved */
255#define USB_DCTL_POPRGDNE (1 << 11)
256#define USB_DCTL_CGONAK (1 << 10)
257#define USB_DCTL_SGONAK (1 << 9)
258#define USB_DCTL_SGINAK (1 << 8)
259#define USB_DCTL_TCTL_MASK (7 << 4)
260#define USB_DCTL_GONSTS (1 << 3)
261#define USB_DCTL_GINSTS (1 << 2)
262#define USB_DCTL_SDIS (1 << 1)
263#define USB_DCTL_RWUSIG (1 << 0)
264
265/* device configuration register (USB_DCFG) */
266#define USB_DCFG_DSPD 0x0003
267#define USB_DCFG_NZLSOHSK 0x0004
268#define USB_DCFG_DAD 0x07F0
269#define USB_DCFG_PFIVL 0x1800
270
271/* Device IN Endpoint Common Interrupt Mask Register (USB_DIEPMSK) */
272/* Bits 31:10 - Reserved */
273#define USB_DIEPMSK_BIM (1 << 9)
274#define USB_DIEPMSK_TXFURM (1 << 8)
275/* Bit 7 - Reserved */
276#define USB_DIEPMSK_INEPNEM (1 << 6)
277#define USB_DIEPMSK_INEPNMM (1 << 5)
278#define USB_DIEPMSK_ITTXFEMSK (1 << 4)
279#define USB_DIEPMSK_TOM (1 << 3)
280/* Bit 2 - Reserved */
281#define USB_DIEPMSK_EPDM (1 << 1)
282#define USB_DIEPMSK_XFRCM (1 << 0)
283
284/* Device OUT Endpoint Common Interrupt Mask Register (USB_DOEPMSK) */
285/* Bits 31:10 - Reserved */
286#define USB_DOEPMSK_BOIM (1 << 9)
287#define USB_DOEPMSK_OPEM (1 << 8)
288/* Bit 7 - Reserved */
289#define USB_DOEPMSK_B2BSTUP (1 << 6)
290/* Bit 5 - Reserved */
291#define USB_DOEPMSK_OTEPDM (1 << 4)
292#define USB_DOEPMSK_STUPM (1 << 3)
293/* Bit 2 - Reserved */
294#define USB_DOEPMSK_EPDM (1 << 1)
295#define USB_DOEPMSK_XFRCM (1 << 0)
296
297/* Device Control IN Endpoint 0 Control Register (USB_DIEP0CTL) */
298#define USB_DIEP0CTL_EPENA (1 << 31)
299#define USB_DIEP0CTL_EPDIS (1 << 30)
300/* Bits 29:28 - Reserved */
301#define USB_DIEP0CTL_SD0PID (1 << 28)
302#define USB_DIEP0CTL_SNAK (1 << 27)
303#define USB_DIEP0CTL_CNAK (1 << 26)
304#define USB_DIEP0CTL_TXFNUM_MASK (0xf << 22)
305#define USB_DIEP0CTL_STALL (1 << 21)
306/* Bit 20 - Reserved */
307#define USB_DIEP0CTL_EPTYP_MASK (0x3 << 18)
308#define USB_DIEP0CTL_NAKSTS (1 << 17)
309/* Bit 16 - Reserved */
310#define USB_DIEP0CTL_USBAEP (1 << 15)
311/* Bits 14:2 - Reserved */
312#define USB_DIEP0CTL_MPSIZ_MASK (0x3 << 0)
313#define USB_DIEP0CTL_MPSIZ_64 (0x0 << 0)
314#define USB_DIEP0CTL_MPSIZ_32 (0x1 << 0)
315#define USB_DIEP0CTL_MPSIZ_16 (0x2 << 0)
316#define USB_DIEP0CTL_MPSIZ_8 (0x3 << 0)
317
318/* Device Control OUT Endpoint 0 Control Register (USB_DOEP0CTL) */
319#define USB_DOEP0CTL_EPENA (1 << 31)
320#define USB_DOEP0CTL_EPDIS (1 << 30)
321/* Bits 29:28 - Reserved */
322#define USB_DOEP0CTL_SD0PID (1 << 28)
323#define USB_DOEP0CTL_SNAK (1 << 27)
324#define USB_DOEP0CTL_CNAK (1 << 26)
325/* Bits 25:22 - Reserved */
326#define USB_DOEP0CTL_STALL (1 << 21)
327#define USB_DOEP0CTL_SNPM (1 << 20)
328#define USB_DOEP0CTL_EPTYP_MASK (0x3 << 18)
329#define USB_DOEP0CTL_NAKSTS (1 << 17)
330/* Bit 16 - Reserved */
331#define USB_DOEP0CTL_USBAEP (1 << 15)
332/* Bits 14:2 - Reserved */
333#define USB_DOEP0CTL_MPSIZ_MASK (0x3 << 0)
334#define USB_DOEP0CTL_MPSIZ_64 (0x0 << 0)
335#define USB_DOEP0CTL_MPSIZ_32 (0x1 << 0)
336#define USB_DOEP0CTL_MPSIZ_16 (0x2 << 0)
337#define USB_DOEP0CTL_MPSIZ_8 (0x3 << 0)
338
339/* Device IN Endpoint Interrupt Register (USB_DIEPINTx) */
340/* Bits 31:8 - Reserved */
341#define USB_DIEP_INT_TXFE (1 << 7)
342#define USB_DIEP_INT_INEPNE (1 << 6)
343/* Bit 5 - Reserved */
344#define USB_DIEP_INT_ITTXFE (1 << 4)
345#define USB_DIEP_INT_TOC (1 << 3)
346/* Bit 2 - Reserved */
347#define USB_DIEP_INT_EPDISD (1 << 1)
348#define USB_DIEP_INT_XFRC (1 << 0)
349
350/* Device IN Endpoint Interrupt Register (USB_DOEPINTx) */
351/* Bits 31:7 - Reserved */
352#define USB_DOEP_INT_B2BSTUP (1 << 6)
353/* Bit 5 - Reserved */
354#define USB_DOEP_INT_OTEPDIS (1 << 4)
355#define USB_DOEP_INT_SETUP (1 << 3)
356/* Bit 2 - Reserved */
357#define USB_DOEP_INT_EPDISD (1 << 1)
358#define USB_DOEP_INT_XFRC (1 << 0)
359
360/* Device OUT Endpoint 0 Transfer Size Register (USB_DOEP0TSIZ) */
361/* Bit 31 - Reserved */
362#define USB_DIEP0TSIZ_STUPCNT_1 (0x1 << 29)
363#define USB_DIEP0TSIZ_STUPCNT_2 (0x2 << 29)
364#define USB_DIEP0TSIZ_STUPCNT_3 (0x3 << 29)
365#define USB_DIEP0TSIZ_STUPCNT_MASK (0x3 << 29)
366/* Bits 28:20 - Reserved */
367#define USB_DIEP0TSIZ_PKTCNT (1 << 19)
368/* Bits 18:7 - Reserved */
369#define USB_DIEP0TSIZ_XFRSIZ_MASK (0x7f << 0)
370
371/**@}*/