Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2 | mjames | 1 | /** |
2 | ****************************************************************************** |
||
3 | * @file stm32f0xx_ll_usart.c |
||
4 | * @author MCD Application Team |
||
5 | * @brief USART LL module driver. |
||
6 | ****************************************************************************** |
||
7 | * @attention |
||
8 | * |
||
9 | * <h2><center>© Copyright (c) 2016 STMicroelectronics. |
||
10 | * All rights reserved.</center></h2> |
||
11 | * |
||
12 | * This software component is licensed by ST under BSD 3-Clause license, |
||
13 | * the "License"; You may not use this file except in compliance with the |
||
14 | * License. You may obtain a copy of the License at: |
||
15 | * opensource.org/licenses/BSD-3-Clause |
||
16 | * |
||
17 | ****************************************************************************** |
||
18 | */ |
||
19 | #if defined(USE_FULL_LL_DRIVER) |
||
20 | |||
21 | /* Includes ------------------------------------------------------------------*/ |
||
22 | #include "stm32f0xx_ll_usart.h" |
||
23 | #include "stm32f0xx_ll_rcc.h" |
||
24 | #include "stm32f0xx_ll_bus.h" |
||
25 | #ifdef USE_FULL_ASSERT |
||
26 | #include "stm32_assert.h" |
||
27 | #else |
||
28 | #define assert_param(expr) ((void)0U) |
||
29 | #endif /* USE_FULL_ASSERT */ |
||
30 | |||
31 | /** @addtogroup STM32F0xx_LL_Driver |
||
32 | * @{ |
||
33 | */ |
||
34 | |||
35 | #if defined (USART1) || defined (USART2) || defined (USART3) || defined (UART4) || defined (UART5) || defined (USART6) || defined (USART7) || defined (USART8) |
||
36 | |||
37 | /** @addtogroup USART_LL |
||
38 | * @{ |
||
39 | */ |
||
40 | |||
41 | /* Private types -------------------------------------------------------------*/ |
||
42 | /* Private variables ---------------------------------------------------------*/ |
||
43 | /* Private constants ---------------------------------------------------------*/ |
||
44 | /* Private macros ------------------------------------------------------------*/ |
||
45 | /** @addtogroup USART_LL_Private_Macros |
||
46 | * @{ |
||
47 | */ |
||
48 | |||
49 | /* __BAUDRATE__ The maximum Baud Rate is derived from the maximum clock available |
||
50 | * divided by the smallest oversampling used on the USART (i.e. 8) */ |
||
51 | #define IS_LL_USART_BAUDRATE(__BAUDRATE__) ((__BAUDRATE__) <= 6000000U) |
||
52 | |||
53 | /* __VALUE__ In case of oversampling by 16 and 8, BRR content must be greater than or equal to 16d. */ |
||
54 | #define IS_LL_USART_BRR_MIN(__VALUE__) ((__VALUE__) >= 16U) |
||
55 | |||
56 | /* __VALUE__ BRR content must be lower than or equal to 0xFFFF. */ |
||
57 | #define IS_LL_USART_BRR_MAX(__VALUE__) ((__VALUE__) <= 0x0000FFFFU) |
||
58 | |||
59 | #define IS_LL_USART_DIRECTION(__VALUE__) (((__VALUE__) == LL_USART_DIRECTION_NONE) \ |
||
60 | || ((__VALUE__) == LL_USART_DIRECTION_RX) \ |
||
61 | || ((__VALUE__) == LL_USART_DIRECTION_TX) \ |
||
62 | || ((__VALUE__) == LL_USART_DIRECTION_TX_RX)) |
||
63 | |||
64 | #define IS_LL_USART_PARITY(__VALUE__) (((__VALUE__) == LL_USART_PARITY_NONE) \ |
||
65 | || ((__VALUE__) == LL_USART_PARITY_EVEN) \ |
||
66 | || ((__VALUE__) == LL_USART_PARITY_ODD)) |
||
67 | |||
68 | #if defined(USART_7BITS_SUPPORT) |
||
69 | #define IS_LL_USART_DATAWIDTH(__VALUE__) (((__VALUE__) == LL_USART_DATAWIDTH_7B) \ |
||
70 | || ((__VALUE__) == LL_USART_DATAWIDTH_8B) \ |
||
71 | || ((__VALUE__) == LL_USART_DATAWIDTH_9B)) |
||
72 | #else |
||
73 | #define IS_LL_USART_DATAWIDTH(__VALUE__) (((__VALUE__) == LL_USART_DATAWIDTH_8B) \ |
||
74 | || ((__VALUE__) == LL_USART_DATAWIDTH_9B)) |
||
75 | #endif /* USART_7BITS_SUPPORT */ |
||
76 | |||
77 | #define IS_LL_USART_OVERSAMPLING(__VALUE__) (((__VALUE__) == LL_USART_OVERSAMPLING_16) \ |
||
78 | || ((__VALUE__) == LL_USART_OVERSAMPLING_8)) |
||
79 | |||
80 | #define IS_LL_USART_LASTBITCLKOUTPUT(__VALUE__) (((__VALUE__) == LL_USART_LASTCLKPULSE_NO_OUTPUT) \ |
||
81 | || ((__VALUE__) == LL_USART_LASTCLKPULSE_OUTPUT)) |
||
82 | |||
83 | #define IS_LL_USART_CLOCKPHASE(__VALUE__) (((__VALUE__) == LL_USART_PHASE_1EDGE) \ |
||
84 | || ((__VALUE__) == LL_USART_PHASE_2EDGE)) |
||
85 | |||
86 | #define IS_LL_USART_CLOCKPOLARITY(__VALUE__) (((__VALUE__) == LL_USART_POLARITY_LOW) \ |
||
87 | || ((__VALUE__) == LL_USART_POLARITY_HIGH)) |
||
88 | |||
89 | #define IS_LL_USART_CLOCKOUTPUT(__VALUE__) (((__VALUE__) == LL_USART_CLOCK_DISABLE) \ |
||
90 | || ((__VALUE__) == LL_USART_CLOCK_ENABLE)) |
||
91 | |||
92 | #if defined(USART_SMARTCARD_SUPPORT) |
||
93 | #define IS_LL_USART_STOPBITS(__VALUE__) (((__VALUE__) == LL_USART_STOPBITS_0_5) \ |
||
94 | || ((__VALUE__) == LL_USART_STOPBITS_1) \ |
||
95 | || ((__VALUE__) == LL_USART_STOPBITS_1_5) \ |
||
96 | || ((__VALUE__) == LL_USART_STOPBITS_2)) |
||
97 | #else |
||
98 | #define IS_LL_USART_STOPBITS(__VALUE__) (((__VALUE__) == LL_USART_STOPBITS_1) \ |
||
99 | || ((__VALUE__) == LL_USART_STOPBITS_2)) |
||
100 | #endif |
||
101 | |||
102 | #define IS_LL_USART_HWCONTROL(__VALUE__) (((__VALUE__) == LL_USART_HWCONTROL_NONE) \ |
||
103 | || ((__VALUE__) == LL_USART_HWCONTROL_RTS) \ |
||
104 | || ((__VALUE__) == LL_USART_HWCONTROL_CTS) \ |
||
105 | || ((__VALUE__) == LL_USART_HWCONTROL_RTS_CTS)) |
||
106 | |||
107 | /** |
||
108 | * @} |
||
109 | */ |
||
110 | |||
111 | /* Private function prototypes -----------------------------------------------*/ |
||
112 | |||
113 | /* Exported functions --------------------------------------------------------*/ |
||
114 | /** @addtogroup USART_LL_Exported_Functions |
||
115 | * @{ |
||
116 | */ |
||
117 | |||
118 | /** @addtogroup USART_LL_EF_Init |
||
119 | * @{ |
||
120 | */ |
||
121 | |||
122 | /** |
||
123 | * @brief De-initialize USART registers (Registers restored to their default values). |
||
124 | * @param USARTx USART Instance |
||
125 | * @retval An ErrorStatus enumeration value: |
||
126 | * - SUCCESS: USART registers are de-initialized |
||
127 | * - ERROR: USART registers are not de-initialized |
||
128 | */ |
||
129 | ErrorStatus LL_USART_DeInit(USART_TypeDef *USARTx) |
||
130 | { |
||
131 | ErrorStatus status = SUCCESS; |
||
132 | |||
133 | /* Check the parameters */ |
||
134 | assert_param(IS_UART_INSTANCE(USARTx)); |
||
135 | |||
136 | if (USARTx == USART1) |
||
137 | { |
||
138 | /* Force reset of USART clock */ |
||
139 | LL_APB1_GRP2_ForceReset(LL_APB1_GRP2_PERIPH_USART1); |
||
140 | |||
141 | /* Release reset of USART clock */ |
||
142 | LL_APB1_GRP2_ReleaseReset(LL_APB1_GRP2_PERIPH_USART1); |
||
143 | } |
||
144 | #if defined(USART2) |
||
145 | else if (USARTx == USART2) |
||
146 | { |
||
147 | /* Force reset of USART clock */ |
||
148 | LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_USART2); |
||
149 | |||
150 | /* Release reset of USART clock */ |
||
151 | LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_USART2); |
||
152 | } |
||
153 | #endif /* USART2 */ |
||
154 | #if defined(USART3) |
||
155 | else if (USARTx == USART3) |
||
156 | { |
||
157 | /* Force reset of USART clock */ |
||
158 | LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_USART3); |
||
159 | |||
160 | /* Release reset of USART clock */ |
||
161 | LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_USART3); |
||
162 | } |
||
163 | #endif /* USART3 */ |
||
164 | #if defined(USART4) |
||
165 | else if (USARTx == USART4) |
||
166 | { |
||
167 | /* Force reset of USART clock */ |
||
168 | LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_USART4); |
||
169 | |||
170 | /* Release reset of USART clock */ |
||
171 | LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_USART4); |
||
172 | } |
||
173 | #endif /* USART4 */ |
||
174 | #if defined(USART5) |
||
175 | else if (USARTx == USART5) |
||
176 | { |
||
177 | /* Force reset of USART clock */ |
||
178 | LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_USART5); |
||
179 | |||
180 | /* Release reset of USART clock */ |
||
181 | LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_USART5); |
||
182 | } |
||
183 | #endif /* USART5 */ |
||
184 | #if defined(USART6) |
||
185 | else if (USARTx == USART6) |
||
186 | { |
||
187 | /* Force reset of USART clock */ |
||
188 | LL_APB1_GRP2_ForceReset(LL_APB1_GRP2_PERIPH_USART6); |
||
189 | |||
190 | /* Release reset of USART clock */ |
||
191 | LL_APB1_GRP2_ReleaseReset(LL_APB1_GRP2_PERIPH_USART6); |
||
192 | } |
||
193 | #endif /* USART6 */ |
||
194 | #if defined(USART7) |
||
195 | else if (USARTx == USART7) |
||
196 | { |
||
197 | /* Force reset of USART clock */ |
||
198 | LL_APB1_GRP2_ForceReset(LL_APB1_GRP2_PERIPH_USART7); |
||
199 | |||
200 | /* Release reset of USART clock */ |
||
201 | LL_APB1_GRP2_ReleaseReset(LL_APB1_GRP2_PERIPH_USART7); |
||
202 | } |
||
203 | #endif /* USART7 */ |
||
204 | #if defined(USART8) |
||
205 | else if (USARTx == USART8) |
||
206 | { |
||
207 | /* Force reset of USART clock */ |
||
208 | LL_APB1_GRP2_ForceReset(LL_APB1_GRP2_PERIPH_USART8); |
||
209 | |||
210 | /* Release reset of USART clock */ |
||
211 | LL_APB1_GRP2_ReleaseReset(LL_APB1_GRP2_PERIPH_USART8); |
||
212 | } |
||
213 | #endif /* USART8 */ |
||
214 | else |
||
215 | { |
||
216 | status = ERROR; |
||
217 | } |
||
218 | |||
219 | return (status); |
||
220 | } |
||
221 | |||
222 | /** |
||
223 | * @brief Initialize USART registers according to the specified |
||
224 | * parameters in USART_InitStruct. |
||
225 | * @note As some bits in USART configuration registers can only be written when the USART is disabled (USART_CR1_UE bit =0), |
||
226 | * USART Peripheral should be in disabled state prior calling this function. Otherwise, ERROR result will be returned. |
||
227 | * @note Baud rate value stored in USART_InitStruct BaudRate field, should be valid (different from 0). |
||
228 | * @param USARTx USART Instance |
||
229 | * @param USART_InitStruct pointer to a LL_USART_InitTypeDef structure |
||
230 | * that contains the configuration information for the specified USART peripheral. |
||
231 | * @retval An ErrorStatus enumeration value: |
||
232 | * - SUCCESS: USART registers are initialized according to USART_InitStruct content |
||
233 | * - ERROR: Problem occurred during USART Registers initialization |
||
234 | */ |
||
235 | ErrorStatus LL_USART_Init(USART_TypeDef *USARTx, LL_USART_InitTypeDef *USART_InitStruct) |
||
236 | { |
||
237 | ErrorStatus status = ERROR; |
||
238 | uint32_t periphclk = LL_RCC_PERIPH_FREQUENCY_NO; |
||
239 | #if defined(USART2)||defined(USART3)||defined(USART4) |
||
240 | LL_RCC_ClocksTypeDef RCC_Clocks; |
||
241 | #endif /* USART2 ||USART3 || USART4 */ |
||
242 | |||
243 | /* Check the parameters */ |
||
244 | assert_param(IS_UART_INSTANCE(USARTx)); |
||
245 | assert_param(IS_LL_USART_BAUDRATE(USART_InitStruct->BaudRate)); |
||
246 | assert_param(IS_LL_USART_DATAWIDTH(USART_InitStruct->DataWidth)); |
||
247 | assert_param(IS_LL_USART_STOPBITS(USART_InitStruct->StopBits)); |
||
248 | assert_param(IS_LL_USART_PARITY(USART_InitStruct->Parity)); |
||
249 | assert_param(IS_LL_USART_DIRECTION(USART_InitStruct->TransferDirection)); |
||
250 | assert_param(IS_LL_USART_HWCONTROL(USART_InitStruct->HardwareFlowControl)); |
||
251 | assert_param(IS_LL_USART_OVERSAMPLING(USART_InitStruct->OverSampling)); |
||
252 | |||
253 | /* USART needs to be in disabled state, in order to be able to configure some bits in |
||
254 | CRx registers */ |
||
255 | if (LL_USART_IsEnabled(USARTx) == 0U) |
||
256 | { |
||
257 | /*---------------------------- USART CR1 Configuration --------------------- |
||
258 | * Configure USARTx CR1 (USART Word Length, Parity, Mode and Oversampling bits) with parameters: |
||
259 | * - DataWidth: USART_CR1_M bits according to USART_InitStruct->DataWidth value |
||
260 | * - Parity: USART_CR1_PCE, USART_CR1_PS bits according to USART_InitStruct->Parity value |
||
261 | * - TransferDirection: USART_CR1_TE, USART_CR1_RE bits according to USART_InitStruct->TransferDirection value |
||
262 | * - Oversampling: USART_CR1_OVER8 bit according to USART_InitStruct->OverSampling value. |
||
263 | */ |
||
264 | MODIFY_REG(USARTx->CR1, |
||
265 | (USART_CR1_M | USART_CR1_PCE | USART_CR1_PS | |
||
266 | USART_CR1_TE | USART_CR1_RE | USART_CR1_OVER8), |
||
267 | (USART_InitStruct->DataWidth | USART_InitStruct->Parity | |
||
268 | USART_InitStruct->TransferDirection | USART_InitStruct->OverSampling)); |
||
269 | |||
270 | /*---------------------------- USART CR2 Configuration --------------------- |
||
271 | * Configure USARTx CR2 (Stop bits) with parameters: |
||
272 | * - Stop Bits: USART_CR2_STOP bits according to USART_InitStruct->StopBits value. |
||
273 | * - CLKEN, CPOL, CPHA and LBCL bits are to be configured using LL_USART_ClockInit(). |
||
274 | */ |
||
275 | LL_USART_SetStopBitsLength(USARTx, USART_InitStruct->StopBits); |
||
276 | |||
277 | /*---------------------------- USART CR3 Configuration --------------------- |
||
278 | * Configure USARTx CR3 (Hardware Flow Control) with parameters: |
||
279 | * - HardwareFlowControl: USART_CR3_RTSE, USART_CR3_CTSE bits according to USART_InitStruct->HardwareFlowControl value. |
||
280 | */ |
||
281 | LL_USART_SetHWFlowCtrl(USARTx, USART_InitStruct->HardwareFlowControl); |
||
282 | |||
283 | /*---------------------------- USART BRR Configuration --------------------- |
||
284 | * Retrieve Clock frequency used for USART Peripheral |
||
285 | */ |
||
286 | if (USARTx == USART1) |
||
287 | { |
||
288 | periphclk = LL_RCC_GetUSARTClockFreq(LL_RCC_USART1_CLKSOURCE); |
||
289 | } |
||
290 | #if defined(USART2) |
||
291 | else if (USARTx == USART2) |
||
292 | { |
||
293 | #if defined(RCC_CFGR3_USART2SW) |
||
294 | periphclk = LL_RCC_GetUSARTClockFreq(LL_RCC_USART2_CLKSOURCE); |
||
295 | #else |
||
296 | /* USART2 clock is PCLK */ |
||
297 | LL_RCC_GetSystemClocksFreq(&RCC_Clocks); |
||
298 | periphclk = RCC_Clocks.PCLK1_Frequency; |
||
299 | #endif |
||
300 | } |
||
301 | #endif /* USART2 */ |
||
302 | #if defined(USART3) |
||
303 | else if (USARTx == USART3) |
||
304 | { |
||
305 | #if defined(RCC_CFGR3_USART3SW) |
||
306 | periphclk = LL_RCC_GetUSARTClockFreq(LL_RCC_USART3_CLKSOURCE); |
||
307 | #else |
||
308 | /* USART3 clock is PCLK */ |
||
309 | LL_RCC_GetSystemClocksFreq(&RCC_Clocks); |
||
310 | periphclk = RCC_Clocks.PCLK1_Frequency; |
||
311 | #endif |
||
312 | } |
||
313 | #endif /* USART3 */ |
||
314 | #if defined(USART4) |
||
315 | else if (USARTx == USART4) |
||
316 | { |
||
317 | /* USART4 clock is PCLK1 */ |
||
318 | LL_RCC_GetSystemClocksFreq(&RCC_Clocks); |
||
319 | periphclk = RCC_Clocks.PCLK1_Frequency; |
||
320 | } |
||
321 | #endif /* USART4 */ |
||
322 | #if defined(USART5) |
||
323 | else if (USARTx == USART5) |
||
324 | { |
||
325 | /* USART5 clock is PCLK1 */ |
||
326 | LL_RCC_GetSystemClocksFreq(&RCC_Clocks); |
||
327 | periphclk = RCC_Clocks.PCLK1_Frequency; |
||
328 | } |
||
329 | #endif /* USART5 */ |
||
330 | #if defined(USART6) |
||
331 | else if (USARTx == USART6) |
||
332 | { |
||
333 | /* USART6 clock is PCLK */ |
||
334 | LL_RCC_GetSystemClocksFreq(&RCC_Clocks); |
||
335 | periphclk = RCC_Clocks.PCLK1_Frequency; |
||
336 | } |
||
337 | #endif /* USART6 */ |
||
338 | #if defined(USART7) |
||
339 | else if (USARTx == USART7) |
||
340 | { |
||
341 | /* USART7 clock is PCLK */ |
||
342 | LL_RCC_GetSystemClocksFreq(&RCC_Clocks); |
||
343 | periphclk = RCC_Clocks.PCLK1_Frequency; |
||
344 | } |
||
345 | #endif /* USART7 */ |
||
346 | #if defined(USART8) |
||
347 | else if (USARTx == USART8) |
||
348 | { |
||
349 | /* USART8 clock is PCLK */ |
||
350 | LL_RCC_GetSystemClocksFreq(&RCC_Clocks); |
||
351 | periphclk = RCC_Clocks.PCLK1_Frequency; |
||
352 | } |
||
353 | #endif /* USART8 */ |
||
354 | else |
||
355 | { |
||
356 | /* Nothing to do, as error code is already assigned to ERROR value */ |
||
357 | } |
||
358 | |||
359 | /* Configure the USART Baud Rate : |
||
360 | - valid baud rate value (different from 0) is required |
||
361 | - Peripheral clock as returned by RCC service, should be valid (different from 0). |
||
362 | */ |
||
363 | if ((periphclk != LL_RCC_PERIPH_FREQUENCY_NO) |
||
364 | && (USART_InitStruct->BaudRate != 0U)) |
||
365 | { |
||
366 | status = SUCCESS; |
||
367 | LL_USART_SetBaudRate(USARTx, |
||
368 | periphclk, |
||
369 | USART_InitStruct->OverSampling, |
||
370 | USART_InitStruct->BaudRate); |
||
371 | |||
372 | /* Check BRR is greater than or equal to 16d */ |
||
373 | assert_param(IS_LL_USART_BRR_MIN(USARTx->BRR)); |
||
374 | |||
375 | /* Check BRR is lower than or equal to 0xFFFF */ |
||
376 | assert_param(IS_LL_USART_BRR_MAX(USARTx->BRR)); |
||
377 | } |
||
378 | } |
||
379 | /* Endif (=> USART not in Disabled state => return ERROR) */ |
||
380 | |||
381 | return (status); |
||
382 | } |
||
383 | |||
384 | /** |
||
385 | * @brief Set each @ref LL_USART_InitTypeDef field to default value. |
||
386 | * @param USART_InitStruct pointer to a @ref LL_USART_InitTypeDef structure |
||
387 | * whose fields will be set to default values. |
||
388 | * @retval None |
||
389 | */ |
||
390 | |||
391 | void LL_USART_StructInit(LL_USART_InitTypeDef *USART_InitStruct) |
||
392 | { |
||
393 | /* Set USART_InitStruct fields to default values */ |
||
394 | USART_InitStruct->BaudRate = 9600U; |
||
395 | USART_InitStruct->DataWidth = LL_USART_DATAWIDTH_8B; |
||
396 | USART_InitStruct->StopBits = LL_USART_STOPBITS_1; |
||
397 | USART_InitStruct->Parity = LL_USART_PARITY_NONE ; |
||
398 | USART_InitStruct->TransferDirection = LL_USART_DIRECTION_TX_RX; |
||
399 | USART_InitStruct->HardwareFlowControl = LL_USART_HWCONTROL_NONE; |
||
400 | USART_InitStruct->OverSampling = LL_USART_OVERSAMPLING_16; |
||
401 | } |
||
402 | |||
403 | /** |
||
404 | * @brief Initialize USART Clock related settings according to the |
||
405 | * specified parameters in the USART_ClockInitStruct. |
||
406 | * @note As some bits in USART configuration registers can only be written when the USART is disabled (USART_CR1_UE bit =0), |
||
407 | * USART Peripheral should be in disabled state prior calling this function. Otherwise, ERROR result will be returned. |
||
408 | * @param USARTx USART Instance |
||
409 | * @param USART_ClockInitStruct pointer to a @ref LL_USART_ClockInitTypeDef structure |
||
410 | * that contains the Clock configuration information for the specified USART peripheral. |
||
411 | * @retval An ErrorStatus enumeration value: |
||
412 | * - SUCCESS: USART registers related to Clock settings are initialized according to USART_ClockInitStruct content |
||
413 | * - ERROR: Problem occurred during USART Registers initialization |
||
414 | */ |
||
415 | ErrorStatus LL_USART_ClockInit(USART_TypeDef *USARTx, LL_USART_ClockInitTypeDef *USART_ClockInitStruct) |
||
416 | { |
||
417 | ErrorStatus status = SUCCESS; |
||
418 | |||
419 | /* Check USART Instance and Clock signal output parameters */ |
||
420 | assert_param(IS_UART_INSTANCE(USARTx)); |
||
421 | assert_param(IS_LL_USART_CLOCKOUTPUT(USART_ClockInitStruct->ClockOutput)); |
||
422 | |||
423 | /* USART needs to be in disabled state, in order to be able to configure some bits in |
||
424 | CRx registers */ |
||
425 | if (LL_USART_IsEnabled(USARTx) == 0U) |
||
426 | { |
||
427 | /*---------------------------- USART CR2 Configuration -----------------------*/ |
||
428 | /* If Clock signal has to be output */ |
||
429 | if (USART_ClockInitStruct->ClockOutput == LL_USART_CLOCK_DISABLE) |
||
430 | { |
||
431 | /* Deactivate Clock signal delivery : |
||
432 | * - Disable Clock Output: USART_CR2_CLKEN cleared |
||
433 | */ |
||
434 | LL_USART_DisableSCLKOutput(USARTx); |
||
435 | } |
||
436 | else |
||
437 | { |
||
438 | /* Ensure USART instance is USART capable */ |
||
439 | assert_param(IS_USART_INSTANCE(USARTx)); |
||
440 | |||
441 | /* Check clock related parameters */ |
||
442 | assert_param(IS_LL_USART_CLOCKPOLARITY(USART_ClockInitStruct->ClockPolarity)); |
||
443 | assert_param(IS_LL_USART_CLOCKPHASE(USART_ClockInitStruct->ClockPhase)); |
||
444 | assert_param(IS_LL_USART_LASTBITCLKOUTPUT(USART_ClockInitStruct->LastBitClockPulse)); |
||
445 | |||
446 | /*---------------------------- USART CR2 Configuration ----------------------- |
||
447 | * Configure USARTx CR2 (Clock signal related bits) with parameters: |
||
448 | * - Enable Clock Output: USART_CR2_CLKEN set |
||
449 | * - Clock Polarity: USART_CR2_CPOL bit according to USART_ClockInitStruct->ClockPolarity value |
||
450 | * - Clock Phase: USART_CR2_CPHA bit according to USART_ClockInitStruct->ClockPhase value |
||
451 | * - Last Bit Clock Pulse Output: USART_CR2_LBCL bit according to USART_ClockInitStruct->LastBitClockPulse value. |
||
452 | */ |
||
453 | MODIFY_REG(USARTx->CR2, |
||
454 | USART_CR2_CLKEN | USART_CR2_CPHA | USART_CR2_CPOL | USART_CR2_LBCL, |
||
455 | USART_CR2_CLKEN | USART_ClockInitStruct->ClockPolarity | |
||
456 | USART_ClockInitStruct->ClockPhase | USART_ClockInitStruct->LastBitClockPulse); |
||
457 | } |
||
458 | } |
||
459 | /* Else (USART not in Disabled state => return ERROR */ |
||
460 | else |
||
461 | { |
||
462 | status = ERROR; |
||
463 | } |
||
464 | |||
465 | return (status); |
||
466 | } |
||
467 | |||
468 | /** |
||
469 | * @brief Set each field of a @ref LL_USART_ClockInitTypeDef type structure to default value. |
||
470 | * @param USART_ClockInitStruct pointer to a @ref LL_USART_ClockInitTypeDef structure |
||
471 | * whose fields will be set to default values. |
||
472 | * @retval None |
||
473 | */ |
||
474 | void LL_USART_ClockStructInit(LL_USART_ClockInitTypeDef *USART_ClockInitStruct) |
||
475 | { |
||
476 | /* Set LL_USART_ClockInitStruct fields with default values */ |
||
477 | USART_ClockInitStruct->ClockOutput = LL_USART_CLOCK_DISABLE; |
||
478 | USART_ClockInitStruct->ClockPolarity = LL_USART_POLARITY_LOW; /* Not relevant when ClockOutput = LL_USART_CLOCK_DISABLE */ |
||
479 | USART_ClockInitStruct->ClockPhase = LL_USART_PHASE_1EDGE; /* Not relevant when ClockOutput = LL_USART_CLOCK_DISABLE */ |
||
480 | USART_ClockInitStruct->LastBitClockPulse = LL_USART_LASTCLKPULSE_NO_OUTPUT; /* Not relevant when ClockOutput = LL_USART_CLOCK_DISABLE */ |
||
481 | } |
||
482 | |||
483 | /** |
||
484 | * @} |
||
485 | */ |
||
486 | |||
487 | /** |
||
488 | * @} |
||
489 | */ |
||
490 | |||
491 | /** |
||
492 | * @} |
||
493 | */ |
||
494 | |||
495 | #endif /* USART1 || USART2 || USART3 || UART4 || UART5 || USART6 || USART7 || USART8 */ |
||
496 | |||
497 | /** |
||
498 | * @} |
||
499 | */ |
||
500 | |||
501 | #endif /* USE_FULL_LL_DRIVER */ |
||
502 | |||
503 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
||
504 |