mbed

Fork of mbed-dev by mbed official

Revision:
180:b0033dcd6934
Parent:
174:e131a1973e81
Child:
182:57724642e740
--- a/targets/TARGET_STM/stm_spi_api.c	Thu Nov 23 11:57:25 2017 +0000
+++ b/targets/TARGET_STM/stm_spi_api.c	Thu Dec 07 14:01:42 2017 +0000
@@ -29,6 +29,7 @@
  */
 #include "mbed_assert.h"
 #include "mbed_error.h"
+#include "mbed_debug.h"
 #include "spi_api.h"
 
 #if DEVICE_SPI
@@ -286,6 +287,16 @@
 
     handle->Init.Mode = (slave) ? SPI_MODE_SLAVE : SPI_MODE_MASTER;
 
+    if (slave && (handle->Init.Direction == SPI_DIRECTION_1LINE)) {
+        /*  SPI slave implemtation in MBED does not support the 3 wires SPI.
+         *  (e.g. when MISO is not connected). So we're forcing slave in
+         *  2LINES mode. As MISO is not connected, slave will only read
+         *  from master, and cannot write to it. Inform user.
+         */
+        debug("3 wires SPI slave not supported - slave will only read\r\n");
+        handle->Init.Direction = SPI_DIRECTION_2LINES;
+    }
+
     init_spi(obj);
 }