Skip to content

Commit 1409f2a

Browse files
committed
Merge pull request #442 from micromint/master
[HAL] LP4330_M4 i2c/spi update
2 parents 23b25bb + c232752 commit 1409f2a

File tree

3 files changed

+83
-67
lines changed

3 files changed

+83
-67
lines changed

libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC43XX/i2c_api.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,20 @@
2020
#include "pinmap.h"
2121
#include "error.h"
2222

23+
// SCU mode for I2C SCL/SDA pins
24+
#define SCU_PINIO_I2C SCU_PINIO_PULLNONE
25+
2326
static const PinMap PinMap_I2C_SDA[] = {
2427
{P_DED, I2C_0, 0},
25-
{P2_3, I2C_1, 1},
26-
{PE_13, I2C_1, 2},
28+
{P2_3, I2C_1, (SCU_PINIO_I2C | 1)},
29+
{PE_13, I2C_1, (SCU_PINIO_I2C | 2)},
2730
{NC, NC, 0}
2831
};
2932

3033
static const PinMap PinMap_I2C_SCL[] = {
3134
{P_DED, I2C_0, 0},
32-
{P2_4, I2C_1, 1},
33-
{PE_14, I2C_1, 2},
35+
{P2_4, I2C_1, (SCU_PINIO_I2C | 1)},
36+
{PE_14, I2C_1, (SCU_PINIO_I2C | 2)},
3437
{NC, NC, 0}
3538
};
3639

libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC43XX/serial_api.c

Lines changed: 38 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -31,45 +31,49 @@
3131
******************************************************************************/
3232
#define UART_NUM 4
3333

34+
// SCU mode for UART pins
35+
#define SCU_PINIO_UART_TX SCU_MODE_PULLDOWN
36+
#define SCU_PINIO_UART_RX SCU_PINIO_PULLNONE
37+
3438
static const PinMap PinMap_UART_TX[] = {
35-
{P1_13, UART_1, (SCU_MODE_PULLDOWN | 1)},
36-
{P1_15, UART_2, (SCU_MODE_PULLDOWN | 1)},
37-
{P2_0, UART_0, (SCU_MODE_PULLDOWN | 1)},
38-
{P2_3, UART_3, (SCU_MODE_PULLDOWN | 2)},
39-
{P2_10, UART_2, (SCU_MODE_PULLDOWN | 2)},
40-
{P3_4, UART_1, (SCU_MODE_PULLDOWN | 4)},
41-
{P4_1, UART_3, (SCU_MODE_PULLDOWN | 6)},
42-
{P5_6, UART_1, (SCU_MODE_PULLDOWN | 4)},
43-
{P6_4, UART_0, (SCU_MODE_PULLDOWN | 2)},
44-
{P7_1, UART_2, (SCU_MODE_PULLDOWN | 6)},
45-
{P9_3, UART_3, (SCU_MODE_PULLDOWN | 7)},
46-
{P9_5, UART_0, (SCU_MODE_PULLDOWN | 7)},
47-
{PA_1, UART_2, (SCU_MODE_PULLDOWN | 3)},
48-
{PC_13, UART_1, (SCU_MODE_PULLDOWN | 2)},
49-
{PE_11, UART_1, (SCU_MODE_PULLDOWN | 2)},
50-
{PF_2, UART_3, (SCU_MODE_PULLDOWN | 1)},
51-
{PF_10, UART_0, (SCU_MODE_PULLDOWN | 1)},
39+
{P1_13, UART_1, (SCU_PINIO_UART_TX | 1)},
40+
{P1_15, UART_2, (SCU_PINIO_UART_TX | 1)},
41+
{P2_0, UART_0, (SCU_PINIO_UART_TX | 1)},
42+
{P2_3, UART_3, (SCU_PINIO_UART_TX | 2)},
43+
{P2_10, UART_2, (SCU_PINIO_UART_TX | 2)},
44+
{P3_4, UART_1, (SCU_PINIO_UART_TX | 4)},
45+
{P4_1, UART_3, (SCU_PINIO_UART_TX | 6)},
46+
{P5_6, UART_1, (SCU_PINIO_UART_TX | 4)},
47+
{P6_4, UART_0, (SCU_PINIO_UART_TX | 2)},
48+
{P7_1, UART_2, (SCU_PINIO_UART_TX | 6)},
49+
{P9_3, UART_3, (SCU_PINIO_UART_TX | 7)},
50+
{P9_5, UART_0, (SCU_PINIO_UART_TX | 7)},
51+
{PA_1, UART_2, (SCU_PINIO_UART_TX | 3)},
52+
{PC_13, UART_1, (SCU_PINIO_UART_TX | 2)},
53+
{PE_11, UART_1, (SCU_PINIO_UART_TX | 2)},
54+
{PF_2, UART_3, (SCU_PINIO_UART_TX | 1)},
55+
{PF_10, UART_0, (SCU_PINIO_UART_TX | 1)},
5256
{NC, NC, 0}
5357
};
5458

