blob: d0ef6625fedc7cbb42eaf56c5f0c1a0317feef20 [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 GPIOA
35#define LED_PIN GPIO_PIN_10
36#define LED_STATE_ON 1
37
38// No physical button is populated
39#define BUTTON_PORT GPIOA
40#define BUTTON_PIN GPIO_PIN_0
41#define BUTTON_STATE_ACTIVE 1
42
43#define UART_DEV USART6
44#define UART_CLK_EN __HAL_RCC_USART6_CLK_ENABLE
45#define UART_GPIO_AF GPIO_AF8_USART6
46
47#define UART_TX_PORT GPIOG
48#define UART_TX_PIN GPIO_PIN_9
49
50#define UART_RX_PORT GPIOG
51#define UART_RX_PIN GPIO_PIN_14
52
53// VBUS Sense detection
54#define OTG_FS_VBUS_SENSE 1
55#define OTG_HS_VBUS_SENSE 0
56
57//--------------------------------------------------------------------+
58// RCC Clock
59//--------------------------------------------------------------------+
60static inline void board_clock_init(void)
61{
62 RCC_ClkInitTypeDef RCC_ClkInitStruct;
63 RCC_OscInitTypeDef RCC_OscInitStruct;
64
65 /* Enable Power Control clock */
66 __HAL_RCC_PWR_CLK_ENABLE();
67
68 /* The voltage scaling allows optimizing the power consumption when the device is
69 clocked below the maximum system frequency, to update the voltage scaling value
70 regarding system frequency refer to product datasheet. */
71 __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
72
73 /* Enable HSE Oscillator and activate PLL with HSE as source */
74 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
75 RCC_OscInitStruct.HSEState = RCC_HSE_BYPASS;
76 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
77 RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
78 RCC_OscInitStruct.PLL.PLLM = HSE_VALUE/1000000;
79 RCC_OscInitStruct.PLL.PLLN = 432;
80 RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
81 RCC_OscInitStruct.PLL.PLLQ = 9;
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_ */