Skip to content

Commit 839bd64

Browse files
committed
STM32: SPI 3 wires mode not supported in SPI slave
This patch handles the case of SPI slave mode without MISO (NC). In case MISO is not connected, we consider that SPI will be configured in 3 wires mode (CLK / MOSI / CS, but no MISO). In this case, the MOSI line is bi-directional : SPI_DIRECTION_1LINE. But as this is not supported yet in slave mode, we force it to SPI_DIRECTION_2LINES. In this case slave SPI will receive data on MOSI but nothing will be sent back to master as MISO is not connected.
1 parent ab1b3ae commit 839bd64

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)