5559
static const PinMap PinMap_UART_RX[] = {
56-
{P1_14, UART_1, (SCU_PINIO_PULLNONE | 1)},
57-
{P1_16, UART_2, (SCU_PINIO_PULLNONE | 1)},
58-
{P2_1, UART_0, (SCU_PINIO_PULLNONE | 1)},
59-
{P2_4, UART_3, (SCU_PINIO_PULLNONE | 2)},
60-
{P2_11, UART_2, (SCU_PINIO_PULLNONE | 2)},
61-
{P3_5, UART_1, (SCU_PINIO_PULLNONE | 4)},
62-
{P4_2, UART_3, (SCU_PINIO_PULLNONE | 6)},
63-
{P5_7, UART_1, (SCU_PINIO_PULLNONE | 4)},
64-
{P6_5, UART_0, (SCU_PINIO_PULLNONE | 2)},
65-
{P7_2, UART_2, (SCU_PINIO_PULLNONE | 6)},
66-
{P9_4, UART_3, (SCU_PINIO_PULLNONE | 7)},
67-
{P9_6, UART_0, (SCU_PINIO_PULLNONE | 7)},
68-
{PA_2, UART_2, (SCU_PINIO_PULLNONE | 3)},
69-
{PC_14, UART_1, (SCU_PINIO_PULLNONE | 2)},
70-
{PE_12, UART_1, (SCU_PINIO_PULLNONE | 2)},
71-
{PF_3, UART_3, (SCU_PINIO_PULLNONE | 1)},
72-
{PF_11, UART_0, (SCU_PINIO_PULLNONE | 1)},
60+
{P1_14, UART_1, (SCU_PINIO_UART_RX | 1)},
61+
{P1_16, UART_2, (SCU_PINIO_UART_RX | 1)},
62+
{P2_1, UART_0, (SCU_PINIO_UART_RX | 1)},
63+
{P2_4, UART_3, (SCU_PINIO_UART_RX | 2)},
64+
{P2_11, UART_2, (SCU_PINIO_UART_RX | 2)},
65+
{P3_5, UART_1, (SCU_PINIO_UART_RX | 4)},
66+
{P4_2, UART_3, (SCU_PINIO_UART_RX | 6)},
67+
{P5_7, UART_1, (SCU_PINIO_UART_RX | 4)},
68+
{P6_5, UART_0, (SCU_PINIO_UART_RX | 2)},
69+
{P7_2, UART_2, (SCU_PINIO_UART_RX | 6)},
70+
{P9_4, UART_3, (SCU_PINIO_UART_RX | 7)},
71+
{P9_6, UART_0, (SCU_PINIO_UART_RX | 7)},
72+
{PA_2, UART_2, (SCU_PINIO_UART_RX | 3)},
73+
{PC_14, UART_1, (SCU_PINIO_UART_RX | 2)},
74+
{PE_12, UART_1, (SCU_PINIO_UART_RX | 2)},
75+
{PF_3, UART_3, (SCU_PINIO_UART_RX | 1)},
76+
{PF_11, UART_0, (SCU_PINIO_UART_RX | 1)},
7377
{NC, NC, 0}
7478
};
7579

libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC43XX/spi_api.c

Lines changed: 38 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -23,48 +23,51 @@
2323
#include "pinmap.h"
2424
#include "error.h"
2525

26+
// SCU mode for SPI pins
27+
#define SCU_PINIO_SPI SCU_PINIO_FAST
28+
2629
static const PinMap PinMap_SPI_SCLK[] = {
27-
{P1_19, SPI_1, (SCU_PINIO_FAST | 1)},
28-
{P3_0, SPI_0, (SCU_PINIO_FAST | 4)},
29-
{P3_3, SPI_0, (SCU_PINIO_FAST | 2)},
30-
{PF_0, SPI_0, (SCU_PINIO_FAST | 0)},
31-
{PF_4, SPI_1, (SCU_PINIO_FAST | 0)},
30+
{P1_19, SPI_1, (SCU_PINIO_SPI | 1)},
31+
{P3_0, SPI_0, (SCU_PINIO_SPI | 4)},
32+
{P3_3, SPI_0, (SCU_PINIO_SPI | 2)},
33+
{PF_0, SPI_0, (SCU_PINIO_SPI | 0)},
34+
{PF_4, SPI_1, (SCU_PINIO_SPI | 0)},
3235
{NC, NC, 0}
3336
};
3437

