rjw | 1f88458 | 2022-01-06 17:20:42 +0800 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (c) 2015 Travis Geiselbrecht |
| 3 | * |
| 4 | * Permission is hereby granted, free of charge, to any person obtaining |
| 5 | * a copy of this software and associated documentation files |
| 6 | * (the "Software"), to deal in the Software without restriction, |
| 7 | * including without limitation the rights to use, copy, modify, merge, |
| 8 | * publish, distribute, sublicense, and/or sell copies of the Software, |
| 9 | * and to permit persons to whom the Software is furnished to do so, |
| 10 | * subject to the following conditions: |
| 11 | * |
| 12 | * The above copyright notice and this permission notice shall be |
| 13 | * included in all copies or substantial portions of the Software. |
| 14 | * |
| 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
| 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY |
| 19 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
| 20 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
| 21 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 22 | */ |
| 23 | #include <err.h> |
| 24 | #include <stdlib.h> |
| 25 | #include <debug.h> |
| 26 | #include <trace.h> |
| 27 | #include <target.h> |
| 28 | #include <compiler.h> |
| 29 | #include <dev/gpio.h> |
| 30 | #include <dev/usb.h> |
| 31 | #include <dev/accelerometer.h> |
| 32 | #include <platform/stm32.h> |
| 33 | #include <platform/sdram.h> |
| 34 | #include <platform/gpio.h> |
| 35 | #include <platform/eth.h> |
| 36 | #include <platform/qspi.h> |
| 37 | #include <platform/n25q128a.h> |
| 38 | #include <target/bmi055.h> |
| 39 | #include <target/debugconfig.h> |
| 40 | #include <target/gpioconfig.h> |
| 41 | #include <target/memory_lcd.h> |
| 42 | #include <target/sensor_bus.h> |
| 43 | #include <reg.h> |
| 44 | |
| 45 | #if WITH_LIB_MINIP |
| 46 | #include <lib/minip.h> |
| 47 | #endif |
| 48 | |
| 49 | #if WITH_LIB_FS_SPIFS |
| 50 | #include <lib/fs.h> |
| 51 | #include <target/fsconfig.h> |
| 52 | #endif |
| 53 | |
| 54 | extern void target_usb_setup(void); |
| 55 | |
| 56 | const sdram_config_t target_sdram_config = { |
| 57 | .bus_width = SDRAM_BUS_WIDTH_16, |
| 58 | .cas_latency = SDRAM_CAS_LATENCY_2, |
| 59 | .col_bits_num = SDRAM_COLUMN_BITS_8 |
| 60 | }; |
| 61 | |
| 62 | void target_early_init(void) |
| 63 | { |
| 64 | GPIO_InitTypeDef gpio_init; |
| 65 | |
| 66 | __HAL_RCC_GPIOE_CLK_ENABLE(); |
| 67 | __HAL_RCC_GPIOD_CLK_ENABLE(); |
| 68 | __HAL_RCC_GPIOJ_CLK_ENABLE(); |
| 69 | |
| 70 | #if DEBUG_UART == 3 |
| 71 | // configure usart 3 pins. |
| 72 | gpio_config(GPIO_USART3_TX, GPIO_STM32_AF | GPIO_STM32_AFn(GPIO_AF7_USART3) | GPIO_PULLUP); |
| 73 | gpio_config(GPIO_USART3_RX, GPIO_STM32_AF | GPIO_STM32_AFn(GPIO_AF7_USART3) | GPIO_PULLUP); |
| 74 | #else |
| 75 | #error need to configure gpio pins for debug uart |
| 76 | #endif |
| 77 | |
| 78 | gpio_init.Mode = GPIO_MODE_OUTPUT_PP; |
| 79 | gpio_init.Pull = GPIO_NOPULL; |
| 80 | gpio_init.Speed = GPIO_SPEED_LOW; |
| 81 | |
| 82 | gpio_init.Pin = GPIO_TO_PIN_MASK(GPIO_LED108) | GPIO_TO_PIN_MASK(GPIO_LED109) | |
| 83 | GPIO_TO_PIN_MASK(GPIO_LED110) | GPIO_TO_PIN_MASK(GPIO_LED111); |
| 84 | HAL_GPIO_Init(GPIOE, &gpio_init); |
| 85 | |
| 86 | gpio_init.Pin = GPIO_TO_PIN_MASK(GPIO_LED112) | GPIO_TO_PIN_MASK(GPIO_LED113); |
| 87 | HAL_GPIO_Init(GPIOD, &gpio_init); |
| 88 | |
| 89 | gpio_init.Pin = GPIO_TO_PIN_MASK(GPIO_LED114) | GPIO_TO_PIN_MASK(GPIO_LED115); |
| 90 | HAL_GPIO_Init(GPIOJ, &gpio_init); |
| 91 | |
| 92 | // Initialize to a pattern just so we know we have something |
| 93 | gpio_set(GPIO_LED108, GPIO_LED_ON); |
| 94 | gpio_set(GPIO_LED109, GPIO_LED_ON); |
| 95 | gpio_set(GPIO_LED110, GPIO_LED_ON); |
| 96 | gpio_set(GPIO_LED111, GPIO_LED_ON); |
| 97 | gpio_set(GPIO_LED112, GPIO_LED_ON); |
| 98 | gpio_set(GPIO_LED113, GPIO_LED_ON); |
| 99 | gpio_set(GPIO_LED114, GPIO_LED_ON); |
| 100 | gpio_set(GPIO_LED115, GPIO_LED_ON); |
| 101 | |
| 102 | // Initialize the switches GPIOs for interrupt on raising edge. In order |
| 103 | // to use stm32_EXTI15_10_IRQ() handler needs to be provided and EXTI15_10_IRQn |
| 104 | // needs to be enabled. |
| 105 | gpio_init.Mode = GPIO_MODE_INPUT; |
| 106 | gpio_init.Pull = GPIO_NOPULL; |
| 107 | gpio_init.Speed = GPIO_SPEED_FAST; |
| 108 | gpio_init.Mode = GPIO_MODE_IT_RISING; |
| 109 | |
| 110 | gpio_init.Pin = GPIO_TO_PIN_MASK(GPIO_SW100) | GPIO_TO_PIN_MASK(GPIO_SW101) | |
| 111 | GPIO_TO_PIN_MASK(GPIO_SW102) | GPIO_TO_PIN_MASK(GPIO_SW103); |
| 112 | HAL_GPIO_Init(GPIOJ, &gpio_init); |
| 113 | |
| 114 | // Initialize Sensor bus (accelerometer / gyroscope / nrf51 spi bus |
| 115 | sensor_bus_init_early(); |
| 116 | |
| 117 | // now that the uart gpios are configured, enable the debug uart. |
| 118 | stm32_debug_early_init(); |
| 119 | |
| 120 | // default all the debug leds to off |
| 121 | target_set_debug_led(0, false); |
| 122 | target_set_debug_led(1, false); |
| 123 | target_set_debug_led(2, false); |
| 124 | target_set_debug_led(3, false); |
| 125 | } |
| 126 | |
| 127 | |
| 128 | void target_init(void) |
| 129 | { |
| 130 | stm32_debug_init(); |
| 131 | |
| 132 | qspi_flash_init(N25Q128A_FLASH_SIZE); |
| 133 | |
| 134 | memory_lcd_init(); |
| 135 | |
| 136 | #if WITH_LIB_MINIP |
| 137 | uint8_t mac_addr[6]; |
| 138 | gen_random_mac_address(mac_addr); |
| 139 | eth_init(mac_addr, PHY_KSZ8721); |
| 140 | |
| 141 | /* start minip */ |
| 142 | minip_set_macaddr(mac_addr); |
| 143 | |
| 144 | uint32_t ip_addr = IPV4(192, 168, 0, 98); |
| 145 | uint32_t ip_mask = IPV4(255, 255, 255, 0); |
| 146 | uint32_t ip_gateway = IPV4_NONE; |
| 147 | |
| 148 | minip_init(stm32_eth_send_minip_pkt, NULL, ip_addr, ip_mask, ip_gateway); |
| 149 | #endif |
| 150 | |
| 151 | #if WITH_LIB_FS_SPIFS |
| 152 | status_t mount_success = |
| 153 | fs_mount(SPIFS_MOUNT_POINT, SPIFS_NAME, SPIFS_TARGET_DEVICE); |
| 154 | if (mount_success != NO_ERROR) { |
| 155 | printf("failed to mount '%s' at path '%s' on '%s'." |
| 156 | " Make sure that device is formatted\n", |
| 157 | SPIFS_NAME, SPIFS_MOUNT_POINT, SPIFS_TARGET_DEVICE); |
| 158 | } |
| 159 | |
| 160 | #endif |
| 161 | |
| 162 | // start usb |
| 163 | target_usb_setup(); |
| 164 | |
| 165 | sensor_bus_init(); |
| 166 | } |
| 167 | |
| 168 | void HAL_SPI_MspInit(SPI_HandleTypeDef *hspi) |
| 169 | { |
| 170 | GPIO_InitTypeDef GPIO_InitStruct; |
| 171 | if (hspi->Instance == SPI2) { |
| 172 | /*##-1- Enable peripherals and GPIO Clocks #################################*/ |
| 173 | /* Enable GPIO TX/RX clock */ |
| 174 | __HAL_RCC_GPIOD_CLK_ENABLE(); |
| 175 | __HAL_RCC_GPIOK_CLK_ENABLE(); |
| 176 | __HAL_RCC_GPIOB_CLK_ENABLE(); |
| 177 | /* Enable SPI clock */ |
| 178 | __HAL_RCC_SPI2_CLK_ENABLE(); |
| 179 | |
| 180 | /*##-2- Configure peripheral GPIO ##########################################*/ |
| 181 | /* SPI SCK GPIO pin configuration */ |
| 182 | GPIO_InitStruct.Pin = GPIO_PIN_3; |
| 183 | GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; |
| 184 | GPIO_InitStruct.Pull = GPIO_PULLDOWN; |
| 185 | GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; |
| 186 | GPIO_InitStruct.Alternate = GPIO_AF5_SPI2; |
| 187 | HAL_GPIO_Init(GPIOD, &GPIO_InitStruct); |
| 188 | |
| 189 | /* SPI MOSI GPIO pin configuration */ |
| 190 | GPIO_InitStruct.Pin = GPIO_PIN_15; |
| 191 | HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); |
| 192 | |
| 193 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; |
| 194 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
| 195 | |
| 196 | /* LCD_ON Pin configuration */ |
| 197 | GPIO_InitStruct.Pin = GPIO_PIN_6; |
| 198 | HAL_GPIO_Init(GPIOK, &GPIO_InitStruct); |
| 199 | |
| 200 | /* LCD_CS Pin configuration */ |
| 201 | GPIO_InitStruct.Pin = GPIO_PIN_12; |
| 202 | HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); |
| 203 | |
| 204 | |
| 205 | /*##-3- Configure the NVIC for SPI #########################################*/ |
| 206 | /* NVIC for SPI */ |
| 207 | HAL_NVIC_EnableIRQ(SPI2_IRQn); |
| 208 | } |
| 209 | } |
| 210 | |
| 211 | /** |
| 212 | * @brief Initializes SDRAM GPIO. |
| 213 | * called back from stm32_sdram_init |
| 214 | */ |
| 215 | void stm_sdram_GPIO_init(void) |
| 216 | { |
| 217 | GPIO_InitTypeDef gpio_init_structure; |
| 218 | |
| 219 | /* Enable GPIOs clock */ |
| 220 | __HAL_RCC_GPIOC_CLK_ENABLE(); |
| 221 | __HAL_RCC_GPIOD_CLK_ENABLE(); |
| 222 | __HAL_RCC_GPIOE_CLK_ENABLE(); |
| 223 | __HAL_RCC_GPIOF_CLK_ENABLE(); |
| 224 | __HAL_RCC_GPIOG_CLK_ENABLE(); |
| 225 | __HAL_RCC_GPIOH_CLK_ENABLE(); |
| 226 | |
| 227 | /* Common GPIO configuration */ |
| 228 | gpio_init_structure.Mode = GPIO_MODE_AF_PP; |
| 229 | gpio_init_structure.Pull = GPIO_PULLUP; |
| 230 | gpio_init_structure.Speed = GPIO_SPEED_FAST; |
| 231 | gpio_init_structure.Alternate = GPIO_AF12_FMC; |
| 232 | |
| 233 | /* GPIOC configuration */ |
| 234 | gpio_init_structure.Pin = GPIO_PIN_3; |
| 235 | HAL_GPIO_Init(GPIOC, &gpio_init_structure); |
| 236 | |
| 237 | /* GPIOD configuration */ |
| 238 | gpio_init_structure.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_3 | GPIO_PIN_8| GPIO_PIN_9 | GPIO_PIN_10 |\ |
| 239 | GPIO_PIN_14 | GPIO_PIN_15; |
| 240 | HAL_GPIO_Init(GPIOD, &gpio_init_structure); |
| 241 | |
| 242 | /* GPIOE configuration */ |
| 243 | gpio_init_structure.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_7| GPIO_PIN_8 | GPIO_PIN_9 |\ |
| 244 | GPIO_PIN_10 | GPIO_PIN_11 | GPIO_PIN_12 | GPIO_PIN_13 | GPIO_PIN_14 |\ |
| 245 | GPIO_PIN_15; |
| 246 | HAL_GPIO_Init(GPIOE, &gpio_init_structure); |
| 247 | |
| 248 | /* GPIOF configuration */ |
| 249 | gpio_init_structure.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2| GPIO_PIN_3 | GPIO_PIN_4 |\ |
| 250 | GPIO_PIN_5 | GPIO_PIN_11 | GPIO_PIN_12 | GPIO_PIN_13 | GPIO_PIN_14 |\ |
| 251 | GPIO_PIN_15; |
| 252 | HAL_GPIO_Init(GPIOF, &gpio_init_structure); |
| 253 | |
| 254 | /* GPIOG configuration */ |
| 255 | gpio_init_structure.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_4| GPIO_PIN_5 | GPIO_PIN_8 |\ |
| 256 | GPIO_PIN_15; |
| 257 | HAL_GPIO_Init(GPIOG, &gpio_init_structure); |
| 258 | |
| 259 | /* GPIOH configuration */ |
| 260 | gpio_init_structure.Pin = GPIO_PIN_3 | GPIO_PIN_5; |
| 261 | HAL_GPIO_Init(GPIOH, &gpio_init_structure); |
| 262 | } |
| 263 | |
| 264 | |
| 265 | /** |
| 266 | * @brief Initializes the ETH MSP. |
| 267 | * @param heth: ETH handle |
| 268 | * @retval None |
| 269 | */ |
| 270 | /* called back from the HAL_ETH_Init routine */ |
| 271 | void HAL_ETH_MspInit(ETH_HandleTypeDef *heth) |
| 272 | { |
| 273 | GPIO_InitTypeDef GPIO_InitStructure; |
| 274 | |
| 275 | /* Enable GPIOs clocks */ |
| 276 | __HAL_RCC_GPIOA_CLK_ENABLE(); |
| 277 | __HAL_RCC_GPIOC_CLK_ENABLE(); |
| 278 | __HAL_RCC_GPIOG_CLK_ENABLE(); |
| 279 | |
| 280 | /* Ethernet pins configuration ************************************************/ |
| 281 | /* |
| 282 | RMII_REF_CLK ----------------------> PA1 |
| 283 | RMII_MDIO -------------------------> PA2 |
| 284 | RMII_MDC --------------------------> PC1 |
| 285 | RMII_MII_CRS_DV -------------------> PA7 |
| 286 | RMII_MII_RXD0 ---------------------> PC4 |
| 287 | RMII_MII_RXD1 ---------------------> PC5 |
| 288 | RMII_MII_TX_EN --------------------> PG11 |
| 289 | RMII_MII_TXD0 ---------------------> PG13 |
| 290 | RMII_MII_TXD1 ---------------------> PG14 |
| 291 | */ |
| 292 | |
| 293 | /* Configure PA1, PA2 and PA7 */ |
| 294 | GPIO_InitStructure.Speed = GPIO_SPEED_HIGH; |
| 295 | GPIO_InitStructure.Mode = GPIO_MODE_AF_PP; |
| 296 | GPIO_InitStructure.Pull = GPIO_NOPULL; |
| 297 | GPIO_InitStructure.Alternate = GPIO_AF11_ETH; |
| 298 | GPIO_InitStructure.Pin = GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_7; |
| 299 | HAL_GPIO_Init(GPIOA, &GPIO_InitStructure); |
| 300 | |
| 301 | /* Configure PC1, PC4 and PC5 */ |
| 302 | GPIO_InitStructure.Pin = GPIO_PIN_1 | GPIO_PIN_4 | GPIO_PIN_5; |
| 303 | HAL_GPIO_Init(GPIOC, &GPIO_InitStructure); |
| 304 | |
| 305 | /* Configure PG2, PG11, PG13 and PG14 */ |
| 306 | GPIO_InitStructure.Pin = GPIO_PIN_2 | GPIO_PIN_11 | GPIO_PIN_13 | GPIO_PIN_14; |
| 307 | HAL_GPIO_Init(GPIOG, &GPIO_InitStructure); |
| 308 | } |
| 309 | |
| 310 | void HAL_QSPI_MspInit(QSPI_HandleTypeDef *hqspi) |
| 311 | { |
| 312 | GPIO_InitTypeDef GPIO_InitStruct; |
| 313 | |
| 314 | /*##-1- Enable peripherals and GPIO Clocks #################################*/ |
| 315 | /* Enable GPIO clocks */ |
| 316 | __HAL_RCC_GPIOB_CLK_ENABLE(); |
| 317 | __HAL_RCC_GPIOD_CLK_ENABLE(); |
| 318 | __HAL_RCC_GPIOE_CLK_ENABLE(); |
| 319 | |
| 320 | /*##-2- Configure peripheral GPIO ##########################################*/ |
| 321 | /* QSPI CS GPIO pin configuration */ |
| 322 | GPIO_InitStruct.Pin = GPIO_PIN_6; |
| 323 | GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; |
| 324 | GPIO_InitStruct.Pull = GPIO_PULLUP; |
| 325 | GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; |
| 326 | GPIO_InitStruct.Alternate = GPIO_AF10_QUADSPI; |
| 327 | HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); |
| 328 | |
| 329 | /* QSPI CLK GPIO pin configuration */ |
| 330 | GPIO_InitStruct.Pin = GPIO_PIN_2; |
| 331 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
| 332 | GPIO_InitStruct.Alternate = GPIO_AF9_QUADSPI; |
| 333 | HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); |
| 334 | |
| 335 | /* QSPI D0 GPIO pin configuration */ |
| 336 | GPIO_InitStruct.Pin = GPIO_PIN_11; |
| 337 | GPIO_InitStruct.Alternate = GPIO_AF9_QUADSPI; |
| 338 | HAL_GPIO_Init(GPIOD, &GPIO_InitStruct); |
| 339 | |
| 340 | /* QSPI D1 GPIO pin configuration */ |
| 341 | GPIO_InitStruct.Pin = GPIO_PIN_12; |
| 342 | GPIO_InitStruct.Alternate = GPIO_AF9_QUADSPI; |
| 343 | HAL_GPIO_Init(GPIOD, &GPIO_InitStruct); |
| 344 | |
| 345 | /* QSPI D2 GPIO pin configuration */ |
| 346 | GPIO_InitStruct.Pin = GPIO_PIN_2; |
| 347 | GPIO_InitStruct.Alternate = GPIO_AF9_QUADSPI; |
| 348 | HAL_GPIO_Init(GPIOE, &GPIO_InitStruct); |
| 349 | |
| 350 | /* QSPI D3 GPIO pin configuration */ |
| 351 | GPIO_InitStruct.Pin = GPIO_PIN_13; |
| 352 | GPIO_InitStruct.Alternate = GPIO_AF9_QUADSPI; |
| 353 | HAL_GPIO_Init(GPIOD, &GPIO_InitStruct); |
| 354 | } |
| 355 | |
| 356 | /** |
| 357 | * @brief Initializes the PCD MSP. |
| 358 | * @param hpcd: PCD handle |
| 359 | * @retval None |
| 360 | */ |
| 361 | void HAL_PCD_MspInit(PCD_HandleTypeDef *hpcd) |
| 362 | { |
| 363 | GPIO_InitTypeDef GPIO_InitStruct; |
| 364 | |
| 365 | if (hpcd->Instance == USB_OTG_FS) { |
| 366 | /* Configure USB FS GPIOs */ |
| 367 | __HAL_RCC_GPIOA_CLK_ENABLE(); |
| 368 | |
| 369 | /* Configure DM DP Pins */ |
| 370 | GPIO_InitStruct.Pin = (GPIO_PIN_11 | GPIO_PIN_12); |
| 371 | GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; |
| 372 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
| 373 | GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; |
| 374 | GPIO_InitStruct.Alternate = GPIO_AF10_OTG_FS; |
| 375 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
| 376 | |
| 377 | /* Enable USB FS Clock */ |
| 378 | __HAL_RCC_USB_OTG_FS_CLK_ENABLE(); |
| 379 | |
| 380 | /* Set USBFS Interrupt priority */ |
| 381 | HAL_NVIC_SetPriority(OTG_FS_IRQn, 5, 0); |
| 382 | |
| 383 | /* Enable USBFS Interrupt */ |
| 384 | HAL_NVIC_EnableIRQ(OTG_FS_IRQn); |
| 385 | |
| 386 | if (hpcd->Init.low_power_enable == 1) { |
| 387 | /* Enable EXTI Line 18 for USB wakeup*/ |
| 388 | __HAL_USB_OTG_FS_WAKEUP_EXTI_CLEAR_FLAG(); |
| 389 | __HAL_USB_OTG_FS_WAKEUP_EXTI_ENABLE_RISING_EDGE(); |
| 390 | __HAL_USB_OTG_FS_WAKEUP_EXTI_ENABLE_IT(); |
| 391 | |
| 392 | /* Set EXTI Wakeup Interrupt priority*/ |
| 393 | HAL_NVIC_SetPriority(OTG_FS_WKUP_IRQn, 0, 0); |
| 394 | |
| 395 | /* Enable EXTI Interrupt */ |
| 396 | HAL_NVIC_EnableIRQ(OTG_FS_WKUP_IRQn); |
| 397 | } |
| 398 | } else if (hpcd->Instance == USB_OTG_HS) { |
| 399 | /* Configure USB FS GPIOs */ |
| 400 | __HAL_RCC_GPIOA_CLK_ENABLE(); |
| 401 | __HAL_RCC_GPIOB_CLK_ENABLE(); |
| 402 | __HAL_RCC_GPIOC_CLK_ENABLE(); |
| 403 | __HAL_RCC_GPIOH_CLK_ENABLE(); |
| 404 | |
| 405 | /* CLK */ |
| 406 | GPIO_InitStruct.Pin = GPIO_PIN_5; |
| 407 | GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; |
| 408 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
| 409 | GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; |
| 410 | GPIO_InitStruct.Alternate = GPIO_AF10_OTG_HS; |
| 411 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
| 412 | |
| 413 | /* D0 */ |
| 414 | GPIO_InitStruct.Pin = GPIO_PIN_3; |
| 415 | GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; |
| 416 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
| 417 | GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; |
| 418 | GPIO_InitStruct.Alternate = GPIO_AF10_OTG_HS; |
| 419 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
| 420 | |
| 421 | /* D1 D2 D3 D4 D5 D6 D7 */ |
| 422 | GPIO_InitStruct.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_5 |\ |
| 423 | GPIO_PIN_10 | GPIO_PIN_11 | GPIO_PIN_12 | GPIO_PIN_13; |
| 424 | GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; |
| 425 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
| 426 | GPIO_InitStruct.Alternate = GPIO_AF10_OTG_HS; |
| 427 | HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); |
| 428 | |
| 429 | /* STP */ |
| 430 | GPIO_InitStruct.Pin = GPIO_PIN_0; |
| 431 | GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; |
| 432 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
| 433 | GPIO_InitStruct.Alternate = GPIO_AF10_OTG_HS; |
| 434 | HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); |
| 435 | |
| 436 | /* NXT */ |
| 437 | GPIO_InitStruct.Pin = GPIO_PIN_4; |
| 438 | GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; |
| 439 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
| 440 | GPIO_InitStruct.Alternate = GPIO_AF10_OTG_HS; |
| 441 | HAL_GPIO_Init(GPIOH, &GPIO_InitStruct); |
| 442 | |
| 443 | /* DIR */ |
| 444 | GPIO_InitStruct.Pin = GPIO_PIN_2; |
| 445 | GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; |
| 446 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
| 447 | GPIO_InitStruct.Alternate = GPIO_AF10_OTG_HS; |
| 448 | HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); |
| 449 | |
| 450 | __HAL_RCC_USB_OTG_HS_ULPI_CLK_ENABLE(); |
| 451 | |
| 452 | /* Enable USB HS Clocks */ |
| 453 | __HAL_RCC_USB_OTG_HS_CLK_ENABLE(); |
| 454 | |
| 455 | /* Set USBHS Interrupt to the lowest priority */ |
| 456 | HAL_NVIC_SetPriority(OTG_HS_IRQn, 5, 0); |
| 457 | |
| 458 | /* Enable USBHS Interrupt */ |
| 459 | HAL_NVIC_EnableIRQ(OTG_HS_IRQn); |
| 460 | } |
| 461 | } |
| 462 | |
| 463 | void target_set_debug_led(unsigned int led, bool on) |
| 464 | { |
| 465 | uint32_t gpio; |
| 466 | |
| 467 | switch (led) { |
| 468 | case 0: |
| 469 | gpio = GPIO_LED112; |
| 470 | break; |
| 471 | case 1: |
| 472 | gpio = GPIO_LED113; |
| 473 | break; |
| 474 | case 2: |
| 475 | gpio = GPIO_LED114; |
| 476 | break; |
| 477 | case 3: |
| 478 | gpio = GPIO_LED115; |
| 479 | break; |
| 480 | default: |
| 481 | return; |
| 482 | } |
| 483 | |
| 484 | gpio_set(gpio, on ? GPIO_LED_ON : GPIO_LED_OFF); |
| 485 | } |
| 486 | |