8000 Merge pull request #4048 from janderit/fix_3763_mimxrt10xx_spi · alexbartlow/circuitpython@0ceac79 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0ceac79

Browse files
authored
Merge pull request adafruit#4048 from janderit/fix_3763_mimxrt10xx_spi
fixes: busio, SPI OS error 5 for mimxrt10xx
2 parents 3c99b09 + 5bf08c5 commit 0ceac79

File tree

1 file changed

+20
-3
lines changed
  • ports/mimxrt10xx/common-hal/busio

1 file changed

+20
-3
lines changed

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

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838

3939
#define LPSPI_MASTER_CLK_FREQ (CLOCK_GetFreq(kCLOCK_Usb1PllPfd0Clk) / (CLOCK_GetDiv(kCLOCK_LpspiDiv) + 1))
4040

41+
#define MAX_SPI_BUSY_RETRIES 100
42+
4143
//arrays use 0 based numbering: SPI1 is stored at index 0
4244
#define MAX_SPI 4
4345
STATIC bool reserved_spi[MAX_SPI];
@@ -289,7 +291,12 @@ bool common_hal_busio_spi_write(busio_spi_obj_t *self,
289291
xfer.dataSize = len;
290292
xfer.configFlags = kLPSPI_MasterPcs0;
291293

292-
const status_t status = LPSPI_MasterTransferBlocking(self->spi, &xfer);
294+
status_t status;
295+
int retries = MAX_SPI_BUSY_RETRIES;
296+
do {
297+
status = LPSPI_MasterTransferBlocking(self->spi, &xfer);
298+
} while (status == kStatus_LPSPI_Busy && --retries > 0);
299+
293300
if (status != kStatus_Success)
294301
printf("%s: status %ld\r\n", __func__, status);
295302

@@ -311,7 +318,12 @@ bool common_hal_busio_spi_read(busio_spi_obj_t *self,
311318
xfer.rxData = data;
312319
xfer.dataSize = len;
313320

314-
const status_t status = LPSPI_MasterTransferBlocking(self->spi, &xfer);
321+
status_t status;
322+
int retries = MAX_SPI_BUSY_RETRIES;
323+
do {
324+
status = LPSPI_MasterTransferBlocking(self->spi, &xfer);
325+
} while (status == kStatus_LPSPI_Busy && --retries > 0);
326+
315327
if (status != kStatus_Success)
316328
printf("%s: status %ld\r\n", __func__, status);
317329

@@ -333,7 +345,12 @@ bool common_hal_busio_spi_transfer(busio_spi_obj_t *self, const uint8_t *data_ou
333345
xfer.rxData = data_in;
334346
xfer.dataSize = len;
335347

336-
const status_t status = LPSPI_MasterTransferBlocking(self->spi, &xfer);
348+
status_t status;
349+
int retries = MAX_SPI_BUSY_RETRIES;
350+
do {
351+
status = LPSPI_MasterTransferBlocking(self->spi, &xfer);
352+
} while (status == kStatus_LPSPI_Busy && --retries > 0);
353+
337354
if (status != kStatus_Success)
338355
printf("%s: status %ld\r\n", __func__, status);
339356

0 commit comments

Comments
 (0)
0