libopencm3
A free/libre/open-source firmware library for various ARM Cortex-M3 microcontrollers.
usb.h
Go to the documentation of this file.
1/*
2 * This file is part of the libopencm3 project.
3 *
4 * Copyright (C) 2012 Alexandru Gagniuc <mr.nuke.me@gmail.com>
5 *
6 * This library is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this library. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20/** @defgroup usb_defines USB Controller
21 *
22 * @brief <b>Defined Constants and Types for the LM4F USB Controller</b>
23 *
24 * @ingroup LM4Fxx_defines
25 *
26 * @version 1.0.0
27 *
28 * @author @htmlonly &copy; @endhtmlonly 2013 Alexandru Gagniuc <mr.nuke.me@gmail.com>
29 *
30 * @date 15 May 2013
31 *
32 * LGPL License Terms @ref lgpl_license
33 */
34
35
36#ifndef LIBOPENCM3_LM4F_USB_H
37#define LIBOPENCM3_LM4F_USB_H
38
39/**@{*/
40
43
44/* ============================================================================
45 * USB registers
46 * --------------------------------------------------------------------------*/
47
48/* USB Device Functional Address */
49#define USB_FADDR MMIO8(USB_BASE + 0x00)
50
51/* USB Power */
52#define USB_POWER MMIO8(USB_BASE + 0x01)
53
54/* USB Transmit Interrupt Status */
55#define USB_TXIS MMIO16(USB_BASE + 0x02)
56
57/* USB Receive Interrupt Status */
58#define USB_RXIS MMIO16(USB_BASE + 0x04)
59
60/* USB Transmit Interrupt Enable */
61#define USB_TXIE MMIO16(USB_BASE + 0x06)
62
63/* USB Receive Interrupt Enable */
64#define USB_RXIE MMIO16(USB_BASE + 0x08)
65
66/* USB General Interrupt Status */
67#define USB_IS MMIO8(USB_BASE + 0x0A)
68
69/* USB Interrupt Enable */
70#define USB_IE MMIO8(USB_BASE + 0x0B)
71
72/* USB Frame Value */
73#define USB_FRAME MMIO16(USB_BASE + 0x0C)
74
75/* USB Endpoint Index */
76#define USB_EPIDX MMIO8(USB_BASE + 0x0E)
77
78/* USB Test Mode */
79#define USB_TEST MMIO8(USB_BASE + 0x0F)
80
81/* USB FIFO Endpoint [0-7] */
82#define USB_FIFO8(n) MMIO8(USB_BASE + 0x20 + (n)*0x04)
83#define USB_FIFO16(n) MMIO16(USB_BASE + 0x20 + (n)*0x04)
84#define USB_FIFO32(n) MMIO32(USB_BASE + 0x20 + (n)*0x04)
85
86/* USB Transmit Dynamic FIFO Sizing */
87#define USB_TXFIFOSZ MMIO8(USB_BASE + 0x62)
88
89/* USB Receive Dynamic FIFO Sizing */
90#define USB_RXFIFOSZ MMIO8(USB_BASE + 0x63)
91
92/* USB Transmit FIFO Start Address */
93#define USB_TXFIFOADD MMIO16(USB_BASE + 0x64)
94
95/* USB Receive FIFO Start Address */
96#define USB_RXFIFOADD MMIO16(USB_BASE + 0x66)
97
98/* USB Connect Timing */
99#define USB_CONTIM MMIO8(USB_BASE + 0x7A)
100
101/* USB Full-Speed Last Transaction to End of Frame Timing */
102#define USB_FSEOF MMIO8(USB_BASE + 0x7D)
103
104/* USB Low-Speed Last Transaction to End of Frame Timing */
105#define USB_LSEOF MMIO8(USB_BASE + 0x7E)
106
107/* USB Control and Status Endpoint 0 Low */
108#define USB_CSRL0 MMIO8(USB_BASE + 0x102)
109
110/* USB Control and Status Endpoint 0 High */
111#define USB_CSRH0 MMIO8(USB_BASE + 0x103)
112
113/* USB Receive Byte Count Endpoint 0 */
114#define USB_COUNT0 MMIO8(USB_BASE + 0x108)
115
116/* USB Maximum Transmit Data Endpoint [1-7] */
117#define USB_TXMAXP(n) MMIO16(USB_BASE + 0x100 + (n)*0x10)
118
119/* USB Transmit Control and Status Endpoint [1-7] Low */
120#define USB_TXCSRL(n) MMIO8(USB_BASE + 0x102 + (n)*0x10)
121
122/* USB Transmit Control and Status Endpoint [1-7] High */
123#define USB_TXCSRH(n) MMIO8(USB_BASE + 0x103 + (n)*0x10)
124
125/* USB Maximum Receive Data Endpoint [1-7] */
126#define USB_RXMAXP(n) MMIO16(USB_BASE + 0x104 + (n)*0x10)
127
128/* USB Receive Control and Status Endpoint [1-7] Low */
129#define USB_RXCSRL(n) MMIO8(USB_BASE + 0x106 + (n)*0x10)
130
131/* USB Receive Control and Status Endpoint [1-7] High */
132#define USB_RXCSRH(n) MMIO8(USB_BASE + 0x107 + (n)*0x10)
133
134/* USB Receive Byte Count Endpoint [1-7] */
135#define USB_RXCOUNT(n) MMIO16(USB_BASE + 0x108 + (n)*0x10)
136
137/* USB Receive Double Packet Buffer Disable */
138#define USB_RXDPKTBUFDIS MMIO16(USB_BASE + 0x340)
139
140/* USB Transmit Double Packet Buffer Disable */
141#define USB_TXDPKTBUFDIS MMIO16(USB_BASE + 0x342)
142
143/* USB Device RESUME Raw Interrupt Status */
144#define USB_DRRIS MMIO32(USB_BASE + 0x410)
145
146/* USB Device RESUME Interrupt Mask */
147#define USB_DRIM MMIO32(USB_BASE + 0x414)
148
149/* USB Device RESUME Interrupt Status and Clear */
150#define USB_DRISC MMIO32(USB_BASE + 0x418)
151
152/* USB DMA Select */
153#define USB_DMASEL MMIO32(USB_BASE + 0x450)
154
155/* USB Peripheral Properties */
156#define USB_PP MMIO32(USB_BASE + 0xFC0)
157
158
159/* =============================================================================
160 * USB_FADDR values
161 * ---------------------------------------------------------------------------*/
162/** Function Address */
163#define USB_FADDR_FUNCADDR_MASK (0x3f << 0)
164
165/* =============================================================================
166 * USB_POWER values
167 * ---------------------------------------------------------------------------*/
168/** Isochronous Update */
169#define USB_POWER_ISOUP (1 << 7)
170/** Soft Connect/Disconnect */
171#define USB_POWER_SOFTCONN (1 << 6)
172/** RESET signaling */
173#define USB_POWER_RESET (1 << 3)
174/** RESUME signaling */
175#define USB_POWER_RESUME (1 << 2)
176/** SUSPEND mode */
177#define USB_POWER_SUSPEND (1 << 1)
178/** Power down PHY */
179#define USB_POWER_PWRDNPHY (1 << 0)
180
181/* =============================================================================
182 * Endpoint bitmasks for interrupt status and control registers
183 * Applies to USB_TXIS, USB_RXIS, USB_TXIE, USB_RXIE, USB_RXDPKTBUFDIS,
184 * USB_TXDPKTBUFDIS
185 * ---------------------------------------------------------------------------*/
186#define USB_EP7 (1 << 7)
187#define USB_EP6 (1 << 6)
188#define USB_EP5 (1 << 5)
189#define USB_EP4 (1 << 4)
190#define USB_EP3 (1 << 3)
191#define USB_EP2 (1 << 2)
192#define USB_EP1 (1 << 1)
193#define USB_EP0 (1 << 0)
194
195/* =============================================================================
196 * USB interrupt mask values
197 *
198 * These are interchangeable across USB_IS, and USB_IE registers.
199 * ---------------------------------------------------------------------------*/
200/** USB disconnect interrupt */
201#define USB_IM_DISCON (1 << 5)
202/** Start of frame */
203#define USB_IM_SOF (1 << 3)
204/** RESET signaling detected */
205#define USB_IM_RESET (1 << 2)
206/** RESUME signaling detected */
207#define USB_IM_RESUME (1 << 1)
208/** SUSPEND signaling detected */
209#define USB_IM_SUSPEND (1 << 0)
210
211/* =============================================================================
212 * USB_FRAME values
213 * ---------------------------------------------------------------------------*/
214/** Frame number */
215#define USB_FRAME_MASK (0x03FF)
216
217/* =============================================================================
218 * USB_IDX values
219 * ---------------------------------------------------------------------------*/
220/** Endpoint Index */
221#define USB_EPIDX_MASK (0x0F)
222
223/* =============================================================================
224 * USB_TEST values
225 * ---------------------------------------------------------------------------*/
226/** FIFO access */
227#define USB_TEST_FIFOACC (1 << 6)
228/** Force full-speed mode */
229#define USB_TEST_FORCEFS (1 << 5)
230
231/* =============================================================================
232 * USB_TXFIFOSZ and USB_RXFIFOSZ values
233 * ---------------------------------------------------------------------------*/
234/** Double packet buffer support */
235#define USB_FIFOSZ_DPB (1 << 4)
236/* USB Transmit Dynamic FIFO Sizing */
237#define USB_FIFOSZ_SIZE_MASK (0x0F << 0)
238#define USB_FIFOSZ_SIZE_8 (0x00 << 0)
239#define USB_FIFOSZ_SIZE_16 (0x01 << 0)
240#define USB_FIFOSZ_SIZE_32 (0x02 << 0)
241#define USB_FIFOSZ_SIZE_64 (0x03 << 0)
242#define USB_FIFOSZ_SIZE_128 (0x04 << 0)
243#define USB_FIFOSZ_SIZE_256 (0x05 << 0)
244#define USB_FIFOSZ_SIZE_512 (0x06 << 0)
245#define USB_FIFOSZ_SIZE_1024 (0x07 << 0)
246#define USB_FIFOSZ_SIZE_2048 (0x08 << 0)
247
248
249/* =============================================================================
250 * USB_CONTIM values
251 * ---------------------------------------------------------------------------*/
252/** Connect wait */
253#define USB_CONTIM_WTCON_MASK (0x0F << 4)
254/** Wait ID */
255#define USB_CONTIM_WTID_MASK (0x0F << 0)
256
257/* =============================================================================
258 * USB_CSRL0 values
259 * ---------------------------------------------------------------------------*/
260/** Setup End Clear */
261#define USB_CSRL0_SETENDC (1 << 7)
262/** RXRDY Clear */
263#define USB_CSRL0_RXRDYC (1 << 6)
264/** Send Stall */
265#define USB_CSRL0_STALL (1 << 5)
266/** Setup End */
267#define USB_CSRL0_SETEND (1 << 4)
268/** Data End */
269#define USB_CSRL0_DATAEND (1 << 3)
270/** Endpoint Stalled */
271#define USB_CSRL0_STALLED (1 << 2)
272/** Transmit Packet Ready */
273#define USB_CSRL0_TXRDY (1 << 1)
274/** Receive Packet Ready */
275#define USB_CSRL0_RXRDY (1 << 0)
276
277/* =============================================================================
278 * USB_CSRH0 values
279 * ---------------------------------------------------------------------------*/
280/** Flush FIFO */
281#define USB_CSRH0_FLUSH (1 << 0)
282
283/* =============================================================================
284 * USB_TXCSRLx values
285 * ---------------------------------------------------------------------------*/
286/** Clear data toggle */
287#define USB_TXCSRL_CLRDT (1 << 6)
288/** Endpoint Stalled */
289#define USB_TXCSRL_STALLED (1 << 5)
290/** Send Stall */
291#define USB_TXCSRL_STALL (1 << 4)
292/** Flush FIFO */
293#define USB_TXCSRL_FLUSH (1 << 3)
294/** Underrun */
295#define USB_TXCSRL_UNDRN (1 << 2)
296/** FIFO not empty */
297#define USB_TXCSRL_FIFONE (1 << 1)
298/** Transmit Packet Ready */
299#define USB_TXCSRL_TXRDY (1 << 0)
300
301/* =============================================================================
302 * USB_TXCSRHx values
303 * ---------------------------------------------------------------------------*/
304/** Auto set */
305#define USB_TXCSRH_AUTOSET (1 << 7)
306/** Isochronous transfers */
307#define USB_TXCSRH_ISO (1 << 6)
308/** Mode */
309#define USB_TXCSRH_MODE (1 << 5)
310/** DMA request enable */
311#define USB_TXCSRH_DMAEN (1 << 4)
312/** Force data toggle */
313#define USB_TXCSRH_FDT (1 << 3)
314/** DMA request mode */
315#define USB_TXCSRH_DMAMOD (1 << 2)
316
317/* =============================================================================
318 * USB_RXCSRLx values
319 * ---------------------------------------------------------------------------*/
320/** Clear data toggle */
321#define USB_RXCSRL_CLRDT (1 << 7)
322/** Endpoint Stalled */
323#define USB_RXCSRL_STALLED (1 << 6)
324/** Send Stall */
325#define USB_RXCSRL_STALL (1 << 5)
326/** Flush FIFO */
327#define USB_RXCSRL_FLUSH (1 << 4)
328/** Data error */
329#define USB_RXCSRL_DATAERR (1 << 2)
330/** Overrun */
331#define USB_RXCSRL_OVER (1 << 2)
332/** FIFO full */
333#define USB_RXCSRL_FULL (1 << 1)
334/** Receive Packet Ready */
335#define USB_RXCSRL_RXRDY (1 << 0)
336
337/* =============================================================================
338 * USB_RXCSRHx values
339 * ---------------------------------------------------------------------------*/
340/** Auto clear */
341#define USB_RXCSRH_AUTOCL (1 << 7)
342/** Isochronous transfers */
343#define USB_RXCSRH_ISO (1 << 6)
344/** DMA request enable */
345#define USB_RXCSRH_DMAEN (1 << 5)
346/** Disable NYET / PID error */
347#define USB_RXCSRH_PIDERR (1 << 4)
348/** DMA request mode */
349#define USB_RXCSRH_DMAMOD (1 << 3)
350
351/* =============================================================================
352 * USB_DRRIS values
353 * ---------------------------------------------------------------------------*/
354/** RESUME interrupt status */
355#define USB_DRRIS_RESUME (1 << 0)
356
357/* =============================================================================
358 * USB_DRIM values
359 * ---------------------------------------------------------------------------*/
360/** RESUME interrupt mask */
361#define USB_DRIM_RESUME (1 << 0)
362
363/* =============================================================================
364 * USB_DRISC values
365 * ---------------------------------------------------------------------------*/
366/** RESUME interrupt status and clear */
367#define USB_DRISC_RESUME (1 << 0)
368
369/* =============================================================================
370 * USB_PP values
371 * ---------------------------------------------------------------------------*/
372/** Endpoint count */
373#define USB_PP_ECNT_MASK (0xFF << 8)
374/** USB capability */
375#define USB_PP_USB_MASK (0x03 << 6)
376#define USB_PP_USB_NA (0x00 << 6)
377#define USB_PP_USB_DEVICE (0x01 << 6)
378#define USB_PP_USB_HOST (0x02 << 6)
379#define USB_PP_USB_OTG (0x03 << 6)
380/** PHY present */
381#define USB_PP_PHY (1 << 4)
382/** Controller type */
383#define USB_PP_TYPE_MASK (0x0F << 0)
384
385/* =============================================================================
386 * Convenience enums
387 * ---------------------------------------------------------------------------*/
394};
395
405};
406/* =============================================================================
407 * Function prototypes
408 * ---------------------------------------------------------------------------*/
410
412 enum usb_ep_interrupt rx_ints,
413 enum usb_ep_interrupt tx_ints);
415 enum usb_ep_interrupt rx_ints,
416 enum usb_ep_interrupt tx_ints);
417
419
420/**@}*/
421
422#endif /* LIBOPENCM3_LM4F_USB_H */
#define END_DECLS
Definition: common.h:34
#define BEGIN_DECLS
Definition: common.h:33
usb_interrupt
Definition: usb.h:388
#define USB_EP5
Definition: usb.h:188
#define USB_EP2
Definition: usb.h:191
#define USB_IM_RESUME
RESUME signaling detected.
Definition: usb.h:207
#define USB_EP7
Definition: usb.h:186
#define USB_EP4
Definition: usb.h:189
#define USB_EP0
Definition: usb.h:193
#define USB_IM_DISCON
USB disconnect interrupt.
Definition: usb.h:201
void usb_disable_interrupts(enum usb_interrupt ints, enum usb_ep_interrupt rx_ints, enum usb_ep_interrupt tx_ints)
Disable Specific USB Interrupts.
Definition: usb_lm4f.c:158
#define USB_EP1
Definition: usb.h:192
#define USB_IM_RESET
RESET signaling detected.
Definition: usb.h:205
#define USB_IM_SOF
Start of frame.
Definition: usb.h:203
#define USB_EP6
Definition: usb.h:187
#define USB_IM_SUSPEND
SUSPEND signaling detected.
Definition: usb.h:209
#define USB_EP3
Definition: usb.h:190
void usb_enable_interrupts(enum usb_interrupt ints, enum usb_ep_interrupt rx_ints, enum usb_ep_interrupt tx_ints)
Enable Specific USB Interrupts.
Definition: usb_lm4f.c:132
usb_ep_interrupt
Definition: usb.h:396
@ USB_INT_SOF
Definition: usb.h:390
@ USB_INT_RESUME
Definition: usb.h:392
@ USB_INT_SUSPEND
Definition: usb.h:393
@ USB_INT_RESET
Definition: usb.h:391
@ USB_INT_DISCON
Definition: usb.h:389
@ USB_EP4_INT
Definition: usb.h:401
@ USB_EP2_INT
Definition: usb.h:399
@ USB_EP1_INT
Definition: usb.h:398
@ USB_EP0_INT
Definition: usb.h:397
@ USB_EP7_INT
Definition: usb.h:404
@ USB_EP6_INT
Definition: usb.h:403
@ USB_EP5_INT
Definition: usb.h:402
@ USB_EP3_INT
Definition: usb.h:400