Skip to content

Commit 70fad08

Browse files
committed
Update SPI API documentation for hardware driven SS. Modify all target spi_api.c implementations. spi_init ssel parameter was used incorrectly to determine master/slave mode rather than enable hardware driven SS (seems to be due to legacy copy paste). Remove duplicate copy paste code of initialization in spi_init that is done by constructor (SPI and SPISlave)
1 parent 5a81e89 commit 70fad08

File tree

31 files changed

+76
-296
lines changed

31 files changed

+76
-296
lines changed

libraries/mbed/api/SPI.h

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,21 @@ namespace mbed {
3737
*
3838
* #include "mbed.h"
3939
*
40+
* // hardware ssel (where applicable)
41+
* //SPI device(p5, p6, p7, p8); // mosi, miso, sclk, ssel
42+
*
43+
* // software ssel
4044
* SPI device(p5, p6, p7); // mosi, miso, sclk
45+
* DigitalOut cs(p8); // ssel
4146
*
4247
* int main() {
48+
* // hardware ssel (where applicable)
49+
* //int response = device.write(0xFF);
50+
*
51+
* // software ssel
52+
* cs = 0;
4353
* int response = device.write(0xFF);
54+
* cs = 1;
4455
* }
4556
* @endcode
4657
*/
@@ -49,17 +60,15 @@ class SPI {
4960
public:
5061

5162
/** Create a SPI master connected to the specified pins
52-
*
53-
* Pin Options:
54-
* (5, 6, 7) or (11, 12, 13)
5563
*
5664
* mosi or miso can be specfied as NC if not used
5765
*
5866
* @param mosi SPI Master Out, Slave In pin
5967
* @param miso SPI Master In, Slave Out pin
6068
* @param sclk SPI Clock pin
69+
* @param ssel SPI chip select pin
6170
*/
62-
SPI(PinName mosi, PinName miso, PinName sclk, PinName _unused=NC);
71+
SPI(PinName mosi, PinName miso, PinName sclk, PinName ssel=NC);
6372

6473
/** Configure the data transmission format
6574
*

libraries/mbed/api/SPISlave.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,13 @@ class SPISlave {
5353
public:
5454

5555
/** Create a SPI slave connected to the specified pins
56-
*
57-
* Pin Options:
58-
* (5, 6, 7i, 8) or (11, 12, 13, 14)
5956
*
6057
* mosi or miso can be specfied as NC if not used
6158
*
6259
* @param mosi SPI Master Out, Slave In pin
6360
* @param miso SPI Master In, Slave Out pin
6461
* @param sclk SPI Clock pin
6562
* @param ssel SPI chip select pin
66-
* @param name (optional) A string to identify the object
6763
*/
6864
SPISlave(PinName mosi, PinName miso, PinName sclk, PinName ssel);
6965

libraries/mbed/common/SPI.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@
1919

2020
namespace mbed {
2121

22-
SPI::SPI(PinName mosi, PinName miso, PinName sclk, PinName _unused) :
22+
SPI::SPI(PinName mosi, PinName miso, PinName sclk, PinName ssel) :
2323
_spi(),
2424
_bits(8),
2525
_mode(0),
2626
_hz(1000000) {
27-
spi_init(&_spi, mosi, miso, sclk, NC);
27+
spi_init(&_spi, mosi, miso, sclk, ssel);
2828
spi_format(&_spi, _bits, _mode, 0);
2929
spi_frequency(&_spi, _hz);
3030
}

libraries/mbed/targets/hal/TARGET_Freescale/TARGET_K20XX/spi_api.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,6 @@ void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel
4141
obj->spi->MCR &= ~(SPI_MCR_MDIS_MASK | SPI_MCR_HALT_MASK);
4242
//obj->spi->MCR |= SPI_MCR_DIS_RXF_MASK | SPI_MCR_DIS_TXF_MASK;
4343

44-
// set default format and frequency
45-
if (ssel == NC) {
46-
spi_format(obj, 8, 0, 0); // 8 bits, mode 0, master
47-
} else {
48-
spi_format(obj, 8, 0, 1); // 8 bits, mode 0, slave
49-
}
50-
spi_frequency(obj, 1000000);
51-
5244
// not halt in the debug mode
5345
obj->spi->SR |= SPI_SR_EOQF_MASK;
5446

libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KLXX/TARGET_KL05Z/spi_api.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,6 @@ void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel
6060
break;
6161
}
6262

63-
// set default format and frequency
64-
if (ssel == NC) {
65-
spi_format(obj, 8, 0, 0); // 8 bits, mode 0, master
66-
} else {
67-
spi_format(obj, 8, 0, 1); // 8 bits, mode 0, slave
68-
}
69-
spi_frequency(obj, 1000000);
70-
7163
// enable SPI
7264
obj->spi->C1 |= SPI_C1_SPE_MASK;
7365

libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KLXX/TARGET_KL25Z/spi_api.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,6 @@ void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel
4040
case SPI_1: SIM->SCGC5 |= 1 << 13; SIM->SCGC4 |= 1 << 23; break;
4141
}
4242

43-
// set default format and frequency
44-
if (ssel == NC) {
45-
spi_format(obj, 8, 0, 0); // 8 bits, mode 0, master
46-
} else {
47-
spi_format(obj, 8, 0, 1); // 8 bits, mode 0, slave
48-
}
49-
spi_frequency(obj, 1000000);
50-
5143
// enable SPI
5244
obj->spi->C1 |= SPI_C1_SPE_MASK;
5345

libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KLXX/TARGET_KL43Z/spi_api.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,6 @@ void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel
8181
case SPI_1: SIM->SCGC5 |= 1 << 13; SIM->SCGC4 |= 1 << 23; break;
8282
}
8383

