Merge pull request #93 from zyp/master
[fw/stlink] / example / stm32f4 / Projects / discovery_demo / usb_conf.h
1 /**
2   ******************************************************************************
3   * @file    usb_conf.h
4   * @author  MCD Application Team
5   * @version V1.0.0
6   * @date    19-September-2011
7   * @brief   General low level driver configuration
8   ******************************************************************************
9   * @attention
10   *
11   * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
12   * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
13   * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
14   * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
15   * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
16   * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
17   *
18   * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2>
19   ******************************************************************************
20   */
21
22 /* Define to prevent recursive inclusion -------------------------------------*/
23 #ifndef __USB_CONF__H__
24 #define __USB_CONF__H__
25
26 /* Includes ------------------------------------------------------------------*/
27 #include "stm32f4xx.h"
28
29
30 /** @addtogroup USB_OTG_DRIVER
31   * @{
32   */
33   
34 /** @defgroup USB_CONF
35   * @brief USB low level driver configuration file
36   * @{
37   */ 
38
39 /** @defgroup USB_CONF_Exported_Defines
40   * @{
41   */ 
42
43 /* USB Core and PHY interface configuration.
44    Tip: To avoid modifying these defines each time you need to change the USB
45         configuration, you can declare the needed define in your toolchain
46         compiler preprocessor.
47    */
48 #ifndef USE_USB_OTG_FS
49  //#define USE_USB_OTG_FS
50 #endif /* USE_USB_OTG_FS */
51
52 #ifdef USE_USB_OTG_FS 
53  #define USB_OTG_FS_CORE
54 #endif
55
56 /*******************************************************************************
57 *                      FIFO Size Configuration in Device mode
58 *  
59 *  (i) Receive data FIFO size = RAM for setup packets + 
60 *                   OUT endpoint control information +
61 *                   data OUT packets + miscellaneous
62 *      Space = ONE 32-bits words
63 *     --> RAM for setup packets = 10 spaces
64 *        (n is the nbr of CTRL EPs the device core supports) 
65 *     --> OUT EP CTRL info      = 1 space
66 *        (one space for status information written to the FIFO along with each 
67 *        received packet)
68 *     --> data OUT packets      = (Largest Packet Size / 4) + 1 spaces 
69 *        (MINIMUM to receive packets)
70 *     --> OR data OUT packets  = at least 2*(Largest Packet Size / 4) + 1 spaces 
71 *        (if high-bandwidth EP is enabled or multiple isochronous EPs)
72 *     --> miscellaneous = 1 space per OUT EP
73 *        (one space for transfer complete status information also pushed to the 
74 *        FIFO with each endpoint's last packet)
75 *
76 *  (ii)MINIMUM RAM space required for each IN EP Tx FIFO = MAX packet size for 
77 *       that particular IN EP. More space allocated in the IN EP Tx FIFO results
78 *       in a better performance on the USB and can hide latencies on the AHB.
79 *
80 *  (iii) TXn min size = 16 words. (n  : Transmit FIFO index)
81 *   (iv) When a TxFIFO is not used, the Configuration should be as follows: 
82 *       case 1 :  n > m    and Txn is not used    (n,m  : Transmit FIFO indexes)
83 *       --> Txm can use the space allocated for Txn.
84 *       case2  :  n < m    and Txn is not used    (n,m  : Transmit FIFO indexes)
85 *       --> Txn should be configured with the minimum space of 16 words
86 *  (v) The FIFO is used optimally when used TxFIFOs are allocated in the top 
87 *       of the FIFO.Ex: use EP1 and EP2 as IN instead of EP1 and EP3 as IN ones.
88 *******************************************************************************/
89  
90
91
92 /****************** USB OTG FS CONFIGURATION **********************************/
93 #ifdef USB_OTG_FS_CORE
94  #define RX_FIFO_FS_SIZE                          128
95  #define TX0_FIFO_FS_SIZE                          64
96  #define TX1_FIFO_FS_SIZE                         128
97  #define TX2_FIFO_FS_SIZE                          0
98  #define TX3_FIFO_FS_SIZE                          0
99
100  //#define USB_OTG_FS_LOW_PWR_MGMT_SUPPORT
101  //#define USB_OTG_FS_SOF_OUTPUT_ENABLED
102 #endif
103
104 /****************** USB OTG MODE CONFIGURATION ********************************/
105
106 //#define USE_HOST_MODE
107 #define USE_DEVICE_MODE
108 //#define USE_OTG_MODE
109
110
111 #ifndef USB_OTG_FS_CORE
112  #ifndef USB_OTG_HS_CORE
113     #error  "USB_OTG_HS_CORE or USB_OTG_FS_CORE should be defined"
114  #endif
115 #endif
116
117
118 #ifndef USE_DEVICE_MODE
119  #ifndef USE_HOST_MODE
120     #error  "USE_DEVICE_MODE or USE_HOST_MODE should be defined"
121  #endif
122 #endif
123
124 #ifndef USE_USB_OTG_HS
125  #ifndef USE_USB_OTG_FS
126     #error  "USE_USB_OTG_HS or USE_USB_OTG_FS should be defined"
127  #endif
128 #else //USE_USB_OTG_HS
129  #ifndef USE_ULPI_PHY
130   #ifndef USE_EMBEDDED_PHY
131    #ifndef USE_I2C_PHY
132      #error  "USE_ULPI_PHY or USE_EMBEDDED_PHY or USE_I2C_PHY should be defined"
133    #endif
134   #endif
135  #endif
136 #endif
137
138 /****************** C Compilers dependant keywords ****************************/
139 /* In HS mode and when the DMA is used, all variables and data structures dealing
140    with the DMA during the transaction process should be 4-bytes aligned */    
141 #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
142   #if defined   (__GNUC__)        /* GNU Compiler */
143     #define __ALIGN_END    __attribute__ ((aligned (4)))
144     #define __ALIGN_BEGIN         
145   #else                           
146     #define __ALIGN_END
147     #if defined   (__CC_ARM)      /* ARM Compiler */
148       #define __ALIGN_BEGIN    __align(4)  
149     #elif defined (__ICCARM__)    /* IAR Compiler */
150       #define __ALIGN_BEGIN 
151     #elif defined  (__TASKING__)  /* TASKING Compiler */
152       #define __ALIGN_BEGIN    __align(4) 
153     #endif /* __CC_ARM */  
154   #endif /* __GNUC__ */ 
155 #else
156   #define __ALIGN_BEGIN
157   #define __ALIGN_END   
158 #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
159
160 /* __packed keyword used to decrease the data type alignment to 1-byte */
161 #if defined (__CC_ARM)         /* ARM Compiler */
162   #define __packed    __packed
163 #elif defined (__ICCARM__)     /* IAR Compiler */
164   #define __packed    __packed
165 #elif defined   ( __GNUC__ )   /* GNU Compiler */                        
166   #define __packed    __attribute__ ((__packed__))
167 #elif defined   (__TASKING__)  /* TASKING Compiler */
168   #define __packed    __unaligned
169 #endif /* __CC_ARM */
170
171 /****************** C Compilers dependant keywords ****************************/
172 /* In HS mode and when the DMA is used, all variables and data structures dealing
173    with the DMA during the transaction process should be 4-bytes aligned */    
174 #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
175   #if defined   (__GNUC__)        /* GNU Compiler */
176     #define __ALIGN_END    __attribute__ ((aligned (4)))
177     #define __ALIGN_BEGIN         
178   #else                           
179     #define __ALIGN_END
180     #if defined   (__CC_ARM)      /* ARM Compiler */
181       #define __ALIGN_BEGIN    __align(4)  
182     #elif defined (__ICCARM__)    /* IAR Compiler */
183       #define __ALIGN_BEGIN 
184     #elif defined  (__TASKING__)  /* TASKING Compiler */
185       #define __ALIGN_BEGIN    __align(4) 
186     #endif /* __CC_ARM */  
187   #endif /* __GNUC__ */ 
188 #else
189   #define __ALIGN_BEGIN
190   #define __ALIGN_END   
191 #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
192
193 /* __packed keyword used to decrease the data type alignment to 1-byte */
194 #if defined (__CC_ARM)         /* ARM Compiler */
195   #define __packed    __packed
196 #elif defined (__ICCARM__)     /* IAR Compiler */
197   #define __packed    __packed
198 #elif defined   ( __GNUC__ )   /* GNU Compiler */                        
199   #define __packed    __attribute__ ((__packed__))
200 #elif defined   (__TASKING__)  /* TASKING Compiler */
201   #define __packed    __unaligned
202 #endif /* __CC_ARM */
203
204
205 /**
206   * @}
207   */ 
208
209
210 /** @defgroup USB_CONF_Exported_Types
211   * @{
212   */ 
213 /**
214   * @}
215   */ 
216
217
218 /** @defgroup USB_CONF_Exported_Macros
219   * @{
220   */ 
221 /**
222   * @}
223   */ 
224
225 /** @defgroup USB_CONF_Exported_Variables
226   * @{
227   */ 
228 /**
229   * @}
230   */ 
231
232 /** @defgroup USB_CONF_Exported_FunctionsPrototype
233   * @{
234   */ 
235 /**
236   * @}
237   */ 
238
239
240 #endif //__USB_CONF__H__
241
242
243 /**
244   * @}
245   */ 
246
247 /**
248   * @}
249   */ 
250
251 /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
252