1 | /** |
---|
2 | ****************************************************************************** |
---|
3 | * @file stm32g0xx_hal.c |
---|
4 | * @author MCD Application Team |
---|
5 | * @brief HAL module driver. |
---|
6 | * This is the common part of the HAL initialization |
---|
7 | * |
---|
8 | @verbatim |
---|
9 | ============================================================================== |
---|
10 | ##### How to use this driver ##### |
---|
11 | ============================================================================== |
---|
12 | [..] |
---|
13 | The common HAL driver contains a set of generic and common APIs that can be |
---|
14 | used by the PPP peripheral drivers and the user to start using the HAL. |
---|
15 | [..] |
---|
16 | The HAL contains two APIs categories: |
---|
17 | (+) Common HAL APIs |
---|
18 | (+) Services HAL APIs |
---|
19 | |
---|
20 | @endverbatim |
---|
21 | ****************************************************************************** |
---|
22 | * @attention |
---|
23 | * |
---|
24 | * <h2><center>© Copyright (c) 2018 STMicroelectronics. |
---|
25 | * All rights reserved.</center></h2> |
---|
26 | * |
---|
27 | * This software component is licensed by ST under BSD 3-Clause license, |
---|
28 | * the "License"; You may not use this file except in compliance with the |
---|
29 | * License. You may obtain a copy of the License at: |
---|
30 | * opensource.org/licenses/BSD-3-Clause |
---|
31 | * |
---|
32 | ****************************************************************************** |
---|
33 | */ |
---|
34 | |
---|
35 | /* Includes ------------------------------------------------------------------*/ |
---|
36 | #include "stm32g0xx_hal.h" |
---|
37 | |
---|
38 | /** @addtogroup STM32G0xx_HAL_Driver |
---|
39 | * @{ |
---|
40 | */ |
---|
41 | |
---|
42 | /** @addtogroup HAL |
---|
43 | * @brief HAL module driver |
---|
44 | * @{ |
---|
45 | */ |
---|
46 | |
---|
47 | #ifdef HAL_MODULE_ENABLED |
---|
48 | |
---|
49 | /* Private typedef -----------------------------------------------------------*/ |
---|
50 | /* Private define ------------------------------------------------------------*/ |
---|
51 | |
---|
52 | /** @defgroup HAL_Private_Constants HAL Private Constants |
---|
53 | * @{ |
---|
54 | */ |
---|
55 | /** |
---|
56 | * @brief STM32G0xx HAL Driver version number |
---|
57 | */ |
---|
58 | #define __STM32G0xx_HAL_VERSION_MAIN (0x01U) /*!< [31:24] main version */ |
---|
59 | #define __STM32G0xx_HAL_VERSION_SUB1 (0x04U) /*!< [23:16] sub1 version */ |
---|
60 | #define __STM32G0xx_HAL_VERSION_SUB2 (0x01U) /*!< [15:8] sub2 version */ |
---|
61 | #define __STM32G0xx_HAL_VERSION_RC (0x00U) /*!< [7:0] release candidate */ |
---|
62 | #define __STM32G0xx_HAL_VERSION ((__STM32G0xx_HAL_VERSION_MAIN << 24U)\ |
---|
63 | |(__STM32G0xx_HAL_VERSION_SUB1 << 16U)\ |
---|
64 | |(__STM32G0xx_HAL_VERSION_SUB2 << 8U )\ |
---|
65 | |(__STM32G0xx_HAL_VERSION_RC)) |
---|
66 | |
---|
67 | #if defined(VREFBUF) |
---|
68 | #define VREFBUF_TIMEOUT_VALUE 10U /*!< 10 ms */ |
---|
69 | #endif /* VREFBUF */ |
---|
70 | |
---|
71 | /** |
---|
72 | * @} |
---|
73 | */ |
---|
74 | |
---|
75 | /* Private macro -------------------------------------------------------------*/ |
---|
76 | /* Exported variables ---------------------------------------------------------*/ |
---|
77 | /** @defgroup HAL_Exported_Variables HAL Exported Variables |
---|
78 | * @{ |
---|
79 | */ |
---|
80 | __IO uint32_t uwTick; |
---|
81 | uint32_t uwTickPrio = (1UL << __NVIC_PRIO_BITS); /* Invalid PRIO */ |
---|
82 | HAL_TickFreqTypeDef uwTickFreq = HAL_TICK_FREQ_DEFAULT; /* 1KHz */ |
---|
83 | /** |
---|
84 | * @} |
---|
85 | */ |
---|
86 | |
---|
87 | /* Private function prototypes -----------------------------------------------*/ |
---|
88 | /* Exported functions --------------------------------------------------------*/ |
---|
89 | |
---|
90 | /** @addtogroup HAL_Exported_Functions |
---|
91 | * @{ |
---|
92 | */ |
---|
93 | |
---|
94 | /** @addtogroup HAL_Exported_Functions_Group1 |
---|
95 | * @brief HAL Initialization and Configuration functions |
---|
96 | * |
---|
97 | @verbatim |
---|
98 | =============================================================================== |
---|
99 | ##### HAL Initialization and Configuration functions ##### |
---|
100 | =============================================================================== |
---|
101 | [..] This section provides functions allowing to: |
---|
102 | (+) Initialize the Flash interface the NVIC allocation and initial time base |
---|
103 | clock configuration. |
---|
104 | (+) De-initialize common part of the HAL. |
---|
105 | (+) Configure the time base source to have 1ms time base with a dedicated |
---|
106 | Tick interrupt priority. |
---|
107 | (++) SysTick timer is used by default as source of time base, but user |
---|
108 | can eventually implement his proper time base source (a general purpose |
---|
109 | timer for example or other time source), keeping in mind that Time base |
---|
110 | duration should be kept 1ms since PPP_TIMEOUT_VALUEs are defined and |
---|
111 | handled in milliseconds basis. |
---|
112 | (++) Time base configuration function (HAL_InitTick ()) is called automatically |
---|
113 | at the beginning of the program after reset by HAL_Init() or at any time |
---|
114 | when clock is configured, by HAL_RCC_ClockConfig(). |
---|
115 | (++) Source of time base is configured to generate interrupts at regular |
---|
116 | time intervals. Care must be taken if HAL_Delay() is called from a |
---|
117 | peripheral ISR process, the Tick interrupt line must have higher priority |
---|
118 | (numerically lower) than the peripheral interrupt. Otherwise the caller |
---|
119 | ISR process will be blocked. |
---|
120 | (++) functions affecting time base configurations are declared as __weak |
---|
121 | to make override possible in case of other implementations in user file. |
---|
122 | @endverbatim |
---|
123 | * @{ |
---|
124 | */ |
---|
125 | |
---|
126 | /** |
---|
127 | * @brief Configure the Flash prefetch and the Instruction cache, |
---|
128 | * the time base source, NVIC and any required global low level hardware |
---|
129 | * by calling the HAL_MspInit() callback function to be optionally defined in user file |
---|
130 | * stm32g0xx_hal_msp.c. |
---|
131 | * |
---|
132 | * @note HAL_Init() function is called at the beginning of program after reset and before |
---|
133 | * the clock configuration. |
---|
134 | * |
---|
135 | * @note In the default implementation the System Timer (Systick) is used as source of time base. |
---|
136 | * The Systick configuration is based on HSI clock, as HSI is the clock |
---|
137 | * used after a system Reset. |
---|
138 | * Once done, time base tick starts incrementing: the tick variable counter is incremented |
---|
139 | * each 1ms in the SysTick_Handler() interrupt handler. |
---|
140 | * |
---|
141 | * @retval HAL status |
---|
142 | */ |
---|
143 | HAL_StatusTypeDef HAL_Init(void) |
---|
144 | { |
---|
145 | HAL_StatusTypeDef status = HAL_OK; |
---|
146 | |
---|
147 | /* Configure Flash prefetch, Instruction cache */ |
---|
148 | /* Default configuration at reset is: */ |
---|
149 | /* - Prefetch disabled */ |
---|
150 | /* - Instruction cache enabled */ |
---|
151 | |
---|
152 | #if (INSTRUCTION_CACHE_ENABLE == 0U) |
---|
153 | __HAL_FLASH_INSTRUCTION_CACHE_DISABLE(); |
---|
154 | #endif /* INSTRUCTION_CACHE_ENABLE */ |
---|
155 | |
---|
156 | #if (PREFETCH_ENABLE != 0U) |
---|
157 | __HAL_FLASH_PREFETCH_BUFFER_ENABLE(); |
---|
158 | #endif /* PREFETCH_ENABLE */ |
---|
159 | |
---|
160 | /* Use SysTick as time base source and configure 1ms tick (default clock after Reset is HSI) */ |
---|
161 | if (HAL_InitTick(TICK_INT_PRIORITY) != HAL_OK) |
---|
162 | { |
---|
163 | status = HAL_ERROR; |
---|
164 | } |
---|
165 | else |
---|
166 | { |
---|
167 | /* Init the low level hardware */ |
---|
168 | HAL_MspInit(); |
---|
169 | } |
---|
170 | |
---|
171 | /* Return function status */ |
---|
172 | return status; |
---|
173 | } |
---|
174 | |
---|
175 | /** |
---|
176 | * @brief This function de-Initializes common part of the HAL and stops the source of time base. |
---|
177 | * @note This function is optional. |
---|
178 | * @retval HAL status |
---|
179 | */ |
---|
180 | HAL_StatusTypeDef HAL_DeInit(void) |
---|
181 | { |
---|
182 | /* Reset of all peripherals */ |
---|
183 | __HAL_RCC_APB1_FORCE_RESET(); |
---|
184 | __HAL_RCC_APB1_RELEASE_RESET(); |
---|
185 | |
---|
186 | __HAL_RCC_APB2_FORCE_RESET(); |
---|
187 | __HAL_RCC_APB2_RELEASE_RESET(); |
---|
188 | |
---|
189 | __HAL_RCC_AHB_FORCE_RESET(); |
---|
190 | __HAL_RCC_AHB_RELEASE_RESET(); |
---|
191 | |
---|
192 | __HAL_RCC_IOP_FORCE_RESET(); |
---|
193 | __HAL_RCC_IOP_RELEASE_RESET(); |
---|
194 | |
---|
195 | /* De-Init the low level hardware */ |
---|
196 | HAL_MspDeInit(); |
---|
197 | |
---|
198 | /* Return function status */ |
---|
199 | return HAL_OK; |
---|
200 | } |
---|
201 | |
---|
202 | /** |
---|
203 | * @brief Initialize the MSP. |
---|
204 | * @retval None |
---|
205 | */ |
---|
206 | __weak void HAL_MspInit(void) |
---|
207 | { |
---|
208 | /* NOTE : This function should not be modified, when the callback is needed, |
---|
209 | the HAL_MspInit could be implemented in the user file |
---|
210 | */ |
---|
211 | } |
---|
212 | |
---|
213 | /** |
---|
214 | * @brief DeInitializes the MSP. |
---|
215 | * @retval None |
---|
216 | */ |
---|
217 | __weak void HAL_MspDeInit(void) |
---|
218 | { |
---|
219 | /* NOTE : This function should not be modified, when the callback is needed, |
---|
220 | the HAL_MspDeInit could be implemented in the user file |
---|
221 | */ |
---|
222 | } |
---|
223 | |
---|
224 | /** |
---|
225 | * @brief This function configures the source of the time base: |
---|
226 | * The time source is configured to have 1ms time base with a dedicated |
---|
227 | * Tick interrupt priority. |
---|
228 | * @note This function is called automatically at the beginning of program after |
---|
229 | * reset by HAL_Init() or at any time when clock is reconfigured by HAL_RCC_ClockConfig(). |
---|
230 | * @note In the default implementation, SysTick timer is the source of time base. |
---|
231 | * It is used to generate interrupts at regular time intervals. |
---|
232 | * Care must be taken if HAL_Delay() is called from a peripheral ISR process, |
---|
233 | * The SysTick interrupt must have higher priority (numerically lower) |
---|
234 | * than the peripheral interrupt. Otherwise the caller ISR process will be blocked. |
---|
235 | * The function is declared as __weak to be overwritten in case of other |
---|
236 | * implementation in user file. |
---|
237 | * @param TickPriority Tick interrupt priority. |
---|
238 | * @retval HAL status |
---|
239 | */ |
---|
240 | __weak HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) |
---|
241 | { |
---|
242 | HAL_StatusTypeDef status = HAL_OK; |
---|
243 | |
---|
244 | /* Check uwTickFreq for MisraC 2012 (even if uwTickFreq is a enum type that doesn't take the value zero)*/ |
---|
245 | if ((uint32_t)uwTickFreq != 0U) |
---|
246 | { |
---|
247 | /*Configure the SysTick to have interrupt in 1ms time basis*/ |
---|
248 | if (HAL_SYSTICK_Config(SystemCoreClock / (1000U /(uint32_t)uwTickFreq)) == 0U) |
---|
249 | { |
---|
250 | /* Configure the SysTick IRQ priority */ |
---|
251 | if (TickPriority < (1UL << __NVIC_PRIO_BITS)) |
---|
252 | { |
---|
253 | HAL_NVIC_SetPriority(SysTick_IRQn, TickPriority, 0U); |
---|
254 | uwTickPrio = TickPriority; |
---|
255 | } |
---|
256 | else |
---|
257 | { |
---|
258 | status = HAL_ERROR; |
---|
259 | } |
---|
260 | } |
---|
261 | else |
---|
262 | { |
---|
263 | status = HAL_ERROR; |
---|
264 | } |
---|
265 | } |
---|
266 | else |
---|
267 | { |
---|
268 | status = HAL_ERROR; |
---|
269 | } |
---|
270 | |
---|
271 | /* Return function status */ |
---|
272 | return status; |
---|
273 | } |
---|
274 | |
---|
275 | /** |
---|
276 | * @} |
---|
277 | */ |
---|
278 | |
---|
279 | /** @addtogroup HAL_Exported_Functions_Group2 |
---|
280 | * @brief HAL Control functions |
---|
281 | * |
---|
282 | @verbatim |
---|
283 | =============================================================================== |
---|
284 | ##### HAL Control functions ##### |
---|
285 | =============================================================================== |
---|
286 | [..] This section provides functions allowing to: |
---|
287 | (+) Provide a tick value in millisecond |
---|
288 | (+) Provide a blocking delay in millisecond |
---|
289 | (+) Suspend the time base source interrupt |
---|
290 | (+) Resume the time base source interrupt |
---|
291 | (+) Get the HAL API driver version |
---|
292 | (+) Get the device identifier |
---|
293 | (+) Get the device revision identifier |
---|
294 | |
---|
295 | @endverbatim |
---|
296 | * @{ |
---|
297 | */ |
---|
298 | |
---|
299 | /** |
---|
300 | * @brief This function is called to increment a global variable "uwTick" |
---|
301 | * used as application time base. |
---|
302 | * @note In the default implementation, this variable is incremented each 1ms |
---|
303 | * in SysTick ISR. |
---|
304 | * @note This function is declared as __weak to be overwritten in case of other |
---|
305 | * implementations in user file. |
---|
306 | * @retval None |
---|
307 | */ |
---|
308 | __weak void HAL_IncTick(void) |
---|
309 | { |
---|
310 | uwTick += (uint32_t)uwTickFreq; |
---|
311 | } |
---|
312 | |
---|
313 | /** |
---|
314 | * @brief Provides a tick value in millisecond. |
---|
315 | * @note This function is declared as __weak to be overwritten in case of other |
---|
316 | * implementations in user file. |
---|
317 | * @retval tick value |
---|
318 | */ |
---|
319 | __weak uint32_t HAL_GetTick(void) |
---|
320 | { |
---|
321 | return uwTick; |
---|
322 | } |
---|
323 | |
---|
324 | /** |
---|
325 | * @brief This function returns a tick priority. |
---|
326 | * @retval tick priority |
---|
327 | */ |
---|
328 | uint32_t HAL_GetTickPrio(void) |
---|
329 | { |
---|
330 | return uwTickPrio; |
---|
331 | } |
---|
332 | |
---|
333 | /** |
---|
334 | * @brief Set new tick Freq. |
---|
335 | * @retval status |
---|
336 | */ |
---|
337 | HAL_StatusTypeDef HAL_SetTickFreq(HAL_TickFreqTypeDef Freq) |
---|
338 | { |
---|
339 | HAL_StatusTypeDef status = HAL_OK; |
---|
340 | HAL_TickFreqTypeDef prevTickFreq; |
---|
341 | assert_param(IS_TICKFREQ(Freq)); |
---|
342 | |
---|
343 | if (uwTickFreq != Freq) |
---|
344 | { |
---|
345 | /* Back up uwTickFreq frequency */ |
---|
346 | prevTickFreq = uwTickFreq; |
---|
347 | |
---|
348 | /* Update uwTickFreq global variable used by HAL_InitTick() */ |
---|
349 | uwTickFreq = Freq; |
---|
350 | |
---|
351 | /* Apply the new tick Freq */ |
---|
352 | status = HAL_InitTick(uwTickPrio); |
---|
353 | if (status != HAL_OK) |
---|
354 | { |
---|
355 | /* Restore previous tick frequency */ |
---|
356 | uwTickFreq = prevTickFreq; |
---|
357 | } |
---|
358 | } |
---|
359 | |
---|
360 | return status; |
---|
361 | } |
---|
362 | |
---|
363 | /** |
---|
364 | * @brief return tick frequency. |
---|
365 | * @retval tick period in Hz |
---|
366 | */ |
---|
367 | HAL_TickFreqTypeDef HAL_GetTickFreq(void) |
---|
368 | { |
---|
369 | return uwTickFreq; |
---|
370 | } |
---|
371 | |
---|
372 | /** |
---|
373 | * @brief This function provides minimum delay (in milliseconds) based |
---|
374 | * on variable incremented. |
---|
375 | * @note In the default implementation , SysTick timer is the source of time base. |
---|
376 | * It is used to generate interrupts at regular time intervals where uwTick |
---|
377 | * is incremented. |
---|
378 | * @note This function is declared as __weak to be overwritten in case of other |
---|
379 | * implementations in user file. |
---|
380 | * @param Delay specifies the delay time length, in milliseconds. |
---|
381 | * @retval None |
---|
382 | */ |
---|
383 | __weak void HAL_Delay(uint32_t Delay) |
---|
384 | { |
---|
385 | uint32_t tickstart = HAL_GetTick(); |
---|
386 | uint32_t wait = Delay; |
---|
387 | |
---|
388 | /* Add a freq to guarantee minimum wait */ |
---|
389 | if (wait < HAL_MAX_DELAY) |
---|
390 | { |
---|
391 | wait += (uint32_t)(uwTickFreq); |
---|
392 | } |
---|
393 | |
---|
394 | while ((HAL_GetTick() - tickstart) < wait) |
---|
395 | { |
---|
396 | } |
---|
397 | } |
---|
398 | |
---|
399 | /** |
---|
400 | * @brief Suspend Tick increment. |
---|
401 | * @note In the default implementation , SysTick timer is the source of time base. It is |
---|
402 | * used to generate interrupts at regular time intervals. Once HAL_SuspendTick() |
---|
403 | * is called, the SysTick interrupt will be disabled and so Tick increment |
---|
404 | * is suspended. |
---|
405 | * @note This function is declared as __weak to be overwritten in case of other |
---|
406 | * implementations in user file. |
---|
407 | * @retval None |
---|
408 | */ |
---|
409 | __weak void HAL_SuspendTick(void) |
---|
410 | { |
---|
411 | /* Disable SysTick Interrupt */ |
---|
412 | CLEAR_BIT(SysTick->CTRL,SysTick_CTRL_TICKINT_Msk); |
---|
413 | } |
---|
414 | |
---|
415 | /** |
---|
416 | * @brief Resume Tick increment. |
---|
417 | * @note In the default implementation , SysTick timer is the source of time base. It is |
---|
418 | * used to generate interrupts at regular time intervals. Once HAL_ResumeTick() |
---|
419 | * is called, the SysTick interrupt will be enabled and so Tick increment |
---|
420 | * is resumed. |
---|
421 | * @note This function is declared as __weak to be overwritten in case of other |
---|
422 | * implementations in user file. |
---|
423 | * @retval None |
---|
424 | */ |
---|
425 | __weak void HAL_ResumeTick(void) |
---|
426 | { |
---|
427 | /* Enable SysTick Interrupt */ |
---|
428 | SET_BIT(SysTick->CTRL, SysTick_CTRL_TICKINT_Msk); |
---|
429 | } |
---|
430 | |
---|
431 | /** |
---|
432 | * @brief Returns the HAL revision |
---|
433 | * @retval version : 0xXYZR (8bits for each decimal, R for RC) |
---|
434 | */ |
---|
435 | uint32_t HAL_GetHalVersion(void) |
---|
436 | { |
---|
437 | return __STM32G0xx_HAL_VERSION; |
---|
438 | } |
---|
439 | |
---|
440 | /** |
---|
441 | * @brief Returns the device revision identifier. |
---|
442 | * @retval Device revision identifier |
---|
443 | */ |
---|
444 | uint32_t HAL_GetREVID(void) |
---|
445 | { |
---|
446 | return ((DBG->IDCODE & DBG_IDCODE_REV_ID) >> 16U); |
---|
447 | } |
---|
448 | |
---|
449 | /** |
---|
450 | * @brief Returns the device identifier. |
---|
451 | * @retval Device identifier |
---|
452 | */ |
---|
453 | uint32_t HAL_GetDEVID(void) |
---|
454 | { |
---|
455 | return ((DBG->IDCODE) & DBG_IDCODE_DEV_ID); |
---|
456 | } |
---|
457 | |
---|
458 | /** |
---|
459 | * @brief Returns first word of the unique device identifier (UID based on 96 bits) |
---|
460 | * @retval Device identifier |
---|
461 | */ |
---|
462 | uint32_t HAL_GetUIDw0(void) |
---|
463 | { |
---|
464 | return (READ_REG(*((uint32_t *)UID_BASE))); |
---|
465 | } |
---|
466 | |
---|
467 | /** |
---|
468 | * @brief Returns second word of the unique device identifier (UID based on 96 bits) |
---|
469 | * @retval Device identifier |
---|
470 | */ |
---|
471 | uint32_t HAL_GetUIDw1(void) |
---|
472 | { |
---|
473 | return (READ_REG(*((uint32_t *)(UID_BASE + 4U)))); |
---|
474 | } |
---|
475 | |
---|
476 | /** |
---|
477 | * @brief Returns third word of the unique device identifier (UID based on 96 bits) |
---|
478 | * @retval Device identifier |
---|
479 | */ |
---|
480 | uint32_t HAL_GetUIDw2(void) |
---|
481 | { |
---|
482 | return (READ_REG(*((uint32_t *)(UID_BASE + 8U)))); |
---|
483 | } |
---|
484 | |
---|
485 | /** |
---|
486 | * @} |
---|
487 | */ |
---|
488 | |
---|
489 | /** @addtogroup HAL_Exported_Functions_Group3 |
---|
490 | * @brief HAL Debug functions |
---|
491 | * |
---|
492 | @verbatim |
---|
493 | =============================================================================== |
---|
494 | ##### HAL Debug functions ##### |
---|
495 | =============================================================================== |
---|
496 | [..] This section provides functions allowing to: |
---|
497 | (+) Enable/Disable Debug module during STOP mode |
---|
498 | (+) Enable/Disable Debug module during STANDBY mode |
---|
499 | |
---|
500 | @endverbatim |
---|
501 | * @{ |
---|
502 | */ |
---|
503 | |
---|
504 | /** |
---|
505 | * @brief Enable the Debug Module during STOP mode |
---|
506 | * @retval None |
---|
507 | */ |
---|
508 | void HAL_DBGMCU_EnableDBGStopMode(void) |
---|
509 | { |
---|
510 | SET_BIT(DBG->CR, DBG_CR_DBG_STOP); |
---|
511 | } |
---|
512 | |
---|
513 | /** |
---|
514 | * @brief Disable the Debug Module during STOP mode |
---|
515 | * @retval None |
---|
516 | */ |
---|
517 | void HAL_DBGMCU_DisableDBGStopMode(void) |
---|
518 | { |
---|
519 | CLEAR_BIT(DBG->CR, DBG_CR_DBG_STOP); |
---|
520 | } |
---|
521 | |
---|
522 | /** |
---|
523 | * @brief Enable the Debug Module during STANDBY mode |
---|
524 | * @retval None |
---|
525 | */ |
---|
526 | void HAL_DBGMCU_EnableDBGStandbyMode(void) |
---|
527 | { |
---|
528 | SET_BIT(DBG->CR, DBG_CR_DBG_STANDBY); |
---|
529 | } |
---|
530 | |
---|
531 | /** |
---|
532 | * @brief Disable the Debug Module during STANDBY mode |
---|
533 | * @retval None |
---|
534 | */ |
---|
535 | void HAL_DBGMCU_DisableDBGStandbyMode(void) |
---|
536 | { |
---|
537 | CLEAR_BIT(DBG->CR, DBG_CR_DBG_STANDBY); |
---|
538 | } |
---|
539 | |
---|
540 | /** |
---|
541 | * @} |
---|
542 | */ |
---|
543 | |
---|
544 | /** @addtogroup HAL_Exported_Functions_Group4 |
---|
545 | * @brief SYSCFG configuration functions |
---|
546 | * |
---|
547 | @verbatim |
---|
548 | =============================================================================== |
---|
549 | ##### HAL SYSCFG configuration functions ##### |
---|
550 | =============================================================================== |
---|
551 | [..] This section provides functions allowing to: |
---|
552 | (+) Enable/Disable Pin remap |
---|
553 | (+) Configure the Voltage reference buffer |
---|
554 | (+) Enable/Disable the Voltage reference buffer |
---|
555 | (+) Enable/Disable the I/O analog switch voltage booster |
---|
556 | (+) Enable/Disable dead battery behavior(*) |
---|
557 | (+) Configure Clamping Diode on specific pins(*) |
---|
558 | (*) Feature not available on all devices |
---|
559 | |
---|
560 | @endverbatim |
---|
561 | * @{ |
---|
562 | */ |
---|
563 | #if defined(VREFBUF) |
---|
564 | /** |
---|
565 | * @brief Configure the internal voltage reference buffer voltage scale. |
---|
566 | * @param VoltageScaling specifies the output voltage to achieve |
---|
567 | * This parameter can be one of the following values: |
---|
568 | * @arg @ref SYSCFG_VREFBUF_VoltageScale |
---|
569 | * @retval None |
---|
570 | */ |
---|
571 | void HAL_SYSCFG_VREFBUF_VoltageScalingConfig(uint32_t VoltageScaling) |
---|
572 | { |
---|
573 | /* Check the parameters */ |
---|
574 | assert_param(IS_SYSCFG_VREFBUF_VOLTAGE_SCALE(VoltageScaling)); |
---|
575 | |
---|
576 | MODIFY_REG(VREFBUF->CSR, VREFBUF_CSR_VRS, VoltageScaling); |
---|
577 | } |
---|
578 | |
---|
579 | /** |
---|
580 | * @brief Configure the internal voltage reference buffer high impedance mode. |
---|
581 | * @param Mode specifies the high impedance mode |
---|
582 | * This parameter can be one of the following values: |
---|
583 | * @arg @ref SYSCFG_VREFBUF_HighImpedance |
---|
584 | * @retval None |
---|
585 | */ |
---|
586 | void HAL_SYSCFG_VREFBUF_HighImpedanceConfig(uint32_t Mode) |
---|
587 | { |
---|
588 | /* Check the parameters */ |
---|
589 | assert_param(IS_SYSCFG_VREFBUF_HIGH_IMPEDANCE(Mode)); |
---|
590 | |
---|
591 | MODIFY_REG(VREFBUF->CSR, VREFBUF_CSR_HIZ, Mode); |
---|
592 | } |
---|
593 | |
---|
594 | /** |
---|
595 | * @brief Tune the Internal Voltage Reference buffer (VREFBUF). |
---|
596 | * @note VrefBuf voltage scale is calibrated in production for each device, |
---|
597 | * using voltage scale 1. This calibration value is loaded |
---|
598 | * as default trimming value at device power up. |
---|
599 | * This trimming value can be fine tuned for voltage scales 0 and 1 |
---|
600 | * using this function. |
---|
601 | * @retval None |
---|
602 | */ |
---|
603 | void HAL_SYSCFG_VREFBUF_TrimmingConfig(uint32_t TrimmingValue) |
---|
604 | { |
---|
605 | /* Check the parameters */ |
---|
606 | assert_param(IS_SYSCFG_VREFBUF_TRIMMING(TrimmingValue)); |
---|
607 | |
---|
608 | MODIFY_REG(VREFBUF->CCR, VREFBUF_CCR_TRIM, TrimmingValue); |
---|
609 | } |
---|
610 | |
---|
611 | /** |
---|
612 | * @brief Enable the Internal Voltage Reference buffer (VREFBUF). |
---|
613 | * @retval HAL_OK/HAL_TIMEOUT |
---|
614 | */ |
---|
615 | HAL_StatusTypeDef HAL_SYSCFG_EnableVREFBUF(void) |
---|
616 | { |
---|
617 | uint32_t tickstart; |
---|
618 | |
---|
619 | SET_BIT(VREFBUF->CSR, VREFBUF_CSR_ENVR); |
---|
620 | |
---|
621 | /* Get Start Tick*/ |
---|
622 | tickstart = HAL_GetTick(); |
---|
623 | |
---|
624 | /* Wait for VRR bit */ |
---|
625 | while (READ_BIT(VREFBUF->CSR, VREFBUF_CSR_VRR) == 0x00U) |
---|
626 | { |
---|
627 | if ((HAL_GetTick() - tickstart) > VREFBUF_TIMEOUT_VALUE) |
---|
628 | { |
---|
629 | return HAL_TIMEOUT; |
---|
630 | } |
---|
631 | } |
---|
632 | |
---|
633 | return HAL_OK; |
---|
634 | } |
---|
635 | |
---|
636 | /** |
---|
637 | * @brief Disable the Internal Voltage Reference buffer (VREFBUF). |
---|
638 | * |
---|
639 | * @retval None |
---|
640 | */ |
---|
641 | void HAL_SYSCFG_DisableVREFBUF(void) |
---|
642 | { |
---|
643 | CLEAR_BIT(VREFBUF->CSR, VREFBUF_CSR_ENVR); |
---|
644 | } |
---|
645 | #endif /* VREFBUF */ |
---|
646 | |
---|
647 | /** |
---|
648 | * @brief Enable the I/O analog switch voltage booster |
---|
649 | * @retval None |
---|
650 | */ |
---|
651 | void HAL_SYSCFG_EnableIOAnalogSwitchBooster(void) |
---|
652 | { |
---|
653 | SET_BIT(SYSCFG->CFGR1, SYSCFG_CFGR1_BOOSTEN); |
---|
654 | } |
---|
655 | |
---|
656 | /** |
---|
657 | * @brief Disable the I/O analog switch voltage booster |
---|
658 | * @retval None |
---|
659 | */ |
---|
660 | void HAL_SYSCFG_DisableIOAnalogSwitchBooster(void) |
---|
661 | { |
---|
662 | CLEAR_BIT(SYSCFG->CFGR1, SYSCFG_CFGR1_BOOSTEN); |
---|
663 | } |
---|
664 | |
---|
665 | /** |
---|
666 | * @brief Enable the remap on PA11_PA12 |
---|
667 | * @param PinRemap specifies which pins have to be remapped |
---|
668 | * This parameter can be any combination of the following values: |
---|
669 | * @arg @ref SYSCFG_REMAP_PA11 |
---|
670 | * @arg @ref SYSCFG_REMAP_PA12 |
---|
671 | * @retval None |
---|
672 | */ |
---|
673 | void HAL_SYSCFG_EnableRemap(uint32_t PinRemap) |
---|
674 | { |
---|
675 | /* Check the parameter */ |
---|
676 | assert_param(IS_HAL_REMAP_PIN(PinRemap)); |
---|
677 | SET_BIT(SYSCFG->CFGR1, PinRemap); |
---|
678 | } |
---|
679 | |
---|
680 | /** |
---|
681 | * @brief Disable the remap on PA11_PA12 |
---|
682 | * @param PinRemap specifies which pins will behave normally |
---|
683 | * This parameter can be any combination of the following values: |
---|
684 | * @arg @ref SYSCFG_REMAP_PA11 |
---|
685 | * @arg @ref SYSCFG_REMAP_PA12 |
---|
686 | * @retval None |
---|
687 | */ |
---|
688 | void HAL_SYSCFG_DisableRemap(uint32_t PinRemap) |
---|
689 | { |
---|
690 | /* Check the parameter */ |
---|
691 | assert_param(IS_HAL_REMAP_PIN(PinRemap)); |
---|
692 | CLEAR_BIT(SYSCFG->CFGR1, PinRemap); |
---|
693 | } |
---|
694 | |
---|
695 | #if defined(SYSCFG_CDEN_SUPPORT) |
---|
696 | /** |
---|
697 | * @brief Enable Clamping Diode on specified IO |
---|
698 | * @param PinConfig specifies on which pins clamping Diode has to be enabled |
---|
699 | * This parameter can be any combination of the following values: |
---|
700 | * @arg @ref SYSCFG_ClampingDiode |
---|
701 | * @retval None |
---|
702 | */ |
---|
703 | void HAL_SYSCFG_EnableClampingDiode(uint32_t PinConfig) |
---|
704 | { |
---|
705 | /* Check the parameter */ |
---|
706 | assert_param(IS_SYSCFG_CLAMPINGDIODE(PinConfig)); |
---|
707 | SET_BIT(SYSCFG->CFGR2, PinConfig); |
---|
708 | } |
---|
709 | |
---|
710 | /** |
---|
711 | * @brief Disable Clamping Diode on specified IO |
---|
712 | * @param PinConfig specifies on which pins clamping Diode has to be disabled |
---|
713 | * This parameter can be any combination of the following values: |
---|
714 | * @arg @ref SYSCFG_ClampingDiode |
---|
715 | * @retval None |
---|
716 | */ |
---|
717 | void HAL_SYSCFG_DisableClampingDiode(uint32_t PinConfig) |
---|
718 | { |
---|
719 | /* Check the parameter */ |
---|
720 | assert_param(IS_SYSCFG_CLAMPINGDIODE(PinConfig)); |
---|
721 | CLEAR_BIT(SYSCFG->CFGR2, PinConfig); |
---|
722 | } |
---|
723 | #endif /* SYSCFG_CDEN_SUPPORT */ |
---|
724 | |
---|
725 | #if defined (SYSCFG_CFGR1_UCPD1_STROBE) || defined (SYSCFG_CFGR1_UCPD2_STROBE) |
---|
726 | /** |
---|
727 | * @brief Strobe configuration of GPIO depending on UCPDx dead battery settings |
---|
728 | * @param ConfigDeadBattery specifies on which pins to make effective or not Dead Battery sw configuration |
---|
729 | * This parameter can be any combination of the following values: |
---|
730 | * @arg @ref SYSCFG_UCPD1_STROBE |
---|
731 | * @arg @ref SYSCFG_UCPD2_STROBE |
---|
732 | * @retval None |
---|
733 | */ |
---|
734 | void HAL_SYSCFG_StrobeDBattpinsConfig(uint32_t ConfigDeadBattery) |
---|
735 | { |
---|
736 | assert_param(IS_SYSCFG_DBATT_CONFIG(ConfigDeadBattery)); |
---|
737 | |
---|
738 | /* Change strobe configuration of GPIO depending on UCPDx dead battery settings */ |
---|
739 | MODIFY_REG(SYSCFG->CFGR1, (SYSCFG_CFGR1_UCPD1_STROBE | SYSCFG_CFGR1_UCPD2_STROBE), ConfigDeadBattery); |
---|
740 | } |
---|
741 | #endif /* SYSCFG_CFGR1_UCPD1_STROBE || SYSCFG_CFGR1_UCPD2_STROBE */ |
---|
742 | /** |
---|
743 | * @} |
---|
744 | */ |
---|
745 | |
---|
746 | /** |
---|
747 | * @} |
---|
748 | */ |
---|
749 | |
---|
750 | #endif /* HAL_MODULE_ENABLED */ |
---|
751 | /** |
---|
752 | * @} |
---|
753 | */ |
---|
754 | |
---|
755 | /** |
---|
756 | * @} |
---|
757 | */ |
---|
758 | |
---|
759 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
---|