Skip to content

Commit 45e9e4c

Browse files
authored
Merge pull request #5565 from LMESTM/fix_slave_3wires
STM32: SPI 3 wires mode not supported in SPI slave
2 parents 118c1bb + 839bd64 commit 45e9e4c

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

targets/TARGET_STM/stm_spi_api.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
*/
3030
#include "mbed_assert.h"
3131
#include "mbed_error.h"
32+
#include "mbed_debug.h"
3233
#include "spi_api.h"
3334

3435
#if DEVICE_SPI
@@ -286,6 +287,16 @@ void spi_format(spi_t *obj, int bits, int mode, int slave)
286287

287288
handle->Init.Mode = (slave) ? SPI_MODE_SLAVE : SPI_MODE_MASTER;
288289

290+
if (slave && (handle->Init.Direction == SPI_DIRECTION_1LINE)) {
291+
/* SPI slave implemtation in MBED does not support the 3 wires SPI.
292+
* (e.g. when MISO is not connected). So we're forcing slave in
293+
* 2LINES mode. As MISO is not connected, slave will only read
294+
* from master, and cannot write to it. Inform user.
295+
*/
296+
debug("3 wires SPI slave not supported - slave will only read\r\n");
297+
handle->Init.Direction = SPI_DIRECTION_2LINES;
298+
}
299+
289300
init_spi(obj);
290301
}
291302

0 commit comments

Comments
 (0)