1 /**
2 ******************************************************************************
3 * @file stm32wlxx_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) 2020 STMicroelectronics.
12 * All rights reserved.
13 *
14 * This software is licensed under terms that can be found in the LICENSE file
15 * in the root directory of this software component.
16 * If no LICENSE file comes with this software, it is provided AS-IS.
17 *
18 ******************************************************************************
19 @verbatim
20 ==============================================================================
21 ##### How to use this driver #####
22 ==============================================================================
23 [..]
24 The common HAL driver contains a set of generic and common APIs that can be
25 used by the PPP peripheral drivers and the user to start using the HAL.
26 [..]
27 The HAL contains two APIs' categories:
28 (+) Common HAL APIs
29 (+) Services HAL APIs
30
31 @endverbatim
32 ******************************************************************************
33 */
34
35 /* Includes ------------------------------------------------------------------*/
36 #include "stm32wlxx_hal.h"
37
38 /** @addtogroup STM32WLxx_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 STM32WLxx HAL Driver version number
57 */
58 #define __STM32WLxx_HAL_VERSION_MAIN (0x01U) /*!< [31:24] main version */
59 #define __STM32WLxx_HAL_VERSION_SUB1 (0x03U) /*!< [23:16] sub1 version */
60 #define __STM32WLxx_HAL_VERSION_SUB2 (0x00U) /*!< [15:8] sub2 version */
61 #define __STM32WLxx_HAL_VERSION_RC (0x00U) /*!< [7:0] release candidate */
62 #define __STM32WLxx_HAL_VERSION ((__STM32WLxx_HAL_VERSION_MAIN << 24U)\
63 |(__STM32WLxx_HAL_VERSION_SUB1 << 16U)\
64 |(__STM32WLxx_HAL_VERSION_SUB2 << 8U )\
65 |(__STM32WLxx_HAL_VERSION_RC))
66
67 #define VREFBUF_TIMEOUT_VALUE 10U /* 10 ms */
68
69 #if defined(STM32WL5Mxx)
70 #define RADIO_SWITCH_CTRL_GPIO_PORT GPIOC
71 #define RADIO_SWITCH_CTRL_GPIO_CLK_ENABLE() __HAL_RCC_GPIOC_CLK_ENABLE()
72 #define RADIO_SWITCH_CTRL_GPIO_CLK_DISABLE() __HAL_RCC_GPIOC_CLK_DISABLE()
73
74 #define RADIO_SWITCH_CTRL3_PIN GPIO_PIN_3
75 #define RADIO_SWITCH_CTRL1_PIN GPIO_PIN_4
76 #define RADIO_SWITCH_CTRL2_PIN GPIO_PIN_5
77
78 #endif /* STM32WL5Mxx */
79
80 /**
81 * @}
82 */
83
84 /* Private macro -------------------------------------------------------------*/
85 /* Exported variables ---------------------------------------------------------*/
86 /** @defgroup HAL_Exported_Variables HAL Exported Variables
87 * @{
88 */
89 __IO uint32_t uwTick;
90 uint32_t uwTickPrio = (1UL << __NVIC_PRIO_BITS); /* Invalid PRIO */
91 HAL_TickFreqTypeDef uwTickFreq = HAL_TICK_FREQ_DEFAULT; /* 1KHz */
92 /**
93 * @}
94 */
95
96 /* Private function prototypes -----------------------------------------------*/
97 /* Exported functions --------------------------------------------------------*/
98
99 /** @addtogroup HAL_Exported_Functions
100 * @{
101 */
102
103 /** @addtogroup HAL_Exported_Functions_Group1
104 * @brief HAL Initialization and Configuration functions
105 *
106 @verbatim
107 ===============================================================================
108 ##### HAL Initialization and Configuration functions #####
109 ===============================================================================
110 [..] This section provides functions allowing to:
111 (+) Initialize the Flash interface the NVIC allocation and initial time base
112 clock configuration.
113 (+) De-initialize common part of the HAL.
114 (+) Configure the time base source to have 1ms time base with a dedicated
115 Tick interrupt priority.
116 (++) SysTick timer is used by default as source of time base, but user
117 can eventually implement his proper time base source (a general purpose
118 timer for example or other time source), keeping in mind that Time base
119 duration should be kept 1ms since PPP_TIMEOUT_VALUEs are defined and
120 handled in milliseconds basis.
121 (++) Time base configuration function (HAL_InitTick ()) is called automatically
122 at the beginning of the program after reset by HAL_Init() or at any time
123 when clock is configured, by HAL_RCC_ClockConfig().
124 (++) Source of time base is configured to generate interrupts at regular
125 time intervals. Care must be taken if HAL_Delay() is called from a
126 peripheral ISR process, the Tick interrupt line must have higher priority
127 (numerically lower) than the peripheral interrupt. Otherwise the caller
128 ISR process will be blocked.
129 (++) functions affecting time base configurations are declared as __weak
130 to make override possible in case of other implementations in user file.
131 @endverbatim
132 * @{
133 */
134
135 /**
136 * @brief This function is used to initialize the HAL Library; it must be the first
137 * instruction to be executed in the main program (before to call any other
138 * HAL function), it performs the following:
139 * Configure the Flash prefetch, instruction and Data caches.
140 * Configures the SysTick to generate an interrupt each 1 millisecond,
141 * which is clocked by the MSI (at this stage, the clock is not yet
142 * configured and thus the system is running from the internal MSI at 4 MHz).
143 * Set NVIC Group Priority to 4.
144 * Calls the HAL_MspInit() callback function defined in user file
145 * "stm32wlxx_hal_msp.c" to do the global low level hardware initialization
146 *
147 * @note SysTick is used as time base for the HAL_Delay() function, the application
148 * need to ensure that the SysTick time base is always set to 1 millisecond
149 * to have correct HAL operation.
150 * @retval HAL status
151 */
HAL_Init(void)152 HAL_StatusTypeDef HAL_Init(void)
153 {
154 HAL_StatusTypeDef status = HAL_OK;
155 /* Configure Flash prefetch, Instruction cache, Data cache */
156 /* Default configuration at reset is: */
157 /* - Prefetch disabled */
158 /* - Instruction cache enabled */
159 /* - Data cache enabled */
160 #if (INSTRUCTION_CACHE_ENABLE == 0U)
161 __HAL_FLASH_INSTRUCTION_CACHE_DISABLE();
162 #endif /* INSTRUCTION_CACHE_ENABLE */
163
164 #ifdef CORE_CM0PLUS
165 #else
166 #if (DATA_CACHE_ENABLE == 0U)
167 __HAL_FLASH_DATA_CACHE_DISABLE();
168 #endif /* DATA_CACHE_ENABLE */
169 #endif
170
171 #if (PREFETCH_ENABLE != 0U)
172 __HAL_FLASH_PREFETCH_BUFFER_ENABLE();
173 #endif /* PREFETCH_ENABLE */
174
175 #ifdef CORE_CM0PLUS
176 #else
177 /* Set Interrupt Group Priority */
178 HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_4);
179 #endif
180
181 /* Update the SystemCoreClock global variable */
182 #if defined(DUAL_CORE) && defined(CORE_CM0PLUS)
183 SystemCoreClock = HAL_RCC_GetHCLK2Freq();
184 #else
185 SystemCoreClock = HAL_RCC_GetHCLKFreq();
186 #endif
187
188 /* Use SysTick as time base source and configure 1ms tick (default clock after Reset is MSI) */
189 if (HAL_InitTick(TICK_INT_PRIORITY) != HAL_OK)
190 {
191 status = HAL_ERROR;
192 }
193 else
194 {
195 /* Init the low level hardware */
196 HAL_MspInit();
197 }
198
199 /* Return function status */
200 return status;
201 }
202
203 /**
204 * @brief This function de-Initializes common part of the HAL and stops the source of time base.
205 * @note This function is optional.
206 * @retval HAL status
207 */
HAL_DeInit(void)208 HAL_StatusTypeDef HAL_DeInit(void)
209 {
210 /* Reset of all peripherals */
211 __HAL_RCC_APB1_FORCE_RESET();
212 __HAL_RCC_APB1_RELEASE_RESET();
213
214 __HAL_RCC_APB2_FORCE_RESET();
215 __HAL_RCC_APB2_RELEASE_RESET();
216
217 __HAL_RCC_APB3_FORCE_RESET();
218 __HAL_RCC_APB3_RELEASE_RESET();
219
220 __HAL_RCC_AHB1_FORCE_RESET();
221 __HAL_RCC_AHB1_RELEASE_RESET();
222
223 __HAL_RCC_AHB2_FORCE_RESET();
224 __HAL_RCC_AHB2_RELEASE_RESET();
225
226 __HAL_RCC_AHB3_FORCE_RESET();
227 __HAL_RCC_AHB3_RELEASE_RESET();
228
229 /* De-Init the low level hardware */
230 HAL_MspDeInit();
231
232 /* Return function status */
233 return HAL_OK;
234 }
235
236 /**
237 * @brief Initialize the MSP.
238 * @retval None
239 */
HAL_MspInit(void)240 __weak void HAL_MspInit(void)
241 {
242 /* NOTE : This function should not be modified, when the callback is needed,
243 the HAL_MspInit could be implemented in the user file
244 */
245 }
246
247 /**
248 * @brief DeInitializes the MSP.
249 * @retval None
250 */
HAL_MspDeInit(void)251 __weak void HAL_MspDeInit(void)
252 {
253 /* NOTE : This function should not be modified, when the callback is needed,
254 the HAL_MspDeInit could be implemented in the user file
255 */
256 }
257
258 /**
259 * @brief This function configures the source of the time base:
260 * The time source is configured to have 1ms time base with a dedicated
261 * Tick interrupt priority.
262 * @note This function is called automatically at the beginning of program after
263 * reset by HAL_Init() or at any time when clock is reconfigured by HAL_RCC_ClockConfig().
264 * @note In the default implementation, SysTick timer is the source of time base.
265 * It is used to generate interrupts at regular time intervals.
266 * Care must be taken if HAL_Delay() is called from a peripheral ISR process,
267 * The SysTick interrupt must have higher priority (numerically lower)
268 * than the peripheral interrupt. Otherwise the caller ISR process will be blocked.
269 * The function is declared as __weak to be overwritten in case of other
270 * implementation in user file.
271 * @param TickPriority Tick interrupt priority.
272 * @retval HAL status
273 */
HAL_InitTick(uint32_t TickPriority)274 __weak HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority)
275 {
276 HAL_StatusTypeDef status = HAL_OK;
277
278 /* Check uwTickFreq for MisraC 2012 (even if uwTickFreq is a enum type that don't take the value zero)*/
279 if ((uint32_t)uwTickFreq != 0U)
280 {
281 /*Configure the SysTick to have interrupt in 1ms time basis*/
282 #ifdef CORE_CM0PLUS
283 if (HAL_SYSTICK_Config(HAL_RCC_GetHCLK2Freq() / (1000U / (uint32_t)uwTickFreq)) == 0U)
284 #else
285 if (HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq() / (1000U / (uint32_t)uwTickFreq)) == 0U)
286 #endif
287 {
288 /* Configure the SysTick IRQ priority */
289 if (TickPriority < (1UL << __NVIC_PRIO_BITS))
290 {
291 HAL_NVIC_SetPriority(SysTick_IRQn, TickPriority, 0U);
292 uwTickPrio = TickPriority;
293 }
294 else
295 {
296 status = HAL_ERROR;
297 }
298 }
299 else
300 {
301 status = HAL_ERROR;
302 }
303 }
304 else
305 {
306 status = HAL_ERROR;
307 }
308
309 /* Return function status */
310 return status;
311 }
312
313 /**
314 * @}
315 */
316
317 /** @addtogroup HAL_Exported_Functions_Group2
318 * @brief HAL Control functions
319 *
320 @verbatim
321 ===============================================================================
322 ##### HAL Control functions #####
323 ===============================================================================
324 [..] This section provides functions allowing to:
325 (+) Provide a tick value in millisecond
326 (+) Provide a blocking delay in millisecond
327 (+) Suspend the time base source interrupt
328 (+) Resume the time base source interrupt
329 (+) Get the HAL API driver version
330 (+) Get the device revision identifier
331 (+) Get the device identifier
332 (+) Get the unique device identifier
333
334 @endverbatim
335 * @{
336 */
337
338 /**
339 * @brief This function is called to increment a global variable "uwTick"
340 * used as application time base.
341 * @note In the default implementation, this variable is incremented each 1ms
342 * in SysTick ISR.
343 * @note This function is declared as __weak to be overwritten in case of other
344 * implementations in user file.
345 * @retval None
346 */
HAL_IncTick(void)347 __weak void HAL_IncTick(void)
348 {
349 uwTick += (uint32_t)uwTickFreq;
350 }
351
352 /**
353 * @brief Provides a tick value in millisecond.
354 * @note This function is declared as __weak to be overwritten in case of other
355 * implementations in user file.
356 * @retval tick value
357 */
HAL_GetTick(void)358 __weak uint32_t HAL_GetTick(void)
359 {
360 return uwTick;
361 }
362
363 /**
364 * @brief This function returns a tick priority.
365 * @retval tick priority
366 */
HAL_GetTickPrio(void)367 uint32_t HAL_GetTickPrio(void)
368 {
369 return uwTickPrio;
370 }
371
372 /**
373 * @brief Set new tick Freq.
374 * @retval Status
375 */
HAL_SetTickFreq(HAL_TickFreqTypeDef Freq)376 HAL_StatusTypeDef HAL_SetTickFreq(HAL_TickFreqTypeDef Freq)
377 {
378 HAL_StatusTypeDef status = HAL_OK;
379 HAL_TickFreqTypeDef prevTickFreq;
380 assert_param(IS_TICKFREQ(Freq));
381
382 if (uwTickFreq != Freq)
383 {
384 /* Back up uwTickFreq frequency */
385 prevTickFreq = uwTickFreq;
386
387 /* Update uwTickFreq global variable used by HAL_InitTick() */
388 uwTickFreq = Freq;
389
390 /* Apply the new tick Freq */
391 status = HAL_InitTick(uwTickPrio);
392
393 if (status != HAL_OK)
394 {
395 /* Restore previous tick frequency */
396 uwTickFreq = prevTickFreq;
397 }
398 }
399
400 return status;
401 }
402
403 /**
404 * @brief Return tick frequency.
405 * @retval tick period in Hz
406 */
HAL_GetTickFreq(void)407 HAL_TickFreqTypeDef HAL_GetTickFreq(void)
408 {
409 return uwTickFreq;
410 }
411
412 /**
413 * @brief This function provides minimum delay (in milliseconds) based
414 * on variable incremented.
415 * @note In the default implementation , SysTick timer is the source of time base.
416 * It is used to generate interrupts at regular time intervals where uwTick
417 * is incremented.
418 * @note This function is declared as __weak to be overwritten in case of other
419 * implementations in user file.
420 * @param Delay specifies the delay time length, in milliseconds.
421 * @retval None
422 */
HAL_Delay(uint32_t Delay)423 __weak void HAL_Delay(uint32_t Delay)
424 {
425 uint32_t tickstart = HAL_GetTick();
426 uint32_t wait = Delay;
427
428 /* Add a freq to guarantee minimum wait */
429 if (wait < HAL_MAX_DELAY)
430 {
431 wait += (uint32_t)(uwTickFreq);
432 }
433
434 while ((HAL_GetTick() - tickstart) < wait)
435 {
436 }
437 }
438
439
440 /**
441 * @brief Suspend Tick increment.
442 * @note In the default implementation , SysTick timer is the source of time base. It is
443 * used to generate interrupts at regular time intervals. Once HAL_SuspendTick()
444 * is called, the SysTick interrupt will be disabled and so Tick increment
445 * is suspended.
446 * @note This function is declared as __weak to be overwritten in case of other
447 * implementations in user file.
448 * @retval None
449 */
HAL_SuspendTick(void)450 __weak void HAL_SuspendTick(void)
451 {
452 /* Disable SysTick Interrupt */
453 CLEAR_BIT(SysTick->CTRL, SysTick_CTRL_TICKINT_Msk);
454 }
455
456 /**
457 * @brief Resume Tick increment.
458 * @note In the default implementation , SysTick timer is the source of time base. It is
459 * used to generate interrupts at regular time intervals. Once HAL_ResumeTick()
460 * is called, the SysTick interrupt will be enabled and so Tick increment
461 * is resumed.
462 * @note This function is declared as __weak to be overwritten in case of other
463 * implementations in user file.
464 * @retval None
465 */
HAL_ResumeTick(void)466 __weak void HAL_ResumeTick(void)
467 {
468 /* Enable SysTick Interrupt */
469 SET_BIT(SysTick->CTRL, SysTick_CTRL_TICKINT_Msk);
470 }
471
472 /**
473 * @brief Returns the HAL revision
474 * @retval version : 0xXYZR (8bits for each decimal, R for RC)
475 */
HAL_GetHalVersion(void)476 uint32_t HAL_GetHalVersion(void)
477 {
478 return __STM32WLxx_HAL_VERSION;
479 }
480
481 #if defined(CORE_CM0PLUS)
482 #else
483 /**
484 * @brief Returns the device revision identifier.
485 * @retval Device revision identifier
486 */
HAL_GetREVID(void)487 uint32_t HAL_GetREVID(void)
488 {
489 return (LL_DBGMCU_GetRevisionID());
490 }
491
492 /**
493 * @brief Returns the device identifier.
494 * @retval Device identifier
495 */
HAL_GetDEVID(void)496 uint32_t HAL_GetDEVID(void)
497 {
498 return (LL_DBGMCU_GetDeviceID());
499 }
500 #endif
501
502 /**
503 * @brief Return the first word of the unique device identifier (UID based on 96 bits)
504 * @retval Device identifier
505 */
HAL_GetUIDw0(void)506 uint32_t HAL_GetUIDw0(void)
507 {
508 return (READ_REG(*((uint32_t *)UID_BASE)));
509 }
510
511 /**
512 * @brief Return the second word of the unique device identifier (UID based on 96 bits)
513 * @retval Device identifier
514 */
HAL_GetUIDw1(void)515 uint32_t HAL_GetUIDw1(void)
516 {
517 return (READ_REG(*((uint32_t *)(UID_BASE + 4U))));
518 }
519
520 /**
521 * @brief Return the third word of the unique device identifier (UID based on 96 bits)
522 * @retval Device identifier
523 */
HAL_GetUIDw2(void)524 uint32_t HAL_GetUIDw2(void)
525 {
526 return (READ_REG(*((uint32_t *)(UID_BASE + 8U))));
527 }
528
529 /**
530 * @}
531 */
532
533 /** @addtogroup HAL_Exported_Functions_Group3
534 * @brief HAL Debug functions
535 *
536 @verbatim
537 ===============================================================================
538 ##### HAL Debug functions #####
539 ===============================================================================
540 [..] This section provides functions allowing to:
541 (+) Enable/Disable Debug module during SLEEP mode
542 (+) Enable/Disable Debug module during STOP mode
543 (+) Enable/Disable Debug module during STANDBY mode
544
545 @endverbatim
546 * @{
547 */
548
549 #if defined(CORE_CM0PLUS)
550 #else
551 /**
552 * @brief Enable the CPU1 Debug Module during SLEEP mode
553 * @retval None
554 */
HAL_DBGMCU_EnableDBGSleepMode(void)555 void HAL_DBGMCU_EnableDBGSleepMode(void)
556 {
557 LL_DBGMCU_EnableDBGSleepMode();
558 }
559
560 /**
561 * @brief Disable the CPU1 Debug Module during SLEEP mode
562 * @retval None
563 */
HAL_DBGMCU_DisableDBGSleepMode(void)564 void HAL_DBGMCU_DisableDBGSleepMode(void)
565 {
566 LL_DBGMCU_DisableDBGSleepMode();
567 }
568
569 /**
570 * @brief Enable the Debug Module during STOP mode
571 * @note This functionality does not influence CPU2 operation, CPU2 cannot be debugged
572 * in Stop mode even when this bit is enabled
573 * @retval None
574 */
HAL_DBGMCU_EnableDBGStopMode(void)575 void HAL_DBGMCU_EnableDBGStopMode(void)
576 {
577 LL_DBGMCU_EnableDBGStopMode();
578 }
579
580 /**
581 * @brief Disable the CPU1 Debug Module during STOP mode
582 * @retval None
583 */
HAL_DBGMCU_DisableDBGStopMode(void)584 void HAL_DBGMCU_DisableDBGStopMode(void)
585 {
586 LL_DBGMCU_DisableDBGStopMode();
587 }
588
589 /**
590 * @brief Enable the Debug Module during STANDBY mode
591 * @note This functionality does not influence CPU2 operation, CPU2 cannot be debugged
592 * in Standby mode even when this bit is enabled
593 * @retval None
594 */
HAL_DBGMCU_EnableDBGStandbyMode(void)595 void HAL_DBGMCU_EnableDBGStandbyMode(void)
596 {
597 LL_DBGMCU_EnableDBGStandbyMode();
598 }
599
600 /**
601 * @brief Disable the CPU1 Debug Module during STANDBY mode
602 * @retval None
603 */
HAL_DBGMCU_DisableDBGStandbyMode(void)604 void HAL_DBGMCU_DisableDBGStandbyMode(void)
605 {
606 LL_DBGMCU_DisableDBGStandbyMode();
607 }
608 #endif
609
610 /**
611 * @}
612 */
613
614 /** @defgroup HAL_Exported_Functions_Group4 HAL System Configuration functions
615 * @brief HAL System Configuration functions
616 *
617 @verbatim
618 ===============================================================================
619 ##### HAL system configuration functions #####
620 ===============================================================================
621 [..] This section provides functions allowing to:
622 (+) Start a hardware SRAM2 erase operation
623 (+) Configure the Voltage reference buffer
624 (+) Enable/Disable the Voltage reference buffer
625 (+) Enable/Disable the I/O analog switch voltage booster
626
627 @endverbatim
628 * @{
629 */
630
631 /**
632 * @brief Start a hardware SRAM2 erase operation.
633 * @note As long as SRAM2 is not erased the SRAM2ER bit will be set.
634 * This bit is automatically reset at the end of the SRAM2 erase operation.
635 * @retval None
636 */
HAL_SYSCFG_SRAM2Erase(void)637 void HAL_SYSCFG_SRAM2Erase(void)
638 {
639 /* unlock the write protection of the SRAM2ER bit */
640 __HAL_SYSCFG_SRAM2_WRP_UNLOCK();
641 /* Starts a hardware SRAM2 erase operation*/
642 __HAL_SYSCFG_SRAM2_ERASE();
643 }
644
645 /**
646 * @brief Configure the internal voltage reference buffer voltage scale.
647 * @param VoltageScaling specifies the output voltage to achieve
648 * This parameter can be one of the following values:
649 * @arg @ref SYSCFG_VREFBUF_VOLTAGE_SCALE0 : VREF_OUT1 around 2.048 V.
650 * This requires VDDA equal to or higher than 2.4 V.
651 * @arg @ref SYSCFG_VREFBUF_VOLTAGE_SCALE1 : VREF_OUT1 around 2.5 V.
652 * This requires VDDA equal to or higher than 2.8 V.
653 * @note Retrieve the TrimmingValue from factory located at
654 * VREFBUF_SC0_CAL_ADDR or VREFBUF_SC1_CAL_ADDR addresses.
655 * @retval None
656 */
HAL_SYSCFG_VREFBUF_VoltageScalingConfig(uint32_t VoltageScaling)657 void HAL_SYSCFG_VREFBUF_VoltageScalingConfig(uint32_t VoltageScaling)
658 {
659 uint32_t TrimmingValue;
660
661 /* Check the parameters */
662 assert_param(IS_SYSCFG_VREFBUF_VOLTAGE_SCALE(VoltageScaling));
663
664 LL_VREFBUF_SetVoltageScaling(VoltageScaling);
665
666 /* Restrieve Calibration data and store them into trimming field */
667 if (VoltageScaling == SYSCFG_VREFBUF_VOLTAGE_SCALE0)
668 {
669 TrimmingValue = ((uint32_t) * VREFBUF_SC0_CAL_ADDR) & 0x3FU;
670 }
671 else
672 {
673 TrimmingValue = ((uint32_t) * VREFBUF_SC1_CAL_ADDR) & 0x3FU;
674 }
675 assert_param(IS_SYSCFG_VREFBUF_TRIMMING(TrimmingValue));
676
677 HAL_SYSCFG_VREFBUF_TrimmingConfig(TrimmingValue);
678 }
679
680 /**
681 * @brief Configure the internal voltage reference buffer high impedance mode.
682 * @param Mode specifies the high impedance mode
683 * This parameter can be one of the following values:
684 * @arg @ref SYSCFG_VREFBUF_HIGH_IMPEDANCE_DISABLE : VREF+ pin is internally connect to VREFINT output.
685 * @arg @ref SYSCFG_VREFBUF_HIGH_IMPEDANCE_ENABLE : VREF+ pin is high impedance.
686 * @retval HAL_OK/HAL_TIMEOUT
687 */
HAL_SYSCFG_VREFBUF_HighImpedanceConfig(uint32_t Mode)688 void HAL_SYSCFG_VREFBUF_HighImpedanceConfig(uint32_t Mode)
689 {
690
691 /* Check the parameters */
692 assert_param(IS_SYSCFG_VREFBUF_HIGH_IMPEDANCE(Mode));
693
694 MODIFY_REG(VREFBUF->CSR, VREFBUF_CSR_HIZ, Mode);
695 }
696
697 /**
698 * @brief Tune the Internal Voltage Reference buffer (VREFBUF).
699 * @note Each VrefBuf voltage scale is calibrated in production for each device,
700 * data stored in flash memory.
701 * Function @ref HAL_SYSCFG_VREFBUF_VoltageScalingConfig retrieves and
702 * applies this calibration data as trimming value at each scale change.
703 * Therefore, optionally, function @ref HAL_SYSCFG_VREFBUF_TrimmingConfig
704 * can be used in a second time to fine tune the trimming.
705 * @param TrimmingValue specifies trimming code for VREFBUF calibration
706 * This parameter can be a number between Min_Data = 0x00 and Max_Data = 0x3F
707 * @retval None
708 */
HAL_SYSCFG_VREFBUF_TrimmingConfig(uint32_t TrimmingValue)709 void HAL_SYSCFG_VREFBUF_TrimmingConfig(uint32_t TrimmingValue)
710 {
711 /* Check the parameters */
712 assert_param(IS_SYSCFG_VREFBUF_TRIMMING(TrimmingValue));
713
714 LL_VREFBUF_SetTrimming(TrimmingValue);
715
716 }
717
718 /**
719 * @brief Enable the Internal Voltage Reference buffer (VREFBUF).
720 * @retval HAL_OK/HAL_TIMEOUT
721 */
HAL_SYSCFG_EnableVREFBUF(void)722 HAL_StatusTypeDef HAL_SYSCFG_EnableVREFBUF(void)
723 {
724 uint32_t tickstart;
725
726 LL_VREFBUF_Enable();
727
728 /* Get Start Tick*/
729 tickstart = HAL_GetTick();
730
731 /* Wait for VRR bit */
732 while (READ_BIT(VREFBUF->CSR, VREFBUF_CSR_VRR) == 0U)
733 {
734 if ((HAL_GetTick() - tickstart) > VREFBUF_TIMEOUT_VALUE)
735 {
736 return HAL_TIMEOUT;
737 }
738 }
739
740 return HAL_OK;
741 }
742
743 /**
744 * @brief Disable the Internal Voltage Reference buffer (VREFBUF).
745 *
746 * @retval None
747 */
HAL_SYSCFG_DisableVREFBUF(void)748 void HAL_SYSCFG_DisableVREFBUF(void)
749 {
750 LL_VREFBUF_Disable();
751 }
752
753 /**
754 * @brief Enable the I/O analog switch voltage booster
755 *
756 * @retval None
757 */
HAL_SYSCFG_EnableIOAnalogSwitchBooster(void)758 void HAL_SYSCFG_EnableIOAnalogSwitchBooster(void)
759 {
760 LL_SYSCFG_EnableAnalogBooster();
761 }
762
763 /**
764 * @brief Disable the I/O analog switch voltage booster
765 *
766 * @retval None
767 */
HAL_SYSCFG_DisableIOAnalogSwitchBooster(void)768 void HAL_SYSCFG_DisableIOAnalogSwitchBooster(void)
769 {
770 LL_SYSCFG_DisableAnalogBooster();
771 }
772
773 #if defined(DUAL_CORE)
774 /**
775 * @brief Enable Additional Interrupt Mask
776 * @note This interface is an additional interrupt masking interface
777 * up to the EXTI interface
778 * @param Interrupt Pointer to a SYSCFG_InterruptTypeDef structure that contains
779 * the Interrupt Mask configuration
780 * @retval None
781 */
HAL_SYSCFG_EnableIT(SYSCFG_InterruptTypeDef * Interrupt)782 void HAL_SYSCFG_EnableIT(SYSCFG_InterruptTypeDef *Interrupt)
783 {
784 uint32_t InterruptMask1 = (Interrupt->InterruptMask1 & ~HAL_SYSCFG_GRP1_RESERVED);
785 uint32_t InterruptMask2 = (Interrupt->InterruptMask2 & ~HAL_SYSCFG_GRP2_RESERVED);
786
787 /* Check the parameters */
788 assert_param(IS_SYSCFG_IM_GRP1(Interrupt->InterruptMask1));
789 assert_param(IS_SYSCFG_IM_GRP2(Interrupt->InterruptMask2));
790
791 #if defined(CORE_CM0PLUS)
792 LL_C2_SYSCFG_GRP1_EnableIT(InterruptMask1);
793 LL_C2_SYSCFG_GRP2_EnableIT(InterruptMask2);
794 #else
795 LL_SYSCFG_GRP1_EnableIT(InterruptMask1);
796 LL_SYSCFG_GRP2_EnableIT(InterruptMask2);
797 #endif
798 }
799
800 /**
801 * @brief Disable Additional Interrupt Mask
802 * @note This interface is an additional interrupt masking interface
803 * up to the EXTI interface
804 * @param Interrupt Pointer to a SYSCFG_InterruptTypeDef structure that contains
805 * the Interrupt Mask configuration
806 * @retval None
807 */
HAL_SYSCFG_DisableIT(SYSCFG_InterruptTypeDef * Interrupt)808 void HAL_SYSCFG_DisableIT(SYSCFG_InterruptTypeDef *Interrupt)
809 {
810 uint32_t InterruptMask1 = (Interrupt->InterruptMask1 & ~HAL_SYSCFG_GRP1_RESERVED);
811 uint32_t InterruptMask2 = (Interrupt->InterruptMask2 & ~HAL_SYSCFG_GRP2_RESERVED);
812
813 /* Check the parameters */
814 assert_param(IS_SYSCFG_IM_GRP1(Interrupt->InterruptMask1));
815 assert_param(IS_SYSCFG_IM_GRP2(Interrupt->InterruptMask2));
816
817 #if defined(CORE_CM0PLUS)
818 LL_C2_SYSCFG_GRP1_DisableIT(InterruptMask1);
819 LL_C2_SYSCFG_GRP2_DisableIT(InterruptMask2);
820 #else
821 LL_SYSCFG_GRP1_DisableIT(InterruptMask1);
822 LL_SYSCFG_GRP2_DisableIT(InterruptMask2);
823 #endif
824 }
825 #endif /* DUAL_CORE */
826 /**
827 * @}
828 */
829
830 #if defined(STM32WL5Mxx)
831 /** @defgroup HAL_Exported_Functions_Group5 HAL Radio Configuration functions
832 * @brief HAL Radio Configuration functions
833 *
834 @verbatim
835 ===============================================================================
836 ##### HAL Radio configuration functions #####
837 ===============================================================================
838 [..] This section provides functions allowing to:
839 (+) Enable/Disable the Radio
840 (+) Configure the Radio to Rx, Tx Low Power or Tx High Power
841
842 @endverbatim
843 * @{
844 */
845
846 /* RADIO Control functions ****************************************************/
847 /**
848 * @brief Init Radio Switch
849 * @retval HAL status
850 */
HAL_RADIO_Init(void)851 HAL_StatusTypeDef HAL_RADIO_Init(void)
852 {
853 HAL_StatusTypeDef status;
854 GPIO_InitTypeDef gpio_init_structure;
855
856 /* Enable the Radio Switch Clock */
857 RADIO_SWITCH_CTRL_GPIO_CLK_ENABLE();
858
859 /* Configure the Radio Switch pin */
860 gpio_init_structure.Pin = (RADIO_SWITCH_CTRL1_PIN | RADIO_SWITCH_CTRL2_PIN | RADIO_SWITCH_CTRL3_PIN);
861 gpio_init_structure.Mode = GPIO_MODE_OUTPUT_PP;
862 gpio_init_structure.Pull = GPIO_NOPULL;
863 gpio_init_structure.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
864
865 HAL_GPIO_Init(RADIO_SWITCH_CTRL_GPIO_PORT, &gpio_init_structure);
866
867 /* Lock RF Switch GPIOs configuration to avoid any user change */
868 /* Only a MCU reset will unlock this configuration */
869 status = HAL_GPIO_LockPin(RADIO_SWITCH_CTRL_GPIO_PORT, (RADIO_SWITCH_CTRL1_PIN | RADIO_SWITCH_CTRL2_PIN | RADIO_SWITCH_CTRL3_PIN));
870 if (status == HAL_OK)
871 {
872 /* By default, the RF Switch is off */
873 HAL_GPIO_WritePin(RADIO_SWITCH_CTRL_GPIO_PORT,
874 (RADIO_SWITCH_CTRL1_PIN | RADIO_SWITCH_CTRL2_PIN | RADIO_SWITCH_CTRL3_PIN), GPIO_PIN_RESET);
875 }
876
877 return status;
878 }
879
880 /**
881 * @brief DeInit Radio Switch
882 * @retval HAL status
883 */
HAL_RADIO_DeInit(void)884 HAL_StatusTypeDef HAL_RADIO_DeInit(void)
885 {
886 /* Enable the Radio Switch Clock */
887 RADIO_SWITCH_CTRL_GPIO_CLK_ENABLE();
888
889 /* Turn off switch */
890 HAL_GPIO_WritePin(RADIO_SWITCH_CTRL_GPIO_PORT,
891 (RADIO_SWITCH_CTRL1_PIN | RADIO_SWITCH_CTRL2_PIN | RADIO_SWITCH_CTRL3_PIN), GPIO_PIN_RESET);
892
893 /* Disable the Radio Switch Clock */
894 RADIO_SWITCH_CTRL_GPIO_CLK_DISABLE();
895
896 return HAL_OK;
897 }
898
899 /**
900 * @brief Configure Radio Switch.
901 * @param Config: Specifies the Radio RF switch path to be set.
902 * This parameter can be one of following parameters:
903 * @arg RADIO_SWITCH_OFF
904 * @arg RADIO_SWITCH_RX
905 * @arg RADIO_SWITCH_RFO_LP
906 * @arg RADIO_SWITCH_RFO_HP
907 * @retval HAL status
908 */
HAL_RADIO_SetSwitchConfig(HAL_RADIO_SwitchConfig_TypeDef Config)909 HAL_StatusTypeDef HAL_RADIO_SetSwitchConfig(HAL_RADIO_SwitchConfig_TypeDef Config)
910 {
911 HAL_StatusTypeDef status = HAL_OK;
912
913 switch (Config)
914 {
915 case RADIO_SWITCH_OFF:
916 {
917 /* Turn off switch */
918 HAL_GPIO_WritePin(RADIO_SWITCH_CTRL_GPIO_PORT,
919 (RADIO_SWITCH_CTRL1_PIN | RADIO_SWITCH_CTRL2_PIN | RADIO_SWITCH_CTRL3_PIN), GPIO_PIN_RESET);
920 break;
921 }
922 case RADIO_SWITCH_RX:
923 {
924 /* Turns On in Rx Mode the RF Switch */
925 HAL_GPIO_WritePin(RADIO_SWITCH_CTRL_GPIO_PORT,
926 (RADIO_SWITCH_CTRL1_PIN | RADIO_SWITCH_CTRL2_PIN | RADIO_SWITCH_CTRL3_PIN), GPIO_PIN_SET);
927
928 break;
929 }
930 case RADIO_SWITCH_RFO_LP:
931 {
932 /* Turns On in Tx Low Power the RF Switch */
933 HAL_GPIO_WriteMultipleStatePin(RADIO_SWITCH_CTRL_GPIO_PORT, RADIO_SWITCH_CTRL2_PIN,
934 (RADIO_SWITCH_CTRL1_PIN | RADIO_SWITCH_CTRL3_PIN));
935 break;
936 }
937 case RADIO_SWITCH_RFO_HP:
938 {
939 /* Turns On in Tx High Power the RF Switch */
940 HAL_GPIO_WriteMultipleStatePin(RADIO_SWITCH_CTRL_GPIO_PORT, RADIO_SWITCH_CTRL1_PIN,
941 (RADIO_SWITCH_CTRL2_PIN | RADIO_SWITCH_CTRL3_PIN));
942 break;
943 }
944 default:
945 {
946 status = HAL_ERROR;
947 break;
948 }
949 }
950
951 return status;
952 }
953
954 /**
955 * @brief Get If TCXO is to be present on board
956 * @note never remove called by MW,
957 * @retval
958 * RADIO_CONF_TCXO_NOT_SUPPORTED
959 * RADIO_CONF_TCXO_SUPPORTED
960 */
HAL_RADIO_IsTCXO(void)961 uint8_t HAL_RADIO_IsTCXO(void)
962 {
963 return RADIO_CONF_TCXO_SUPPORTED;
964 }
965
966 /**
967 * @brief Get If DCDC is to be present on board
968 * @note never remove called by MW,
969 * @retval
970 * RADIO_CONF_DCDC_NOT_SUPPORTED
971 * RADIO_CONF_DCDC_SUPPORTED
972 */
HAL_RADIO_IsDCDC(void)973 uint8_t HAL_RADIO_IsDCDC(void)
974 {
975 return RADIO_CONF_DCDC_SUPPORTED;
976 }
977
978 /**
979 * @brief Return RF Output Max Power Configuration
980 * @retval
981 * RADIO_CONF_RFO_LP_MAX_15_dBm for LP mode
982 * RADIO_CONF_RFO_HP_MAX_22_dBm for HP mode
983 */
HAL_RADIO_GetRFOMaxPowerConfig(HAL_RADIO_RFOMaxPowerConfig_TypeDef Config)984 int32_t HAL_RADIO_GetRFOMaxPowerConfig(HAL_RADIO_RFOMaxPowerConfig_TypeDef Config)
985 {
986 int32_t ret;
987
988 if (Config == RADIO_RFO_LP_MAXPOWER)
989 {
990 ret = RADIO_CONF_RFO_LP_MAX_15_dBm;
991 }
992 else
993 {
994 ret = RADIO_CONF_RFO_HP_MAX_22_dBm;
995 }
996
997 return ret;
998 }
999
1000 /**
1001 * @}
1002 */
1003 #endif /* STM32WL5Mxx */
1004
1005 /**
1006 * @}
1007 */
1008
1009 #endif /* HAL_MODULE_ENABLED */
1010 /**
1011 * @}
1012 */
1013
1014 /**
1015 * @}
1016 */
1017