mbed library sources

Dependents:   Encrypted my_mbed lklk CyaSSL_DTLS_Cellular ... more

Superseded

This library was superseded by mbed-dev - https://os.mbed.com/users/mbed_official/code/mbed-dev/.

Development branch of the mbed library sources. This library is kept in synch with the latest changes from the mbed SDK and it is not guaranteed to work.

If you are looking for a stable and tested release, please import one of the official mbed library releases:

Import librarymbed

The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Committer:
mbed_official
Date:
Tue Nov 25 07:15:09 2014 +0000
Revision:
414:4ec4c5b614b0
Parent:
402:09075a3b15e3
Child:
489:119543c9f674
Synchronized with git revision fbc74e874ac089c6cb05add312fb5422be628886

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

Targets: NUCLEOs - Add PeripheralPins files for all nucleo targets

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 52:a51c77007319 1 /* mbed Microcontroller Library
mbed_official 70:c1fbde68b492 2 *******************************************************************************
mbed_official 70:c1fbde68b492 3 * Copyright (c) 2014, STMicroelectronics
mbed_official 70:c1fbde68b492 4 * All rights reserved.
mbed_official 52:a51c77007319 5 *
mbed_official 70:c1fbde68b492 6 * Redistribution and use in source and binary forms, with or without
mbed_official 70:c1fbde68b492 7 * modification, are permitted provided that the following conditions are met:
mbed_official 52:a51c77007319 8 *
mbed_official 70:c1fbde68b492 9 * 1. Redistributions of source code must retain the above copyright notice,
mbed_official 70:c1fbde68b492 10 * this list of conditions and the following disclaimer.
mbed_official 70:c1fbde68b492 11 * 2. Redistributions in binary form must reproduce the above copyright notice,
mbed_official 70:c1fbde68b492 12 * this list of conditions and the following disclaimer in the documentation
mbed_official 70:c1fbde68b492 13 * and/or other materials provided with the distribution.
mbed_official 70:c1fbde68b492 14 * 3. Neither the name of STMicroelectronics nor the names of its contributors
mbed_official 70:c1fbde68b492 15 * may be used to endorse or promote products derived from this software
mbed_official 70:c1fbde68b492 16 * without specific prior written permission.
mbed_official 52:a51c77007319 17 *
mbed_official 70:c1fbde68b492 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
mbed_official 70:c1fbde68b492 19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
mbed_official 70:c1fbde68b492 20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
mbed_official 70:c1fbde68b492 21 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
mbed_official 70:c1fbde68b492 22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
mbed_official 70:c1fbde68b492 23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
mbed_official 70:c1fbde68b492 24 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
mbed_official 70:c1fbde68b492 25 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
mbed_official 70:c1fbde68b492 26 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
mbed_official 70:c1fbde68b492 27 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
mbed_official 70:c1fbde68b492 28 *******************************************************************************
mbed_official 52:a51c77007319 29 */
mbed_official 227:7bd0639b8911 30 #include "mbed_assert.h"
mbed_official 52:a51c77007319 31 #include "serial_api.h"
mbed_official 174:8bb9f3a33240 32
mbed_official 174:8bb9f3a33240 33 #if DEVICE_SERIAL
mbed_official 174:8bb9f3a33240 34
mbed_official 52:a51c77007319 35 #include "cmsis.h"
mbed_official 52:a51c77007319 36 #include "pinmap.h"
mbed_official 52:a51c77007319 37 #include <string.h>
mbed_official 414:4ec4c5b614b0 38 #include "PeripheralPins.h"
mbed_official 52:a51c77007319 39
mbed_official 167:d5744491c362 40 #define UART_NUM (3)
mbed_official 52:a51c77007319 41
mbed_official 167:d5744491c362 42 static uint32_t serial_irq_ids[UART_NUM] = {0, 0, 0};
mbed_official 52:a51c77007319 43
mbed_official 52:a51c77007319 44 static uart_irq_handler irq_handler;
mbed_official 52:a51c77007319 45
mbed_official 52:a51c77007319 46 int stdio_uart_inited = 0;
mbed_official 52:a51c77007319 47 serial_t stdio_uart;
mbed_official 52:a51c77007319 48
mbed_official 402:09075a3b15e3 49 static void init_usart(serial_t *obj)
mbed_official 402:09075a3b15e3 50 {
mbed_official 56:99eb381a3269 51 USART_TypeDef *usart = (USART_TypeDef *)(obj->uart);
mbed_official 52:a51c77007319 52 USART_InitTypeDef USART_InitStructure;
mbed_official 174:8bb9f3a33240 53
mbed_official 56:99eb381a3269 54 USART_Cmd(usart, DISABLE);
mbed_official 56:99eb381a3269 55
mbed_official 167:d5744491c362 56 USART_InitStructure.USART_BaudRate = obj->baudrate;
mbed_official 167:d5744491c362 57 USART_InitStructure.USART_WordLength = obj->databits;
mbed_official 167:d5744491c362 58 USART_InitStructure.USART_StopBits = obj->stopbits;
mbed_official 167:d5744491c362 59 USART_InitStructure.USART_Parity = obj->parity;
mbed_official 56:99eb381a3269 60 USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
mbed_official 242:7074e42da0b2 61
mbed_official 242:7074e42da0b2 62 if (obj->pin_rx == NC) {
mbed_official 242:7074e42da0b2 63 USART_InitStructure.USART_Mode = USART_Mode_Tx;
mbed_official 242:7074e42da0b2 64 } else if (obj->pin_tx == NC) {
mbed_official 242:7074e42da0b2 65 USART_InitStructure.USART_Mode = USART_Mode_Rx;
mbed_official 242:7074e42da0b2 66 } else {
mbed_official 242:7074e42da0b2 67 USART_InitStructure.USART_Mode = USART_Mode_Tx | USART_Mode_Rx;
mbed_official 242:7074e42da0b2 68 }
mbed_official 242:7074e42da0b2 69
mbed_official 56:99eb381a3269 70 USART_Init(usart, &USART_InitStructure);
mbed_official 174:8bb9f3a33240 71
mbed_official 56:99eb381a3269 72 USART_Cmd(usart, ENABLE);
mbed_official 56:99eb381a3269 73 }
mbed_official 56:99eb381a3269 74
mbed_official 402:09075a3b15e3 75 void serial_init(serial_t *obj, PinName tx, PinName rx)
mbed_official 402:09075a3b15e3 76 {
mbed_official 52:a51c77007319 77 // Determine the UART to use (UART_1, UART_2, ...)
mbed_official 52:a51c77007319 78 UARTName uart_tx = (UARTName)pinmap_peripheral(tx, PinMap_UART_TX);
mbed_official 52:a51c77007319 79 UARTName uart_rx = (UARTName)pinmap_peripheral(rx, PinMap_UART_RX);
mbed_official 174:8bb9f3a33240 80
mbed_official 52:a51c77007319 81 // Get the peripheral name (UART_1, UART_2, ...) from the pin and assign it to the object
mbed_official 52:a51c77007319 82 obj->uart = (UARTName)pinmap_merge(uart_tx, uart_rx);
mbed_official 227:7bd0639b8911 83 MBED_ASSERT(obj->uart != (UARTName)NC);
mbed_official 56:99eb381a3269 84
mbed_official 52:a51c77007319 85 // Enable USART clock
mbed_official 52:a51c77007319 86 if (obj->uart == UART_1) {
mbed_official 174:8bb9f3a33240 87 RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
mbed_official 215:83cf97a28428 88 obj->index = 0;
mbed_official 52:a51c77007319 89 }
mbed_official 52:a51c77007319 90 if (obj->uart == UART_2) {
mbed_official 174:8bb9f3a33240 91 RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
mbed_official 215:83cf97a28428 92 obj->index = 1;
mbed_official 52:a51c77007319 93 }
mbed_official 167:d5744491c362 94 if (obj->uart == UART_3) {
mbed_official 174:8bb9f3a33240 95 RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);
mbed_official 215:83cf97a28428 96 obj->index = 2;
mbed_official 167:d5744491c362 97 }
mbed_official 174:8bb9f3a33240 98
mbed_official 52:a51c77007319 99 // Configure the UART pins
mbed_official 52:a51c77007319 100 pinmap_pinout(tx, PinMap_UART_TX);
mbed_official 52:a51c77007319 101 pinmap_pinout(rx, PinMap_UART_RX);
mbed_official 52:a51c77007319 102
mbed_official 52:a51c77007319 103 // Configure UART
mbed_official 52:a51c77007319 104 obj->baudrate = 9600;
mbed_official 52:a51c77007319 105 obj->databits = USART_WordLength_8b;
mbed_official 52:a51c77007319 106 obj->stopbits = USART_StopBits_1;
mbed_official 174:8bb9f3a33240 107 obj->parity = USART_Parity_No;
mbed_official 52:a51c77007319 108
mbed_official 208:4557f4bb2dd5 109 obj->pin_tx = tx;
mbed_official 208:4557f4bb2dd5 110 obj->pin_rx = rx;
mbed_official 208:4557f4bb2dd5 111
mbed_official 56:99eb381a3269 112 init_usart(obj);
mbed_official 52:a51c77007319 113
mbed_official 52:a51c77007319 114 // For stdio management
mbed_official 52:a51c77007319 115 if (obj->uart == STDIO_UART) {
mbed_official 52:a51c77007319 116 stdio_uart_inited = 1;
mbed_official 52:a51c77007319 117 memcpy(&stdio_uart, obj, sizeof(serial_t));
mbed_official 52:a51c77007319 118 }
mbed_official 52:a51c77007319 119 }
mbed_official 52:a51c77007319 120
mbed_official 402:09075a3b15e3 121 void serial_free(serial_t *obj)
mbed_official 402:09075a3b15e3 122 {
mbed_official 208:4557f4bb2dd5 123 // Reset UART and disable clock
mbed_official 208:4557f4bb2dd5 124 if (obj->uart == UART_1) {
mbed_official 208:4557f4bb2dd5 125 RCC_APB2PeriphResetCmd(RCC_APB2Periph_USART1, ENABLE);
mbed_official 208:4557f4bb2dd5 126 RCC_APB2PeriphResetCmd(RCC_APB2Periph_USART1, DISABLE);
mbed_official 208:4557f4bb2dd5 127 RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, DISABLE);
mbed_official 208:4557f4bb2dd5 128 }
mbed_official 208:4557f4bb2dd5 129 if (obj->uart == UART_2) {
mbed_official 208:4557f4bb2dd5 130 RCC_APB1PeriphResetCmd(RCC_APB1Periph_USART2, ENABLE);
mbed_official 208:4557f4bb2dd5 131 RCC_APB1PeriphResetCmd(RCC_APB1Periph_USART2, DISABLE);
mbed_official 208:4557f4bb2dd5 132 RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, DISABLE);
mbed_official 208:4557f4bb2dd5 133 }
mbed_official 208:4557f4bb2dd5 134 if (obj->uart == UART_3) {
mbed_official 208:4557f4bb2dd5 135 RCC_APB1PeriphResetCmd(RCC_APB1Periph_USART3, ENABLE);
mbed_official 208:4557f4bb2dd5 136 RCC_APB1PeriphResetCmd(RCC_APB1Periph_USART3, DISABLE);
mbed_official 208:4557f4bb2dd5 137 RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, DISABLE);
mbed_official 208:4557f4bb2dd5 138 }
mbed_official 208:4557f4bb2dd5 139
mbed_official 208:4557f4bb2dd5 140 // Configure GPIOs
mbed_official 208:4557f4bb2dd5 141 pin_function(obj->pin_tx, STM_PIN_DATA(GPIO_Mode_IN_FLOATING, 0));
mbed_official 208:4557f4bb2dd5 142 pin_function(obj->pin_rx, STM_PIN_DATA(GPIO_Mode_IN_FLOATING, 0));
mbed_official 208:4557f4bb2dd5 143
mbed_official 52:a51c77007319 144 serial_irq_ids[obj->index] = 0;
mbed_official 52:a51c77007319 145 }
mbed_official 52:a51c77007319 146
mbed_official 402:09075a3b15e3 147 void serial_baud(serial_t *obj, int baudrate)
mbed_official 402:09075a3b15e3 148 {
mbed_official 52:a51c77007319 149 obj->baudrate = baudrate;
mbed_official 56:99eb381a3269 150 init_usart(obj);
mbed_official 52:a51c77007319 151 }
mbed_official 52:a51c77007319 152
mbed_official 402:09075a3b15e3 153 void serial_format(serial_t *obj, int data_bits, SerialParity parity, int stop_bits)
mbed_official 402:09075a3b15e3 154 {
mbed_official 242:7074e42da0b2 155 if (data_bits == 9) {
mbed_official 242:7074e42da0b2 156 obj->databits = USART_WordLength_9b;
mbed_official 242:7074e42da0b2 157 } else {
mbed_official 52:a51c77007319 158 obj->databits = USART_WordLength_8b;
mbed_official 52:a51c77007319 159 }
mbed_official 52:a51c77007319 160
mbed_official 52:a51c77007319 161 switch (parity) {
mbed_official 174:8bb9f3a33240 162 case ParityOdd:
mbed_official 174:8bb9f3a33240 163 case ParityForced0:
mbed_official 174:8bb9f3a33240 164 obj->parity = USART_Parity_Odd;
mbed_official 174:8bb9f3a33240 165 break;
mbed_official 174:8bb9f3a33240 166 case ParityEven:
mbed_official 174:8bb9f3a33240 167 case ParityForced1:
mbed_official 174:8bb9f3a33240 168 obj->parity = USART_Parity_Even;
mbed_official 174:8bb9f3a33240 169 break;
mbed_official 174:8bb9f3a33240 170 default: // ParityNone
mbed_official 174:8bb9f3a33240 171 obj->parity = USART_Parity_No;
mbed_official 174:8bb9f3a33240 172 break;
mbed_official 52:a51c77007319 173 }
mbed_official 174:8bb9f3a33240 174
mbed_official 52:a51c77007319 175 if (stop_bits == 2) {
mbed_official 52:a51c77007319 176 obj->stopbits = USART_StopBits_2;
mbed_official 174:8bb9f3a33240 177 } else {
mbed_official 52:a51c77007319 178 obj->stopbits = USART_StopBits_1;
mbed_official 52:a51c77007319 179 }
mbed_official 52:a51c77007319 180
mbed_official 56:99eb381a3269 181 init_usart(obj);
mbed_official 52:a51c77007319 182 }
mbed_official 52:a51c77007319 183
mbed_official 52:a51c77007319 184 /******************************************************************************
mbed_official 52:a51c77007319 185 * INTERRUPTS HANDLING
mbed_official 52:a51c77007319 186 ******************************************************************************/
mbed_official 52:a51c77007319 187
mbed_official 52:a51c77007319 188 // not api
mbed_official 402:09075a3b15e3 189 static void uart_irq(USART_TypeDef* usart, int id)
mbed_official 402:09075a3b15e3 190 {
mbed_official 55:3b765ca737a5 191 if (serial_irq_ids[id] != 0) {
mbed_official 55:3b765ca737a5 192 if (USART_GetITStatus(usart, USART_IT_TC) != RESET) {
mbed_official 55:3b765ca737a5 193 irq_handler(serial_irq_ids[id], TxIrq);
mbed_official 55:3b765ca737a5 194 USART_ClearITPendingBit(usart, USART_IT_TC);
mbed_official 52:a51c77007319 195 }
mbed_official 52:a51c77007319 196 if (USART_GetITStatus(usart, USART_IT_RXNE) != RESET) {
mbed_official 55:3b765ca737a5 197 irq_handler(serial_irq_ids[id], RxIrq);
mbed_official 55:3b765ca737a5 198 USART_ClearITPendingBit(usart, USART_IT_RXNE);
mbed_official 52:a51c77007319 199 }
mbed_official 52:a51c77007319 200 }
mbed_official 52:a51c77007319 201 }
mbed_official 52:a51c77007319 202
mbed_official 402:09075a3b15e3 203 static void uart1_irq(void)
mbed_official 402:09075a3b15e3 204 {
mbed_official 167:d5744491c362 205 uart_irq((USART_TypeDef*)UART_1, 0);
mbed_official 167:d5744491c362 206 }
mbed_official 402:09075a3b15e3 207 static void uart2_irq(void)
mbed_official 402:09075a3b15e3 208 {
mbed_official 167:d5744491c362 209 uart_irq((USART_TypeDef*)UART_2, 1);
mbed_official 167:d5744491c362 210 }
mbed_official 402:09075a3b15e3 211 static void uart3_irq(void)
mbed_official 402:09075a3b15e3 212 {
mbed_official 167:d5744491c362 213 uart_irq((USART_TypeDef*)UART_3, 2);
mbed_official 167:d5744491c362 214 }
mbed_official 52:a51c77007319 215
mbed_official 402:09075a3b15e3 216 void serial_irq_handler(serial_t *obj, uart_irq_handler handler, uint32_t id)
mbed_official 402:09075a3b15e3 217 {
mbed_official 52:a51c77007319 218 irq_handler = handler;
mbed_official 52:a51c77007319 219 serial_irq_ids[obj->index] = id;
mbed_official 52:a51c77007319 220 }
mbed_official 52:a51c77007319 221
mbed_official 402:09075a3b15e3 222 void serial_irq_set(serial_t *obj, SerialIrq irq, uint32_t enable)
mbed_official 402:09075a3b15e3 223 {
mbed_official 52:a51c77007319 224 IRQn_Type irq_n = (IRQn_Type)0;
mbed_official 52:a51c77007319 225 uint32_t vector = 0;
mbed_official 52:a51c77007319 226 USART_TypeDef *usart = (USART_TypeDef *)(obj->uart);
mbed_official 52:a51c77007319 227
mbed_official 52:a51c77007319 228 if (obj->uart == UART_1) {
mbed_official 174:8bb9f3a33240 229 irq_n = USART1_IRQn;
mbed_official 174:8bb9f3a33240 230 vector = (uint32_t)&uart1_irq;
mbed_official 52:a51c77007319 231 }
mbed_official 174:8bb9f3a33240 232
mbed_official 52:a51c77007319 233 if (obj->uart == UART_2) {
mbed_official 174:8bb9f3a33240 234 irq_n = USART2_IRQn;
mbed_official 174:8bb9f3a33240 235 vector = (uint32_t)&uart2_irq;
mbed_official 52:a51c77007319 236 }
mbed_official 167:d5744491c362 237
mbed_official 167:d5744491c362 238 if (obj->uart == UART_3) {
mbed_official 174:8bb9f3a33240 239 irq_n = USART3_IRQn;
mbed_official 174:8bb9f3a33240 240 vector = (uint32_t)&uart3_irq;
mbed_official 167:d5744491c362 241 }
mbed_official 174:8bb9f3a33240 242
mbed_official 52:a51c77007319 243 if (enable) {
mbed_official 174:8bb9f3a33240 244
mbed_official 52:a51c77007319 245 if (irq == RxIrq) {
mbed_official 52:a51c77007319 246 USART_ITConfig(usart, USART_IT_RXNE, ENABLE);
mbed_official 174:8bb9f3a33240 247 } else { // TxIrq
mbed_official 55:3b765ca737a5 248 USART_ITConfig(usart, USART_IT_TC, ENABLE);
mbed_official 174:8bb9f3a33240 249 }
mbed_official 174:8bb9f3a33240 250
mbed_official 52:a51c77007319 251 NVIC_SetVector(irq_n, vector);
mbed_official 52:a51c77007319 252 NVIC_EnableIRQ(irq_n);
mbed_official 174:8bb9f3a33240 253
mbed_official 52:a51c77007319 254 } else { // disable
mbed_official 174:8bb9f3a33240 255
mbed_official 52:a51c77007319 256 int all_disabled = 0;
mbed_official 174:8bb9f3a33240 257
mbed_official 52:a51c77007319 258 if (irq == RxIrq) {
mbed_official 52:a51c77007319 259 USART_ITConfig(usart, USART_IT_RXNE, DISABLE);
mbed_official 52:a51c77007319 260 // Check if TxIrq is disabled too
mbed_official 52:a51c77007319 261 if ((usart->CR1 & USART_CR1_TXEIE) == 0) all_disabled = 1;
mbed_official 174:8bb9f3a33240 262 } else { // TxIrq
mbed_official 52:a51c77007319 263 USART_ITConfig(usart, USART_IT_TXE, DISABLE);
mbed_official 52:a51c77007319 264 // Check if RxIrq is disabled too
mbed_official 174:8bb9f3a33240 265 if ((usart->CR1 & USART_CR1_RXNEIE) == 0) all_disabled = 1;
mbed_official 52:a51c77007319 266 }
mbed_official 174:8bb9f3a33240 267
mbed_official 52:a51c77007319 268 if (all_disabled) NVIC_DisableIRQ(irq_n);
mbed_official 174:8bb9f3a33240 269
mbed_official 174:8bb9f3a33240 270 }
mbed_official 52:a51c77007319 271 }
mbed_official 52:a51c77007319 272
mbed_official 52:a51c77007319 273 /******************************************************************************
mbed_official 52:a51c77007319 274 * READ/WRITE
mbed_official 52:a51c77007319 275 ******************************************************************************/
mbed_official 52:a51c77007319 276
mbed_official 402:09075a3b15e3 277 int serial_getc(serial_t *obj)
mbed_official 402:09075a3b15e3 278 {
mbed_official 52:a51c77007319 279 USART_TypeDef *usart = (USART_TypeDef *)(obj->uart);
mbed_official 52:a51c77007319 280 while (!serial_readable(obj));
mbed_official 52:a51c77007319 281 return (int)(USART_ReceiveData(usart));
mbed_official 52:a51c77007319 282 }
mbed_official 52:a51c77007319 283
mbed_official 402:09075a3b15e3 284 void serial_putc(serial_t *obj, int c)
mbed_official 402:09075a3b15e3 285 {
mbed_official 52:a51c77007319 286 USART_TypeDef *usart = (USART_TypeDef *)(obj->uart);
mbed_official 52:a51c77007319 287 while (!serial_writable(obj));
mbed_official 52:a51c77007319 288 USART_SendData(usart, (uint16_t)c);
mbed_official 52:a51c77007319 289 }
mbed_official 52:a51c77007319 290
mbed_official 402:09075a3b15e3 291 int serial_readable(serial_t *obj)
mbed_official 402:09075a3b15e3 292 {
mbed_official 52:a51c77007319 293 int status;
mbed_official 52:a51c77007319 294 USART_TypeDef *usart = (USART_TypeDef *)(obj->uart);
mbed_official 52:a51c77007319 295 // Check if data is received
mbed_official 52:a51c77007319 296 status = ((USART_GetFlagStatus(usart, USART_FLAG_RXNE) != RESET) ? 1 : 0);
mbed_official 52:a51c77007319 297 return status;
mbed_official 52:a51c77007319 298 }
mbed_official 52:a51c77007319 299
mbed_official 402:09075a3b15e3 300 int serial_writable(serial_t *obj)
mbed_official 402:09075a3b15e3 301 {
mbed_official 52:a51c77007319 302 int status;
mbed_official 52:a51c77007319 303 USART_TypeDef *usart = (USART_TypeDef *)(obj->uart);
mbed_official 52:a51c77007319 304 // Check if data is transmitted
mbed_official 52:a51c77007319 305 status = ((USART_GetFlagStatus(usart, USART_FLAG_TXE) != RESET) ? 1 : 0);
mbed_official 52:a51c77007319 306 return status;
mbed_official 52:a51c77007319 307 }
mbed_official 52:a51c77007319 308
mbed_official 402:09075a3b15e3 309 void serial_clear(serial_t *obj)
mbed_official 402:09075a3b15e3 310 {
mbed_official 52:a51c77007319 311 USART_TypeDef *usart = (USART_TypeDef *)(obj->uart);
mbed_official 52:a51c77007319 312 USART_ClearFlag(usart, USART_FLAG_TXE);
mbed_official 52:a51c77007319 313 USART_ClearFlag(usart, USART_FLAG_RXNE);
mbed_official 52:a51c77007319 314 }
mbed_official 52:a51c77007319 315
mbed_official 402:09075a3b15e3 316 void serial_pinout_tx(PinName tx)
mbed_official 402:09075a3b15e3 317 {
mbed_official 52:a51c77007319 318 pinmap_pinout(tx, PinMap_UART_TX);
mbed_official 52:a51c77007319 319 }
mbed_official 52:a51c77007319 320
mbed_official 402:09075a3b15e3 321 void serial_break_set(serial_t *obj)
mbed_official 402:09075a3b15e3 322 {
mbed_official 52:a51c77007319 323 USART_TypeDef *usart = (USART_TypeDef *)(obj->uart);
mbed_official 52:a51c77007319 324 USART_SendBreak(usart);
mbed_official 52:a51c77007319 325 }
mbed_official 52:a51c77007319 326
mbed_official 402:09075a3b15e3 327 void serial_break_clear(serial_t *obj)
mbed_official 402:09075a3b15e3 328 {
mbed_official 52:a51c77007319 329 }
mbed_official 174:8bb9f3a33240 330
mbed_official 174:8bb9f3a33240 331 #endif