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