84-
// set default format and frequency
85-
if (ssel == NC) {
86-
spi_format(obj, 8, 0, 0); // 8 bits, mode 0, master
87-
} else {
88-
spi_format(obj, 8, 0, 1); // 8 bits, mode 0, slave
89-
}
90-
spi_frequency(obj, 1000000);
91-
9284
// enable SPI
9385
obj->spi->C1 |= SPI_C1_SPE_MASK;
9486
obj->spi->C2 &= ~SPI_C2_SPIMODE_MASK; //8bit

libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KLXX/TARGET_KL46Z/spi_api.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,6 @@ void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel
9898
case SPI_1: SIM->SCGC5 |= 1 << 13; SIM->SCGC4 |= 1 << 23; break;
9999
}
100100

101-
// set default format and frequency
102-
if (ssel == NC) {
103-
spi_format(obj, 8, 0, 0); // 8 bits, mode 0, master
104-
} else {
105-
spi_format(obj, 8, 0, 1); // 8 bits, mode 0, slave
106-
}
107-
spi_frequency(obj, 1000000);
108-
109101
// enable SPI
110102
obj->spi->C1 |= SPI_C1_SPE_MASK;
111103
obj->spi->C2 &= ~SPI_C2_SPIMODE_MASK; //8bit

libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/spi_api.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,7 @@ void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel
4343
uint32_t spi_address[] = SPI_BASE_ADDRS;
4444
DSPI_HAL_Init(spi_address[obj->instance]);
4545
DSPI_HAL_Disable(spi_address[obj->instance]);
46-
// set default format and frequency
47-
if (ssel == NC) {
48-
spi_format(obj, 8, 0, 0); // 8 bits, mode 0, master
49-
} else {
50-
spi_format(obj, 8, 0, 1); // 8 bits, mode 0, slave
51-
}
5246
DSPI_HAL_SetDelay(spi_address[obj->instance], kDspiCtar0, 0, 0, kDspiPcsToSck);
53-
spi_frequency(obj, 1000000);
5447

5548
DSPI_HAL_Enable(spi_address[obj->instance]);
5649
DSPI_HAL_StartTransfer(spi_address[obj->instance]);

libraries/mbed/targets/hal/TARGET_Maxim/TARGET_MAX32610/spi_api.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,6 @@ void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel
8888
obj->spi->gen_ctrl = (MXC_F_SPI_GEN_CTRL_SPI_MSTR_EN |
8989
MXC_F_SPI_GEN_CTRL_TX_FIFO_EN |
9090
MXC_F_SPI_GEN_CTRL_RX_FIFO_EN );
91-
92-
// Give instance the default settings
93-
spi_format(obj, DEFAULT_CHAR, DEFAULT_MODE, 0);
94-
spi_frequency(obj, DEFAULT_FREQ);
9591
}
9692

9793
//******************************************************************************

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

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -85,17 +85,6 @@ void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel
8585
break;
8686
}
8787

