Austin Schuh | 41baf20 | 2022-01-01 14:33:40 -0800 | [diff] [blame^] | 1 | /* |
| 2 | * The MIT License (MIT) |
| 3 | * |
| 4 | * Copyright (c) 2021, Ha Thach (tinyusb.org) |
| 5 | * |
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | * of this software and associated documentation files (the "Software"), to deal |
| 8 | * in the Software without restriction, including without limitation the rights |
| 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 10 | * copies of the Software, and to permit persons to whom the Software is |
| 11 | * furnished to do so, subject to the following conditions: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice shall be included in |
| 14 | * all copies or substantial portions of the Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 22 | * THE SOFTWARE. |
| 23 | * |
| 24 | * This file is part of the TinyUSB stack. |
| 25 | */ |
| 26 | |
| 27 | #ifndef BOARD_H_ |
| 28 | #define BOARD_H_ |
| 29 | |
| 30 | #ifdef __cplusplus |
| 31 | extern "C" { |
| 32 | #endif |
| 33 | |
| 34 | #define LED_PORT GPIOJ |
| 35 | #define LED_PIN GPIO_PIN_12 |
| 36 | #define LED_STATE_ON 5 |
| 37 | |
| 38 | #define BUTTON_PORT GPIOA |
| 39 | #define BUTTON_PIN GPIO_PIN_0 |
| 40 | #define BUTTON_STATE_ACTIVE 1 |
| 41 | |
| 42 | #define UART_DEV USART1 |
| 43 | #define UART_CLK_EN __HAL_RCC_USART1_CLK_ENABLE |
| 44 | #define UART_GPIO_AF GPIO_AF7_USART1 |
| 45 | |
| 46 | #define UART_TX_PORT GPIOA |
| 47 | #define UART_TX_PIN GPIO_PIN_9 |
| 48 | |
| 49 | #define UART_RX_PORT GPIOA |
| 50 | #define UART_RX_PIN GPIO_PIN_10 |
| 51 | |
| 52 | // VBUS Sense detection |
| 53 | #define OTG_FS_VBUS_SENSE 1 |
| 54 | #define OTG_HS_VBUS_SENSE 0 |
| 55 | |
| 56 | //--------------------------------------------------------------------+ |
| 57 | // RCC Clock |
| 58 | //--------------------------------------------------------------------+ |
| 59 | static inline void board_clock_init(void) |
| 60 | { |
| 61 | RCC_ClkInitTypeDef RCC_ClkInitStruct; |
| 62 | RCC_OscInitTypeDef RCC_OscInitStruct; |
| 63 | |
| 64 | /* Enable Power Control clock */ |
| 65 | __HAL_RCC_PWR_CLK_ENABLE(); |
| 66 | |
| 67 | /* The voltage scaling allows optimizing the power consumption when the device is |
| 68 | clocked below the maximum system frequency, to update the voltage scaling value |
| 69 | regarding system frequency refer to product datasheet. */ |
| 70 | __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1); |
| 71 | |
| 72 | /* Enable HSE Oscillator and activate PLL with HSE as source */ |
| 73 | RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; |
| 74 | RCC_OscInitStruct.HSEState = RCC_HSE_ON; |
| 75 | RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; |
| 76 | RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; |
| 77 | RCC_OscInitStruct.PLL.PLLM = HSE_VALUE/1000000; |
| 78 | RCC_OscInitStruct.PLL.PLLN = 432; |
| 79 | RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2; |
| 80 | RCC_OscInitStruct.PLL.PLLQ = 9; |
| 81 | RCC_OscInitStruct.PLL.PLLR = 7; |
| 82 | HAL_RCC_OscConfig(&RCC_OscInitStruct); |
| 83 | |
| 84 | /* Activate the OverDrive to reach the 216 MHz Frequency */ |
| 85 | HAL_PWREx_EnableOverDrive(); |
| 86 | |
| 87 | /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2 clocks dividers */ |
| 88 | RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2); |
| 89 | RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; |
| 90 | RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; |
| 91 | RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4; |
| 92 | RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2; |
| 93 | |
| 94 | HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_7); |
| 95 | } |
| 96 | |
| 97 | #ifdef __cplusplus |
| 98 | } |
| 99 | #endif |
| 100 | |
| 101 | #endif /* BOARD_H_ */ |