aboutsummaryrefslogtreecommitdiff
path: root/lib/chibios-contrib/os/hal/ports/HT32/HT32F165x/hal_lld.h
diff options
context:
space:
mode:
Diffstat (limited to 'lib/chibios-contrib/os/hal/ports/HT32/HT32F165x/hal_lld.h')
-rw-r--r--lib/chibios-contrib/os/hal/ports/HT32/HT32F165x/hal_lld.h166
1 files changed, 166 insertions, 0 deletions
diff --git a/lib/chibios-contrib/os/hal/ports/HT32/HT32F165x/hal_lld.h b/lib/chibios-contrib/os/hal/ports/HT32/HT32F165x/hal_lld.h
new file mode 100644
index 000000000..3a0b76bc0
--- /dev/null
+++ b/lib/chibios-contrib/os/hal/ports/HT32/HT32F165x/hal_lld.h
@@ -0,0 +1,166 @@
1/*
2 ChibiOS - Copyright (C) 2006..2016 Giovanni Di Sirio
3 Copyright (C) 2020 Yaotian Feng
4
5 Licensed under the Apache License, Version 2.0 (the "License");
6 you may not use this file except in compliance with the License.
7 You may obtain a copy of the License at
8
9 http://www.apache.org/licenses/LICENSE-2.0
10
11 Unless required by applicable law or agreed to in writing, software
12 distributed under the License is distributed on an "AS IS" BASIS,
13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 See the License for the specific language governing permissions and
15 limitations under the License.
16*/
17
18/**
19 * @file hal_lld.h
20 * @brief HT32 HAL subsystem low level driver header.
21 *
22 * @addtogroup HAL
23 * @{
24 */
25
26#ifndef _HAL_LLD_H_
27#define _HAL_LLD_H_
28
29#include "ht32_registry.h"
30#include "nvic.h"
31
32/*===========================================================================*/
33/* Driver constants. */
34/*===========================================================================*/
35
36/**
37 * @name Platform identification macros
38 * @{
39 */
40#define PLATFORM_NAME "HT32"
41/** @} */
42
43/*===========================================================================*/
44/* Driver pre-compile time settings. */
45/*===========================================================================*/
46
47/**
48 * @name PLATFORM configuration options
49 * @{
50 */
51/** @} */
52
53/*===========================================================================*/
54/* Derived constants and error checks. */
55/*===========================================================================*/
56
57/*
58 * Configuration-related checks.
59 */
60#if !defined(HT32F165x_MCUCONF) && !defined(HT32F1654_MCUCONF) && \
61 !defined(HT32F1653_MCUCONF)
62 #error "Using a wrong mcuconf.h file, HT32_MCUCONF not defined"
63#endif
64
65#define HT32_CK_HSI_FREQUENCY 8000000UL // 8 MHz
66
67#if HT32_CKCU_SW == CKCU_GCCR_SW_HSI
68 #define HT32_CK_SYS_FREQUENCY HT32_CK_HSI_FREQUENCY
69
70#elif HT32_CKCU_SW == CKCU_GCCR_SW_HSE
71 #if !defined(HT32_CK_HSE_FREQUENCY)
72 #error "HT32_CK_HSE_FREQUENCY must be defined"
73 #endif
74 #define HT32_CK_SYS_FREQUENCY HT32_CK_HSE_FREQUENCY
75
76#elif HT32_CKCU_SW == CKCU_GCCR_SW_PLL
77 #if !defined(HT32_PLL_USE_HSE)
78 #error "HT32_PLL_USE_HSE must be defined"
79 #endif
80
81 #if HT32_PLL_USE_HSE == TRUE
82 #if !defined(HT32_CK_HSE_FREQUENCY)
83 #error "HT32_CK_HSE_FREQUENCY must be defined"
84 #endif
85 #define HT32_PLL_IN_FREQ HT32_CK_HSE_FREQUENCY
86 #else
87 #define HT32_PLL_IN_FREQ HT32_CK_HSI_FREQUENCY
88 #endif
89
90 #if !defined(HT32_PLL_FBDIV)
91 #error "HT32_PLL_FBDIV must be defined"
92 #endif
93 #if !defined(HT32_PLL_OTDIV)
94 #error "HT32_PLL_OTDIV must be defined"
95 #endif
96
97 #define HT32_CK_PLL_FREQUENCY ((HT32_PLL_IN_FREQ * HT32_PLL_FBDIV) / (1 << HT32_PLL_OTDIV))
98 #define HT32_CK_SYS_FREQUENCY HT32_CK_PLL_FREQUENCY
99
100#else
101 #error "HT32_CKCU_SW is invalid"
102#endif
103
104#if !defined(HT32_AHB_PRESCALER)
105 #define HT32_AHB_PRESCALER 1
106#endif
107
108// AHB clock
109#define HT32_CK_AHB_FREQUENCY (HT32_CK_SYS_FREQUENCY / HT32_AHB_PRESCALER) // Max 72 MHz
110// SysTick (may also use HCLK)
111#define HT32_STCLK_FREQUENCY (HT32_CK_AHB_FREQUENCY / 8) // Max 8MHz
112// CPU clock
113#define HT32_HCLK_FREQUENCY HT32_CK_AHB_FREQUENCY
114// Peripheral clocks
115#define HT32_PCLK_FREQUENCY HT32_CK_AHB_FREQUENCY
116
117// Checks
118#if HT32_CK_SYS_FREQUENCY > 144000000
119 #error "HT32 CK_SYS invalid"
120#endif
121#if HT32_CK_AHB_FREQUENCY > 72000000
122 #error "HT32 CK_AHB invalid"
123#endif
124
125#if (HAL_USE_UART == TRUE || HAL_USE_SERIAL == TRUE)
126 #define HT32_CK_USART_FREQUENCY (HT32_CK_AHB_FREQUENCY / HT32_USART_PRESCALER) // Max 72 MHz
127 #if HT32_CK_USART_FREQUENCY > 72000000
128 #error "HT32 CK_USART invalid"
129 #endif
130#endif
131
132#if HAL_USE_USB == TRUE
133 #if HT32_CKCU_SW != CKCU_GCCR_SW_PLL
134 #error "HT32 USB requires PLL"
135 #endif
136 #define HT32_CK_USB_FREQUENCY (HT32_CK_PLL_FREQUENCY / HT32_USB_PRESCALER) // Max 48 MHz
137
138 #if HT32_CK_USB_FREQUENCY > 48000000
139 #error "HT32 CK_USB invalid"
140 #endif
141#endif
142
143/*===========================================================================*/
144/* Driver data structures and types. */
145/*===========================================================================*/
146
147/*===========================================================================*/
148/* Driver macros. */
149/*===========================================================================*/
150
151/*===========================================================================*/
152/* External declarations. */
153/*===========================================================================*/
154
155#ifdef __cplusplus
156extern "C" {
157#endif
158 void hal_lld_init(void);
159 void ht32_clock_init(void);
160#ifdef __cplusplus
161}
162#endif
163
164#endif /* _HAL_LLD_H_ */
165
166/** @} */