88-
// set default format and frequency
89-
if (ssel == NC) {
90-
spi_format(obj, 8, 0, 0); // 8 bits, mode 0, master
91-
} else {
92-
spi_format(obj, 8, 0, 1); // 8 bits, mode 0, slave
93-
}
94-
spi_frequency(obj, 1000000);
95-
96-
// enable the ssp channel
97-
ssp_enable(obj);
98-
9988
// pin out the spi pins
10089
pinmap_pinout(mosi, PinMap_SPI_MOSI);
10190
pinmap_pinout(miso, PinMap_SPI_MISO);

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

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,6 @@ void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel
5050
break;
5151
}
5252

53-
// set default format and frequency
54-
if (ssel == NC) {
55-
spi_format(obj, 8, 0, 0); // 8 bits, mode 0, master
56-
} else {
57-
spi_format(obj, 8, 0, 1); // 8 bits, mode 0, slave
58-
}
59-
spi_frequency(obj, 1000000);
60-
61-
// enable the ssp channel
62-
ssp_enable(obj);
63-
6453
// pin out the spi pins
6554
pinmap_pinout(mosi, PinMap_SPI_MOSI);
6655
pinmap_pinout(miso, PinMap_SPI_MISO);

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

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -87,17 +87,6 @@ void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel
8787
break;
8888
}
8989

90-
// set default format and frequency
91-
if (ssel == NC) {
92-
spi_format(obj, 8, 0, 0); // 8 bits, mode 0, master
93-
} else {
94-
spi_format(obj, 8, 0, 1); // 8 bits, mode 0, slave
95-
}
96-
spi_frequency(obj, 1000000);
97-
98-
// enable the ssp channel
99-
ssp_enable(obj);
100-
10190
// pin out the spi pins
10291
pinmap_pinout(mosi, PinMap_SPI_MOSI);
10392
pinmap_pinout(miso, PinMap_SPI_MISO);

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

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -79,17 +79,6 @@ void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel
7979
break;
8080
}
8181

82-
// set default format and frequency
83-
if (ssel == NC) {
84-
spi_format(obj, 8, 0, 0); // 8 bits, mode 0, master
85-
} else {
86-
spi_format(obj, 8, 0, 1); // 8 bits, mode 0, slave
87-
}
88-
spi_frequency(obj, 1000000);
89-
90-
// enable the ssp channel
91-
ssp_enable(obj);
92-
9382
// pin out the spi pins
9483
pinmap_pinout(mosi, PinMap_SPI_MOSI);
9584
pinmap_pinout(miso, PinMap_SPI_MISO);

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

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -158,17 +158,6 @@ void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel
158158
LPC_SYSCON->SYSAHBCLKCTRL1 |= (0x1 << (obj->spi_n + 9));
159159
LPC_SYSCON->PRESETCTRL1 |= (0x1 << (obj->spi_n + 9));
160160
LPC_SYSCON->PRESETCTRL1 &= ~(0x1 << (obj->spi_n + 9));
161-
162-
// set default format and frequency
163-
if (ssel == NC) {
164-
spi_format(obj, 8, 0, 0); // 8 bits, mode 0, master
165-
} else {
166-
spi_format(obj, 8, 0, 1); // 8 bits, mode 0, slave
167-
}
168-
spi_frequency(obj, 1000000);
169-
170-
// enable the spi channel
171-
spi_enable(obj);
172161
}
173162

174163
void spi_free(spi_t *obj)

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

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -72,17 +72,6 @@ void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel
7272
case SPI_0: LPC_SC->PCONP |= 1 << 21; break;
7373
case SPI_1: LPC_SC->PCONP |= 1 << 10; break;
7474
}
75-
76-
// set default format and frequency
77-
if (ssel == NC) {
78-
spi_format(obj, 8, 0, 0); // 8 bits, mode 0, master
79-
} else {
80-
spi_format(obj, 8, 0, 1); // 8 bits, mode 0, slave
81-
}
82-
spi_frequency(obj, 1000000);
83-
84-
// enable the ssp channel
85-
ssp_enable(obj);
8675

8776
// pin out the spi pins
8877
pinmap_pinout(mosi, PinMap_SPI_MOSI);

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

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -73,17 +73,6 @@ void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel
7373
case SPI_1: LPC_SC->PCONP |= 1 << 10; break;
7474
}
7575

