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