Rev 2 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2 | Rev 6 | ||
---|---|---|---|
Line 51... | Line 51... | ||
51 | #define IS_LL_USART_BAUDRATE(__BAUDRATE__) ((__BAUDRATE__) <= 6000000U) |
51 | #define IS_LL_USART_BAUDRATE(__BAUDRATE__) ((__BAUDRATE__) <= 6000000U) |
52 | 52 | ||
53 | /* __VALUE__ In case of oversampling by 16 and 8, BRR content must be greater than or equal to 16d. */ |
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) |
54 | #define IS_LL_USART_BRR_MIN(__VALUE__) ((__VALUE__) >= 16U) |
55 | 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) \ |
56 | #define IS_LL_USART_DIRECTION(__VALUE__) (((__VALUE__) == LL_USART_DIRECTION_NONE) \ |
60 | || ((__VALUE__) == LL_USART_DIRECTION_RX) \ |
57 | || ((__VALUE__) == LL_USART_DIRECTION_RX) \ |
61 | || ((__VALUE__) == LL_USART_DIRECTION_TX) \ |
58 | || ((__VALUE__) == LL_USART_DIRECTION_TX) \ |
62 | || ((__VALUE__) == LL_USART_DIRECTION_TX_RX)) |
59 | || ((__VALUE__) == LL_USART_DIRECTION_TX_RX)) |
63 | 60 | ||
Line 69... | Line 66... | ||
69 | #define IS_LL_USART_DATAWIDTH(__VALUE__) (((__VALUE__) == LL_USART_DATAWIDTH_7B) \ |
66 | #define IS_LL_USART_DATAWIDTH(__VALUE__) (((__VALUE__) == LL_USART_DATAWIDTH_7B) \ |
70 | || ((__VALUE__) == LL_USART_DATAWIDTH_8B) \ |
67 | || ((__VALUE__) == LL_USART_DATAWIDTH_8B) \ |
71 | || ((__VALUE__) == LL_USART_DATAWIDTH_9B)) |
68 | || ((__VALUE__) == LL_USART_DATAWIDTH_9B)) |
72 | #else |
69 | #else |
73 | #define IS_LL_USART_DATAWIDTH(__VALUE__) (((__VALUE__) == LL_USART_DATAWIDTH_8B) \ |
70 | #define IS_LL_USART_DATAWIDTH(__VALUE__) (((__VALUE__) == LL_USART_DATAWIDTH_8B) \ |
74 | || ((__VALUE__) == LL_USART_DATAWIDTH_9B)) |
71 | || ((__VALUE__) == LL_USART_DATAWIDTH_9B)) |
75 | #endif /* USART_7BITS_SUPPORT */ |
72 | #endif /* USART_7BITS_SUPPORT */ |
76 | 73 | ||
77 | #define IS_LL_USART_OVERSAMPLING(__VALUE__) (((__VALUE__) == LL_USART_OVERSAMPLING_16) \ |
74 | #define IS_LL_USART_OVERSAMPLING(__VALUE__) (((__VALUE__) == LL_USART_OVERSAMPLING_16) \ |
78 | || ((__VALUE__) == LL_USART_OVERSAMPLING_8)) |
75 | || ((__VALUE__) == LL_USART_OVERSAMPLING_8)) |
79 | 76 | ||
Line 220... | Line 217... | ||
220 | } |
217 | } |
221 | 218 | ||
222 | /** |
219 | /** |
223 | * @brief Initialize USART registers according to the specified |
220 | * @brief Initialize USART registers according to the specified |
224 | * parameters in USART_InitStruct. |
221 | * 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), |
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 |
|
226 | * USART Peripheral should be in disabled state prior calling this function. Otherwise, ERROR result will be returned. |
224 | * 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). |
225 | * @note Baud rate value stored in USART_InitStruct BaudRate field, should be valid (different from 0). |
228 | * @param USARTx USART Instance |
226 | * @param USARTx USART Instance |
229 | * @param USART_InitStruct pointer to a LL_USART_InitTypeDef structure |
227 | * @param USART_InitStruct pointer to a LL_USART_InitTypeDef structure |
230 | * that contains the configuration information for the specified USART peripheral. |
228 | * that contains the configuration information for the specified USART peripheral. |
231 | * @retval An ErrorStatus enumeration value: |
229 | * @retval An ErrorStatus enumeration value: |
Line 274... | Line 272... | ||
274 | */ |
272 | */ |
275 | LL_USART_SetStopBitsLength(USARTx, USART_InitStruct->StopBits); |
273 | LL_USART_SetStopBitsLength(USARTx, USART_InitStruct->StopBits); |
276 | 274 | ||
277 | /*---------------------------- USART CR3 Configuration --------------------- |
275 | /*---------------------------- USART CR3 Configuration --------------------- |
278 | * Configure USARTx CR3 (Hardware Flow Control) with parameters: |
276 | * Configure USARTx CR3 (Hardware Flow Control) with parameters: |
279 | * - HardwareFlowControl: USART_CR3_RTSE, USART_CR3_CTSE bits according to USART_InitStruct->HardwareFlowControl value. |
277 | * - HardwareFlowControl: USART_CR3_RTSE, USART_CR3_CTSE bits according to |
- | 278 | * USART_InitStruct->HardwareFlowControl value. |
|
280 | */ |
279 | */ |
281 | LL_USART_SetHWFlowCtrl(USARTx, USART_InitStruct->HardwareFlowControl); |
280 | LL_USART_SetHWFlowCtrl(USARTx, USART_InitStruct->HardwareFlowControl); |
282 | 281 | ||
283 | /*---------------------------- USART BRR Configuration --------------------- |
282 | /*---------------------------- USART BRR Configuration --------------------- |
284 | * Retrieve Clock frequency used for USART Peripheral |
283 | * Retrieve Clock frequency used for USART Peripheral |
Line 328... | Line 327... | ||
328 | } |
327 | } |
329 | #endif /* USART5 */ |
328 | #endif /* USART5 */ |
330 | #if defined(USART6) |
329 | #if defined(USART6) |
331 | else if (USARTx == USART6) |
330 | else if (USARTx == USART6) |
332 | { |
331 | { |
333 | /* USART6 clock is PCLK */ |
332 | /* USART6 clock is PCLK1 */ |
334 | LL_RCC_GetSystemClocksFreq(&RCC_Clocks); |
333 | LL_RCC_GetSystemClocksFreq(&RCC_Clocks); |
335 | periphclk = RCC_Clocks.PCLK1_Frequency; |
334 | periphclk = RCC_Clocks.PCLK1_Frequency; |
336 | } |
335 | } |
337 | #endif /* USART6 */ |
336 | #endif /* USART6 */ |
338 | #if defined(USART7) |
337 | #if defined(USART7) |
Line 369... | Line 368... | ||
369 | USART_InitStruct->OverSampling, |
368 | USART_InitStruct->OverSampling, |
370 | USART_InitStruct->BaudRate); |
369 | USART_InitStruct->BaudRate); |
371 | 370 | ||
372 | /* Check BRR is greater than or equal to 16d */ |
371 | /* Check BRR is greater than or equal to 16d */ |
373 | assert_param(IS_LL_USART_BRR_MIN(USARTx->BRR)); |
372 | 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 | } |
373 | } |
378 | } |
374 | } |
379 | /* Endif (=> USART not in Disabled state => return ERROR) */ |
375 | /* Endif (=> USART not in Disabled state => return ERROR) */ |
380 | 376 | ||
381 | return (status); |
377 | return (status); |
Line 401... | Line 397... | ||
401 | } |
397 | } |
402 | 398 | ||
403 | /** |
399 | /** |
404 | * @brief Initialize USART Clock related settings according to the |
400 | * @brief Initialize USART Clock related settings according to the |
405 | * specified parameters in the USART_ClockInitStruct. |
401 | * 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), |
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 |
|
407 | * USART Peripheral should be in disabled state prior calling this function. Otherwise, ERROR result will be returned. |
404 | * this function. Otherwise, ERROR result will be returned. |
408 | * @param USARTx USART Instance |
405 | * @param USARTx USART Instance |
409 | * @param USART_ClockInitStruct pointer to a @ref LL_USART_ClockInitTypeDef structure |
406 | * @param USART_ClockInitStruct pointer to a @ref LL_USART_ClockInitTypeDef structure |
410 | * that contains the Clock configuration information for the specified USART peripheral. |
407 | * that contains the Clock configuration information for the specified USART peripheral. |
411 | * @retval An ErrorStatus enumeration value: |
408 | * @retval An ErrorStatus enumeration value: |
412 | * - SUCCESS: USART registers related to Clock settings are initialized according to USART_ClockInitStruct content |
409 | * - SUCCESS: USART registers related to Clock settings are initialized according |
- | 410 | * to USART_ClockInitStruct content |
|
413 | * - ERROR: Problem occurred during USART Registers initialization |
411 | * - ERROR: Problem occurred during USART Registers initialization |
414 | */ |
412 | */ |
415 | ErrorStatus LL_USART_ClockInit(USART_TypeDef *USARTx, LL_USART_ClockInitTypeDef *USART_ClockInitStruct) |
413 | ErrorStatus LL_USART_ClockInit(USART_TypeDef *USARTx, LL_USART_ClockInitTypeDef *USART_ClockInitStruct) |
416 | { |
414 | { |
417 | ErrorStatus status = SUCCESS; |
415 | ErrorStatus status = SUCCESS; |
Line 422... | Line 420... | ||
422 | 420 | ||
423 | /* USART needs to be in disabled state, in order to be able to configure some bits in |
421 | /* USART needs to be in disabled state, in order to be able to configure some bits in |
424 | CRx registers */ |
422 | CRx registers */ |
425 | if (LL_USART_IsEnabled(USARTx) == 0U) |
423 | if (LL_USART_IsEnabled(USARTx) == 0U) |
426 | { |
424 | { |
427 | /*---------------------------- USART CR2 Configuration -----------------------*/ |
- | |
428 | /* If Clock signal has to be output */ |
425 | /* If USART Clock signal is disabled */ |
429 | if (USART_ClockInitStruct->ClockOutput == LL_USART_CLOCK_DISABLE) |
426 | if (USART_ClockInitStruct->ClockOutput == LL_USART_CLOCK_DISABLE) |
430 | { |
427 | { |
431 | /* Deactivate Clock signal delivery : |
428 | /* Deactivate Clock signal delivery : |
432 | * - Disable Clock Output: USART_CR2_CLKEN cleared |
429 | * - Disable Clock Output: USART_CR2_CLKEN cleared |
433 | */ |
430 | */ |
Line 473... | Line 470... | ||
473 | */ |
470 | */ |
474 | void LL_USART_ClockStructInit(LL_USART_ClockInitTypeDef *USART_ClockInitStruct) |
471 | void LL_USART_ClockStructInit(LL_USART_ClockInitTypeDef *USART_ClockInitStruct) |
475 | { |
472 | { |
476 | /* Set LL_USART_ClockInitStruct fields with default values */ |
473 | /* Set LL_USART_ClockInitStruct fields with default values */ |
477 | USART_ClockInitStruct->ClockOutput = LL_USART_CLOCK_DISABLE; |
474 | USART_ClockInitStruct->ClockOutput = LL_USART_CLOCK_DISABLE; |
478 | USART_ClockInitStruct->ClockPolarity = LL_USART_POLARITY_LOW; /* Not relevant when ClockOutput = LL_USART_CLOCK_DISABLE */ |
475 | USART_ClockInitStruct->ClockPolarity = LL_USART_POLARITY_LOW; /* Not relevant when ClockOutput = |
- | 476 | LL_USART_CLOCK_DISABLE */ |
|
479 | USART_ClockInitStruct->ClockPhase = LL_USART_PHASE_1EDGE; /* Not relevant when ClockOutput = LL_USART_CLOCK_DISABLE */ |
477 | USART_ClockInitStruct->ClockPhase = LL_USART_PHASE_1EDGE; /* Not relevant when ClockOutput = |
- | 478 | LL_USART_CLOCK_DISABLE */ |
|
480 | USART_ClockInitStruct->LastBitClockPulse = LL_USART_LASTCLKPULSE_NO_OUTPUT; /* Not relevant when ClockOutput = LL_USART_CLOCK_DISABLE */ |
479 | USART_ClockInitStruct->LastBitClockPulse = LL_USART_LASTCLKPULSE_NO_OUTPUT; /* Not relevant when ClockOutput = |
- | 480 | LL_USART_CLOCK_DISABLE */ |
|
481 | } |
481 | } |
482 | 482 | ||
483 | /** |
483 | /** |
484 | * @} |
484 | * @} |
485 | */ |
485 | */ |