From 00ee94d24b407768612a5f2a40c4099a7899aa0b Mon Sep 17 00:00:00 2001 From: Lucian Copeland Date: Wed, 16 Sep 2020 14:05:15 -0400 Subject: [PATCH] Add SPI memset, optional flags --- ports/stm/Makefile | 3 ++- ports/stm/common-hal/busio/SPI.c | 13 ++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/ports/stm/Makefile b/ports/stm/Makefile index dccc749ed8..9e1d10b998 100755 --- a/ports/stm/Makefile +++ b/ports/stm/Makefile @@ -102,7 +102,8 @@ CFLAGS += $(INC) -Werror -Wall -std=gnu11 -fshort-enums $(BASE_CFLAGS) $(C_DEFS) # Undo some warnings. # STM32 HAL uses undefined preprocessor variables, shadowed variables, casts that change alignment reqs -CFLAGS += -Wno-undef -Wno-shadow -Wno-cast-align +# You can add your own temporary suppression by setting ADD_CFLAGS in the make command +CFLAGS += -Wno-undef -Wno-shadow -Wno-cast-align $(ADD_CFLAGS) CFLAGS += -mthumb -mabi=aapcs-linux diff --git a/ports/stm/common-hal/busio/SPI.c b/ports/stm/common-hal/busio/SPI.c index 0354d64ad3..913385e962 100644 --- a/ports/stm/common-hal/busio/SPI.c +++ b/ports/stm/common-hal/busio/SPI.c @@ -25,6 +25,7 @@ * THE SOFTWARE. */ #include +#include #include "shared-bindings/busio/SPI.h" #include "py/mperrno.h" @@ -340,7 +341,7 @@ bool common_hal_busio_spi_write(busio_spi_obj_t *self, if (self->mosi == NULL) { mp_raise_ValueError(translate("No MOSI Pin")); } - HAL_StatusTypeDef result = HAL_SPI_Transmit (&self->handle, (uint8_t *)data, (uint16_t)len, HAL_MAX_DELAY); + HAL_StatusTypeDef result = HAL_SPI_Transmit(&self->handle, (uint8_t *)data, (uint16_t)len, HAL_MAX_DELAY); return result == HAL_OK; } @@ -349,7 +350,13 @@ bool common_hal_busio_spi_read(busio_spi_obj_t *self, if (self->miso == NULL) { mp_raise_ValueError(translate("No MISO Pin")); } - HAL_StatusTypeDef result = HAL_SPI_Receive (&self->handle, data, (uint16_t)len, HAL_MAX_DELAY); + HAL_StatusTypeDef result = HAL_OK; + if (self->mosi == NULL) { + result = HAL_SPI_Receive(&self->handle, data, (uint16_t)len, HAL_MAX_DELAY); + } else { + memset(data, write_value, len); + result = HAL_SPI_TransmitReceive(&self->handle, data, data, (uint16_t)len, HAL_MAX_DELAY); + } return result == HAL_OK; } @@ -358,7 +365,7 @@ bool common_hal_busio_spi_transfer(busio_spi_obj_t *self, if (self->miso == NULL || self->mosi == NULL) { mp_raise_ValueError(translate("Missing MISO or MOSI Pin")); } - HAL_StatusTypeDef result = HAL_SPI_TransmitReceive (&self->handle, + HAL_StatusTypeDef result = HAL_SPI_TransmitReceive(&self->handle, (uint8_t *) data_out, data_in, (uint16_t)len,HAL_MAX_DELAY); return result == HAL_OK; }