summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Shawcroft <scott@adafruit.com>2021-02-08 16:29:48 -0800
committerGitHub <noreply@github.com>2021-02-08 16:29:48 -0800
commit0ceac79dfb1bc1df9e0c25f1eebc9ab1074cf905 (patch)
tree7d17345120cfb597462ade75e3e99623a0ed9339
parent3c99b0999315a7fa2114cbad98fe7f4058cc1562 (diff)
parent5bf08c503ba50fc24652c1d8720aee8c6e7de627 (diff)
Merge pull request #4048 from janderit/fix_3763_mimxrt10xx_spi
fixes: busio, SPI OS error 5 for mimxrt10xx
-rw-r--r--ports/mimxrt10xx/common-hal/busio/SPI.c23
1 files changed, 20 insertions, 3 deletions
diff --git a/ports/mimxrt10xx/common-hal/busio/SPI.c b/ports/mimxrt10xx/common-hal/busio/SPI.c
index ce7cbea7e..00d8d9867 100644
--- a/ports/mimxrt10xx/common-hal/busio/SPI.c
+++ b/ports/mimxrt10xx/common-hal/busio/SPI.c
@@ -38,6 +38,8 @@
#define LPSPI_MASTER_CLK_FREQ (CLOCK_GetFreq(kCLOCK_Usb1PllPfd0Clk) / (CLOCK_GetDiv(kCLOCK_LpspiDiv) + 1))
+#define MAX_SPI_BUSY_RETRIES 100
+
//arrays use 0 based numbering: SPI1 is stored at index 0
#define MAX_SPI 4
STATIC bool reserved_spi[MAX_SPI];
@@ -289,7 +291,12 @@ bool common_hal_busio_spi_write(busio_spi_obj_t *self,
xfer.dataSize = len;
xfer.configFlags = kLPSPI_MasterPcs0;
- const status_t status = LPSPI_MasterTransferBlocking(self->spi, &xfer);
+ status_t status;
+ int retries = MAX_SPI_BUSY_RETRIES;
+ do {
+ status = LPSPI_MasterTransferBlocking(self->spi, &xfer);
+ } while (status == kStatus_LPSPI_Busy && --retries > 0);
+
if (status != kStatus_Success)
printf("%s: status %ld\r\n", __func__, status);
@@ -311,7 +318,12 @@ bool common_hal_busio_spi_read(busio_spi_obj_t *self,
xfer.rxData = data;
xfer.dataSize = len;
- const status_t status = LPSPI_MasterTransferBlocking(self->spi, &xfer);
+ status_t status;
+ int retries = MAX_SPI_BUSY_RETRIES;
+ do {
+ status = LPSPI_MasterTransferBlocking(self->spi, &xfer);
+ } while (status == kStatus_LPSPI_Busy && --retries > 0);
+
if (status != kStatus_Success)
printf("%s: status %ld\r\n", __func__, status);
@@ -333,7 +345,12 @@ bool common_hal_busio_spi_transfer(busio_spi_obj_t *self, const uint8_t *data_ou
xfer.rxData = data_in;
xfer.dataSize = len;
- const status_t status = LPSPI_MasterTransferBlocking(self->spi, &xfer);
+ status_t status;
+ int retries = MAX_SPI_BUSY_RETRIES;
+ do {
+ status = LPSPI_MasterTransferBlocking(self->spi, &xfer);
+ } while (status == kStatus_LPSPI_Busy && --retries > 0);
+
if (status != kStatus_Success)
printf("%s: status %ld\r\n", __func__, status);