blob: ee342b9f5029ecae3ed1c29bc3a3820fe7cf57b1 [file] [log] [blame]
Austin Schuh41baf202022-01-01 14:33:40 -08001/*
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 GPIOI
35#define LED_PIN GPIO_PIN_1
36#define LED_STATE_ON 1
37
38#define BUTTON_PORT GPIOI
39#define BUTTON_PIN GPIO_PIN_11
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 GPIOB
50#define UART_RX_PIN GPIO_PIN_7
51
52// VBUS Sense detection
53#define OTG_FS_VBUS_SENSE 0
54#define OTG_HS_VBUS_SENSE 0
55
56//--------------------------------------------------------------------+
57// RCC Clock
58//--------------------------------------------------------------------+
59static 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_BYPASS;
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 HAL_RCC_OscConfig(&RCC_OscInitStruct);
82
83 /* Activate the OverDrive to reach the 216 MHz Frequency */
84 HAL_PWREx_EnableOverDrive();
85
86 /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2 clocks dividers */
87 RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2);
88 RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
89 RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
90 RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
91 RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
92
93 HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_7);
94}
95
96#ifdef __cplusplus
97 }
98#endif
99
100#endif /* BOARD_H_ */