Merge pull request #3431 from hierophect/stm32-spi-writevalue
STM32: Change SPI Read to acknowledge write_value
This commit is contained in:
commit
8cf0171c06
@ -102,7 +102,8 @@ CFLAGS += $(INC) -Werror -Wall -std=gnu11 -fshort-enums $(BASE_CFLAGS) $(C_DEFS)
|
|||||||
|
|
||||||
# Undo some warnings.
|
# Undo some warnings.
|
||||||
# STM32 HAL uses undefined preprocessor variables, shadowed variables, casts that change alignment reqs
|
# 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
|
CFLAGS += -mthumb -mabi=aapcs-linux
|
||||||
|
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#include "shared-bindings/busio/SPI.h"
|
#include "shared-bindings/busio/SPI.h"
|
||||||
#include "py/mperrno.h"
|
#include "py/mperrno.h"
|
||||||
@ -340,7 +341,7 @@ bool common_hal_busio_spi_write(busio_spi_obj_t *self,
|
|||||||
if (self->mosi == NULL) {
|
if (self->mosi == NULL) {
|
||||||
mp_raise_ValueError(translate("No MOSI Pin"));
|
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;
|
return result == HAL_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -349,7 +350,13 @@ bool common_hal_busio_spi_read(busio_spi_obj_t *self,
|
|||||||
if (self->miso == NULL) {
|
if (self->miso == NULL) {
|
||||||
mp_raise_ValueError(translate("No MISO Pin"));
|
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;
|
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) {
|
if (self->miso == NULL || self->mosi == NULL) {
|
||||||
mp_raise_ValueError(translate("Missing MISO or MOSI Pin"));
|
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);
|
(uint8_t *) data_out, data_in, (uint16_t)len,HAL_MAX_DELAY);
|
||||||
return result == HAL_OK;
|
return result == HAL_OK;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user