mbed library sources

Dependents:   Encrypted my_mbed lklk CyaSSL_DTLS_Cellular ... more

Superseded

This library was superseded by mbed-dev - https://os.mbed.com/users/mbed_official/code/mbed-dev/.

Development branch of the mbed library sources. This library is kept in synch with the latest changes from the mbed SDK and it is not guaranteed to work.

If you are looking for a stable and tested release, please import one of the official mbed library releases:

Import librarymbed

The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Revision:
335:6848febe3436
Parent:
239:8cadf13dff33
Child:
402:09075a3b15e3
--- a/targets/hal/TARGET_STM/TARGET_NUCLEO_F072RB/spi_api.c	Tue Sep 30 15:30:06 2014 +0100
+++ b/targets/hal/TARGET_STM/TARGET_NUCLEO_F072RB/spi_api.c	Fri Oct 03 16:45:07 2014 +0100
@@ -241,13 +241,12 @@
 static inline void ssp_write(spi_t *obj, int value) {
     SPI_TypeDef *spi = (SPI_TypeDef *)(obj->spi);
     while (!ssp_writeable(obj));
-
-    if (obj->bits <= SPI_DATASIZE_8BIT) {
-        // force 8-bit access the data register due to SPI data buffer in this device
+    if (obj->bits == SPI_DATASIZE_8BIT) {
+        // Force 8-bit access to the data register
         uint8_t *p_spi_dr = 0;
         p_spi_dr = (uint8_t *) & (spi->DR);
         *p_spi_dr = (uint8_t)value;
-    } else {
+    } else { // SPI_DATASIZE_16BIT
         spi->DR = (uint16_t)value;
     }
 }
@@ -255,9 +254,8 @@
 static inline int ssp_read(spi_t *obj) {
     SPI_TypeDef *spi = (SPI_TypeDef *)(obj->spi);
     while (!ssp_readable(obj));
-
-    if (obj->bits <= SPI_DATASIZE_8BIT) {
-        // force 8-bit access the data register due to SPI data buffer in this device
+    if (obj->bits == SPI_DATASIZE_8BIT) {
+        // Force 8-bit access to the data register
         uint8_t *p_spi_dr = 0;
         p_spi_dr = (uint8_t *) & (spi->DR);
         return (int)(*p_spi_dr);
@@ -285,13 +283,27 @@
 int spi_slave_read(spi_t *obj) {
     SPI_TypeDef *spi = (SPI_TypeDef *)(obj->spi);
     while (!ssp_readable(obj));
-    return (int)spi->DR;
+    if (obj->bits == SPI_DATASIZE_8BIT) {
+        // Force 8-bit access to the data register
+        uint8_t *p_spi_dr = 0;
+        p_spi_dr = (uint8_t *) & (spi->DR);
+        return (int)(*p_spi_dr);
+    } else {
+        return (int)spi->DR;
+    }
 }
 
 void spi_slave_write(spi_t *obj, int value) {
     SPI_TypeDef *spi = (SPI_TypeDef *)(obj->spi);
     while (!ssp_writeable(obj));
-    spi->DR = (uint16_t)value;
+    if (obj->bits == SPI_DATASIZE_8BIT) {
+        // Force 8-bit access to the data register
+        uint8_t *p_spi_dr = 0;
+        p_spi_dr = (uint8_t *) & (spi->DR);
+        *p_spi_dr = (uint8_t)value;
+    } else { // SPI_DATASIZE_16BIT
+        spi->DR = (uint16_t)value;
+    }
 }
 
 int spi_busy(spi_t *obj) {