mbed library sources
Dependents: frdm_kl05z_gpio_test
Fork of mbed-src by
Diff: targets/hal/TARGET_STM/TARGET_NUCLEO_F401RE/serial_api.c
- Revision:
- 215:83cf97a28428
- Parent:
- 172:2f4f8c56b261
- Child:
- 227:7bd0639b8911
diff -r b6ec89a903fb -r 83cf97a28428 targets/hal/TARGET_STM/TARGET_NUCLEO_F401RE/serial_api.c --- a/targets/hal/TARGET_STM/TARGET_NUCLEO_F401RE/serial_api.c Tue May 27 08:15:07 2014 +0100 +++ b/targets/hal/TARGET_STM/TARGET_NUCLEO_F401RE/serial_api.c Tue May 27 08:30:06 2014 +0100 @@ -93,12 +93,15 @@ // Enable USART clock if (obj->uart == UART_1) { __USART1_CLK_ENABLE(); + obj->index = 0; } if (obj->uart == UART_2) { __USART2_CLK_ENABLE(); + obj->index = 1; } if (obj->uart == UART_6) { __USART6_CLK_ENABLE(); + obj->index = 2; } // Configure the UART pins @@ -113,12 +116,10 @@ obj->stopbits = UART_STOPBITS_1; obj->parity = UART_PARITY_NONE; - init_uart(obj); + obj->pin_tx = tx; + obj->pin_rx = rx; - // The index is used by irq - if (obj->uart == UART_1) obj->index = 0; - if (obj->uart == UART_2) obj->index = 1; - if (obj->uart == UART_6) obj->index = 2; + init_uart(obj); // For stdio management if (obj->uart == STDIO_UART) { @@ -129,6 +130,27 @@ } void serial_free(serial_t *obj) { + // Reset UART and disable clock + if (obj->uart == UART_1) { + __USART1_FORCE_RESET(); + __USART1_RELEASE_RESET(); + __USART1_CLK_DISABLE(); + } + if (obj->uart == UART_2) { + __USART2_FORCE_RESET(); + __USART2_RELEASE_RESET(); + __USART2_CLK_DISABLE(); + } + if (obj->uart == UART_6) { + __USART6_FORCE_RESET(); + __USART6_RELEASE_RESET(); + __USART6_CLK_DISABLE(); + } + + // Configure GPIOs + pin_function(obj->pin_tx, STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, 0)); + pin_function(obj->pin_rx, STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, 0)); + serial_irq_ids[obj->index] = 0; }