mbed library sources
Dependents: frdm_kl05z_gpio_test
Fork of mbed-src by
Diff: targets/hal/TARGET_STM/TARGET_DISCO_F303VC/serial_api.c
- Revision:
- 227:7bd0639b8911
- Parent:
- 157:90e3acc479a2
- Child:
- 241:ffe41b0c8126
--- a/targets/hal/TARGET_STM/TARGET_DISCO_F303VC/serial_api.c Wed Jun 11 09:45:09 2014 +0100 +++ b/targets/hal/TARGET_STM/TARGET_DISCO_F303VC/serial_api.c Wed Jun 11 16:00:09 2014 +0100 @@ -27,10 +27,10 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ******************************************************************************* */ +#include "mbed_assert.h" #include "serial_api.h" #include "cmsis.h" #include "pinmap.h" -#include "error.h" #include <string.h> static const PinMap PinMap_UART_TX[] = { @@ -85,27 +85,24 @@ USART_Cmd(usart, ENABLE); } -void serial_init(serial_t *obj, PinName tx, PinName rx) { +void serial_init(serial_t *obj, PinName tx, PinName rx) { // Determine the UART to use UARTName uart_tx = (UARTName)pinmap_peripheral(tx, PinMap_UART_TX); UARTName uart_rx = (UARTName)pinmap_peripheral(rx, PinMap_UART_RX); // Get the peripheral name from the pin and assign it to the object obj->uart = (UARTName)pinmap_merge(uart_tx, uart_rx); - - if (obj->uart == (UARTName)NC) { - error("Serial pinout mapping failed"); - } + MBED_ASSERT(obj->uart != (UARTName)NC); // Enable USART clock if (obj->uart == UART_1) { - RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE); + RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE); } if (obj->uart == UART_2) { - RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE); + RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE); } if (obj->uart == UART_3) { - RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE); + RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE); } // Configure the UART pins @@ -118,7 +115,7 @@ obj->baudrate = 9600; obj->databits = USART_WordLength_8b; obj->stopbits = USART_StopBits_1; - obj->parity = USART_Parity_No; + obj->parity = USART_Parity_No; init_usart(obj); @@ -157,7 +154,7 @@ obj->parity = USART_Parity_Odd; break; case ParityEven: - case ParityForced1: + case ParityForced1: obj->parity = USART_Parity_Even; break; default: // ParityNone @@ -233,7 +230,7 @@ USART_ITConfig(usart, USART_IT_RXNE, ENABLE); } else { // TxIrq USART_ITConfig(usart, USART_IT_TC, ENABLE); - } + } NVIC_SetVector(irq_n, vector); NVIC_EnableIRQ(irq_n); @@ -249,12 +246,12 @@ } else { // TxIrq USART_ITConfig(usart, USART_IT_TXE, DISABLE); // Check if RxIrq is disabled too - if ((usart->CR1 & USART_CR1_RXNEIE) == 0) all_disabled = 1; + if ((usart->CR1 & USART_CR1_RXNEIE) == 0) all_disabled = 1; } if (all_disabled) NVIC_DisableIRQ(irq_n); - } + } } /******************************************************************************