|
33 | 33 | #include "stm32f4xx_hal.h"
|
34 | 34 |
|
35 | 35 | void init_usb_hardware(void) {
|
36 |
| - GPIO_InitTypeDef GPIO_InitStruct = {0}; |
37 |
| - /**USB_OTG_FS GPIO Configuration |
38 |
| - PA10 ------> USB_OTG_FS_ID |
39 |
| - PA11 ------> USB_OTG_FS_DM |
40 |
| - PA12 ------> USB_OTG_FS_DP |
41 |
| - */ |
42 |
| - __HAL_RCC_GPIOA_CLK_ENABLE(); |
| 36 | + //TODO: if future chips overload this with options, move to peripherals management. |
43 | 37 |
|
44 |
| - /* Configure DM DP Pins */ |
45 |
| - GPIO_InitStruct.Pin = GPIO_PIN_11 | GPIO_PIN_12; |
46 |
| - GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; |
47 |
| - GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; |
48 |
| - GPIO_InitStruct.Pull = GPIO_NOPULL; |
49 |
| - GPIO_InitStruct.Alternate = GPIO_AF10_OTG_FS; |
50 |
| - HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
| 38 | + GPIO_InitTypeDef GPIO_InitStruct = {0}; |
| 39 | + /**USB_OTG_FS GPIO Configuration |
| 40 | + PA10 ------> USB_OTG_FS_ID |
| 41 | + PA11 ------> USB_OTG_FS_DM |
| 42 | + PA12 ------> USB_OTG_FS_DP |
| 43 | + */ |
| 44 | + __HAL_RCC_GPIOA_CLK_ENABLE(); |
51 | 45 |
|
52 |
| - /* Configure VBUS Pin */ |
53 |
| - GPIO_InitStruct.Pin = GPIO_PIN_9; |
54 |
| - GPIO_InitStruct.Mode = GPIO_MODE_INPUT; |
55 |
| - GPIO_InitStruct.Pull = GPIO_NOPULL; |
56 |
| - HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
| 46 | + /* Configure DM DP Pins */ |
| 47 | + GPIO_InitStruct.Pin = GPIO_PIN_11 | GPIO_PIN_12; |
| 48 | + GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; |
| 49 | + GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; |
| 50 | + GPIO_InitStruct.Pull = GPIO_NOPULL; |
| 51 | + GPIO_InitStruct.Alternate = GPIO_AF10_OTG_FS; |
| 52 | + HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
57 | 53 |
|
58 |
| - /* This for ID line debug */ |
59 |
| - GPIO_InitStruct.Pin = GPIO_PIN_10; |
60 |
| - GPIO_InitStruct.Mode = GPIO_MODE_AF_OD; |
61 |
| - GPIO_InitStruct.Pull = GPIO_PULLUP; |
62 |
| - GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; |
63 |
| - GPIO_InitStruct.Alternate = GPIO_AF10_OTG_FS; |
64 |
| - HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
| 54 | + /* Configure VBUS Pin */ |
| 55 | + GPIO_InitStruct.Pin = GPIO_PIN_9; |
| 56 | + GPIO_InitStruct.Mode = GPIO_MODE_INPUT; |
| 57 | + GPIO_InitStruct.Pull = GPIO_NOPULL; |
| 58 | + HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
65 | 59 |
|
66 |
| - /* Configure POWER_SWITCH IO pin (F412 ONLY)*/ |
67 |
| - GPIO_InitStruct.Pin = GPIO_PIN_8; |
68 |
| - GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_OD; |
69 |
| - GPIO_InitStruct.Pull = GPIO_NOPULL; |
70 |
| - HAL_GPIO_Init(GPIOG, &GPIO_InitStruct); |
| 60 | + /* This for ID line debug */ |
| 61 | + GPIO_InitStruct.Pin = GPIO_PIN_10; |
| 62 | + GPIO_InitStruct.Mode = GPIO_MODE_AF_OD; |
| 63 | + GPIO_InitStruct.Pull = GPIO_PULLUP; |
| 64 | + GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; |
| 65 | + GPIO_InitStruct.Alternate = GPIO_AF10_OTG_FS; |
| 66 | + HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
71 | 67 |
|
72 |
| - /* Peripheral clock enable */ |
73 |
| - __HAL_RCC_USB_OTG_FS_CLK_ENABLE(); |
| 68 | +#ifdef STM32F412Zx |
| 69 | + /* Configure POWER_SWITCH IO pin (F412 ONLY)*/ |
| 70 | + GPIO_InitStruct.Pin = GPIO_PIN_8; |
| 71 | + GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_OD; |
| 72 | + GPIO_InitStruct.Pull = GPIO_NOPULL; |
| 73 | + HAL_GPIO_Init(GPIOG, &GPIO_InitStruct); |
| 74 | +#endif |
| 75 | + |
| 76 | + /* Peripheral clock enable */ |
| 77 | + __HAL_RCC_USB_OTG_FS_CLK_ENABLE(); |
74 | 78 | }
|
0 commit comments