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