Skip to content

STM32: Change SPI Read to acknowledge write_value #3431

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion ports/stm/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
13 changes: 10 additions & 3 deletions ports/stm/common-hal/busio/SPI.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
* THE SOFTWARE.
*/
#include <stdbool.h>
#include <string.h>

#include "shared-bindings/busio/SPI.h"
#include "py/mperrno.h"
Expand Down Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand All @@ -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;
}
Expand Down