Subversion Repositories LedShow

Rev

Rev 2 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2 Rev 9
Line 4... Line 4...
4
  * @author  MCD Application Team
4
  * @author  MCD Application Team
5
  * @brief   USART LL module driver.
5
  * @brief   USART LL module driver.
6
  ******************************************************************************
6
  ******************************************************************************
7
  * @attention
7
  * @attention
8
  *
8
  *
9
  * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
9
  * <h2><center>&copy; Copyright (c) 2016 STMicroelectronics.
-
 
10
  * All rights reserved.</center></h2>
10
  *
11
  *
11
  * Redistribution and use in source and binary forms, with or without modification,
12
  * This software component is licensed by ST under BSD 3-Clause license,
12
  * are permitted provided that the following conditions are met:
13
  * the "License"; You may not use this file except in compliance with the
13
  *   1. Redistributions of source code must retain the above copyright notice,
-
 
14
  *      this list of conditions and the following disclaimer.
-
 
15
  *   2. Redistributions in binary form must reproduce the above copyright notice,
-
 
16
  *      this list of conditions and the following disclaimer in the documentation
-
 
17
  *      and/or other materials provided with the distribution.
14
  * License. You may obtain a copy of the License at:
18
  *   3. Neither the name of STMicroelectronics nor the names of its contributors
-
 
19
  *      may be used to endorse or promote products derived from this software
15
  *                        opensource.org/licenses/BSD-3-Clause
20
  *      without specific prior written permission.
-
 
21
  *
-
 
22
  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-
 
23
  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-
 
24
  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-
 
25
  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-
 
26
  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-
 
27
  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-
 
28
  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-
 
29
  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-
 
30
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-
 
31
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
 
32
  *
16
  *
33
  ******************************************************************************
17
  ******************************************************************************
34
  */
18
  */
-
 
19
 
35
#if defined(USE_FULL_LL_DRIVER)
20
#if defined(USE_FULL_LL_DRIVER)
36
 
21
 
37
/* Includes ------------------------------------------------------------------*/
22
/* Includes ------------------------------------------------------------------*/
38
#include "stm32f1xx_ll_usart.h"
23
#include "stm32f1xx_ll_usart.h"
39
#include "stm32f1xx_ll_rcc.h"
24
#include "stm32f1xx_ll_rcc.h"
Line 71... Line 56...
71
  * @{
56
  * @{
72
  */
57
  */
73
 
58
 
74
/* __BAUDRATE__ The maximum Baud Rate is derived from the maximum clock available
59
/* __BAUDRATE__ The maximum Baud Rate is derived from the maximum clock available
75
 *              divided by the smallest oversampling used on the USART (i.e. 8)    */
60
 *              divided by the smallest oversampling used on the USART (i.e. 8)    */
76
#define IS_LL_USART_BAUDRATE(__BAUDRATE__) ((__BAUDRATE__) <= 10000000U)
61
#define IS_LL_USART_BAUDRATE(__BAUDRATE__) ((__BAUDRATE__) <= 4500000U)
-
 
62
 
-
 
63
/* __VALUE__ In case of oversampling by 16 and 8, BRR content must be greater than or equal to 16d. */
-
 
64
#define IS_LL_USART_BRR_MIN(__VALUE__) ((__VALUE__) >= 16U)
-
 
65
 
-
 
66
/* __VALUE__ BRR content must be lower than or equal to 0xFFFF. */
-
 
67
#define IS_LL_USART_BRR_MAX(__VALUE__) ((__VALUE__) <= 0x0000FFFFU)
77
 
68
 
78
#define IS_LL_USART_DIRECTION(__VALUE__) (((__VALUE__) == LL_USART_DIRECTION_NONE) \
69
#define IS_LL_USART_DIRECTION(__VALUE__) (((__VALUE__) == LL_USART_DIRECTION_NONE) \
79
                                       || ((__VALUE__) == LL_USART_DIRECTION_RX) \
70
                                       || ((__VALUE__) == LL_USART_DIRECTION_RX) \
80
                                       || ((__VALUE__) == LL_USART_DIRECTION_TX) \
71
                                       || ((__VALUE__) == LL_USART_DIRECTION_TX) \
81
                                       || ((__VALUE__) == LL_USART_DIRECTION_TX_RX))
72
                                       || ((__VALUE__) == LL_USART_DIRECTION_TX_RX))
Line 200... Line 191...
200
  *         parameters in USART_InitStruct.
191
  *         parameters in USART_InitStruct.
201
  * @note   As some bits in USART configuration registers can only be written when the USART is disabled (USART_CR1_UE bit =0),
192
  * @note   As some bits in USART configuration registers can only be written when the USART is disabled (USART_CR1_UE bit =0),
202
  *         USART IP should be in disabled state prior calling this function. Otherwise, ERROR result will be returned.
193
  *         USART IP should be in disabled state prior calling this function. Otherwise, ERROR result will be returned.
203
  * @note   Baud rate value stored in USART_InitStruct BaudRate field, should be valid (different from 0).
194
  * @note   Baud rate value stored in USART_InitStruct BaudRate field, should be valid (different from 0).
204
  * @param  USARTx USART Instance
195
  * @param  USARTx USART Instance
205
  * @param  USART_InitStruct: pointer to a LL_USART_InitTypeDef structure
