Skip to content

Commit 8cf0171

Browse files
authored
Merge pull request #3431 from hierophect/stm32-spi-writevalue
STM32: Change SPI Read to acknowledge write_value
2 parents 5116375 + 00ee94d commit 8cf0171

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

ports/stm/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@ CFLAGS += $(INC) -Werror -Wall -std=gnu11 -fshort-enums $(BASE_CFLAGS) $(C_DEFS)
102102

103103
# Undo some warnings.
104104
# STM32 HAL uses undefined preprocessor variables, shadowed variables, casts that change alignment reqs
105-
CFLAGS += -Wno-undef -Wno-shadow -Wno-cast-align
105+
# You can add your own temporary suppression by setting ADD_CFLAGS in the make command
106+
CFLAGS += -Wno-undef -Wno-shadow -Wno-cast-align $(ADD_CFLAGS)
106107

107108
CFLAGS += -mthumb -mabi=aapcs-linux
108109

ports/stm/common-hal/busio/SPI.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
* THE SOFTWARE.
2626
*/
2727
#include <stdbool.h>
28+
#include <string.h>
2829

2930
#include "shared-bindings/busio/SPI.h"
3031
#include "py/mperrno.h"
@@ -340,7 +341,7 @@ bool common_hal_busio_spi_write(busio_spi_obj_t *self,
340341
if (self->mosi == NULL) {
341342
mp_raise_ValueError(translate("No MOSI Pin"));
342343
}
343-
HAL_StatusTypeDef result = HAL_SPI_Transmit (&self->handle, (uint8_t *)data, (uint16_t)len, HAL_MAX_DELAY);
344+
HAL_StatusTypeDef result = HAL_SPI_Transmit(&self->handle, (uint8_t *)data, (uint16_t)len, HAL_MAX_DELAY);
344345
return result == HAL_OK;
345346
}
346347

@@ -349,7 +350,13 @@ bool common_hal_busio_spi_read(busio_spi_obj_t *self,
349350
if (self->miso == NULL) {
350351
mp_raise_ValueError(translate("No MISO Pin"));
351352
}
352-
HAL_StatusTypeDef result = HAL_SPI_Receive (&self->handle, data, (uint16_t)len, HAL_MAX_DELAY);
353+
HAL_StatusTypeDef result = HAL_OK;
354+
if (self->mosi == NULL) {
355+
result = HAL_SPI_Receive(&self->handle, data, (uint16_t)len, HAL_MAX_DELAY);
356+
} else {
357+
memset(data, write_value, len);
358+
result = HAL_SPI_TransmitReceive(&self->handle, data, data, (uint16_t)len, HAL_MAX_DELAY);
359+
}
353360
return result == HAL_OK;
354361
}
355362

@@ -358,7 +365,7 @@ bool common_hal_busio_spi_transfer(busio_spi_obj_t *self,
358365
if (self->miso == NULL || self->mosi == NULL) {
359366
mp_raise_ValueError(translate("Missing MISO or MOSI Pin"));
360367
}
361-
HAL_StatusTypeDef result = HAL_SPI_TransmitReceive (&self->handle,
368+
HAL_StatusTypeDef result = HAL_SPI_TransmitReceive(&self->handle,
362369
(uint8_t *) data_out, data_in, (uint16_t)len,HAL_MAX_DELAY);
363370
return result == HAL_OK;
364371
}

0 commit comments

Comments
 (0)