1 /**
2 ******************************************************************************
3 * @file stm32u5xx_hal.c
4 * @author MCD Application Team
5 * @brief HAL module driver.
6 * This is the common part of the HAL initialization
7 *
8 ******************************************************************************
9 * @attention
10 *
11 * Copyright (c) 2021 STMicroelectronics.
12 * All rights reserved.
13 *
14 * This software component is licensed by ST under BSD 3-Clause license,
15 * the "License"; You may not use this file except in compliance with the
16 * License. You may obtain a copy of the License at:
17 * opensource.org/licenses/BSD-3-Clause
18 *
19 ******************************************************************************
20
21 @verbatim
22 ==============================================================================
23 ##### How to use this driver #####
24 ==============================================================================
25 [..]
26 The common HAL driver contains a set of generic and common APIs that can be
27 used by the PPP peripheral drivers and the user to start using the HAL.
28 [..]
29 The HAL contains two APIs' categories:
30 (+) Common HAL APIs
31 (+) Services HAL APIs
32
33 @endverbatim
34 ******************************************************************************
35 */
36
37 /* Includes ------------------------------------------------------------------*/
38 #include "stm32u5xx_hal.h"
39
40 /** @addtogroup STM32U5xx_HAL_Driver
41 * @{
42 */
43
44 /** @defgroup HAL HAL
45 * @brief HAL module driver
46 * @{
47 */
48
49 #ifdef HAL_MODULE_ENABLED
50
51 /* Private typedef -----------------------------------------------------------*/
52 /* Private define ------------------------------------------------------------*/
53 /** @defgroup HAL_Private_Defines HAL Private Defines
54 * @{
55 */
56 /**
57 * @brief STM32U5xx HAL Driver version number 1.0.0
58 */
59 #define __STM32U5xx_HAL_VERSION_MAIN (0x01U) /*!< [31:24] main version */
60 #define __STM32U5xx_HAL_VERSION_SUB1 (0x00U) /*!< [23:16] sub1 version */
61 #define __STM32U5xx_HAL_VERSION_SUB2 (0x00U) /*!< [15:8] sub2 version */
62 #define __STM32U5xx_HAL_VERSION_RC (0x00U) /*!< [7:0] release candidate */
63 #define __STM32U5xx_HAL_VERSION ((__STM32U5xx_HAL_VERSION_MAIN << 24U)\
64 |(__STM32U5xx_HAL_VERSION_SUB1 << 16U)\
65 |(__STM32U5xx_HAL_VERSION_SUB2 << 8U )\
66 |(__STM32U5xx_HAL_VERSION_RC))
67
68 #define VREFBUF_TIMEOUT_VALUE 10U /* 10 ms (to be confirmed) */
69 /**
70 * @}
71 */
72 /* Private macro -------------------------------------------------------------*/
73 /* Private variables ---------------------------------------------------------*/
74 /* Exported variables --------------------------------------------------------*/
75
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 HAL_TickFreqTypeDef uwTickFreq = HAL_TICK_FREQ_DEFAULT; /* 1KHz */
82 /**
83 * @}
84 */
85
86 /* Private function prototypes -----------------------------------------------*/
87 /* Exported functions --------------------------------------------------------*/
88
89 /** @defgroup HAL_Exported_Functions HAL Exported Functions
90 * @{
91 */
92
93 /** @defgroup HAL_Exported_Functions_Group1 Initialization and de-initialization Functions
94 * @brief Initialization and de-initialization functions
95 *
96 @verbatim
97 ===============================================================================
98 ##### Initialization and de-initialization functions #####
99 ===============================================================================
100 [..] This section provides functions allowing to:
101 (+) Initializes the Flash interface the NVIC allocation and initial clock
102 configuration. It initializes the systick also when timeout is needed
103 and the backup domain when enabled.
104 (+) De-Initializes 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, the time base source, NVIC and any required global low
128 * level hardware by calling the HAL_MspInit() callback function to be optionally defined
129 * in user file stm32u5xx_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 MSI clock, as MSI is the clock
136 * used after a system Reset and the NVIC configuration is set to Priority group 4.
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 /* Configure Flash prefetch */
145 #if (PREFETCH_ENABLE != 0U)
146 __HAL_FLASH_PREFETCH_BUFFER_ENABLE();
147 #endif /* PREFETCH_ENABLE */
148
149 /* Set Interrupt Group Priority */
150 HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_4);
151
152 /* Update the SystemCoreClock global variable */
153 SystemCoreClock = HAL_RCC_GetSysClockFreq() >> AHBPrescTable[(RCC->CFGR2 & RCC_CFGR2_HPRE) >> RCC_CFGR2_HPRE_Pos];
154
155 /* Use systick as time base source and configure 1ms tick (default clock after Reset is HSI) */
156 if (HAL_InitTick(TICK_INT_PRIORITY) != HAL_OK)
157 {
158 return HAL_ERROR;
159 }
160
161 /* Init the low level hardware */
162 HAL_MspInit();
163
164 /* Return function status */
165 return HAL_OK;
166 }
167
168 /**
169 * @brief This function de-Initializes common part of the HAL and stops the systick.
170 * This function is optional.
171 * @retval HAL status
172 */
HAL_DeInit(void)173 HAL_StatusTypeDef HAL_DeInit(void)
174 {
175 /* Reset of all peripherals */
176 __HAL_RCC_APB1_FORCE_RESET();
177 __HAL_RCC_APB1_RELEASE_RESET();
178
179 __HAL_RCC_APB2_FORCE_RESET();
180 __HAL_RCC_APB2_RELEASE_RESET();
181
182 __HAL_RCC_AHB1_FORCE_RESET();
183 __HAL_RCC_AHB1_RELEASE_RESET();
184
185 __HAL_RCC_AHB2_FORCE_RESET();
186 __HAL_RCC_AHB2_RELEASE_RESET();
187
188 __HAL_RCC_AHB3_FORCE_RESET();
189 __HAL_RCC_AHB3_RELEASE_RESET();
190
191 /* De-Init the low level hardware */
192 HAL_MspDeInit();
193
194 /* Return function status */
195 return HAL_OK;
196 }
197
198 /**
199 * @brief Initializes the MSP.
200 * @retval None
201 */
HAL_MspInit(void)202 __weak void HAL_MspInit(void)
203 {
204 /* NOTE : This function Should not be modified, when the callback is needed,
205 the HAL_MspInit could be implemented in the user file
206 */
207 }
208
209 /**
210 * @brief DeInitializes the MSP.
211 * @retval None
212 */
HAL_MspDeInit(void)213 __weak void HAL_MspDeInit(void)
214 {
215 /* NOTE : This function Should not be modified, when the callback is needed,
216 the HAL_MspDeInit could be implemented in the user file
217 */
218 }
219
220 /**
221 * @brief This function configures the source of the time base.
222 * The time source is configured to have 1ms time base with a dedicated
223 * Tick interrupt priority.
224 * @note This function is called automatically at the beginning of program after
225 * reset by HAL_Init() or at any time when clock is reconfigured by HAL_RCC_ClockConfig().
226 * @note In the default implementation, SysTick timer is the source of time base.
227 * It is used to generate interrupts at regular time intervals.
228 * Care must be taken if HAL_Delay() is called from a peripheral ISR process,
229 * The SysTick interrupt must have higher priority (numerically lower)
230 * than the peripheral interrupt. Otherwise the caller ISR process will be blocked.
231 * The function is declared as __weak to be overwritten in case of other
232 * implementation in user file.
233 * @param TickPriority: Tick interrupt priority.
234 * @retval HAL status
235 */
HAL_InitTick(uint32_t TickPriority)236 __weak HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority)
237 {
238 /* Check uwTickFreq for MisraC 2012 (even if uwTickFreq is a enum type that don't take the value zero)*/
239 if ((uint32_t)uwTickFreq == 0UL)
240 {
241 return HAL_ERROR;
242 }
243
244 /* Configure the SysTick to have interrupt in 1ms time basis*/
245 if (HAL_SYSTICK_Config(SystemCoreClock / (1000UL / (uint32_t)uwTickFreq)) > 0U)
246 {
247 return HAL_ERROR;
248 }
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 return HAL_ERROR;
259 }
260
261 /* Return function status */
262 return HAL_OK;
263 }
264
265 /**
266 * @}
267 */
268
269 /** @defgroup HAL_Group2 HAL Control functions
270 * @brief HAL Control functions
271 *
272 @verbatim
273 ===============================================================================
274 ##### HAL Control functions #####
275 ===============================================================================
276 [..] This section provides functions allowing to:
277 (+) Provide a tick value in millisecond
278 (+) Provide a blocking delay in millisecond
279 (+) Suspend the time base source interrupt
280 (+) Resume the time base source interrupt
281 (+) Get the HAL API driver version
282 (+) Get the device identifier
283 (+) Get the device revision identifier
284 (+) Enable/Disable Debug module during SLEEP mode
285 (+) Enable/Disable Debug module during STOP mode
286 (+) Enable/Disable Debug module during STANDBY mode
287
288 @endverbatim
289 * @{
290 */
291
292 /**
293 * @brief This function is called to increment a global variable "uwTick"
294 * used as application time base.
295 * @note In the default implementation, this variable is incremented each 1ms
296 * in Systick ISR.
297 * @note This function is declared as __weak to be overwritten in case of other
298 * implementations in user file.
299 * @retval None
300 */
HAL_IncTick(void)301 __weak void HAL_IncTick(void)
302 {
303 uwTick += (uint32_t)uwTickFreq;
304 }
305
306 /**
307 * @brief Provides a tick value in millisecond.
308 * @note This function is declared as __weak to be overwritten in case of other
309 * implementations in user file.
310 * @retval tick value
311 */
HAL_GetTick(void)312 __weak uint32_t HAL_GetTick(void)
313 {
314 return uwTick;
315 }
316
317 /**
318 * @brief This function returns a tick priority.
319 * @retval tick priority
320 */
HAL_GetTickPrio(void)321 uint32_t HAL_GetTickPrio(void)
322 {
323 return uwTickPrio;
324 }
325
326 /**
327 * @brief Set new tick Freq.
328 * @retval Status
329 */
HAL_SetTickFreq(HAL_TickFreqTypeDef Freq)330 HAL_StatusTypeDef HAL_SetTickFreq(HAL_TickFreqTypeDef Freq)
331 {
332 HAL_StatusTypeDef status = HAL_OK;
333 assert_param(IS_TICKFREQ(Freq));
334
335 if (uwTickFreq != Freq)
336 {
337 /* Apply the new tick Freq */
338 status = HAL_InitTick(uwTickPrio);
339
340 if (status == HAL_OK)
341 {
342 uwTickFreq = Freq;
343 }
344 }
345
346 return status;
347 }
348
349 /**
350 * @brief Return tick frequency.
351 * @retval tick period in Hz
352 */
HAL_GetTickFreq(void)353 HAL_TickFreqTypeDef HAL_GetTickFreq(void)
354 {
355 return uwTickFreq;
356 }
357
358 /**
359 * @brief This function provides minimum delay (in milliseconds) based
360 * on variable incremented.
361 * @note In the default implementation , SysTick timer is the source of time base.
362 * It is used to generate interrupts at regular time intervals where uwTick
363 * is incremented.
364 * @note This function is declared as __weak to be overwritten in case of other
365 * implementations in user file.
366 * @param Delay specifies the delay time length, in milliseconds.
367 * @retval None
368 */
HAL_Delay(uint32_t Delay)369 __weak void HAL_Delay(uint32_t Delay)
370 {
371 uint32_t tickstart = HAL_GetTick();
372 uint32_t wait = Delay;
373
374 /* Add a freq to guarantee minimum wait */
375 if (wait < HAL_MAX_DELAY)
376 {
377 wait += (uint32_t)(uwTickFreq);
378 }
379
380 while ((HAL_GetTick() - tickstart) < wait)
381 {
382 }
383 }
384
385 /**
386 * @brief Suspend Tick increment.
387 * @note In the default implementation , SysTick timer is the source of time base. It is
388 * used to generate interrupts at regular time intervals. Once HAL_SuspendTick()
389 * is called, the SysTick interrupt will be disabled and so Tick increment
390 * is suspended.
391 * @note This function is declared as __weak to be overwritten in case of other
392 * implementations in user file.
393 * @retval None
394 */
HAL_SuspendTick(void)395 __weak void HAL_SuspendTick(void)
396 {
397 /* Disable SysTick Interrupt */
398 SysTick->CTRL &= ~SysTick_CTRL_TICKINT_Msk;
399 }
400
401 /**
402 * @brief Resume Tick increment.
403 * @note In the default implementation , SysTick timer is the source of time base. It is
404 * used to generate interrupts at regular time intervals. Once HAL_ResumeTick()
405 * is called, the SysTick interrupt will be enabled and so Tick increment
406 * is resumed.
407 * @note This function is declared as __weak to be overwritten in case of other
408 * implementations in user file.
409 * @retval None
410 */
HAL_ResumeTick(void)411 __weak void HAL_ResumeTick(void)
412 {
413 /* Enable SysTick Interrupt */
414 SysTick->CTRL |= SysTick_CTRL_TICKINT_Msk;
415 }
416
417 /**
418 * @brief Returns the HAL revision
419 * @retval version : 0xXYZR (8bits for each decimal, R for RC)
420 */
HAL_GetHalVersion(void)421 uint32_t HAL_GetHalVersion(void)
422 {
423 return __STM32U5xx_HAL_VERSION;
424 }
425
426 /**
427 * @brief Returns the device revision identifier.
428 * @retval Device revision identifier
429 */
HAL_GetREVID(void)430 uint32_t HAL_GetREVID(void)
431 {
432 return ((DBGMCU->IDCODE & DBGMCU_IDCODE_REV_ID) >> 16);
433 }
434
435 /**
436 * @brief Returns the device identifier.
437 * @retval Device identifier
438 */
HAL_GetDEVID(void)439 uint32_t HAL_GetDEVID(void)
440 {
441 return (DBGMCU->IDCODE & DBGMCU_IDCODE_DEV_ID);
442 }
443
444 /**
445 * @}
446 */
447
448
449 /** @defgroup HAL_Exported_Functions_Group3 HAL Debug functions
450 * @brief HAL Debug functions
451 *
452 @verbatim
453 ===============================================================================
454 ##### HAL Debug functions #####
455 ===============================================================================
456 [..] This section provides functions allowing to:
457 (+) Enable/Disable Debug module during STOP0/STOP1/STOP2 modes
458 (+) Enable/Disable Debug module during STANDBY mode
459
460 @endverbatim
461 * @{
462 */
463
464 /**
465 * @brief Enable the Debug Module during STOP0/STOP1/STOP2 modes.
466 * @retval None
467 */
HAL_DBGMCU_EnableDBGStopMode(void)468 void HAL_DBGMCU_EnableDBGStopMode(void)
469 {
470 SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STOP);
471 }
472
473 /**
474 * @brief Disable the Debug Module during STOP0/STOP1/STOP2 modes.
475 * @retval None
476 */
HAL_DBGMCU_DisableDBGStopMode(void)477 void HAL_DBGMCU_DisableDBGStopMode(void)
478 {
479 CLEAR_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STOP);
480 }
481
482 /**
483 * @brief Enable the Debug Module during STANDBY mode.
484 * @retval None
485 */
HAL_DBGMCU_EnableDBGStandbyMode(void)486 void HAL_DBGMCU_EnableDBGStandbyMode(void)
487 {
488 SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STANDBY);
489 }
490
491 /**
492 * @brief Disable the Debug Module during STANDBY mode.
493 * @retval None
494 */
HAL_DBGMCU_DisableDBGStandbyMode(void)495 void HAL_DBGMCU_DisableDBGStandbyMode(void)
496 {
497 CLEAR_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STANDBY);
498 }
499
500 /**
501 * @}
502 */
503
504 /** @defgroup HAL_Exported_Functions_Group4 HAL SYSCFG configuration functions
505 * @brief HAL SYSCFG configuration functions
506 *
507 @verbatim
508 ===============================================================================
509 ##### HAL SYSCFG configuration functions #####
510 ===============================================================================
511 [..] This section provides functions allowing to:
512 (+) Configure the Voltage reference buffer
513 (+) Enable/Disable the Voltage reference buffer
514 (+) Enable/Disable the I/O analog switch voltage booster
515
516 @endverbatim
517 * @{
518 */
519
520 /**
521 * @brief Configure the internal voltage reference buffer voltage scale.
522 * @param VoltageScaling: specifies the output voltage to achieve
523 * This parameter can be one of the following values:
524 * @arg SYSCFG_VREFBUF_VOLTAGE_SCALE0: VREF_OUT1 around 1.5 V.
525 * This requires VDDA equal to or higher than 1.8 V.
526 * @arg SYSCFG_VREFBUF_VOLTAGE_SCALE1: VREF_OUT1 around 1.8 V.
527 * This requires VDDA equal to or higher than 2.1 V.
528 * @arg SYSCFG_VREFBUF_VOLTAGE_SCALE2: VREF_OUT1 around 2.048 V.
529 * This requires VDDA equal to or higher than 2.4 V.
530 * @arg SYSCFG_VREFBUF_VOLTAGE_SCALE3: VREF_OUT1 around 2.5 V.
531 * This requires VDDA equal to or higher than 2.8 V.
532 * @retval None
533 */
HAL_SYSCFG_VREFBUF_VoltageScalingConfig(uint32_t VoltageScaling)534 void HAL_SYSCFG_VREFBUF_VoltageScalingConfig(uint32_t VoltageScaling)
535 {
536 /* Check the parameters */
537 assert_param(IS_SYSCFG_VREFBUF_VOLTAGE_SCALE(VoltageScaling));
538
539 MODIFY_REG(VREFBUF->CSR, VREFBUF_CSR_VRS, VoltageScaling);
540 }
541
542 /**
543 * @brief Configure the internal voltage reference buffer high impedance mode.
544 * @param Mode: specifies the high impedance mode
545 * This parameter can be one of the following values:
546 * @arg SYSCFG_VREFBUF_HIGH_IMPEDANCE_DISABLE: VREF+ pin is internally connect to VREFINT output.
547 * @arg SYSCFG_VREFBUF_HIGH_IMPEDANCE_ENABLE: VREF+ pin is high impedance.
548 * @retval None
549 */
HAL_SYSCFG_VREFBUF_HighImpedanceConfig(uint32_t Mode)550 void HAL_SYSCFG_VREFBUF_HighImpedanceConfig(uint32_t Mode)
551 {
552 /* Check the parameters */
553 assert_param(IS_SYSCFG_VREFBUF_HIGH_IMPEDANCE(Mode));
554
555 MODIFY_REG(VREFBUF->CSR, VREFBUF_CSR_HIZ, Mode);
556 }
557
558 /**
559 * @brief Tune the Internal Voltage Reference buffer (VREFBUF).
560 * @retval None
561 */
HAL_SYSCFG_VREFBUF_TrimmingConfig(uint32_t TrimmingValue)562 void HAL_SYSCFG_VREFBUF_TrimmingConfig(uint32_t TrimmingValue)
563 {
564 /* Check the parameters */
565 assert_param(IS_SYSCFG_VREFBUF_TRIMMING(TrimmingValue));
566
567 MODIFY_REG(VREFBUF->CCR, VREFBUF_CCR_TRIM, TrimmingValue);
568 }
569
570 /**
571 * @brief Enable the Internal Voltage Reference buffer (VREFBUF).
572 * @retval HAL_OK/HAL_TIMEOUT
573 */
HAL_SYSCFG_EnableVREFBUF(void)574 HAL_StatusTypeDef HAL_SYSCFG_EnableVREFBUF(void)
575 {
576 uint32_t tickstart;
577
578 SET_BIT(VREFBUF->CSR, VREFBUF_CSR_ENVR);
579
580 /* Get Start Tick*/
581 tickstart = HAL_GetTick();
582
583 /* Wait for VRR bit */
584 while (READ_BIT(VREFBUF->CSR, VREFBUF_CSR_VRR) == 0UL)
585 {
586 if ((HAL_GetTick() - tickstart) > VREFBUF_TIMEOUT_VALUE)
587 {
588 return HAL_TIMEOUT;
589 }
590 }
591
592 return HAL_OK;
593 }
594
595 /**
596 * @brief Disable the Internal Voltage Reference buffer (VREFBUF).
597 *
598 * @retval None
599 */
HAL_SYSCFG_DisableVREFBUF(void)600 void HAL_SYSCFG_DisableVREFBUF(void)
601 {
602 CLEAR_BIT(VREFBUF->CSR, VREFBUF_CSR_ENVR);
603 }
604
605 /**
606 * @brief Enable the I/O analog switch voltage booster
607 *
608 * @retval None
609 */
HAL_SYSCFG_EnableIOAnalogSwitchBooster(void)610 void HAL_SYSCFG_EnableIOAnalogSwitchBooster(void)
611 {
612 SET_BIT(SYSCFG->CFGR1, SYSCFG_CFGR1_BOOSTEN);
613 }
614
615 /**
616 * @brief Disable the I/O analog switch voltage booster
617 *
618 * @retval None
619 */
HAL_SYSCFG_DisableIOAnalogSwitchBooster(void)620 void HAL_SYSCFG_DisableIOAnalogSwitchBooster(void)
621 {
622 CLEAR_BIT(SYSCFG->CFGR1, SYSCFG_CFGR1_BOOSTEN);
623 }
624
625 /**
626 * @}
627 */
628
629 /** @defgroup HAL_Exported_Functions_Group5 HAL SYSCFG lock management functions
630 * @brief SYSCFG lock management functions.
631 *
632 @verbatim
633 ===============================================================================
634 ##### SYSCFG lock functions #####
635 ===============================================================================
636
637 @endverbatim
638 * @{
639 */
640
641 /**
642 * @brief Lock the SYSCFG item(s).
643 * @note Setting lock(s) depends on privilege mode in secure/non-secure code
644 * Lock(s) cleared only at system reset
645 * @param Item Item(s) to set lock on.
646 * This parameter can be a combination of @ref SYSCFG_Lock_items
647 * @retval None
648 */
HAL_SYSCFG_Lock(uint32_t Item)649 void HAL_SYSCFG_Lock(uint32_t Item)
650 {
651 /* Check the parameters */
652 assert_param(IS_SYSCFG_LOCK_ITEMS(Item));
653
654 /* Privilege secure/non-secure locks */
655 SYSCFG->CNSLCKR = (0xFFFFU & Item); /* non-secure lock item in 16 lowest bits */
656
657 #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U)
658 /* Privilege secure only locks */
659 SYSCFG->CSLCKR = ((0xFFFF0000U & Item) >> 16U); /* Secure-only lock item in 16 highest bits */
660 #endif /* __ARM_FEATURE_CMSE */
661 }
662
663 /**
664 * @brief Get the lock state of SYSCFG item.
665 * @note Getting lock(s) depends on privilege mode in secure/non-secure code
666 * @param pItem pointer to return locked items
667 * the return value can be a combination of @ref SYSCFG_Lock_items
668 * @retval HAL status
669 */
HAL_SYSCFG_GetLock(uint32_t * pItem)670 HAL_StatusTypeDef HAL_SYSCFG_GetLock(uint32_t *pItem)
671 {
672 uint32_t tmp_lock;
673
674 /* Check null pointer */
675 if (pItem == NULL)
676 {
677 return HAL_ERROR;
678 }
679
680 /* Get the non-secure lock state */
681 tmp_lock = SYSCFG->CNSLCKR;
682
683 /* Get the secure lock state in secure code */
684 #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U)
685 tmp_lock |= (SYSCFG->CSLCKR << 16U);
686 #endif /* __ARM_FEATURE_CMSE */
687
688 /* Return overall lock status */
689 *pItem = tmp_lock;
690
691 return HAL_OK;
692 }
693
694 /**
695 * @}
696 */
697
698 #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U)
699
700
701 /** @defgroup HAL_Exported_Functions_Group6 HAL SYSCFG attributes management functions
702 * @brief SYSCFG attributes management functions.
703 *
704 @verbatim
705 ===============================================================================
706 ##### SYSCFG attributes functions #####
707 ===============================================================================
708
709 @endverbatim
710 * @{
711 */
712
713 /**
714 * @brief Configure the SYSCFG item attribute(s).
715 * @note Available attributes are to secure SYSCFG items, so this function is
716 * only available in secure
717 * @param Item Item(s) to set attributes on.
718 * This parameter can be a one or a combination of @ref SYSCFG_Attributes_items
719 * @param Attributes specifies the secure/non-secure attributes.
720 * @retval None
721 */
HAL_SYSCFG_ConfigAttributes(uint32_t Item,uint32_t Attributes)722 void HAL_SYSCFG_ConfigAttributes(uint32_t Item, uint32_t Attributes)
723 {
724 uint32_t tmp;
725
726 /* Check the parameters */
727 assert_param(IS_SYSCFG_ITEMS_ATTRIBUTES(Item));
728 assert_param(IS_SYSCFG_ATTRIBUTES(Attributes));
729
730 tmp = SYSCFG_S->SECCFGR;
731
732 /* Set or reset Item */
733 if ((Attributes & SYSCFG_SEC) != 0x00U)
734 {
735 tmp |= Item;
736 }
737 else
738 {
739 tmp &= ~Item;
740 }
741
742 /* Set secure attributes */
743 SYSCFG_S->SECCFGR = tmp;
744 }
745
746 /**
747 * @brief Get the attribute of a SYSCFG item.
748 * @note Available attributes are to secure SYSCFG items, so this function is
749 * only available in secure
750 * @param Item Single item to get secure/non-secure attribute from.
751 * @param pAttributes pointer to return the attribute.
752 * @retval HAL status
753 */
HAL_SYSCFG_GetConfigAttributes(uint32_t Item,uint32_t * pAttributes)754 HAL_StatusTypeDef HAL_SYSCFG_GetConfigAttributes(uint32_t Item, uint32_t *pAttributes)
755 {
756 /* Check null pointer */
757 if (pAttributes == NULL)
758 {
759 return HAL_ERROR;
760 }
761
762 /* Check the parameters */
763 assert_param(IS_SYSCFG_ITEMS_ATTRIBUTES(Item));
764
765 /* Get the secure attribute state */
766 if ((SYSCFG_S->SECCFGR & Item) != 0U)
767 {
768 *pAttributes = SYSCFG_SEC;
769 }
770 else
771 {
772 *pAttributes = SYSCFG_NSEC;
773 }
774
775 return HAL_OK;
776 }
777
778 /**
779 * @}
780 */
781
782 #endif /* __ARM_FEATURE_CMSE */
783
784 /**
785 * @}
786 */
787
788 #endif /* HAL_MODULE_ENABLED */
789 /**
790 * @}
791 */
792
793 /**
794 * @}
795 */
796