Skip to content

fixes: busio, SPI OS error 5 for mimxrt10xx #4048

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 9, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions ports/mimxrt10xx/common-hal/busio/SPI.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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);

Expand All @@ -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);

Expand All @@ -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);

Expand Down