1 /**
2 ******************************************************************************
3 * @file stm32wb0x_ll_rng.c
4 * @author MCD Application Team
5 * @brief RNG LL module driver.
6 ******************************************************************************
7 * @attention
8 *
9 * Copyright (c) 2024 STMicroelectronics.
10 * All rights reserved.
11 *
12 * This software is licensed under terms that can be found in the LICENSE file
13 * in the root directory of this software component.
14 * If no LICENSE file comes with this software, it is provided AS-IS.
15 *
16 ******************************************************************************
17 */
18 #if defined(USE_FULL_LL_DRIVER)
19
20 /* Includes ------------------------------------------------------------------*/
21 #include "stm32wb0x_ll_rng.h"
22 #include "stm32wb0x_ll_bus.h"
23
24 #ifdef USE_FULL_ASSERT
25 #include "stm32_assert.h"
26 #else
27 #define assert_param(expr) ((void)0U)
28 #endif /* USE_FULL_ASSERT */
29
30 /** @addtogroup STM32WB0x_LL_Driver
31 * @{
32 */
33
34 #if defined (RNG)
35
36 /** @addtogroup RNG_LL
37 * @{
38 */
39
40 /* Private types -------------------------------------------------------------*/
41 /* Private variables ---------------------------------------------------------*/
42 /* Private constants ---------------------------------------------------------*/
43 /* Private macros ------------------------------------------------------------*/
44
45 /* Private function prototypes -----------------------------------------------*/
46
47 /* Exported functions --------------------------------------------------------*/
48 #if defined (STM32WB09)
49 /** @addtogroup RNG_LL_Exported_Functions
50 * @{
51 */
52
53 /** @addtogroup RNG_LL_EF_Init
54 * @{
55 */
56
57 /**
58 * @brief De-initialize RNG registers (Registers restored to their default values).
59 * @param RNGx RNG Instance
60 * @retval An ErrorStatus enumeration value:
61 * - SUCCESS: RNG registers are de-initialized
62 * - ERROR: not applicable
63 */
LL_RNG_DeInit(RNG_TypeDef * RNGx)64 ErrorStatus LL_RNG_DeInit(RNG_TypeDef *RNGx)
65 {
66 /* Check the parameters */
67 assert_param(IS_RNG_ALL_INSTANCE(RNGx));
68
69 /* Enable RNG reset state */
70 LL_AHB1_GRP1_ForceReset(LL_AHB1_GRP1_PERIPH_RNG);
71
72 /* Release RNG from reset state */
73 LL_AHB1_GRP1_ReleaseReset(LL_AHB1_GRP1_PERIPH_RNG);
74 return (SUCCESS);
75 }
76
77 /**
78 * @brief Initialize RNG registers according to the specified parameters in RNG_InitStruct.
79 * @param RNGx RNG Instance
80 * @param RNG_InitStruct pointer to a LL_RNG_InitTypeDef structure
81 * that contains the configuration information for the specified RNG peripheral.
82 * @retval An ErrorStatus enumeration value:
83 * - SUCCESS: RNG registers are initialized according to RNG_InitStruct content
84 * - ERROR: not applicable
85 */
LL_RNG_Init(RNG_TypeDef * RNGx,LL_RNG_InitTypeDef * RNG_InitStruct)86 ErrorStatus LL_RNG_Init(RNG_TypeDef *RNGx, LL_RNG_InitTypeDef *RNG_InitStruct)
87 {
88
89 /* Check that the divider value is equal to the one to configure. If not, it must redo the write and checking. */
90 while (LL_RNG_GetSamplingClockEnableDivider(RNGx) != RNG_InitStruct->SamplingClockDivider)
91 {
92 /* While the new divider value is being resynchronized with the TRNG core clock domain, it is not possible to
93 write another new value. */
94 LL_RNG_SetSamplingClockEnableDivider(RNGx, RNG_InitStruct->SamplingClockDivider);
95 }
96
97
98 return (SUCCESS);
99 }
100
101 /**
102 * @brief Set each @ref LL_RNG_InitTypeDef field to default value.
103 * @param RNG_InitStruct pointer to a @ref LL_RNG_InitTypeDef structure
104 * whose fields will be set to default values.
105 * @retval None
106 */
LL_RNG_StructInit(LL_RNG_InitTypeDef * RNG_InitStruct)107 void LL_RNG_StructInit(LL_RNG_InitTypeDef *RNG_InitStruct)
108 {
109 RNG_InitStruct->SamplingClockDivider = 0;
110
111 }
112 /**
113 * @}
114 */
115
116 /**
117 * @}
118 */
119 #endif /* STM32WB09 */
120 #if defined (STM32WB07) || defined (STM32WB06) || defined(STM32WB05)
121 /** @addtogroup RNG_LL_Private_Macros
122 * @{
123 */
124 #define IS_LL_RNG_CLK_DET(__MODE__) (((__MODE__) == LL_RNG_CLK_DET_ENABLE) || \
125 ((__MODE__) == LL_RNG_CLK_DET_DISABLE))
126
127 /**
128 * @}
129 */
130 /* Private function prototypes -----------------------------------------------*/
131
132 /* Exported functions --------------------------------------------------------*/
133 /** @addtogroup RNG_LL_Exported_Functions
134 * @{
135 */
136
137 /** @addtogroup RNG_LL_EF_Init
138 * @{
139 */
140
141 /**
142 * @brief De-initialize RNG registers (Registers restored to their default values).
143 * @param RNGx RNG Instance
144 * @retval An ErrorStatus enumeration value:
145 * - SUCCESS: RNG registers are de-initialized
146 * - ERROR: not applicable
147 */
LL_RNG_DeInit(RNG_TypeDef * RNGx)148 ErrorStatus LL_RNG_DeInit(RNG_TypeDef *RNGx)
149 {
150 /* Check the parameters */
151 assert_param(IS_RNG_ALL_INSTANCE(RNGx));
152 /* Enable RNG reset state */
153 LL_AHB1_GRP1_ForceReset(LL_AHB1_GRP1_PERIPH_RNG);
154
155 /* Release RNG from reset state */
156 LL_AHB1_GRP1_ReleaseReset(LL_AHB1_GRP1_PERIPH_RNG);
157 return (SUCCESS);
158 }
159
160 /**
161 * @brief Initialize RNG registers according to the specified parameters in RNG_InitStruct.
162 * @param RNGx RNG Instance
163 * @param RNG_InitStruct pointer to a LL_RNG_InitTypeDef structure
164 * that contains the configuration information for the specified RNG peripheral.
165 * @retval An ErrorStatus enumeration value:
166 * - SUCCESS: RNG registers are initialized according to RNG_InitStruct content
167 * - ERROR: not applicable
168 */
LL_RNG_Init(RNG_TypeDef * RNGx,LL_RNG_InitTypeDef * RNG_InitStruct)169 ErrorStatus LL_RNG_Init(RNG_TypeDef *RNGx, LL_RNG_InitTypeDef *RNG_InitStruct)
170 {
171 /* Check the parameters */
172 assert_param(IS_RNG_ALL_INSTANCE(RNGx));
173 assert_param(IS_LL_RNG_CLK_DET(RNG_InitStruct->ClockDetection));
174
175 /* Clock Detection configuration */
176 MODIFY_REG(RNGx->CR, RNG_CR_TST_CLK, RNG_InitStruct->ClockDetection);
177
178 return (SUCCESS);
179 }
180
181 /**
182 * @brief Set each @ref LL_RNG_InitTypeDef field to default value.
183 * @param RNG_InitStruct pointer to a @ref LL_RNG_InitTypeDef structure
184 * whose fields will be set to default values.
185 * @retval None
186 */
LL_RNG_StructInit(LL_RNG_InitTypeDef * RNG_InitStruct)187 void LL_RNG_StructInit(LL_RNG_InitTypeDef *RNG_InitStruct)
188 {
189 /* Set RNG_InitStruct fields to default values */
190 RNG_InitStruct->ClockDetection = LL_RNG_CLK_DET_DISABLE;
191
192 }
193 /**
194 * @}
195 */
196
197 /**
198 * @}
199 */
200 #endif /* STM32WB07 || STM32WB06 || STM32WB05*/
201 /**
202 * @}
203 */
204
205 #endif /* RNG */
206
207 /**
208 * @}
209 */
210
211 #endif /* USE_FULL_LL_DRIVER */
212