38
38
39
39
#define LPSPI_MASTER_CLK_FREQ (CLOCK_GetFreq(kCLOCK_Usb1PllPfd0Clk) / (CLOCK_GetDiv(kCLOCK_LpspiDiv) + 1))
40
40
41
+ #define MAX_SPI_BUSY_RETRIES 100
42
+
41
43
//arrays use 0 based numbering: SPI1 is stored at index 0
42
44
#define MAX_SPI 4
43
45
STATIC bool reserved_spi [MAX_SPI ];
@@ -290,9 +292,10 @@ bool common_hal_busio_spi_write(busio_spi_obj_t *self,
290
292
xfer .configFlags = kLPSPI_MasterPcs0 ;
291
293
292
294
status_t status ;
295
+ int retries = MAX_SPI_BUSY_RETRIES ;
293
296
do {
294
297
status = LPSPI_MasterTransferBlocking (self -> spi , & xfer );
295
- } while (status == kStatus_LPSPI_Busy );
298
+ } while (status == kStatus_LPSPI_Busy && -- retries > 0 );
296
299
297
300
if (status != kStatus_Success )
298
301
printf ("%s: status %ld\r\n" , __func__ , status );
@@ -316,9 +319,10 @@ bool common_hal_busio_spi_read(busio_spi_obj_t *self,
316
319
xfer .dataSize = len ;
317
320
318
321
status_t status ;
322
+ int retries = MAX_SPI_BUSY_RETRIES ;
319
323
do {
320
324
status = LPSPI_MasterTransferBlocking (self -> spi , & xfer );
321
- } while (status == kStatus_LPSPI_Busy );
325
+ } while (status == kStatus_LPSPI_Busy && -- retries > 0 );
322
326
323
327
if (status != kStatus_Success )
324
328
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
342
346
xfer .dataSize = len ;
343
347
344
348
status_t status ;
349
+ int retries = MAX_SPI_BUSY_RETRIES ;
345
350
do {
346
351
status = LPSPI_MasterTransferBlocking (self -> spi , & xfer );
347
- } while (status == kStatus_LPSPI_Busy );
352
+ } while (status == kStatus_LPSPI_Busy && -- retries > 0 );
348
353
349
354
if (status != kStatus_Success )
350
355
printf ("%s: status %ld\r\n" , __func__ , status );
0 commit comments