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 ];
@@ -289,7 +291,12 @@ bool common_hal_busio_spi_write(busio_spi_obj_t *self,
289
291
xfer .dataSize = len ;
290
292
xfer .configFlags = kLPSPI_MasterPcs0 ;
291
293
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
+
293
300
if (status != kStatus_Success )
294
301
printf ("%s: status %ld\r\n" , __func__ , status );
295
302
@@ -311,7 +318,12 @@ bool common_hal_busio_spi_read(busio_spi_obj_t *self,
311
318
xfer .rxData = data ;
312
319
xfer .dataSize = len ;
313
320
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
+
315
327
if (status != kStatus_Success )
316
328
printf ("%s: status %ld\r\n" , __func__ , status );
317
329
@@ -333,7 +345,12 @@ bool common_hal_busio_spi_transfer(busio_spi_obj_t *self, const uint8_t *data_ou
333
345
xfer .rxData = data_in ;
334
346
xfer .dataSize = len ;
335
347
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
+
337
354
if (status != kStatus_Success )
338
355
printf ("%s: status %ld\r\n" , __func__ , status );
339
356
0 commit comments