aboutsummaryrefslogtreecommitdiff
path: root/lib/chibios-contrib/os/hal/ports/NUMICRO/NUC123/hal_lld.h
diff options
context:
space:
mode:
Diffstat (limited to 'lib/chibios-contrib/os/hal/ports/NUMICRO/NUC123/hal_lld.h')
-rw-r--r--lib/chibios-contrib/os/hal/ports/NUMICRO/NUC123/hal_lld.h330
1 files changed, 330 insertions, 0 deletions
diff --git a/lib/chibios-contrib/os/hal/ports/NUMICRO/NUC123/hal_lld.h b/lib/chibios-contrib/os/hal/ports/NUMICRO/NUC123/hal_lld.h
new file mode 100644
index 000000000..0c022e3b8
--- /dev/null
+++ b/lib/chibios-contrib/os/hal/ports/NUMICRO/NUC123/hal_lld.h
@@ -0,0 +1,330 @@
1/*
2 Copyright (C) 2020 Alex Lewontin
3 Copyright (C) 2019 /u/KeepItUnder
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 NUC123/hal_lld.h
20 * @brief NUC123 HAL subsystem low level driver header.
21 * @pre This module requires the following macros to be defined in the
22 * @p board.h file:
23 * - NUC123_HSECLK.
24 * - NUC123_HSE_BYPASS (optionally).
25 * .
26 *
27 * @addtogroup HAL
28 * @{
29 */
30
31#ifndef HAL_LLD_H
32#define HAL_LLD_H
33
34/*===========================================================================*/
35/* Driver constants. */
36/*===========================================================================*/
37
38/**
39 * @name Platform identification macros
40 * @{
41 */
42#if defined(NUC123SD4AN0) || defined(__DOXYGEN__)
43#define PLATFORM_NAME "NUC123SD4AN0 NUC123 Cortex M0 USB Micro"
44#define NUC123xxxANx
45#undef NUC123xxxAEx
46#define NUC123_FLASH_SIZE 0x11000
47#else
48#error "NUC123 device unsupported or not specified"
49#endif
50
51/* TODO: Add other NUC123xxxxxx versions */
52
53/** @} */
54
55/**
56 * @name Absolute Maximum Ratings
57 * @{
58 */
59
60/**
61 * @brief Maximum HSE clock frequency.
62 */
63#define NUC123_HSECLK_MAX 24000000
64
65/**
66 * @brief Minimum HSE clock frequency.
67 */
68#define NUC123_HSECLK_MIN 4000000
69
70/**
71 * @brief Minimum PLL frequency.
72 */
73#define NUC123_PLLCLK_MIN 25000000UL
74
75/**
76 * @brief Maximum PLL frequency.
77 */
78#define NUC123_PLLCLK_MAX 144000000UL
79
80/**
81 * @brief Minimum HCLK divider value.
82 */
83#define NUC123_HCLKDIV_MIN 1
84
85/**
86 * @brief Maximum HCLK divider value.
87 */
88#define NUC123_HCLKDIV_MAX 16
89/** @} */
90
91/**
92 * @name Internal clock sources
93 * @{
94 */
95#define NUC123_HSICLK __HIRC /**< High speed internal clock. */
96#define NUC123_LSICLK __LIRC /**< Low speed internal clock. */
97/** @} */
98
99/**
100 * @name HCLK_S bit definitions
101 * @{
102 */
103#define NUC123_HCLKSRC_HSE (0 << CLK_CLKSEL0_HCLK_S_Pos) /**< HCLK source is HSE. */
104#define NUC123_HCLKSRC_PLL_2 (1 << CLK_CLKSEL0_HCLK_S_Pos) /**< HCLK source is PLL/2. */
105#define NUC123_HCLKSRC_PLL (2 << CLK_CLKSEL0_HCLK_S_Pos) /**< HCLK source is PLL. */
106#define NUC123_HCLKSRC_LSI (3 << CLK_CLKSEL0_HCLK_S_Pos) /**< HCLK source is LSI. */
107#define NUC123_HCLKSRC_HSI (7 << CLK_CLKSEL0_HCLK_S_Pos) /**< HCLK source is HSI. */
108/** @} */
109
110/**
111 * @name PLL_SRC bit definitions
112 * @{
113 */
114#define NUC123_PLLSRC_HSE (0 << CLK_PLLCON_PLL_SRC_Pos) /**< PLL source is HSE. */
115#define NUC123_PLLSRC_HSI (1 << CLK_PLLCON_PLL_SRC_Pos) /**< PLL source is HSI. */
116/** @} */
117
118/**
119 * @name User config bit definitions
120 * @{
121 */
122#define NUC123_CONFIG0_DFEN_Pos 0
123#define NUC123_CONFIG0_DFEN_Msk (1 << NUC123_CONFIG0_DFEN_Pos)
124
125#define NUC123_CONFIG0_LOCK_Pos 1
126#define NUC123_CONFIG0_LOCK_Msk (1 << NUC123_CONFIG0_LOCK_Pos)
127
128#define NUC123_CONFIG0_DFVSEN_Pos 2
129#define NUC123_CONFIG0_DFVSEN_Msk (1 << NUC123_CONFIG0_DFVSEN_Pos)
130
131#define NUC123_CONFIG0_CGPFMFP_Pos 27
132#define NUC123_CONFIG0_CGPFMFP_Msk (1 << NUC123_CONFIG0_CGPFMFP_Pos)
133/** @} */
134
135/*===========================================================================*/
136/* Driver pre-compile time settings. */
137/*===========================================================================*/
138
139/**
140 * @name NUMICRO configuration options
141 * @{
142 */
143
144/**
145 * @brief Disables the PWR/RCC initialization in the HAL.
146 */
147#if !defined(NUC123_NO_INIT) || defined(__DOXYGEN__)
148#define NUC123_NO_INIT FALSE
149#endif
150
151/**
152 * @brief Enables or disables the HSI clock source.
153 */
154#if !defined(NUC123_HSI_ENABLED) || defined(__DOXYGEN__)
155#define NUC123_HSI_ENABLED TRUE
156#endif
157
158/**
159 * @brief Enables or disables the LSI clock source.
160 */
161#if !defined(NUC123_LSI_ENABLED) || defined(__DOXYGEN__)
162#define NUC123_LSI_ENABLED FALSE
163#endif
164
165/**
166 * @brief Enables or disables the HSE clock source.
167 */
168#if !defined(NUC123_HSE_ENABLED) || defined(__DOXYGEN__)
169#define NUC123_HSE_ENABLED TRUE
170#endif
171
172/**
173 * @brief Enables or disables PLL
174 */
175#if !defined(NUC123_PLL_ENABLED) || defined(__DOXYGEN__)
176#define NUC123_PLL_ENABLED TRUE
177#endif
178
179/**
180 * @brief Core clock speed.
181 */
182#if !defined(NUC123_HCLK) || defined(__DOXYGEN__)
183#if NUC123_PLL_ENABLED
184#define NUC123_HCLK 72000000UL
185#else
186#define NUC123_HCLK __HIRC
187#endif
188#endif
189
190/**
191 * @brief Enables the use of the CONFIG0/1 registers
192 */
193#if !defined(NUC123_CONFIG_ENABLED) || defined(__DOXYGEN__)
194#define NUC123_CONFIG_ENABLED FALSE
195#endif
196
197#if (NUC123_CONFIG_ENABLED == TRUE)
198/**
199 * @brief Enables or disables data flash
200 * @warning If data this is set to @p TRUE, the data flash
201 * is subtracted from the APROM. The linker script is not aware
202 * of this, so therefore it is the responsiblity of the user to ensure
203 * that the combination of the data flash & the text section still fit
204 * into ROM.
205
206 * @note The default is @p TRUE.
207 */
208#if !defined(NUC123_CONFIG_DATAFLASH_ENABLED) || defined(__DOXYGEN__)
209#define NUC123_CONFIG_DATAFLASH_ENABLED TRUE
210#endif
211
212/**
213 * @brief Sets the data flash size. This is ignored if data flash is disabled.
214 */
215#if !defined(NUC123_CONFIG_DATAFLASH_SIZE) || defined(__DOXYGEN__)
216#define NUC123_CONFIG_DATAFLASH_SIZE 4096
217#endif
218
219#endif /* NUC123_CONFIG_ENABLED == TRUE */
220
221/** @} */
222
223/*===========================================================================*/
224/* Derived constants and error checks. */
225/*===========================================================================*/
226
227/*
228 * Configuration-related checks.
229 */
230#if !defined(NUC123_MCUCONF)
231#error "Using a wrong mcuconf.h file, NUC123_MCUCONF not defined"
232#endif
233
234/*
235 * HSE checks.
236 */
237#if NUC123_HSE_ENABLED
238
239#if !defined(NUC123_HSECLK)
240#error "HSE frequency not defined"
241#elif (NUC123_HSECLK < NUC123_HSECLK_MIN) || (NUC123_HSECLK > NUC123_HSECLK_MAX)
242#error "NUC123_HSECLK outside acceptable range (NUC123_HSECLK_MIN...NUC123_HSECLK_MAX)"
243#endif
244#define NUC123_CONFIG0_HSE_PINS 0
245#else
246#define NUC123_CONFIG0_HSE_PINS NUC123_CONFIG0_CGPFMFP_Msk
247#endif
248
249#define NUC123_PLLCLK (NUC123_HCLK * 2)
250
251/*
252* Persistant configuration settings.
253*/
254
255#if (NUC123_CONFIG_ENABLED == TRUE)
256
257#if (NUC123_CONFIG_DATAFLASH_ENABLED == TRUE)
258
259#if (NUC123_CONFIG_DATAFLASH_SIZE == 4096)
260/* DFVSEN = 1, nothing else matters */
261#define NUC123_CONFIG0_DATAFLASH 0UL
262/* NUC123_DFBADDR doesn't actually control anything here, but convenient for flash drivers
263which need the starting address */
264#define NUC123_DFBADDR 0x1F000UL
265#else /* NUC123_CONFIG_DATAFLASH_SIZE != 4096 */
266/* DFVSEN = 0, DFEN = 0 */
267#define NUC123_CONFIG0_DATAFLASH (NUC123_CONFIG0_DFVSEN_Msk | NUC123_CONFIG0_DFEN_Msk)
268#define NUC123_DFBADDR ((0x11000UL - NUC123_CONFIG_DATAFLASH_SIZE) & ~(0xFFUL))
269#endif /* NUC123_CONFIG_DATAFLASH_SIZE ?= 4096 */
270#else /* NUC123_CONFIG_DATAFLASH_ENABLED == TRUE/FALSE */
271
272#undef NUC123_CONFIG_DATAFLASH_SIZE
273#define NUC123_CONFIG_DATAFLASH_SIZE 0
274/* DFVSEN = 0, DFEN = 1 */
275#define NUC123_CONFIG0_DATAFLASH NUC123_CONFIG0_DFVSEN_Msk
276#define NUC123_DFBADDR 0xFFFFFF00UL
277
278#endif /* NUC123_CONFIG_DATAFLASH_ENABLED == TRUE/FALSE */
279
280#define NUC123_CONFIG0 \
281 0xFFFFFFFFUL & (~NUC123_CONFIG0_DATAFLASH) & (~NUC123_CONFIG0_HSE_PINS)
282#define NUC123_CONFIG1 NUC123_DFBADDR
283
284#else /* NUC123_CONFIG_ENABLED == FALSE */
285
286#if defined(NUC123_CONFIG_DATAFLASH_ENABLED)
287#error \
288 "Defining NUC123_CONFIG_DATAFLASH_ENABLED requires NUC123_CONFIG_ENABLED to be TRUE"
289#endif
290
291#if defined(NUC123_CONFIG_DATAFLASH_SIZE)
292#error \
293 "Defining NUC123_CONFIG_DATAFLASH_SIZE requires NUC123_CONFIG_ENABLED to be TRUE"
294#endif
295
296#endif /* NUC123_CONFIG_ENABLED == TRUE/FALSE */
297
298/*===========================================================================*/
299/* Driver data structures and types. */
300/*===========================================================================*/
301
302/*===========================================================================*/
303/* Driver macros. */
304/*===========================================================================*/
305
306/* Alias for compatibility */
307#define SystemUnlockReg() UNLOCKREG()
308
309/*===========================================================================*/
310/* External declarations. */
311/*===========================================================================*/
312
313/* Various helpers */
314#include "NUC123.h"
315#include "nuc123_isr.h"
316#include "nuc123_registry.h"
317#include "nvic.h"
318
319#ifdef __cplusplus
320extern "C" {
321#endif
322 void hal_lld_init(void);
323 void NUC123_clock_init(void);
324#ifdef __cplusplus
325}
326#endif
327
328#endif /* _HAL_LLD_H_ */
329
330/** @} */