Skip to content

Commit

Permalink
mimxrt: Compensate for a bug in the fsl_lpspi.c file.
Browse files Browse the repository at this point in the history
This library file has a bug, in that TransferBlocking returns before the
transfer has finished. That is a problem if a write follows immediately
a read.
  • Loading branch information
robert-hh authored and dpgeorge committed Jan 27, 2022
1 parent 84b76e4 commit b8a0358
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion ports/mimxrt/machine_spi.c
Expand Up @@ -230,7 +230,7 @@ void LPSPI_EDMAMasterCallback(LPSPI_Type *base, lpspi_master_edma_handle_t *hand
STATIC void machine_spi_transfer(mp_obj_base_t *self_in, size_t len, const uint8_t *src, uint8_t *dest) {
machine_spi_obj_t *self = (machine_spi_obj_t *)self_in;
// Use DMA for large transfers if channels are available
const size_t dma_min_size_threshold = 16; // That's the FIFO size
const size_t dma_min_size_threshold = FSL_FEATURE_LPSPI_FIFO_SIZEn(0); // The Macro argument is ignored

int chan_tx = -1;
int chan_rx = -1;
Expand Down Expand Up @@ -302,6 +302,10 @@ STATIC void machine_spi_transfer(mp_obj_base_t *self_in, size_t len, const uint8
}

if (!use_dma) {
// Wait until a previous Transfer is finished
while (LPSPI_GetTxFifoCount(self->spi_inst) > 0) {
MICROPY_EVENT_POLL_HOOK
}
// Reconfigure the TCR, required after switch between DMA vs. non-DMA
LPSPI_Enable(self->spi_inst, false); // Disable first before new settings are applied
self->spi_inst->TCR = LPSPI_TCR_CPOL(self->master_config->cpol) | LPSPI_TCR_CPHA(self->master_config->cpha) |
Expand Down

0 comments on commit b8a0358

Please sign in to comment.