mbed library with additional peripherals for ST F401 board

Fork of mbed-src by mbed official

This mbed LIB has additional peripherals for ST F401 board

  • UART2 : PA_3 rx, PA_2 tx
  • UART3 : PC_7 rx, PC_6 tx
  • I2C2 : PB_3 SDA, PB_10 SCL
  • I2C3 : PB_4 SDA, PA_8 SCL
Committer:
mbed_official
Date:
Mon Jan 27 14:30:07 2014 +0000
Revision:
76:aeb1df146756
Child:
80:66393a7b209d
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 stm32l1xx_usart.c
mbed_official 76:aeb1df146756 4 * @author MCD Application Team
mbed_official 76:aeb1df146756 5 * @version V1.2.0
mbed_official 76:aeb1df146756 6 * @date 22-February-2013
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 * + Data transfers
mbed_official 76:aeb1df146756 12 * + Multi-Processor Communication
mbed_official 76:aeb1df146756 13 * + LIN mode
mbed_official 76:aeb1df146756 14 * + Half-duplex mode
mbed_official 76:aeb1df146756 15 * + Smartcard mode
mbed_official 76:aeb1df146756 16 * + IrDA mode
mbed_official 76:aeb1df146756 17 * + DMA transfers management
mbed_official 76:aeb1df146756 18 * + Interrupts and flags management
mbed_official 76:aeb1df146756 19 *
mbed_official 76:aeb1df146756 20 * @verbatim
mbed_official 76:aeb1df146756 21 ===============================================================================
mbed_official 76:aeb1df146756 22 ##### How to use this driver #####
mbed_official 76:aeb1df146756 23 ===============================================================================
mbed_official 76:aeb1df146756 24 [..]
mbed_official 76:aeb1df146756 25 (#) Enable peripheral clock using
mbed_official 76:aeb1df146756 26 RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE) function for
mbed_official 76:aeb1df146756 27 USART1 or using RCC_APB1PeriphClockCmd(RCC_APB1Periph_USARTx, ENABLE)
mbed_official 76:aeb1df146756 28 function for USART2 and USART3.
mbed_official 76:aeb1df146756 29 (#) According to the USART mode, enable the GPIO clocks using
mbed_official 76:aeb1df146756 30 RCC_AHBPeriphClockCmd() function. (The I/O can be TX, RX, CTS,
mbed_official 76:aeb1df146756 31 or and SCLK).
mbed_official 76:aeb1df146756 32 (#) Peripheral's alternate function:
mbed_official 76:aeb1df146756 33 (++) Connect the pin to the desired peripherals' Alternate
mbed_official 76:aeb1df146756 34 Function (AF) using GPIO_PinAFConfig() function.
mbed_official 76:aeb1df146756 35 (++) Configure the desired pin in alternate function by:
mbed_official 76:aeb1df146756 36 GPIO_InitStruct->GPIO_Mode = GPIO_Mode_AF.
mbed_official 76:aeb1df146756 37 (++) Select the type, pull-up/pull-down and output speed via
mbed_official 76:aeb1df146756 38 GPIO_PuPd, GPIO_OType and GPIO_Speed members.
mbed_official 76:aeb1df146756 39 (++) Call GPIO_Init() function.
mbed_official 76:aeb1df146756 40 (#) Program the Baud Rate, Word Length , Stop Bit, Parity, Hardware
mbed_official 76:aeb1df146756 41 flow control and Mode(Receiver/Transmitter) using the SPI_Init()
mbed_official 76:aeb1df146756 42 function.
mbed_official 76:aeb1df146756 43 (#) For synchronous mode, enable the clock and program the polarity,
mbed_official 76:aeb1df146756 44 phase and last bit using the USART_ClockInit() function.
mbed_official 76:aeb1df146756 45 (#) Enable the NVIC and the corresponding interrupt using the function
mbed_official 76:aeb1df146756 46 USART_ITConfig() if you need to use interrupt mode.
mbed_official 76:aeb1df146756 47 (#) When using the DMA mode.
mbed_official 76:aeb1df146756 48 (++) Configure the DMA using DMA_Init() function.
mbed_official 76:aeb1df146756 49 (++) Active the needed channel Request using USART_DMACmd() function.
mbed_official 76:aeb1df146756 50 (#) Enable the USART using the USART_Cmd() function.
mbed_official 76:aeb1df146756 51 (#) Enable the DMA using the DMA_Cmd() function, when using DMA mode.
mbed_official 76:aeb1df146756 52 [..]
mbed_official 76:aeb1df146756 53 Refer to Multi-Processor, LIN, half-duplex, Smartcard, IrDA sub-sections
mbed_official 76:aeb1df146756 54 for more details.
mbed_official 76:aeb1df146756 55
mbed_official 76:aeb1df146756 56 @endverbatim
mbed_official 76:aeb1df146756 57
mbed_official 76:aeb1df146756 58 ******************************************************************************
mbed_official 76:aeb1df146756 59 * @attention
mbed_official 76:aeb1df146756 60 *
mbed_official 76:aeb1df146756 61 * <h2><center>&copy; COPYRIGHT 2013 STMicroelectronics</center></h2>
mbed_official 76:aeb1df146756 62 *
mbed_official 76:aeb1df146756 63 * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
mbed_official 76:aeb1df146756 64 * You may not use this file except in compliance with the License.
mbed_official 76:aeb1df146756 65 * You may obtain a copy of the License at:
mbed_official 76:aeb1df146756 66 *
mbed_official 76:aeb1df146756 67 * http://www.st.com/software_license_agreement_liberty_v2
mbed_official 76:aeb1df146756 68 *
mbed_official 76:aeb1df146756 69 * Unless required by applicable law or agreed to in writing, software
mbed_official 76:aeb1df146756 70 * distributed under the License is distributed on an "AS IS" BASIS,
mbed_official 76:aeb1df146756 71 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
mbed_official 76:aeb1df146756 72 * See the License for the specific language governing permissions and
mbed_official 76:aeb1df146756 73 * limitations under the License.
mbed_official 76:aeb1df146756 74 *
mbed_official 76:aeb1df146756 75 ******************************************************************************
mbed_official 76:aeb1df146756 76 */
mbed_official 76:aeb1df146756 77
mbed_official 76:aeb1df146756 78 /* Includes ------------------------------------------------------------------*/
mbed_official 76:aeb1df146756 79 #include "stm32l1xx_usart.h"
mbed_official 76:aeb1df146756 80 #include "stm32l1xx_rcc.h"
mbed_official 76:aeb1df146756 81
mbed_official 76:aeb1df146756 82 /** @addtogroup STM32L1xx_StdPeriph_Driver
mbed_official 76:aeb1df146756 83 * @{
mbed_official 76:aeb1df146756 84 */
mbed_official 76:aeb1df146756 85
mbed_official 76:aeb1df146756 86 /** @defgroup USART
mbed_official 76:aeb1df146756 87 * @brief USART driver modules
mbed_official 76:aeb1df146756 88 * @{
mbed_official 76:aeb1df146756 89 */
mbed_official 76:aeb1df146756 90
mbed_official 76:aeb1df146756 91 /* Private typedef -----------------------------------------------------------*/
mbed_official 76:aeb1df146756 92 /* Private define ------------------------------------------------------------*/
mbed_official 76:aeb1df146756 93
mbed_official 76:aeb1df146756 94 /*!< USART CR1 register clear Mask ((~(uint16_t)0xE9F3)) */
mbed_official 76:aeb1df146756 95 #define CR1_CLEAR_MASK ((uint16_t)(USART_CR1_M | USART_CR1_PCE | \
mbed_official 76:aeb1df146756 96 USART_CR1_PS | USART_CR1_TE | \
mbed_official 76:aeb1df146756 97 USART_CR1_RE))
mbed_official 76:aeb1df146756 98
mbed_official 76:aeb1df146756 99 /*!< USART CR2 register clock bits clear Mask ((~(uint16_t)0xF0FF)) */
mbed_official 76:aeb1df146756 100 #define CR2_CLOCK_CLEAR_MASK ((uint16_t)(USART_CR2_CLKEN | USART_CR2_CPOL | \
mbed_official 76:aeb1df146756 101 USART_CR2_CPHA | USART_CR2_LBCL))
mbed_official 76:aeb1df146756 102
mbed_official 76:aeb1df146756 103 /*!< USART CR3 register clear Mask ((~(uint16_t)0xFCFF)) */
mbed_official 76:aeb1df146756 104 #define CR3_CLEAR_MASK ((uint16_t)(USART_CR3_RTSE | USART_CR3_CTSE))
mbed_official 76:aeb1df146756 105
mbed_official 76:aeb1df146756 106 /*!< USART Interrupts mask */
mbed_official 76:aeb1df146756 107 #define IT_MASK ((uint16_t)0x001F)
mbed_official 76:aeb1df146756 108
mbed_official 76:aeb1df146756 109 /* Private macro -------------------------------------------------------------*/
mbed_official 76:aeb1df146756 110 /* Private variables ---------------------------------------------------------*/
mbed_official 76:aeb1df146756 111 /* Private function prototypes -----------------------------------------------*/
mbed_official 76:aeb1df146756 112 /* Private functions ---------------------------------------------------------*/
mbed_official 76:aeb1df146756 113
mbed_official 76:aeb1df146756 114 /** @defgroup USART_Private_Functions
mbed_official 76:aeb1df146756 115 * @{
mbed_official 76:aeb1df146756 116 */
mbed_official 76:aeb1df146756 117
mbed_official 76:aeb1df146756 118 /** @defgroup USART_Group1 Initialization and Configuration functions
mbed_official 76:aeb1df146756 119 * @brief Initialization and Configuration functions
mbed_official 76:aeb1df146756 120 *
mbed_official 76:aeb1df146756 121 @verbatim
mbed_official 76:aeb1df146756 122 ===============================================================================
mbed_official 76:aeb1df146756 123 ##### Initialization and Configuration functions #####
mbed_official 76:aeb1df146756 124 ===============================================================================
mbed_official 76:aeb1df146756 125 [..]
mbed_official 76:aeb1df146756 126 This subsection provides a set of functions allowing to initialize the USART
mbed_official 76:aeb1df146756 127 in asynchronous and in synchronous modes.
mbed_official 76:aeb1df146756 128 (+) For the asynchronous mode only these parameters can be configured:
mbed_official 76:aeb1df146756 129 (+) Baud Rate.
mbed_official 76:aeb1df146756 130 (+) Word Length.
mbed_official 76:aeb1df146756 131 (+) Stop Bit.
mbed_official 76:aeb1df146756 132 (+) Parity: If the parity is enabled, then the MSB bit of the data written
mbed_official 76:aeb1df146756 133 in the data register is transmitted but is changed by the parity bit.
mbed_official 76:aeb1df146756 134 Depending on the frame length defined by the M bit (8-bits or 9-bits),
mbed_official 76:aeb1df146756 135 the possible USART frame formats are as listed in the following table:
mbed_official 76:aeb1df146756 136 [..]
mbed_official 76:aeb1df146756 137 +-------------------------------------------------------------+
mbed_official 76:aeb1df146756 138 | M bit | PCE bit | USART frame |
mbed_official 76:aeb1df146756 139 |---------------------|---------------------------------------|
mbed_official 76:aeb1df146756 140 | 0 | 0 | | SB | 8 bit data | STB | |
mbed_official 76:aeb1df146756 141 |---------|-----------|---------------------------------------|
mbed_official 76:aeb1df146756 142 | 0 | 1 | | SB | 7 bit data | PB | STB | |
mbed_official 76:aeb1df146756 143 |---------|-----------|---------------------------------------|
mbed_official 76:aeb1df146756 144 | 1 | 0 | | SB | 9 bit data | STB | |
mbed_official 76:aeb1df146756 145 |---------|-----------|---------------------------------------|
mbed_official 76:aeb1df146756 146 | 1 | 1 | | SB | 8 bit data | PB | STB | |
mbed_official 76:aeb1df146756 147 +-------------------------------------------------------------+
mbed_official 76:aeb1df146756 148 [..]
mbed_official 76:aeb1df146756 149 (+) Hardware flow control.
mbed_official 76:aeb1df146756 150 (+) Receiver/transmitter modes.
mbed_official 76:aeb1df146756 151 [..] The USART_Init() function follows the USART asynchronous configuration
mbed_official 76:aeb1df146756 152 procedure(details for the procedure are available in reference manual
mbed_official 76:aeb1df146756 153 (RM0038)).
mbed_official 76:aeb1df146756 154 (+) For the synchronous mode in addition to the asynchronous mode parameters
mbed_official 76:aeb1df146756 155 these parameters should be also configured:
mbed_official 76:aeb1df146756 156 (++) USART Clock Enabled.
mbed_official 76:aeb1df146756 157 (++) USART polarity.
mbed_official 76:aeb1df146756 158 (++) USART phase.
mbed_official 76:aeb1df146756 159 (++) USART LastBit.
mbed_official 76:aeb1df146756 160 [..] These parameters can be configured using the USART_ClockInit() function.
mbed_official 76:aeb1df146756 161
mbed_official 76:aeb1df146756 162 @endverbatim
mbed_official 76:aeb1df146756 163 * @{
mbed_official 76:aeb1df146756 164 */
mbed_official 76:aeb1df146756 165
mbed_official 76:aeb1df146756 166 /**
mbed_official 76:aeb1df146756 167 * @brief Deinitializes the USARTx peripheral registers to their default reset values.
mbed_official 76:aeb1df146756 168 * @param USARTx: Select the USART peripheral.
mbed_official 76:aeb1df146756 169 * This parameter can be one of the following values: USART1, USART2, USART3,
mbed_official 76:aeb1df146756 170 * UART4 or UART5.
mbed_official 76:aeb1df146756 171 * @retval None.
mbed_official 76:aeb1df146756 172 */
mbed_official 76:aeb1df146756 173 void USART_DeInit(USART_TypeDef* USARTx)
mbed_official 76:aeb1df146756 174 {
mbed_official 76:aeb1df146756 175 /* Check the parameters */
mbed_official 76:aeb1df146756 176 assert_param(IS_USART_ALL_PERIPH(USARTx));
mbed_official 76:aeb1df146756 177
mbed_official 76:aeb1df146756 178 if (USARTx == USART1)
mbed_official 76:aeb1df146756 179 {
mbed_official 76:aeb1df146756 180 RCC_APB2PeriphResetCmd(RCC_APB2Periph_USART1, ENABLE);
mbed_official 76:aeb1df146756 181 RCC_APB2PeriphResetCmd(RCC_APB2Periph_USART1, DISABLE);
mbed_official 76:aeb1df146756 182 }
mbed_official 76:aeb1df146756 183 else if (USARTx == USART2)
mbed_official 76:aeb1df146756 184 {
mbed_official 76:aeb1df146756 185 RCC_APB1PeriphResetCmd(RCC_APB1Periph_USART2, ENABLE);
mbed_official 76:aeb1df146756 186 RCC_APB1PeriphResetCmd(RCC_APB1Periph_USART2, DISABLE);
mbed_official 76:aeb1df146756 187 }
mbed_official 76:aeb1df146756 188 else if (USARTx == USART3)
mbed_official 76:aeb1df146756 189 {
mbed_official 76:aeb1df146756 190 RCC_APB1PeriphResetCmd(RCC_APB1Periph_USART3, ENABLE);
mbed_official 76:aeb1df146756 191 RCC_APB1PeriphResetCmd(RCC_APB1Periph_USART3, DISABLE);
mbed_official 76:aeb1df146756 192 }
mbed_official 76:aeb1df146756 193 else if (USARTx == UART4)
mbed_official 76:aeb1df146756 194 {
mbed_official 76:aeb1df146756 195 RCC_APB1PeriphResetCmd(RCC_APB1Periph_UART4, ENABLE);
mbed_official 76:aeb1df146756 196 RCC_APB1PeriphResetCmd(RCC_APB1Periph_UART4, DISABLE);
mbed_official 76:aeb1df146756 197 }
mbed_official 76:aeb1df146756 198 else
mbed_official 76:aeb1df146756 199 {
mbed_official 76:aeb1df146756 200 if (USARTx == UART5)
mbed_official 76:aeb1df146756 201 {
mbed_official 76:aeb1df146756 202 RCC_APB1PeriphResetCmd(RCC_APB1Periph_UART5, ENABLE);
mbed_official 76:aeb1df146756 203 RCC_APB1PeriphResetCmd(RCC_APB1Periph_UART5, DISABLE);
mbed_official 76:aeb1df146756 204 }
mbed_official 76:aeb1df146756 205 }
mbed_official 76:aeb1df146756 206 }
mbed_official 76:aeb1df146756 207
mbed_official 76:aeb1df146756 208 /**
mbed_official 76:aeb1df146756 209 * @brief Initializes the USARTx peripheral according to the specified
mbed_official 76:aeb1df146756 210 * parameters in the USART_InitStruct.
mbed_official 76:aeb1df146756 211 * @param USARTx: Select the USART peripheral.
mbed_official 76:aeb1df146756 212 * This parameter can be one of the following values: USART1, USART2, USART3,
mbed_official 76:aeb1df146756 213 * UART4 or UART5.
mbed_official 76:aeb1df146756 214 * @param USART_InitStruct: pointer to a USART_InitTypeDef structure that
mbed_official 76:aeb1df146756 215 * contains the configuration information for the specified USART peripheral.
mbed_official 76:aeb1df146756 216 * @retval None.
mbed_official 76:aeb1df146756 217 */
mbed_official 76:aeb1df146756 218 void USART_Init(USART_TypeDef* USARTx, USART_InitTypeDef* USART_InitStruct)
mbed_official 76:aeb1df146756 219 {
mbed_official 76:aeb1df146756 220 uint32_t tmpreg = 0x00, apbclock = 0x00;
mbed_official 76:aeb1df146756 221 uint32_t integerdivider = 0x00;
mbed_official 76:aeb1df146756 222 uint32_t fractionaldivider = 0x00;
mbed_official 76:aeb1df146756 223 RCC_ClocksTypeDef RCC_ClocksStatus;
mbed_official 76:aeb1df146756 224
mbed_official 76:aeb1df146756 225 /* Check the parameters */
mbed_official 76:aeb1df146756 226 assert_param(IS_USART_ALL_PERIPH(USARTx));
mbed_official 76:aeb1df146756 227 assert_param(IS_USART_BAUDRATE(USART_InitStruct->USART_BaudRate));
mbed_official 76:aeb1df146756 228 assert_param(IS_USART_WORD_LENGTH(USART_InitStruct->USART_WordLength));
mbed_official 76:aeb1df146756 229 assert_param(IS_USART_STOPBITS(USART_InitStruct->USART_StopBits));
mbed_official 76:aeb1df146756 230 assert_param(IS_USART_PARITY(USART_InitStruct->USART_Parity));
mbed_official 76:aeb1df146756 231 assert_param(IS_USART_MODE(USART_InitStruct->USART_Mode));
mbed_official 76:aeb1df146756 232 assert_param(IS_USART_HARDWARE_FLOW_CONTROL(USART_InitStruct->USART_HardwareFlowControl));
mbed_official 76:aeb1df146756 233
mbed_official 76:aeb1df146756 234 /* The hardware flow control is available only for USART1, USART2 and USART3 */
mbed_official 76:aeb1df146756 235 if (USART_InitStruct->USART_HardwareFlowControl != USART_HardwareFlowControl_None)
mbed_official 76:aeb1df146756 236 {
mbed_official 76:aeb1df146756 237 assert_param(IS_USART_123_PERIPH(USARTx));
mbed_official 76:aeb1df146756 238 }
mbed_official 76:aeb1df146756 239
mbed_official 76:aeb1df146756 240 /*---------------------------- USART CR2 Configuration -----------------------*/
mbed_official 76:aeb1df146756 241 tmpreg = USARTx->CR2;
mbed_official 76:aeb1df146756 242 /* Clear STOP[13:12] bits */
mbed_official 76:aeb1df146756 243 tmpreg &= (uint32_t)~((uint32_t)USART_CR2_STOP);
mbed_official 76:aeb1df146756 244
mbed_official 76:aeb1df146756 245 /* Configure the USART Stop Bits, Clock, CPOL, CPHA and LastBit ------------*/
mbed_official 76:aeb1df146756 246 /* Set STOP[13:12] bits according to USART_StopBits value */
mbed_official 76:aeb1df146756 247 tmpreg |= (uint32_t)USART_InitStruct->USART_StopBits;
mbed_official 76:aeb1df146756 248
mbed_official 76:aeb1df146756 249 /* Write to USART CR2 */
mbed_official 76:aeb1df146756 250 USARTx->CR2 = (uint16_t)tmpreg;
mbed_official 76:aeb1df146756 251
mbed_official 76:aeb1df146756 252 /*---------------------------- USART CR1 Configuration -----------------------*/
mbed_official 76:aeb1df146756 253 tmpreg = USARTx->CR1;
mbed_official 76:aeb1df146756 254 /* Clear M, PCE, PS, TE and RE bits */
mbed_official 76:aeb1df146756 255 tmpreg &= (uint32_t)~((uint32_t)CR1_CLEAR_MASK);
mbed_official 76:aeb1df146756 256
mbed_official 76:aeb1df146756 257 /* Configure the USART Word Length, Parity and mode ----------------------- */
mbed_official 76:aeb1df146756 258 /* Set the M bits according to USART_WordLength value */
mbed_official 76:aeb1df146756 259 /* Set PCE and PS bits according to USART_Parity value */
mbed_official 76:aeb1df146756 260 /* Set TE and RE bits according to USART_Mode value */
mbed_official 76:aeb1df146756 261 tmpreg |= (uint32_t)USART_InitStruct->USART_WordLength | USART_InitStruct->USART_Parity |
mbed_official 76:aeb1df146756 262 USART_InitStruct->USART_Mode;
mbed_official 76:aeb1df146756 263
mbed_official 76:aeb1df146756 264 /* Write to USART CR1 */
mbed_official 76:aeb1df146756 265 USARTx->CR1 = (uint16_t)tmpreg;
mbed_official 76:aeb1df146756 266
mbed_official 76:aeb1df146756 267 /*---------------------------- USART CR3 Configuration -----------------------*/
mbed_official 76:aeb1df146756 268 tmpreg = USARTx->CR3;
mbed_official 76:aeb1df146756 269 /* Clear CTSE and RTSE bits */
mbed_official 76:aeb1df146756 270 tmpreg &= (uint32_t)~((uint32_t)CR3_CLEAR_MASK);
mbed_official 76:aeb1df146756 271
mbed_official 76:aeb1df146756 272 /* Configure the USART HFC -------------------------------------------------*/
mbed_official 76:aeb1df146756 273 /* Set CTSE and RTSE bits according to USART_HardwareFlowControl value */
mbed_official 76:aeb1df146756 274 tmpreg |= USART_InitStruct->USART_HardwareFlowControl;
mbed_official 76:aeb1df146756 275
mbed_official 76:aeb1df146756 276 /* Write to USART CR3 */
mbed_official 76:aeb1df146756 277 USARTx->CR3 = (uint16_t)tmpreg;
mbed_official 76:aeb1df146756 278
mbed_official 76:aeb1df146756 279 /*---------------------------- USART BRR Configuration -----------------------*/
mbed_official 76:aeb1df146756 280 /* Configure the USART Baud Rate -------------------------------------------*/
mbed_official 76:aeb1df146756 281 RCC_GetClocksFreq(&RCC_ClocksStatus);
mbed_official 76:aeb1df146756 282 if (USARTx == USART1)
mbed_official 76:aeb1df146756 283 {
mbed_official 76:aeb1df146756 284 apbclock = RCC_ClocksStatus.PCLK2_Frequency;
mbed_official 76:aeb1df146756 285 }
mbed_official 76:aeb1df146756 286 else
mbed_official 76:aeb1df146756 287 {
mbed_official 76:aeb1df146756 288 apbclock = RCC_ClocksStatus.PCLK1_Frequency;
mbed_official 76:aeb1df146756 289 }
mbed_official 76:aeb1df146756 290
mbed_official 76:aeb1df146756 291 /* Determine the integer part */
mbed_official 76:aeb1df146756 292 if ((USARTx->CR1 & USART_CR1_OVER8) != 0)
mbed_official 76:aeb1df146756 293 {
mbed_official 76:aeb1df146756 294 /* Integer part computing in case Oversampling mode is 8 Samples */
mbed_official 76:aeb1df146756 295 integerdivider = ((25 * apbclock) / (2 * (USART_InitStruct->USART_BaudRate)));
mbed_official 76:aeb1df146756 296 }
mbed_official 76:aeb1df146756 297 else /* if ((USARTx->CR1 & CR1_OVER8_Set) == 0) */
mbed_official 76:aeb1df146756 298 {
mbed_official 76:aeb1df146756 299 /* Integer part computing in case Oversampling mode is 16 Samples */
mbed_official 76:aeb1df146756 300 integerdivider = ((25 * apbclock) / (4 * (USART_InitStruct->USART_BaudRate)));
mbed_official 76:aeb1df146756 301 }
mbed_official 76:aeb1df146756 302 tmpreg = (integerdivider / 100) << 4;
mbed_official 76:aeb1df146756 303
mbed_official 76:aeb1df146756 304 /* Determine the fractional part */
mbed_official 76:aeb1df146756 305 fractionaldivider = integerdivider - (100 * (tmpreg >> 4));
mbed_official 76:aeb1df146756 306
mbed_official 76:aeb1df146756 307 /* Implement the fractional part in the register */
mbed_official 76:aeb1df146756 308 if ((USARTx->CR1 & USART_CR1_OVER8) != 0)
mbed_official 76:aeb1df146756 309 {
mbed_official 76:aeb1df146756 310 tmpreg |= ((((fractionaldivider * 8) + 50) / 100)) & ((uint8_t)0x07);
mbed_official 76:aeb1df146756 311 }
mbed_official 76:aeb1df146756 312 else /* if ((USARTx->CR1 & CR1_OVER8_Set) == 0) */
mbed_official 76:aeb1df146756 313 {
mbed_official 76:aeb1df146756 314 tmpreg |= ((((fractionaldivider * 16) + 50) / 100)) & ((uint8_t)0x0F);
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)tmpreg;
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 to select the USART peripheral.
mbed_official 76:aeb1df146756 342 * @param USART_ClockInitStruct: pointer to a USART_ClockInitTypeDef
mbed_official 76:aeb1df146756 343 * structure that contains the configuration information for the specified
mbed_official 76:aeb1df146756 344 * USART peripheral.
mbed_official 76:aeb1df146756 345 * @note The Smart Card and Synchronous modes are not available for UART4 and UART5.
mbed_official 76:aeb1df146756 346 * @retval None.
mbed_official 76:aeb1df146756 347 */
mbed_official 76:aeb1df146756 348 void USART_ClockInit(USART_TypeDef* USARTx, USART_ClockInitTypeDef* USART_ClockInitStruct)
mbed_official 76:aeb1df146756 349 {
mbed_official 76:aeb1df146756 350 uint32_t tmpreg = 0x00;
mbed_official 76:aeb1df146756 351 /* Check the parameters */
mbed_official 76:aeb1df146756 352 assert_param(IS_USART_123_PERIPH(USARTx));
mbed_official 76:aeb1df146756 353 assert_param(IS_USART_CLOCK(USART_ClockInitStruct->USART_Clock));
mbed_official 76:aeb1df146756 354 assert_param(IS_USART_CPOL(USART_ClockInitStruct->USART_CPOL));
mbed_official 76:aeb1df146756 355 assert_param(IS_USART_CPHA(USART_ClockInitStruct->USART_CPHA));
mbed_official 76:aeb1df146756 356 assert_param(IS_USART_LASTBIT(USART_ClockInitStruct->USART_LastBit));
mbed_official 76:aeb1df146756 357
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 and LBCL 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 and LastBit ------------*/
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 = (uint16_t)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: Select the USART peripheral.
mbed_official 76:aeb1df146756 391 * This parameter can be one of the following values:
mbed_official 76:aeb1df146756 392 * USART1, USART2, USART3, UART4 or UART5.
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 &= (uint16_t)~((uint16_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 Sets the system clock prescaler.
mbed_official 76:aeb1df146756 417 * @param USARTx: Select the USART peripheral.
mbed_official 76:aeb1df146756 418 * This parameter can be one of the following values:
mbed_official 76:aeb1df146756 419 * USART1, USART2, USART3, UART4 or UART5.
mbed_official 76:aeb1df146756 420 * @param USART_Prescaler: specifies the prescaler clock.
mbed_official 76:aeb1df146756 421 * @note The function is used for IrDA mode with UART4 and UART5.
mbed_official 76:aeb1df146756 422 * @retval None.
mbed_official 76:aeb1df146756 423 */
mbed_official 76:aeb1df146756 424 void USART_SetPrescaler(USART_TypeDef* USARTx, uint8_t USART_Prescaler)
mbed_official 76:aeb1df146756 425 {
mbed_official 76:aeb1df146756 426 /* Check the parameters */
mbed_official 76:aeb1df146756 427 assert_param(IS_USART_ALL_PERIPH(USARTx));
mbed_official 76:aeb1df146756 428
mbed_official 76:aeb1df146756 429 /* Clear the USART prescaler */
mbed_official 76:aeb1df146756 430 USARTx->GTPR &= USART_GTPR_GT;
mbed_official 76:aeb1df146756 431 /* Set the USART prescaler */
mbed_official 76:aeb1df146756 432 USARTx->GTPR |= USART_Prescaler;
mbed_official 76:aeb1df146756 433 }
mbed_official 76:aeb1df146756 434
mbed_official 76:aeb1df146756 435 /**
mbed_official 76:aeb1df146756 436 * @brief Enables or disables the USART's 8x oversampling mode.
mbed_official 76:aeb1df146756 437 * @param USARTx: Select the USART peripheral.
mbed_official 76:aeb1df146756 438 * This parameter can be one of the following values:
mbed_official 76:aeb1df146756 439 * USART1, USART2, USART3, UART4 or UART5.
mbed_official 76:aeb1df146756 440 * @param NewState: new state of the USART 8x oversampling mode.
mbed_official 76:aeb1df146756 441 * This parameter can be: ENABLE or DISABLE.
mbed_official 76:aeb1df146756 442 *
mbed_official 76:aeb1df146756 443 * @note
mbed_official 76:aeb1df146756 444 * This function has to be called before calling USART_Init()
mbed_official 76:aeb1df146756 445 * function in order to have correct baudrate Divider value.
mbed_official 76:aeb1df146756 446 * @retval None
mbed_official 76:aeb1df146756 447 */
mbed_official 76:aeb1df146756 448 void USART_OverSampling8Cmd(USART_TypeDef* USARTx, FunctionalState NewState)
mbed_official 76:aeb1df146756 449 {
mbed_official 76:aeb1df146756 450 /* Check the parameters */
mbed_official 76:aeb1df146756 451 assert_param(IS_USART_ALL_PERIPH(USARTx));
mbed_official 76:aeb1df146756 452 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 76:aeb1df146756 453
mbed_official 76:aeb1df146756 454 if (NewState != DISABLE)
mbed_official 76:aeb1df146756 455 {
mbed_official 76:aeb1df146756 456 /* Enable the 8x Oversampling mode by setting the OVER8 bit in the CR1 register */
mbed_official 76:aeb1df146756 457 USARTx->CR1 |= USART_CR1_OVER8;
mbed_official 76:aeb1df146756 458 }
mbed_official 76:aeb1df146756 459 else
mbed_official 76:aeb1df146756 460 {
mbed_official 76:aeb1df146756 461 /* Disable the 8x Oversampling mode by clearing the OVER8 bit in the CR1 register */
mbed_official 76:aeb1df146756 462 USARTx->CR1 &= (uint16_t)~((uint16_t)USART_CR1_OVER8);
mbed_official 76:aeb1df146756 463 }
mbed_official 76:aeb1df146756 464 }
mbed_official 76:aeb1df146756 465
mbed_official 76:aeb1df146756 466 /**
mbed_official 76:aeb1df146756 467 * @brief Enables or disables the USART's one bit sampling method.
mbed_official 76:aeb1df146756 468 * @param USARTx: Select the USART peripheral.
mbed_official 76:aeb1df146756 469 * This parameter can be one of the following values:
mbed_official 76:aeb1df146756 470 * USART1, USART2, USART3, UART4 or UART5.
mbed_official 76:aeb1df146756 471 * @param NewState: new state of the USART one bit sampling method.
mbed_official 76:aeb1df146756 472 * This parameter can be: ENABLE or DISABLE.
mbed_official 76:aeb1df146756 473 * @retval None.
mbed_official 76:aeb1df146756 474 */
mbed_official 76:aeb1df146756 475 void USART_OneBitMethodCmd(USART_TypeDef* USARTx, FunctionalState NewState)
mbed_official 76:aeb1df146756 476 {
mbed_official 76:aeb1df146756 477 /* Check the parameters */
mbed_official 76:aeb1df146756 478 assert_param(IS_USART_ALL_PERIPH(USARTx));
mbed_official 76:aeb1df146756 479 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 76:aeb1df146756 480
mbed_official 76:aeb1df146756 481 if (NewState != DISABLE)
mbed_official 76:aeb1df146756 482 {
mbed_official 76:aeb1df146756 483 /* Enable the one bit method by setting the ONEBITE bit in the CR3 register */
mbed_official 76:aeb1df146756 484 USARTx->CR3 |= USART_CR3_ONEBIT;
mbed_official 76:aeb1df146756 485 }
mbed_official 76:aeb1df146756 486 else
mbed_official 76:aeb1df146756 487 {
mbed_official 76:aeb1df146756 488 /* Disable the one bit method by clearing the ONEBITE bit in the CR3 register */
mbed_official 76:aeb1df146756 489 USARTx->CR3 &= (uint16_t)~((uint16_t)USART_CR3_ONEBIT);
mbed_official 76:aeb1df146756 490 }
mbed_official 76:aeb1df146756 491 }
mbed_official 76:aeb1df146756 492
mbed_official 76:aeb1df146756 493 /**
mbed_official 76:aeb1df146756 494 * @}
mbed_official 76:aeb1df146756 495 */
mbed_official 76:aeb1df146756 496
mbed_official 76:aeb1df146756 497 /** @defgroup USART_Group2 Data transfers functions
mbed_official 76:aeb1df146756 498 * @brief Data transfers functions
mbed_official 76:aeb1df146756 499 *
mbed_official 76:aeb1df146756 500 @verbatim
mbed_official 76:aeb1df146756 501 ===============================================================================
mbed_official 76:aeb1df146756 502 ##### Data transfers functions #####
mbed_official 76:aeb1df146756 503 ===============================================================================
mbed_official 76:aeb1df146756 504 [..] This subsection provides a set of functions allowing to manage
mbed_official 76:aeb1df146756 505 the USART data transfers.
mbed_official 76:aeb1df146756 506 [..] During an USART reception, data shifts in least significant bit first
mbed_official 76:aeb1df146756 507 through the RX pin. In this mode, the USART_DR register consists of
mbed_official 76:aeb1df146756 508 a buffer (RDR) between the internal bus and the received shift register.
mbed_official 76:aeb1df146756 509 When a transmission is taking place, a write instruction to
mbed_official 76:aeb1df146756 510 the USART_DR register stores the data in the TDR register and which is
mbed_official 76:aeb1df146756 511 copied in the shift register at the end of the current transmission.
mbed_official 76:aeb1df146756 512 [..] The read access of the USART_DR register can be done using
mbed_official 76:aeb1df146756 513 the USART_ReceiveData() function and returns the RDR buffered value.
mbed_official 76:aeb1df146756 514 Whereas a write access to the USART_DR can be done using USART_SendData()
mbed_official 76:aeb1df146756 515 function and stores the written data into TDR buffer.
mbed_official 76:aeb1df146756 516
mbed_official 76:aeb1df146756 517 @endverbatim
mbed_official 76:aeb1df146756 518 * @{
mbed_official 76:aeb1df146756 519 */
mbed_official 76:aeb1df146756 520
mbed_official 76:aeb1df146756 521 /**
mbed_official 76:aeb1df146756 522 * @brief Transmits single data through the USARTx peripheral.
mbed_official 76:aeb1df146756 523 * @param USARTx: Select the USART peripheral.
mbed_official 76:aeb1df146756 524 * This parameter can be one of the following values:
mbed_official 76:aeb1df146756 525 * USART1, USART2, USART3, UART4 or UART5.
mbed_official 76:aeb1df146756 526 * @param Data: the data to transmit.
mbed_official 76:aeb1df146756 527 * @retval None.
mbed_official 76:aeb1df146756 528 */
mbed_official 76:aeb1df146756 529 void USART_SendData(USART_TypeDef* USARTx, uint16_t Data)
mbed_official 76:aeb1df146756 530 {
mbed_official 76:aeb1df146756 531 /* Check the parameters */
mbed_official 76:aeb1df146756 532 assert_param(IS_USART_ALL_PERIPH(USARTx));
mbed_official 76:aeb1df146756 533 assert_param(IS_USART_DATA(Data));
mbed_official 76:aeb1df146756 534
mbed_official 76:aeb1df146756 535 /* Transmit Data */
mbed_official 76:aeb1df146756 536 USARTx->DR = (Data & (uint16_t)0x01FF);
mbed_official 76:aeb1df146756 537 }
mbed_official 76:aeb1df146756 538
mbed_official 76:aeb1df146756 539 /**
mbed_official 76:aeb1df146756 540 * @brief Returns the most recent received data by the USARTx peripheral.
mbed_official 76:aeb1df146756 541 * @param USARTx: Select the USART peripheral.
mbed_official 76:aeb1df146756 542 * This parameter can be one of the following values:
mbed_official 76:aeb1df146756 543 * USART1, USART2, USART3, UART4 or UART5.
mbed_official 76:aeb1df146756 544 * @retval The received data.
mbed_official 76:aeb1df146756 545 */
mbed_official 76:aeb1df146756 546 uint16_t USART_ReceiveData(USART_TypeDef* USARTx)
mbed_official 76:aeb1df146756 547 {
mbed_official 76:aeb1df146756 548 /* Check the parameters */
mbed_official 76:aeb1df146756 549 assert_param(IS_USART_ALL_PERIPH(USARTx));
mbed_official 76:aeb1df146756 550
mbed_official 76:aeb1df146756 551 /* Receive Data */
mbed_official 76:aeb1df146756 552 return (uint16_t)(USARTx->DR & (uint16_t)0x01FF);
mbed_official 76:aeb1df146756 553 }
mbed_official 76:aeb1df146756 554
mbed_official 76:aeb1df146756 555 /**
mbed_official 76:aeb1df146756 556 * @}
mbed_official 76:aeb1df146756 557 */
mbed_official 76:aeb1df146756 558
mbed_official 76:aeb1df146756 559 /** @defgroup USART_Group3 MultiProcessor Communication functions
mbed_official 76:aeb1df146756 560 * @brief Multi-Processor Communication functions
mbed_official 76:aeb1df146756 561 *
mbed_official 76:aeb1df146756 562 @verbatim
mbed_official 76:aeb1df146756 563 ===============================================================================
mbed_official 76:aeb1df146756 564 ##### Multi-Processor Communication functions #####
mbed_official 76:aeb1df146756 565 ===============================================================================
mbed_official 76:aeb1df146756 566 [..] This subsection provides a set of functions allowing to manage the USART
mbed_official 76:aeb1df146756 567 multiprocessor communication.
mbed_official 76:aeb1df146756 568 [..] For instance one of the USARTs can be the master, its TX output is
mbed_official 76:aeb1df146756 569 connected to the RX input of the other USART. The others are slaves,
mbed_official 76:aeb1df146756 570 their respective TX outputs are logically ANDed together and connected
mbed_official 76:aeb1df146756 571 to the RX input of the master. USART multiprocessor communication is
mbed_official 76:aeb1df146756 572 possible through the following procedure:
mbed_official 76:aeb1df146756 573 (#) Program the Baud rate, Word length = 9 bits, Stop bits, Parity,
mbed_official 76:aeb1df146756 574 Mode transmitter or Mode receiver and hardware flow control values
mbed_official 76:aeb1df146756 575 using the USART_Init() function.
mbed_official 76:aeb1df146756 576 (#) Configures the USART address using the USART_SetAddress() function.
mbed_official 76:aeb1df146756 577 (#) Configures the wake up methode (USART_WakeUp_IdleLine or
mbed_official 76:aeb1df146756 578 USART_WakeUp_AddressMark) using USART_WakeUpConfig() function only
mbed_official 76:aeb1df146756 579 for the slaves.
mbed_official 76:aeb1df146756 580 (#) Enable the USART using the USART_Cmd() function.
mbed_official 76:aeb1df146756 581 (#) Enter the USART slaves in mute mode using USART_ReceiverWakeUpCmd()
mbed_official 76:aeb1df146756 582 function.
mbed_official 76:aeb1df146756 583
mbed_official 76:aeb1df146756 584 [..] The USART Slave exit from mute mode when receive the wake up condition.
mbed_official 76:aeb1df146756 585
mbed_official 76:aeb1df146756 586 @endverbatim
mbed_official 76:aeb1df146756 587 * @{
mbed_official 76:aeb1df146756 588 */
mbed_official 76:aeb1df146756 589
mbed_official 76:aeb1df146756 590 /**
mbed_official 76:aeb1df146756 591 * @brief Sets the address of the USART node.
mbed_official 76:aeb1df146756 592 * @param USARTx: Select the USART peripheral.
mbed_official 76:aeb1df146756 593 * This parameter can be one of the following values:
mbed_official 76:aeb1df146756 594 * USART1, USART2, USART3, UART4 or UART5.
mbed_official 76:aeb1df146756 595 * @param USART_Address: Indicates the address of the USART node.
mbed_official 76:aeb1df146756 596 * @retval None
mbed_official 76:aeb1df146756 597 */
mbed_official 76:aeb1df146756 598 void USART_SetAddress(USART_TypeDef* USARTx, uint8_t USART_Address)
mbed_official 76:aeb1df146756 599 {
mbed_official 76:aeb1df146756 600 /* Check the parameters */
mbed_official 76:aeb1df146756 601 assert_param(IS_USART_ALL_PERIPH(USARTx));
mbed_official 76:aeb1df146756 602 assert_param(IS_USART_ADDRESS(USART_Address));
mbed_official 76:aeb1df146756 603
mbed_official 76:aeb1df146756 604 /* Clear the USART address */
mbed_official 76:aeb1df146756 605 USARTx->CR2 &= (uint16_t)~((uint16_t)USART_CR2_ADD);
mbed_official 76:aeb1df146756 606 /* Set the USART address node */
mbed_official 76:aeb1df146756 607 USARTx->CR2 |= USART_Address;
mbed_official 76:aeb1df146756 608 }
mbed_official 76:aeb1df146756 609
mbed_official 76:aeb1df146756 610 /**
mbed_official 76:aeb1df146756 611 * @brief Determines if the USART is in mute mode or not.
mbed_official 76:aeb1df146756 612 * @param USARTx: Select the USART peripheral.
mbed_official 76:aeb1df146756 613 * This parameter can be one of the following values:
mbed_official 76:aeb1df146756 614 * USART1, USART2, USART3, UART4 or UART5.
mbed_official 76:aeb1df146756 615 * @param NewState: new state of the USART mute mode.
mbed_official 76:aeb1df146756 616 * This parameter can be: ENABLE or DISABLE.
mbed_official 76:aeb1df146756 617 * @retval None
mbed_official 76:aeb1df146756 618 */
mbed_official 76:aeb1df146756 619 void USART_ReceiverWakeUpCmd(USART_TypeDef* USARTx, FunctionalState NewState)
mbed_official 76:aeb1df146756 620 {
mbed_official 76:aeb1df146756 621 /* Check the parameters */
mbed_official 76:aeb1df146756 622 assert_param(IS_USART_ALL_PERIPH(USARTx));
mbed_official 76:aeb1df146756 623 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 76:aeb1df146756 624
mbed_official 76:aeb1df146756 625 if (NewState != DISABLE)
mbed_official 76:aeb1df146756 626 {
mbed_official 76:aeb1df146756 627 /* Enable the USART mute mode by setting the RWU bit in the CR1 register */
mbed_official 76:aeb1df146756 628 USARTx->CR1 |= USART_CR1_RWU;
mbed_official 76:aeb1df146756 629 }
mbed_official 76:aeb1df146756 630 else
mbed_official 76:aeb1df146756 631 {
mbed_official 76:aeb1df146756 632 /* Disable the USART mute mode by clearing the RWU bit in the CR1 register */
mbed_official 76:aeb1df146756 633 USARTx->CR1 &= (uint16_t)~((uint16_t)USART_CR1_RWU);
mbed_official 76:aeb1df146756 634 }
mbed_official 76:aeb1df146756 635 }
mbed_official 76:aeb1df146756 636 /**
mbed_official 76:aeb1df146756 637 * @brief Selects the USART WakeUp method.
mbed_official 76:aeb1df146756 638 * @param USARTx: Select the USART peripheral.
mbed_official 76:aeb1df146756 639 * This parameter can be one of the following values:
mbed_official 76:aeb1df146756 640 * USART1, USART2, USART3, UART4 or UART5.
mbed_official 76:aeb1df146756 641 * @param USART_WakeUp: specifies the USART wakeup method.
mbed_official 76:aeb1df146756 642 * This parameter can be one of the following values:
mbed_official 76:aeb1df146756 643 * @arg USART_WakeUp_IdleLine: WakeUp by an idle line detection.
mbed_official 76:aeb1df146756 644 * @arg USART_WakeUp_AddressMark: WakeUp by an address mark.
mbed_official 76:aeb1df146756 645 * @retval None.
mbed_official 76:aeb1df146756 646 */
mbed_official 76:aeb1df146756 647 void USART_WakeUpConfig(USART_TypeDef* USARTx, uint16_t USART_WakeUp)
mbed_official 76:aeb1df146756 648 {
mbed_official 76:aeb1df146756 649 /* Check the parameters */
mbed_official 76:aeb1df146756 650 assert_param(IS_USART_ALL_PERIPH(USARTx));
mbed_official 76:aeb1df146756 651 assert_param(IS_USART_WAKEUP(USART_WakeUp));
mbed_official 76:aeb1df146756 652
mbed_official 76:aeb1df146756 653 USARTx->CR1 &= (uint16_t)~((uint16_t)USART_CR1_WAKE);
mbed_official 76:aeb1df146756 654 USARTx->CR1 |= USART_WakeUp;
mbed_official 76:aeb1df146756 655 }
mbed_official 76:aeb1df146756 656
mbed_official 76:aeb1df146756 657 /**
mbed_official 76:aeb1df146756 658 * @}
mbed_official 76:aeb1df146756 659 */
mbed_official 76:aeb1df146756 660
mbed_official 76:aeb1df146756 661 /** @defgroup USART_Group4 LIN mode functions
mbed_official 76:aeb1df146756 662 * @brief LIN mode functions
mbed_official 76:aeb1df146756 663 *
mbed_official 76:aeb1df146756 664 @verbatim
mbed_official 76:aeb1df146756 665 ===============================================================================
mbed_official 76:aeb1df146756 666 ##### LIN mode functions #####
mbed_official 76:aeb1df146756 667 ===============================================================================
mbed_official 76:aeb1df146756 668 [..] This subsection provides a set of functions allowing to manage the USART
mbed_official 76:aeb1df146756 669 LIN Mode communication.
mbed_official 76:aeb1df146756 670 [..] In LIN mode, 8-bit data format with 1 stop bit is required in accordance
mbed_official 76:aeb1df146756 671 with the LIN standard.
mbed_official 76:aeb1df146756 672 [..] Only this LIN Feature is supported by the USART IP:
mbed_official 76:aeb1df146756 673 (+) LIN Master Synchronous Break send capability and LIN slave break
mbed_official 76:aeb1df146756 674 detection capability : 13-bit break generation and 10/11 bit break
mbed_official 76:aeb1df146756 675 detection.
mbed_official 76:aeb1df146756 676 [..] USART LIN Master transmitter communication is possible through the
mbed_official 76:aeb1df146756 677 following procedure:
mbed_official 76:aeb1df146756 678 (#) Program the Baud rate, Word length = 8bits, Stop bits = 1bit, Parity,
mbed_official 76:aeb1df146756 679 Mode transmitter or Mode receiver and hardware flow control values
mbed_official 76:aeb1df146756 680 using the USART_Init() function.
mbed_official 76:aeb1df146756 681 (#) Enable the USART using the USART_Cmd() function.
mbed_official 76:aeb1df146756 682 (#) Enable the LIN mode using the USART_LINCmd() function.
mbed_official 76:aeb1df146756 683 (#) Send the break character using USART_SendBreak() function.
mbed_official 76:aeb1df146756 684 [..] USART LIN Master receiver communication is possible through the
mbed_official 76:aeb1df146756 685 following procedure:
mbed_official 76:aeb1df146756 686 (#) Program the Baud rate, Word length = 8bits, Stop bits = 1bit, Parity,
mbed_official 76:aeb1df146756 687 Mode transmitter or Mode receiver and hardware flow control values
mbed_official 76:aeb1df146756 688 using the USART_Init() function.
mbed_official 76:aeb1df146756 689 (#) Enable the USART using the USART_Cmd() function.
mbed_official 76:aeb1df146756 690 (#) Configures the break detection length
mbed_official 76:aeb1df146756 691 using the USART_LINBreakDetectLengthConfig() function.
mbed_official 76:aeb1df146756 692 (#) Enable the LIN mode using the USART_LINCmd() function.
mbed_official 76:aeb1df146756 693 -@- In LIN mode, the following bits must be kept cleared:
mbed_official 76:aeb1df146756 694 (+@) CLKEN in the USART_CR2 register.
mbed_official 76:aeb1df146756 695 (+@) STOP[1:0], SCEN, HDSEL and IREN in the USART_CR3 register.
mbed_official 76:aeb1df146756 696
mbed_official 76:aeb1df146756 697 @endverbatim
mbed_official 76:aeb1df146756 698 * @{
mbed_official 76:aeb1df146756 699 */
mbed_official 76:aeb1df146756 700
mbed_official 76:aeb1df146756 701 /**
mbed_official 76:aeb1df146756 702 * @brief Sets the USART LIN Break detection length.
mbed_official 76:aeb1df146756 703 * @param USARTx: Select the USART peripheral.
mbed_official 76:aeb1df146756 704 * This parameter can be one of the following values:
mbed_official 76:aeb1df146756 705 * USART1, USART2, USART3, UART4 or UART5.
mbed_official 76:aeb1df146756 706 * @param USART_LINBreakDetectLength: specifies the LIN break detection length.
mbed_official 76:aeb1df146756 707 * This parameter can be one of the following values:
mbed_official 76:aeb1df146756 708 * @arg USART_LINBreakDetectLength_10b: 10-bit break detection.
mbed_official 76:aeb1df146756 709 * @arg USART_LINBreakDetectLength_11b: 11-bit break detection.
mbed_official 76:aeb1df146756 710 * @retval None.
mbed_official 76:aeb1df146756 711 */
mbed_official 76:aeb1df146756 712 void USART_LINBreakDetectLengthConfig(USART_TypeDef* USARTx, uint16_t USART_LINBreakDetectLength)
mbed_official 76:aeb1df146756 713 {
mbed_official 76:aeb1df146756 714 /* Check the parameters */
mbed_official 76:aeb1df146756 715 assert_param(IS_USART_ALL_PERIPH(USARTx));
mbed_official 76:aeb1df146756 716 assert_param(IS_USART_LIN_BREAK_DETECT_LENGTH(USART_LINBreakDetectLength));
mbed_official 76:aeb1df146756 717
mbed_official 76:aeb1df146756 718 USARTx->CR2 &= (uint16_t)~((uint16_t)USART_CR2_LBDL);
mbed_official 76:aeb1df146756 719 USARTx->CR2 |= USART_LINBreakDetectLength;
mbed_official 76:aeb1df146756 720 }
mbed_official 76:aeb1df146756 721
mbed_official 76:aeb1df146756 722 /**
mbed_official 76:aeb1df146756 723 * @brief Enables or disables the USART's LIN mode.
mbed_official 76:aeb1df146756 724 * @param USARTx: Select the USART peripheral.
mbed_official 76:aeb1df146756 725 * This parameter can be one of the following values:
mbed_official 76:aeb1df146756 726 * USART1, USART2, USART3, UART4 or UART5.
mbed_official 76:aeb1df146756 727 * @param NewState: new state of the USART LIN mode.
mbed_official 76:aeb1df146756 728 * This parameter can be: ENABLE or DISABLE.
mbed_official 76:aeb1df146756 729 * @retval None.
mbed_official 76:aeb1df146756 730 */
mbed_official 76:aeb1df146756 731 void USART_LINCmd(USART_TypeDef* USARTx, FunctionalState NewState)
mbed_official 76:aeb1df146756 732 {
mbed_official 76:aeb1df146756 733 /* Check the parameters */
mbed_official 76:aeb1df146756 734 assert_param(IS_USART_ALL_PERIPH(USARTx));
mbed_official 76:aeb1df146756 735 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 76:aeb1df146756 736
mbed_official 76:aeb1df146756 737 if (NewState != DISABLE)
mbed_official 76:aeb1df146756 738 {
mbed_official 76:aeb1df146756 739 /* Enable the LIN mode by setting the LINEN bit in the CR2 register */
mbed_official 76:aeb1df146756 740 USARTx->CR2 |= USART_CR2_LINEN;
mbed_official 76:aeb1df146756 741 }
mbed_official 76:aeb1df146756 742 else
mbed_official 76:aeb1df146756 743 {
mbed_official 76:aeb1df146756 744 /* Disable the LIN mode by clearing the LINEN bit in the CR2 register */
mbed_official 76:aeb1df146756 745 USARTx->CR2 &= (uint16_t)~((uint16_t)USART_CR2_LINEN);
mbed_official 76:aeb1df146756 746 }
mbed_official 76:aeb1df146756 747 }
mbed_official 76:aeb1df146756 748
mbed_official 76:aeb1df146756 749 /**
mbed_official 76:aeb1df146756 750 * @brief Transmits break characters.
mbed_official 76:aeb1df146756 751 * @param USARTx: Select the USART peripheral.
mbed_official 76:aeb1df146756 752 * This parameter can be one of the following values:
mbed_official 76:aeb1df146756 753 * USART1, USART2, USART3, UART4 or UART5.
mbed_official 76:aeb1df146756 754 * @retval None.
mbed_official 76:aeb1df146756 755 */
mbed_official 76:aeb1df146756 756 void USART_SendBreak(USART_TypeDef* USARTx)
mbed_official 76:aeb1df146756 757 {
mbed_official 76:aeb1df146756 758 /* Check the parameters */
mbed_official 76:aeb1df146756 759 assert_param(IS_USART_ALL_PERIPH(USARTx));
mbed_official 76:aeb1df146756 760
mbed_official 76:aeb1df146756 761 /* Send break characters */
mbed_official 76:aeb1df146756 762 USARTx->CR1 |= USART_CR1_SBK;
mbed_official 76:aeb1df146756 763 }
mbed_official 76:aeb1df146756 764
mbed_official 76:aeb1df146756 765 /**
mbed_official 76:aeb1df146756 766 * @}
mbed_official 76:aeb1df146756 767 */
mbed_official 76:aeb1df146756 768
mbed_official 76:aeb1df146756 769 /** @defgroup USART_Group5 Halfduplex mode function
mbed_official 76:aeb1df146756 770 * @brief Half-duplex mode function
mbed_official 76:aeb1df146756 771 *
mbed_official 76:aeb1df146756 772 @verbatim
mbed_official 76:aeb1df146756 773 ===============================================================================
mbed_official 76:aeb1df146756 774 ##### Half-duplex mode function #####
mbed_official 76:aeb1df146756 775 ===============================================================================
mbed_official 76:aeb1df146756 776 [..] This subsection provides a set of functions allowing to manage the USART
mbed_official 76:aeb1df146756 777 Half-duplex communication.
mbed_official 76:aeb1df146756 778 [..] The USART can be configured to follow a single-wire half-duplex protocol
mbed_official 76:aeb1df146756 779 where the TX and RX lines are internally connected.
mbed_official 76:aeb1df146756 780 [..] USART Half duplex communication is possible through the following procedure:
mbed_official 76:aeb1df146756 781 (#) Program the Baud rate, Word length, Stop bits, Parity, Mode transmitter
mbed_official 76:aeb1df146756 782 or Mode receiver and hardware flow control values using the USART_Init()
mbed_official 76:aeb1df146756 783 function.
mbed_official 76:aeb1df146756 784 (#) Configures the USART address using the USART_SetAddress() function.
mbed_official 76:aeb1df146756 785 (#) Enable the USART using the USART_Cmd() function.
mbed_official 76:aeb1df146756 786 (#) Enable the half duplex mode using USART_HalfDuplexCmd() function.
mbed_official 76:aeb1df146756 787 -@- The RX pin is no longer used.
mbed_official 76:aeb1df146756 788 -@- In Half-duplex mode the following bits must be kept cleared:
mbed_official 76:aeb1df146756 789 (+@) LINEN and CLKEN bits in the USART_CR2 register.
mbed_official 76:aeb1df146756 790 (+@) SCEN and IREN bits in the USART_CR3 register.
mbed_official 76:aeb1df146756 791
mbed_official 76:aeb1df146756 792 @endverbatim
mbed_official 76:aeb1df146756 793 * @{
mbed_official 76:aeb1df146756 794 */
mbed_official 76:aeb1df146756 795
mbed_official 76:aeb1df146756 796 /**
mbed_official 76:aeb1df146756 797 * @brief Enables or disables the USART's Half Duplex communication.
mbed_official 76:aeb1df146756 798 * @param USARTx: Select the USART peripheral.
mbed_official 76:aeb1df146756 799 * This parameter can be one of the following values:
mbed_official 76:aeb1df146756 800 * USART1, USART2, USART3, UART4 or UART5.
mbed_official 76:aeb1df146756 801 * @param NewState: new state of the USART Communication.
mbed_official 76:aeb1df146756 802 * This parameter can be: ENABLE or DISABLE.
mbed_official 76:aeb1df146756 803 * @retval None
mbed_official 76:aeb1df146756 804 */
mbed_official 76:aeb1df146756 805 void USART_HalfDuplexCmd(USART_TypeDef* USARTx, FunctionalState NewState)
mbed_official 76:aeb1df146756 806 {
mbed_official 76:aeb1df146756 807 /* Check the parameters */
mbed_official 76:aeb1df146756 808 assert_param(IS_USART_ALL_PERIPH(USARTx));
mbed_official 76:aeb1df146756 809 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 76:aeb1df146756 810
mbed_official 76:aeb1df146756 811 if (NewState != DISABLE)
mbed_official 76:aeb1df146756 812 {
mbed_official 76:aeb1df146756 813 /* Enable the Half-Duplex mode by setting the HDSEL bit in the CR3 register */
mbed_official 76:aeb1df146756 814 USARTx->CR3 |= USART_CR3_HDSEL;
mbed_official 76:aeb1df146756 815 }
mbed_official 76:aeb1df146756 816 else
mbed_official 76:aeb1df146756 817 {
mbed_official 76:aeb1df146756 818 /* Disable the Half-Duplex mode by clearing the HDSEL bit in the CR3 register */
mbed_official 76:aeb1df146756 819 USARTx->CR3 &= (uint16_t)~((uint16_t)USART_CR3_HDSEL);
mbed_official 76:aeb1df146756 820 }
mbed_official 76:aeb1df146756 821 }
mbed_official 76:aeb1df146756 822
mbed_official 76:aeb1df146756 823 /**
mbed_official 76:aeb1df146756 824 * @}
mbed_official 76:aeb1df146756 825 */
mbed_official 76:aeb1df146756 826
mbed_official 76:aeb1df146756 827
mbed_official 76:aeb1df146756 828 /** @defgroup USART_Group6 Smartcard mode functions
mbed_official 76:aeb1df146756 829 * @brief Smartcard mode functions
mbed_official 76:aeb1df146756 830 *
mbed_official 76:aeb1df146756 831 @verbatim
mbed_official 76:aeb1df146756 832 ===============================================================================
mbed_official 76:aeb1df146756 833 ##### Smartcard mode functions #####
mbed_official 76:aeb1df146756 834 ===============================================================================
mbed_official 76:aeb1df146756 835 [..] This subsection provides a set of functions allowing to manage the USART
mbed_official 76:aeb1df146756 836 Smartcard communication.
mbed_official 76:aeb1df146756 837 [..] The Smartcard interface is designed to support asynchronous protocol
mbed_official 76:aeb1df146756 838 Smartcards as defined in the ISO 7816-3 standard. The USART can provide
mbed_official 76:aeb1df146756 839 a clock to the smartcard through the SCLK output. In smartcard mode,
mbed_official 76:aeb1df146756 840 SCLK is not associated to the communication but is simply derived from
mbed_official 76:aeb1df146756 841 the internal peripheral input clock through a 5-bit prescaler.
mbed_official 76:aeb1df146756 842 [..] Smartcard communication is possible through the following procedure:
mbed_official 76:aeb1df146756 843 (#) Configures the Smartcard Prsecaler using the USART_SetPrescaler()
mbed_official 76:aeb1df146756 844 function.
mbed_official 76:aeb1df146756 845 (#) Configures the Smartcard Guard Time using the USART_SetGuardTime()
mbed_official 76:aeb1df146756 846 function.
mbed_official 76:aeb1df146756 847 (#) Program the USART clock using the USART_ClockInit() function as following:
mbed_official 76:aeb1df146756 848 (++) USART Clock enabled.
mbed_official 76:aeb1df146756 849 (++) USART CPOL Low.
mbed_official 76:aeb1df146756 850 (++) USART CPHA on first edge.
mbed_official 76:aeb1df146756 851 (++) USART Last Bit Clock Enabled.
mbed_official 76:aeb1df146756 852 (#) Program the Smartcard interface using the USART_Init() function as
mbed_official 76:aeb1df146756 853 following:
mbed_official 76:aeb1df146756 854 (++) Word Length = 9 Bits.
mbed_official 76:aeb1df146756 855 (++) 1.5 Stop Bit.
mbed_official 76:aeb1df146756 856 (++) Even parity.
mbed_official 76:aeb1df146756 857 (++) BaudRate = 12096 baud.
mbed_official 76:aeb1df146756 858 (++) Hardware flow control disabled (RTS and CTS signals).
mbed_official 76:aeb1df146756 859 (++) Tx and Rx enabled
mbed_official 76:aeb1df146756 860 (#) Optionally you can enable the parity error interrupt using
mbed_official 76:aeb1df146756 861 the USART_ITConfig() function.
mbed_official 76:aeb1df146756 862 (#) Enable the USART using the USART_Cmd() function.
mbed_official 76:aeb1df146756 863 (#) Enable the Smartcard NACK using the USART_SmartCardNACKCmd() function.
mbed_official 76:aeb1df146756 864 (#) Enable the Smartcard interface using the USART_SmartCardCmd() function.
mbed_official 76:aeb1df146756 865 [..]
mbed_official 76:aeb1df146756 866 Please refer to the ISO 7816-3 specification for more details.
mbed_official 76:aeb1df146756 867 [..]
mbed_official 76:aeb1df146756 868 (@) It is also possible to choose 0.5 stop bit for receiving but it is
mbed_official 76:aeb1df146756 869 recommended to use 1.5 stop bits for both transmitting and receiving
mbed_official 76:aeb1df146756 870 to avoid switching between the two configurations.
mbed_official 76:aeb1df146756 871 (@) In smartcard mode, the following bits must be kept cleared:
mbed_official 76:aeb1df146756 872 (+@) LINEN bit in the USART_CR2 register.
mbed_official 76:aeb1df146756 873 (+@) HDSEL and IREN bits in the USART_CR3 register.
mbed_official 76:aeb1df146756 874
mbed_official 76:aeb1df146756 875 @endverbatim
mbed_official 76:aeb1df146756 876 * @{
mbed_official 76:aeb1df146756 877 */
mbed_official 76:aeb1df146756 878
mbed_official 76:aeb1df146756 879 /**
mbed_official 76:aeb1df146756 880 * @brief Sets the specified USART guard time.
mbed_official 76:aeb1df146756 881 * @param USARTx: Select the USART peripheral.
mbed_official 76:aeb1df146756 882 * This parameter can be one of the following values:
mbed_official 76:aeb1df146756 883 * USART1, USART2 or USART3.
mbed_official 76:aeb1df146756 884 * @param USART_GuardTime: specifies the guard time.
mbed_official 76:aeb1df146756 885 * @retval None.
mbed_official 76:aeb1df146756 886 */
mbed_official 76:aeb1df146756 887 void USART_SetGuardTime(USART_TypeDef* USARTx, uint8_t USART_GuardTime)
mbed_official 76:aeb1df146756 888 {
mbed_official 76:aeb1df146756 889 /* Check the parameters */
mbed_official 76:aeb1df146756 890 assert_param(IS_USART_123_PERIPH(USARTx));
mbed_official 76:aeb1df146756 891
mbed_official 76:aeb1df146756 892 /* Clear the USART Guard time */
mbed_official 76:aeb1df146756 893 USARTx->GTPR &= USART_GTPR_PSC;
mbed_official 76:aeb1df146756 894 /* Set the USART guard time */
mbed_official 76:aeb1df146756 895 USARTx->GTPR |= (uint16_t)((uint16_t)USART_GuardTime << 0x08);
mbed_official 76:aeb1df146756 896 }
mbed_official 76:aeb1df146756 897
mbed_official 76:aeb1df146756 898 /**
mbed_official 76:aeb1df146756 899 * @brief Enables or disables the USART's Smart Card mode.
mbed_official 76:aeb1df146756 900 * @param USARTx: Select the USART peripheral.
mbed_official 76:aeb1df146756 901 * This parameter can be one of the following values:
mbed_official 76:aeb1df146756 902 * USART1, USART2 or USART3.
mbed_official 76:aeb1df146756 903 * @param NewState: new state of the Smart Card mode.
mbed_official 76:aeb1df146756 904 * This parameter can be: ENABLE or DISABLE.
mbed_official 76:aeb1df146756 905 * @retval None
mbed_official 76:aeb1df146756 906 */
mbed_official 76:aeb1df146756 907 void USART_SmartCardCmd(USART_TypeDef* USARTx, FunctionalState NewState)
mbed_official 76:aeb1df146756 908 {
mbed_official 76:aeb1df146756 909 /* Check the parameters */
mbed_official 76:aeb1df146756 910 assert_param(IS_USART_123_PERIPH(USARTx));
mbed_official 76:aeb1df146756 911 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 76:aeb1df146756 912 if (NewState != DISABLE)
mbed_official 76:aeb1df146756 913 {
mbed_official 76:aeb1df146756 914 /* Enable the SC mode by setting the SCEN bit in the CR3 register */
mbed_official 76:aeb1df146756 915 USARTx->CR3 |= USART_CR3_SCEN;
mbed_official 76:aeb1df146756 916 }
mbed_official 76:aeb1df146756 917 else
mbed_official 76:aeb1df146756 918 {
mbed_official 76:aeb1df146756 919 /* Disable the SC mode by clearing the SCEN bit in the CR3 register */
mbed_official 76:aeb1df146756 920 USARTx->CR3 &= (uint16_t)~((uint16_t)USART_CR3_SCEN);
mbed_official 76:aeb1df146756 921 }
mbed_official 76:aeb1df146756 922 }
mbed_official 76:aeb1df146756 923
mbed_official 76:aeb1df146756 924 /**
mbed_official 76:aeb1df146756 925 * @brief Enables or disables NACK transmission.
mbed_official 76:aeb1df146756 926 * @param USARTx: Select the USART peripheral.
mbed_official 76:aeb1df146756 927 * This parameter can be one of the following values:
mbed_official 76:aeb1df146756 928 * USART1, USART2 or USART3.
mbed_official 76:aeb1df146756 929 * @param NewState: new state of the NACK transmission.
mbed_official 76:aeb1df146756 930 * This parameter can be: ENABLE or DISABLE.
mbed_official 76:aeb1df146756 931 * @retval None.
mbed_official 76:aeb1df146756 932 */
mbed_official 76:aeb1df146756 933 void USART_SmartCardNACKCmd(USART_TypeDef* USARTx, FunctionalState NewState)
mbed_official 76:aeb1df146756 934 {
mbed_official 76:aeb1df146756 935 /* Check the parameters */
mbed_official 76:aeb1df146756 936 assert_param(IS_USART_123_PERIPH(USARTx));
mbed_official 76:aeb1df146756 937 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 76:aeb1df146756 938 if (NewState != DISABLE)
mbed_official 76:aeb1df146756 939 {
mbed_official 76:aeb1df146756 940 /* Enable the NACK transmission by setting the NACK bit in the CR3 register */
mbed_official 76:aeb1df146756 941 USARTx->CR3 |= USART_CR3_NACK;
mbed_official 76:aeb1df146756 942 }
mbed_official 76:aeb1df146756 943 else
mbed_official 76:aeb1df146756 944 {
mbed_official 76:aeb1df146756 945 /* Disable the NACK transmission by clearing the NACK bit in the CR3 register */
mbed_official 76:aeb1df146756 946 USARTx->CR3 &= (uint16_t)~((uint16_t)USART_CR3_NACK);
mbed_official 76:aeb1df146756 947 }
mbed_official 76:aeb1df146756 948 }
mbed_official 76:aeb1df146756 949
mbed_official 76:aeb1df146756 950 /**
mbed_official 76:aeb1df146756 951 * @}
mbed_official 76:aeb1df146756 952 */
mbed_official 76:aeb1df146756 953
mbed_official 76:aeb1df146756 954 /** @defgroup USART_Group7 IrDA mode functions
mbed_official 76:aeb1df146756 955 * @brief IrDA mode functions
mbed_official 76:aeb1df146756 956 *
mbed_official 76:aeb1df146756 957 @verbatim
mbed_official 76:aeb1df146756 958 ===============================================================================
mbed_official 76:aeb1df146756 959 ##### IrDA mode functions #####
mbed_official 76:aeb1df146756 960 ===============================================================================
mbed_official 76:aeb1df146756 961 [..] This subsection provides a set of functions allowing to manage the USART
mbed_official 76:aeb1df146756 962 IrDA communication.
mbed_official 76:aeb1df146756 963 [..] IrDA is a half duplex communication protocol. If the Transmitter is busy,
mbed_official 76:aeb1df146756 964 any data on the IrDA receive line will be ignored by the IrDA decoder
mbed_official 76:aeb1df146756 965 and if the Receiver is busy, data on the TX from the USART to IrDA will
mbed_official 76:aeb1df146756 966 not be encoded by IrDA. While receiving data, transmission should be
mbed_official 76:aeb1df146756 967 avoided as the data to be transmitted could be corrupted.
mbed_official 76:aeb1df146756 968
mbed_official 76:aeb1df146756 969 [..] IrDA communication is possible through the following procedure:
mbed_official 76:aeb1df146756 970 (#) Program the Baud rate, Word length = 8 bits, Stop bits, Parity,
mbed_official 76:aeb1df146756 971 Transmitter/Receiver modes and hardware flow control values using
mbed_official 76:aeb1df146756 972 the USART_Init() function.
mbed_official 76:aeb1df146756 973 (#) Enable the USART using the USART_Cmd() function.
mbed_official 76:aeb1df146756 974 (#) Configures the IrDA pulse width by configuring the prescaler using
mbed_official 76:aeb1df146756 975 the USART_SetPrescaler() function.
mbed_official 76:aeb1df146756 976 (#) Configures the IrDA USART_IrDAMode_LowPower or USART_IrDAMode_Normal
mbed_official 76:aeb1df146756 977 mode using the USART_IrDAConfig() function.
mbed_official 76:aeb1df146756 978 (#) Enable the IrDA using the USART_IrDACmd() function.
mbed_official 76:aeb1df146756 979
mbed_official 76:aeb1df146756 980 [..]
mbed_official 76:aeb1df146756 981 (@) A pulse of width less than two and greater than one PSC period(s) may or
mbed_official 76:aeb1df146756 982 may not be rejected.
mbed_official 76:aeb1df146756 983 (@) The receiver set up time should be managed by software. The IrDA physical
mbed_official 76:aeb1df146756 984 layer specification specifies a minimum of 10 ms delay between
mbed_official 76:aeb1df146756 985 transmission and reception (IrDA is a half duplex protocol).
mbed_official 76:aeb1df146756 986 (@) In IrDA mode, the following bits must be kept cleared:
mbed_official 76:aeb1df146756 987 (+@) LINEN, STOP and CLKEN bits in the USART_CR2 register.
mbed_official 76:aeb1df146756 988 (+@) SCEN and HDSEL bits in the USART_CR3 register.
mbed_official 76:aeb1df146756 989
mbed_official 76:aeb1df146756 990 @endverbatim
mbed_official 76:aeb1df146756 991 * @{
mbed_official 76:aeb1df146756 992 */
mbed_official 76:aeb1df146756 993
mbed_official 76:aeb1df146756 994 /**
mbed_official 76:aeb1df146756 995 * @brief Configures the USART's IrDA interface.
mbed_official 76:aeb1df146756 996 * @param USARTx: Select the USART peripheral.
mbed_official 76:aeb1df146756 997 * This parameter can be one of the following values:
mbed_official 76:aeb1df146756 998 * USART1, USART2, USART3, UART4 or UART5.
mbed_official 76:aeb1df146756 999 * @param USART_IrDAMode: specifies the IrDA mode.
mbed_official 76:aeb1df146756 1000 * This parameter can be one of the following values:
mbed_official 76:aeb1df146756 1001 * @arg USART_IrDAMode_LowPower: USART IrDA Low Power mode selected.
mbed_official 76:aeb1df146756 1002 * @arg USART_IrDAMode_Normal: USART IrDA Normal mode selected.
mbed_official 76:aeb1df146756 1003 * @retval None
mbed_official 76:aeb1df146756 1004 */
mbed_official 76:aeb1df146756 1005 void USART_IrDAConfig(USART_TypeDef* USARTx, uint16_t USART_IrDAMode)
mbed_official 76:aeb1df146756 1006 {
mbed_official 76:aeb1df146756 1007 /* Check the parameters */
mbed_official 76:aeb1df146756 1008 assert_param(IS_USART_ALL_PERIPH(USARTx));
mbed_official 76:aeb1df146756 1009 assert_param(IS_USART_IRDA_MODE(USART_IrDAMode));
mbed_official 76:aeb1df146756 1010
mbed_official 76:aeb1df146756 1011 USARTx->CR3 &= (uint16_t)~((uint16_t)USART_CR3_IRLP);
mbed_official 76:aeb1df146756 1012 USARTx->CR3 |= USART_IrDAMode;
mbed_official 76:aeb1df146756 1013 }
mbed_official 76:aeb1df146756 1014
mbed_official 76:aeb1df146756 1015 /**
mbed_official 76:aeb1df146756 1016 * @brief Enables or disables the USART's IrDA interface.
mbed_official 76:aeb1df146756 1017 * @param USARTx: Select the USART peripheral.
mbed_official 76:aeb1df146756 1018 * This parameter can be one of the following values:
mbed_official 76:aeb1df146756 1019 * USART1, USART2, USART3, UART4 or UART5.
mbed_official 76:aeb1df146756 1020 * @param NewState: new state of the IrDA mode.
mbed_official 76:aeb1df146756 1021 * This parameter can be: ENABLE or DISABLE.
mbed_official 76:aeb1df146756 1022 * @retval None
mbed_official 76:aeb1df146756 1023 */
mbed_official 76:aeb1df146756 1024 void USART_IrDACmd(USART_TypeDef* USARTx, FunctionalState NewState)
mbed_official 76:aeb1df146756 1025 {
mbed_official 76:aeb1df146756 1026 /* Check the parameters */
mbed_official 76:aeb1df146756 1027 assert_param(IS_USART_ALL_PERIPH(USARTx));
mbed_official 76:aeb1df146756 1028 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 76:aeb1df146756 1029
mbed_official 76:aeb1df146756 1030 if (NewState != DISABLE)
mbed_official 76:aeb1df146756 1031 {
mbed_official 76:aeb1df146756 1032 /* Enable the IrDA mode by setting the IREN bit in the CR3 register */
mbed_official 76:aeb1df146756 1033 USARTx->CR3 |= USART_CR3_IREN;
mbed_official 76:aeb1df146756 1034 }
mbed_official 76:aeb1df146756 1035 else
mbed_official 76:aeb1df146756 1036 {
mbed_official 76:aeb1df146756 1037 /* Disable the IrDA mode by clearing the IREN bit in the CR3 register */
mbed_official 76:aeb1df146756 1038 USARTx->CR3 &= (uint16_t)~((uint16_t)USART_CR3_IREN);
mbed_official 76:aeb1df146756 1039 }
mbed_official 76:aeb1df146756 1040 }
mbed_official 76:aeb1df146756 1041
mbed_official 76:aeb1df146756 1042 /**
mbed_official 76:aeb1df146756 1043 * @}
mbed_official 76:aeb1df146756 1044 */
mbed_official 76:aeb1df146756 1045
mbed_official 76:aeb1df146756 1046 /** @defgroup USART_Group8 DMA transfers management functions
mbed_official 76:aeb1df146756 1047 * @brief DMA transfers management functions
mbed_official 76:aeb1df146756 1048 *
mbed_official 76:aeb1df146756 1049 @verbatim
mbed_official 76:aeb1df146756 1050 ===============================================================================
mbed_official 76:aeb1df146756 1051 ##### DMA transfers management functions #####
mbed_official 76:aeb1df146756 1052 ===============================================================================
mbed_official 76:aeb1df146756 1053
mbed_official 76:aeb1df146756 1054 @endverbatim
mbed_official 76:aeb1df146756 1055 * @{
mbed_official 76:aeb1df146756 1056 */
mbed_official 76:aeb1df146756 1057
mbed_official 76:aeb1df146756 1058 /**
mbed_official 76:aeb1df146756 1059 * @brief Enables or disables the USART's DMA interface.
mbed_official 76:aeb1df146756 1060 * @param USARTx: Select the USART peripheral.
mbed_official 76:aeb1df146756 1061 * This parameter can be one of the following values:
mbed_official 76:aeb1df146756 1062 * USART1, USART2, USART3, UART4 or UART5.
mbed_official 76:aeb1df146756 1063 * @param USART_DMAReq: specifies the DMA request.
mbed_official 76:aeb1df146756 1064 * This parameter can be any combination of the following values:
mbed_official 76:aeb1df146756 1065 * @arg USART_DMAReq_Tx: USART DMA transmit request.
mbed_official 76:aeb1df146756 1066 * @arg USART_DMAReq_Rx: USART DMA receive request.
mbed_official 76:aeb1df146756 1067 * @param NewState: new state of the DMA Request sources.
mbed_official 76:aeb1df146756 1068 * This parameter can be: ENABLE or DISABLE.
mbed_official 76:aeb1df146756 1069 * @retval None
mbed_official 76:aeb1df146756 1070 */
mbed_official 76:aeb1df146756 1071 void USART_DMACmd(USART_TypeDef* USARTx, uint16_t USART_DMAReq, FunctionalState NewState)
mbed_official 76:aeb1df146756 1072 {
mbed_official 76:aeb1df146756 1073 /* Check the parameters */
mbed_official 76:aeb1df146756 1074 assert_param(IS_USART_ALL_PERIPH(USARTx));
mbed_official 76:aeb1df146756 1075 assert_param(IS_USART_DMAREQ(USART_DMAReq));
mbed_official 76:aeb1df146756 1076 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 76:aeb1df146756 1077
mbed_official 76:aeb1df146756 1078 if (NewState != DISABLE)
mbed_official 76:aeb1df146756 1079 {
mbed_official 76:aeb1df146756 1080 /* Enable the DMA transfer for selected requests by setting the DMAT and/or
mbed_official 76:aeb1df146756 1081 DMAR bits in the USART CR3 register */
mbed_official 76:aeb1df146756 1082 USARTx->CR3 |= USART_DMAReq;
mbed_official 76:aeb1df146756 1083 }
mbed_official 76:aeb1df146756 1084 else
mbed_official 76:aeb1df146756 1085 {
mbed_official 76:aeb1df146756 1086 /* Disable the DMA transfer for selected requests by clearing the DMAT and/or
mbed_official 76:aeb1df146756 1087 DMAR bits in the USART CR3 register */
mbed_official 76:aeb1df146756 1088 USARTx->CR3 &= (uint16_t)~USART_DMAReq;
mbed_official 76:aeb1df146756 1089 }
mbed_official 76:aeb1df146756 1090 }
mbed_official 76:aeb1df146756 1091
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 /** @defgroup USART_Group9 Interrupts and flags management functions
mbed_official 76:aeb1df146756 1097 * @brief Interrupts and flags management functions
mbed_official 76:aeb1df146756 1098 *
mbed_official 76:aeb1df146756 1099 @verbatim
mbed_official 76:aeb1df146756 1100 ===============================================================================
mbed_official 76:aeb1df146756 1101 ##### Interrupts and flags management functions #####
mbed_official 76:aeb1df146756 1102 ===============================================================================
mbed_official 76:aeb1df146756 1103 [..] This subsection provides a set of functions allowing to configure the
mbed_official 76:aeb1df146756 1104 USART Interrupts sources, DMA channels requests and check or clear the
mbed_official 76:aeb1df146756 1105 flags or pending bits status. The user should identify which mode will
mbed_official 76:aeb1df146756 1106 be used in his application to manage the communication: Polling mode,
mbed_official 76:aeb1df146756 1107 Interrupt mode or DMA mode.
mbed_official 76:aeb1df146756 1108 *** Polling Mode ***
mbed_official 76:aeb1df146756 1109 ====================
mbed_official 76:aeb1df146756 1110 [..] In Polling Mode, the SPI communication can be managed by 10 flags:
mbed_official 76:aeb1df146756 1111 (#) USART_FLAG_TXE: to indicate the status of the transmit buffer register.
mbed_official 76:aeb1df146756 1112 (#) USART_FLAG_RXNE: to indicate the status of the receive buffer register.
mbed_official 76:aeb1df146756 1113 (#) USART_FLAG_TC: to indicate the status of the transmit operation.
mbed_official 76:aeb1df146756 1114 (#) USART_FLAG_IDLE: to indicate the status of the Idle Line.
mbed_official 76:aeb1df146756 1115 (#) USART_FLAG_CTS: to indicate the status of the nCTS input.
mbed_official 76:aeb1df146756 1116 (#) USART_FLAG_LBD: to indicate the status of the LIN break detection.
mbed_official 76:aeb1df146756 1117 (#) USART_FLAG_NE: to indicate if a noise error occur.
mbed_official 76:aeb1df146756 1118 (#) USART_FLAG_FE: to indicate if a frame error occur.
mbed_official 76:aeb1df146756 1119 (#) USART_FLAG_PE: to indicate if a parity error occur.
mbed_official 76:aeb1df146756 1120 (#) USART_FLAG_ORE: to indicate if an Overrun error occur.
mbed_official 76:aeb1df146756 1121 [..] In this Mode it is advised to use the following functions:
mbed_official 76:aeb1df146756 1122 (+) FlagStatus USART_GetFlagStatus(USART_TypeDef* USARTx, uint16_t USART_FLAG).
mbed_official 76:aeb1df146756 1123 (+) void USART_ClearFlag(USART_TypeDef* USARTx, uint16_t USART_FLAG).
mbed_official 76:aeb1df146756 1124
mbed_official 76:aeb1df146756 1125 *** Interrupt Mode ***
mbed_official 76:aeb1df146756 1126 ======================
mbed_official 76:aeb1df146756 1127 [..] In Interrupt Mode, the USART communication can be managed by 8 interrupt
mbed_official 76:aeb1df146756 1128 sources and 10 pending bits:
mbed_official 76:aeb1df146756 1129 (+) Pending Bits:
mbed_official 76:aeb1df146756 1130 (##) USART_IT_TXE: to indicate the status of the transmit buffer
mbed_official 76:aeb1df146756 1131 register.
mbed_official 76:aeb1df146756 1132 (##) USART_IT_RXNE: to indicate the status of the receive buffer
mbed_official 76:aeb1df146756 1133 register.
mbed_official 76:aeb1df146756 1134 (##) USART_IT_TC: to indicate the status of the transmit operation.
mbed_official 76:aeb1df146756 1135 (##) USART_IT_IDLE: to indicate the status of the Idle Line.
mbed_official 76:aeb1df146756 1136 (##) USART_IT_CTS: to indicate the status of the nCTS input.
mbed_official 76:aeb1df146756 1137 (##) USART_IT_LBD: to indicate the status of the LIN break detection.
mbed_official 76:aeb1df146756 1138 (##) USART_IT_NE: to indicate if a noise error occur.
mbed_official 76:aeb1df146756 1139 (##) USART_IT_FE: to indicate if a frame error occur.
mbed_official 76:aeb1df146756 1140 (##) USART_IT_PE: to indicate if a parity error occur.
mbed_official 76:aeb1df146756 1141 (##) USART_IT_ORE: to indicate if an Overrun error occur
mbed_official 76:aeb1df146756 1142 (if the RXNEIE or EIE bits are set).
mbed_official 76:aeb1df146756 1143
mbed_official 76:aeb1df146756 1144 (+) Interrupt Source:
mbed_official 76:aeb1df146756 1145 (##) USART_IT_TXE: specifies the interrupt source for the Tx buffer
mbed_official 76:aeb1df146756 1146 empty interrupt.
mbed_official 76:aeb1df146756 1147 (##) USART_IT_RXNE: specifies the interrupt source for the Rx buffer
mbed_official 76:aeb1df146756 1148 not empty interrupt.
mbed_official 76:aeb1df146756 1149 (##) USART_IT_TC: specifies the interrupt source for the Transmit
mbed_official 76:aeb1df146756 1150 complete interrupt.
mbed_official 76:aeb1df146756 1151 (##) USART_IT_IDLE: specifies the interrupt source for the Idle Line
mbed_official 76:aeb1df146756 1152 interrupt.
mbed_official 76:aeb1df146756 1153 (##) USART_IT_CTS: specifies the interrupt source for the CTS interrupt.
mbed_official 76:aeb1df146756 1154 (##) USART_IT_LBD: specifies the interrupt source for the LIN break
mbed_official 76:aeb1df146756 1155 detection interrupt.
mbed_official 76:aeb1df146756 1156 (##) USART_IT_PE: specifies the interrupt source for theparity error
mbed_official 76:aeb1df146756 1157 interrupt.
mbed_official 76:aeb1df146756 1158 (##) USART_IT_ERR: specifies the interrupt source for the errors
mbed_official 76:aeb1df146756 1159 interrupt.
mbed_official 76:aeb1df146756 1160 -@@- Some parameters are coded in order to use them as interrupt
mbed_official 76:aeb1df146756 1161 source or as pending bits.
mbed_official 76:aeb1df146756 1162 [..] In this Mode it is advised to use the following functions:
mbed_official 76:aeb1df146756 1163 (+) void USART_ITConfig(USART_TypeDef* USARTx, uint16_t USART_IT,
mbed_official 76:aeb1df146756 1164 FunctionalState NewState).
mbed_official 76:aeb1df146756 1165 (+) ITStatus USART_GetITStatus(USART_TypeDef* USARTx, uint16_t USART_IT).
mbed_official 76:aeb1df146756 1166 (+) void USART_ClearITPendingBit(USART_TypeDef* USARTx, uint16_t USART_IT).
mbed_official 76:aeb1df146756 1167
mbed_official 76:aeb1df146756 1168 *** DMA Mode ***
mbed_official 76:aeb1df146756 1169 ================
mbed_official 76:aeb1df146756 1170 [..] In DMA Mode, the USART communication can be managed by 2 DMA Channel
mbed_official 76:aeb1df146756 1171 requests:
mbed_official 76:aeb1df146756 1172 (#) USART_DMAReq_Tx: specifies the Tx buffer DMA transfer request.
mbed_official 76:aeb1df146756 1173 (#) USART_DMAReq_Rx: specifies the Rx buffer DMA transfer request.
mbed_official 76:aeb1df146756 1174 [..] In this Mode it is advised to use the following function:
mbed_official 76:aeb1df146756 1175 (+) void USART_DMACmd(USART_TypeDef* USARTx, uint16_t USART_DMAReq,
mbed_official 76:aeb1df146756 1176 FunctionalState NewState).
mbed_official 76:aeb1df146756 1177 @endverbatim
mbed_official 76:aeb1df146756 1178 * @{
mbed_official 76:aeb1df146756 1179 */
mbed_official 76:aeb1df146756 1180
mbed_official 76:aeb1df146756 1181 /**
mbed_official 76:aeb1df146756 1182 * @brief Enables or disables the specified USART interrupts.
mbed_official 76:aeb1df146756 1183 * @param USARTx: Select the USART peripheral.
mbed_official 76:aeb1df146756 1184 * This parameter can be one of the following values:
mbed_official 76:aeb1df146756 1185 * USART1, USART2, USART3, UART4 or UART5.
mbed_official 76:aeb1df146756 1186 * @param USART_IT: specifies the USART interrupt sources to be enabled or disabled.
mbed_official 76:aeb1df146756 1187 * This parameter can be one of the following values:
mbed_official 76:aeb1df146756 1188 * @arg USART_IT_CTS: CTS change interrupt.
mbed_official 76:aeb1df146756 1189 * @arg USART_IT_LBD: LIN Break detection interrupt.
mbed_official 76:aeb1df146756 1190 * @arg USART_IT_TXE: Tansmit Data Register empty interrupt.
mbed_official 76:aeb1df146756 1191 * @arg USART_IT_TC: Transmission complete interrupt.
mbed_official 76:aeb1df146756 1192 * @arg USART_IT_RXNE: Receive Data register not empty interrupt.
mbed_official 76:aeb1df146756 1193 * @arg USART_IT_IDLE: Idle line detection interrupt.
mbed_official 76:aeb1df146756 1194 * @arg USART_IT_PE: Parity Error interrupt.
mbed_official 76:aeb1df146756 1195 * @arg USART_IT_ERR: Error interrupt(Frame error, noise error, overrun error).
mbed_official 76:aeb1df146756 1196 * @param NewState: new state of the specified USARTx interrupts.
mbed_official 76:aeb1df146756 1197 * This parameter can be: ENABLE or DISABLE.
mbed_official 76:aeb1df146756 1198 * @retval None.
mbed_official 76:aeb1df146756 1199 */
mbed_official 76:aeb1df146756 1200 void USART_ITConfig(USART_TypeDef* USARTx, uint16_t USART_IT, FunctionalState NewState)
mbed_official 76:aeb1df146756 1201 {
mbed_official 76:aeb1df146756 1202 uint32_t usartreg = 0x00, itpos = 0x00, itmask = 0x00;
mbed_official 76:aeb1df146756 1203 uint32_t usartxbase = 0x00;
mbed_official 76:aeb1df146756 1204 /* Check the parameters */
mbed_official 76:aeb1df146756 1205 assert_param(IS_USART_ALL_PERIPH(USARTx));
mbed_official 76:aeb1df146756 1206 assert_param(IS_USART_CONFIG_IT(USART_IT));
mbed_official 76:aeb1df146756 1207 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 76:aeb1df146756 1208
mbed_official 76:aeb1df146756 1209 /* The CTS interrupt is not available for UART4 and UART5 */
mbed_official 76:aeb1df146756 1210 if (USART_IT == USART_IT_CTS)
mbed_official 76:aeb1df146756 1211 {
mbed_official 76:aeb1df146756 1212 assert_param(IS_USART_123_PERIPH(USARTx));
mbed_official 76:aeb1df146756 1213 }
mbed_official 76:aeb1df146756 1214
mbed_official 76:aeb1df146756 1215 usartxbase = (uint32_t)USARTx;
mbed_official 76:aeb1df146756 1216
mbed_official 76:aeb1df146756 1217 /* Get the USART register index */
mbed_official 76:aeb1df146756 1218 usartreg = (((uint8_t)USART_IT) >> 0x05);
mbed_official 76:aeb1df146756 1219
mbed_official 76:aeb1df146756 1220 /* Get the interrupt position */
mbed_official 76:aeb1df146756 1221 itpos = USART_IT & IT_MASK;
mbed_official 76:aeb1df146756 1222 itmask = (((uint32_t)0x01) << itpos);
mbed_official 76:aeb1df146756 1223
mbed_official 76:aeb1df146756 1224 if (usartreg == 0x01) /* The IT is in CR1 register */
mbed_official 76:aeb1df146756 1225 {
mbed_official 76:aeb1df146756 1226 usartxbase += 0x0C;
mbed_official 76:aeb1df146756 1227 }
mbed_official 76:aeb1df146756 1228 else if (usartreg == 0x02) /* The IT is in CR2 register */
mbed_official 76:aeb1df146756 1229 {
mbed_official 76:aeb1df146756 1230 usartxbase += 0x10;
mbed_official 76:aeb1df146756 1231 }
mbed_official 76:aeb1df146756 1232 else /* The IT is in CR3 register */
mbed_official 76:aeb1df146756 1233 {
mbed_official 76:aeb1df146756 1234 usartxbase += 0x14;
mbed_official 76:aeb1df146756 1235 }
mbed_official 76:aeb1df146756 1236 if (NewState != DISABLE)
mbed_official 76:aeb1df146756 1237 {
mbed_official 76:aeb1df146756 1238 *(__IO uint32_t*)usartxbase |= itmask;
mbed_official 76:aeb1df146756 1239 }
mbed_official 76:aeb1df146756 1240 else
mbed_official 76:aeb1df146756 1241 {
mbed_official 76:aeb1df146756 1242 *(__IO uint32_t*)usartxbase &= ~itmask;
mbed_official 76:aeb1df146756 1243 }
mbed_official 76:aeb1df146756 1244 }
mbed_official 76:aeb1df146756 1245
mbed_official 76:aeb1df146756 1246 /**
mbed_official 76:aeb1df146756 1247 * @brief Checks whether the specified USART flag is set or not.
mbed_official 76:aeb1df146756 1248 * @param USARTx: Select the USART peripheral.
mbed_official 76:aeb1df146756 1249 * This parameter can be one of the following values:
mbed_official 76:aeb1df146756 1250 * USART1, USART2, USART3, UART4 or UART5.
mbed_official 76:aeb1df146756 1251 * @param USART_FLAG: specifies the flag to check.
mbed_official 76:aeb1df146756 1252 * This parameter can be one of the following values:
mbed_official 76:aeb1df146756 1253 * @arg USART_FLAG_CTS: CTS Change flag (not available for UART4 and UART5).
mbed_official 76:aeb1df146756 1254 * @arg USART_FLAG_LBD: LIN Break detection flag.
mbed_official 76:aeb1df146756 1255 * @arg USART_FLAG_TXE: Transmit data register empty flag.
mbed_official 76:aeb1df146756 1256 * @arg USART_FLAG_TC: Transmission Complete flag.
mbed_official 76:aeb1df146756 1257 * @arg USART_FLAG_RXNE: Receive data register not empty flag.
mbed_official 76:aeb1df146756 1258 * @arg USART_FLAG_IDLE: Idle Line detection flag.
mbed_official 76:aeb1df146756 1259 * @arg USART_FLAG_ORE: OverRun Error flag.
mbed_official 76:aeb1df146756 1260 * @arg USART_FLAG_NE: Noise Error flag.
mbed_official 76:aeb1df146756 1261 * @arg USART_FLAG_FE: Framing Error flag.
mbed_official 76:aeb1df146756 1262 * @arg USART_FLAG_PE: Parity Error flag.
mbed_official 76:aeb1df146756 1263 * @retval The new state of USART_FLAG (SET or RESET).
mbed_official 76:aeb1df146756 1264 */
mbed_official 76:aeb1df146756 1265 FlagStatus USART_GetFlagStatus(USART_TypeDef* USARTx, uint16_t USART_FLAG)
mbed_official 76:aeb1df146756 1266 {
mbed_official 76:aeb1df146756 1267 FlagStatus bitstatus = RESET;
mbed_official 76:aeb1df146756 1268 /* Check the parameters */
mbed_official 76:aeb1df146756 1269 assert_param(IS_USART_ALL_PERIPH(USARTx));
mbed_official 76:aeb1df146756 1270 assert_param(IS_USART_FLAG(USART_FLAG));
mbed_official 76:aeb1df146756 1271
mbed_official 76:aeb1df146756 1272 /* The CTS flag is not available for UART4 and UART5 */
mbed_official 76:aeb1df146756 1273 if (USART_FLAG == USART_FLAG_CTS)
mbed_official 76:aeb1df146756 1274 {
mbed_official 76:aeb1df146756 1275 assert_param(IS_USART_123_PERIPH(USARTx));
mbed_official 76:aeb1df146756 1276 }
mbed_official 76:aeb1df146756 1277
mbed_official 76:aeb1df146756 1278 if ((USARTx->SR & USART_FLAG) != (uint16_t)RESET)
mbed_official 76:aeb1df146756 1279 {
mbed_official 76:aeb1df146756 1280 bitstatus = SET;
mbed_official 76:aeb1df146756 1281 }
mbed_official 76:aeb1df146756 1282 else
mbed_official 76:aeb1df146756 1283 {
mbed_official 76:aeb1df146756 1284 bitstatus = RESET;
mbed_official 76:aeb1df146756 1285 }
mbed_official 76:aeb1df146756 1286 return bitstatus;
mbed_official 76:aeb1df146756 1287 }
mbed_official 76:aeb1df146756 1288
mbed_official 76:aeb1df146756 1289 /**
mbed_official 76:aeb1df146756 1290 * @brief Clears the USARTx's pending flags.
mbed_official 76:aeb1df146756 1291 * @param USARTx: Select the USART peripheral.
mbed_official 76:aeb1df146756 1292 * This parameter can be one of the following values:
mbed_official 76:aeb1df146756 1293 * USART1, USART2, USART3, UART4 or UART5.
mbed_official 76:aeb1df146756 1294 * @param USART_FLAG: specifies the flag to clear.
mbed_official 76:aeb1df146756 1295 * This parameter can be any combination of the following values:
mbed_official 76:aeb1df146756 1296 * @arg USART_FLAG_CTS: CTS Change flag (not available for UART4 and UART5).
mbed_official 76:aeb1df146756 1297 * @arg USART_FLAG_LBD: LIN Break detection flag.
mbed_official 76:aeb1df146756 1298 * @arg USART_FLAG_TC: Transmission Complete flag.
mbed_official 76:aeb1df146756 1299 * @arg USART_FLAG_RXNE: Receive data register not empty flag.
mbed_official 76:aeb1df146756 1300 *
mbed_official 76:aeb1df146756 1301 *
mbed_official 76:aeb1df146756 1302 * @note PE (Parity error), FE (Framing error), NE (Noise error), ORE (OverRun
mbed_official 76:aeb1df146756 1303 * error) and IDLE (Idle line detected) flags are cleared by software
mbed_official 76:aeb1df146756 1304 * sequence: a read operation to USART_SR register (USART_GetFlagStatus())
mbed_official 76:aeb1df146756 1305 * followed by a read operation to USART_DR register (USART_ReceiveData()).
mbed_official 76:aeb1df146756 1306 * @note RXNE flag can be also cleared by a read to the USART_DR register
mbed_official 76:aeb1df146756 1307 * (USART_ReceiveData()).
mbed_official 76:aeb1df146756 1308 * @note TC flag can be also cleared by software sequence: a read operation to
mbed_official 76:aeb1df146756 1309 * USART_SR register (USART_GetFlagStatus()) followed by a write operation
mbed_official 76:aeb1df146756 1310 * to USART_DR register (USART_SendData()).
mbed_official 76:aeb1df146756 1311 * @note TXE flag is cleared only by a write to the USART_DR register
mbed_official 76:aeb1df146756 1312 * (USART_SendData()).
mbed_official 76:aeb1df146756 1313 * @retval None
mbed_official 76:aeb1df146756 1314 */
mbed_official 76:aeb1df146756 1315 void USART_ClearFlag(USART_TypeDef* USARTx, uint16_t USART_FLAG)
mbed_official 76:aeb1df146756 1316 {
mbed_official 76:aeb1df146756 1317 /* Check the parameters */
mbed_official 76:aeb1df146756 1318 assert_param(IS_USART_ALL_PERIPH(USARTx));
mbed_official 76:aeb1df146756 1319 assert_param(IS_USART_CLEAR_FLAG(USART_FLAG));
mbed_official 76:aeb1df146756 1320
mbed_official 76:aeb1df146756 1321 /* The CTS flag is not available for UART4 and UART5 */
mbed_official 76:aeb1df146756 1322 if ((USART_FLAG & USART_FLAG_CTS) == USART_FLAG_CTS)
mbed_official 76:aeb1df146756 1323 {
mbed_official 76:aeb1df146756 1324 assert_param(IS_USART_123_PERIPH(USARTx));
mbed_official 76:aeb1df146756 1325 }
mbed_official 76:aeb1df146756 1326
mbed_official 76:aeb1df146756 1327 USARTx->SR = (uint16_t)~USART_FLAG;
mbed_official 76:aeb1df146756 1328 }
mbed_official 76:aeb1df146756 1329
mbed_official 76:aeb1df146756 1330 /**
mbed_official 76:aeb1df146756 1331 * @brief Checks whether the specified USART interrupt has occurred or not.
mbed_official 76:aeb1df146756 1332 * @param USARTx: Select the USART peripheral.
mbed_official 76:aeb1df146756 1333 * This parameter can be one of the following values:
mbed_official 76:aeb1df146756 1334 * USART1, USART2, USART3, UART4 or UART5.
mbed_official 76:aeb1df146756 1335 * @param USART_IT: specifies the USART interrupt source to check.
mbed_official 76:aeb1df146756 1336 * This parameter can be one of the following values:
mbed_official 76:aeb1df146756 1337 * @arg USART_IT_CTS: CTS change interrupt (not available for UART4 and UART5)
mbed_official 76:aeb1df146756 1338 * @arg USART_IT_LBD: LIN Break detection interrupt
mbed_official 76:aeb1df146756 1339 * @arg USART_IT_TXE: Tansmit Data Register empty interrupt
mbed_official 76:aeb1df146756 1340 * @arg USART_IT_TC: Transmission complete interrupt
mbed_official 76:aeb1df146756 1341 * @arg USART_IT_RXNE: Receive Data register not empty interrupt
mbed_official 76:aeb1df146756 1342 * @arg USART_IT_IDLE: Idle line detection interrupt
mbed_official 76:aeb1df146756 1343 * @arg USART_IT_ORE_RX: OverRun Error interrupt if the RXNEIE bit is set.
mbed_official 76:aeb1df146756 1344 * @arg USART_IT_ORE_ER: OverRun Error interrupt if the EIE bit is set.
mbed_official 76:aeb1df146756 1345 * @arg USART_IT_NE: Noise Error interrupt
mbed_official 76:aeb1df146756 1346 * @arg USART_IT_FE: Framing Error interrupt
mbed_official 76:aeb1df146756 1347 * @arg USART_IT_PE: Parity Error interrupt
mbed_official 76:aeb1df146756 1348 * @retval The new state of USART_IT (SET or RESET).
mbed_official 76:aeb1df146756 1349 */
mbed_official 76:aeb1df146756 1350 ITStatus USART_GetITStatus(USART_TypeDef* USARTx, uint16_t USART_IT)
mbed_official 76:aeb1df146756 1351 {
mbed_official 76:aeb1df146756 1352 uint32_t bitpos = 0x00, itmask = 0x00, usartreg = 0x00;
mbed_official 76:aeb1df146756 1353 ITStatus bitstatus = RESET;
mbed_official 76:aeb1df146756 1354 /* Check the parameters */
mbed_official 76:aeb1df146756 1355 assert_param(IS_USART_ALL_PERIPH(USARTx));
mbed_official 76:aeb1df146756 1356 assert_param(IS_USART_GET_IT(USART_IT));
mbed_official 76:aeb1df146756 1357
mbed_official 76:aeb1df146756 1358 /* The CTS interrupt is not available for UART4 and UART5 */
mbed_official 76:aeb1df146756 1359 if (USART_IT == USART_IT_CTS)
mbed_official 76:aeb1df146756 1360 {
mbed_official 76:aeb1df146756 1361 assert_param(IS_USART_123_PERIPH(USARTx));
mbed_official 76:aeb1df146756 1362 }
mbed_official 76:aeb1df146756 1363
mbed_official 76:aeb1df146756 1364 /* Get the USART register index */
mbed_official 76:aeb1df146756 1365 usartreg = (((uint8_t)USART_IT) >> 0x05);
mbed_official 76:aeb1df146756 1366 /* Get the interrupt position */
mbed_official 76:aeb1df146756 1367 itmask = USART_IT & IT_MASK;
mbed_official 76:aeb1df146756 1368 itmask = (uint32_t)0x01 << itmask;
mbed_official 76:aeb1df146756 1369
mbed_official 76:aeb1df146756 1370 if (usartreg == 0x01) /* The IT is in CR1 register */
mbed_official 76:aeb1df146756 1371 {
mbed_official 76:aeb1df146756 1372 itmask &= USARTx->CR1;
mbed_official 76:aeb1df146756 1373 }
mbed_official 76:aeb1df146756 1374 else if (usartreg == 0x02) /* The IT is in CR2 register */
mbed_official 76:aeb1df146756 1375 {
mbed_official 76:aeb1df146756 1376 itmask &= USARTx->CR2;
mbed_official 76:aeb1df146756 1377 }
mbed_official 76:aeb1df146756 1378 else /* The IT is in CR3 register */
mbed_official 76:aeb1df146756 1379 {
mbed_official 76:aeb1df146756 1380 itmask &= USARTx->CR3;
mbed_official 76:aeb1df146756 1381 }
mbed_official 76:aeb1df146756 1382
mbed_official 76:aeb1df146756 1383 bitpos = USART_IT >> 0x08;
mbed_official 76:aeb1df146756 1384 bitpos = (uint32_t)0x01 << bitpos;
mbed_official 76:aeb1df146756 1385 bitpos &= USARTx->SR;
mbed_official 76:aeb1df146756 1386 if ((itmask != (uint16_t)RESET)&&(bitpos != (uint16_t)RESET))
mbed_official 76:aeb1df146756 1387 {
mbed_official 76:aeb1df146756 1388 bitstatus = SET;
mbed_official 76:aeb1df146756 1389 }
mbed_official 76:aeb1df146756 1390 else
mbed_official 76:aeb1df146756 1391 {
mbed_official 76:aeb1df146756 1392 bitstatus = RESET;
mbed_official 76:aeb1df146756 1393 }
mbed_official 76:aeb1df146756 1394
mbed_official 76:aeb1df146756 1395 return bitstatus;
mbed_official 76:aeb1df146756 1396 }
mbed_official 76:aeb1df146756 1397
mbed_official 76:aeb1df146756 1398 /**
mbed_official 76:aeb1df146756 1399 * @brief Clears the USARTx's interrupt pending bits.
mbed_official 76:aeb1df146756 1400 * @param USARTx: Select the USART peripheral.
mbed_official 76:aeb1df146756 1401 * This parameter can be one of the following values:
mbed_official 76:aeb1df146756 1402 * USART1, USART2, USART3, UART4 or UART5.
mbed_official 76:aeb1df146756 1403 * @param USART_IT: specifies the interrupt pending bit to clear.
mbed_official 76:aeb1df146756 1404 * This parameter can be one of the following values:
mbed_official 76:aeb1df146756 1405 * @arg USART_IT_CTS: CTS change interrupt (not available for UART4 and UART5)
mbed_official 76:aeb1df146756 1406 * @arg USART_IT_LBD: LIN Break detection interrupt
mbed_official 76:aeb1df146756 1407 * @arg USART_IT_TC: Transmission complete interrupt.
mbed_official 76:aeb1df146756 1408 * @arg USART_IT_RXNE: Receive Data register not empty interrupt.
mbed_official 76:aeb1df146756 1409 *
mbed_official 76:aeb1df146756 1410
mbed_official 76:aeb1df146756 1411 * @note PE (Parity error), FE (Framing error), NE (Noise error), ORE (OverRun
mbed_official 76:aeb1df146756 1412 * error) and IDLE (Idle line detected) pending bits are cleared by
mbed_official 76:aeb1df146756 1413 * software sequence: a read operation to USART_SR register
mbed_official 76:aeb1df146756 1414 * (USART_GetITStatus()) followed by a read operation to USART_DR register
mbed_official 76:aeb1df146756 1415 * (USART_ReceiveData()).
mbed_official 76:aeb1df146756 1416 * @note RXNE pending bit can be also cleared by a read to the USART_DR register
mbed_official 76:aeb1df146756 1417 * (USART_ReceiveData()).
mbed_official 76:aeb1df146756 1418 * @note TC pending bit can be also cleared by software sequence: a read
mbed_official 76:aeb1df146756 1419 * operation to USART_SR register (USART_GetITStatus()) followed by a write
mbed_official 76:aeb1df146756 1420 * operation to USART_DR register (USART_SendData()).
mbed_official 76:aeb1df146756 1421 * @note TXE pending bit is cleared only by a write to the USART_DR register
mbed_official 76:aeb1df146756 1422 * (USART_SendData()).
mbed_official 76:aeb1df146756 1423 * @retval None
mbed_official 76:aeb1df146756 1424 */
mbed_official 76:aeb1df146756 1425 void USART_ClearITPendingBit(USART_TypeDef* USARTx, uint16_t USART_IT)
mbed_official 76:aeb1df146756 1426 {
mbed_official 76:aeb1df146756 1427 uint16_t bitpos = 0x00, itmask = 0x00;
mbed_official 76:aeb1df146756 1428 /* Check the parameters */
mbed_official 76:aeb1df146756 1429 assert_param(IS_USART_ALL_PERIPH(USARTx));
mbed_official 76:aeb1df146756 1430 assert_param(IS_USART_CLEAR_IT(USART_IT));
mbed_official 76:aeb1df146756 1431
mbed_official 76:aeb1df146756 1432 /* The CTS interrupt is not available for UART4 and UART5 */
mbed_official 76:aeb1df146756 1433 if (USART_IT == USART_IT_CTS)
mbed_official 76:aeb1df146756 1434 {
mbed_official 76:aeb1df146756 1435 assert_param(IS_USART_123_PERIPH(USARTx));
mbed_official 76:aeb1df146756 1436 }
mbed_official 76:aeb1df146756 1437
mbed_official 76:aeb1df146756 1438 bitpos = USART_IT >> 0x08;
mbed_official 76:aeb1df146756 1439 itmask = ((uint16_t)0x01 << (uint16_t)bitpos);
mbed_official 76:aeb1df146756 1440 USARTx->SR = (uint16_t)~itmask;
mbed_official 76:aeb1df146756 1441 }
mbed_official 76:aeb1df146756 1442
mbed_official 76:aeb1df146756 1443 /**
mbed_official 76:aeb1df146756 1444 * @}
mbed_official 76:aeb1df146756 1445 */
mbed_official 76:aeb1df146756 1446
mbed_official 76:aeb1df146756 1447 /**
mbed_official 76:aeb1df146756 1448 * @}
mbed_official 76:aeb1df146756 1449 */
mbed_official 76:aeb1df146756 1450
mbed_official 76:aeb1df146756 1451 /**
mbed_official 76:aeb1df146756 1452 * @}
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 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/