Skip to content

Commit e019d7a

Browse files
mmahadevan108Evelyne Donnaes
authored andcommitted
MCUXpresso: Update LPC SPI HAL driver
Add support for different slave selects Signed-off-by: Mahesh Mahadevan <[email protected]>
1 parent ccb8f25 commit e019d7a

File tree

10 files changed

+14
-7
lines changed

10 files changed

+14
-7
lines changed

targets/TARGET_NXP/TARGET_MCUXpresso_MCUS/TARGET_LPC/objects.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ struct i2c_s {
5858
struct spi_s {
5959
uint32_t instance;
6060
uint8_t bits;
61+
uint8_t ssel_num;
6162
};
6263

6364
#if DEVICE_FLASH && !defined(TARGET_FLASH_CMSIS_ALGO)

targets/TARGET_NXP/TARGET_MCUXpresso_MCUS/TARGET_LPC/pinmap.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ void pin_function(PinName pin, int function)
3333
IOCON->PIO[port_number][pin_number] |= IOCON_PIO_DIGIMODE_MASK;
3434

3535
reg = IOCON->PIO[port_number][pin_number];
36-
reg = (reg & ~0x7) | (function & IOCON_PIO_FUNC_MASK);
36+
reg = (reg & ~IOCON_PIO_FUNC_MASK) | (function & IOCON_PIO_FUNC_MASK);
3737
IOCON->PIO[port_number][pin_number] = reg;
3838
}
3939

targets/TARGET_NXP/TARGET_MCUXpresso_MCUS/TARGET_LPC/spi_api.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel
4242

4343
obj->instance = pinmap_merge(spi_data, spi_cntl);
4444
MBED_ASSERT((int)obj->instance != NC);
45+
obj->ssel_num = 0;
4546

4647
switch (obj->instance) {
4748
case 0:
@@ -96,6 +97,7 @@ void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel
9697
pinmap_pinout(sclk, PinMap_SPI_SCLK);
9798
if (ssel != NC) {
9899
pinmap_pinout(ssel, PinMap_SPI_SSEL);
100+
obj->ssel_num = pinmap_function(ssel, PinMap_SPI_SSEL) >> SSELNUM_SHIFT;
99101
}
100102
}
101103

@@ -128,6 +130,7 @@ void spi_format(spi_t *obj, int bits, int mode, int slave)
128130
master_config.polarity = (mode & 0x2) ? kSPI_ClockPolarityActiveLow : kSPI_ClockPolarityActiveHigh;
129131
master_config.phase = (mode & 0x1) ? kSPI_ClockPhaseSecondEdge : kSPI_ClockPhaseFirstEdge;
130132
master_config.direction = kSPI_MsbFirst;
133+
master_config.sselNum = obj->ssel_num;
131134
if (baud_rate > 0) {
132135
master_config.baudRate_Bps = baud_rate;
133136
}

targets/TARGET_NXP/TARGET_MCUXpresso_MCUS/TARGET_LPC54114/TARGET_LPCXpresso/PeripheralNames.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ typedef enum {
9494
ADC0_SE11 = 11,
9595
} ADCName;
9696

97-
97+
#define SSELNUM_SHIFT 16
9898
typedef enum {
9999
SPI_0 = Flexcomm3,
100100
SPI_1 = Flexcomm5

targets/TARGET_NXP/TARGET_MCUXpresso_MCUS/TARGET_LPC54114/TARGET_LPCXpresso/PeripheralPins.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ const PinMap PinMap_SPI_MISO[] = {
9090

9191
const PinMap PinMap_SPI_SSEL[] = {
9292
{P0_14, SPI_0, 1},
93-
{P1_1, SPI_1, 4},
94-
{P1_2, SPI_1, 4},
93+
{P1_1, SPI_1, ((2 << SSELNUM_SHIFT) | 4)},
94+
{P1_2, SPI_1, ((3 << SSELNUM_SHIFT) | 4)},
9595
{NC , NC , 0}
9696
};
9797

targets/TARGET_NXP/TARGET_MCUXpresso_MCUS/TARGET_LPC55S69/TARGET_LPCXpresso/PeripheralNames.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ typedef enum {
104104
CAN_1 = 1
105105
} CANName;
106106

107+
#define SSELNUM_SHIFT 16
107108
typedef enum {
108109
SPI_0 = Flexcomm3,
109110
SPI_1 = Flexcomm7,

targets/TARGET_NXP/TARGET_MCUXpresso_MCUS/TARGET_LPC55S69/TARGET_LPCXpresso/PeripheralPins.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ const PinMap PinMap_SPI_MISO[] = {
113113

114114
const PinMap PinMap_SPI_SSEL[] = {
115115
{P0_4, SPI_0, 8},
116-
{P1_20, SPI_1, 1},
117-
{P1_1, SPI_2, 5},
116+
{P1_20, SPI_1, ((1 << SSELNUM_SHIFT) | 1)},
117+
{P1_1, SPI_2, ((1 << SSELNUM_SHIFT) | 5)},
118118
{NC , NC , 0}
119119
};
120120

targets/TARGET_NXP/TARGET_MCUXpresso_MCUS/TARGET_MCU_LPC546XX/TARGET_FF_LPC546XX/PeripheralNames.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ typedef enum {
100100
CAN_1 = 1
101101
} CANName;
102102

103+
#define SSELNUM_SHIFT 16
103104
typedef enum {
104105
SPI_0 = Flexcomm0,
105106
SPI_2 = Flexcomm2,

targets/TARGET_NXP/TARGET_MCUXpresso_MCUS/TARGET_MCU_LPC546XX/TARGET_LPCXpresso/PeripheralNames.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ typedef enum {
100100
CAN_1 = 1
101101
} CANName;
102102

103+
#define SSELNUM_SHIFT 16
103104
typedef enum {
104105
SPI_0 = Flexcomm3,
105106
SPI_1 = Flexcomm9

targets/TARGET_NXP/TARGET_MCUXpresso_MCUS/TARGET_MCU_LPC546XX/TARGET_LPCXpresso/PeripheralPins.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ const PinMap PinMap_SPI_MISO[] = {
107107
const PinMap PinMap_SPI_SSEL[] = {
108108
{P0_1, SPI_0, 2},
109109
{P3_30, SPI_1, 1},
110-
{P4_6, SPI_1, 2},
110+
{P4_6, SPI_1, ((1 << SSELNUM_SHIFT) | 2)},
111111
{NC , NC , 0}
112112
};
113113

0 commit comments

Comments
 (0)