196
  * @param  USART_InitStruct pointer to a LL_USART_InitTypeDef structure
206
  *         that contains the configuration information for the specified USART peripheral.
197
  *         that contains the configuration information for the specified USART peripheral.
207
  * @retval An ErrorStatus enumeration value:
198
  * @retval An ErrorStatus enumeration value:
208
  *          - SUCCESS: USART registers are initialized according to USART_InitStruct content
199
  *          - SUCCESS: USART registers are initialized according to USART_InitStruct content
209
  *          - ERROR: Problem occurred during USART Registers initialization
200
  *          - ERROR: Problem occurred during USART Registers initialization
210
  */
201
  */
Line 315... Line 306...
315
#else
306
#else
316
      LL_USART_SetBaudRate(USARTx,
307
      LL_USART_SetBaudRate(USARTx,
317
                           periphclk,
308
                           periphclk,
318
                           USART_InitStruct->BaudRate);
309
                           USART_InitStruct->BaudRate);
319
#endif /* USART_OverSampling_Feature */
310
#endif /* USART_OverSampling_Feature */
-
 
311
 
-
 
312
      /* Check BRR is greater than or equal to 16d */
-
 
313
      assert_param(IS_LL_USART_BRR_MIN(USARTx->BRR));
-
 
314
 
-
 
315
      /* Check BRR is greater than or equal to 16d */
-
 
316
      assert_param(IS_LL_USART_BRR_MAX(USARTx->BRR));
320
    }
317
    }
321
  }
318
  }
322
  /* Endif (=> USART not in Disabled state => return ERROR) */
319
  /* Endif (=> USART not in Disabled state => return ERROR) */
323
 
320
 
324
  return (status);
321
  return (status);
325
}
322
}
326
 
323
 
327
/**
324
/**
328
  * @brief Set each @ref LL_USART_InitTypeDef field to default value.
325
  * @brief Set each @ref LL_USART_InitTypeDef field to default value.
329
  * @param USART_InitStruct: pointer to a @ref LL_USART_InitTypeDef structure
326
  * @param USART_InitStruct Pointer to a @ref LL_USART_InitTypeDef structure
330
  *                          whose fields will be set to default values.
327
  *                         whose fields will be set to default values.
331
  * @retval None
328
  * @retval None
332
  */
329
  */
333
 
330
 
334
void LL_USART_StructInit(LL_USART_InitTypeDef *USART_InitStruct)
331
void LL_USART_StructInit(LL_USART_InitTypeDef *USART_InitStruct)
335
{
332
{
Line 349... Line 346...
349
  * @brief  Initialize USART Clock related settings according to the
346
  * @brief  Initialize USART Clock related settings according to the
350
  *         specified parameters in the USART_ClockInitStruct.
347
  *         specified parameters in the USART_ClockInitStruct.
351
  * @note   As some bits in USART configuration registers can only be written when the USART is disabled (USART_CR1_UE bit =0),
348
  * @note   As some bits in USART configuration registers can only be written when the USART is disabled (USART_CR1_UE bit =0),
352
  *         USART IP should be in disabled state prior calling this function. Otherwise, ERROR result will be returned.
349
  *         USART IP should be in disabled state prior calling this function. Otherwise, ERROR result will be returned.
353
  * @param  USARTx USART Instance
350
  * @param  USARTx USART Instance
354
  * @param  USART_ClockInitStruct: pointer to a @ref LL_USART_ClockInitTypeDef structure
351
  * @param  USART_ClockInitStruct Pointer to a @ref LL_USART_ClockInitTypeDef structure
355
  *         that contains the Clock configuration information for the specified USART peripheral.
352
  *         that contains the Clock configuration information for the specified USART peripheral.
356
  * @retval An ErrorStatus enumeration value:
353
  * @retval An ErrorStatus enumeration value:
357
  *          - SUCCESS: USART registers related to Clock settings are initialized according to USART_ClockInitStruct content
354
  *          - SUCCESS: USART registers related to Clock settings are initialized according to USART_ClockInitStruct content
358
  *          - ERROR: Problem occurred during USART Registers initialization
355
  *          - ERROR: Problem occurred during USART Registers initialization
359
  */
356
  */
Line 410... Line 407...
410
  return (status);
407
  return (status);
411
}
408
}
412
 
409
 
413
/**
410
/**
414
  * @brief Set each field of a @ref LL_USART_ClockInitTypeDef type structure to default value.
411
  * @brief Set each field of a @ref LL_USART_ClockInitTypeDef type structure to default value.
415
  * @param USART_ClockInitStruct: pointer to a @ref LL_USART_ClockInitTypeDef structure
412
  * @param USART_ClockInitStruct Pointer to a @ref LL_USART_ClockInitTypeDef structure
416
  *                               whose fields will be set to default values.
413
  *                              whose fields will be set to default values.
417
  * @retval None
414
  * @retval None
418
  */
415
  */
419
void LL_USART_ClockStructInit(LL_USART_ClockInitTypeDef *USART_ClockInitStruct)
416
void LL_USART_ClockStructInit(LL_USART_ClockInitTypeDef *USART_ClockInitStruct)
420
{
417
{
421
  /* Set LL_USART_ClockInitStruct fields with default values */
418
  /* Set LL_USART_ClockInitStruct fields with default values */