76-
// set default format and frequency
77-
if (ssel == NC) {
78-
spi_format(obj, 8, 0, 0); // 8 bits, mode 0, master
79-
} else {
80-
spi_format(obj, 8, 0, 1); // 8 bits, mode 0, slave
81-
}
82-
spi_frequency(obj, 1000000);
83-
84-
// enable the ssp channel
85-
ssp_enable(obj);
86-
8776
// pin out the spi pins
8877
pinmap_pinout(mosi, PinMap_SPI_MOSI);
8978
pinmap_pinout(miso, PinMap_SPI_MISO);

libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC408X/TARGET_LPC4088/spi_api.c

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -93,17 +93,6 @@ void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel
9393
case SPI_2: LPC_SC->PCONP |= 1 << 20; break;
9494
}
9595

96-
// set default format and frequency
97-
if (ssel == NC) {
98-
spi_format(obj, 8, 0, 0); // 8 bits, mode 0, master
99-
} else {
100-
spi_format(obj, 8, 0, 1); // 8 bits, mode 0, slave
101-
}
102-
spi_frequency(obj, 1000000);
103-
104-
// enable the ssp channel
105-
ssp_enable(obj);
106-
10796
// pin out the spi pins
10897
pinmap_pinout(mosi, PinMap_SPI_MOSI);
10998
pinmap_pinout(miso, PinMap_SPI_MISO);

libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC408X/TARGET_LPC4088_DM/spi_api.c

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -73,17 +73,6 @@ void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel
7373
case SPI_2: LPC_SC->PCONP |= 1 << 20; break;
7474
}
7575

76-
// set default format and frequency
77-
if (ssel == NC) {
78-
spi_format(obj, 8, 0, 0); // 8 bits, mode 0, master
79-
} else {
80-
spi_format(obj, 8, 0, 1); // 8 bits, mode 0, slave
81-
}
82-
spi_frequency(obj, 1000000);
83-
84-
// enable the ssp channel
85-
ssp_enable(obj);
86-
8776
// pin out the spi pins
8877
pinmap_pinout(mosi, PinMap_SPI_MOSI);
8978
pinmap_pinout(miso, PinMap_SPI_MISO);

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

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -91,17 +91,6 @@ void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel
9191
case SPI_0: LPC_CGU->BASE_CLK[CLK_BASE_SSP0] = (1 << 11) | (CLKIN_MAINPLL << 24); break;
9292
case SPI_1: LPC_CGU->BASE_CLK[CLK_BASE_SSP1] = (1 << 11) | (CLKIN_MAINPLL << 24); break;
9393
}
94-
95-
// set default format and frequency
96-
if (ssel == NC) {
97-
spi_format(obj, 8, 0, 0); // 8 bits, mode 0, master
98-
} else {
99-
spi_format(obj, 8, 0, 1); // 8 bits, mode 0, slave
100-
}
101-
spi_frequency(obj, 1000000);
102-
103-
// enable the ssp channel
104-
ssp_enable(obj);
10594

10695
// pin out the spi pins
10796
pinmap_pinout(mosi, PinMap_SPI_MOSI);

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

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -100,17 +100,6 @@ void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel
100100
LPC_SYSCON->PRESETCTRL |= (0x1<<1);
101101
break;
102102
}
103-
104-
// set default format and frequency
105-
if (ssel == NC) {
106-
spi_format(obj, 8, 0, 0); // 8 bits, mode 0, master
107-
} else {
108-
spi_format(obj, 8, 0, 1); // 8 bits, mode 0, slave
109-
}
110-
spi_frequency(obj, 1000000);
111-
112-
// enable the ssp channel
113-
ssp_enable(obj);
114103
}
115104

116105
void spi_free(spi_t *obj) {}

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

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -103,17 +103,7 @@ void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel
103103
LPC_SYSCON->PRESETCTRL &= ~(1 << obj->spi_n);
104104
LPC_SYSCON->PRESETCTRL |= (1 << obj->spi_n);
105105

106-
// set default format and frequency
107-
if (ssel == (PinName)NC) {
108-
spi_format(obj, 8, 0, 0); // 8 bits, mode 0, master
109-
} else {
110-
spi_format(obj, 8, 0, 1); // 8 bits, mode 0, slave
111-
}
112-
spi_frequency(obj, 1000000);
113106
obj->spi->DLY = 2; // 2 SPI clock times pre-delay
114-
115-
// enable the ssp channel
116-
spi_enable(obj);
117107
}
118108

119109
void spi_free(spi_t *obj)

0 commit comments

Comments
 (0)