From c2327523bd093282707d42705b364a71db73250d Mon Sep 17 00:00:00 2001 From: jesusalvarez Date: Tue, 12 Aug 2014 19:25:25 -0400 Subject: [PATCH] LP4330_M4 i2c/spi update --- .../hal/TARGET_NXP/TARGET_LPC43XX/i2c_api.c | 11 +-- .../TARGET_NXP/TARGET_LPC43XX/serial_api.c | 72 ++++++++++--------- .../hal/TARGET_NXP/TARGET_LPC43XX/spi_api.c | 67 +++++++++-------- 3 files changed, 83 insertions(+), 67 deletions(-) diff --git a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC43XX/i2c_api.c b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC43XX/i2c_api.c index 4d4747fc45..27c8f018b1 100644 --- a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC43XX/i2c_api.c +++ b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC43XX/i2c_api.c @@ -20,17 +20,20 @@ #include "pinmap.h" #include "error.h" +// SCU mode for I2C SCL/SDA pins +#define SCU_PINIO_I2C SCU_PINIO_PULLNONE + static const PinMap PinMap_I2C_SDA[] = { {P_DED, I2C_0, 0}, - {P2_3, I2C_1, 1}, - {PE_13, I2C_1, 2}, + {P2_3, I2C_1, (SCU_PINIO_I2C | 1)}, + {PE_13, I2C_1, (SCU_PINIO_I2C | 2)}, {NC, NC, 0} }; static const PinMap PinMap_I2C_SCL[] = { {P_DED, I2C_0, 0}, - {P2_4, I2C_1, 1}, - {PE_14, I2C_1, 2}, + {P2_4, I2C_1, (SCU_PINIO_I2C | 1)}, + {PE_14, I2C_1, (SCU_PINIO_I2C | 2)}, {NC, NC, 0} }; diff --git a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC43XX/serial_api.c b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC43XX/serial_api.c index ed3df6eab7..997581e552 100644 --- a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC43XX/serial_api.c +++ b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC43XX/serial_api.c @@ -31,45 +31,49 @@ ******************************************************************************/ #define UART_NUM 4 +// SCU mode for UART pins +#define SCU_PINIO_UART_TX SCU_MODE_PULLDOWN +#define SCU_PINIO_UART_RX SCU_PINIO_PULLNONE + static const PinMap PinMap_UART_TX[] = { - {P1_13, UART_1, (SCU_MODE_PULLDOWN | 1)}, - {P1_15, UART_2, (SCU_MODE_PULLDOWN | 1)}, - {P2_0, UART_0, (SCU_MODE_PULLDOWN | 1)}, - {P2_3, UART_3, (SCU_MODE_PULLDOWN | 2)}, - {P2_10, UART_2, (SCU_MODE_PULLDOWN | 2)}, - {P3_4, UART_1, (SCU_MODE_PULLDOWN | 4)}, - {P4_1, UART_3, (SCU_MODE_PULLDOWN | 6)}, - {P5_6, UART_1, (SCU_MODE_PULLDOWN | 4)}, - {P6_4, UART_0, (SCU_MODE_PULLDOWN | 2)}, - {P7_1, UART_2, (SCU_MODE_PULLDOWN | 6)}, - {P9_3, UART_3, (SCU_MODE_PULLDOWN | 7)}, - {P9_5, UART_0, (SCU_MODE_PULLDOWN | 7)}, - {PA_1, UART_2, (SCU_MODE_PULLDOWN | 3)}, - {PC_13, UART_1, (SCU_MODE_PULLDOWN | 2)}, - {PE_11, UART_1, (SCU_MODE_PULLDOWN | 2)}, - {PF_2, UART_3, (SCU_MODE_PULLDOWN | 1)}, - {PF_10, UART_0, (SCU_MODE_PULLDOWN | 1)}, + {P1_13, UART_1, (SCU_PINIO_UART_TX | 1)}, + {P1_15, UART_2, (SCU_PINIO_UART_TX | 1)}, + {P2_0, UART_0, (SCU_PINIO_UART_TX | 1)}, + {P2_3, UART_3, (SCU_PINIO_UART_TX | 2)}, + {P2_10, UART_2, (SCU_PINIO_UART_TX | 2)}, + {P3_4, UART_1, (SCU_PINIO_UART_TX | 4)}, + {P4_1, UART_3, (SCU_PINIO_UART_TX | 6)}, + {P5_6, UART_1, (SCU_PINIO_UART_TX | 4)}, + {P6_4, UART_0, (SCU_PINIO_UART_TX | 2)}, + {P7_1, UART_2, (SCU_PINIO_UART_TX | 6)}, + {P9_3, UART_3, (SCU_PINIO_UART_TX | 7)}, + {P9_5, UART_0, (SCU_PINIO_UART_TX | 7)}, + {PA_1, UART_2, (SCU_PINIO_UART_TX | 3)}, + {PC_13, UART_1, (SCU_PINIO_UART_TX | 2)}, + {PE_11, UART_1, (SCU_PINIO_UART_TX | 2)}, + {PF_2, UART_3, (SCU_PINIO_UART_TX | 1)}, + {PF_10, UART_0, (SCU_PINIO_UART_TX | 1)}, {NC, NC, 0} }; static const PinMap PinMap_UART_RX[] = { - {P1_14, UART_1, (SCU_PINIO_PULLNONE | 1)}, - {P1_16, UART_2, (SCU_PINIO_PULLNONE | 1)}, - {P2_1, UART_0, (SCU_PINIO_PULLNONE | 1)}, - {P2_4, UART_3, (SCU_PINIO_PULLNONE | 2)}, - {P2_11, UART_2, (SCU_PINIO_PULLNONE | 2)}, - {P3_5, UART_1, (SCU_PINIO_PULLNONE | 4)}, - {P4_2, UART_3, (SCU_PINIO_PULLNONE | 6)}, - {P5_7, UART_1, (SCU_PINIO_PULLNONE | 4)}, - {P6_5, UART_0, (SCU_PINIO_PULLNONE | 2)}, - {P7_2, UART_2, (SCU_PINIO_PULLNONE | 6)}, - {P9_4, UART_3, (SCU_PINIO_PULLNONE | 7)}, - {P9_6, UART_0, (SCU_PINIO_PULLNONE | 7)}, - {PA_2, UART_2, (SCU_PINIO_PULLNONE | 3)}, - {PC_14, UART_1, (SCU_PINIO_PULLNONE | 2)}, - {PE_12, UART_1, (SCU_PINIO_PULLNONE | 2)}, - {PF_3, UART_3, (SCU_PINIO_PULLNONE | 1)}, - {PF_11, UART_0, (SCU_PINIO_PULLNONE | 1)}, + {P1_14, UART_1, (SCU_PINIO_UART_RX | 1)}, + {P1_16, UART_2, (SCU_PINIO_UART_RX | 1)}, + {P2_1, UART_0, (SCU_PINIO_UART_RX | 1)}, + {P2_4, UART_3, (SCU_PINIO_UART_RX | 2)}, + {P2_11, UART_2, (SCU_PINIO_UART_RX | 2)}, + {P3_5, UART_1, (SCU_PINIO_UART_RX | 4)}, + {P4_2, UART_3, (SCU_PINIO_UART_RX | 6)}, + {P5_7, UART_1, (SCU_PINIO_UART_RX | 4)}, + {P6_5, UART_0, (SCU_PINIO_UART_RX | 2)}, + {P7_2, UART_2, (SCU_PINIO_UART_RX | 6)}, + {P9_4, UART_3, (SCU_PINIO_UART_RX | 7)}, + {P9_6, UART_0, (SCU_PINIO_UART_RX | 7)}, + {PA_2, UART_2, (SCU_PINIO_UART_RX | 3)}, + {PC_14, UART_1, (SCU_PINIO_UART_RX | 2)}, + {PE_12, UART_1, (SCU_PINIO_UART_RX | 2)}, + {PF_3, UART_3, (SCU_PINIO_UART_RX | 1)}, + {PF_11, UART_0, (SCU_PINIO_UART_RX | 1)}, {NC, NC, 0} }; diff --git a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC43XX/spi_api.c b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC43XX/spi_api.c index e510f66d33..d5818cc97e 100644 --- a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC43XX/spi_api.c +++ b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC43XX/spi_api.c @@ -23,48 +23,51 @@ #include "pinmap.h" #include "error.h" +// SCU mode for SPI pins +#define SCU_PINIO_SPI SCU_PINIO_FAST + static const PinMap PinMap_SPI_SCLK[] = { - {P1_19, SPI_1, (SCU_PINIO_FAST | 1)}, - {P3_0, SPI_0, (SCU_PINIO_FAST | 4)}, - {P3_3, SPI_0, (SCU_PINIO_FAST | 2)}, - {PF_0, SPI_0, (SCU_PINIO_FAST | 0)}, - {PF_4, SPI_1, (SCU_PINIO_FAST | 0)}, + {P1_19, SPI_1, (SCU_PINIO_SPI | 1)}, + {P3_0, SPI_0, (SCU_PINIO_SPI | 4)}, + {P3_3, SPI_0, (SCU_PINIO_SPI | 2)}, + {PF_0, SPI_0, (SCU_PINIO_SPI | 0)}, + {PF_4, SPI_1, (SCU_PINIO_SPI | 0)}, {NC, NC, 0} }; static const PinMap PinMap_SPI_MOSI[] = { - {P0_1, SPI_1, (SCU_PINIO_FAST | 1)}, - {P1_2, SPI_0, (SCU_PINIO_FAST | 5)}, - {P1_4, SPI_1, (SCU_PINIO_FAST | 5)}, - {P3_7, SPI_0, (SCU_PINIO_FAST | 5)}, - {P3_8, SPI_0, (SCU_PINIO_FAST | 2)}, - {P9_2, SPI_0, (SCU_PINIO_FAST | 7)}, - {PF_3, SPI_0, (SCU_PINIO_FAST | 2)}, - {PF_7, SPI_1, (SCU_PINIO_FAST | 2)}, + {P0_1, SPI_1, (SCU_PINIO_SPI | 1)}, + {P1_2, SPI_0, (SCU_PINIO_SPI | 5)}, + {P1_4, SPI_1, (SCU_PINIO_SPI | 5)}, + {P3_7, SPI_0, (SCU_PINIO_SPI | 5)}, + {P3_8, SPI_0, (SCU_PINIO_SPI | 2)}, + {P9_2, SPI_0, (SCU_PINIO_SPI | 7)}, + {PF_3, SPI_0, (SCU_PINIO_SPI | 2)}, + {PF_7, SPI_1, (SCU_PINIO_SPI | 2)}, {NC, NC, 0} }; static const PinMap PinMap_SPI_MISO[] = { - {P0_0, SPI_1, (SCU_PINIO_FAST | 1)}, - {P1_1, SPI_0, (SCU_PINIO_FAST | 5)}, - {P1_3, SPI_1, (SCU_PINIO_FAST | 5)}, - {P3_6, SPI_0, (SCU_PINIO_FAST | 5)}, - {P3_7, SPI_0, (SCU_PINIO_FAST | 2)}, - {P9_1, SPI_0, (SCU_PINIO_FAST | 7)}, - {PF_2, SPI_0, (SCU_PINIO_FAST | 2)}, - {PF_6, SPI_1, (SCU_PINIO_FAST | 2)}, + {P0_0, SPI_1, (SCU_PINIO_SPI | 1)}, + {P1_1, SPI_0, (SCU_PINIO_SPI | 5)}, + {P1_3, SPI_1, (SCU_PINIO_SPI | 5)}, + {P3_6, SPI_0, (SCU_PINIO_SPI | 5)}, + {P3_7, SPI_0, (SCU_PINIO_SPI | 2)}, + {P9_1, SPI_0, (SCU_PINIO_SPI | 7)}, + {PF_2, SPI_0, (SCU_PINIO_SPI | 2)}, + {PF_6, SPI_1, (SCU_PINIO_SPI | 2)}, {NC, NC, 0} }; static const PinMap PinMap_SPI_SSEL[] = { - {P1_0, SPI_0, (SCU_PINIO_FAST | 5)}, - {P1_5, SPI_1, (SCU_PINIO_FAST | 5)}, - {P1_20, SPI_1, (SCU_PINIO_FAST | 2)}, - {P3_6, SPI_0, (SCU_PINIO_FAST | 2)}, - {P3_8, SPI_0, (SCU_PINIO_FAST | 5)}, - {P9_0, SPI_0, (SCU_PINIO_FAST | 7)}, - {PF_1, SPI_0, (SCU_PINIO_FAST | 2)}, - {PF_5, SPI_1, (SCU_PINIO_FAST | 2)}, + {P1_0, SPI_0, (SCU_PINIO_SPI | 5)}, + {P1_5, SPI_1, (SCU_PINIO_SPI | 5)}, + {P1_20, SPI_1, (SCU_PINIO_SPI | 2)}, + {P3_6, SPI_0, (SCU_PINIO_SPI | 2)}, + {P3_8, SPI_0, (SCU_PINIO_SPI | 5)}, + {P9_0, SPI_0, (SCU_PINIO_SPI | 7)}, + {PF_1, SPI_0, (SCU_PINIO_SPI | 2)}, + {PF_5, SPI_1, (SCU_PINIO_SPI | 2)}, {NC, NC, 0} }; @@ -82,6 +85,12 @@ void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel obj->spi = (LPC_SSP_T*)pinmap_merge(spi_data, spi_cntl); MBED_ASSERT((int)obj->spi != NC); + + // enable clocking + switch ((int)obj->spi) { + case SPI_0: LPC_CGU->BASE_CLK[CLK_BASE_SSP0] = (1 << 11) | (CLKIN_MAINPLL << 24); break; + case SPI_1: LPC_CGU->BASE_CLK[CLK_BASE_SSP1] = (1 << 11) | (CLKIN_MAINPLL << 24); break; + } // set default format and frequency if (ssel == NC) {