Added TARGET_DISCO_F469NI in USBHOST\USBHost\TARGET_STM\USBHALHost_STM_TARGET.h
Dependents: DISCO-F469NI_USB_Disk STM32F4xx_USB_Memory
Fork of USBHOST by
targets/TARGET_STM/USBHALHost_STM.h@8:3e7a33f81048, 2020-01-04 (annotated)
- Committer:
- kenjiArai
- Date:
- Sat Jan 04 23:30:59 2020 +0000
- Revision:
- 8:3e7a33f81048
updated for STM32F4xx
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kenjiArai | 8:3e7a33f81048 | 1 | /* Copyright (c) 2017 mbed.org, MIT License |
kenjiArai | 8:3e7a33f81048 | 2 | * |
kenjiArai | 8:3e7a33f81048 | 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
kenjiArai | 8:3e7a33f81048 | 4 | * and associated documentation files (the "Software"), to deal in the Software without |
kenjiArai | 8:3e7a33f81048 | 5 | * restriction, including without limitation the rights to use, copy, modify, merge, publish, |
kenjiArai | 8:3e7a33f81048 | 6 | * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the |
kenjiArai | 8:3e7a33f81048 | 7 | * Software is furnished to do so, subject to the following conditions: |
kenjiArai | 8:3e7a33f81048 | 8 | * |
kenjiArai | 8:3e7a33f81048 | 9 | * The above copyright notice and this permission notice shall be included in all copies or |
kenjiArai | 8:3e7a33f81048 | 10 | * substantial portions of the Software. |
kenjiArai | 8:3e7a33f81048 | 11 | * |
kenjiArai | 8:3e7a33f81048 | 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
kenjiArai | 8:3e7a33f81048 | 13 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
kenjiArai | 8:3e7a33f81048 | 14 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
kenjiArai | 8:3e7a33f81048 | 15 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
kenjiArai | 8:3e7a33f81048 | 16 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
kenjiArai | 8:3e7a33f81048 | 17 | */ |
kenjiArai | 8:3e7a33f81048 | 18 | #ifndef USBHALHOST_STM_H |
kenjiArai | 8:3e7a33f81048 | 19 | #define USBHALHOST_STM_H |
kenjiArai | 8:3e7a33f81048 | 20 | |
kenjiArai | 8:3e7a33f81048 | 21 | #if defined(TARGET_DISCO_F746NG) |
kenjiArai | 8:3e7a33f81048 | 22 | #if (MBED_CONF_TARGET_USB_SPEED == 1) // Defined in json configuration file |
kenjiArai | 8:3e7a33f81048 | 23 | #define TARGET_DISCO_F746NG_HS |
kenjiArai | 8:3e7a33f81048 | 24 | #else |
kenjiArai | 8:3e7a33f81048 | 25 | #define TARGET_DISCO_F746NG_FS |
kenjiArai | 8:3e7a33f81048 | 26 | #endif |
kenjiArai | 8:3e7a33f81048 | 27 | #endif |
kenjiArai | 8:3e7a33f81048 | 28 | |
kenjiArai | 8:3e7a33f81048 | 29 | #if defined(TARGET_DISCO_F746NG_HS) || defined(TARGET_DISCO_F769NI) |
kenjiArai | 8:3e7a33f81048 | 30 | #define USBHAL_IRQn OTG_HS_IRQn |
kenjiArai | 8:3e7a33f81048 | 31 | #else |
kenjiArai | 8:3e7a33f81048 | 32 | #define USBHAL_IRQn OTG_FS_IRQn |
kenjiArai | 8:3e7a33f81048 | 33 | #endif |
kenjiArai | 8:3e7a33f81048 | 34 | |
kenjiArai | 8:3e7a33f81048 | 35 | #define HCCA_SIZE sizeof(HCD_HandleTypeDef) |
kenjiArai | 8:3e7a33f81048 | 36 | #define ED_SIZE sizeof(HCED) |
kenjiArai | 8:3e7a33f81048 | 37 | #define TD_SIZE sizeof(HCTD) |
kenjiArai | 8:3e7a33f81048 | 38 | |
kenjiArai | 8:3e7a33f81048 | 39 | #define TOTAL_SIZE (HCCA_SIZE + (MAX_ENDPOINT * ED_SIZE) + (MAX_TD * TD_SIZE)) |
kenjiArai | 8:3e7a33f81048 | 40 | |
kenjiArai | 8:3e7a33f81048 | 41 | /* STM device FS have 11 channels (definition is for 60 channels) */ |
kenjiArai | 8:3e7a33f81048 | 42 | static volatile uint8_t usb_buf[TOTAL_SIZE]; |
kenjiArai | 8:3e7a33f81048 | 43 | |
kenjiArai | 8:3e7a33f81048 | 44 | typedef struct { |
kenjiArai | 8:3e7a33f81048 | 45 | /* store the request ongoing on each endpoit */ |
kenjiArai | 8:3e7a33f81048 | 46 | /* 1st field of structure avoid giving knowledge of all structure to |
kenjiArai | 8:3e7a33f81048 | 47 | * endpoint */ |
kenjiArai | 8:3e7a33f81048 | 48 | volatile uint32_t addr[MAX_ENDPOINT]; |
kenjiArai | 8:3e7a33f81048 | 49 | USBHALHost *inst; |
kenjiArai | 8:3e7a33f81048 | 50 | void (USBHALHost::*deviceConnected)(int hub, int port, bool lowSpeed, USBHostHub *hub_parent); |
kenjiArai | 8:3e7a33f81048 | 51 | void (USBHALHost::*deviceDisconnected)(int hub, int port, USBHostHub *hub_parent, volatile uint32_t addr); |
kenjiArai | 8:3e7a33f81048 | 52 | void (USBHALHost::*transferCompleted)(volatile uint32_t addr); |
kenjiArai | 8:3e7a33f81048 | 53 | } USBHALHost_Private_t; |
kenjiArai | 8:3e7a33f81048 | 54 | |
kenjiArai | 8:3e7a33f81048 | 55 | static gpio_t gpio_powerpin; |
kenjiArai | 8:3e7a33f81048 | 56 | |
kenjiArai | 8:3e7a33f81048 | 57 | // NUCLEO_64 boards |
kenjiArai | 8:3e7a33f81048 | 58 | #if defined(TARGET_NUCLEO_F401RE) || \ |
kenjiArai | 8:3e7a33f81048 | 59 | defined(TARGET_NUCLEO_F411RE) || \ |
kenjiArai | 8:3e7a33f81048 | 60 | defined(TARGET_NUCLEO_F446RE) || \ |
kenjiArai | 8:3e7a33f81048 | 61 | defined(TARGET_NUCLEO_L476RG) || \ |
kenjiArai | 8:3e7a33f81048 | 62 | defined(TARGET_NUCLEO_L486RG) |
kenjiArai | 8:3e7a33f81048 | 63 | #define USB_POWER_ON 0 |
kenjiArai | 8:3e7a33f81048 | 64 | #define USB_POWER_OFF 1 |
kenjiArai | 8:3e7a33f81048 | 65 | #define USB_POWERPIN_CONFIG {__HAL_RCC_GPIOC_CLK_ENABLE();gpio_init_out_ex(&gpio_powerpin, PC_0, USB_POWER_OFF);} |
kenjiArai | 8:3e7a33f81048 | 66 | |
kenjiArai | 8:3e7a33f81048 | 67 | // NUCLEO_144 boards |
kenjiArai | 8:3e7a33f81048 | 68 | #elif defined(TARGET_NUCLEO_F207ZG) || \ |
kenjiArai | 8:3e7a33f81048 | 69 | defined(TARGET_NUCLEO_F412ZG) || \ |
kenjiArai | 8:3e7a33f81048 | 70 | defined(TARGET_NUCLEO_F413ZH) || \ |
kenjiArai | 8:3e7a33f81048 | 71 | defined(TARGET_NUCLEO_F429ZI) || \ |
kenjiArai | 8:3e7a33f81048 | 72 | defined(TARGET_NUCLEO_F439ZI) || \ |
kenjiArai | 8:3e7a33f81048 | 73 | defined(TARGET_NUCLEO_F446ZE) || \ |
kenjiArai | 8:3e7a33f81048 | 74 | defined(TARGET_NUCLEO_F767ZI) || \ |
kenjiArai | 8:3e7a33f81048 | 75 | defined(TARGET_NUCLEO_F746ZG) || \ |
kenjiArai | 8:3e7a33f81048 | 76 | defined(TARGET_NUCLEO_F756ZG) || \ |
kenjiArai | 8:3e7a33f81048 | 77 | defined(TARGET_NUCLEO_F767ZI) |
kenjiArai | 8:3e7a33f81048 | 78 | #define USB_POWER_ON 1 |
kenjiArai | 8:3e7a33f81048 | 79 | #define USB_POWER_OFF 0 |
kenjiArai | 8:3e7a33f81048 | 80 | #define USB_POWERPIN_CONFIG {__HAL_RCC_GPIOG_CLK_ENABLE();gpio_init_out_ex(&gpio_powerpin, PG_6, USB_POWER_OFF);} |
kenjiArai | 8:3e7a33f81048 | 81 | |
kenjiArai | 8:3e7a33f81048 | 82 | // DISCOVERY boards |
kenjiArai | 8:3e7a33f81048 | 83 | #elif defined(TARGET_DISCO_F413ZH) |
kenjiArai | 8:3e7a33f81048 | 84 | #define USB_POWER_ON 0 |
kenjiArai | 8:3e7a33f81048 | 85 | #define USB_POWER_OFF 1 |
kenjiArai | 8:3e7a33f81048 | 86 | #define USB_POWERPIN_CONFIG {__HAL_RCC_GPIOG_CLK_ENABLE();gpio_init_out_ex(&gpio_powerpin, PG_8, USB_POWER_OFF);} |
kenjiArai | 8:3e7a33f81048 | 87 | |
kenjiArai | 8:3e7a33f81048 | 88 | #elif defined(TARGET_DISCO_F469NI) |
kenjiArai | 8:3e7a33f81048 | 89 | #define USB_POWER_ON 1 |
kenjiArai | 8:3e7a33f81048 | 90 | #define USB_POWER_OFF 0 |
kenjiArai | 8:3e7a33f81048 | 91 | #define USB_POWERPIN_CONFIG {__HAL_RCC_GPIOB_CLK_ENABLE();gpio_init_out_ex(&gpio_powerpin, PB_2, USB_POWER_OFF);} |
kenjiArai | 8:3e7a33f81048 | 92 | |
kenjiArai | 8:3e7a33f81048 | 93 | #elif defined(TARGET_DISCO_F746NG_FS) |
kenjiArai | 8:3e7a33f81048 | 94 | #define USB_POWER_ON 0 |
kenjiArai | 8:3e7a33f81048 | 95 | #define USB_POWER_OFF 1 |
kenjiArai | 8:3e7a33f81048 | 96 | #define USB_POWERPIN_CONFIG {__HAL_RCC_GPIOD_CLK_ENABLE();gpio_init_out_ex(&gpio_powerpin, PD_5, USB_POWER_OFF);} |
kenjiArai | 8:3e7a33f81048 | 97 | |
kenjiArai | 8:3e7a33f81048 | 98 | #elif defined(TARGET_DISCO_F746NG_HS) |
kenjiArai | 8:3e7a33f81048 | 99 | #define USB_POWER_ON 0 |
kenjiArai | 8:3e7a33f81048 | 100 | #define USB_POWER_OFF 1 |
kenjiArai | 8:3e7a33f81048 | 101 | #define USB_POWERPIN_CONFIG {} |
kenjiArai | 8:3e7a33f81048 | 102 | |
kenjiArai | 8:3e7a33f81048 | 103 | #elif defined(TARGET_DISCO_F769NI) |
kenjiArai | 8:3e7a33f81048 | 104 | #define USB_POWER_ON 0 |
kenjiArai | 8:3e7a33f81048 | 105 | #define USB_POWER_OFF 1 |
kenjiArai | 8:3e7a33f81048 | 106 | #define USB_POWERPIN_CONFIG {} |
kenjiArai | 8:3e7a33f81048 | 107 | |
kenjiArai | 8:3e7a33f81048 | 108 | #elif defined(TARGET_DISCO_L475VG_IOT01A) |
kenjiArai | 8:3e7a33f81048 | 109 | #define USB_POWER_ON 0 |
kenjiArai | 8:3e7a33f81048 | 110 | #define USB_POWER_OFF 1 |
kenjiArai | 8:3e7a33f81048 | 111 | #define USB_POWERPIN_CONFIG {__HAL_RCC_GPIOD_CLK_ENABLE();gpio_init_out_ex(&gpio_powerpin, PD_12, USB_POWER_OFF);} |
kenjiArai | 8:3e7a33f81048 | 112 | |
kenjiArai | 8:3e7a33f81048 | 113 | #elif defined(TARGET_DISCO_L476VG) |
kenjiArai | 8:3e7a33f81048 | 114 | #define USB_POWER_ON 0 |
kenjiArai | 8:3e7a33f81048 | 115 | #define USB_POWER_OFF 1 |
kenjiArai | 8:3e7a33f81048 | 116 | #define USB_POWERPIN_CONFIG {__HAL_RCC_GPIOC_CLK_ENABLE();gpio_init_out_ex(&gpio_powerpin, PC_9, USB_POWER_OFF);} |
kenjiArai | 8:3e7a33f81048 | 117 | |
kenjiArai | 8:3e7a33f81048 | 118 | #else |
kenjiArai | 8:3e7a33f81048 | 119 | #error "USB power pin is not configured !" |
kenjiArai | 8:3e7a33f81048 | 120 | #endif |
kenjiArai | 8:3e7a33f81048 | 121 | |
kenjiArai | 8:3e7a33f81048 | 122 | |
kenjiArai | 8:3e7a33f81048 | 123 | void usb_vbus(uint8_t state) |
kenjiArai | 8:3e7a33f81048 | 124 | { |
kenjiArai | 8:3e7a33f81048 | 125 | if (gpio_powerpin.reg_set && gpio_powerpin.reg_clr) { |
kenjiArai | 8:3e7a33f81048 | 126 | if (state == 0) { |
kenjiArai | 8:3e7a33f81048 | 127 | gpio_write(&gpio_powerpin, USB_POWER_OFF); |
kenjiArai | 8:3e7a33f81048 | 128 | } else { |
kenjiArai | 8:3e7a33f81048 | 129 | gpio_write(&gpio_powerpin, USB_POWER_ON); |
kenjiArai | 8:3e7a33f81048 | 130 | } |
kenjiArai | 8:3e7a33f81048 | 131 | } else { |
kenjiArai | 8:3e7a33f81048 | 132 | /* The board does not have GPIO pin to control usb supply */ |
kenjiArai | 8:3e7a33f81048 | 133 | } |
kenjiArai | 8:3e7a33f81048 | 134 | wait(0.2); |
kenjiArai | 8:3e7a33f81048 | 135 | } |
kenjiArai | 8:3e7a33f81048 | 136 | |
kenjiArai | 8:3e7a33f81048 | 137 | |
kenjiArai | 8:3e7a33f81048 | 138 | USBHALHost::USBHALHost() |
kenjiArai | 8:3e7a33f81048 | 139 | { |
kenjiArai | 8:3e7a33f81048 | 140 | instHost = this; |
kenjiArai | 8:3e7a33f81048 | 141 | HCD_HandleTypeDef *hhcd = {0}; |
kenjiArai | 8:3e7a33f81048 | 142 | USBHALHost_Private_t *HALPriv = new (USBHALHost_Private_t); |
kenjiArai | 8:3e7a33f81048 | 143 | |
kenjiArai | 8:3e7a33f81048 | 144 | memset(HALPriv, 0, sizeof(USBHALHost_Private_t)); |
kenjiArai | 8:3e7a33f81048 | 145 | memInit(); |
kenjiArai | 8:3e7a33f81048 | 146 | memset((void *)usb_hcca, 0, HCCA_SIZE); |
kenjiArai | 8:3e7a33f81048 | 147 | |
kenjiArai | 8:3e7a33f81048 | 148 | hhcd = (HCD_HandleTypeDef *)usb_hcca; |
kenjiArai | 8:3e7a33f81048 | 149 | hhcd->pData = (void *)HALPriv; |
kenjiArai | 8:3e7a33f81048 | 150 | |
kenjiArai | 8:3e7a33f81048 | 151 | #if defined(TARGET_DISCO_F746NG_HS) || defined(TARGET_DISCO_F769NI) |
kenjiArai | 8:3e7a33f81048 | 152 | hhcd->Instance = USB_OTG_HS; |
kenjiArai | 8:3e7a33f81048 | 153 | hhcd->Init.speed = HCD_SPEED_HIGH; |
kenjiArai | 8:3e7a33f81048 | 154 | hhcd->Init.phy_itface = HCD_PHY_ULPI; |
kenjiArai | 8:3e7a33f81048 | 155 | #else |
kenjiArai | 8:3e7a33f81048 | 156 | hhcd->Instance = USB_OTG_FS; |
kenjiArai | 8:3e7a33f81048 | 157 | hhcd->Init.speed = HCD_SPEED_FULL; |
kenjiArai | 8:3e7a33f81048 | 158 | hhcd->Init.phy_itface = HCD_PHY_EMBEDDED; |
kenjiArai | 8:3e7a33f81048 | 159 | #endif |
kenjiArai | 8:3e7a33f81048 | 160 | |
kenjiArai | 8:3e7a33f81048 | 161 | hhcd->Init.Host_channels = 11; |
kenjiArai | 8:3e7a33f81048 | 162 | hhcd->Init.dma_enable = 0; // for now failed with dma |
kenjiArai | 8:3e7a33f81048 | 163 | hhcd->Init.low_power_enable = 0; |
kenjiArai | 8:3e7a33f81048 | 164 | hhcd->Init.Sof_enable = 0; |
kenjiArai | 8:3e7a33f81048 | 165 | hhcd->Init.vbus_sensing_enable = 0; |
kenjiArai | 8:3e7a33f81048 | 166 | hhcd->Init.use_external_vbus = 1; |
kenjiArai | 8:3e7a33f81048 | 167 | hhcd->Init.lpm_enable = 0; |
kenjiArai | 8:3e7a33f81048 | 168 | |
kenjiArai | 8:3e7a33f81048 | 169 | HALPriv->inst = this; |
kenjiArai | 8:3e7a33f81048 | 170 | HALPriv->deviceConnected = &USBHALHost::deviceConnected; |
kenjiArai | 8:3e7a33f81048 | 171 | HALPriv->deviceDisconnected = &USBHALHost::deviceDisconnected; |
kenjiArai | 8:3e7a33f81048 | 172 | HALPriv->transferCompleted = &USBHALHost::transferCompleted; |
kenjiArai | 8:3e7a33f81048 | 173 | |
kenjiArai | 8:3e7a33f81048 | 174 | for (int i = 0; i < MAX_ENDPOINT; i++) { |
kenjiArai | 8:3e7a33f81048 | 175 | edBufAlloc[i] = false; |
kenjiArai | 8:3e7a33f81048 | 176 | HALPriv->addr[i] = (uint32_t) - 1; |
kenjiArai | 8:3e7a33f81048 | 177 | } |
kenjiArai | 8:3e7a33f81048 | 178 | |
kenjiArai | 8:3e7a33f81048 | 179 | for (int i = 0; i < MAX_TD; i++) { |
kenjiArai | 8:3e7a33f81048 | 180 | tdBufAlloc[i] = false; |
kenjiArai | 8:3e7a33f81048 | 181 | } |
kenjiArai | 8:3e7a33f81048 | 182 | |
kenjiArai | 8:3e7a33f81048 | 183 | __HAL_RCC_PWR_CLK_ENABLE(); |
kenjiArai | 8:3e7a33f81048 | 184 | |
kenjiArai | 8:3e7a33f81048 | 185 | #ifdef TARGET_STM32L4 |
kenjiArai | 8:3e7a33f81048 | 186 | HAL_PWREx_EnableVddUSB(); |
kenjiArai | 8:3e7a33f81048 | 187 | #endif |
kenjiArai | 8:3e7a33f81048 | 188 | |
kenjiArai | 8:3e7a33f81048 | 189 | // Configure USB pins |
kenjiArai | 8:3e7a33f81048 | 190 | #if defined(TARGET_NUCLEO_F401RE) || \ |
kenjiArai | 8:3e7a33f81048 | 191 | defined(TARGET_NUCLEO_F411RE) || \ |
kenjiArai | 8:3e7a33f81048 | 192 | defined(TARGET_NUCLEO_F446RE) || \ |
kenjiArai | 8:3e7a33f81048 | 193 | defined(TARGET_NUCLEO_L476RG) || \ |
kenjiArai | 8:3e7a33f81048 | 194 | defined(TARGET_NUCLEO_L486RG) || \ |
kenjiArai | 8:3e7a33f81048 | 195 | defined(TARGET_NUCLEO_F207ZG) || \ |
kenjiArai | 8:3e7a33f81048 | 196 | defined(TARGET_NUCLEO_F412ZG) || \ |
kenjiArai | 8:3e7a33f81048 | 197 | defined(TARGET_NUCLEO_F413ZH) || \ |
kenjiArai | 8:3e7a33f81048 | 198 | defined(TARGET_NUCLEO_F429ZI) || \ |
kenjiArai | 8:3e7a33f81048 | 199 | defined(TARGET_NUCLEO_F439ZI) || \ |
kenjiArai | 8:3e7a33f81048 | 200 | defined(TARGET_NUCLEO_F446ZE) || \ |
kenjiArai | 8:3e7a33f81048 | 201 | defined(TARGET_NUCLEO_F767ZI) || \ |
kenjiArai | 8:3e7a33f81048 | 202 | defined(TARGET_NUCLEO_F746ZG) || \ |
kenjiArai | 8:3e7a33f81048 | 203 | defined(TARGET_NUCLEO_F756ZG) || \ |
kenjiArai | 8:3e7a33f81048 | 204 | defined(TARGET_NUCLEO_F767ZI) || \ |
kenjiArai | 8:3e7a33f81048 | 205 | defined(TARGET_DISCO_F413ZH) || \ |
kenjiArai | 8:3e7a33f81048 | 206 | defined(TARGET_DISCO_F469NI) || \ |
kenjiArai | 8:3e7a33f81048 | 207 | defined(TARGET_DISCO_L475VG_IOT01A) |
kenjiArai | 8:3e7a33f81048 | 208 | __HAL_RCC_GPIOA_CLK_ENABLE(); |
kenjiArai | 8:3e7a33f81048 | 209 | pin_function(PA_11, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF10_OTG_FS)); // DM |
kenjiArai | 8:3e7a33f81048 | 210 | pin_function(PA_12, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF10_OTG_FS)); // DP |
kenjiArai | 8:3e7a33f81048 | 211 | pin_function(PA_10, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_PULLUP, GPIO_AF10_OTG_FS)); // ID |
kenjiArai | 8:3e7a33f81048 | 212 | pin_function(PA_9, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF10_OTG_FS)); // VBUS |
kenjiArai | 8:3e7a33f81048 | 213 | |
kenjiArai | 8:3e7a33f81048 | 214 | #elif defined(TARGET_DISCO_F746NG_FS) |
kenjiArai | 8:3e7a33f81048 | 215 | __HAL_RCC_GPIOA_CLK_ENABLE(); |
kenjiArai | 8:3e7a33f81048 | 216 | pin_function(PA_11, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF10_OTG_FS)); // DM |
kenjiArai | 8:3e7a33f81048 | 217 | pin_function(PA_12, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF10_OTG_FS)); // DP |
kenjiArai | 8:3e7a33f81048 | 218 | pin_function(PA_10, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_PULLUP, GPIO_AF10_OTG_FS)); // ID |
kenjiArai | 8:3e7a33f81048 | 219 | __HAL_RCC_GPIOJ_CLK_ENABLE(); |
kenjiArai | 8:3e7a33f81048 | 220 | pin_function(PJ_12, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF10_OTG_FS)); // VBUS |
kenjiArai | 8:3e7a33f81048 | 221 | |
kenjiArai | 8:3e7a33f81048 | 222 | #elif defined(TARGET_DISCO_F746NG_HS) |
kenjiArai | 8:3e7a33f81048 | 223 | __HAL_RCC_GPIOA_CLK_ENABLE(); |
kenjiArai | 8:3e7a33f81048 | 224 | __HAL_RCC_GPIOB_CLK_ENABLE(); |
kenjiArai | 8:3e7a33f81048 | 225 | __HAL_RCC_GPIOC_CLK_ENABLE(); |
kenjiArai | 8:3e7a33f81048 | 226 | __HAL_RCC_GPIOH_CLK_ENABLE(); |
kenjiArai | 8:3e7a33f81048 | 227 | pin_function(PA_5, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF10_OTG_HS)); // CLK |
kenjiArai | 8:3e7a33f81048 | 228 | pin_function(PA_3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF10_OTG_HS)); // D0 |
kenjiArai | 8:3e7a33f81048 | 229 | pin_function(PB_0, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF10_OTG_HS)); // D1 |
kenjiArai | 8:3e7a33f81048 | 230 | pin_function(PB_1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF10_OTG_HS)); // D2 |
kenjiArai | 8:3e7a33f81048 | 231 | pin_function(PB_5, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF10_OTG_HS)); // D3 |
kenjiArai | 8:3e7a33f81048 | 232 | pin_function(PB_10, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF10_OTG_HS)); // D4 |
kenjiArai | 8:3e7a33f81048 | 233 | pin_function(PB_11, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF10_OTG_HS)); // D5 |
kenjiArai | 8:3e7a33f81048 | 234 | pin_function(PB_12, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF10_OTG_HS)); // D6 |
kenjiArai | 8:3e7a33f81048 | 235 | pin_function(PB_13, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF10_OTG_HS)); // D7 |
kenjiArai | 8:3e7a33f81048 | 236 | pin_function(PC_0, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF10_OTG_HS)); // STP |
kenjiArai | 8:3e7a33f81048 | 237 | pin_function(PH_4, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF10_OTG_HS)); // NXT |
kenjiArai | 8:3e7a33f81048 | 238 | pin_function(PC_2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF10_OTG_HS)); // DIR |
kenjiArai | 8:3e7a33f81048 | 239 | |
kenjiArai | 8:3e7a33f81048 | 240 | #elif defined(TARGET_DISCO_F769NI) |
kenjiArai | 8:3e7a33f81048 | 241 | __HAL_RCC_GPIOA_CLK_ENABLE(); |
kenjiArai | 8:3e7a33f81048 | 242 | __HAL_RCC_GPIOB_CLK_ENABLE(); |
kenjiArai | 8:3e7a33f81048 | 243 | __HAL_RCC_GPIOC_CLK_ENABLE(); |
kenjiArai | 8:3e7a33f81048 | 244 | __HAL_RCC_GPIOH_CLK_ENABLE(); |
kenjiArai | 8:3e7a33f81048 | 245 | __HAL_RCC_GPIOI_CLK_ENABLE(); |
kenjiArai | 8:3e7a33f81048 | 246 | pin_function(PA_5, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF10_OTG_HS)); // CLK |
kenjiArai | 8:3e7a33f81048 | 247 | pin_function(PA_3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF10_OTG_HS)); // D0 |
kenjiArai | 8:3e7a33f81048 | 248 | pin_function(PB_0, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF10_OTG_HS)); // D1 |
kenjiArai | 8:3e7a33f81048 | 249 | pin_function(PB_1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF10_OTG_HS)); // D2 |
kenjiArai | 8:3e7a33f81048 | 250 | pin_function(PB_5, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF10_OTG_HS)); // D3 |
kenjiArai | 8:3e7a33f81048 | 251 | pin_function(PB_10, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF10_OTG_HS)); // D4 |
kenjiArai | 8:3e7a33f81048 | 252 | pin_function(PB_11, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF10_OTG_HS)); // D5 |
kenjiArai | 8:3e7a33f81048 | 253 | pin_function(PB_12, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF10_OTG_HS)); // D6 |
kenjiArai | 8:3e7a33f81048 | 254 | pin_function(PB_13, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF10_OTG_HS)); // D7 |
kenjiArai | 8:3e7a33f81048 | 255 | pin_function(PC_0, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF10_OTG_HS)); // STP |
kenjiArai | 8:3e7a33f81048 | 256 | pin_function(PH_4, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF10_OTG_HS)); // NXT |
kenjiArai | 8:3e7a33f81048 | 257 | pin_function(PI_11, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF10_OTG_HS)); // DIR |
kenjiArai | 8:3e7a33f81048 | 258 | |
kenjiArai | 8:3e7a33f81048 | 259 | #elif defined(TARGET_DISCO_L476VG) |
kenjiArai | 8:3e7a33f81048 | 260 | __HAL_RCC_GPIOA_CLK_ENABLE(); |
kenjiArai | 8:3e7a33f81048 | 261 | pin_function(PA_11, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF10_OTG_FS)); // DM |
kenjiArai | 8:3e7a33f81048 | 262 | pin_function(PA_12, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF10_OTG_FS)); // DP |
kenjiArai | 8:3e7a33f81048 | 263 | pin_function(PA_10, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_PULLUP, GPIO_AF10_OTG_FS)); // ID |
kenjiArai | 8:3e7a33f81048 | 264 | pin_function(PC_11, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF10_OTG_FS)); // VBUS |
kenjiArai | 8:3e7a33f81048 | 265 | |
kenjiArai | 8:3e7a33f81048 | 266 | #elif defined(TARGET_STEVAL_3DP001V1) |
kenjiArai | 8:3e7a33f81048 | 267 | __HAL_RCC_GPIOA_CLK_ENABLE(); |
kenjiArai | 8:3e7a33f81048 | 268 | pin_function(PA_11, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF10_OTG_FS)); // DM |
kenjiArai | 8:3e7a33f81048 | 269 | pin_function(PA_12, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF10_OTG_FS)); // DP |
kenjiArai | 8:3e7a33f81048 | 270 | |
kenjiArai | 8:3e7a33f81048 | 271 | #else |
kenjiArai | 8:3e7a33f81048 | 272 | #error "USB pins are not configured !" |
kenjiArai | 8:3e7a33f81048 | 273 | #endif |
kenjiArai | 8:3e7a33f81048 | 274 | |
kenjiArai | 8:3e7a33f81048 | 275 | // Configure USB POWER pin |
kenjiArai | 8:3e7a33f81048 | 276 | USB_POWERPIN_CONFIG; |
kenjiArai | 8:3e7a33f81048 | 277 | |
kenjiArai | 8:3e7a33f81048 | 278 | // Enable clocks |
kenjiArai | 8:3e7a33f81048 | 279 | __HAL_RCC_SYSCFG_CLK_ENABLE(); |
kenjiArai | 8:3e7a33f81048 | 280 | |
kenjiArai | 8:3e7a33f81048 | 281 | #if defined(TARGET_DISCO_F746NG_HS) || defined(TARGET_DISCO_F769NI) |
kenjiArai | 8:3e7a33f81048 | 282 | __HAL_RCC_USB_OTG_HS_ULPI_CLK_ENABLE(); |
kenjiArai | 8:3e7a33f81048 | 283 | __HAL_RCC_USB_OTG_HS_CLK_ENABLE(); |
kenjiArai | 8:3e7a33f81048 | 284 | #else |
kenjiArai | 8:3e7a33f81048 | 285 | __HAL_RCC_USB_OTG_FS_CLK_ENABLE(); |
kenjiArai | 8:3e7a33f81048 | 286 | #endif |
kenjiArai | 8:3e7a33f81048 | 287 | |
kenjiArai | 8:3e7a33f81048 | 288 | // Set USB interrupt |
kenjiArai | 8:3e7a33f81048 | 289 | HAL_NVIC_SetPriority(USBHAL_IRQn, 5, 0); |
kenjiArai | 8:3e7a33f81048 | 290 | NVIC_SetVector(USBHAL_IRQn, (uint32_t)&_usbisr); |
kenjiArai | 8:3e7a33f81048 | 291 | } |
kenjiArai | 8:3e7a33f81048 | 292 | |
kenjiArai | 8:3e7a33f81048 | 293 | #endif // USBHALHOST_STM_H |