long dao / mbed-src

Fork of mbed-src by mbed official

Committer:
mbed_official
Date:
Thu Oct 09 08:15:07 2014 +0100
Revision:
340:28d1f895c6fe
Parent:
339:40bd4701f3e2
Child:
402:09075a3b15e3
Synchronized with git revision b5a4c8e80393336b2656fb29ab46d405d3068602

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

HAL: nrf51822 - Few fixes for PWM and Serial

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 76:aeb1df146756 1 /* mbed Microcontroller Library
mbed_official 76:aeb1df146756 2 *******************************************************************************
mbed_official 76:aeb1df146756 3 * Copyright (c) 2014, STMicroelectronics
mbed_official 76:aeb1df146756 4 * All rights reserved.
mbed_official 76:aeb1df146756 5 *
mbed_official 76:aeb1df146756 6 * Redistribution and use in source and binary forms, with or without
mbed_official 76:aeb1df146756 7 * modification, are permitted provided that the following conditions are met:
mbed_official 76:aeb1df146756 8 *
mbed_official 76:aeb1df146756 9 * 1. Redistributions of source code must retain the above copyright notice,
mbed_official 76:aeb1df146756 10 * this list of conditions and the following disclaimer.
mbed_official 76:aeb1df146756 11 * 2. Redistributions in binary form must reproduce the above copyright notice,
mbed_official 76:aeb1df146756 12 * this list of conditions and the following disclaimer in the documentation
mbed_official 76:aeb1df146756 13 * and/or other materials provided with the distribution.
mbed_official 76:aeb1df146756 14 * 3. Neither the name of STMicroelectronics nor the names of its contributors
mbed_official 76:aeb1df146756 15 * may be used to endorse or promote products derived from this software
mbed_official 76:aeb1df146756 16 * without specific prior written permission.
mbed_official 76:aeb1df146756 17 *
mbed_official 76:aeb1df146756 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
mbed_official 76:aeb1df146756 19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
mbed_official 76:aeb1df146756 20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
mbed_official 76:aeb1df146756 21 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
mbed_official 76:aeb1df146756 22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
mbed_official 76:aeb1df146756 23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
mbed_official 76:aeb1df146756 24 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
mbed_official 76:aeb1df146756 25 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
mbed_official 76:aeb1df146756 26 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
mbed_official 76:aeb1df146756 27 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
mbed_official 76:aeb1df146756 28 *******************************************************************************
mbed_official 76:aeb1df146756 29 */
mbed_official 227:7bd0639b8911 30 #include "mbed_assert.h"
mbed_official 76:aeb1df146756 31 #include "serial_api.h"
mbed_official 166:cb4253f91ada 32
mbed_official 166:cb4253f91ada 33 #if DEVICE_SERIAL
mbed_official 166:cb4253f91ada 34
mbed_official 76:aeb1df146756 35 #include "cmsis.h"
mbed_official 76:aeb1df146756 36 #include "pinmap.h"
mbed_official 76:aeb1df146756 37 #include <string.h>
mbed_official 76:aeb1df146756 38
mbed_official 76:aeb1df146756 39 static const PinMap PinMap_UART_TX[] = {
mbed_official 340:28d1f895c6fe 40 {PA_2, UART_2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_USART2)},
mbed_official 340:28d1f895c6fe 41 {PA_9, UART_1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_USART1)},
mbed_official 340:28d1f895c6fe 42 {PB_6, UART_1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF0_USART1)},
mbed_official 76:aeb1df146756 43 {NC, NC, 0}
mbed_official 76:aeb1df146756 44 };
mbed_official 76:aeb1df146756 45
mbed_official 76:aeb1df146756 46 static const PinMap PinMap_UART_RX[] = {
mbed_official 340:28d1f895c6fe 47 {PA_3, UART_2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_USART2)},
mbed_official 340:28d1f895c6fe 48 {PA_10, UART_1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_USART1)},
mbed_official 340:28d1f895c6fe 49 {PA_15, UART_2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_USART2)},
mbed_official 340:28d1f895c6fe 50 {PB_7, UART_1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF0_USART1)},
mbed_official 76:aeb1df146756 51 {NC, NC, 0}
mbed_official 76:aeb1df146756 52 };
mbed_official 76:aeb1df146756 53
mbed_official 76:aeb1df146756 54 #define UART_NUM (2)
mbed_official 76:aeb1df146756 55
mbed_official 340:28d1f895c6fe 56 static uint32_t serial_irq_ids[UART_NUM] = {0, 0};
mbed_official 76:aeb1df146756 57
mbed_official 76:aeb1df146756 58 static uart_irq_handler irq_handler;
mbed_official 76:aeb1df146756 59
mbed_official 340:28d1f895c6fe 60 UART_HandleTypeDef UartHandle;
mbed_official 340:28d1f895c6fe 61
mbed_official 76:aeb1df146756 62 int stdio_uart_inited = 0;
mbed_official 76:aeb1df146756 63 serial_t stdio_uart;
mbed_official 76:aeb1df146756 64
mbed_official 340:28d1f895c6fe 65 static void init_uart(serial_t *obj) {
mbed_official 340:28d1f895c6fe 66 UartHandle.Instance = (USART_TypeDef *)(obj->uart);
mbed_official 76:aeb1df146756 67
mbed_official 340:28d1f895c6fe 68 UartHandle.Init.BaudRate = obj->baudrate;
mbed_official 340:28d1f895c6fe 69 UartHandle.Init.WordLength = obj->databits;
mbed_official 340:28d1f895c6fe 70 UartHandle.Init.StopBits = obj->stopbits;
mbed_official 340:28d1f895c6fe 71 UartHandle.Init.Parity = obj->parity;
mbed_official 340:28d1f895c6fe 72 UartHandle.Init.HwFlowCtl = UART_HWCONTROL_NONE;
mbed_official 242:7074e42da0b2 73
mbed_official 242:7074e42da0b2 74 if (obj->pin_rx == NC) {
mbed_official 340:28d1f895c6fe 75 UartHandle.Init.Mode = UART_MODE_TX;
mbed_official 242:7074e42da0b2 76 } else if (obj->pin_tx == NC) {
mbed_official 340:28d1f895c6fe 77 UartHandle.Init.Mode = UART_MODE_RX;
mbed_official 242:7074e42da0b2 78 } else {
mbed_official 340:28d1f895c6fe 79 UartHandle.Init.Mode = UART_MODE_TX_RX;
mbed_official 242:7074e42da0b2 80 }
mbed_official 242:7074e42da0b2 81
mbed_official 340:28d1f895c6fe 82 // Disable the reception overrun detection
mbed_official 340:28d1f895c6fe 83 UartHandle.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_RXOVERRUNDISABLE_INIT;
mbed_official 340:28d1f895c6fe 84 UartHandle.AdvancedInit.OverrunDisable = UART_ADVFEATURE_OVERRUN_DISABLE;
mbed_official 340:28d1f895c6fe 85
mbed_official 340:28d1f895c6fe 86 HAL_UART_Init(&UartHandle);
mbed_official 76:aeb1df146756 87 }
mbed_official 76:aeb1df146756 88
mbed_official 216:577900467c9e 89 void serial_init(serial_t *obj, PinName tx, PinName rx) {
mbed_official 76:aeb1df146756 90 // Determine the UART to use (UART_1, UART_2, ...)
mbed_official 76:aeb1df146756 91 UARTName uart_tx = (UARTName)pinmap_peripheral(tx, PinMap_UART_TX);
mbed_official 76:aeb1df146756 92 UARTName uart_rx = (UARTName)pinmap_peripheral(rx, PinMap_UART_RX);
mbed_official 216:577900467c9e 93
mbed_official 76:aeb1df146756 94 // Get the peripheral name (UART_1, UART_2, ...) from the pin and assign it to the object
mbed_official 76:aeb1df146756 95 obj->uart = (UARTName)pinmap_merge(uart_tx, uart_rx);
mbed_official 227:7bd0639b8911 96 MBED_ASSERT(obj->uart != (UARTName)NC);
mbed_official 76:aeb1df146756 97
mbed_official 76:aeb1df146756 98 // Enable USART clock
mbed_official 76:aeb1df146756 99 if (obj->uart == UART_1) {
mbed_official 340:28d1f895c6fe 100 __USART1_CLK_ENABLE();
mbed_official 216:577900467c9e 101 obj->index = 0;
mbed_official 76:aeb1df146756 102 }
mbed_official 76:aeb1df146756 103 if (obj->uart == UART_2) {
mbed_official 340:28d1f895c6fe 104 __USART2_CLK_ENABLE();
mbed_official 216:577900467c9e 105 obj->index = 1;
mbed_official 76:aeb1df146756 106 }
mbed_official 216:577900467c9e 107
mbed_official 76:aeb1df146756 108 // Configure the UART pins
mbed_official 76:aeb1df146756 109 pinmap_pinout(tx, PinMap_UART_TX);
mbed_official 76:aeb1df146756 110 pinmap_pinout(rx, PinMap_UART_RX);
mbed_official 340:28d1f895c6fe 111 pin_mode(tx, PullUp);
mbed_official 340:28d1f895c6fe 112 pin_mode(rx, PullUp);
mbed_official 77:b5886236e6f0 113
mbed_official 76:aeb1df146756 114 // Configure UART
mbed_official 76:aeb1df146756 115 obj->baudrate = 9600;
mbed_official 340:28d1f895c6fe 116 obj->databits = UART_WORDLENGTH_8B;
mbed_official 340:28d1f895c6fe 117 obj->stopbits = UART_STOPBITS_1;
mbed_official 340:28d1f895c6fe 118 obj->parity = UART_PARITY_NONE;
mbed_official 216:577900467c9e 119
mbed_official 216:577900467c9e 120 obj->pin_tx = tx;
mbed_official 216:577900467c9e 121 obj->pin_rx = rx;
mbed_official 76:aeb1df146756 122
mbed_official 340:28d1f895c6fe 123 init_uart(obj);
mbed_official 76:aeb1df146756 124
mbed_official 76:aeb1df146756 125 // For stdio management
mbed_official 76:aeb1df146756 126 if (obj->uart == STDIO_UART) {
mbed_official 76:aeb1df146756 127 stdio_uart_inited = 1;
mbed_official 76:aeb1df146756 128 memcpy(&stdio_uart, obj, sizeof(serial_t));
mbed_official 76:aeb1df146756 129 }
mbed_official 76:aeb1df146756 130 }
mbed_official 76:aeb1df146756 131
mbed_official 76:aeb1df146756 132 void serial_free(serial_t *obj) {
mbed_official 216:577900467c9e 133 // Reset UART and disable clock
mbed_official 216:577900467c9e 134 if (obj->uart == UART_1) {
mbed_official 340:28d1f895c6fe 135 __USART1_FORCE_RESET();
mbed_official 340:28d1f895c6fe 136 __USART1_RELEASE_RESET();
mbed_official 340:28d1f895c6fe 137 __USART1_CLK_DISABLE();
mbed_official 216:577900467c9e 138 }
mbed_official 216:577900467c9e 139 if (obj->uart == UART_2) {
mbed_official 340:28d1f895c6fe 140 __USART2_FORCE_RESET();
mbed_official 340:28d1f895c6fe 141 __USART2_RELEASE_RESET();
mbed_official 340:28d1f895c6fe 142 __USART2_CLK_DISABLE();
mbed_official 216:577900467c9e 143 }
mbed_official 216:577900467c9e 144
mbed_official 216:577900467c9e 145 // Configure GPIOs
mbed_official 340:28d1f895c6fe 146 pin_function(obj->pin_tx, STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, 0));
mbed_official 340:28d1f895c6fe 147 pin_function(obj->pin_rx, STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, 0));
mbed_official 216:577900467c9e 148
mbed_official 76:aeb1df146756 149 serial_irq_ids[obj->index] = 0;
mbed_official 76:aeb1df146756 150 }
mbed_official 76:aeb1df146756 151
mbed_official 76:aeb1df146756 152 void serial_baud(serial_t *obj, int baudrate) {
mbed_official 76:aeb1df146756 153 obj->baudrate = baudrate;
mbed_official 340:28d1f895c6fe 154 init_uart(obj);
mbed_official 76:aeb1df146756 155 }
mbed_official 76:aeb1df146756 156
mbed_official 76:aeb1df146756 157 void serial_format(serial_t *obj, int data_bits, SerialParity parity, int stop_bits) {
mbed_official 242:7074e42da0b2 158 if (data_bits == 9) {
mbed_official 340:28d1f895c6fe 159 obj->databits = UART_WORDLENGTH_9B;
mbed_official 242:7074e42da0b2 160 } else {
mbed_official 340:28d1f895c6fe 161 obj->databits = UART_WORDLENGTH_8B;
mbed_official 76:aeb1df146756 162 }
mbed_official 76:aeb1df146756 163
mbed_official 76:aeb1df146756 164 switch (parity) {
mbed_official 216:577900467c9e 165 case ParityOdd:
mbed_official 216:577900467c9e 166 case ParityForced0:
mbed_official 340:28d1f895c6fe 167 obj->parity = UART_PARITY_ODD;
mbed_official 216:577900467c9e 168 break;
mbed_official 216:577900467c9e 169 case ParityEven:
mbed_official 216:577900467c9e 170 case ParityForced1:
mbed_official 340:28d1f895c6fe 171 obj->parity = UART_PARITY_EVEN;
mbed_official 216:577900467c9e 172 break;
mbed_official 216:577900467c9e 173 default: // ParityNone
mbed_official 340:28d1f895c6fe 174 obj->parity = UART_PARITY_NONE;
mbed_official 216:577900467c9e 175 break;
mbed_official 76:aeb1df146756 176 }
mbed_official 216:577900467c9e 177
mbed_official 76:aeb1df146756 178 if (stop_bits == 2) {
mbed_official 340:28d1f895c6fe 179 obj->stopbits = UART_STOPBITS_2;
mbed_official 216:577900467c9e 180 } else {
mbed_official 340:28d1f895c6fe 181 obj->stopbits = UART_STOPBITS_1;
mbed_official 76:aeb1df146756 182 }
mbed_official 76:aeb1df146756 183
mbed_official 340:28d1f895c6fe 184 init_uart(obj);
mbed_official 76:aeb1df146756 185 }
mbed_official 76:aeb1df146756 186
mbed_official 76:aeb1df146756 187 /******************************************************************************
mbed_official 76:aeb1df146756 188 * INTERRUPTS HANDLING
mbed_official 76:aeb1df146756 189 ******************************************************************************/
mbed_official 76:aeb1df146756 190
mbed_official 340:28d1f895c6fe 191 static void uart_irq(UARTName name, int id) {
mbed_official 340:28d1f895c6fe 192 UartHandle.Instance = (USART_TypeDef *)name;
mbed_official 76:aeb1df146756 193 if (serial_irq_ids[id] != 0) {
mbed_official 340:28d1f895c6fe 194 if (__HAL_UART_GET_FLAG(&UartHandle, UART_FLAG_TC) != RESET) {
mbed_official 76:aeb1df146756 195 irq_handler(serial_irq_ids[id], TxIrq);
mbed_official 340:28d1f895c6fe 196 __HAL_UART_CLEAR_IT(&UartHandle, UART_FLAG_TC);
mbed_official 76:aeb1df146756 197 }
mbed_official 340:28d1f895c6fe 198 if (__HAL_UART_GET_FLAG(&UartHandle, UART_FLAG_RXNE) != RESET) {
mbed_official 76:aeb1df146756 199 irq_handler(serial_irq_ids[id], RxIrq);
mbed_official 340:28d1f895c6fe 200 volatile uint32_t tmpval = UartHandle.Instance->RDR; // Clear RXNE bit
mbed_official 76:aeb1df146756 201 }
mbed_official 76:aeb1df146756 202 }
mbed_official 76:aeb1df146756 203 }
mbed_official 76:aeb1df146756 204
mbed_official 216:577900467c9e 205 static void uart1_irq(void) {
mbed_official 340:28d1f895c6fe 206 uart_irq(UART_1, 0);
mbed_official 216:577900467c9e 207 }
mbed_official 340:28d1f895c6fe 208
mbed_official 216:577900467c9e 209 static void uart2_irq(void) {
mbed_official 340:28d1f895c6fe 210 uart_irq(UART_2, 1);
mbed_official 216:577900467c9e 211 }
mbed_official 76:aeb1df146756 212
mbed_official 76:aeb1df146756 213 void serial_irq_handler(serial_t *obj, uart_irq_handler handler, uint32_t id) {
mbed_official 76:aeb1df146756 214 irq_handler = handler;
mbed_official 76:aeb1df146756 215 serial_irq_ids[obj->index] = id;
mbed_official 76:aeb1df146756 216 }
mbed_official 76:aeb1df146756 217
mbed_official 76:aeb1df146756 218 void serial_irq_set(serial_t *obj, SerialIrq irq, uint32_t enable) {
mbed_official 76:aeb1df146756 219 IRQn_Type irq_n = (IRQn_Type)0;
mbed_official 76:aeb1df146756 220 uint32_t vector = 0;
mbed_official 340:28d1f895c6fe 221
mbed_official 340:28d1f895c6fe 222 UartHandle.Instance = (USART_TypeDef *)(obj->uart);
mbed_official 76:aeb1df146756 223
mbed_official 76:aeb1df146756 224 if (obj->uart == UART_1) {
mbed_official 216:577900467c9e 225 irq_n = USART1_IRQn;
mbed_official 216:577900467c9e 226 vector = (uint32_t)&uart1_irq;
mbed_official 76:aeb1df146756 227 }
mbed_official 216:577900467c9e 228
mbed_official 76:aeb1df146756 229 if (obj->uart == UART_2) {
mbed_official 216:577900467c9e 230 irq_n = USART2_IRQn;
mbed_official 216:577900467c9e 231 vector = (uint32_t)&uart2_irq;
mbed_official 76:aeb1df146756 232 }
mbed_official 216:577900467c9e 233
mbed_official 76:aeb1df146756 234 if (enable) {
mbed_official 216:577900467c9e 235
mbed_official 76:aeb1df146756 236 if (irq == RxIrq) {
mbed_official 340:28d1f895c6fe 237 __HAL_UART_ENABLE_IT(&UartHandle, UART_IT_RXNE);
mbed_official 216:577900467c9e 238 } else { // TxIrq
mbed_official 340:28d1f895c6fe 239 __HAL_UART_ENABLE_IT(&UartHandle, UART_IT_TC);
mbed_official 216:577900467c9e 240 }
mbed_official 216:577900467c9e 241
mbed_official 76:aeb1df146756 242 NVIC_SetVector(irq_n, vector);
mbed_official 76:aeb1df146756 243 NVIC_EnableIRQ(irq_n);
mbed_official 216:577900467c9e 244
mbed_official 76:aeb1df146756 245 } else { // disable
mbed_official 216:577900467c9e 246
mbed_official 76:aeb1df146756 247 int all_disabled = 0;
mbed_official 216:577900467c9e 248
mbed_official 76:aeb1df146756 249 if (irq == RxIrq) {
mbed_official 340:28d1f895c6fe 250 __HAL_UART_DISABLE_IT(&UartHandle, UART_IT_RXNE);
mbed_official 76:aeb1df146756 251 // Check if TxIrq is disabled too
mbed_official 340:28d1f895c6fe 252 if ((UartHandle.Instance->CR1 & USART_CR1_TCIE) == 0) all_disabled = 1;
mbed_official 216:577900467c9e 253 } else { // TxIrq
mbed_official 340:28d1f895c6fe 254 __HAL_UART_DISABLE_IT(&UartHandle, UART_IT_TC);
mbed_official 76:aeb1df146756 255 // Check if RxIrq is disabled too
mbed_official 340:28d1f895c6fe 256 if ((UartHandle.Instance->CR1 & USART_CR1_RXNEIE) == 0) all_disabled = 1;
mbed_official 76:aeb1df146756 257 }
mbed_official 216:577900467c9e 258
mbed_official 76:aeb1df146756 259 if (all_disabled) NVIC_DisableIRQ(irq_n);
mbed_official 216:577900467c9e 260
mbed_official 216:577900467c9e 261 }
mbed_official 76:aeb1df146756 262 }
mbed_official 76:aeb1df146756 263
mbed_official 76:aeb1df146756 264 /******************************************************************************
mbed_official 76:aeb1df146756 265 * READ/WRITE
mbed_official 76:aeb1df146756 266 ******************************************************************************/
mbed_official 76:aeb1df146756 267
mbed_official 76:aeb1df146756 268 int serial_getc(serial_t *obj) {
mbed_official 340:28d1f895c6fe 269 USART_TypeDef *uart = (USART_TypeDef *)(obj->uart);
mbed_official 76:aeb1df146756 270 while (!serial_readable(obj));
mbed_official 340:28d1f895c6fe 271 return (int)(uart->RDR & (uint16_t)0xFF);
mbed_official 76:aeb1df146756 272 }
mbed_official 76:aeb1df146756 273
mbed_official 76:aeb1df146756 274 void serial_putc(serial_t *obj, int c) {
mbed_official 340:28d1f895c6fe 275 USART_TypeDef *uart = (USART_TypeDef *)(obj->uart);
mbed_official 76:aeb1df146756 276 while (!serial_writable(obj));
mbed_official 340:28d1f895c6fe 277 uart->TDR = (uint32_t)(c & (uint16_t)0xFF);
mbed_official 76:aeb1df146756 278 }
mbed_official 76:aeb1df146756 279
mbed_official 76:aeb1df146756 280 int serial_readable(serial_t *obj) {
mbed_official 76:aeb1df146756 281 int status;
mbed_official 340:28d1f895c6fe 282 UartHandle.Instance = (USART_TypeDef *)(obj->uart);
mbed_official 76:aeb1df146756 283 // Check if data is received
mbed_official 340:28d1f895c6fe 284 status = ((__HAL_UART_GET_FLAG(&UartHandle, UART_FLAG_RXNE) != RESET) ? 1 : 0);
mbed_official 76:aeb1df146756 285 return status;
mbed_official 76:aeb1df146756 286 }
mbed_official 76:aeb1df146756 287
mbed_official 76:aeb1df146756 288 int serial_writable(serial_t *obj) {
mbed_official 76:aeb1df146756 289 int status;
mbed_official 340:28d1f895c6fe 290 UartHandle.Instance = (USART_TypeDef *)(obj->uart);
mbed_official 76:aeb1df146756 291 // Check if data is transmitted
mbed_official 340:28d1f895c6fe 292 status = ((__HAL_UART_GET_FLAG(&UartHandle, UART_FLAG_TXE) != RESET) ? 1 : 0);
mbed_official 76:aeb1df146756 293 return status;
mbed_official 76:aeb1df146756 294 }
mbed_official 76:aeb1df146756 295
mbed_official 76:aeb1df146756 296 void serial_clear(serial_t *obj) {
mbed_official 340:28d1f895c6fe 297 UartHandle.Instance = (USART_TypeDef *)(obj->uart);
mbed_official 340:28d1f895c6fe 298 __HAL_UART_CLEAR_IT(&UartHandle, UART_FLAG_TC);
mbed_official 340:28d1f895c6fe 299 __HAL_UART_SEND_REQ(&UartHandle, UART_RXDATA_FLUSH_REQUEST);
mbed_official 76:aeb1df146756 300 }
mbed_official 76:aeb1df146756 301
mbed_official 76:aeb1df146756 302 void serial_pinout_tx(PinName tx) {
mbed_official 76:aeb1df146756 303 pinmap_pinout(tx, PinMap_UART_TX);
mbed_official 76:aeb1df146756 304 }
mbed_official 76:aeb1df146756 305
mbed_official 76:aeb1df146756 306 void serial_break_set(serial_t *obj) {
mbed_official 340:28d1f895c6fe 307 // [TODO]
mbed_official 76:aeb1df146756 308 }
mbed_official 76:aeb1df146756 309
mbed_official 76:aeb1df146756 310 void serial_break_clear(serial_t *obj) {
mbed_official 340:28d1f895c6fe 311 // [TODO]
mbed_official 76:aeb1df146756 312 }
mbed_official 166:cb4253f91ada 313
mbed_official 166:cb4253f91ada 314 #endif