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:
- 118:b44c45162f28
- Parent:
- 76:aeb1df146756
- Child:
- 129:0182c99221bc
diff -r e0a7df0a9a56 -r b44c45162f28 targets/hal/TARGET_STM/TARGET_NUCLEO_L152RE/serial_api.c --- a/targets/hal/TARGET_STM/TARGET_NUCLEO_L152RE/serial_api.c Wed Mar 12 10:30:07 2014 +0000 +++ b/targets/hal/TARGET_STM/TARGET_NUCLEO_L152RE/serial_api.c Fri Mar 14 10:00:07 2014 +0000 @@ -35,17 +35,27 @@ static const PinMap PinMap_UART_TX[] = { {PA_9, UART_1, STM_PIN_DATA(GPIO_Mode_AF, GPIO_OType_PP, GPIO_PuPd_UP, GPIO_AF_USART1)}, + {PB_6, UART_1, STM_PIN_DATA(GPIO_Mode_AF, GPIO_OType_PP, GPIO_PuPd_UP, GPIO_AF_USART1)}, {PA_2, UART_2, STM_PIN_DATA(GPIO_Mode_AF, GPIO_OType_PP, GPIO_PuPd_UP, GPIO_AF_USART2)}, + {PB_10, UART_3, STM_PIN_DATA(GPIO_Mode_AF, GPIO_OType_PP, GPIO_PuPd_UP, GPIO_AF_USART3)}, + {PC_10, UART_4, STM_PIN_DATA(GPIO_Mode_AF, GPIO_OType_PP, GPIO_PuPd_UP, GPIO_AF_UART4)}, + //{PC_10, UART_3, STM_PIN_DATA(GPIO_Mode_AF, GPIO_OType_PP, GPIO_PuPd_UP, GPIO_AF_USART3)}, //The consructor will find UART4 + {PC_12, UART_5, STM_PIN_DATA(GPIO_Mode_AF, GPIO_OType_PP, GPIO_PuPd_UP, GPIO_AF_UART5)}, //which share the same PIN {NC, NC, 0} }; static const PinMap PinMap_UART_RX[] = { {PA_10, UART_1, STM_PIN_DATA(GPIO_Mode_AF, GPIO_OType_PP, GPIO_PuPd_UP, GPIO_AF_USART1)}, + {PB_7 , UART_1, STM_PIN_DATA(GPIO_Mode_AF, GPIO_OType_PP, GPIO_PuPd_UP, GPIO_AF_USART1)}, {PA_3, UART_2, STM_PIN_DATA(GPIO_Mode_AF, GPIO_OType_PP, GPIO_PuPd_UP, GPIO_AF_USART2)}, + {PB_11, UART_3, STM_PIN_DATA(GPIO_Mode_AF, GPIO_OType_PP, GPIO_PuPd_UP, GPIO_AF_USART3)}, + {PC_11, UART_4, STM_PIN_DATA(GPIO_Mode_AF, GPIO_OType_PP, GPIO_PuPd_UP, GPIO_AF_UART4)}, + //{PC_11, UART_3, STM_PIN_DATA(GPIO_Mode_AF, GPIO_OType_PP, GPIO_PuPd_UP, GPIO_AF_USART3)}, + {PC_2 , UART_5, STM_PIN_DATA(GPIO_Mode_AF, GPIO_OType_PP, GPIO_PuPd_UP, GPIO_AF_UART5)}, {NC, NC, 0} }; -#define UART_NUM (2) +#define UART_NUM (5) static uint32_t serial_irq_ids[UART_NUM] = {0}; @@ -90,6 +100,16 @@ if (obj->uart == UART_2) { RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE); } + if (obj->uart == UART_3) { + RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE); + } + if (obj->uart == UART_4) { + RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART4, ENABLE); + } + if (obj->uart == UART_5) { + RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART5, ENABLE); + } + // Configure the UART pins pinmap_pinout(tx, PinMap_UART_TX); @@ -108,6 +128,9 @@ // 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; // For stdio management if (obj->uart == STDIO_UART) { @@ -178,6 +201,9 @@ static void uart1_irq(void) {uart_irq((USART_TypeDef*)UART_1, 0);} static void uart2_irq(void) {uart_irq((USART_TypeDef*)UART_2, 1);} +static void uart3_irq(void) {uart_irq((USART_TypeDef*)UART_3, 2);} +static void uart4_irq(void) {uart_irq((USART_TypeDef*)UART_4, 3);} +static void uart5_irq(void) {uart_irq((USART_TypeDef*)UART_5, 4);} void serial_irq_handler(serial_t *obj, uart_irq_handler handler, uint32_t id) { irq_handler = handler; @@ -199,6 +225,22 @@ vector = (uint32_t)&uart2_irq; } + if (obj->uart == UART_3) { + irq_n = USART3_IRQn; + vector = (uint32_t)&uart3_irq; + } + + if (obj->uart == UART_4) { + irq_n = UART4_IRQn; + vector = (uint32_t)&uart4_irq; + } + + if (obj->uart == UART_5) { + irq_n = UART5_IRQn; + vector = (uint32_t)&uart5_irq; + } + + if (enable) { if (irq == RxIrq) {