@@ -0,0 +1,47 | |||
|
1 | /*------------------------------------------------------------------------------ | |
|
2 | -- This file is a part of the libuc, microcontroler library | |
|
3 | -- Copyright (C) 2014, Alexis Jeandet | |
|
4 | -- | |
|
5 | -- This program is free software; you can redistribute it and/or modify | |
|
6 | -- it under the terms of the GNU General Public License as published by | |
|
7 | -- the Free Software Foundation; either version 3 of the License, or | |
|
8 | -- (at your option) any later version. | |
|
9 | -- | |
|
10 | -- This program is distributed in the hope that it will be useful, | |
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
|
13 | -- GNU General Public License for more details. | |
|
14 | -- | |
|
15 | -- You should have received a copy of the GNU General Public License | |
|
16 | -- along with this program; if not, write to the Free Software | |
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
|
18 | ------------------------------------------------------------------------------- | |
|
19 | -- Author : Alexis Jeandet | |
|
20 | -- Mail : alexis.jeandet@member.fsf.org | |
|
21 | -------------------------------------------------------------------------------*/ | |
|
22 | ||
|
23 | #include <uhandle.h> | |
|
24 | #define USB_LowSpeed 1 | |
|
25 | #define USB_FullSpeed 2 | |
|
26 | #define USB_HighSpeed 3 | |
|
27 | ||
|
28 | #define USB_MODE_RAW 1 | |
|
29 | #define USB_MODE_VCP 2 | |
|
30 | #define USB_MODE_HID 3 | |
|
31 | #define USB_MODE_MSC 4 | |
|
32 | #define USB_MODE_AUDIO 5 | |
|
33 | ||
|
34 | struct usbdev_str | |
|
35 | { | |
|
36 | UHANDLE phy; | |
|
37 | int (*epread) (UHANDLE phy,char *buff,uint32_t bc,char ep); | |
|
38 | int (*epwrite) (UHANDLE phy,char *buff,uint32_t bc,char ep); | |
|
39 | }; | |
|
40 | ||
|
41 | typedef volatile struct usbdev_str usbDev; | |
|
42 | ||
|
43 | extern int usbdevopen(usbDev*dev, uint32_t DATAPpin,uint32_t DATAMpin,uint32_t VBUSpin,uint32_t IDpin,int USBSpeed,int usbmode); | |
|
44 | ||
|
45 | ||
|
46 | ||
|
47 |
@@ -0,0 +1,294 | |||
|
1 | /** | |
|
2 | ****************************************************************************** | |
|
3 | * @file usb_conf.h | |
|
4 | * @author MCD Application Team | |
|
5 | * @version V1.1.0 | |
|
6 | * @date 19-March-2012 | |
|
7 | * @brief General low level driver configuration | |
|
8 | ****************************************************************************** | |
|
9 | * @attention | |
|
10 | * | |
|
11 | * <h2><center>© COPYRIGHT 2012 STMicroelectronics</center></h2> | |
|
12 | * | |
|
13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); | |
|
14 | * You may not use this file except in compliance with the License. | |
|
15 | * You may obtain a copy of the License at: | |
|
16 | * | |
|
17 | * http://www.st.com/software_license_agreement_liberty_v2 | |
|
18 | * | |
|
19 | * Unless required by applicable law or agreed to in writing, software | |
|
20 | * distributed under the License is distributed on an "AS IS" BASIS, | |
|
21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
|
22 | * See the License for the specific language governing permissions and | |
|
23 | * limitations under the License. | |
|
24 | * | |
|
25 | ****************************************************************************** | |
|
26 | */ | |
|
27 | ||
|
28 | /* Define to prevent recursive inclusion -------------------------------------*/ | |
|
29 | #ifndef __USB_CONF__H__ | |
|
30 | #define __USB_CONF__H__ | |
|
31 | ||
|
32 | /* Includes ------------------------------------------------------------------*/ | |
|
33 | #include "stm32f4xx.h" | |
|
34 | ||
|
35 | #define USE_USB_OTG_FS | |
|
36 | ||
|
37 | //#define USE_USB_OTG_HS | |
|
38 | //#define USE_ULPI_PHY | |
|
39 | ||
|
40 | /** @addtogroup USB_OTG_DRIVER | |
|
41 | * @{ | |
|
42 | */ | |
|
43 | ||
|
44 | /** @defgroup USB_CONF | |
|
45 | * @brief USB low level driver configuration file | |
|
46 | * @{ | |
|
47 | */ | |
|
48 | ||
|
49 | /** @defgroup USB_CONF_Exported_Defines | |
|
50 | * @{ | |
|
51 | */ | |
|
52 | ||
|
53 | /* USB Core and PHY interface configuration. | |
|
54 | Tip: To avoid modifying these defines each time you need to change the USB | |
|
55 | configuration, you can declare the needed define in your toolchain | |
|
56 | compiler preprocessor. | |
|
57 | */ | |
|
58 | /****************** USB OTG FS PHY CONFIGURATION ******************************* | |
|
59 | * The USB OTG FS Core supports one on-chip Full Speed PHY. | |
|
60 | * | |
|
61 | * The USE_EMBEDDED_PHY symbol is defined in the project compiler preprocessor | |
|
62 | * when FS core is used. | |
|
63 | *******************************************************************************/ | |
|
64 | #ifndef USE_USB_OTG_FS | |
|
65 | //#define USE_USB_OTG_FS | |
|
66 | #endif /* USE_USB_OTG_FS */ | |
|
67 | ||
|
68 | #ifdef USE_USB_OTG_FS | |
|
69 | #define USB_OTG_FS_CORE | |
|
70 | #endif | |
|
71 | ||
|
72 | /****************** USB OTG HS PHY CONFIGURATION ******************************* | |
|
73 | * The USB OTG HS Core supports two PHY interfaces: | |
|
74 | * (i) An ULPI interface for the external High Speed PHY: the USB HS Core will | |
|
75 | * operate in High speed mode | |
|
76 | * (ii) An on-chip Full Speed PHY: the USB HS Core will operate in Full speed mode | |
|
77 | * | |
|
78 | * You can select the PHY to be used using one of these two defines: | |
|
79 | * (i) USE_ULPI_PHY: if the USB OTG HS Core is to be used in High speed mode | |
|
80 | * (ii) USE_EMBEDDED_PHY: if the USB OTG HS Core is to be used in Full speed mode | |
|
81 | * | |
|
82 | * Notes: | |
|
83 | * - The USE_ULPI_PHY symbol is defined in the project compiler preprocessor as | |
|
84 | * default PHY when HS core is used. | |
|
85 | * - On STM322xG-EVAL and STM324xG-EVAL boards, only configuration(i) is available. | |
|
86 | * Configuration (ii) need a different hardware, for more details refer to your | |
|
87 | * STM32 device datasheet. | |
|
88 | *******************************************************************************/ | |
|
89 | #ifndef USE_USB_OTG_HS | |
|
90 | //#define USE_USB_OTG_HS | |
|
91 | #endif /* USE_USB_OTG_HS */ | |
|
92 | ||
|
93 | #ifndef USE_ULPI_PHY | |
|
94 | //#define USE_ULPI_PHY | |
|
95 | #endif /* USE_ULPI_PHY */ | |
|
96 | ||
|
97 | #ifndef USE_EMBEDDED_PHY | |
|
98 | //#define USE_EMBEDDED_PHY | |
|
99 | #endif /* USE_EMBEDDED_PHY */ | |
|
100 | ||
|
101 | #ifdef USE_USB_OTG_HS | |
|
102 | #define USB_OTG_HS_CORE | |
|
103 | #endif | |
|
104 | ||
|
105 | /******************************************************************************* | |
|
106 | * FIFO Size Configuration in Device mode | |
|
107 | * | |
|
108 | * (i) Receive data FIFO size = RAM for setup packets + | |
|
109 | * OUT endpoint control information + | |
|
110 | * data OUT packets + miscellaneous | |
|
111 | * Space = ONE 32-bits words | |
|
112 | * --> RAM for setup packets = 10 spaces | |
|
113 | * (n is the nbr of CTRL EPs the device core supports) | |
|
114 | * --> OUT EP CTRL info = 1 space | |
|
115 | * (one space for status information written to the FIFO along with each | |
|
116 | * received packet) | |
|
117 | * --> data OUT packets = (Largest Packet Size / 4) + 1 spaces | |
|
118 | * (MINIMUM to receive packets) | |
|
119 | * --> OR data OUT packets = at least 2*(Largest Packet Size / 4) + 1 spaces | |
|
120 | * (if high-bandwidth EP is enabled or multiple isochronous EPs) | |
|
121 | * --> miscellaneous = 1 space per OUT EP | |
|
122 | * (one space for transfer complete status information also pushed to the | |
|
123 | * FIFO with each endpoint's last packet) | |
|
124 | * | |
|
125 | * (ii)MINIMUM RAM space required for each IN EP Tx FIFO = MAX packet size for | |
|
126 | * that particular IN EP. More space allocated in the IN EP Tx FIFO results | |
|
127 | * in a better performance on the USB and can hide latencies on the AHB. | |
|
128 | * | |
|
129 | * (iii) TXn min size = 16 words. (n : Transmit FIFO index) | |
|
130 | * (iv) When a TxFIFO is not used, the Configuration should be as follows: | |
|
131 | * case 1 : n > m and Txn is not used (n,m : Transmit FIFO indexes) | |
|
132 | * --> Txm can use the space allocated for Txn. | |
|
133 | * case2 : n < m and Txn is not used (n,m : Transmit FIFO indexes) | |
|
134 | * --> Txn should be configured with the minimum space of 16 words | |
|
135 | * (v) The FIFO is used optimally when used TxFIFOs are allocated in the top | |
|
136 | * of the FIFO.Ex: use EP1 and EP2 as IN instead of EP1 and EP3 as IN ones. | |
|
137 | * (vi) In HS case 12 FIFO locations should be reserved for internal DMA registers | |
|
138 | * so total FIFO size should be 1012 Only instead of 1024 | |
|
139 | *******************************************************************************/ | |
|
140 | ||
|
141 | /****************** USB OTG HS CONFIGURATION **********************************/ | |
|
142 | #ifdef USB_OTG_HS_CORE | |
|
143 | #define RX_FIFO_HS_SIZE 512 | |
|
144 | #define TX0_FIFO_HS_SIZE 64 | |
|
145 | #define TX1_FIFO_HS_SIZE 372 | |
|
146 | #define TX2_FIFO_HS_SIZE 64 | |
|
147 | #define TX3_FIFO_HS_SIZE 0 | |
|
148 | #define TX4_FIFO_HS_SIZE 0 | |
|
149 | #define TX5_FIFO_HS_SIZE 0 | |
|
150 | ||
|
151 | // #define USB_OTG_HS_SOF_OUTPUT_ENABLED | |
|
152 | ||
|
153 | #ifdef USE_ULPI_PHY | |
|
154 | #define USB_OTG_ULPI_PHY_ENABLED | |
|
155 | #endif | |
|
156 | #ifdef USE_EMBEDDED_PHY | |
|
157 | #define USB_OTG_EMBEDDED_PHY_ENABLED | |
|
158 | /* wakeup is working only when HS core is configured in FS mode */ | |
|
159 | #define USB_OTG_HS_LOW_PWR_MGMT_SUPPORT | |
|
160 | #endif | |
|
161 | // #define USB_OTG_HS_INTERNAL_DMA_ENABLED | |
|
162 | /* Be aware that enabling DMA mode will result in data being sent only by | |
|
163 | multiple of 4 packet sizes. This is due to the fact that USB DMA does | |
|
164 | not allow sending data from non word-aligned addresses. | |
|
165 | For this specific application, it is advised to not enable this option | |
|
166 | unless required. */ | |
|
167 | #define USB_OTG_HS_DEDICATED_EP1_ENABLED | |
|
168 | #endif | |
|
169 | ||
|
170 | /****************** USB OTG FS CONFIGURATION **********************************/ | |
|
171 | #ifdef USB_OTG_FS_CORE | |
|
172 | #define RX_FIFO_FS_SIZE 128 | |
|
173 | #define TX0_FIFO_FS_SIZE 32 | |
|
174 | #define TX1_FIFO_FS_SIZE 128 | |
|
175 | #define TX2_FIFO_FS_SIZE 32 | |
|
176 | #define TX3_FIFO_FS_SIZE 0 | |
|
177 | ||
|
178 | // #define USB_OTG_FS_LOW_PWR_MGMT_SUPPORT | |
|
179 | // #define USB_OTG_FS_SOF_OUTPUT_ENABLED | |
|
180 | #endif | |
|
181 | ||
|
182 | /****************** USB OTG MISC CONFIGURATION ********************************/ | |
|
183 | #define VBUS_SENSING_ENABLED | |
|
184 | ||
|
185 | /****************** USB OTG MODE CONFIGURATION ********************************/ | |
|
186 | //#define USE_HOST_MODE | |
|
187 | #define USE_DEVICE_MODE | |
|
188 | //#define USE_OTG_MODE | |
|
189 | ||
|
190 | #ifndef USB_OTG_FS_CORE | |
|
191 | #ifndef USB_OTG_HS_CORE | |
|
192 | #error "USB_OTG_HS_CORE or USB_OTG_FS_CORE should be defined" | |
|
193 | #endif | |
|
194 | #endif | |
|
195 | ||
|
196 | #ifndef USE_DEVICE_MODE | |
|
197 | #ifndef USE_HOST_MODE | |
|
198 | #error "USE_DEVICE_MODE or USE_HOST_MODE should be defined" | |
|
199 | #endif | |
|
200 | #endif | |
|
201 | ||
|
202 | #ifndef USE_USB_OTG_HS | |
|
203 | #ifndef USE_USB_OTG_FS | |
|
204 | #error "USE_USB_OTG_HS or USE_USB_OTG_FS should be defined" | |
|
205 | #endif | |
|
206 | #else //USE_USB_OTG_HS | |
|
207 | #ifndef USE_ULPI_PHY | |
|
208 | #ifndef USE_EMBEDDED_PHY | |
|
209 | #error "USE_ULPI_PHY or USE_EMBEDDED_PHY should be defined" | |
|
210 | #endif | |
|
211 | #endif | |
|
212 | #endif | |
|
213 | ||
|
214 | /****************** C Compilers dependant keywords ****************************/ | |
|
215 | /* In HS mode and when the DMA is used, all variables and data structures dealing | |
|
216 | with the DMA during the transaction process should be 4-bytes aligned */ | |
|
217 | #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED | |
|
218 | #if defined (__GNUC__) /* GNU Compiler */ | |
|
219 | #define __ALIGN_END __attribute__ ((aligned (4))) __attribute__((section(".ahbram_data"))) | |
|
220 | #define __ALIGN_BEGIN | |
|
221 | #else | |
|
222 | #define __ALIGN_END | |
|
223 | #if defined (__CC_ARM) /* ARM Compiler */ | |
|
224 | #define __ALIGN_BEGIN __align(4) | |
|
225 | #elif defined (__ICCARM__) /* IAR Compiler */ | |
|
226 | #define __ALIGN_BEGIN | |
|
227 | #elif defined (__TASKING__) /* TASKING Compiler */ | |
|
228 | #define __ALIGN_BEGIN __align(4) | |
|
229 | #endif /* __CC_ARM */ | |
|
230 | #endif /* __GNUC__ */ | |
|
231 | #else | |
|
232 | #define __ALIGN_BEGIN | |
|
233 | #define __ALIGN_END __attribute__((section(".ahbram_data"))) | |
|
234 | #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */ | |
|
235 | ||
|
236 | /* __packed keyword used to decrease the data type alignment to 1-byte */ | |
|
237 | #if defined (__CC_ARM) /* ARM Compiler */ | |
|
238 | #define __packed __packed | |
|
239 | #elif defined (__ICCARM__) /* IAR Compiler */ | |
|
240 | #define __packed __packed | |
|
241 | #elif defined ( __GNUC__ ) /* GNU Compiler */ | |
|
242 | #define __packed __attribute__ ((__packed__)) | |
|
243 | #elif defined (__TASKING__) /* TASKING Compiler */ | |
|
244 | #define __packed __unaligned | |
|
245 | #endif /* __CC_ARM */ | |
|
246 | ||
|
247 | /** | |
|
248 | * @} | |
|
249 | */ | |
|
250 | ||
|
251 | ||
|
252 | /** @defgroup USB_CONF_Exported_Types | |
|
253 | * @{ | |
|
254 | */ | |
|
255 | /** | |
|
256 | * @} | |
|
257 | */ | |
|
258 | ||
|
259 | ||
|
260 | /** @defgroup USB_CONF_Exported_Macros | |
|
261 | * @{ | |
|
262 | */ | |
|
263 | /** | |
|
264 | * @} | |
|
265 | */ | |
|
266 | ||
|
267 | /** @defgroup USB_CONF_Exported_Variables | |
|
268 | * @{ | |
|
269 | */ | |
|
270 | /** | |
|
271 | * @} | |
|
272 | */ | |
|
273 | ||
|
274 | /** @defgroup USB_CONF_Exported_FunctionsPrototype | |
|
275 | * @{ | |
|
276 | */ | |
|
277 | /** | |
|
278 | * @} | |
|
279 | */ | |
|
280 | ||
|
281 | ||
|
282 | #endif //__USB_CONF__H__ | |
|
283 | ||
|
284 | ||
|
285 | /** | |
|
286 | * @} | |
|
287 | */ | |
|
288 | ||
|
289 | /** | |
|
290 | * @} | |
|
291 | */ | |
|
292 | ||
|
293 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ | |
|
294 |
@@ -0,0 +1,11 | |||
|
1 | TEMPLATE = lib | |
|
2 | CONFIG += libuc2lib | |
|
3 | ||
|
4 | SOURCES += \ | |
|
5 | usbdev.c | |
|
6 | ||
|
7 | UCMODEL=stm32f4 | |
|
8 | ||
|
9 | HEADERS += \ | |
|
10 | ../../../include/USB/usbdev.h | |
|
11 |
@@ -0,0 +1,64 | |||
|
1 | /*------------------------------------------------------------------------------ | |
|
2 | -- This file is a part of the libuc, microcontroler library | |
|
3 | -- Copyright (C) 2014, Alexis Jeandet | |
|
4 | -- | |
|
5 | -- This program is free software; you can redistribute it and/or modify | |
|
6 | -- it under the terms of the GNU General Public License as published by | |
|
7 | -- the Free Software Foundation; either version 3 of the License, or | |
|
8 | -- (at your option) any later version. | |
|
9 | -- | |
|
10 | -- This program is distributed in the hope that it will be useful, | |
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
|
13 | -- GNU General Public License for more details. | |
|
14 | -- | |
|
15 | -- You should have received a copy of the GNU General Public License | |
|
16 | -- along with this program; if not, write to the Free Software | |
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
|
18 | ------------------------------------------------------------------------------- | |
|
19 | -- Author : Alexis Jeandet | |
|
20 | -- Mail : alexis.jeandet@member.fsf.org | |
|
21 | -------------------------------------------------------------------------------*/ | |
|
22 | ||
|
23 | #include <usbdev.h> | |
|
24 | #include <gpio.h> | |
|
25 | #include <stm32f4xx_gpio.h> | |
|
26 | #include <core.h> | |
|
27 | #include <stm32f4xx_rcc.h> | |
|
28 | //#include <usb_core.h> | |
|
29 | ||
|
30 | int usbfsopen(uint32_t DATAPpin,uint32_t DATAMpin,uint32_t VBUSpin,uint32_t IDpin) | |
|
31 | { | |
|
32 | ||
|
33 | RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE); | |
|
34 | gpio_t DP,DM,VBUS,ID; | |
|
35 | DP = gpioopen(DATAPpin); | |
|
36 | DM = gpioopen(DATAMpin); | |
|
37 | VBUS = gpioopen(VBUSpin); | |
|
38 | ID = gpioopen(IDpin); | |
|
39 | DP |= gpiohighspeed | gpioaf | gpiopushpulltype | gpionopulltype; | |
|
40 | DM |= gpiohighspeed | gpioaf | gpiopushpulltype | gpionopulltype; | |
|
41 | VBUS |= gpiohighspeed | gpioindir | gpioopendraintype | gpionopulltype; | |
|
42 | ID |= gpiohighspeed | gpioaf | gpiopushpulltype | gpionopulltype; | |
|
43 | gpiosetconfig(&DP); | |
|
44 | gpiosetconfig(&DM); | |
|
45 | gpiosetconfig(&ID); | |
|
46 | gpiosetconfig(&VBUS); | |
|
47 | ||
|
48 | GPIO_PinAFConfig(GPIOGETPORT(DP), (uint8_t)(DP & 0xF), GPIO_AF_OTG1_FS); | |
|
49 | GPIO_PinAFConfig(GPIOGETPORT(DM), (uint8_t)(DM & 0xF), GPIO_AF_OTG1_FS); | |
|
50 | GPIO_PinAFConfig(GPIOGETPORT(ID), (uint8_t)(ID & 0xF), GPIO_AF_OTG1_FS); | |
|
51 | ||
|
52 | RCC_AHB2PeriphClockCmd(RCC_AHB2Periph_OTG_FS, ENABLE) ; | |
|
53 | ||
|
54 | return 0; | |
|
55 | } | |
|
56 | ||
|
57 | int usbdevopen(usbDev*dev, uint32_t DATAPpin,uint32_t DATAMpin,uint32_t VBUSpin,uint32_t IDpin,int USBSpeed,int usbmode) | |
|
58 | { | |
|
59 | if(USBSpeed==USB_FullSpeed) | |
|
60 | { | |
|
61 | return usbfsopen(PA12,PA11,PA9,PA10); //fixed pins on STM32F4 | |
|
62 | } | |
|
63 | return -1; | |
|
64 | } |
@@ -1,24 +1,28 | |||
|
1 | 1 | # use glob syntax. |
|
2 | 2 | syntax: glob |
|
3 | 3 | |
|
4 | 4 | *.*~ |
|
5 | 5 | *~ |
|
6 | 6 | *.o |
|
7 | 7 | *.a |
|
8 | 8 | *.hex |
|
9 | 9 | *.bin |
|
10 | 10 | *.d |
|
11 | 11 | *.dump |
|
12 | 12 | *.map |
|
13 | 13 | *.user |
|
14 | 14 | *.user.* |
|
15 | 15 | *.orig |
|
16 | 16 | Makefile.* |
|
17 | 17 | *.Makefile.* |
|
18 | 18 | *.aux |
|
19 | 19 | *.ps |
|
20 | 20 | *.out |
|
21 | 21 | *.prl |
|
22 | 22 | *.dfu |
|
23 | 23 | mkspecs/default/qmake.conf |
|
24 | 24 | mkspecs/default/qplatformdefs.h |
|
25 | Makefile | |
|
26 | doc/doxygen/html/* | |
|
27 | doc/doxygen/latex/* | |
|
28 | *.qch |
General Comments 0
You need to be logged in to leave comments.
Login now