mbed library sources
Dependents: frdm_kl05z_gpio_test
Fork of mbed-src by
Diff: targets/hal/TARGET_STM/TARGET_NUCLEO_L152RE/serial_api.c
- Revision:
- 215:83cf97a28428
- Parent:
- 174:8bb9f3a33240
- Child:
- 227:7bd0639b8911
diff -r b6ec89a903fb -r 83cf97a28428 targets/hal/TARGET_STM/TARGET_NUCLEO_L152RE/serial_api.c --- a/targets/hal/TARGET_STM/TARGET_NUCLEO_L152RE/serial_api.c Tue May 27 08:15:07 2014 +0100 +++ b/targets/hal/TARGET_STM/TARGET_NUCLEO_L152RE/serial_api.c Tue May 27 08:30:06 2014 +0100 @@ -99,18 +99,23 @@ // Enable USART clock if (obj->uart == UART_1) { RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE); + obj->index = 0; } if (obj->uart == UART_2) { RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE); + obj->index = 1; } if (obj->uart == UART_3) { RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE); + obj->index = 2; } if (obj->uart == UART_4) { RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART4, ENABLE); + obj->index = 3; } if (obj->uart == UART_5) { RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART5, ENABLE); + obj->index = 4; } // Configure the UART pins @@ -125,14 +130,10 @@ obj->stopbits = USART_StopBits_1; obj->parity = USART_Parity_No; - init_usart(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_3) obj->index = 2; - if (obj->uart == UART_4) obj->index = 3; - if (obj->uart == UART_5) obj->index = 4; + init_usart(obj); // For stdio management if (obj->uart == STDIO_UART) { @@ -142,6 +143,37 @@ } void serial_free(serial_t *obj) { + // Reset UART and disable clock + if (obj->uart == UART_1) { + RCC_APB2PeriphResetCmd(RCC_APB2Periph_USART1, ENABLE); + RCC_APB2PeriphResetCmd(RCC_APB2Periph_USART1, DISABLE); + RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, DISABLE); + } + if (obj->uart == UART_2) { + RCC_APB1PeriphResetCmd(RCC_APB1Periph_USART2, ENABLE); + RCC_APB1PeriphResetCmd(RCC_APB1Periph_USART2, DISABLE); + RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, DISABLE); + } + if (obj->uart == UART_3) { + RCC_APB1PeriphResetCmd(RCC_APB1Periph_USART3, ENABLE); + RCC_APB1PeriphResetCmd(RCC_APB1Periph_USART3, DISABLE); + RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, DISABLE); + } + if (obj->uart == UART_4) { + RCC_APB1PeriphResetCmd(RCC_APB1Periph_UART4, ENABLE); + RCC_APB1PeriphResetCmd(RCC_APB1Periph_UART4, DISABLE); + RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART4, DISABLE); + } + if (obj->uart == UART_5) { + RCC_APB1PeriphResetCmd(RCC_APB1Periph_UART5, ENABLE); + RCC_APB1PeriphResetCmd(RCC_APB1Periph_UART5, DISABLE); + RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART5, DISABLE); + } + + // Configure GPIOs + pin_function(obj->pin_tx, STM_PIN_DATA(GPIO_Mode_IN, 0, GPIO_PuPd_NOPULL, 0xFF)); + pin_function(obj->pin_rx, STM_PIN_DATA(GPIO_Mode_IN, 0, GPIO_PuPd_NOPULL, 0xFF)); + serial_irq_ids[obj->index] = 0; }