From 71bbdb6f1f4e937ecc2ca6cfaa3b070b4e0103e8 Mon Sep 17 00:00:00 2001 From: dreschpe Date: Thu, 13 Mar 2014 23:38:09 +0100 Subject: [PATCH] Add additional peripherie for ST Nucleo L152 board Add code for . UART 3-5, SPI 2 + 3, I2C2 --- .../TARGET_NUCLEO_L152RE/PeripheralNames.h | 8 +++- .../TARGET_STM/TARGET_NUCLEO_L152RE/i2c_api.c | 4 ++ .../TARGET_NUCLEO_L152RE/serial_api.c | 44 ++++++++++++++++++- .../TARGET_STM/TARGET_NUCLEO_L152RE/spi_api.c | 21 ++++++++- 4 files changed, 73 insertions(+), 4 deletions(-) diff --git a/libraries/mbed/targets/hal/TARGET_STM/TARGET_NUCLEO_L152RE/PeripheralNames.h b/libraries/mbed/targets/hal/TARGET_STM/TARGET_NUCLEO_L152RE/PeripheralNames.h index 31b84b2c14..52daa978d7 100644 --- a/libraries/mbed/targets/hal/TARGET_STM/TARGET_NUCLEO_L152RE/PeripheralNames.h +++ b/libraries/mbed/targets/hal/TARGET_STM/TARGET_NUCLEO_L152RE/PeripheralNames.h @@ -47,7 +47,10 @@ typedef enum { typedef enum { UART_1 = (int)USART1_BASE, - UART_2 = (int)USART2_BASE + UART_2 = (int)USART2_BASE, + UART_3 = (int)USART3_BASE, + UART_4 = (int)UART4_BASE, + UART_5 = (int)UART5_BASE } UARTName; #define STDIO_UART_TX PA_2 @@ -56,7 +59,8 @@ typedef enum { typedef enum { SPI_1 = (int)SPI1_BASE, - SPI_2 = (int)SPI2_BASE + SPI_2 = (int)SPI2_BASE, + SPI_3 = (int)SPI3_BASE } SPIName; typedef enum { diff --git a/libraries/mbed/targets/hal/TARGET_STM/TARGET_NUCLEO_L152RE/i2c_api.c b/libraries/mbed/targets/hal/TARGET_STM/TARGET_NUCLEO_L152RE/i2c_api.c index 56c7b4628e..65a6341cac 100644 --- a/libraries/mbed/targets/hal/TARGET_STM/TARGET_NUCLEO_L152RE/i2c_api.c +++ b/libraries/mbed/targets/hal/TARGET_STM/TARGET_NUCLEO_L152RE/i2c_api.c @@ -42,12 +42,16 @@ #define LONG_TIMEOUT ((int)0x8000) static const PinMap PinMap_I2C_SDA[] = { + {PB_7, I2C_1, STM_PIN_DATA(GPIO_Mode_AF, GPIO_OType_OD, GPIO_PuPd_UP, GPIO_AF_I2C1)}, {PB_9, I2C_1, STM_PIN_DATA(GPIO_Mode_AF, GPIO_OType_OD, GPIO_PuPd_UP, GPIO_AF_I2C1)}, + {PB_11, I2C_2, STM_PIN_DATA(GPIO_Mode_AF, GPIO_OType_OD, GPIO_PuPd_UP, GPIO_AF_I2C2)}, {NC, NC, 0} }; static const PinMap PinMap_I2C_SCL[] = { + {PB_6, I2C_1, STM_PIN_DATA(GPIO_Mode_AF, GPIO_OType_OD, GPIO_PuPd_UP, GPIO_AF_I2C1)}, {PB_8, I2C_1, STM_PIN_DATA(GPIO_Mode_AF, GPIO_OType_OD, GPIO_PuPd_UP, GPIO_AF_I2C1)}, + {PB_10, I2C_2, STM_PIN_DATA(GPIO_Mode_AF, GPIO_OType_OD, GPIO_PuPd_UP, GPIO_AF_I2C2)}, {NC, NC, 0} }; diff --git a/libraries/mbed/targets/hal/TARGET_STM/TARGET_NUCLEO_L152RE/serial_api.c b/libraries/mbed/targets/hal/TARGET_STM/TARGET_NUCLEO_L152RE/serial_api.c index 689ed67197..4edff042dd 100644 --- a/libraries/mbed/targets/hal/TARGET_STM/TARGET_NUCLEO_L152RE/serial_api.c +++ b/libraries/mbed/targets/hal/TARGET_STM/TARGET_NUCLEO_L152RE/serial_api.c @@ -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 @@ void serial_init(serial_t *obj, PinName tx, PinName rx) { 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 @@ void serial_init(serial_t *obj, PinName tx, PinName 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; // For stdio management if (obj->uart == STDIO_UART) { @@ -178,6 +201,9 @@ static void uart_irq(USART_TypeDef* usart, int id) { 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 @@ void serial_irq_set(serial_t *obj, SerialIrq irq, uint32_t enable) { 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) { diff --git a/libraries/mbed/targets/hal/TARGET_STM/TARGET_NUCLEO_L152RE/spi_api.c b/libraries/mbed/targets/hal/TARGET_STM/TARGET_NUCLEO_L152RE/spi_api.c index 0a383d9387..f35edd2b84 100644 --- a/libraries/mbed/targets/hal/TARGET_STM/TARGET_NUCLEO_L152RE/spi_api.c +++ b/libraries/mbed/targets/hal/TARGET_STM/TARGET_NUCLEO_L152RE/spi_api.c @@ -39,25 +39,41 @@ static const PinMap PinMap_SPI_MOSI[] = { {PA_7, SPI_1, STM_PIN_DATA(GPIO_Mode_AF, GPIO_OType_PP, GPIO_PuPd_UP, GPIO_AF_SPI1)}, {PA_12, SPI_1, STM_PIN_DATA(GPIO_Mode_AF, GPIO_OType_PP, GPIO_PuPd_UP, GPIO_AF_SPI1)}, // REMAP + {PB_4, SPI_1, STM_PIN_DATA(GPIO_Mode_AF, GPIO_OType_PP, GPIO_PuPd_UP, GPIO_AF_SPI1)}, // REMAP2 + {PB_15, SPI_2, STM_PIN_DATA(GPIO_Mode_AF, GPIO_OType_PP, GPIO_PuPd_UP, GPIO_AF_SPI2)}, + {PB_5, SPI_3, STM_PIN_DATA(GPIO_Mode_AF, GPIO_OType_PP, GPIO_PuPd_UP, GPIO_AF_SPI3)}, + {PC_12, SPI_3, STM_PIN_DATA(GPIO_Mode_AF, GPIO_OType_PP, GPIO_PuPd_UP, GPIO_AF_SPI3)}, // REMAP + {NC, NC, 0} }; static const PinMap PinMap_SPI_MISO[] = { {PA_6, SPI_1, STM_PIN_DATA(GPIO_Mode_AF, GPIO_OType_PP, GPIO_PuPd_UP, GPIO_AF_SPI1)}, {PA_11, SPI_1, STM_PIN_DATA(GPIO_Mode_AF, GPIO_OType_PP, GPIO_PuPd_UP, GPIO_AF_SPI1)}, // REMAP + {PB_5, SPI_1, STM_PIN_DATA(GPIO_Mode_AF, GPIO_OType_PP, GPIO_PuPd_UP, GPIO_AF_SPI1)}, // REMAP2 + {PA_6, SPI_1, STM_PIN_DATA(GPIO_Mode_AF, GPIO_OType_PP, GPIO_PuPd_UP, GPIO_AF_SPI1)}, + {PB_14, SPI_2, STM_PIN_DATA(GPIO_Mode_AF, GPIO_OType_PP, GPIO_PuPd_UP, GPIO_AF_SPI2)}, + {PB_4 , SPI_3, STM_PIN_DATA(GPIO_Mode_AF, GPIO_OType_PP, GPIO_PuPd_UP, GPIO_AF_SPI3)}, + {PC_11, SPI_3, STM_PIN_DATA(GPIO_Mode_AF, GPIO_OType_PP, GPIO_PuPd_UP, GPIO_AF_SPI3)}, {NC, NC, 0} }; static const PinMap PinMap_SPI_SCLK[] = { {PA_5, SPI_1, STM_PIN_DATA(GPIO_Mode_AF, GPIO_OType_PP, GPIO_PuPd_UP, GPIO_AF_SPI1)}, {PB_3, SPI_1, STM_PIN_DATA(GPIO_Mode_AF, GPIO_OType_PP, GPIO_PuPd_UP, GPIO_AF_SPI1)}, // REMAP + {PB_13, SPI_2, STM_PIN_DATA(GPIO_Mode_AF, GPIO_OType_PP, GPIO_PuPd_UP, GPIO_AF_SPI2)}, + {PB_3, SPI_3, STM_PIN_DATA(GPIO_Mode_AF, GPIO_OType_PP, GPIO_PuPd_UP, GPIO_AF_SPI3)}, + {PC_10, SPI_3, STM_PIN_DATA(GPIO_Mode_AF, GPIO_OType_PP, GPIO_PuPd_UP, GPIO_AF_SPI3)}, {NC, NC, 0} }; // Only used in Slave mode static const PinMap PinMap_SPI_SSEL[] = { {PA_4, SPI_1, STM_PIN_DATA(GPIO_Mode_AF, GPIO_OType_PP, GPIO_PuPd_UP, GPIO_AF_SPI1)}, - {PA_15, SPI_1, STM_PIN_DATA(GPIO_Mode_AF, GPIO_OType_PP, GPIO_PuPd_UP, GPIO_AF_SPI1)}, // REMAP + {PA_15, SPI_1, STM_PIN_DATA(GPIO_Mode_AF, GPIO_OType_PP, GPIO_PuPd_UP, GPIO_AF_SPI1)}, // REMAP + {PB_12, SPI_2, STM_PIN_DATA(GPIO_Mode_AF, GPIO_OType_PP, GPIO_PuPd_UP, GPIO_AF_SPI2)}, + {PA_4 , SPI_3, STM_PIN_DATA(GPIO_Mode_AF, GPIO_OType_PP, GPIO_PuPd_UP, GPIO_AF_SPI3)}, + {PA_15, SPI_3, STM_PIN_DATA(GPIO_Mode_AF, GPIO_OType_PP, GPIO_PuPd_UP, GPIO_AF_SPI3)}, {NC, NC, 0} }; @@ -104,6 +120,9 @@ void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel if (obj->spi == SPI_2) { RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2, ENABLE); } + if (obj->spi == SPI_3) { + RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI3, ENABLE); + } // Configure the SPI pins pinmap_pinout(mosi, PinMap_SPI_MOSI);