3538
static const PinMap PinMap_SPI_MOSI[] = {
36-
{P0_1, SPI_1, (SCU_PINIO_FAST | 1)},
37-
{P1_2, SPI_0, (SCU_PINIO_FAST | 5)},
38-
{P1_4, SPI_1, (SCU_PINIO_FAST | 5)},
39-
{P3_7, SPI_0, (SCU_PINIO_FAST | 5)},
40-
{P3_8, SPI_0, (SCU_PINIO_FAST | 2)},
41-
{P9_2, SPI_0, (SCU_PINIO_FAST | 7)},
42-
{PF_3, SPI_0, (SCU_PINIO_FAST | 2)},
43-
{PF_7, SPI_1, (SCU_PINIO_FAST | 2)},
39+
{P0_1, SPI_1, (SCU_PINIO_SPI | 1)},
40+
{P1_2, SPI_0, (SCU_PINIO_SPI | 5)},
41+
{P1_4, SPI_1, (SCU_PINIO_SPI | 5)},
42+
{P3_7, SPI_0, (SCU_PINIO_SPI | 5)},
43+
{P3_8, SPI_0, (SCU_PINIO_SPI | 2)},
44+
{P9_2, SPI_0, (SCU_PINIO_SPI | 7)},
45+
{PF_3, SPI_0, (SCU_PINIO_SPI | 2)},
46+
{PF_7, SPI_1, (SCU_PINIO_SPI | 2)},
4447
{NC, NC, 0}
4548
};
4649

4750
static const PinMap PinMap_SPI_MISO[] = {
48-
{P0_0, SPI_1, (SCU_PINIO_FAST | 1)},
49-
{P1_1, SPI_0, (SCU_PINIO_FAST | 5)},
50-
{P1_3, SPI_1, (SCU_PINIO_FAST | 5)},
51-
{P3_6, SPI_0, (SCU_PINIO_FAST | 5)},
52-
{P3_7, SPI_0, (SCU_PINIO_FAST | 2)},
53-
{P9_1, SPI_0, (SCU_PINIO_FAST | 7)},
54-
{PF_2, SPI_0, (SCU_PINIO_FAST | 2)},
55-
{PF_6, SPI_1, (SCU_PINIO_FAST | 2)},
51+
{P0_0, SPI_1, (SCU_PINIO_SPI | 1)},
52+
{P1_1, SPI_0, (SCU_PINIO_SPI | 5)},
53+
{P1_3, SPI_1, (SCU_PINIO_SPI | 5)},
54+
{P3_6, SPI_0, (SCU_PINIO_SPI | 5)},
55+
{P3_7, SPI_0, (SCU_PINIO_SPI | 2)},
56+
{P9_1, SPI_0, (SCU_PINIO_SPI | 7)},
57+
{PF_2, SPI_0, (SCU_PINIO_SPI | 2)},
58+
{PF_6, SPI_1, (SCU_PINIO_SPI | 2)},
5659
{NC, NC, 0}
5760
};
5861

5962
static const PinMap PinMap_SPI_SSEL[] = {
60-
{P1_0, SPI_0, (SCU_PINIO_FAST | 5)},
61-
{P1_5, SPI_1, (SCU_PINIO_FAST | 5)},
62-
{P1_20, SPI_1, (SCU_PINIO_FAST | 2)},
63-
{P3_6, SPI_0, (SCU_PINIO_FAST | 2)},
64-
{P3_8, SPI_0, (SCU_PINIO_FAST | 5)},
65-
{P9_0, SPI_0, (SCU_PINIO_FAST | 7)},
66-
{PF_1, SPI_0, (SCU_PINIO_FAST | 2)},
67-
{PF_5, SPI_1, (SCU_PINIO_FAST | 2)},
63+
{P1_0, SPI_0, (SCU_PINIO_SPI | 5)},
64+
{P1_5, SPI_1, (SCU_PINIO_SPI | 5)},
65+
{P1_20, SPI_1, (SCU_PINIO_SPI | 2)},
66+
{P3_6, SPI_0, (SCU_PINIO_SPI | 2)},
67+
{P3_8, SPI_0, (SCU_PINIO_SPI | 5)},
68+
{P9_0, SPI_0, (SCU_PINIO_SPI | 7)},
69+
{PF_1, SPI_0, (SCU_PINIO_SPI | 2)},
70+
{PF_5, SPI_1, (SCU_PINIO_SPI | 2)},
6871
{NC, NC, 0}
6972
};
7073

@@ -82,6 +85,12 @@ void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel
8285

8386
obj->spi = (LPC_SSP_T*)pinmap_merge(spi_data, spi_cntl);
8487
MBED_ASSERT((int)obj->spi != NC);
88+
89+
// enable clocking
90+
switch ((int)obj->spi) {
91+
case SPI_0: LPC_CGU->BASE_CLK[CLK_BASE_SSP0] = (1 << 11) | (CLKIN_MAINPLL << 24); break;
92+
case SPI_1: LPC_CGU->BASE_CLK[CLK_BASE_SSP1] = (1 << 11) | (CLKIN_MAINPLL << 24); break;
93+
}
8594

8695
// set default format and frequency
8796
if (ssel == NC) {

0 commit comments

Comments
 (0)