diff options
Diffstat (limited to 'lib/chibios-contrib/os/hal/ports/HT32/HT32F523xx/hal_lld.h')
-rw-r--r-- | lib/chibios-contrib/os/hal/ports/HT32/HT32F523xx/hal_lld.h | 168 |
1 files changed, 168 insertions, 0 deletions
diff --git a/lib/chibios-contrib/os/hal/ports/HT32/HT32F523xx/hal_lld.h b/lib/chibios-contrib/os/hal/ports/HT32/HT32F523xx/hal_lld.h new file mode 100644 index 000000000..31a755412 --- /dev/null +++ b/lib/chibios-contrib/os/hal/ports/HT32/HT32F523xx/hal_lld.h | |||
@@ -0,0 +1,168 @@ | |||
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 | /*===========================================================================*/ | ||
34 | /* Driver constants. */ | ||
35 | /*===========================================================================*/ | ||
36 | |||
37 | /** | ||
38 | * @name Platform identification macros | ||
39 | * @{ | ||
40 | */ | ||
41 | #define PLATFORM_NAME "HT32" | ||
42 | /** @} */ | ||
43 | |||
44 | /*===========================================================================*/ | ||
45 | /* Driver pre-compile time settings. */ | ||
46 | /*===========================================================================*/ | ||
47 | |||
48 | /** | ||
49 | * @name PLATFORM configuration options | ||
50 | * @{ | ||
51 | */ | ||
52 | /** @} */ | ||
53 | |||
54 | /*===========================================================================*/ | ||
55 | /* Derived constants and error checks. */ | ||
56 | /*===========================================================================*/ | ||
57 | |||
58 | /* | ||
59 | * Configuration-related checks. | ||
60 | */ | ||
61 | #if !defined(HT32F52342_MCUCONF) && !defined(HT32F52352_MCUCONF) && \ | ||
62 | !defined(HT32F523x2_MCUCONF) | ||
63 | #error "Using a wrong mcuconf.h file, HT32_MCUCONF not defined" | ||
64 | #endif | ||
65 | |||
66 | #define HT32_CK_HSI_FREQUENCY 8000000UL // 8 MHz | ||
67 | |||
68 | #if HT32_CKCU_SW == CKCU_GCCR_SW_HSI | ||
69 | #define HT32_CK_SYS_FREQUENCY HT32_CK_HSI_FREQUENCY | ||
70 | |||
71 | #elif HT32_CKCU_SW == CKCU_GCCR_SW_HSE | ||
72 | #if !defined(HT32_CK_HSE_FREQUENCY) | ||
73 | #error "HT32_CK_HSE_FREQUENCY must be defined" | ||
74 | #endif | ||
75 | #define HT32_CK_SYS_FREQUENCY HT32_CK_HSE_FREQUENCY | ||
76 | |||
77 | #elif HT32_CKCU_SW == CKCU_GCCR_SW_PLL | ||
78 | #if !defined(HT32_PLL_USE_HSE) | ||
79 | #error "HT32_PLL_USE_HSE must be defined" | ||
80 | #endif | ||
81 | |||
82 | #if HT32_PLL_USE_HSE == TRUE | ||
83 | #if !defined(HT32_CK_HSE_FREQUENCY) | ||
84 | #error "HT32_CK_HSE_FREQUENCY must be defined" | ||
85 | #endif | ||
86 | #define HT32_PLL_IN_FREQ HT32_CK_HSE_FREQUENCY | ||
87 | #else | ||
88 | #define HT32_PLL_IN_FREQ HT32_CK_HSI_FREQUENCY | ||
89 | #endif | ||
90 | |||
91 | #if !defined(HT32_PLL_FBDIV) | ||
92 | #error "HT32_PLL_FBDIV must be defined" | ||
93 | #endif | ||
94 | #if !defined(HT32_PLL_OTDIV) | ||
95 | #error "HT32_PLL_OTDIV must be defined" | ||
96 | #endif | ||
97 | |||
98 | #define HT32_CK_PLL_FREQUENCY ((HT32_PLL_IN_FREQ * HT32_PLL_FBDIV) / (1 << HT32_PLL_OTDIV)) | ||
99 | #define HT32_CK_SYS_FREQUENCY HT32_CK_PLL_FREQUENCY | ||
100 | |||
101 | #else | ||
102 | #error "HT32_CKCU_SW is invalid" | ||
103 | #endif | ||
104 | |||
105 | #if !defined(HT32_AHB_PRESCALER) | ||
106 | #define HT32_AHB_PRESCALER 1 | ||
107 | #endif | ||
108 | |||
109 | // AHB clock | ||
110 | #define HT32_CK_AHB_FREQUENCY (HT32_CK_SYS_FREQUENCY / HT32_AHB_PRESCALER) // Max 48 MHz | ||
111 | // SysTick (may also use HCLK) | ||
112 | #define HT32_STCLK_FREQUENCY (HT32_CK_AHB_FREQUENCY / 8) // Max 8MHz | ||
113 | // CPU clock | ||
114 | #define HT32_HCLK_FREQUENCY HT32_CK_AHB_FREQUENCY | ||
115 | // Peripheral clocks | ||
116 | #define HT32_PCLK_FREQUENCY HT32_CK_AHB_FREQUENCY | ||
117 | |||
118 | // Checks | ||
119 | #if HT32_CK_SYS_FREQUENCY > 48000000 | ||
120 | #error "HT32 CK_SYS invalid" | ||
121 | #endif | ||
122 | #if HT32_CK_AHB_FREQUENCY > 48000000 | ||
123 | #error "HT32 CK_AHB invalid" | ||
124 | #endif | ||
125 | |||
126 | #if HAL_USE_UART == TRUE || HAL_USE_SERIAL == TRUE | ||
127 | #define HT32_CK_USART_FREQUENCY (HT32_CK_AHB_FREQUENCY / HT32_USART_PRESCALER) // Max 48 MHz | ||
128 | |||
129 | #if HT32_CK_USART_FREQUENCY > 48000000 | ||
130 | #error "HT32 CK_USART invalid" | ||
131 | #endif | ||
132 | #endif | ||
133 | |||
134 | #if HAL_USE_USB == TRUE | ||
135 | #if HT32_CKCU_SW != CKCU_GCCR_SW_PLL | ||
136 | #error "HT32 USB requires PLL" | ||
137 | #endif | ||
138 | #define HT32_CK_USB_FREQUENCY (HT32_CK_PLL_FREQUENCY / HT32_USB_PRESCALER) // Max 48 MHz | ||
139 | |||
140 | #if HT32_CK_USB_FREQUENCY > 48000000 | ||
141 | #error "HT32 CK_USB invalid" | ||
142 | #endif | ||
143 | #endif | ||
144 | |||
145 | /*===========================================================================*/ | ||
146 | /* Driver data structures and types. */ | ||
147 | /*===========================================================================*/ | ||
148 | |||
149 | /*===========================================================================*/ | ||
150 | /* Driver macros. */ | ||
151 | /*===========================================================================*/ | ||
152 | |||
153 | /*===========================================================================*/ | ||
154 | /* External declarations. */ | ||
155 | /*===========================================================================*/ | ||
156 | |||
157 | #ifdef __cplusplus | ||
158 | extern "C" { | ||
159 | #endif | ||
160 | void hal_lld_init(void); | ||
161 | void ht32_clock_init(void); | ||
162 | #ifdef __cplusplus | ||
163 | } | ||
164 | #endif | ||
165 | |||
166 | #endif /* _HAL_LLD_H_ */ | ||
167 | |||
168 | /** @} */ | ||