8000 adds: maximum retries on SPI busy · alexbartlow/circuitpython@5bf08c5 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5bf08c5

Browse files
committed
adds: maximum retries on SPI busy
1 parent ae91b12 commit 5bf08c5

File tree

1 file changed

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

1 file changed

+8
-3
lines changed

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

Lines changed: 8 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];
@@ -290,9 +292,10 @@ bool common_hal_busio_spi_write(busio_spi_obj_t *self,
290292
xfer.configFlags = kLPSPI_MasterPcs0;
291293

292294
status_t status;
295+
int retries = MAX_SPI_BUSY_RETRIES;
293296
do {
294297
status = LPSPI_MasterTransferBlocking(self->spi, &xfer);
295-
} while (status == kStatus_LPSPI_Busy);
298+
} while (status == kStatus_LPSPI_Busy && --retries > 0);
296299

297300
if (status != kStatus_Success)
298301
printf("%s: status %ld\r\n", __func__, status);
@@ -316,9 +319,10 @@ bool common_hal_busio_spi_read(busio_spi_obj_t *self,
316319
xfer.dataSize = len;
317320

318321
status_t status;
322+
int retries = MAX_SPI_BUSY_RETRIES;
319323
do {
320324
status = LPSPI_MasterTransferBlocking(self->spi, &xfer);
321-
} while (status == kStatus_LPSPI_Busy);
325+
} while (status == kStatus_LPSPI_Busy && --retries > 0);
322326

323327
if (status != kStatus_Success)
324328
printf("%s: status %ld\r\n", __func__, status);
@@ -342,9 +346,10 @@ bool common_hal_busio_spi_transfer(busio_spi_obj_t *self, const uint8_t *data_ou
342346
xfer.dataSize = len;
343347

344348
status_t status;
349+
int retries = MAX_SPI_BUSY_RETRIES;
345350
do {
346351
status = LPSPI_MasterTransferBlocking(self->spi, &xfer);
347-
} while (status == kStatus_LPSPI_Busy);
352+
} while (status == kStatus_LPSPI_Busy && --retries > 0);
348353

349354
if (status != kStatus_Success)
350355
printf("%s: status %ld\r\n", __func__, status);

0 commit comments

Comments
 (0)
0