mbed library sources

Dependents:   frdm_kl05z_gpio_test

Fork of mbed-src by mbed official

Committer:
mbed_official
Date:
Mon Jan 27 14:30:07 2014 +0000
Revision:
76:aeb1df146756
Child:
106:ced8cbb51063
Synchronized with git revision a31ec9c5f7bcb5c8a1b2eced103f6a1dfa921abd

Full URL: https://github.com/mbedmicro/mbed/commit/a31ec9c5f7bcb5c8a1b2eced103f6a1dfa921abd/

Add NUCLEO_L152RE

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 76:aeb1df146756 1 /**
mbed_official 76:aeb1df146756 2 ******************************************************************************
mbed_official 76:aeb1df146756 3 * @file stm32f0xx_usart.c
mbed_official 76:aeb1df146756 4 * @author MCD Application Team
mbed_official 76:aeb1df146756 5 * @version V1.3.0
mbed_official 76:aeb1df146756 6 * @date 16-January-2014
mbed_official 76:aeb1df146756 7 * @brief This file provides firmware functions to manage the following
mbed_official 76:aeb1df146756 8 * functionalities of the Universal synchronous asynchronous receiver
mbed_official 76:aeb1df146756 9 * transmitter (USART):
mbed_official 76:aeb1df146756 10 * + Initialization and Configuration
mbed_official 76:aeb1df146756 11 * + STOP Mode
mbed_official 76:aeb1df146756 12 * + AutoBaudRate
mbed_official 76:aeb1df146756 13 * + Data transfers
mbed_official 76:aeb1df146756 14 * + Multi-Processor Communication
mbed_official 76:aeb1df146756 15 * + LIN mode
mbed_official 76:aeb1df146756 16 * + Half-duplex mode
mbed_official 76:aeb1df146756 17 * + Smartcard mode
mbed_official 76:aeb1df146756 18 * + IrDA mode
mbed_official 76:aeb1df146756 19 * + RS485 mode
mbed_official 76:aeb1df146756 20 * + DMA transfers management
mbed_official 76:aeb1df146756 21 * + Interrupts and flags management
mbed_official 76:aeb1df146756 22 *
mbed_official 76:aeb1df146756 23 * @verbatim
mbed_official 76:aeb1df146756 24 ===============================================================================
mbed_official 76:aeb1df146756 25 ##### How to use this driver #####
mbed_official 76:aeb1df146756 26 ===============================================================================
mbed_official 76:aeb1df146756 27 [..]
mbed_official 76:aeb1df146756 28 (#) Enable peripheral clock using RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE)
mbed_official 76:aeb1df146756 29 function for USART1 or using RCC_APB1PeriphClockCmd(RCC_APB1Periph_USARTx, ENABLE)
mbed_official 76:aeb1df146756 30 function for USART2 and USART3.
mbed_official 76:aeb1df146756 31 (#) According to the USART mode, enable the GPIO clocks using
mbed_official 76:aeb1df146756 32 RCC_AHBPeriphClockCmd() function. (The I/O can be TX, RX, CTS,
mbed_official 76:aeb1df146756 33 or and SCLK).
mbed_official 76:aeb1df146756 34 (#) Peripheral's alternate function:
mbed_official 76:aeb1df146756 35 (++) Connect the pin to the desired peripherals' Alternate
mbed_official 76:aeb1df146756 36 Function (AF) using GPIO_PinAFConfig() function.
mbed_official 76:aeb1df146756 37 (++) Configure the desired pin in alternate function by:
mbed_official 76:aeb1df146756 38 GPIO_InitStruct->GPIO_Mode = GPIO_Mode_AF.
mbed_official 76:aeb1df146756 39 (++) Select the type, pull-up/pull-down and output speed via
mbed_official 76:aeb1df146756 40 GPIO_PuPd, GPIO_OType and GPIO_Speed members.
mbed_official 76:aeb1df146756 41 (++) Call GPIO_Init() function.
mbed_official 76:aeb1df146756 42 (#) Program the Baud Rate, Word Length , Stop Bit, Parity, Hardware
mbed_official 76:aeb1df146756 43 flow control and Mode(Receiver/Transmitter) using the SPI_Init()
mbed_official 76:aeb1df146756 44 function.
mbed_official 76:aeb1df146756 45 (#) For synchronous mode, enable the clock and program the polarity,
mbed_official 76:aeb1df146756 46 phase and last bit using the USART_ClockInit() function.
mbed_official 76:aeb1df146756 47 (#) Enable the NVIC and the corresponding interrupt using the function
mbed_official 76:aeb1df146756 48 USART_ITConfig() if you need to use interrupt mode.
mbed_official 76:aeb1df146756 49 (#) When using the DMA mode:
mbed_official 76:aeb1df146756 50 (++) Configure the DMA using DMA_Init() function.
mbed_official 76:aeb1df146756 51 (++) Active the needed channel Request using USART_DMACmd() function.
mbed_official 76:aeb1df146756 52 (#) Enable the USART using the USART_Cmd() function.
mbed_official 76:aeb1df146756 53 (#) Enable the DMA using the DMA_Cmd() function, when using DMA mode.
mbed_official 76:aeb1df146756 54 [..]
mbed_official 76:aeb1df146756 55 Refer to Multi-Processor, LIN, half-duplex, Smartcard, IrDA sub-sections
mbed_official 76:aeb1df146756 56 for more details.
mbed_official 76:aeb1df146756 57
mbed_official 76:aeb1df146756 58 @endverbatim
mbed_official 76:aeb1df146756 59
mbed_official 76:aeb1df146756 60 ******************************************************************************
mbed_official 76:aeb1df146756 61 * @attention
mbed_official 76:aeb1df146756 62 *
mbed_official 76:aeb1df146756 63 * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
mbed_official 76:aeb1df146756 64 *
mbed_official 76:aeb1df146756 65 * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
mbed_official 76:aeb1df146756 66 * You may not use this file except in compliance with the License.
mbed_official 76:aeb1df146756 67 * You may obtain a copy of the License at:
mbed_official 76:aeb1df146756 68 *
mbed_official 76:aeb1df146756 69 * http://www.st.com/software_license_agreement_liberty_v2
mbed_official 76:aeb1df146756 70 *
mbed_official 76:aeb1df146756 71 * Unless required by applicable law or agreed to in writing, software
mbed_official 76:aeb1df146756 72 * distributed under the License is distributed on an "AS IS" BASIS,
mbed_official 76:aeb1df146756 73 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
mbed_official 76:aeb1df146756 74 * See the License for the specific language governing permissions and
mbed_official 76:aeb1df146756 75 * limitations under the License.
mbed_official 76:aeb1df146756 76 *
mbed_official 76:aeb1df146756 77 ******************************************************************************
mbed_official 76:aeb1df146756 78 */
mbed_official 76:aeb1df146756 79
mbed_official 76:aeb1df146756 80 /* Includes ------------------------------------------------------------------*/
mbed_official 76:aeb1df146756 81 #include "stm32f0xx_usart.h"
mbed_official 76:aeb1df146756 82 #include "stm32f0xx_rcc.h"
mbed_official 76:aeb1df146756 83
mbed_official 76:aeb1df146756 84 /** @addtogroup STM32F0xx_StdPeriph_Driver
mbed_official 76:aeb1df146756 85 * @{
mbed_official 76:aeb1df146756 86 */
mbed_official 76:aeb1df146756 87
mbed_official 76:aeb1df146756 88 /** @defgroup USART
mbed_official 76:aeb1df146756 89 * @brief USART driver modules
mbed_official 76:aeb1df146756 90 * @{
mbed_official 76:aeb1df146756 91 */
mbed_official 76:aeb1df146756 92
mbed_official 76:aeb1df146756 93 /* Private typedef -----------------------------------------------------------*/
mbed_official 76:aeb1df146756 94 /* Private define ------------------------------------------------------------*/
mbed_official 76:aeb1df146756 95
mbed_official 76:aeb1df146756 96 /*!< USART CR1 register clear Mask ((~(uint32_t)0xFFFFE6F3)) */
mbed_official 76:aeb1df146756 97 #define CR1_CLEAR_MASK ((uint32_t)(USART_CR1_M | USART_CR1_PCE | \
mbed_official 76:aeb1df146756 98 USART_CR1_PS | USART_CR1_TE | \
mbed_official 76:aeb1df146756 99 USART_CR1_RE))
mbed_official 76:aeb1df146756 100
mbed_official 76:aeb1df146756 101 /*!< USART CR2 register clock bits clear Mask ((~(uint32_t)0xFFFFF0FF)) */
mbed_official 76:aeb1df146756 102 #define CR2_CLOCK_CLEAR_MASK ((uint32_t)(USART_CR2_CLKEN | USART_CR2_CPOL | \
mbed_official 76:aeb1df146756 103 USART_CR2_CPHA | USART_CR2_LBCL))
mbed_official 76:aeb1df146756 104
mbed_official 76:aeb1df146756 105 /*!< USART CR3 register clear Mask ((~(uint32_t)0xFFFFFCFF)) */
mbed_official 76:aeb1df146756 106 #define CR3_CLEAR_MASK ((uint32_t)(USART_CR3_RTSE | USART_CR3_CTSE))
mbed_official 76:aeb1df146756 107
mbed_official 76:aeb1df146756 108 /*!< USART Interrupts mask */
mbed_official 76:aeb1df146756 109 #define IT_MASK ((uint32_t)0x000000FF)
mbed_official 76:aeb1df146756 110
mbed_official 76:aeb1df146756 111 /* Private macro -------------------------------------------------------------*/
mbed_official 76:aeb1df146756 112 /* Private variables ---------------------------------------------------------*/
mbed_official 76:aeb1df146756 113 /* Private function prototypes -----------------------------------------------*/
mbed_official 76:aeb1df146756 114 /* Private functions ---------------------------------------------------------*/
mbed_official 76:aeb1df146756 115
mbed_official 76:aeb1df146756 116 /** @defgroup USART_Private_Functions
mbed_official 76:aeb1df146756 117 * @{
mbed_official 76:aeb1df146756 118 */
mbed_official 76:aeb1df146756 119
mbed_official 76:aeb1df146756 120 /** @defgroup USART_Group1 Initialization and Configuration functions
mbed_official 76:aeb1df146756 121 * @brief Initialization and Configuration functions
mbed_official 76:aeb1df146756 122 *
mbed_official 76:aeb1df146756 123 @verbatim
mbed_official 76:aeb1df146756 124 ===============================================================================
mbed_official 76:aeb1df146756 125 ##### Initialization and Configuration functions #####
mbed_official 76:aeb1df146756 126 ===============================================================================
mbed_official 76:aeb1df146756 127 [..]
mbed_official 76:aeb1df146756 128 This subsection provides a set of functions allowing to initialize the USART
mbed_official 76:aeb1df146756 129 in asynchronous and in synchronous modes.
mbed_official 76:aeb1df146756 130 (+) For the asynchronous mode only these parameters can be configured:
mbed_official 76:aeb1df146756 131 (++) Baud Rate.
mbed_official 76:aeb1df146756 132 (++) Word Length.
mbed_official 76:aeb1df146756 133 (++) Stop Bit.
mbed_official 76:aeb1df146756 134 (++) Parity: If the parity is enabled, then the MSB bit of the data written
mbed_official 76:aeb1df146756 135 in the data register is transmitted but is changed by the parity bit.
mbed_official 76:aeb1df146756 136 Depending on the frame length defined by the M bit (8-bits or 9-bits),
mbed_official 76:aeb1df146756 137 the possible USART frame formats are as listed in the following table:
mbed_official 76:aeb1df146756 138
mbed_official 76:aeb1df146756 139 +-------------------------------------------------------------+
mbed_official 76:aeb1df146756 140 | M bit | PCE bit | USART frame |
mbed_official 76:aeb1df146756 141 |---------------------|---------------------------------------|
mbed_official 76:aeb1df146756 142 | 0 | 0 | | SB | 8 bit data | STB | |
mbed_official 76:aeb1df146756 143 |---------|-----------|---------------------------------------|
mbed_official 76:aeb1df146756 144 | 0 | 1 | | SB | 7 bit data | PB | STB | |
mbed_official 76:aeb1df146756 145 |---------|-----------|---------------------------------------|
mbed_official 76:aeb1df146756 146 | 1 | 0 | | SB | 9 bit data | STB | |
mbed_official 76:aeb1df146756 147 |---------|-----------|---------------------------------------|
mbed_official 76:aeb1df146756 148 | 1 | 1 | | SB | 8 bit data | PB | STB | |
mbed_official 76:aeb1df146756 149 +-------------------------------------------------------------+
mbed_official 76:aeb1df146756 150
mbed_official 76:aeb1df146756 151 (++) Hardware flow control.
mbed_official 76:aeb1df146756 152 (++) Receiver/transmitter modes.
mbed_official 76:aeb1df146756 153 [..] The USART_Init() function follows the USART asynchronous configuration
mbed_official 76:aeb1df146756 154 procedure(details for the procedure are available in reference manual.
mbed_official 76:aeb1df146756 155 (+) For the synchronous mode in addition to the asynchronous mode parameters
mbed_official 76:aeb1df146756 156 these parameters should be also configured:
mbed_official 76:aeb1df146756 157 (++) USART Clock Enabled.
mbed_official 76:aeb1df146756 158 (++) USART polarity.
mbed_official 76:aeb1df146756 159 (++) USART phase.
mbed_official 76:aeb1df146756 160 (++) USART LastBit.
mbed_official 76:aeb1df146756 161 [..] These parameters can be configured using the USART_ClockInit() function.
mbed_official 76:aeb1df146756 162
mbed_official 76:aeb1df146756 163 @endverbatim
mbed_official 76:aeb1df146756 164 * @{
mbed_official 76:aeb1df146756 165 */
mbed_official 76:aeb1df146756 166
mbed_official 76:aeb1df146756 167 /**
mbed_official 76:aeb1df146756 168 * @brief Deinitializes the USARTx peripheral registers to their default reset values.
mbed_official 76:aeb1df146756 169 * @param USARTx: where x can be 1, 2, 3 or 4 to select the USART peripheral.
mbed_official 76:aeb1df146756 170 * @note USART3 and USART4 are available only for STM32F072 devices.
mbed_official 76:aeb1df146756 171 * @note USART2 is not available for STM32F031 devices.
mbed_official 76:aeb1df146756 172 * @retval None
mbed_official 76:aeb1df146756 173 */
mbed_official 76:aeb1df146756 174 void USART_DeInit(USART_TypeDef* USARTx)
mbed_official 76:aeb1df146756 175 {
mbed_official 76:aeb1df146756 176 /* Check the parameters */
mbed_official 76:aeb1df146756 177 assert_param(IS_USART_ALL_PERIPH(USARTx));
mbed_official 76:aeb1df146756 178
mbed_official 76:aeb1df146756 179 if (USARTx == USART1)
mbed_official 76:aeb1df146756 180 {
mbed_official 76:aeb1df146756 181 RCC_APB2PeriphResetCmd(RCC_APB2Periph_USART1, ENABLE);
mbed_official 76:aeb1df146756 182 RCC_APB2PeriphResetCmd(RCC_APB2Periph_USART1, DISABLE);
mbed_official 76:aeb1df146756 183 }
mbed_official 76:aeb1df146756 184 else if (USARTx == USART2)
mbed_official 76:aeb1df146756 185 {
mbed_official 76:aeb1df146756 186 RCC_APB1PeriphResetCmd(RCC_APB1Periph_USART2, ENABLE);
mbed_official 76:aeb1df146756 187 RCC_APB1PeriphResetCmd(RCC_APB1Periph_USART2, DISABLE);
mbed_official 76:aeb1df146756 188 }
mbed_official 76:aeb1df146756 189 else if (USARTx == USART3)
mbed_official 76:aeb1df146756 190 {
mbed_official 76:aeb1df146756 191 RCC_APB1PeriphResetCmd(RCC_APB1Periph_USART3, ENABLE);
mbed_official 76:aeb1df146756 192 RCC_APB1PeriphResetCmd(RCC_APB1Periph_USART3, DISABLE);
mbed_official 76:aeb1df146756 193 }
mbed_official 76:aeb1df146756 194 else
mbed_official 76:aeb1df146756 195 {
mbed_official 76:aeb1df146756 196 if (USARTx == USART4)
mbed_official 76:aeb1df146756 197 {
mbed_official 76:aeb1df146756 198 RCC_APB1PeriphResetCmd(RCC_APB1Periph_USART4, ENABLE);
mbed_official 76:aeb1df146756 199 RCC_APB1PeriphResetCmd(RCC_APB1Periph_USART4, DISABLE);
mbed_official 76:aeb1df146756 200 }
mbed_official 76:aeb1df146756 201 }
mbed_official 76:aeb1df146756 202 }
mbed_official 76:aeb1df146756 203
mbed_official 76:aeb1df146756 204 /**
mbed_official 76:aeb1df146756 205 * @brief Initializes the USARTx peripheral according to the specified
mbed_official 76:aeb1df146756 206 * parameters in the USART_InitStruct .
mbed_official 76:aeb1df146756 207 * @param USARTx: where x can be 1, 2, 3 or 4 to select the USART peripheral.
mbed_official 76:aeb1df146756 208 * @note USART3 and USART4 are available only for STM32F072 devices.
mbed_official 76:aeb1df146756 209 * @note USART2 is not available for STM32F031 devices.
mbed_official 76:aeb1df146756 210 * @param USART_InitStruct: pointer to a USART_InitTypeDef structure that contains
mbed_official 76:aeb1df146756 211 * the configuration information for the specified USART peripheral.
mbed_official 76:aeb1df146756 212 * @retval None
mbed_official 76:aeb1df146756 213 */
mbed_official 76:aeb1df146756 214 void USART_Init(USART_TypeDef* USARTx, USART_InitTypeDef* USART_InitStruct)
mbed_official 76:aeb1df146756 215 {
mbed_official 76:aeb1df146756 216 uint32_t divider = 0, apbclock = 0, tmpreg = 0;
mbed_official 76:aeb1df146756 217 RCC_ClocksTypeDef RCC_ClocksStatus;
mbed_official 76:aeb1df146756 218
mbed_official 76:aeb1df146756 219 /* Check the parameters */
mbed_official 76:aeb1df146756 220 assert_param(IS_USART_ALL_PERIPH(USARTx));
mbed_official 76:aeb1df146756 221 assert_param(IS_USART_BAUDRATE(USART_InitStruct->USART_BaudRate));
mbed_official 76:aeb1df146756 222 assert_param(IS_USART_WORD_LENGTH(USART_InitStruct->USART_WordLength));
mbed_official 76:aeb1df146756 223 assert_param(IS_USART_STOPBITS(USART_InitStruct->USART_StopBits));
mbed_official 76:aeb1df146756 224 assert_param(IS_USART_PARITY(USART_InitStruct->USART_Parity));
mbed_official 76:aeb1df146756 225 assert_param(IS_USART_MODE(USART_InitStruct->USART_Mode));
mbed_official 76:aeb1df146756 226 assert_param(IS_USART_HARDWARE_FLOW_CONTROL(USART_InitStruct->USART_HardwareFlowControl));
mbed_official 76:aeb1df146756 227
mbed_official 76:aeb1df146756 228 /* Disable USART */
mbed_official 76:aeb1df146756 229 USARTx->CR1 &= (uint32_t)~((uint32_t)USART_CR1_UE);
mbed_official 76:aeb1df146756 230
mbed_official 76:aeb1df146756 231 /*---------------------------- USART CR2 Configuration -----------------------*/
mbed_official 76:aeb1df146756 232 tmpreg = USARTx->CR2;
mbed_official 76:aeb1df146756 233 /* Clear STOP[13:12] bits */
mbed_official 76:aeb1df146756 234 tmpreg &= (uint32_t)~((uint32_t)USART_CR2_STOP);
mbed_official 76:aeb1df146756 235
mbed_official 76:aeb1df146756 236 /* Configure the USART Stop Bits, Clock, CPOL, CPHA and LastBit ------------*/
mbed_official 76:aeb1df146756 237 /* Set STOP[13:12] bits according to USART_StopBits value */
mbed_official 76:aeb1df146756 238 tmpreg |= (uint32_t)USART_InitStruct->USART_StopBits;
mbed_official 76:aeb1df146756 239
mbed_official 76:aeb1df146756 240 /* Write to USART CR2 */
mbed_official 76:aeb1df146756 241 USARTx->CR2 = tmpreg;
mbed_official 76:aeb1df146756 242
mbed_official 76:aeb1df146756 243 /*---------------------------- USART CR1 Configuration -----------------------*/
mbed_official 76:aeb1df146756 244 tmpreg = USARTx->CR1;
mbed_official 76:aeb1df146756 245 /* Clear M, PCE, PS, TE and RE bits */
mbed_official 76:aeb1df146756 246 tmpreg &= (uint32_t)~((uint32_t)CR1_CLEAR_MASK);
mbed_official 76:aeb1df146756 247
mbed_official 76:aeb1df146756 248 /* Configure the USART Word Length, Parity and mode ----------------------- */
mbed_official 76:aeb1df146756 249 /* Set the M bits according to USART_WordLength value */
mbed_official 76:aeb1df146756 250 /* Set PCE and PS bits according to USART_Parity value */
mbed_official 76:aeb1df146756 251 /* Set TE and RE bits according to USART_Mode value */
mbed_official 76:aeb1df146756 252 tmpreg |= (uint32_t)USART_InitStruct->USART_WordLength | USART_InitStruct->USART_Parity |
mbed_official 76:aeb1df146756 253 USART_InitStruct->USART_Mode;
mbed_official 76:aeb1df146756 254
mbed_official 76:aeb1df146756 255 /* Write to USART CR1 */
mbed_official 76:aeb1df146756 256 USARTx->CR1 = tmpreg;
mbed_official 76:aeb1df146756 257
mbed_official 76:aeb1df146756 258 /*---------------------------- USART CR3 Configuration -----------------------*/
mbed_official 76:aeb1df146756 259 tmpreg = USARTx->CR3;
mbed_official 76:aeb1df146756 260 /* Clear CTSE and RTSE bits */
mbed_official 76:aeb1df146756 261 tmpreg &= (uint32_t)~((uint32_t)CR3_CLEAR_MASK);
mbed_official 76:aeb1df146756 262
mbed_official 76:aeb1df146756 263 /* Configure the USART HFC -------------------------------------------------*/
mbed_official 76:aeb1df146756 264 /* Set CTSE and RTSE bits according to USART_HardwareFlowControl value */
mbed_official 76:aeb1df146756 265 tmpreg |= USART_InitStruct->USART_HardwareFlowControl;
mbed_official 76:aeb1df146756 266
mbed_official 76:aeb1df146756 267 /* Write to USART CR3 */
mbed_official 76:aeb1df146756 268 USARTx->CR3 = tmpreg;
mbed_official 76:aeb1df146756 269
mbed_official 76:aeb1df146756 270 /*---------------------------- USART BRR Configuration -----------------------*/
mbed_official 76:aeb1df146756 271 /* Configure the USART Baud Rate -------------------------------------------*/
mbed_official 76:aeb1df146756 272 RCC_GetClocksFreq(&RCC_ClocksStatus);
mbed_official 76:aeb1df146756 273
mbed_official 76:aeb1df146756 274 if (USARTx == USART1)
mbed_official 76:aeb1df146756 275 {
mbed_official 76:aeb1df146756 276 apbclock = RCC_ClocksStatus.USART1CLK_Frequency;
mbed_official 76:aeb1df146756 277 }
mbed_official 76:aeb1df146756 278 else if (USARTx == USART2)
mbed_official 76:aeb1df146756 279 {
mbed_official 76:aeb1df146756 280 apbclock = RCC_ClocksStatus.USART2CLK_Frequency;
mbed_official 76:aeb1df146756 281 }
mbed_official 76:aeb1df146756 282 else
mbed_official 76:aeb1df146756 283 {
mbed_official 76:aeb1df146756 284 apbclock = RCC_ClocksStatus.PCLK_Frequency;
mbed_official 76:aeb1df146756 285 }
mbed_official 76:aeb1df146756 286
mbed_official 76:aeb1df146756 287 /* Determine the integer part */
mbed_official 76:aeb1df146756 288 if ((USARTx->CR1 & USART_CR1_OVER8) != 0)
mbed_official 76:aeb1df146756 289 {
mbed_official 76:aeb1df146756 290 /* (divider * 10) computing in case Oversampling mode is 8 Samples */
mbed_official 76:aeb1df146756 291 divider = (uint32_t)((2 * apbclock) / (USART_InitStruct->USART_BaudRate));
mbed_official 76:aeb1df146756 292 tmpreg = (uint32_t)((2 * apbclock) % (USART_InitStruct->USART_BaudRate));
mbed_official 76:aeb1df146756 293 }
mbed_official 76:aeb1df146756 294 else /* if ((USARTx->CR1 & CR1_OVER8_Set) == 0) */
mbed_official 76:aeb1df146756 295 {
mbed_official 76:aeb1df146756 296 /* (divider * 10) computing in case Oversampling mode is 16 Samples */
mbed_official 76:aeb1df146756 297 divider = (uint32_t)((apbclock) / (USART_InitStruct->USART_BaudRate));
mbed_official 76:aeb1df146756 298 tmpreg = (uint32_t)((apbclock) % (USART_InitStruct->USART_BaudRate));
mbed_official 76:aeb1df146756 299 }
mbed_official 76:aeb1df146756 300
mbed_official 76:aeb1df146756 301 /* round the divider : if fractional part i greater than 0.5 increment divider */
mbed_official 76:aeb1df146756 302 if (tmpreg >= (USART_InitStruct->USART_BaudRate) / 2)
mbed_official 76:aeb1df146756 303 {
mbed_official 76:aeb1df146756 304 divider++;
mbed_official 76:aeb1df146756 305 }
mbed_official 76:aeb1df146756 306
mbed_official 76:aeb1df146756 307 /* Implement the divider in case Oversampling mode is 8 Samples */
mbed_official 76:aeb1df146756 308 if ((USARTx->CR1 & USART_CR1_OVER8) != 0)
mbed_official 76:aeb1df146756 309 {
mbed_official 76:aeb1df146756 310 /* get the LSB of divider and shift it to the right by 1 bit */
mbed_official 76:aeb1df146756 311 tmpreg = (divider & (uint16_t)0x000F) >> 1;
mbed_official 76:aeb1df146756 312
mbed_official 76:aeb1df146756 313 /* update the divider value */
mbed_official 76:aeb1df146756 314 divider = (divider & (uint16_t)0xFFF0) | tmpreg;
mbed_official 76:aeb1df146756 315 }
mbed_official 76:aeb1df146756 316
mbed_official 76:aeb1df146756 317 /* Write to USART BRR */
mbed_official 76:aeb1df146756 318 USARTx->BRR = (uint16_t)divider;
mbed_official 76:aeb1df146756 319 }
mbed_official 76:aeb1df146756 320
mbed_official 76:aeb1df146756 321 /**
mbed_official 76:aeb1df146756 322 * @brief Fills each USART_InitStruct member with its default value.
mbed_official 76:aeb1df146756 323 * @param USART_InitStruct: pointer to a USART_InitTypeDef structure
mbed_official 76:aeb1df146756 324 * which will be initialized.
mbed_official 76:aeb1df146756 325 * @retval None
mbed_official 76:aeb1df146756 326 */
mbed_official 76:aeb1df146756 327 void USART_StructInit(USART_InitTypeDef* USART_InitStruct)
mbed_official 76:aeb1df146756 328 {
mbed_official 76:aeb1df146756 329 /* USART_InitStruct members default value */
mbed_official 76:aeb1df146756 330 USART_InitStruct->USART_BaudRate = 9600;
mbed_official 76:aeb1df146756 331 USART_InitStruct->USART_WordLength = USART_WordLength_8b;
mbed_official 76:aeb1df146756 332 USART_InitStruct->USART_StopBits = USART_StopBits_1;
mbed_official 76:aeb1df146756 333 USART_InitStruct->USART_Parity = USART_Parity_No ;
mbed_official 76:aeb1df146756 334 USART_InitStruct->USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
mbed_official 76:aeb1df146756 335 USART_InitStruct->USART_HardwareFlowControl = USART_HardwareFlowControl_None;
mbed_official 76:aeb1df146756 336 }
mbed_official 76:aeb1df146756 337
mbed_official 76:aeb1df146756 338 /**
mbed_official 76:aeb1df146756 339 * @brief Initializes the USARTx peripheral Clock according to the
mbed_official 76:aeb1df146756 340 * specified parameters in the USART_ClockInitStruct.
mbed_official 76:aeb1df146756 341 * @param USARTx: where x can be 1, 2, 3 or 4 to select the USART peripheral.
mbed_official 76:aeb1df146756 342 * @note USART3 and USART4 are available only for STM32F072 devices.
mbed_official 76:aeb1df146756 343 * @note USART2 is not available for STM32F031 devices.
mbed_official 76:aeb1df146756 344 * @param USART_ClockInitStruct: pointer to a USART_ClockInitTypeDef
mbed_official 76:aeb1df146756 345 * structure that contains the configuration information for the specified
mbed_official 76:aeb1df146756 346 * USART peripheral.
mbed_official 76:aeb1df146756 347 * @retval None
mbed_official 76:aeb1df146756 348 */
mbed_official 76:aeb1df146756 349 void USART_ClockInit(USART_TypeDef* USARTx, USART_ClockInitTypeDef* USART_ClockInitStruct)
mbed_official 76:aeb1df146756 350 {
mbed_official 76:aeb1df146756 351 uint32_t tmpreg = 0;
mbed_official 76:aeb1df146756 352 /* Check the parameters */
mbed_official 76:aeb1df146756 353 assert_param(IS_USART_ALL_PERIPH(USARTx));
mbed_official 76:aeb1df146756 354 assert_param(IS_USART_CLOCK(USART_ClockInitStruct->USART_Clock));
mbed_official 76:aeb1df146756 355 assert_param(IS_USART_CPOL(USART_ClockInitStruct->USART_CPOL));
mbed_official 76:aeb1df146756 356 assert_param(IS_USART_CPHA(USART_ClockInitStruct->USART_CPHA));
mbed_official 76:aeb1df146756 357 assert_param(IS_USART_LASTBIT(USART_ClockInitStruct->USART_LastBit));
mbed_official 76:aeb1df146756 358 /*---------------------------- USART CR2 Configuration -----------------------*/
mbed_official 76:aeb1df146756 359 tmpreg = USARTx->CR2;
mbed_official 76:aeb1df146756 360 /* Clear CLKEN, CPOL, CPHA, LBCL and SSM bits */
mbed_official 76:aeb1df146756 361 tmpreg &= (uint32_t)~((uint32_t)CR2_CLOCK_CLEAR_MASK);
mbed_official 76:aeb1df146756 362 /* Configure the USART Clock, CPOL, CPHA, LastBit and SSM ------------*/
mbed_official 76:aeb1df146756 363 /* Set CLKEN bit according to USART_Clock value */
mbed_official 76:aeb1df146756 364 /* Set CPOL bit according to USART_CPOL value */
mbed_official 76:aeb1df146756 365 /* Set CPHA bit according to USART_CPHA value */
mbed_official 76:aeb1df146756 366 /* Set LBCL bit according to USART_LastBit value */
mbed_official 76:aeb1df146756 367 tmpreg |= (uint32_t)(USART_ClockInitStruct->USART_Clock | USART_ClockInitStruct->USART_CPOL |
mbed_official 76:aeb1df146756 368 USART_ClockInitStruct->USART_CPHA | USART_ClockInitStruct->USART_LastBit);
mbed_official 76:aeb1df146756 369 /* Write to USART CR2 */
mbed_official 76:aeb1df146756 370 USARTx->CR2 = tmpreg;
mbed_official 76:aeb1df146756 371 }
mbed_official 76:aeb1df146756 372
mbed_official 76:aeb1df146756 373 /**
mbed_official 76:aeb1df146756 374 * @brief Fills each USART_ClockInitStruct member with its default value.
mbed_official 76:aeb1df146756 375 * @param USART_ClockInitStruct: pointer to a USART_ClockInitTypeDef
mbed_official 76:aeb1df146756 376 * structure which will be initialized.
mbed_official 76:aeb1df146756 377 * @retval None
mbed_official 76:aeb1df146756 378 */
mbed_official 76:aeb1df146756 379 void USART_ClockStructInit(USART_ClockInitTypeDef* USART_ClockInitStruct)
mbed_official 76:aeb1df146756 380 {
mbed_official 76:aeb1df146756 381 /* USART_ClockInitStruct members default value */
mbed_official 76:aeb1df146756 382 USART_ClockInitStruct->USART_Clock = USART_Clock_Disable;
mbed_official 76:aeb1df146756 383 USART_ClockInitStruct->USART_CPOL = USART_CPOL_Low;
mbed_official 76:aeb1df146756 384 USART_ClockInitStruct->USART_CPHA = USART_CPHA_1Edge;
mbed_official 76:aeb1df146756 385 USART_ClockInitStruct->USART_LastBit = USART_LastBit_Disable;
mbed_official 76:aeb1df146756 386 }
mbed_official 76:aeb1df146756 387
mbed_official 76:aeb1df146756 388 /**
mbed_official 76:aeb1df146756 389 * @brief Enables or disables the specified USART peripheral.
mbed_official 76:aeb1df146756 390 * @param USARTx: where x can be 1, 2, 3 or 4 to select the USART peripheral.
mbed_official 76:aeb1df146756 391 * @note USART3 and USART4 are available only for STM32F072 devices.
mbed_official 76:aeb1df146756 392 * @note USART2 is not available for STM32F031 devices.
mbed_official 76:aeb1df146756 393 * @param NewState: new state of the USARTx peripheral.
mbed_official 76:aeb1df146756 394 * This parameter can be: ENABLE or DISABLE.
mbed_official 76:aeb1df146756 395 * @retval None
mbed_official 76:aeb1df146756 396 */
mbed_official 76:aeb1df146756 397 void USART_Cmd(USART_TypeDef* USARTx, FunctionalState NewState)
mbed_official 76:aeb1df146756 398 {
mbed_official 76:aeb1df146756 399 /* Check the parameters */
mbed_official 76:aeb1df146756 400 assert_param(IS_USART_ALL_PERIPH(USARTx));
mbed_official 76:aeb1df146756 401 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 76:aeb1df146756 402
mbed_official 76:aeb1df146756 403 if (NewState != DISABLE)
mbed_official 76:aeb1df146756 404 {
mbed_official 76:aeb1df146756 405 /* Enable the selected USART by setting the UE bit in the CR1 register */
mbed_official 76:aeb1df146756 406 USARTx->CR1 |= USART_CR1_UE;
mbed_official 76:aeb1df146756 407 }
mbed_official 76:aeb1df146756 408 else
mbed_official 76:aeb1df146756 409 {
mbed_official 76:aeb1df146756 410 /* Disable the selected USART by clearing the UE bit in the CR1 register */
mbed_official 76:aeb1df146756 411 USARTx->CR1 &= (uint32_t)~((uint32_t)USART_CR1_UE);
mbed_official 76:aeb1df146756 412 }
mbed_official 76:aeb1df146756 413 }
mbed_official 76:aeb1df146756 414
mbed_official 76:aeb1df146756 415 /**
mbed_official 76:aeb1df146756 416 * @brief Enables or disables the USART's transmitter or receiver.
mbed_official 76:aeb1df146756 417 * @param USARTx: where x can be 1, 2, 3 or 4 to select the USART peripheral.
mbed_official 76:aeb1df146756 418 * @note USART3 and USART4 are available only for STM32F072 devices.
mbed_official 76:aeb1df146756 419 * @note USART2 is not available for STM32F031 devices.
mbed_official 76:aeb1df146756 420 * @param USART_Direction: specifies the USART direction.
mbed_official 76:aeb1df146756 421 * This parameter can be any combination of the following values:
mbed_official 76:aeb1df146756 422 * @arg USART_Mode_Tx: USART Transmitter
mbed_official 76:aeb1df146756 423 * @arg USART_Mode_Rx: USART Receiver
mbed_official 76:aeb1df146756 424 * @param NewState: new state of the USART transfer direction.
mbed_official 76:aeb1df146756 425 * This parameter can be: ENABLE or DISABLE.
mbed_official 76:aeb1df146756 426 * @retval None
mbed_official 76:aeb1df146756 427 */
mbed_official 76:aeb1df146756 428 void USART_DirectionModeCmd(USART_TypeDef* USARTx, uint32_t USART_DirectionMode, FunctionalState NewState)
mbed_official 76:aeb1df146756 429 {
mbed_official 76:aeb1df146756 430 /* Check the parameters */
mbed_official 76:aeb1df146756 431 assert_param(IS_USART_ALL_PERIPH(USARTx));
mbed_official 76:aeb1df146756 432 assert_param(IS_USART_MODE(USART_DirectionMode));
mbed_official 76:aeb1df146756 433 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 76:aeb1df146756 434
mbed_official 76:aeb1df146756 435 if (NewState != DISABLE)
mbed_official 76:aeb1df146756 436 {
mbed_official 76:aeb1df146756 437 /* Enable the USART's transfer interface by setting the TE and/or RE bits
mbed_official 76:aeb1df146756 438 in the USART CR1 register */
mbed_official 76:aeb1df146756 439 USARTx->CR1 |= USART_DirectionMode;
mbed_official 76:aeb1df146756 440 }
mbed_official 76:aeb1df146756 441 else
mbed_official 76:aeb1df146756 442 {
mbed_official 76:aeb1df146756 443 /* Disable the USART's transfer interface by clearing the TE and/or RE bits
mbed_official 76:aeb1df146756 444 in the USART CR3 register */
mbed_official 76:aeb1df146756 445 USARTx->CR1 &= (uint32_t)~USART_DirectionMode;
mbed_official 76:aeb1df146756 446 }
mbed_official 76:aeb1df146756 447 }
mbed_official 76:aeb1df146756 448
mbed_official 76:aeb1df146756 449 /**
mbed_official 76:aeb1df146756 450 * @brief Enables or disables the USART's 8x oversampling mode.
mbed_official 76:aeb1df146756 451 * @param USARTx: where x can be 1, 2, 3 or 4 to select the USART peripheral.
mbed_official 76:aeb1df146756 452 * @note USART3 and USART4 are available only for STM32F072 devices.
mbed_official 76:aeb1df146756 453 * @note USART2 is not available for STM32F031 devices.
mbed_official 76:aeb1df146756 454 * @param NewState: new state of the USART 8x oversampling mode.
mbed_official 76:aeb1df146756 455 * This parameter can be: ENABLE or DISABLE.
mbed_official 76:aeb1df146756 456 * @note This function has to be called before calling USART_Init() function
mbed_official 76:aeb1df146756 457 * in order to have correct baudrate Divider value.
mbed_official 76:aeb1df146756 458 * @retval None
mbed_official 76:aeb1df146756 459 */
mbed_official 76:aeb1df146756 460 void USART_OverSampling8Cmd(USART_TypeDef* USARTx, FunctionalState NewState)
mbed_official 76:aeb1df146756 461 {
mbed_official 76:aeb1df146756 462 /* Check the parameters */
mbed_official 76:aeb1df146756 463 assert_param(IS_USART_ALL_PERIPH(USARTx));
mbed_official 76:aeb1df146756 464 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 76:aeb1df146756 465
mbed_official 76:aeb1df146756 466 if (NewState != DISABLE)
mbed_official 76:aeb1df146756 467 {
mbed_official 76:aeb1df146756 468 /* Enable the 8x Oversampling mode by setting the OVER8 bit in the CR1 register */
mbed_official 76:aeb1df146756 469 USARTx->CR1 |= USART_CR1_OVER8;
mbed_official 76:aeb1df146756 470 }
mbed_official 76:aeb1df146756 471 else
mbed_official 76:aeb1df146756 472 {
mbed_official 76:aeb1df146756 473 /* Disable the 8x Oversampling mode by clearing the OVER8 bit in the CR1 register */
mbed_official 76:aeb1df146756 474 USARTx->CR1 &= (uint32_t)~((uint32_t)USART_CR1_OVER8);
mbed_official 76:aeb1df146756 475 }
mbed_official 76:aeb1df146756 476 }
mbed_official 76:aeb1df146756 477
mbed_official 76:aeb1df146756 478 /**
mbed_official 76:aeb1df146756 479 * @brief Enables or disables the USART's one bit sampling method.
mbed_official 76:aeb1df146756 480 * @param USARTx: where x can be 1, 2, 3 or 4 to select the USART peripheral.
mbed_official 76:aeb1df146756 481 * @note USART3 and USART4 are available only for STM32F072 devices.
mbed_official 76:aeb1df146756 482 * @note USART2 is not available for STM32F031 devices.
mbed_official 76:aeb1df146756 483 * @param NewState: new state of the USART one bit sampling method.
mbed_official 76:aeb1df146756 484 * This parameter can be: ENABLE or DISABLE.
mbed_official 76:aeb1df146756 485 * @note This function has to be called before calling USART_Cmd() function.
mbed_official 76:aeb1df146756 486 * @retval None
mbed_official 76:aeb1df146756 487 */
mbed_official 76:aeb1df146756 488 void USART_OneBitMethodCmd(USART_TypeDef* USARTx, FunctionalState NewState)
mbed_official 76:aeb1df146756 489 {
mbed_official 76:aeb1df146756 490 /* Check the parameters */
mbed_official 76:aeb1df146756 491 assert_param(IS_USART_ALL_PERIPH(USARTx));
mbed_official 76:aeb1df146756 492 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 76:aeb1df146756 493
mbed_official 76:aeb1df146756 494 if (NewState != DISABLE)
mbed_official 76:aeb1df146756 495 {
mbed_official 76:aeb1df146756 496 /* Enable the one bit method by setting the ONEBITE bit in the CR3 register */
mbed_official 76:aeb1df146756 497 USARTx->CR3 |= USART_CR3_ONEBIT;
mbed_official 76:aeb1df146756 498 }
mbed_official 76:aeb1df146756 499 else
mbed_official 76:aeb1df146756 500 {
mbed_official 76:aeb1df146756 501 /* Disable the one bit method by clearing the ONEBITE bit in the CR3 register */
mbed_official 76:aeb1df146756 502 USARTx->CR3 &= (uint32_t)~((uint32_t)USART_CR3_ONEBIT);
mbed_official 76:aeb1df146756 503 }
mbed_official 76:aeb1df146756 504 }
mbed_official 76:aeb1df146756 505
mbed_official 76:aeb1df146756 506 /**
mbed_official 76:aeb1df146756 507 * @brief Enables or disables the USART's most significant bit first
mbed_official 76:aeb1df146756 508 * transmitted/received following the start bit.
mbed_official 76:aeb1df146756 509 * @param USARTx: where x can be 1, 2, 3 or 4 to select the USART peripheral.
mbed_official 76:aeb1df146756 510 * @note USART3 and USART4 are available only for STM32F072 devices.
mbed_official 76:aeb1df146756 511 * @note USART2 is not available for STM32F031 devices.
mbed_official 76:aeb1df146756 512 * @param NewState: new state of the USART most significant bit first
mbed_official 76:aeb1df146756 513 * transmitted/received following the start bit.
mbed_official 76:aeb1df146756 514 * This parameter can be: ENABLE or DISABLE.
mbed_official 76:aeb1df146756 515 * @note This function has to be called before calling USART_Cmd() function.
mbed_official 76:aeb1df146756 516 * @retval None
mbed_official 76:aeb1df146756 517 */
mbed_official 76:aeb1df146756 518 void USART_MSBFirstCmd(USART_TypeDef* USARTx, FunctionalState NewState)
mbed_official 76:aeb1df146756 519 {
mbed_official 76:aeb1df146756 520 /* Check the parameters */
mbed_official 76:aeb1df146756 521 assert_param(IS_USART_ALL_PERIPH(USARTx));
mbed_official 76:aeb1df146756 522 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 76:aeb1df146756 523
mbed_official 76:aeb1df146756 524 if (NewState != DISABLE)
mbed_official 76:aeb1df146756 525 {
mbed_official 76:aeb1df146756 526 /* Enable the most significant bit first transmitted/received following the
mbed_official 76:aeb1df146756 527 start bit by setting the MSBFIRST bit in the CR2 register */
mbed_official 76:aeb1df146756 528 USARTx->CR2 |= USART_CR2_MSBFIRST;
mbed_official 76:aeb1df146756 529 }
mbed_official 76:aeb1df146756 530 else
mbed_official 76:aeb1df146756 531 {
mbed_official 76:aeb1df146756 532 /* Disable the most significant bit first transmitted/received following the
mbed_official 76:aeb1df146756 533 start bit by clearing the MSBFIRST bit in the CR2 register */
mbed_official 76:aeb1df146756 534 USARTx->CR2 &= (uint32_t)~((uint32_t)USART_CR2_MSBFIRST);
mbed_official 76:aeb1df146756 535 }
mbed_official 76:aeb1df146756 536 }
mbed_official 76:aeb1df146756 537
mbed_official 76:aeb1df146756 538 /**
mbed_official 76:aeb1df146756 539 * @brief Enables or disables the binary data inversion.
mbed_official 76:aeb1df146756 540 * @param USARTx: where x can be 1, 2, 3 or 4 to select the USART peripheral.
mbed_official 76:aeb1df146756 541 * @note USART3 and USART4 are available only for STM32F072 devices.
mbed_official 76:aeb1df146756 542 * @note USART2 is not available for STM32F031 devices.
mbed_official 76:aeb1df146756 543 * @param NewState: new defined levels for the USART data.
mbed_official 76:aeb1df146756 544 * This parameter can be:
mbed_official 76:aeb1df146756 545 * @arg ENABLE: Logical data from the data register are send/received in negative
mbed_official 76:aeb1df146756 546 * logic (1=L, 0=H). The parity bit is also inverted.
mbed_official 76:aeb1df146756 547 * @arg DISABLE: Logical data from the data register are send/received in positive
mbed_official 76:aeb1df146756 548 * logic (1=H, 0=L)
mbed_official 76:aeb1df146756 549 * @note This function has to be called before calling USART_Cmd() function.
mbed_official 76:aeb1df146756 550 * @retval None
mbed_official 76:aeb1df146756 551 */
mbed_official 76:aeb1df146756 552 void USART_DataInvCmd(USART_TypeDef* USARTx, FunctionalState NewState)
mbed_official 76:aeb1df146756 553 {
mbed_official 76:aeb1df146756 554 /* Check the parameters */
mbed_official 76:aeb1df146756 555 assert_param(IS_USART_ALL_PERIPH(USARTx));
mbed_official 76:aeb1df146756 556 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 76:aeb1df146756 557
mbed_official 76:aeb1df146756 558 if (NewState != DISABLE)
mbed_official 76:aeb1df146756 559 {
mbed_official 76:aeb1df146756 560 /* Enable the binary data inversion feature by setting the DATAINV bit in
mbed_official 76:aeb1df146756 561 the CR2 register */
mbed_official 76:aeb1df146756 562 USARTx->CR2 |= USART_CR2_DATAINV;
mbed_official 76:aeb1df146756 563 }
mbed_official 76:aeb1df146756 564 else
mbed_official 76:aeb1df146756 565 {
mbed_official 76:aeb1df146756 566 /* Disable the binary data inversion feature by clearing the DATAINV bit in
mbed_official 76:aeb1df146756 567 the CR2 register */
mbed_official 76:aeb1df146756 568 USARTx->CR2 &= (uint32_t)~((uint32_t)USART_CR2_DATAINV);
mbed_official 76:aeb1df146756 569 }
mbed_official 76:aeb1df146756 570 }
mbed_official 76:aeb1df146756 571
mbed_official 76:aeb1df146756 572 /**
mbed_official 76:aeb1df146756 573 * @brief Enables or disables the Pin(s) active level inversion.
mbed_official 76:aeb1df146756 574 * @param USARTx: where x can be 1, 2, 3 or 4 to select the USART peripheral.
mbed_official 76:aeb1df146756 575 * @note USART3 and USART4 are available only for STM32F072 devices.
mbed_official 76:aeb1df146756 576 * @note USART2 is not available for STM32F031 devices.
mbed_official 76:aeb1df146756 577 * @param USART_InvPin: specifies the USART pin(s) to invert.
mbed_official 76:aeb1df146756 578 * This parameter can be any combination of the following values:
mbed_official 76:aeb1df146756 579 * @arg USART_InvPin_Tx: USART Tx pin active level inversion.
mbed_official 76:aeb1df146756 580 * @arg USART_InvPin_Rx: USART Rx pin active level inversion.
mbed_official 76:aeb1df146756 581 * @param NewState: new active level status for the USART pin(s).
mbed_official 76:aeb1df146756 582 * This parameter can be:
mbed_official 76:aeb1df146756 583 * @arg ENABLE: pin(s) signal values are inverted (Vdd =0, Gnd =1).
mbed_official 76:aeb1df146756 584 * @arg DISABLE: pin(s) signal works using the standard logic levels (Vdd =1, Gnd =0).
mbed_official 76:aeb1df146756 585 * @note This function has to be called before calling USART_Cmd() function.
mbed_official 76:aeb1df146756 586 * @retval None
mbed_official 76:aeb1df146756 587 */
mbed_official 76:aeb1df146756 588 void USART_InvPinCmd(USART_TypeDef* USARTx, uint32_t USART_InvPin, FunctionalState NewState)
mbed_official 76:aeb1df146756 589 {
mbed_official 76:aeb1df146756 590 /* Check the parameters */
mbed_official 76:aeb1df146756 591 assert_param(IS_USART_ALL_PERIPH(USARTx));
mbed_official 76:aeb1df146756 592 assert_param(IS_USART_INVERSTION_PIN(USART_InvPin));
mbed_official 76:aeb1df146756 593 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 76:aeb1df146756 594
mbed_official 76:aeb1df146756 595 if (NewState != DISABLE)
mbed_official 76:aeb1df146756 596 {
mbed_official 76:aeb1df146756 597 /* Enable the active level inversion for selected pins by setting the TXINV
mbed_official 76:aeb1df146756 598 and/or RXINV bits in the USART CR2 register */
mbed_official 76:aeb1df146756 599 USARTx->CR2 |= USART_InvPin;
mbed_official 76:aeb1df146756 600 }
mbed_official 76:aeb1df146756 601 else
mbed_official 76:aeb1df146756 602 {
mbed_official 76:aeb1df146756 603 /* Disable the active level inversion for selected requests by clearing the
mbed_official 76:aeb1df146756 604 TXINV and/or RXINV bits in the USART CR2 register */
mbed_official 76:aeb1df146756 605 USARTx->CR2 &= (uint32_t)~USART_InvPin;
mbed_official 76:aeb1df146756 606 }
mbed_official 76:aeb1df146756 607 }
mbed_official 76:aeb1df146756 608
mbed_official 76:aeb1df146756 609 /**
mbed_official 76:aeb1df146756 610 * @brief Enables or disables the swap Tx/Rx pins.
mbed_official 76:aeb1df146756 611 * @param USARTx: where x can be 1, 2, 3 or 4 to select the USART peripheral.
mbed_official 76:aeb1df146756 612 * @note USART3 and USART4 are available only for STM32F072 devices.
mbed_official 76:aeb1df146756 613 * @note USART2 is not available for STM32F031 devices.
mbed_official 76:aeb1df146756 614 * @param NewState: new state of the USARTx TX/RX pins pinout.
mbed_official 76:aeb1df146756 615 * This parameter can be:
mbed_official 76:aeb1df146756 616 * @arg ENABLE: The TX and RX pins functions are swapped.
mbed_official 76:aeb1df146756 617 * @arg DISABLE: TX/RX pins are used as defined in standard pinout
mbed_official 76:aeb1df146756 618 * @note This function has to be called before calling USART_Cmd() function.
mbed_official 76:aeb1df146756 619 * @retval None
mbed_official 76:aeb1df146756 620 */
mbed_official 76:aeb1df146756 621 void USART_SWAPPinCmd(USART_TypeDef* USARTx, FunctionalState NewState)
mbed_official 76:aeb1df146756 622 {
mbed_official 76:aeb1df146756 623 /* Check the parameters */
mbed_official 76:aeb1df146756 624 assert_param(IS_USART_ALL_PERIPH(USARTx));
mbed_official 76:aeb1df146756 625 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 76:aeb1df146756 626
mbed_official 76:aeb1df146756 627 if (NewState != DISABLE)
mbed_official 76:aeb1df146756 628 {
mbed_official 76:aeb1df146756 629 /* Enable the SWAP feature by setting the SWAP bit in the CR2 register */
mbed_official 76:aeb1df146756 630 USARTx->CR2 |= USART_CR2_SWAP;
mbed_official 76:aeb1df146756 631 }
mbed_official 76:aeb1df146756 632 else
mbed_official 76:aeb1df146756 633 {
mbed_official 76:aeb1df146756 634 /* Disable the SWAP feature by clearing the SWAP bit in the CR2 register */
mbed_official 76:aeb1df146756 635 USARTx->CR2 &= (uint32_t)~((uint32_t)USART_CR2_SWAP);
mbed_official 76:aeb1df146756 636 }
mbed_official 76:aeb1df146756 637 }
mbed_official 76:aeb1df146756 638
mbed_official 76:aeb1df146756 639 /**
mbed_official 76:aeb1df146756 640 * @brief Enables or disables the receiver Time Out feature.
mbed_official 76:aeb1df146756 641 * @param USARTx: where x can be 1 to select the USART peripheral.
mbed_official 76:aeb1df146756 642 * @param NewState: new state of the USARTx receiver Time Out.
mbed_official 76:aeb1df146756 643 * This parameter can be: ENABLE or DISABLE.
mbed_official 76:aeb1df146756 644 * @retval None
mbed_official 76:aeb1df146756 645 */
mbed_official 76:aeb1df146756 646 void USART_ReceiverTimeOutCmd(USART_TypeDef* USARTx, FunctionalState NewState)
mbed_official 76:aeb1df146756 647 {
mbed_official 76:aeb1df146756 648 /* Check the parameters */
mbed_official 76:aeb1df146756 649 assert_param(IS_USART_12_PERIPH(USARTx));
mbed_official 76:aeb1df146756 650 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 76:aeb1df146756 651
mbed_official 76:aeb1df146756 652 if (NewState != DISABLE)
mbed_official 76:aeb1df146756 653 {
mbed_official 76:aeb1df146756 654 /* Enable the receiver time out feature by setting the RTOEN bit in the CR2
mbed_official 76:aeb1df146756 655 register */
mbed_official 76:aeb1df146756 656 USARTx->CR2 |= USART_CR2_RTOEN;
mbed_official 76:aeb1df146756 657 }
mbed_official 76:aeb1df146756 658 else
mbed_official 76:aeb1df146756 659 {
mbed_official 76:aeb1df146756 660 /* Disable the receiver time out feature by clearing the RTOEN bit in the CR2
mbed_official 76:aeb1df146756 661 register */
mbed_official 76:aeb1df146756 662 USARTx->CR2 &= (uint32_t)~((uint32_t)USART_CR2_RTOEN);
mbed_official 76:aeb1df146756 663 }
mbed_official 76:aeb1df146756 664 }
mbed_official 76:aeb1df146756 665
mbed_official 76:aeb1df146756 666 /**
mbed_official 76:aeb1df146756 667 * @brief Sets the receiver Time Out value.
mbed_official 76:aeb1df146756 668 * @param USARTx: where x can be 1or 2 to select the USART peripheral.
mbed_official 76:aeb1df146756 669 * @note USART2 is available only for STM32F072 devices.
mbed_official 76:aeb1df146756 670 * @param USART_ReceiverTimeOut: specifies the Receiver Time Out value.
mbed_official 76:aeb1df146756 671 * @retval None
mbed_official 76:aeb1df146756 672 */
mbed_official 76:aeb1df146756 673 void USART_SetReceiverTimeOut(USART_TypeDef* USARTx, uint32_t USART_ReceiverTimeOut)
mbed_official 76:aeb1df146756 674 {
mbed_official 76:aeb1df146756 675 /* Check the parameters */
mbed_official 76:aeb1df146756 676 assert_param(IS_USART_12_PERIPH(USARTx));
mbed_official 76:aeb1df146756 677 assert_param(IS_USART_TIMEOUT(USART_ReceiverTimeOut));
mbed_official 76:aeb1df146756 678
mbed_official 76:aeb1df146756 679 /* Clear the receiver Time Out value by clearing the RTO[23:0] bits in the RTOR
mbed_official 76:aeb1df146756 680 register */
mbed_official 76:aeb1df146756 681 USARTx->RTOR &= (uint32_t)~((uint32_t)USART_RTOR_RTO);
mbed_official 76:aeb1df146756 682 /* Set the receiver Time Out value by setting the RTO[23:0] bits in the RTOR
mbed_official 76:aeb1df146756 683 register */
mbed_official 76:aeb1df146756 684 USARTx->RTOR |= USART_ReceiverTimeOut;
mbed_official 76:aeb1df146756 685 }
mbed_official 76:aeb1df146756 686
mbed_official 76:aeb1df146756 687 /**
mbed_official 76:aeb1df146756 688 * @brief Sets the system clock prescaler.
mbed_official 76:aeb1df146756 689 * @note This function is not available for STM32F030 devices.
mbed_official 76:aeb1df146756 690 * @param USARTx: where x can be 1or 2 to select the USART peripheral.
mbed_official 76:aeb1df146756 691 * @note USART2 is available only for STM32F072 devices.
mbed_official 76:aeb1df146756 692 * @param USART_Prescaler: specifies the prescaler clock.
mbed_official 76:aeb1df146756 693 * @note This function has to be called before calling USART_Cmd() function.
mbed_official 76:aeb1df146756 694 * @retval None
mbed_official 76:aeb1df146756 695 */
mbed_official 76:aeb1df146756 696 void USART_SetPrescaler(USART_TypeDef* USARTx, uint8_t USART_Prescaler)
mbed_official 76:aeb1df146756 697 {
mbed_official 76:aeb1df146756 698 /* Check the parameters */
mbed_official 76:aeb1df146756 699 assert_param(IS_USART_12_PERIPH(USARTx));
mbed_official 76:aeb1df146756 700
mbed_official 76:aeb1df146756 701 /* Clear the USART prescaler */
mbed_official 76:aeb1df146756 702 USARTx->GTPR &= USART_GTPR_GT;
mbed_official 76:aeb1df146756 703 /* Set the USART prescaler */
mbed_official 76:aeb1df146756 704 USARTx->GTPR |= USART_Prescaler;
mbed_official 76:aeb1df146756 705 }
mbed_official 76:aeb1df146756 706
mbed_official 76:aeb1df146756 707 /**
mbed_official 76:aeb1df146756 708 * @}
mbed_official 76:aeb1df146756 709 */
mbed_official 76:aeb1df146756 710
mbed_official 76:aeb1df146756 711
mbed_official 76:aeb1df146756 712 /** @defgroup USART_Group2 STOP Mode functions
mbed_official 76:aeb1df146756 713 * @brief STOP Mode functions
mbed_official 76:aeb1df146756 714 *
mbed_official 76:aeb1df146756 715 @verbatim
mbed_official 76:aeb1df146756 716 ===============================================================================
mbed_official 76:aeb1df146756 717 ##### STOP Mode functions #####
mbed_official 76:aeb1df146756 718 ===============================================================================
mbed_official 76:aeb1df146756 719 [..] This subsection provides a set of functions allowing to manage
mbed_official 76:aeb1df146756 720 WakeUp from STOP mode.
mbed_official 76:aeb1df146756 721
mbed_official 76:aeb1df146756 722 [..] The USART is able to WakeUp from Stop Mode if USART clock is set to HSI
mbed_official 76:aeb1df146756 723 or LSI.
mbed_official 76:aeb1df146756 724
mbed_official 76:aeb1df146756 725 [..] The WakeUp source is configured by calling USART_StopModeWakeUpSourceConfig()
mbed_official 76:aeb1df146756 726 function.
mbed_official 76:aeb1df146756 727
mbed_official 76:aeb1df146756 728 [..] After configuring the source of WakeUp and before entering in Stop Mode
mbed_official 76:aeb1df146756 729 USART_STOPModeCmd() function should be called to allow USART WakeUp.
mbed_official 76:aeb1df146756 730
mbed_official 76:aeb1df146756 731 @endverbatim
mbed_official 76:aeb1df146756 732 * @{
mbed_official 76:aeb1df146756 733 */
mbed_official 76:aeb1df146756 734
mbed_official 76:aeb1df146756 735 /**
mbed_official 76:aeb1df146756 736 * @brief Enables or disables the specified USART peripheral in STOP Mode.
mbed_official 76:aeb1df146756 737 * @param USARTx: where x can be 1or 2 to select the USART peripheral.
mbed_official 76:aeb1df146756 738 * @note USART2 is available only for STM32F072 devices.
mbed_official 76:aeb1df146756 739 * @param NewState: new state of the USARTx peripheral state in stop mode.
mbed_official 76:aeb1df146756 740 * This parameter can be: ENABLE or DISABLE.
mbed_official 76:aeb1df146756 741 * @note This function has to be called when USART clock is set to HSI or LSE.
mbed_official 76:aeb1df146756 742 * @retval None
mbed_official 76:aeb1df146756 743 */
mbed_official 76:aeb1df146756 744 void USART_STOPModeCmd(USART_TypeDef* USARTx, FunctionalState NewState)
mbed_official 76:aeb1df146756 745 {
mbed_official 76:aeb1df146756 746 /* Check the parameters */
mbed_official 76:aeb1df146756 747 assert_param(IS_USART_12_PERIPH(USARTx));
mbed_official 76:aeb1df146756 748 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 76:aeb1df146756 749
mbed_official 76:aeb1df146756 750 if (NewState != DISABLE)
mbed_official 76:aeb1df146756 751 {
mbed_official 76:aeb1df146756 752 /* Enable the selected USART in STOP mode by setting the UESM bit in the CR1
mbed_official 76:aeb1df146756 753 register */
mbed_official 76:aeb1df146756 754 USARTx->CR1 |= USART_CR1_UESM;
mbed_official 76:aeb1df146756 755 }
mbed_official 76:aeb1df146756 756 else
mbed_official 76:aeb1df146756 757 {
mbed_official 76:aeb1df146756 758 /* Disable the selected USART in STOP mode by clearing the UE bit in the CR1
mbed_official 76:aeb1df146756 759 register */
mbed_official 76:aeb1df146756 760 USARTx->CR1 &= (uint32_t)~((uint32_t)USART_CR1_UESM);
mbed_official 76:aeb1df146756 761 }
mbed_official 76:aeb1df146756 762 }
mbed_official 76:aeb1df146756 763
mbed_official 76:aeb1df146756 764 /**
mbed_official 76:aeb1df146756 765 * @brief Selects the USART WakeUp method form stop mode.
mbed_official 76:aeb1df146756 766 * @note This function is not available for STM32F030 devices.
mbed_official 76:aeb1df146756 767 * @param USARTx: where x can be 1or 2 to select the USART peripheral.
mbed_official 76:aeb1df146756 768 * @note USART2 is available only for STM32F072 devices.
mbed_official 76:aeb1df146756 769 * @param USART_WakeUp: specifies the selected USART wakeup method.
mbed_official 76:aeb1df146756 770 * This parameter can be one of the following values:
mbed_official 76:aeb1df146756 771 * @arg USART_WakeUpSource_AddressMatch: WUF active on address match.
mbed_official 76:aeb1df146756 772 * @arg USART_WakeUpSource_StartBit: WUF active on Start bit detection.
mbed_official 76:aeb1df146756 773 * @arg USART_WakeUpSource_RXNE: WUF active on RXNE.
mbed_official 76:aeb1df146756 774 * @note This function has to be called before calling USART_Cmd() function.
mbed_official 76:aeb1df146756 775 * @retval None
mbed_official 76:aeb1df146756 776 */
mbed_official 76:aeb1df146756 777 void USART_StopModeWakeUpSourceConfig(USART_TypeDef* USARTx, uint32_t USART_WakeUpSource)
mbed_official 76:aeb1df146756 778 {
mbed_official 76:aeb1df146756 779 /* Check the parameters */
mbed_official 76:aeb1df146756 780 assert_param(IS_USART_12_PERIPH(USARTx));
mbed_official 76:aeb1df146756 781 assert_param(IS_USART_STOPMODE_WAKEUPSOURCE(USART_WakeUpSource));
mbed_official 76:aeb1df146756 782
mbed_official 76:aeb1df146756 783 USARTx->CR3 &= (uint32_t)~((uint32_t)USART_CR3_WUS);
mbed_official 76:aeb1df146756 784 USARTx->CR3 |= USART_WakeUpSource;
mbed_official 76:aeb1df146756 785 }
mbed_official 76:aeb1df146756 786
mbed_official 76:aeb1df146756 787 /**
mbed_official 76:aeb1df146756 788 * @}
mbed_official 76:aeb1df146756 789 */
mbed_official 76:aeb1df146756 790
mbed_official 76:aeb1df146756 791
mbed_official 76:aeb1df146756 792 /** @defgroup USART_Group3 AutoBaudRate functions
mbed_official 76:aeb1df146756 793 * @brief AutoBaudRate functions
mbed_official 76:aeb1df146756 794 *
mbed_official 76:aeb1df146756 795 @verbatim
mbed_official 76:aeb1df146756 796 ===============================================================================
mbed_official 76:aeb1df146756 797 ##### AutoBaudRate functions #####
mbed_official 76:aeb1df146756 798 ===============================================================================
mbed_official 76:aeb1df146756 799 [..] This subsection provides a set of functions allowing to manage
mbed_official 76:aeb1df146756 800 the AutoBaudRate detections.
mbed_official 76:aeb1df146756 801
mbed_official 76:aeb1df146756 802 [..] Before Enabling AutoBaudRate detection using USART_AutoBaudRateCmd ()
mbed_official 76:aeb1df146756 803 The character patterns used to calculate baudrate must be chosen by calling
mbed_official 76:aeb1df146756 804 USART_AutoBaudRateConfig() function. These function take as parameter :
mbed_official 76:aeb1df146756 805 (#)USART_AutoBaudRate_StartBit : any character starting with a bit 1.
mbed_official 76:aeb1df146756 806 (#)USART_AutoBaudRate_FallingEdge : any character starting with a 10xx bit pattern.
mbed_official 76:aeb1df146756 807
mbed_official 76:aeb1df146756 808 [..] At any later time, another request for AutoBaudRate detection can be performed
mbed_official 76:aeb1df146756 809 using USART_RequestCmd() function.
mbed_official 76:aeb1df146756 810
mbed_official 76:aeb1df146756 811 [..] The AutoBaudRate detection is monitored by the status of ABRF flag which indicate
mbed_official 76:aeb1df146756 812 that the AutoBaudRate detection is completed. In addition to ABRF flag, the ABRE flag
mbed_official 76:aeb1df146756 813 indicate that this procedure is completed without success. USART_GetFlagStatus ()
mbed_official 76:aeb1df146756 814 function should be used to monitor the status of these flags.
mbed_official 76:aeb1df146756 815
mbed_official 76:aeb1df146756 816 @endverbatim
mbed_official 76:aeb1df146756 817 * @{
mbed_official 76:aeb1df146756 818 */
mbed_official 76:aeb1df146756 819
mbed_official 76:aeb1df146756 820 /**
mbed_official 76:aeb1df146756 821 * @brief Enables or disables the Auto Baud Rate.
mbed_official 76:aeb1df146756 822 * @param USARTx: where x can be 1or 2 to select the USART peripheral.
mbed_official 76:aeb1df146756 823 * @note USART2 is available only for STM32F072 devices.
mbed_official 76:aeb1df146756 824 * @param NewState: new state of the USARTx auto baud rate.
mbed_official 76:aeb1df146756 825 * This parameter can be: ENABLE or DISABLE.
mbed_official 76:aeb1df146756 826 * @retval None
mbed_official 76:aeb1df146756 827 */
mbed_official 76:aeb1df146756 828 void USART_AutoBaudRateCmd(USART_TypeDef* USARTx, FunctionalState NewState)
mbed_official 76:aeb1df146756 829 {
mbed_official 76:aeb1df146756 830 /* Check the parameters */
mbed_official 76:aeb1df146756 831 assert_param(IS_USART_12_PERIPH(USARTx));
mbed_official 76:aeb1df146756 832 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 76:aeb1df146756 833
mbed_official 76:aeb1df146756 834 if (NewState != DISABLE)
mbed_official 76:aeb1df146756 835 {
mbed_official 76:aeb1df146756 836 /* Enable the auto baud rate feature by setting the ABREN bit in the CR2
mbed_official 76:aeb1df146756 837 register */
mbed_official 76:aeb1df146756 838 USARTx->CR2 |= USART_CR2_ABREN;
mbed_official 76:aeb1df146756 839 }
mbed_official 76:aeb1df146756 840 else
mbed_official 76:aeb1df146756 841 {
mbed_official 76:aeb1df146756 842 /* Disable the auto baud rate feature by clearing the ABREN bit in the CR2
mbed_official 76:aeb1df146756 843 register */
mbed_official 76:aeb1df146756 844 USARTx->CR2 &= (uint32_t)~((uint32_t)USART_CR2_ABREN);
mbed_official 76:aeb1df146756 845 }
mbed_official 76:aeb1df146756 846 }
mbed_official 76:aeb1df146756 847
mbed_official 76:aeb1df146756 848 /**
mbed_official 76:aeb1df146756 849 * @brief Selects the USART auto baud rate method.
mbed_official 76:aeb1df146756 850 * @param USARTx: where x can be 1or 2 to select the USART peripheral.
mbed_official 76:aeb1df146756 851 * @note USART2 is available only for STM32F072 devices.
mbed_official 76:aeb1df146756 852 * @param USART_AutoBaudRate: specifies the selected USART auto baud rate method.
mbed_official 76:aeb1df146756 853 * This parameter can be one of the following values:
mbed_official 76:aeb1df146756 854 * @arg USART_AutoBaudRate_StartBit: Start Bit duration measurement.
mbed_official 76:aeb1df146756 855 * @arg USART_AutoBaudRate_FallingEdge: Falling edge to falling edge measurement.
mbed_official 76:aeb1df146756 856 * @note This function has to be called before calling USART_Cmd() function.
mbed_official 76:aeb1df146756 857 * @retval None
mbed_official 76:aeb1df146756 858 */
mbed_official 76:aeb1df146756 859 void USART_AutoBaudRateConfig(USART_TypeDef* USARTx, uint32_t USART_AutoBaudRate)
mbed_official 76:aeb1df146756 860 {
mbed_official 76:aeb1df146756 861 /* Check the parameters */
mbed_official 76:aeb1df146756 862 assert_param(IS_USART_12_PERIPH(USARTx));
mbed_official 76:aeb1df146756 863 assert_param(IS_USART_AUTOBAUDRATE_MODE(USART_AutoBaudRate));
mbed_official 76:aeb1df146756 864
mbed_official 76:aeb1df146756 865 USARTx->CR2 &= (uint32_t)~((uint32_t)USART_CR2_ABRMODE);
mbed_official 76:aeb1df146756 866 USARTx->CR2 |= USART_AutoBaudRate;
mbed_official 76:aeb1df146756 867 }
mbed_official 76:aeb1df146756 868
mbed_official 76:aeb1df146756 869 /**
mbed_official 76:aeb1df146756 870 * @}
mbed_official 76:aeb1df146756 871 */
mbed_official 76:aeb1df146756 872
mbed_official 76:aeb1df146756 873
mbed_official 76:aeb1df146756 874 /** @defgroup USART_Group4 Data transfers functions
mbed_official 76:aeb1df146756 875 * @brief Data transfers functions
mbed_official 76:aeb1df146756 876 *
mbed_official 76:aeb1df146756 877 @verbatim
mbed_official 76:aeb1df146756 878 ===============================================================================
mbed_official 76:aeb1df146756 879 ##### Data transfers functions #####
mbed_official 76:aeb1df146756 880 ===============================================================================
mbed_official 76:aeb1df146756 881 [..] This subsection provides a set of functions allowing to manage
mbed_official 76:aeb1df146756 882 the USART data transfers.
mbed_official 76:aeb1df146756 883 [..] During an USART reception, data shifts in least significant bit first
mbed_official 76:aeb1df146756 884 through the RX pin. When a transmission is taking place, a write instruction to
mbed_official 76:aeb1df146756 885 the USART_TDR register stores the data in the shift register.
mbed_official 76:aeb1df146756 886 [..] The read access of the USART_RDR register can be done using
mbed_official 76:aeb1df146756 887 the USART_ReceiveData() function and returns the RDR value.
mbed_official 76:aeb1df146756 888 Whereas a write access to the USART_TDR can be done using USART_SendData()
mbed_official 76:aeb1df146756 889 function and stores the written data into TDR.
mbed_official 76:aeb1df146756 890
mbed_official 76:aeb1df146756 891 @endverbatim
mbed_official 76:aeb1df146756 892 * @{
mbed_official 76:aeb1df146756 893 */
mbed_official 76:aeb1df146756 894
mbed_official 76:aeb1df146756 895 /**
mbed_official 76:aeb1df146756 896 * @brief Transmits single data through the USARTx peripheral.
mbed_official 76:aeb1df146756 897 * @param USARTx: where x can be 1, 2, 3 or 4 to select the USART peripheral.
mbed_official 76:aeb1df146756 898 * @note USART3 and USART4 are available only for STM32F072 devices.
mbed_official 76:aeb1df146756 899 * @note USART2 is not available for STM32F031 devices.
mbed_official 76:aeb1df146756 900 * @param Data: the data to transmit.
mbed_official 76:aeb1df146756 901 * @retval None
mbed_official 76:aeb1df146756 902 */
mbed_official 76:aeb1df146756 903 void USART_SendData(USART_TypeDef* USARTx, uint16_t Data)
mbed_official 76:aeb1df146756 904 {
mbed_official 76:aeb1df146756 905 /* Check the parameters */
mbed_official 76:aeb1df146756 906 assert_param(IS_USART_ALL_PERIPH(USARTx));
mbed_official 76:aeb1df146756 907 assert_param(IS_USART_DATA(Data));
mbed_official 76:aeb1df146756 908
mbed_official 76:aeb1df146756 909 /* Transmit Data */
mbed_official 76:aeb1df146756 910 USARTx->TDR = (Data & (uint16_t)0x01FF);
mbed_official 76:aeb1df146756 911 }
mbed_official 76:aeb1df146756 912
mbed_official 76:aeb1df146756 913 /**
mbed_official 76:aeb1df146756 914 * @brief Returns the most recent received data by the USARTx peripheral.
mbed_official 76:aeb1df146756 915 * @param USARTx: where x can be 1, 2, 3 or 4 to select the USART peripheral.
mbed_official 76:aeb1df146756 916 * @note USART3 and USART4 are available only for STM32F072 devices.
mbed_official 76:aeb1df146756 917 * @note USART2 is not available for STM32F031 devices.
mbed_official 76:aeb1df146756 918 * @retval The received data.
mbed_official 76:aeb1df146756 919 */
mbed_official 76:aeb1df146756 920 uint16_t USART_ReceiveData(USART_TypeDef* USARTx)
mbed_official 76:aeb1df146756 921 {
mbed_official 76:aeb1df146756 922 /* Check the parameters */
mbed_official 76:aeb1df146756 923 assert_param(IS_USART_ALL_PERIPH(USARTx));
mbed_official 76:aeb1df146756 924
mbed_official 76:aeb1df146756 925 /* Receive Data */
mbed_official 76:aeb1df146756 926 return (uint16_t)(USARTx->RDR & (uint16_t)0x01FF);
mbed_official 76:aeb1df146756 927 }
mbed_official 76:aeb1df146756 928
mbed_official 76:aeb1df146756 929 /**
mbed_official 76:aeb1df146756 930 * @}
mbed_official 76:aeb1df146756 931 */
mbed_official 76:aeb1df146756 932
mbed_official 76:aeb1df146756 933 /** @defgroup USART_Group5 MultiProcessor Communication functions
mbed_official 76:aeb1df146756 934 * @brief Multi-Processor Communication functions
mbed_official 76:aeb1df146756 935 *
mbed_official 76:aeb1df146756 936 @verbatim
mbed_official 76:aeb1df146756 937 ===============================================================================
mbed_official 76:aeb1df146756 938 ##### Multi-Processor Communication functions #####
mbed_official 76:aeb1df146756 939 ===============================================================================
mbed_official 76:aeb1df146756 940 [..] This subsection provides a set of functions allowing to manage the USART
mbed_official 76:aeb1df146756 941 multiprocessor communication.
mbed_official 76:aeb1df146756 942 [..] For instance one of the USARTs can be the master, its TX output is
mbed_official 76:aeb1df146756 943 connected to the RX input of the other USART. The others are slaves,
mbed_official 76:aeb1df146756 944 their respective TX outputs are logically ANDed together and connected
mbed_official 76:aeb1df146756 945 to the RX input of the master. USART multiprocessor communication is
mbed_official 76:aeb1df146756 946 possible through the following procedure:
mbed_official 76:aeb1df146756 947 (#) Program the Baud rate, Word length = 9 bits, Stop bits, Parity,
mbed_official 76:aeb1df146756 948 Mode transmitter or Mode receiver and hardware flow control values
mbed_official 76:aeb1df146756 949 using the USART_Init() function.
mbed_official 76:aeb1df146756 950 (#) Configures the USART address using the USART_SetAddress() function.
mbed_official 76:aeb1df146756 951 (#) Configures the wake up methode (USART_WakeUp_IdleLine or
mbed_official 76:aeb1df146756 952 USART_WakeUp_AddressMark) using USART_WakeUpConfig() function only
mbed_official 76:aeb1df146756 953 for the slaves.
mbed_official 76:aeb1df146756 954 (#) Enable the USART using the USART_Cmd() function.
mbed_official 76:aeb1df146756 955 (#) Enter the USART slaves in mute mode using USART_ReceiverWakeUpCmd()
mbed_official 76:aeb1df146756 956 function.
mbed_official 76:aeb1df146756 957 [..] The USART Slave exit from mute mode when receive the wake up condition.
mbed_official 76:aeb1df146756 958
mbed_official 76:aeb1df146756 959 @endverbatim
mbed_official 76:aeb1df146756 960 * @{
mbed_official 76:aeb1df146756 961 */
mbed_official 76:aeb1df146756 962
mbed_official 76:aeb1df146756 963 /**
mbed_official 76:aeb1df146756 964 * @brief Sets the address of the USART node.
mbed_official 76:aeb1df146756 965 * @param USARTx: where x can be 1, 2, 3 or 4 to select the USART peripheral.
mbed_official 76:aeb1df146756 966 * @note USART3 and USART4 are available only for STM32F072 devices.
mbed_official 76:aeb1df146756 967 * @note USART2 is not available for STM32F031 devices.
mbed_official 76:aeb1df146756 968 * @param USART_Address: Indicates the address of the USART node.
mbed_official 76:aeb1df146756 969 * @retval None
mbed_official 76:aeb1df146756 970 */
mbed_official 76:aeb1df146756 971 void USART_SetAddress(USART_TypeDef* USARTx, uint8_t USART_Address)
mbed_official 76:aeb1df146756 972 {
mbed_official 76:aeb1df146756 973 /* Check the parameters */
mbed_official 76:aeb1df146756 974 assert_param(IS_USART_ALL_PERIPH(USARTx));
mbed_official 76:aeb1df146756 975
mbed_official 76:aeb1df146756 976 /* Clear the USART address */
mbed_official 76:aeb1df146756 977 USARTx->CR2 &= (uint32_t)~((uint32_t)USART_CR2_ADD);
mbed_official 76:aeb1df146756 978 /* Set the USART address node */
mbed_official 76:aeb1df146756 979 USARTx->CR2 |=((uint32_t)USART_Address << (uint32_t)0x18);
mbed_official 76:aeb1df146756 980 }
mbed_official 76:aeb1df146756 981
mbed_official 76:aeb1df146756 982 /**
mbed_official 76:aeb1df146756 983 * @brief Enables or disables the USART's mute mode.
mbed_official 76:aeb1df146756 984 * @param USARTx: where x can be 1, 2, 3 or 4 to select the USART peripheral.
mbed_official 76:aeb1df146756 985 * @note USART3 and USART4 are available only for STM32F072 devices.
mbed_official 76:aeb1df146756 986 * @note USART2 is not available for STM32F031 devices.
mbed_official 76:aeb1df146756 987 * @param NewState: new state of the USART mute mode.
mbed_official 76:aeb1df146756 988 * This parameter can be: ENABLE or DISABLE.
mbed_official 76:aeb1df146756 989 * @retval None
mbed_official 76:aeb1df146756 990 */
mbed_official 76:aeb1df146756 991 void USART_MuteModeCmd(USART_TypeDef* USARTx, FunctionalState NewState)
mbed_official 76:aeb1df146756 992 {
mbed_official 76:aeb1df146756 993 /* Check the parameters */
mbed_official 76:aeb1df146756 994 assert_param(IS_USART_ALL_PERIPH(USARTx));
mbed_official 76:aeb1df146756 995 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 76:aeb1df146756 996
mbed_official 76:aeb1df146756 997 if (NewState != DISABLE)
mbed_official 76:aeb1df146756 998 {
mbed_official 76:aeb1df146756 999 /* Enable the USART mute mode by setting the MME bit in the CR1 register */
mbed_official 76:aeb1df146756 1000 USARTx->CR1 |= USART_CR1_MME;
mbed_official 76:aeb1df146756 1001 }
mbed_official 76:aeb1df146756 1002 else
mbed_official 76:aeb1df146756 1003 {
mbed_official 76:aeb1df146756 1004 /* Disable the USART mute mode by clearing the MME bit in the CR1 register */
mbed_official 76:aeb1df146756 1005 USARTx->CR1 &= (uint32_t)~((uint32_t)USART_CR1_MME);
mbed_official 76:aeb1df146756 1006 }
mbed_official 76:aeb1df146756 1007 }
mbed_official 76:aeb1df146756 1008
mbed_official 76:aeb1df146756 1009 /**
mbed_official 76:aeb1df146756 1010 * @brief Selects the USART WakeUp method from mute mode.
mbed_official 76:aeb1df146756 1011 * @param USARTx: where x can be 1, 2, 3 or 4 to select the USART peripheral.
mbed_official 76:aeb1df146756 1012 * @note USART3 and USART4 are available only for STM32F072 devices.
mbed_official 76:aeb1df146756 1013 * @note USART2 is not available for STM32F031 devices.
mbed_official 76:aeb1df146756 1014 * @param USART_WakeUp: specifies the USART wakeup method.
mbed_official 76:aeb1df146756 1015 * This parameter can be one of the following values:
mbed_official 76:aeb1df146756 1016 * @arg USART_WakeUp_IdleLine: WakeUp by an idle line detection
mbed_official 76:aeb1df146756 1017 * @arg USART_WakeUp_AddressMark: WakeUp by an address mark
mbed_official 76:aeb1df146756 1018 * @retval None
mbed_official 76:aeb1df146756 1019 */
mbed_official 76:aeb1df146756 1020 void USART_MuteModeWakeUpConfig(USART_TypeDef* USARTx, uint32_t USART_WakeUp)
mbed_official 76:aeb1df146756 1021 {
mbed_official 76:aeb1df146756 1022 /* Check the parameters */
mbed_official 76:aeb1df146756 1023 assert_param(IS_USART_ALL_PERIPH(USARTx));
mbed_official 76:aeb1df146756 1024 assert_param(IS_USART_MUTEMODE_WAKEUP(USART_WakeUp));
mbed_official 76:aeb1df146756 1025
mbed_official 76:aeb1df146756 1026 USARTx->CR1 &= (uint32_t)~((uint32_t)USART_CR1_WAKE);
mbed_official 76:aeb1df146756 1027 USARTx->CR1 |= USART_WakeUp;
mbed_official 76:aeb1df146756 1028 }
mbed_official 76:aeb1df146756 1029
mbed_official 76:aeb1df146756 1030 /**
mbed_official 76:aeb1df146756 1031 * @brief Configure the the USART Address detection length.
mbed_official 76:aeb1df146756 1032 * @param USARTx: where x can be 1, 2, 3 or 4 to select the USART peripheral.
mbed_official 76:aeb1df146756 1033 * @note USART3 and USART4 are available only for STM32F072 devices.
mbed_official 76:aeb1df146756 1034 * @note USART2 is not available for STM32F031 devices.
mbed_official 76:aeb1df146756 1035 * @param USART_AddressLength: specifies the USART address length detection.
mbed_official 76:aeb1df146756 1036 * This parameter can be one of the following values:
mbed_official 76:aeb1df146756 1037 * @arg USART_AddressLength_4b: 4-bit address length detection
mbed_official 76:aeb1df146756 1038 * @arg USART_AddressLength_7b: 7-bit address length detection
mbed_official 76:aeb1df146756 1039 * @retval None
mbed_official 76:aeb1df146756 1040 */
mbed_official 76:aeb1df146756 1041 void USART_AddressDetectionConfig(USART_TypeDef* USARTx, uint32_t USART_AddressLength)
mbed_official 76:aeb1df146756 1042 {
mbed_official 76:aeb1df146756 1043 /* Check the parameters */
mbed_official 76:aeb1df146756 1044 assert_param(IS_USART_ALL_PERIPH(USARTx));
mbed_official 76:aeb1df146756 1045 assert_param(IS_USART_ADDRESS_DETECTION(USART_AddressLength));
mbed_official 76:aeb1df146756 1046
mbed_official 76:aeb1df146756 1047 USARTx->CR2 &= (uint32_t)~((uint32_t)USART_CR2_ADDM7);
mbed_official 76:aeb1df146756 1048 USARTx->CR2 |= USART_AddressLength;
mbed_official 76:aeb1df146756 1049 }
mbed_official 76:aeb1df146756 1050
mbed_official 76:aeb1df146756 1051 /**
mbed_official 76:aeb1df146756 1052 * @}
mbed_official 76:aeb1df146756 1053 */
mbed_official 76:aeb1df146756 1054
mbed_official 76:aeb1df146756 1055 /** @defgroup USART_Group6 LIN mode functions
mbed_official 76:aeb1df146756 1056 * @brief LIN mode functions
mbed_official 76:aeb1df146756 1057 *
mbed_official 76:aeb1df146756 1058 @verbatim
mbed_official 76:aeb1df146756 1059 ===============================================================================
mbed_official 76:aeb1df146756 1060 ##### LIN mode functions #####
mbed_official 76:aeb1df146756 1061 ===============================================================================
mbed_official 76:aeb1df146756 1062 [..] This subsection provides a set of functions allowing to manage the USART
mbed_official 76:aeb1df146756 1063 LIN Mode communication.
mbed_official 76:aeb1df146756 1064 [..] In LIN mode, 8-bit data format with 1 stop bit is required in accordance
mbed_official 76:aeb1df146756 1065 with the LIN standard.
mbed_official 76:aeb1df146756 1066 [..] Only this LIN Feature is supported by the USART IP:
mbed_official 76:aeb1df146756 1067 (+) LIN Master Synchronous Break send capability and LIN slave break
mbed_official 76:aeb1df146756 1068 detection capability : 13-bit break generation and 10/11 bit break
mbed_official 76:aeb1df146756 1069 detection.
mbed_official 76:aeb1df146756 1070 [..] USART LIN Master transmitter communication is possible through the
mbed_official 76:aeb1df146756 1071 following procedure:
mbed_official 76:aeb1df146756 1072 (#) Program the Baud rate, Word length = 8bits, Stop bits = 1bit, Parity,
mbed_official 76:aeb1df146756 1073 Mode transmitter or Mode receiver and hardware flow control values
mbed_official 76:aeb1df146756 1074 using the USART_Init() function.
mbed_official 76:aeb1df146756 1075 (#) Enable the LIN mode using the USART_LINCmd() function.
mbed_official 76:aeb1df146756 1076 (#) Enable the USART using the USART_Cmd() function.
mbed_official 76:aeb1df146756 1077 (#) Send the break character using USART_SendBreak() function.
mbed_official 76:aeb1df146756 1078 [..] USART LIN Master receiver communication is possible through the
mbed_official 76:aeb1df146756 1079 following procedure:
mbed_official 76:aeb1df146756 1080 (#) Program the Baud rate, Word length = 8bits, Stop bits = 1bit, Parity,
mbed_official 76:aeb1df146756 1081 Mode transmitter or Mode receiver and hardware flow control values
mbed_official 76:aeb1df146756 1082 using the USART_Init() function.
mbed_official 76:aeb1df146756 1083 (#) Configures the break detection length
mbed_official 76:aeb1df146756 1084 using the USART_LINBreakDetectLengthConfig() function.
mbed_official 76:aeb1df146756 1085 (#) Enable the LIN mode using the USART_LINCmd() function.
mbed_official 76:aeb1df146756 1086 -@- In LIN mode, the following bits must be kept cleared:
mbed_official 76:aeb1df146756 1087 (+@) CLKEN in the USART_CR2 register.
mbed_official 76:aeb1df146756 1088 (+@) STOP[1:0], SCEN, HDSEL and IREN in the USART_CR3 register.
mbed_official 76:aeb1df146756 1089 (#) Enable the USART using the USART_Cmd() function.
mbed_official 76:aeb1df146756 1090
mbed_official 76:aeb1df146756 1091 @endverbatim
mbed_official 76:aeb1df146756 1092 * @{
mbed_official 76:aeb1df146756 1093 */
mbed_official 76:aeb1df146756 1094
mbed_official 76:aeb1df146756 1095 /**
mbed_official 76:aeb1df146756 1096 * @brief Sets the USART LIN Break detection length.
mbed_official 76:aeb1df146756 1097 * @note This function is not available for STM32F030 devices.
mbed_official 76:aeb1df146756 1098 * @param USARTx: where x can be 1or 2 to select the USART peripheral.
mbed_official 76:aeb1df146756 1099 * @note USART2 is available only for STM32F072 devices.
mbed_official 76:aeb1df146756 1100 * @param USART_LINBreakDetectLength: specifies the LIN break detection length.
mbed_official 76:aeb1df146756 1101 * This parameter can be one of the following values:
mbed_official 76:aeb1df146756 1102 * @arg USART_LINBreakDetectLength_10b: 10-bit break detection
mbed_official 76:aeb1df146756 1103 * @arg USART_LINBreakDetectLength_11b: 11-bit break detection
mbed_official 76:aeb1df146756 1104 * @retval None
mbed_official 76:aeb1df146756 1105 */
mbed_official 76:aeb1df146756 1106 void USART_LINBreakDetectLengthConfig(USART_TypeDef* USARTx, uint32_t USART_LINBreakDetectLength)
mbed_official 76:aeb1df146756 1107 {
mbed_official 76:aeb1df146756 1108 /* Check the parameters */
mbed_official 76:aeb1df146756 1109 assert_param(IS_USART_12_PERIPH(USARTx));
mbed_official 76:aeb1df146756 1110 assert_param(IS_USART_LIN_BREAK_DETECT_LENGTH(USART_LINBreakDetectLength));
mbed_official 76:aeb1df146756 1111
mbed_official 76:aeb1df146756 1112 USARTx->CR2 &= (uint32_t)~((uint32_t)USART_CR2_LBDL);
mbed_official 76:aeb1df146756 1113 USARTx->CR2 |= USART_LINBreakDetectLength;
mbed_official 76:aeb1df146756 1114 }
mbed_official 76:aeb1df146756 1115
mbed_official 76:aeb1df146756 1116 /**
mbed_official 76:aeb1df146756 1117 * @brief Enables or disables the USART's LIN mode.
mbed_official 76:aeb1df146756 1118 * @note This function is not available for STM32F030 devices.
mbed_official 76:aeb1df146756 1119 * @param USARTx: where x can be 1or 2 to select the USART peripheral.
mbed_official 76:aeb1df146756 1120 * @note USART2 is available only for STM32F072 devices.
mbed_official 76:aeb1df146756 1121 * @param NewState: new state of the USART LIN mode.
mbed_official 76:aeb1df146756 1122 * This parameter can be: ENABLE or DISABLE.
mbed_official 76:aeb1df146756 1123 * @retval None
mbed_official 76:aeb1df146756 1124 */
mbed_official 76:aeb1df146756 1125 void USART_LINCmd(USART_TypeDef* USARTx, FunctionalState NewState)
mbed_official 76:aeb1df146756 1126 {
mbed_official 76:aeb1df146756 1127 /* Check the parameters */
mbed_official 76:aeb1df146756 1128 assert_param(IS_USART_12_PERIPH(USARTx));
mbed_official 76:aeb1df146756 1129 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 76:aeb1df146756 1130
mbed_official 76:aeb1df146756 1131 if (NewState != DISABLE)
mbed_official 76:aeb1df146756 1132 {
mbed_official 76:aeb1df146756 1133 /* Enable the LIN mode by setting the LINEN bit in the CR2 register */
mbed_official 76:aeb1df146756 1134 USARTx->CR2 |= USART_CR2_LINEN;
mbed_official 76:aeb1df146756 1135 }
mbed_official 76:aeb1df146756 1136 else
mbed_official 76:aeb1df146756 1137 {
mbed_official 76:aeb1df146756 1138 /* Disable the LIN mode by clearing the LINEN bit in the CR2 register */
mbed_official 76:aeb1df146756 1139 USARTx->CR2 &= (uint32_t)~((uint32_t)USART_CR2_LINEN);
mbed_official 76:aeb1df146756 1140 }
mbed_official 76:aeb1df146756 1141 }
mbed_official 76:aeb1df146756 1142
mbed_official 76:aeb1df146756 1143 /**
mbed_official 76:aeb1df146756 1144 * @}
mbed_official 76:aeb1df146756 1145 */
mbed_official 76:aeb1df146756 1146
mbed_official 76:aeb1df146756 1147 /** @defgroup USART_Group7 Halfduplex mode function
mbed_official 76:aeb1df146756 1148 * @brief Half-duplex mode function
mbed_official 76:aeb1df146756 1149 *
mbed_official 76:aeb1df146756 1150 @verbatim
mbed_official 76:aeb1df146756 1151 ===============================================================================
mbed_official 76:aeb1df146756 1152 ##### Half-duplex mode function #####
mbed_official 76:aeb1df146756 1153 ===============================================================================
mbed_official 76:aeb1df146756 1154 [..] This subsection provides a set of functions allowing to manage the USART
mbed_official 76:aeb1df146756 1155 Half-duplex communication.
mbed_official 76:aeb1df146756 1156 [..] The USART can be configured to follow a single-wire half-duplex protocol
mbed_official 76:aeb1df146756 1157 where the TX and RX lines are internally connected.
mbed_official 76:aeb1df146756 1158 [..] USART Half duplex communication is possible through the following procedure:
mbed_official 76:aeb1df146756 1159 (#) Program the Baud rate, Word length, Stop bits, Parity, Mode transmitter
mbed_official 76:aeb1df146756 1160 or Mode receiver and hardware flow control values using the USART_Init()
mbed_official 76:aeb1df146756 1161 function.
mbed_official 76:aeb1df146756 1162 (#) Configures the USART address using the USART_SetAddress() function.
mbed_official 76:aeb1df146756 1163 (#) Enable the half duplex mode using USART_HalfDuplexCmd() function.
mbed_official 76:aeb1df146756 1164 (#) Enable the USART using the USART_Cmd() function.
mbed_official 76:aeb1df146756 1165 -@- The RX pin is no longer used.
mbed_official 76:aeb1df146756 1166 -@- In Half-duplex mode the following bits must be kept cleared:
mbed_official 76:aeb1df146756 1167 (+@) LINEN and CLKEN bits in the USART_CR2 register.
mbed_official 76:aeb1df146756 1168 (+@) SCEN and IREN bits in the USART_CR3 register.
mbed_official 76:aeb1df146756 1169
mbed_official 76:aeb1df146756 1170 @endverbatim
mbed_official 76:aeb1df146756 1171 * @{
mbed_official 76:aeb1df146756 1172 */
mbed_official 76:aeb1df146756 1173
mbed_official 76:aeb1df146756 1174 /**
mbed_official 76:aeb1df146756 1175 * @brief Enables or disables the USART's Half Duplex communication.
mbed_official 76:aeb1df146756 1176 * @param USARTx: where x can be 1, 2, 3 or 4 to select the USART peripheral.
mbed_official 76:aeb1df146756 1177 * @note USART3 and USART4 are available only for STM32F072 devices.
mbed_official 76:aeb1df146756 1178 * @note USART2 is not available for STM32F031 devices.
mbed_official 76:aeb1df146756 1179 * @param NewState: new state of the USART Communication.
mbed_official 76:aeb1df146756 1180 * This parameter can be: ENABLE or DISABLE.
mbed_official 76:aeb1df146756 1181 * @retval None
mbed_official 76:aeb1df146756 1182 */
mbed_official 76:aeb1df146756 1183 void USART_HalfDuplexCmd(USART_TypeDef* USARTx, FunctionalState NewState)
mbed_official 76:aeb1df146756 1184 {
mbed_official 76:aeb1df146756 1185 /* Check the parameters */
mbed_official 76:aeb1df146756 1186 assert_param(IS_USART_ALL_PERIPH(USARTx));
mbed_official 76:aeb1df146756 1187 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 76:aeb1df146756 1188
mbed_official 76:aeb1df146756 1189 if (NewState != DISABLE)
mbed_official 76:aeb1df146756 1190 {
mbed_official 76:aeb1df146756 1191 /* Enable the Half-Duplex mode by setting the HDSEL bit in the CR3 register */
mbed_official 76:aeb1df146756 1192 USARTx->CR3 |= USART_CR3_HDSEL;
mbed_official 76:aeb1df146756 1193 }
mbed_official 76:aeb1df146756 1194 else
mbed_official 76:aeb1df146756 1195 {
mbed_official 76:aeb1df146756 1196 /* Disable the Half-Duplex mode by clearing the HDSEL bit in the CR3 register */
mbed_official 76:aeb1df146756 1197 USARTx->CR3 &= (uint32_t)~((uint32_t)USART_CR3_HDSEL);
mbed_official 76:aeb1df146756 1198 }
mbed_official 76:aeb1df146756 1199 }
mbed_official 76:aeb1df146756 1200
mbed_official 76:aeb1df146756 1201 /**
mbed_official 76:aeb1df146756 1202 * @}
mbed_official 76:aeb1df146756 1203 */
mbed_official 76:aeb1df146756 1204
mbed_official 76:aeb1df146756 1205
mbed_official 76:aeb1df146756 1206 /** @defgroup USART_Group8 Smartcard mode functions
mbed_official 76:aeb1df146756 1207 * @brief Smartcard mode functions
mbed_official 76:aeb1df146756 1208 *
mbed_official 76:aeb1df146756 1209 @verbatim
mbed_official 76:aeb1df146756 1210 ===============================================================================
mbed_official 76:aeb1df146756 1211 ##### Smartcard mode functions #####
mbed_official 76:aeb1df146756 1212 ===============================================================================
mbed_official 76:aeb1df146756 1213 [..] This subsection provides a set of functions allowing to manage the USART
mbed_official 76:aeb1df146756 1214 Smartcard communication.
mbed_official 76:aeb1df146756 1215 [..] The Smartcard interface is designed to support asynchronous protocol
mbed_official 76:aeb1df146756 1216 Smartcards as defined in the ISO 7816-3 standard. The USART can provide
mbed_official 76:aeb1df146756 1217 a clock to the smartcard through the SCLK output. In smartcard mode,
mbed_official 76:aeb1df146756 1218 SCLK is not associated to the communication but is simply derived from
mbed_official 76:aeb1df146756 1219 the internal peripheral input clock through a 5-bit prescaler.
mbed_official 76:aeb1df146756 1220 [..] Smartcard communication is possible through the following procedure:
mbed_official 76:aeb1df146756 1221 (#) Configures the Smartcard Prsecaler using the USART_SetPrescaler()
mbed_official 76:aeb1df146756 1222 function.
mbed_official 76:aeb1df146756 1223 (#) Configures the Smartcard Guard Time using the USART_SetGuardTime()
mbed_official 76:aeb1df146756 1224 function.
mbed_official 76:aeb1df146756 1225 (#) Program the USART clock using the USART_ClockInit() function as following:
mbed_official 76:aeb1df146756 1226 (++) USART Clock enabled.
mbed_official 76:aeb1df146756 1227 (++) USART CPOL Low.
mbed_official 76:aeb1df146756 1228 (++) USART CPHA on first edge.
mbed_official 76:aeb1df146756 1229 (++) USART Last Bit Clock Enabled.
mbed_official 76:aeb1df146756 1230 (#) Program the Smartcard interface using the USART_Init() function as
mbed_official 76:aeb1df146756 1231 following:
mbed_official 76:aeb1df146756 1232 (++) Word Length = 9 Bits.
mbed_official 76:aeb1df146756 1233 (++) 1.5 Stop Bit.
mbed_official 76:aeb1df146756 1234 (++) Even parity.
mbed_official 76:aeb1df146756 1235 (++) BaudRate = 12096 baud.
mbed_official 76:aeb1df146756 1236 (++) Hardware flow control disabled (RTS and CTS signals).
mbed_official 76:aeb1df146756 1237 (++) Tx and Rx enabled
mbed_official 76:aeb1df146756 1238 (#) Optionally you can enable the parity error interrupt using
mbed_official 76:aeb1df146756 1239 the USART_ITConfig() function.
mbed_official 76:aeb1df146756 1240 (#) Enable the Smartcard NACK using the USART_SmartCardNACKCmd() function.
mbed_official 76:aeb1df146756 1241 (#) Enable the Smartcard interface using the USART_SmartCardCmd() function.
mbed_official 76:aeb1df146756 1242 (#) Enable the USART using the USART_Cmd() function.
mbed_official 76:aeb1df146756 1243 [..]
mbed_official 76:aeb1df146756 1244 Please refer to the ISO 7816-3 specification for more details.
mbed_official 76:aeb1df146756 1245 [..]
mbed_official 76:aeb1df146756 1246 (@) It is also possible to choose 0.5 stop bit for receiving but it is
mbed_official 76:aeb1df146756 1247 recommended to use 1.5 stop bits for both transmitting and receiving
mbed_official 76:aeb1df146756 1248 to avoid switching between the two configurations.
mbed_official 76:aeb1df146756 1249 (@) In smartcard mode, the following bits must be kept cleared:
mbed_official 76:aeb1df146756 1250 (+@) LINEN bit in the USART_CR2 register.
mbed_official 76:aeb1df146756 1251 (+@) HDSEL and IREN bits in the USART_CR3 register.
mbed_official 76:aeb1df146756 1252
mbed_official 76:aeb1df146756 1253 @endverbatim
mbed_official 76:aeb1df146756 1254 * @{
mbed_official 76:aeb1df146756 1255 */
mbed_official 76:aeb1df146756 1256
mbed_official 76:aeb1df146756 1257 /**
mbed_official 76:aeb1df146756 1258 * @brief Sets the specified USART guard time.
mbed_official 76:aeb1df146756 1259 * @note This function is not available for STM32F030 devices.
mbed_official 76:aeb1df146756 1260 * @param USARTx: where x can be 1or 2 to select the USART peripheral.
mbed_official 76:aeb1df146756 1261 * @note USART2 is applicable only for STM32F072 devices.
mbed_official 76:aeb1df146756 1262 * @param USART_GuardTime: specifies the guard time.
mbed_official 76:aeb1df146756 1263 * @retval None
mbed_official 76:aeb1df146756 1264 */
mbed_official 76:aeb1df146756 1265 void USART_SetGuardTime(USART_TypeDef* USARTx, uint8_t USART_GuardTime)
mbed_official 76:aeb1df146756 1266 {
mbed_official 76:aeb1df146756 1267 /* Check the parameters */
mbed_official 76:aeb1df146756 1268 assert_param(IS_USART_12_PERIPH(USARTx));
mbed_official 76:aeb1df146756 1269
mbed_official 76:aeb1df146756 1270 /* Clear the USART Guard time */
mbed_official 76:aeb1df146756 1271 USARTx->GTPR &= USART_GTPR_PSC;
mbed_official 76:aeb1df146756 1272 /* Set the USART guard time */
mbed_official 76:aeb1df146756 1273 USARTx->GTPR |= (uint16_t)((uint16_t)USART_GuardTime << 0x08);
mbed_official 76:aeb1df146756 1274 }
mbed_official 76:aeb1df146756 1275
mbed_official 76:aeb1df146756 1276 /**
mbed_official 76:aeb1df146756 1277 * @brief Enables or disables the USART's Smart Card mode.
mbed_official 76:aeb1df146756 1278 * @note This function is not available for STM32F030 devices.
mbed_official 76:aeb1df146756 1279 * @param USARTx: where x can be 1or 2 to select the USART peripheral.
mbed_official 76:aeb1df146756 1280 * @note USART2 is applicable only for STM32F072 devices.
mbed_official 76:aeb1df146756 1281 * @param NewState: new state of the Smart Card mode.
mbed_official 76:aeb1df146756 1282 * This parameter can be: ENABLE or DISABLE.
mbed_official 76:aeb1df146756 1283 * @retval None
mbed_official 76:aeb1df146756 1284 */
mbed_official 76:aeb1df146756 1285 void USART_SmartCardCmd(USART_TypeDef* USARTx, FunctionalState NewState)
mbed_official 76:aeb1df146756 1286 {
mbed_official 76:aeb1df146756 1287 /* Check the parameters */
mbed_official 76:aeb1df146756 1288 assert_param(IS_USART_12_PERIPH(USARTx));
mbed_official 76:aeb1df146756 1289 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 76:aeb1df146756 1290 if (NewState != DISABLE)
mbed_official 76:aeb1df146756 1291 {
mbed_official 76:aeb1df146756 1292 /* Enable the SC mode by setting the SCEN bit in the CR3 register */
mbed_official 76:aeb1df146756 1293 USARTx->CR3 |= USART_CR3_SCEN;
mbed_official 76:aeb1df146756 1294 }
mbed_official 76:aeb1df146756 1295 else
mbed_official 76:aeb1df146756 1296 {
mbed_official 76:aeb1df146756 1297 /* Disable the SC mode by clearing the SCEN bit in the CR3 register */
mbed_official 76:aeb1df146756 1298 USARTx->CR3 &= (uint32_t)~((uint32_t)USART_CR3_SCEN);
mbed_official 76:aeb1df146756 1299 }
mbed_official 76:aeb1df146756 1300 }
mbed_official 76:aeb1df146756 1301
mbed_official 76:aeb1df146756 1302 /**
mbed_official 76:aeb1df146756 1303 * @brief Enables or disables NACK transmission.
mbed_official 76:aeb1df146756 1304 * @note This function is not available for STM32F030 devices.
mbed_official 76:aeb1df146756 1305 * @param USARTx: where x can be 1or 2 to select the USART peripheral.
mbed_official 76:aeb1df146756 1306 * @note USART2 is applicable only for STM32F072 devices.
mbed_official 76:aeb1df146756 1307 * @param NewState: new state of the NACK transmission.
mbed_official 76:aeb1df146756 1308 * This parameter can be: ENABLE or DISABLE.
mbed_official 76:aeb1df146756 1309 * @retval None
mbed_official 76:aeb1df146756 1310 */
mbed_official 76:aeb1df146756 1311 void USART_SmartCardNACKCmd(USART_TypeDef* USARTx, FunctionalState NewState)
mbed_official 76:aeb1df146756 1312 {
mbed_official 76:aeb1df146756 1313 /* Check the parameters */
mbed_official 76:aeb1df146756 1314 assert_param(IS_USART_12_PERIPH(USARTx));
mbed_official 76:aeb1df146756 1315 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 76:aeb1df146756 1316 if (NewState != DISABLE)
mbed_official 76:aeb1df146756 1317 {
mbed_official 76:aeb1df146756 1318 /* Enable the NACK transmission by setting the NACK bit in the CR3 register */
mbed_official 76:aeb1df146756 1319 USARTx->CR3 |= USART_CR3_NACK;
mbed_official 76:aeb1df146756 1320 }
mbed_official 76:aeb1df146756 1321 else
mbed_official 76:aeb1df146756 1322 {
mbed_official 76:aeb1df146756 1323 /* Disable the NACK transmission by clearing the NACK bit in the CR3 register */
mbed_official 76:aeb1df146756 1324 USARTx->CR3 &= (uint32_t)~((uint32_t)USART_CR3_NACK);
mbed_official 76:aeb1df146756 1325 }
mbed_official 76:aeb1df146756 1326 }
mbed_official 76:aeb1df146756 1327
mbed_official 76:aeb1df146756 1328 /**
mbed_official 76:aeb1df146756 1329 * @brief Sets the Smart Card number of retries in transmit and receive.
mbed_official 76:aeb1df146756 1330 * @note This function is not available for STM32F030 devices.
mbed_official 76:aeb1df146756 1331 * @param USARTx: where x can be 1or 2 to select the USART peripheral.
mbed_official 76:aeb1df146756 1332 * @note USART2 is applicable only for STM32F072 devices.
mbed_official 76:aeb1df146756 1333 * @param USART_AutoCount: specifies the Smart Card auto retry count.
mbed_official 76:aeb1df146756 1334 * @retval None
mbed_official 76:aeb1df146756 1335 */
mbed_official 76:aeb1df146756 1336 void USART_SetAutoRetryCount(USART_TypeDef* USARTx, uint8_t USART_AutoCount)
mbed_official 76:aeb1df146756 1337 {
mbed_official 76:aeb1df146756 1338 /* Check the parameters */
mbed_official 76:aeb1df146756 1339 assert_param(IS_USART_12_PERIPH(USARTx));
mbed_official 76:aeb1df146756 1340 assert_param(IS_USART_AUTO_RETRY_COUNTER(USART_AutoCount));
mbed_official 76:aeb1df146756 1341 /* Clear the USART auto retry count */
mbed_official 76:aeb1df146756 1342 USARTx->CR3 &= (uint32_t)~((uint32_t)USART_CR3_SCARCNT);
mbed_official 76:aeb1df146756 1343 /* Set the USART auto retry count*/
mbed_official 76:aeb1df146756 1344 USARTx->CR3 |= (uint32_t)((uint32_t)USART_AutoCount << 0x11);
mbed_official 76:aeb1df146756 1345 }
mbed_official 76:aeb1df146756 1346
mbed_official 76:aeb1df146756 1347 /**
mbed_official 76:aeb1df146756 1348 * @brief Sets the Smart Card Block length.
mbed_official 76:aeb1df146756 1349 * @note This function is not available for STM32F030 devices.
mbed_official 76:aeb1df146756 1350 * @param USARTx: where x can be 1or 2 to select the USART peripheral.
mbed_official 76:aeb1df146756 1351 * @note USART2 is applicable only for STM32F072 devices.
mbed_official 76:aeb1df146756 1352 * @param USART_BlockLength: specifies the Smart Card block length.
mbed_official 76:aeb1df146756 1353 * @retval None
mbed_official 76:aeb1df146756 1354 */
mbed_official 76:aeb1df146756 1355 void USART_SetBlockLength(USART_TypeDef* USARTx, uint8_t USART_BlockLength)
mbed_official 76:aeb1df146756 1356 {
mbed_official 76:aeb1df146756 1357 /* Check the parameters */
mbed_official 76:aeb1df146756 1358 assert_param(IS_USART_12_PERIPH(USARTx));
mbed_official 76:aeb1df146756 1359
mbed_official 76:aeb1df146756 1360 /* Clear the Smart card block length */
mbed_official 76:aeb1df146756 1361 USARTx->RTOR &= (uint32_t)~((uint32_t)USART_RTOR_BLEN);
mbed_official 76:aeb1df146756 1362 /* Set the Smart Card block length */
mbed_official 76:aeb1df146756 1363 USARTx->RTOR |= (uint32_t)((uint32_t)USART_BlockLength << 0x18);
mbed_official 76:aeb1df146756 1364 }
mbed_official 76:aeb1df146756 1365
mbed_official 76:aeb1df146756 1366 /**
mbed_official 76:aeb1df146756 1367 * @}
mbed_official 76:aeb1df146756 1368 */
mbed_official 76:aeb1df146756 1369
mbed_official 76:aeb1df146756 1370 /** @defgroup USART_Group9 IrDA mode functions
mbed_official 76:aeb1df146756 1371 * @brief IrDA mode functions
mbed_official 76:aeb1df146756 1372 *
mbed_official 76:aeb1df146756 1373 @verbatim
mbed_official 76:aeb1df146756 1374 ===============================================================================
mbed_official 76:aeb1df146756 1375 ##### IrDA mode functions #####
mbed_official 76:aeb1df146756 1376 ===============================================================================
mbed_official 76:aeb1df146756 1377 [..] This subsection provides a set of functions allowing to manage the USART
mbed_official 76:aeb1df146756 1378 IrDA communication.
mbed_official 76:aeb1df146756 1379 [..] IrDA is a half duplex communication protocol. If the Transmitter is busy,
mbed_official 76:aeb1df146756 1380 any data on the IrDA receive line will be ignored by the IrDA decoder
mbed_official 76:aeb1df146756 1381 and if the Receiver is busy, data on the TX from the USART to IrDA will
mbed_official 76:aeb1df146756 1382 not be encoded by IrDA. While receiving data, transmission should be
mbed_official 76:aeb1df146756 1383 avoided as the data to be transmitted could be corrupted.
mbed_official 76:aeb1df146756 1384 [..] IrDA communication is possible through the following procedure:
mbed_official 76:aeb1df146756 1385 (#) Program the Baud rate, Word length = 8 bits, Stop bits, Parity,
mbed_official 76:aeb1df146756 1386 Transmitter/Receiver modes and hardware flow control values using
mbed_official 76:aeb1df146756 1387 the USART_Init() function.
mbed_official 76:aeb1df146756 1388 (#) Configures the IrDA pulse width by configuring the prescaler using
mbed_official 76:aeb1df146756 1389 the USART_SetPrescaler() function.
mbed_official 76:aeb1df146756 1390 (#) Configures the IrDA USART_IrDAMode_LowPower or USART_IrDAMode_Normal
mbed_official 76:aeb1df146756 1391 mode using the USART_IrDAConfig() function.
mbed_official 76:aeb1df146756 1392 (#) Enable the IrDA using the USART_IrDACmd() function.
mbed_official 76:aeb1df146756 1393 (#) Enable the USART using the USART_Cmd() function.
mbed_official 76:aeb1df146756 1394 [..]
mbed_official 76:aeb1df146756 1395 (@) A pulse of width less than two and greater than one PSC period(s) may or
mbed_official 76:aeb1df146756 1396 may not be rejected.
mbed_official 76:aeb1df146756 1397 (@) The receiver set up time should be managed by software. The IrDA physical
mbed_official 76:aeb1df146756 1398 layer specification specifies a minimum of 10 ms delay between
mbed_official 76:aeb1df146756 1399 transmission and reception (IrDA is a half duplex protocol).
mbed_official 76:aeb1df146756 1400 (@) In IrDA mode, the following bits must be kept cleared:
mbed_official 76:aeb1df146756 1401 (+@) LINEN, STOP and CLKEN bits in the USART_CR2 register.
mbed_official 76:aeb1df146756 1402 (+@) SCEN and HDSEL bits in the USART_CR3 register.
mbed_official 76:aeb1df146756 1403
mbed_official 76:aeb1df146756 1404 @endverbatim
mbed_official 76:aeb1df146756 1405 * @{
mbed_official 76:aeb1df146756 1406 */
mbed_official 76:aeb1df146756 1407
mbed_official 76:aeb1df146756 1408 /**
mbed_official 76:aeb1df146756 1409 * @brief Configures the USART's IrDA interface.
mbed_official 76:aeb1df146756 1410 * @note This function is not available for STM32F030 devices.
mbed_official 76:aeb1df146756 1411 * @param USARTx: where x can be 1or 2 to select the USART peripheral.
mbed_official 76:aeb1df146756 1412 * @note USART2 is applicable only for STM32F072 devices.
mbed_official 76:aeb1df146756 1413 * @param USART_IrDAMode: specifies the IrDA mode.
mbed_official 76:aeb1df146756 1414 * This parameter can be one of the following values:
mbed_official 76:aeb1df146756 1415 * @arg USART_IrDAMode_LowPower
mbed_official 76:aeb1df146756 1416 * @arg USART_IrDAMode_Normal
mbed_official 76:aeb1df146756 1417 * @retval None
mbed_official 76:aeb1df146756 1418 */
mbed_official 76:aeb1df146756 1419 void USART_IrDAConfig(USART_TypeDef* USARTx, uint32_t USART_IrDAMode)
mbed_official 76:aeb1df146756 1420 {
mbed_official 76:aeb1df146756 1421 /* Check the parameters */
mbed_official 76:aeb1df146756 1422 assert_param(IS_USART_12_PERIPH(USARTx));
mbed_official 76:aeb1df146756 1423 assert_param(IS_USART_IRDA_MODE(USART_IrDAMode));
mbed_official 76:aeb1df146756 1424
mbed_official 76:aeb1df146756 1425 USARTx->CR3 &= (uint32_t)~((uint32_t)USART_CR3_IRLP);
mbed_official 76:aeb1df146756 1426 USARTx->CR3 |= USART_IrDAMode;
mbed_official 76:aeb1df146756 1427 }
mbed_official 76:aeb1df146756 1428
mbed_official 76:aeb1df146756 1429 /**
mbed_official 76:aeb1df146756 1430 * @brief Enables or disables the USART's IrDA interface.
mbed_official 76:aeb1df146756 1431 * @note This function is not available for STM32F030 devices.
mbed_official 76:aeb1df146756 1432 * @param USARTx: where x can be 1or 2 to select the USART peripheral.
mbed_official 76:aeb1df146756 1433 * @note USART2 is applicable only for STM32F072 devices.
mbed_official 76:aeb1df146756 1434 * @param NewState: new state of the IrDA mode.
mbed_official 76:aeb1df146756 1435 * This parameter can be: ENABLE or DISABLE.
mbed_official 76:aeb1df146756 1436 * @retval None
mbed_official 76:aeb1df146756 1437 */
mbed_official 76:aeb1df146756 1438 void USART_IrDACmd(USART_TypeDef* USARTx, FunctionalState NewState)
mbed_official 76:aeb1df146756 1439 {
mbed_official 76:aeb1df146756 1440 /* Check the parameters */
mbed_official 76:aeb1df146756 1441 assert_param(IS_USART_12_PERIPH(USARTx));
mbed_official 76:aeb1df146756 1442 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 76:aeb1df146756 1443
mbed_official 76:aeb1df146756 1444 if (NewState != DISABLE)
mbed_official 76:aeb1df146756 1445 {
mbed_official 76:aeb1df146756 1446 /* Enable the IrDA mode by setting the IREN bit in the CR3 register */
mbed_official 76:aeb1df146756 1447 USARTx->CR3 |= USART_CR3_IREN;
mbed_official 76:aeb1df146756 1448 }
mbed_official 76:aeb1df146756 1449 else
mbed_official 76:aeb1df146756 1450 {
mbed_official 76:aeb1df146756 1451 /* Disable the IrDA mode by clearing the IREN bit in the CR3 register */
mbed_official 76:aeb1df146756 1452 USARTx->CR3 &= (uint32_t)~((uint32_t)USART_CR3_IREN);
mbed_official 76:aeb1df146756 1453 }
mbed_official 76:aeb1df146756 1454 }
mbed_official 76:aeb1df146756 1455 /**
mbed_official 76:aeb1df146756 1456 * @}
mbed_official 76:aeb1df146756 1457 */
mbed_official 76:aeb1df146756 1458
mbed_official 76:aeb1df146756 1459 /** @defgroup USART_Group10 RS485 mode function
mbed_official 76:aeb1df146756 1460 * @brief RS485 mode function
mbed_official 76:aeb1df146756 1461 *
mbed_official 76:aeb1df146756 1462 @verbatim
mbed_official 76:aeb1df146756 1463 ===============================================================================
mbed_official 76:aeb1df146756 1464 ##### RS485 mode functions #####
mbed_official 76:aeb1df146756 1465 ===============================================================================
mbed_official 76:aeb1df146756 1466 [..] This subsection provides a set of functions allowing to manage the USART
mbed_official 76:aeb1df146756 1467 RS485 flow control.
mbed_official 76:aeb1df146756 1468 [..] RS485 flow control (Driver enable feature) handling is possible through
mbed_official 76:aeb1df146756 1469 the following procedure:
mbed_official 76:aeb1df146756 1470 (#) Program the Baud rate, Word length = 8 bits, Stop bits, Parity,
mbed_official 76:aeb1df146756 1471 Transmitter/Receiver modes and hardware flow control values using
mbed_official 76:aeb1df146756 1472 the USART_Init() function.
mbed_official 76:aeb1df146756 1473 (#) Enable the Driver Enable using the USART_DECmd() function.
mbed_official 76:aeb1df146756 1474 (#) Configures the Driver Enable polarity using the USART_DEPolarityConfig()
mbed_official 76:aeb1df146756 1475 function.
mbed_official 76:aeb1df146756 1476 (#) Configures the Driver Enable assertion time using USART_SetDEAssertionTime()
mbed_official 76:aeb1df146756 1477 function and deassertion time using the USART_SetDEDeassertionTime()
mbed_official 76:aeb1df146756 1478 function.
mbed_official 76:aeb1df146756 1479 (#) Enable the USART using the USART_Cmd() function.
mbed_official 76:aeb1df146756 1480 -@-
mbed_official 76:aeb1df146756 1481 (+@) The assertion and dessertion times are expressed in sample time units (1/8 or
mbed_official 76:aeb1df146756 1482 1/16 bit time, depending on the oversampling rate).
mbed_official 76:aeb1df146756 1483
mbed_official 76:aeb1df146756 1484 @endverbatim
mbed_official 76:aeb1df146756 1485 * @{
mbed_official 76:aeb1df146756 1486 */
mbed_official 76:aeb1df146756 1487
mbed_official 76:aeb1df146756 1488 /**
mbed_official 76:aeb1df146756 1489 * @brief Enables or disables the USART's DE functionality.
mbed_official 76:aeb1df146756 1490 * @param USARTx: where x can be 1, 2, 3 or 4 to select the USART peripheral.
mbed_official 76:aeb1df146756 1491 * @note USART3 and USART4 are available only for STM32F072 devices.
mbed_official 76:aeb1df146756 1492 * @note USART2 is not available for STM32F031 devices.
mbed_official 76:aeb1df146756 1493 * @param NewState: new state of the driver enable mode.
mbed_official 76:aeb1df146756 1494 * This parameter can be: ENABLE or DISABLE.
mbed_official 76:aeb1df146756 1495 * @retval None
mbed_official 76:aeb1df146756 1496 */
mbed_official 76:aeb1df146756 1497 void USART_DECmd(USART_TypeDef* USARTx, FunctionalState NewState)
mbed_official 76:aeb1df146756 1498 {
mbed_official 76:aeb1df146756 1499 /* Check the parameters */
mbed_official 76:aeb1df146756 1500 assert_param(IS_USART_ALL_PERIPH(USARTx));
mbed_official 76:aeb1df146756 1501 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 76:aeb1df146756 1502 if (NewState != DISABLE)
mbed_official 76:aeb1df146756 1503 {
mbed_official 76:aeb1df146756 1504 /* Enable the DE functionality by setting the DEM bit in the CR3 register */
mbed_official 76:aeb1df146756 1505 USARTx->CR3 |= USART_CR3_DEM;
mbed_official 76:aeb1df146756 1506 }
mbed_official 76:aeb1df146756 1507 else
mbed_official 76:aeb1df146756 1508 {
mbed_official 76:aeb1df146756 1509 /* Disable the DE functionality by clearing the DEM bit in the CR3 register */
mbed_official 76:aeb1df146756 1510 USARTx->CR3 &= (uint32_t)~((uint32_t)USART_CR3_DEM);
mbed_official 76:aeb1df146756 1511 }
mbed_official 76:aeb1df146756 1512 }
mbed_official 76:aeb1df146756 1513
mbed_official 76:aeb1df146756 1514 /**
mbed_official 76:aeb1df146756 1515 * @brief Configures the USART's DE polarity
mbed_official 76:aeb1df146756 1516 * @param USARTx: where x can be 1, 2, 3 or 4 to select the USART peripheral.
mbed_official 76:aeb1df146756 1517 * @note USART3 and USART4 are available only for STM32F072 devices.
mbed_official 76:aeb1df146756 1518 * @note USART2 is not available for STM32F031 devices.
mbed_official 76:aeb1df146756 1519 * @param USART_DEPolarity: specifies the DE polarity.
mbed_official 76:aeb1df146756 1520 * This parameter can be one of the following values:
mbed_official 76:aeb1df146756 1521 * @arg USART_DEPolarity_Low
mbed_official 76:aeb1df146756 1522 * @arg USART_DEPolarity_High
mbed_official 76:aeb1df146756 1523 * @retval None
mbed_official 76:aeb1df146756 1524 */
mbed_official 76:aeb1df146756 1525 void USART_DEPolarityConfig(USART_TypeDef* USARTx, uint32_t USART_DEPolarity)
mbed_official 76:aeb1df146756 1526 {
mbed_official 76:aeb1df146756 1527 /* Check the parameters */
mbed_official 76:aeb1df146756 1528 assert_param(IS_USART_ALL_PERIPH(USARTx));
mbed_official 76:aeb1df146756 1529 assert_param(IS_USART_DE_POLARITY(USART_DEPolarity));
mbed_official 76:aeb1df146756 1530
mbed_official 76:aeb1df146756 1531 USARTx->CR3 &= (uint32_t)~((uint32_t)USART_CR3_DEP);
mbed_official 76:aeb1df146756 1532 USARTx->CR3 |= USART_DEPolarity;
mbed_official 76:aeb1df146756 1533 }
mbed_official 76:aeb1df146756 1534
mbed_official 76:aeb1df146756 1535 /**
mbed_official 76:aeb1df146756 1536 * @brief Sets the specified RS485 DE assertion time
mbed_official 76:aeb1df146756 1537 * @param USARTx: where x can be 1, 2, 3 or 4 to select the USART peripheral.
mbed_official 76:aeb1df146756 1538 * @note USART3 and USART4 are available only for STM32F072 devices.
mbed_official 76:aeb1df146756 1539 * @note USART2 is not available for STM32F031 devices.
mbed_official 76:aeb1df146756 1540 * @param USART_DEAssertionTime: specifies the time between the activation of
mbed_official 76:aeb1df146756 1541 * the DE signal and the beginning of the start bit
mbed_official 76:aeb1df146756 1542 * @retval None
mbed_official 76:aeb1df146756 1543 */
mbed_official 76:aeb1df146756 1544 void USART_SetDEAssertionTime(USART_TypeDef* USARTx, uint32_t USART_DEAssertionTime)
mbed_official 76:aeb1df146756 1545 {
mbed_official 76:aeb1df146756 1546 /* Check the parameters */
mbed_official 76:aeb1df146756 1547 assert_param(IS_USART_ALL_PERIPH(USARTx));
mbed_official 76:aeb1df146756 1548 assert_param(IS_USART_DE_ASSERTION_DEASSERTION_TIME(USART_DEAssertionTime));
mbed_official 76:aeb1df146756 1549
mbed_official 76:aeb1df146756 1550 /* Clear the DE assertion time */
mbed_official 76:aeb1df146756 1551 USARTx->CR1 &= (uint32_t)~((uint32_t)USART_CR1_DEAT);
mbed_official 76:aeb1df146756 1552 /* Set the new value for the DE assertion time */
mbed_official 76:aeb1df146756 1553 USARTx->CR1 |=((uint32_t)USART_DEAssertionTime << (uint32_t)0x15);
mbed_official 76:aeb1df146756 1554 }
mbed_official 76:aeb1df146756 1555
mbed_official 76:aeb1df146756 1556 /**
mbed_official 76:aeb1df146756 1557 * @brief Sets the specified RS485 DE deassertion time
mbed_official 76:aeb1df146756 1558 * @param USARTx: where x can be 1, 2, 3 or 4 to select the USART peripheral.
mbed_official 76:aeb1df146756 1559 * @note USART3 and USART4 are available only for STM32F072 devices.
mbed_official 76:aeb1df146756 1560 * @note USART2 is not available for STM32F031 devices.
mbed_official 76:aeb1df146756 1561 * @param USART_DeassertionTime: specifies the time between the middle of the last
mbed_official 76:aeb1df146756 1562 * stop bit in a transmitted message and the de-activation of the DE signal
mbed_official 76:aeb1df146756 1563 * @retval None
mbed_official 76:aeb1df146756 1564 */
mbed_official 76:aeb1df146756 1565 void USART_SetDEDeassertionTime(USART_TypeDef* USARTx, uint32_t USART_DEDeassertionTime)
mbed_official 76:aeb1df146756 1566 {
mbed_official 76:aeb1df146756 1567 /* Check the parameters */
mbed_official 76:aeb1df146756 1568 assert_param(IS_USART_ALL_PERIPH(USARTx));
mbed_official 76:aeb1df146756 1569 assert_param(IS_USART_DE_ASSERTION_DEASSERTION_TIME(USART_DEDeassertionTime));
mbed_official 76:aeb1df146756 1570
mbed_official 76:aeb1df146756 1571 /* Clear the DE deassertion time */
mbed_official 76:aeb1df146756 1572 USARTx->CR1 &= (uint32_t)~((uint32_t)USART_CR1_DEDT);
mbed_official 76:aeb1df146756 1573 /* Set the new value for the DE deassertion time */
mbed_official 76:aeb1df146756 1574 USARTx->CR1 |=((uint32_t)USART_DEDeassertionTime << (uint32_t)0x10);
mbed_official 76:aeb1df146756 1575 }
mbed_official 76:aeb1df146756 1576
mbed_official 76:aeb1df146756 1577 /**
mbed_official 76:aeb1df146756 1578 * @}
mbed_official 76:aeb1df146756 1579 */
mbed_official 76:aeb1df146756 1580
mbed_official 76:aeb1df146756 1581 /** @defgroup USART_Group11 DMA transfers management functions
mbed_official 76:aeb1df146756 1582 * @brief DMA transfers management functions
mbed_official 76:aeb1df146756 1583 *
mbed_official 76:aeb1df146756 1584 @verbatim
mbed_official 76:aeb1df146756 1585 ===============================================================================
mbed_official 76:aeb1df146756 1586 ##### DMA transfers management functions #####
mbed_official 76:aeb1df146756 1587 ===============================================================================
mbed_official 76:aeb1df146756 1588 [..] This section provides two functions that can be used only in DMA mode.
mbed_official 76:aeb1df146756 1589 [..] In DMA Mode, the USART communication can be managed by 2 DMA Channel
mbed_official 76:aeb1df146756 1590 requests:
mbed_official 76:aeb1df146756 1591 (#) USART_DMAReq_Tx: specifies the Tx buffer DMA transfer request.
mbed_official 76:aeb1df146756 1592 (#) USART_DMAReq_Rx: specifies the Rx buffer DMA transfer request.
mbed_official 76:aeb1df146756 1593 [..] In this Mode it is advised to use the following function:
mbed_official 76:aeb1df146756 1594 (+) void USART_DMACmd(USART_TypeDef* USARTx, uint16_t USART_DMAReq,
mbed_official 76:aeb1df146756 1595 FunctionalState NewState).
mbed_official 76:aeb1df146756 1596 @endverbatim
mbed_official 76:aeb1df146756 1597 * @{
mbed_official 76:aeb1df146756 1598 */
mbed_official 76:aeb1df146756 1599
mbed_official 76:aeb1df146756 1600 /**
mbed_official 76:aeb1df146756 1601 * @brief Enables or disables the USART's DMA interface.
mbed_official 76:aeb1df146756 1602 * @param USARTx: where x can be 1, 2, 3 or 4 to select the USART peripheral.
mbed_official 76:aeb1df146756 1603 * @note USART3 and USART4 are available only for STM32F072 devices.
mbed_official 76:aeb1df146756 1604 * @note USART2 is not available for STM32F031 devices.
mbed_official 76:aeb1df146756 1605 * @param USART_DMAReq: specifies the DMA request.
mbed_official 76:aeb1df146756 1606 * This parameter can be any combination of the following values:
mbed_official 76:aeb1df146756 1607 * @arg USART_DMAReq_Tx: USART DMA transmit request
mbed_official 76:aeb1df146756 1608 * @arg USART_DMAReq_Rx: USART DMA receive request
mbed_official 76:aeb1df146756 1609 * @param NewState: new state of the DMA Request sources.
mbed_official 76:aeb1df146756 1610 * This parameter can be: ENABLE or DISABLE.
mbed_official 76:aeb1df146756 1611 * @retval None
mbed_official 76:aeb1df146756 1612 */
mbed_official 76:aeb1df146756 1613 void USART_DMACmd(USART_TypeDef* USARTx, uint32_t USART_DMAReq, FunctionalState NewState)
mbed_official 76:aeb1df146756 1614 {
mbed_official 76:aeb1df146756 1615 /* Check the parameters */
mbed_official 76:aeb1df146756 1616 assert_param(IS_USART_ALL_PERIPH(USARTx));
mbed_official 76:aeb1df146756 1617 assert_param(IS_USART_DMAREQ(USART_DMAReq));
mbed_official 76:aeb1df146756 1618 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 76:aeb1df146756 1619
mbed_official 76:aeb1df146756 1620 if (NewState != DISABLE)
mbed_official 76:aeb1df146756 1621 {
mbed_official 76:aeb1df146756 1622 /* Enable the DMA transfer for selected requests by setting the DMAT and/or
mbed_official 76:aeb1df146756 1623 DMAR bits in the USART CR3 register */
mbed_official 76:aeb1df146756 1624 USARTx->CR3 |= USART_DMAReq;
mbed_official 76:aeb1df146756 1625 }
mbed_official 76:aeb1df146756 1626 else
mbed_official 76:aeb1df146756 1627 {
mbed_official 76:aeb1df146756 1628 /* Disable the DMA transfer for selected requests by clearing the DMAT and/or
mbed_official 76:aeb1df146756 1629 DMAR bits in the USART CR3 register */
mbed_official 76:aeb1df146756 1630 USARTx->CR3 &= (uint32_t)~USART_DMAReq;
mbed_official 76:aeb1df146756 1631 }
mbed_official 76:aeb1df146756 1632 }
mbed_official 76:aeb1df146756 1633
mbed_official 76:aeb1df146756 1634 /**
mbed_official 76:aeb1df146756 1635 * @brief Enables or disables the USART's DMA interface when reception error occurs.
mbed_official 76:aeb1df146756 1636 * @param USARTx: where x can be 1, 2, 3 or 4 to select the USART peripheral.
mbed_official 76:aeb1df146756 1637 * @note USART3 and USART4 are available only for STM32F072 devices.
mbed_official 76:aeb1df146756 1638 * @note USART2 is not available for STM32F031 devices.
mbed_official 76:aeb1df146756 1639 * @param USART_DMAOnError: specifies the DMA status in case of reception error.
mbed_official 76:aeb1df146756 1640 * This parameter can be any combination of the following values:
mbed_official 76:aeb1df146756 1641 * @arg USART_DMAOnError_Enable: DMA receive request enabled when the USART DMA
mbed_official 76:aeb1df146756 1642 * reception error is asserted.
mbed_official 76:aeb1df146756 1643 * @arg USART_DMAOnError_Disable: DMA receive request disabled when the USART DMA
mbed_official 76:aeb1df146756 1644 * reception error is asserted.
mbed_official 76:aeb1df146756 1645 * @retval None
mbed_official 76:aeb1df146756 1646 */
mbed_official 76:aeb1df146756 1647 void USART_DMAReceptionErrorConfig(USART_TypeDef* USARTx, uint32_t USART_DMAOnError)
mbed_official 76:aeb1df146756 1648 {
mbed_official 76:aeb1df146756 1649 /* Check the parameters */
mbed_official 76:aeb1df146756 1650 assert_param(IS_USART_ALL_PERIPH(USARTx));
mbed_official 76:aeb1df146756 1651 assert_param(IS_USART_DMAONERROR(USART_DMAOnError));
mbed_official 76:aeb1df146756 1652
mbed_official 76:aeb1df146756 1653 /* Clear the DMA Reception error detection bit */
mbed_official 76:aeb1df146756 1654 USARTx->CR3 &= (uint32_t)~((uint32_t)USART_CR3_DDRE);
mbed_official 76:aeb1df146756 1655 /* Set the new value for the DMA Reception error detection bit */
mbed_official 76:aeb1df146756 1656 USARTx->CR3 |= USART_DMAOnError;
mbed_official 76:aeb1df146756 1657 }
mbed_official 76:aeb1df146756 1658
mbed_official 76:aeb1df146756 1659 /**
mbed_official 76:aeb1df146756 1660 * @}
mbed_official 76:aeb1df146756 1661 */
mbed_official 76:aeb1df146756 1662
mbed_official 76:aeb1df146756 1663 /** @defgroup USART_Group12 Interrupts and flags management functions
mbed_official 76:aeb1df146756 1664 * @brief Interrupts and flags management functions
mbed_official 76:aeb1df146756 1665 *
mbed_official 76:aeb1df146756 1666 @verbatim
mbed_official 76:aeb1df146756 1667 ===============================================================================
mbed_official 76:aeb1df146756 1668 ##### Interrupts and flags management functions #####
mbed_official 76:aeb1df146756 1669 ===============================================================================
mbed_official 76:aeb1df146756 1670 [..] This subsection provides a set of functions allowing to configure the
mbed_official 76:aeb1df146756 1671 USART Interrupts sources, Requests and check or clear the flags or pending bits status.
mbed_official 76:aeb1df146756 1672 The user should identify which mode will be used in his application to
mbed_official 76:aeb1df146756 1673 manage the communication: Polling mode, Interrupt mode.
mbed_official 76:aeb1df146756 1674
mbed_official 76:aeb1df146756 1675 *** Polling Mode ***
mbed_official 76:aeb1df146756 1676 ====================
mbed_official 76:aeb1df146756 1677 [..] In Polling Mode, the SPI communication can be managed by these flags:
mbed_official 76:aeb1df146756 1678 (#) USART_FLAG_REACK: to indicate the status of the Receive Enable
mbed_official 76:aeb1df146756 1679 acknowledge flag
mbed_official 76:aeb1df146756 1680 (#) USART_FLAG_TEACK: to indicate the status of the Transmit Enable
mbed_official 76:aeb1df146756 1681 acknowledge flag.
mbed_official 76:aeb1df146756 1682 (#) USART_FLAG_WU: to indicate the status of the Wake up flag.
mbed_official 76:aeb1df146756 1683 (#) USART_FLAG_RWU: to indicate the status of the Receive Wake up flag.
mbed_official 76:aeb1df146756 1684 (#) USART_FLAG_SBK: to indicate the status of the Send Break flag.
mbed_official 76:aeb1df146756 1685 (#) USART_FLAG_CM: to indicate the status of the Character match flag.
mbed_official 76:aeb1df146756 1686 (#) USART_FLAG_BUSY: to indicate the status of the Busy flag.
mbed_official 76:aeb1df146756 1687 (#) USART_FLAG_ABRF: to indicate the status of the Auto baud rate flag.
mbed_official 76:aeb1df146756 1688 (#) USART_FLAG_ABRE: to indicate the status of the Auto baud rate error flag.
mbed_official 76:aeb1df146756 1689 (#) USART_FLAG_EOB: to indicate the status of the End of block flag.
mbed_official 76:aeb1df146756 1690 (#) USART_FLAG_RTO: to indicate the status of the Receive time out flag.
mbed_official 76:aeb1df146756 1691 (#) USART_FLAG_nCTSS: to indicate the status of the Inverted nCTS input
mbed_official 76:aeb1df146756 1692 bit status.
mbed_official 76:aeb1df146756 1693 (#) USART_FLAG_TXE: to indicate the status of the transmit buffer register.
mbed_official 76:aeb1df146756 1694 (#) USART_FLAG_RXNE: to indicate the status of the receive buffer register.
mbed_official 76:aeb1df146756 1695 (#) USART_FLAG_TC: to indicate the status of the transmit operation.
mbed_official 76:aeb1df146756 1696 (#) USART_FLAG_IDLE: to indicate the status of the Idle Line.
mbed_official 76:aeb1df146756 1697 (#) USART_FLAG_CTS: to indicate the status of the nCTS input.
mbed_official 76:aeb1df146756 1698 (#) USART_FLAG_LBD: to indicate the status of the LIN break detection.
mbed_official 76:aeb1df146756 1699 (#) USART_FLAG_NE: to indicate if a noise error occur.
mbed_official 76:aeb1df146756 1700 (#) USART_FLAG_FE: to indicate if a frame error occur.
mbed_official 76:aeb1df146756 1701 (#) USART_FLAG_PE: to indicate if a parity error occur.
mbed_official 76:aeb1df146756 1702 (#) USART_FLAG_ORE: to indicate if an Overrun error occur.
mbed_official 76:aeb1df146756 1703 [..] In this Mode it is advised to use the following functions:
mbed_official 76:aeb1df146756 1704 (+) FlagStatus USART_GetFlagStatus(USART_TypeDef* USARTx, uint16_t USART_FLAG).
mbed_official 76:aeb1df146756 1705 (+) void USART_ClearFlag(USART_TypeDef* USARTx, uint16_t USART_FLAG).
mbed_official 76:aeb1df146756 1706
mbed_official 76:aeb1df146756 1707 *** Interrupt Mode ***
mbed_official 76:aeb1df146756 1708 ======================
mbed_official 76:aeb1df146756 1709 [..] In Interrupt Mode, the USART communication can be managed by 8 interrupt
mbed_official 76:aeb1df146756 1710 sources and 10 pending bits:
mbed_official 76:aeb1df146756 1711 (+) Pending Bits:
mbed_official 76:aeb1df146756 1712 (##) USART_IT_WU: to indicate the status of the Wake up interrupt.
mbed_official 76:aeb1df146756 1713 (##) USART_IT_CM: to indicate the status of Character match interrupt.
mbed_official 76:aeb1df146756 1714 (##) USART_IT_EOB: to indicate the status of End of block interrupt.
mbed_official 76:aeb1df146756 1715 (##) USART_IT_RTO: to indicate the status of Receive time out interrupt.
mbed_official 76:aeb1df146756 1716 (##) USART_IT_CTS: to indicate the status of CTS change interrupt.
mbed_official 76:aeb1df146756 1717 (##) USART_IT_LBD: to indicate the status of LIN Break detection interrupt.
mbed_official 76:aeb1df146756 1718 (##) USART_IT_TC: to indicate the status of Transmission complete interrupt.
mbed_official 76:aeb1df146756 1719 (##) USART_IT_IDLE: to indicate the status of IDLE line detected interrupt.
mbed_official 76:aeb1df146756 1720 (##) USART_IT_ORE: to indicate the status of OverRun Error interrupt.
mbed_official 76:aeb1df146756 1721 (##) USART_IT_NE: to indicate the status of Noise Error interrupt.
mbed_official 76:aeb1df146756 1722 (##) USART_IT_FE: to indicate the status of Framing Error interrupt.
mbed_official 76:aeb1df146756 1723 (##) USART_IT_PE: to indicate the status of Parity Error interrupt.
mbed_official 76:aeb1df146756 1724
mbed_official 76:aeb1df146756 1725 (+) Interrupt Source:
mbed_official 76:aeb1df146756 1726 (##) USART_IT_WU: specifies the interrupt source for Wake up interrupt.
mbed_official 76:aeb1df146756 1727 (##) USART_IT_CM: specifies the interrupt source for Character match
mbed_official 76:aeb1df146756 1728 interrupt.
mbed_official 76:aeb1df146756 1729 (##) USART_IT_EOB: specifies the interrupt source for End of block
mbed_official 76:aeb1df146756 1730 interrupt.
mbed_official 76:aeb1df146756 1731 (##) USART_IT_RTO: specifies the interrupt source for Receive time-out
mbed_official 76:aeb1df146756 1732 interrupt.
mbed_official 76:aeb1df146756 1733 (##) USART_IT_CTS: specifies the interrupt source for CTS change interrupt.
mbed_official 76:aeb1df146756 1734 (##) USART_IT_LBD: specifies the interrupt source for LIN Break
mbed_official 76:aeb1df146756 1735 detection interrupt.
mbed_official 76:aeb1df146756 1736 (##) USART_IT_TXE: specifies the interrupt source for Tansmit Data
mbed_official 76:aeb1df146756 1737 Register empty interrupt.
mbed_official 76:aeb1df146756 1738 (##) USART_IT_TC: specifies the interrupt source for Transmission
mbed_official 76:aeb1df146756 1739 complete interrupt.
mbed_official 76:aeb1df146756 1740 (##) USART_IT_RXNE: specifies the interrupt source for Receive Data
mbed_official 76:aeb1df146756 1741 register not empty interrupt.
mbed_official 76:aeb1df146756 1742 (##) USART_IT_IDLE: specifies the interrupt source for Idle line
mbed_official 76:aeb1df146756 1743 detection interrupt.
mbed_official 76:aeb1df146756 1744 (##) USART_IT_PE: specifies the interrupt source for Parity Error interrupt.
mbed_official 76:aeb1df146756 1745 (##) USART_IT_ERR: specifies the interrupt source for Error interrupt
mbed_official 76:aeb1df146756 1746 (Frame error, noise error, overrun error)
mbed_official 76:aeb1df146756 1747 -@@- Some parameters are coded in order to use them as interrupt
mbed_official 76:aeb1df146756 1748 source or as pending bits.
mbed_official 76:aeb1df146756 1749 [..] In this Mode it is advised to use the following functions:
mbed_official 76:aeb1df146756 1750 (+) void USART_ITConfig(USART_TypeDef* USARTx, uint16_t USART_IT, FunctionalState NewState).
mbed_official 76:aeb1df146756 1751 (+) ITStatus USART_GetITStatus(USART_TypeDef* USARTx, uint16_t USART_IT).
mbed_official 76:aeb1df146756 1752 (+) void USART_ClearITPendingBit(USART_TypeDef* USARTx, uint16_t USART_IT).
mbed_official 76:aeb1df146756 1753
mbed_official 76:aeb1df146756 1754 @endverbatim
mbed_official 76:aeb1df146756 1755 * @{
mbed_official 76:aeb1df146756 1756 */
mbed_official 76:aeb1df146756 1757
mbed_official 76:aeb1df146756 1758 /**
mbed_official 76:aeb1df146756 1759 * @brief Enables or disables the specified USART interrupts.
mbed_official 76:aeb1df146756 1760 * @param USARTx: where x can be 1, 2, 3 or 4 to select the USART peripheral.
mbed_official 76:aeb1df146756 1761 * @note USART3 and USART4 are available only for STM32F072 devices.
mbed_official 76:aeb1df146756 1762 * @note USART2 is not available for STM32F031 devices.
mbed_official 76:aeb1df146756 1763 * @param USART_IT: specifies the USART interrupt sources to be enabled or disabled.
mbed_official 76:aeb1df146756 1764 * This parameter can be one of the following values:
mbed_official 76:aeb1df146756 1765 * @arg USART_IT_WU: Wake up interrupt, not available for STM32F030 devices.
mbed_official 76:aeb1df146756 1766 * @arg USART_IT_CM: Character match interrupt.
mbed_official 76:aeb1df146756 1767 * @arg USART_IT_EOB: End of block interrupt, not available for STM32F030 devices.
mbed_official 76:aeb1df146756 1768 * @arg USART_IT_RTO: Receive time out interrupt.
mbed_official 76:aeb1df146756 1769 * @arg USART_IT_CTS: CTS change interrupt.
mbed_official 76:aeb1df146756 1770 * @arg USART_IT_LBD: LIN Break detection interrupt, not available for STM32F030 devices.
mbed_official 76:aeb1df146756 1771 * @arg USART_IT_TXE: Tansmit Data Register empty interrupt.
mbed_official 76:aeb1df146756 1772 * @arg USART_IT_TC: Transmission complete interrupt.
mbed_official 76:aeb1df146756 1773 * @arg USART_IT_RXNE: Receive Data register not empty interrupt.
mbed_official 76:aeb1df146756 1774 * @arg USART_IT_IDLE: Idle line detection interrupt.
mbed_official 76:aeb1df146756 1775 * @arg USART_IT_PE: Parity Error interrupt.
mbed_official 76:aeb1df146756 1776 * @arg USART_IT_ERR: Error interrupt(Frame error, noise error, overrun error)
mbed_official 76:aeb1df146756 1777 * @param NewState: new state of the specified USARTx interrupts.
mbed_official 76:aeb1df146756 1778 * This parameter can be: ENABLE or DISABLE.
mbed_official 76:aeb1df146756 1779 * @retval None
mbed_official 76:aeb1df146756 1780 */
mbed_official 76:aeb1df146756 1781 void USART_ITConfig(USART_TypeDef* USARTx, uint32_t USART_IT, FunctionalState NewState)
mbed_official 76:aeb1df146756 1782 {
mbed_official 76:aeb1df146756 1783 uint32_t usartreg = 0, itpos = 0, itmask = 0;
mbed_official 76:aeb1df146756 1784 uint32_t usartxbase = 0;
mbed_official 76:aeb1df146756 1785 /* Check the parameters */
mbed_official 76:aeb1df146756 1786 assert_param(IS_USART_ALL_PERIPH(USARTx));
mbed_official 76:aeb1df146756 1787 assert_param(IS_USART_CONFIG_IT(USART_IT));
mbed_official 76:aeb1df146756 1788 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 76:aeb1df146756 1789
mbed_official 76:aeb1df146756 1790 usartxbase = (uint32_t)USARTx;
mbed_official 76:aeb1df146756 1791
mbed_official 76:aeb1df146756 1792 /* Get the USART register index */
mbed_official 76:aeb1df146756 1793 usartreg = (((uint16_t)USART_IT) >> 0x08);
mbed_official 76:aeb1df146756 1794
mbed_official 76:aeb1df146756 1795 /* Get the interrupt position */
mbed_official 76:aeb1df146756 1796 itpos = USART_IT & IT_MASK;
mbed_official 76:aeb1df146756 1797 itmask = (((uint32_t)0x01) << itpos);
mbed_official 76:aeb1df146756 1798
mbed_official 76:aeb1df146756 1799 if (usartreg == 0x02) /* The IT is in CR2 register */
mbed_official 76:aeb1df146756 1800 {
mbed_official 76:aeb1df146756 1801 usartxbase += 0x04;
mbed_official 76:aeb1df146756 1802 }
mbed_official 76:aeb1df146756 1803 else if (usartreg == 0x03) /* The IT is in CR3 register */
mbed_official 76:aeb1df146756 1804 {
mbed_official 76:aeb1df146756 1805 usartxbase += 0x08;
mbed_official 76:aeb1df146756 1806 }
mbed_official 76:aeb1df146756 1807 else /* The IT is in CR1 register */
mbed_official 76:aeb1df146756 1808 {
mbed_official 76:aeb1df146756 1809 }
mbed_official 76:aeb1df146756 1810 if (NewState != DISABLE)
mbed_official 76:aeb1df146756 1811 {
mbed_official 76:aeb1df146756 1812 *(__IO uint32_t*)usartxbase |= itmask;
mbed_official 76:aeb1df146756 1813 }
mbed_official 76:aeb1df146756 1814 else
mbed_official 76:aeb1df146756 1815 {
mbed_official 76:aeb1df146756 1816 *(__IO uint32_t*)usartxbase &= ~itmask;
mbed_official 76:aeb1df146756 1817 }
mbed_official 76:aeb1df146756 1818 }
mbed_official 76:aeb1df146756 1819
mbed_official 76:aeb1df146756 1820 /**
mbed_official 76:aeb1df146756 1821 * @brief Enables the specified USART's Request.
mbed_official 76:aeb1df146756 1822 * @param USARTx: where x can be 1, 2, 3 or 4 to select the USART peripheral.
mbed_official 76:aeb1df146756 1823 * @note USART3 and USART4 are available only for STM32F072 devices.
mbed_official 76:aeb1df146756 1824 * @note USART2 is not available for STM32F031 devices.
mbed_official 76:aeb1df146756 1825 * @param USART_Request: specifies the USART request.
mbed_official 76:aeb1df146756 1826 * This parameter can be any combination of the following values:
mbed_official 76:aeb1df146756 1827 * @arg USART_Request_TXFRQ: Transmit data flush ReQuest
mbed_official 76:aeb1df146756 1828 * @arg USART_Request_RXFRQ: Receive data flush ReQuest
mbed_official 76:aeb1df146756 1829 * @arg USART_Request_MMRQ: Mute Mode ReQuest
mbed_official 76:aeb1df146756 1830 * @arg USART_Request_SBKRQ: Send Break ReQuest
mbed_official 76:aeb1df146756 1831 * @arg USART_Request_ABRRQ: Auto Baud Rate ReQuest
mbed_official 76:aeb1df146756 1832 * @param NewState: new state of the DMA interface when reception error occurs.
mbed_official 76:aeb1df146756 1833 * This parameter can be: ENABLE or DISABLE.
mbed_official 76:aeb1df146756 1834 * @retval None
mbed_official 76:aeb1df146756 1835 */
mbed_official 76:aeb1df146756 1836 void USART_RequestCmd(USART_TypeDef* USARTx, uint32_t USART_Request, FunctionalState NewState)
mbed_official 76:aeb1df146756 1837 {
mbed_official 76:aeb1df146756 1838 /* Check the parameters */
mbed_official 76:aeb1df146756 1839 assert_param(IS_USART_ALL_PERIPH(USARTx));
mbed_official 76:aeb1df146756 1840 assert_param(IS_USART_REQUEST(USART_Request));
mbed_official 76:aeb1df146756 1841 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 76:aeb1df146756 1842
mbed_official 76:aeb1df146756 1843 if (NewState != DISABLE)
mbed_official 76:aeb1df146756 1844 {
mbed_official 76:aeb1df146756 1845 /* Enable the USART ReQuest by setting the dedicated request bit in the RQR
mbed_official 76:aeb1df146756 1846 register.*/
mbed_official 76:aeb1df146756 1847 USARTx->RQR |= USART_Request;
mbed_official 76:aeb1df146756 1848 }
mbed_official 76:aeb1df146756 1849 else
mbed_official 76:aeb1df146756 1850 {
mbed_official 76:aeb1df146756 1851 /* Disable the USART ReQuest by clearing the dedicated request bit in the RQR
mbed_official 76:aeb1df146756 1852 register.*/
mbed_official 76:aeb1df146756 1853 USARTx->RQR &= (uint32_t)~USART_Request;
mbed_official 76:aeb1df146756 1854 }
mbed_official 76:aeb1df146756 1855 }
mbed_official 76:aeb1df146756 1856
mbed_official 76:aeb1df146756 1857 /**
mbed_official 76:aeb1df146756 1858 * @brief Enables or disables the USART's Overrun detection.
mbed_official 76:aeb1df146756 1859 * @param USARTx: where x can be 1, 2, 3 or 4 to select the USART peripheral.
mbed_official 76:aeb1df146756 1860 * @note USART3 and USART4 are available only for STM32F072 devices.
mbed_official 76:aeb1df146756 1861 * @note USART2 is not available for STM32F031 devices.
mbed_official 76:aeb1df146756 1862 * @param USART_OVRDetection: specifies the OVR detection status in case of OVR error.
mbed_official 76:aeb1df146756 1863 * This parameter can be any combination of the following values:
mbed_official 76:aeb1df146756 1864 * @arg USART_OVRDetection_Enable: OVR error detection enabled when
mbed_official 76:aeb1df146756 1865 * the USART OVR error is asserted.
mbed_official 76:aeb1df146756 1866 * @arg USART_OVRDetection_Disable: OVR error detection disabled when
mbed_official 76:aeb1df146756 1867 * the USART OVR error is asserted.
mbed_official 76:aeb1df146756 1868 * @retval None
mbed_official 76:aeb1df146756 1869 */
mbed_official 76:aeb1df146756 1870 void USART_OverrunDetectionConfig(USART_TypeDef* USARTx, uint32_t USART_OVRDetection)
mbed_official 76:aeb1df146756 1871 {
mbed_official 76:aeb1df146756 1872 /* Check the parameters */
mbed_official 76:aeb1df146756 1873 assert_param(IS_USART_ALL_PERIPH(USARTx));
mbed_official 76:aeb1df146756 1874 assert_param(IS_USART_OVRDETECTION(USART_OVRDetection));
mbed_official 76:aeb1df146756 1875
mbed_official 76:aeb1df146756 1876 /* Clear the OVR detection bit */
mbed_official 76:aeb1df146756 1877 USARTx->CR3 &= (uint32_t)~((uint32_t)USART_CR3_OVRDIS);
mbed_official 76:aeb1df146756 1878 /* Set the new value for the OVR detection bit */
mbed_official 76:aeb1df146756 1879 USARTx->CR3 |= USART_OVRDetection;
mbed_official 76:aeb1df146756 1880 }
mbed_official 76:aeb1df146756 1881
mbed_official 76:aeb1df146756 1882 /**
mbed_official 76:aeb1df146756 1883 * @brief Checks whether the specified USART flag is set or not.
mbed_official 76:aeb1df146756 1884 * @param USARTx: where x can be 1, 2, 3 or 4 to select the USART peripheral.
mbed_official 76:aeb1df146756 1885 * @note USART3 and USART4 are available only for STM32F072 devices.
mbed_official 76:aeb1df146756 1886 * @note USART2 is not available for STM32F031 devices.
mbed_official 76:aeb1df146756 1887 * @param USART_FLAG: specifies the flag to check.
mbed_official 76:aeb1df146756 1888 * This parameter can be one of the following values:
mbed_official 76:aeb1df146756 1889 * @arg USART_FLAG_REACK: Receive Enable acknowledge flag.
mbed_official 76:aeb1df146756 1890 * @arg USART_FLAG_TEACK: Transmit Enable acknowledge flag.
mbed_official 76:aeb1df146756 1891 * @arg USART_FLAG_WU: Wake up flag, not available for STM32F030 devices.
mbed_official 76:aeb1df146756 1892 * @arg USART_FLAG_RWU: Receive Wake up flag, not available for STM32F030 devices.
mbed_official 76:aeb1df146756 1893 * @arg USART_FLAG_SBK: Send Break flag.
mbed_official 76:aeb1df146756 1894 * @arg USART_FLAG_CM: Character match flag.
mbed_official 76:aeb1df146756 1895 * @arg USART_FLAG_BUSY: Busy flag.
mbed_official 76:aeb1df146756 1896 * @arg USART_FLAG_ABRF: Auto baud rate flag.
mbed_official 76:aeb1df146756 1897 * @arg USART_FLAG_ABRE: Auto baud rate error flag.
mbed_official 76:aeb1df146756 1898 * @arg USART_FLAG_EOB: End of block flag, not available for STM32F030 devices.
mbed_official 76:aeb1df146756 1899 * @arg USART_FLAG_RTO: Receive time out flag.
mbed_official 76:aeb1df146756 1900 * @arg USART_FLAG_nCTSS: Inverted nCTS input bit status.
mbed_official 76:aeb1df146756 1901 * @arg USART_FLAG_CTS: CTS Change flag.
mbed_official 76:aeb1df146756 1902 * @arg USART_FLAG_LBD: LIN Break detection flag, not available for STM32F030 devices.
mbed_official 76:aeb1df146756 1903 * @arg USART_FLAG_TXE: Transmit data register empty flag.
mbed_official 76:aeb1df146756 1904 * @arg USART_FLAG_TC: Transmission Complete flag.
mbed_official 76:aeb1df146756 1905 * @arg USART_FLAG_RXNE: Receive data register not empty flag.
mbed_official 76:aeb1df146756 1906 * @arg USART_FLAG_IDLE: Idle Line detection flag.
mbed_official 76:aeb1df146756 1907 * @arg USART_FLAG_ORE: OverRun Error flag.
mbed_official 76:aeb1df146756 1908 * @arg USART_FLAG_NE: Noise Error flag.
mbed_official 76:aeb1df146756 1909 * @arg USART_FLAG_FE: Framing Error flag.
mbed_official 76:aeb1df146756 1910 * @arg USART_FLAG_PE: Parity Error flag.
mbed_official 76:aeb1df146756 1911 * @retval The new state of USART_FLAG (SET or RESET).
mbed_official 76:aeb1df146756 1912 */
mbed_official 76:aeb1df146756 1913 FlagStatus USART_GetFlagStatus(USART_TypeDef* USARTx, uint32_t USART_FLAG)
mbed_official 76:aeb1df146756 1914 {
mbed_official 76:aeb1df146756 1915 FlagStatus bitstatus = RESET;
mbed_official 76:aeb1df146756 1916 /* Check the parameters */
mbed_official 76:aeb1df146756 1917 assert_param(IS_USART_ALL_PERIPH(USARTx));
mbed_official 76:aeb1df146756 1918 assert_param(IS_USART_FLAG(USART_FLAG));
mbed_official 76:aeb1df146756 1919
mbed_official 76:aeb1df146756 1920 if ((USARTx->ISR & USART_FLAG) != (uint16_t)RESET)
mbed_official 76:aeb1df146756 1921 {
mbed_official 76:aeb1df146756 1922 bitstatus = SET;
mbed_official 76:aeb1df146756 1923 }
mbed_official 76:aeb1df146756 1924 else
mbed_official 76:aeb1df146756 1925 {
mbed_official 76:aeb1df146756 1926 bitstatus = RESET;
mbed_official 76:aeb1df146756 1927 }
mbed_official 76:aeb1df146756 1928 return bitstatus;
mbed_official 76:aeb1df146756 1929 }
mbed_official 76:aeb1df146756 1930
mbed_official 76:aeb1df146756 1931 /**
mbed_official 76:aeb1df146756 1932 * @brief Clears the USARTx's pending flags.
mbed_official 76:aeb1df146756 1933 * @param USARTx: where x can be 1, 2, 3 or 4 to select the USART peripheral.
mbed_official 76:aeb1df146756 1934 * @note USART3 and USART4 are available only for STM32F072 devices.
mbed_official 76:aeb1df146756 1935 * @note USART2 is not available for STM32F031 devices.
mbed_official 76:aeb1df146756 1936 * @param USART_FLAG: specifies the flag to clear.
mbed_official 76:aeb1df146756 1937 * This parameter can be any combination of the following values:
mbed_official 76:aeb1df146756 1938 * @arg USART_FLAG_WU: Wake up flag, not available for STM32F030 devices.
mbed_official 76:aeb1df146756 1939 * @arg USART_FLAG_CM: Character match flag.
mbed_official 76:aeb1df146756 1940 * @arg USART_FLAG_EOB: End of block flag, not available for STM32F030 devices.
mbed_official 76:aeb1df146756 1941 * @arg USART_FLAG_RTO: Receive time out flag.
mbed_official 76:aeb1df146756 1942 * @arg USART_FLAG_CTS: CTS Change flag.
mbed_official 76:aeb1df146756 1943 * @arg USART_FLAG_LBD: LIN Break detection flag, not available for STM32F030 devices.
mbed_official 76:aeb1df146756 1944 * @arg USART_FLAG_TC: Transmission Complete flag.
mbed_official 76:aeb1df146756 1945 * @arg USART_FLAG_IDLE: IDLE line detected flag.
mbed_official 76:aeb1df146756 1946 * @arg USART_FLAG_ORE: OverRun Error flag.
mbed_official 76:aeb1df146756 1947 * @arg USART_FLAG_NE: Noise Error flag.
mbed_official 76:aeb1df146756 1948 * @arg USART_FLAG_FE: Framing Error flag.
mbed_official 76:aeb1df146756 1949 * @arg USART_FLAG_PE: Parity Errorflag.
mbed_official 76:aeb1df146756 1950 *
mbed_official 76:aeb1df146756 1951 * @note RXNE pending bit is cleared by a read to the USART_RDR register
mbed_official 76:aeb1df146756 1952 * (USART_ReceiveData()) or by writing 1 to the RXFRQ in the register
mbed_official 76:aeb1df146756 1953 * USART_RQR (USART_RequestCmd()).
mbed_official 76:aeb1df146756 1954 * @note TC flag can be also cleared by software sequence: a read operation
mbed_official 76:aeb1df146756 1955 * to USART_SR register (USART_GetFlagStatus()) followed by a write
mbed_official 76:aeb1df146756 1956 * operation to USART_TDR register (USART_SendData()).
mbed_official 76:aeb1df146756 1957 * @note TXE flag is cleared by a write to the USART_TDR register (USART_SendData())
mbed_official 76:aeb1df146756 1958 * or by writing 1 to the TXFRQ in the register USART_RQR (USART_RequestCmd()).
mbed_official 76:aeb1df146756 1959 * @note SBKF flag is cleared by 1 to the SBKRQ in the register USART_RQR
mbed_official 76:aeb1df146756 1960 * (USART_RequestCmd()).
mbed_official 76:aeb1df146756 1961 * @retval None
mbed_official 76:aeb1df146756 1962 */
mbed_official 76:aeb1df146756 1963 void USART_ClearFlag(USART_TypeDef* USARTx, uint32_t USART_FLAG)
mbed_official 76:aeb1df146756 1964 {
mbed_official 76:aeb1df146756 1965 /* Check the parameters */
mbed_official 76:aeb1df146756 1966 assert_param(IS_USART_ALL_PERIPH(USARTx));
mbed_official 76:aeb1df146756 1967 assert_param(IS_USART_CLEAR_FLAG(USART_FLAG));
mbed_official 76:aeb1df146756 1968
mbed_official 76:aeb1df146756 1969 USARTx->ICR = USART_FLAG;
mbed_official 76:aeb1df146756 1970 }
mbed_official 76:aeb1df146756 1971
mbed_official 76:aeb1df146756 1972 /**
mbed_official 76:aeb1df146756 1973 * @brief Checks whether the specified USART interrupt has occurred or not.
mbed_official 76:aeb1df146756 1974 * @param USARTx: where x can be 1, 2, 3 or 4 to select the USART peripheral.
mbed_official 76:aeb1df146756 1975 * @note USART3 and USART4 are available only for STM32F072 devices.
mbed_official 76:aeb1df146756 1976 * @note USART2 is not available for STM32F031 devices.
mbed_official 76:aeb1df146756 1977 * @param USART_IT: specifies the USART interrupt source to check.
mbed_official 76:aeb1df146756 1978 * This parameter can be one of the following values:
mbed_official 76:aeb1df146756 1979 * @arg USART_IT_WU: Wake up interrupt, not available for STM32F030 devices.
mbed_official 76:aeb1df146756 1980 * @arg USART_IT_CM: Character match interrupt.
mbed_official 76:aeb1df146756 1981 * @arg USART_IT_EOB: End of block interrupt, not available for STM32F030 devices.
mbed_official 76:aeb1df146756 1982 * @arg USART_IT_RTO: Receive time out interrupt.
mbed_official 76:aeb1df146756 1983 * @arg USART_IT_CTS: CTS change interrupt.
mbed_official 76:aeb1df146756 1984 * @arg USART_IT_LBD: LIN Break detection interrupt, not available for STM32F030 devices.
mbed_official 76:aeb1df146756 1985 * @arg USART_IT_TXE: Tansmit Data Register empty interrupt.
mbed_official 76:aeb1df146756 1986 * @arg USART_IT_TC: Transmission complete interrupt.
mbed_official 76:aeb1df146756 1987 * @arg USART_IT_RXNE: Receive Data register not empty interrupt.
mbed_official 76:aeb1df146756 1988 * @arg USART_IT_IDLE: Idle line detection interrupt.
mbed_official 76:aeb1df146756 1989 * @arg USART_IT_ORE: OverRun Error interrupt.
mbed_official 76:aeb1df146756 1990 * @arg USART_IT_NE: Noise Error interrupt.
mbed_official 76:aeb1df146756 1991 * @arg USART_IT_FE: Framing Error interrupt.
mbed_official 76:aeb1df146756 1992 * @arg USART_IT_PE: Parity Error interrupt.
mbed_official 76:aeb1df146756 1993 * @retval The new state of USART_IT (SET or RESET).
mbed_official 76:aeb1df146756 1994 */
mbed_official 76:aeb1df146756 1995 ITStatus USART_GetITStatus(USART_TypeDef* USARTx, uint32_t USART_IT)
mbed_official 76:aeb1df146756 1996 {
mbed_official 76:aeb1df146756 1997 uint32_t bitpos = 0, itmask = 0, usartreg = 0;
mbed_official 76:aeb1df146756 1998 ITStatus bitstatus = RESET;
mbed_official 76:aeb1df146756 1999 /* Check the parameters */
mbed_official 76:aeb1df146756 2000 assert_param(IS_USART_ALL_PERIPH(USARTx));
mbed_official 76:aeb1df146756 2001 assert_param(IS_USART_GET_IT(USART_IT));
mbed_official 76:aeb1df146756 2002
mbed_official 76:aeb1df146756 2003 /* Get the USART register index */
mbed_official 76:aeb1df146756 2004 usartreg = (((uint16_t)USART_IT) >> 0x08);
mbed_official 76:aeb1df146756 2005 /* Get the interrupt position */
mbed_official 76:aeb1df146756 2006 itmask = USART_IT & IT_MASK;
mbed_official 76:aeb1df146756 2007 itmask = (uint32_t)0x01 << itmask;
mbed_official 76:aeb1df146756 2008
mbed_official 76:aeb1df146756 2009 if (usartreg == 0x01) /* The IT is in CR1 register */
mbed_official 76:aeb1df146756 2010 {
mbed_official 76:aeb1df146756 2011 itmask &= USARTx->CR1;
mbed_official 76:aeb1df146756 2012 }
mbed_official 76:aeb1df146756 2013 else if (usartreg == 0x02) /* The IT is in CR2 register */
mbed_official 76:aeb1df146756 2014 {
mbed_official 76:aeb1df146756 2015 itmask &= USARTx->CR2;
mbed_official 76:aeb1df146756 2016 }
mbed_official 76:aeb1df146756 2017 else /* The IT is in CR3 register */
mbed_official 76:aeb1df146756 2018 {
mbed_official 76:aeb1df146756 2019 itmask &= USARTx->CR3;
mbed_official 76:aeb1df146756 2020 }
mbed_official 76:aeb1df146756 2021
mbed_official 76:aeb1df146756 2022 bitpos = USART_IT >> 0x10;
mbed_official 76:aeb1df146756 2023 bitpos = (uint32_t)0x01 << bitpos;
mbed_official 76:aeb1df146756 2024 bitpos &= USARTx->ISR;
mbed_official 76:aeb1df146756 2025 if ((itmask != (uint16_t)RESET)&&(bitpos != (uint16_t)RESET))
mbed_official 76:aeb1df146756 2026 {
mbed_official 76:aeb1df146756 2027 bitstatus = SET;
mbed_official 76:aeb1df146756 2028 }
mbed_official 76:aeb1df146756 2029 else
mbed_official 76:aeb1df146756 2030 {
mbed_official 76:aeb1df146756 2031 bitstatus = RESET;
mbed_official 76:aeb1df146756 2032 }
mbed_official 76:aeb1df146756 2033
mbed_official 76:aeb1df146756 2034 return bitstatus;
mbed_official 76:aeb1df146756 2035 }
mbed_official 76:aeb1df146756 2036
mbed_official 76:aeb1df146756 2037 /**
mbed_official 76:aeb1df146756 2038 * @brief Clears the USARTx's interrupt pending bits.
mbed_official 76:aeb1df146756 2039 * @param USARTx: where x can be 1, 2, 3 or 4 to select the USART peripheral.
mbed_official 76:aeb1df146756 2040 * @note USART3 and USART4 are available only for STM32F072 devices.
mbed_official 76:aeb1df146756 2041 * @note USART2 is not available for STM32F031 devices.
mbed_official 76:aeb1df146756 2042 * @param USART_IT: specifies the interrupt pending bit to clear.
mbed_official 76:aeb1df146756 2043 * This parameter can be one of the following values:
mbed_official 76:aeb1df146756 2044 * @arg USART_IT_WU: Wake up interrupt, not available for STM32F030 devices.
mbed_official 76:aeb1df146756 2045 * @arg USART_IT_CM: Character match interrupt.
mbed_official 76:aeb1df146756 2046 * @arg USART_IT_EOB: End of block interrupt, not available for STM32F030 devices.
mbed_official 76:aeb1df146756 2047 * @arg USART_IT_RTO: Receive time out interrupt.
mbed_official 76:aeb1df146756 2048 * @arg USART_IT_CTS: CTS change interrupt.
mbed_official 76:aeb1df146756 2049 * @arg USART_IT_LBD: LIN Break detection interrupt, not available for STM32F030 devices.
mbed_official 76:aeb1df146756 2050 * @arg USART_IT_TC: Transmission complete interrupt.
mbed_official 76:aeb1df146756 2051 * @arg USART_IT_IDLE: IDLE line detected interrupt.
mbed_official 76:aeb1df146756 2052 * @arg USART_IT_ORE: OverRun Error interrupt.
mbed_official 76:aeb1df146756 2053 * @arg USART_IT_NE: Noise Error interrupt.
mbed_official 76:aeb1df146756 2054 * @arg USART_IT_FE: Framing Error interrupt.
mbed_official 76:aeb1df146756 2055 * @arg USART_IT_PE: Parity Error interrupt.
mbed_official 76:aeb1df146756 2056 *
mbed_official 76:aeb1df146756 2057 * @note RXNE pending bit is cleared by a read to the USART_RDR register
mbed_official 76:aeb1df146756 2058 * (USART_ReceiveData()) or by writing 1 to the RXFRQ in the register
mbed_official 76:aeb1df146756 2059 * USART_RQR (USART_RequestCmd()).
mbed_official 76:aeb1df146756 2060 * @note TC pending bit can be also cleared by software sequence: a read
mbed_official 76:aeb1df146756 2061 * operation to USART_SR register (USART_GetITStatus()) followed by
mbed_official 76:aeb1df146756 2062 * a write operation to USART_TDR register (USART_SendData()).
mbed_official 76:aeb1df146756 2063 * @note TXE pending bit is cleared by a write to the USART_TDR register
mbed_official 76:aeb1df146756 2064 * (USART_SendData()) or by writing 1 to the TXFRQ in the register
mbed_official 76:aeb1df146756 2065 * USART_RQR (USART_RequestCmd()).
mbed_official 76:aeb1df146756 2066 * @retval None
mbed_official 76:aeb1df146756 2067 */
mbed_official 76:aeb1df146756 2068 void USART_ClearITPendingBit(USART_TypeDef* USARTx, uint32_t USART_IT)
mbed_official 76:aeb1df146756 2069 {
mbed_official 76:aeb1df146756 2070 uint32_t bitpos = 0, itmask = 0;
mbed_official 76:aeb1df146756 2071 /* Check the parameters */
mbed_official 76:aeb1df146756 2072 assert_param(IS_USART_ALL_PERIPH(USARTx));
mbed_official 76:aeb1df146756 2073 assert_param(IS_USART_CLEAR_IT(USART_IT));
mbed_official 76:aeb1df146756 2074
mbed_official 76:aeb1df146756 2075 bitpos = USART_IT >> 0x10;
mbed_official 76:aeb1df146756 2076 itmask = ((uint32_t)0x01 << (uint32_t)bitpos);
mbed_official 76:aeb1df146756 2077 USARTx->ICR = (uint32_t)itmask;
mbed_official 76:aeb1df146756 2078 }
mbed_official 76:aeb1df146756 2079
mbed_official 76:aeb1df146756 2080 /**
mbed_official 76:aeb1df146756 2081 * @}
mbed_official 76:aeb1df146756 2082 */
mbed_official 76:aeb1df146756 2083
mbed_official 76:aeb1df146756 2084 /**
mbed_official 76:aeb1df146756 2085 * @}
mbed_official 76:aeb1df146756 2086 */
mbed_official 76:aeb1df146756 2087
mbed_official 76:aeb1df146756 2088 /**
mbed_official 76:aeb1df146756 2089 * @}
mbed_official 76:aeb1df146756 2090 */
mbed_official 76:aeb1df146756 2091
mbed_official 76:aeb1df146756 2092 /**
mbed_official 76:aeb1df146756 2093 * @}
mbed_official 76:aeb1df146756 2094 */
mbed_official 76:aeb1df146756 2095
mbed_official 76:aeb1df146756 2096 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/