From b440883fe55666d12f94a6d48513a1a68d218bc4 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Wed, 24 Mar 2021 13:07:07 -0500 Subject: [PATCH] mimxrt: SPI: Set the TCR value returned by MasterBaudSetRate without this, the baud rate could be wrong; in my testing, it was low by a factor of 2 when requesating baudrate=1_000_000 (1MHz). When passing the baudrate in to LPSPI_MasterInit, the setting is made automatically, but LPSPI_MAster_SetBaudRate just returns it via the out-parameter tcrPrescaleValue. --- ports/mimxrt10xx/common-hal/busio/SPI.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ports/mimxrt10xx/common-hal/busio/SPI.c b/ports/mimxrt10xx/common-hal/busio/SPI.c index 3488ac0fbe..1b72921d31 100644 --- a/ports/mimxrt10xx/common-hal/busio/SPI.c +++ b/ports/mimxrt10xx/common-hal/busio/SPI.c @@ -187,6 +187,7 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self, LPSPI_Enable(self->spi, false); uint32_t tcrPrescaleValue; self->baudrate = LPSPI_MasterSetBaudRate(self->spi, config.baudRate, LPSPI_MASTER_CLK_FREQ, &tcrPrescaleValue); + self->spi->TCR = (self->spi->TCR & ~LPSPI_TCR_PRESCALE_MASK) | LPSPI_TCR_PRESCALE(tcrPrescaleValue); LPSPI_Enable(self->spi, true); claim_pin(self->clock->pin); @@ -236,6 +237,7 @@ bool common_hal_busio_spi_configure(busio_spi_obj_t *self, LPSPI_Enable(self->spi, false); uint32_t tcrPrescaleValue; self->baudrate = LPSPI_MasterSetBaudRate(self->spi, baudrate, LPSPI_MASTER_CLK_FREQ, &tcrPrescaleValue); + self->spi->TCR = (self->spi->TCR & ~LPSPI_TCR_PRESCALE_MASK) | LPSPI_TCR_PRESCALE(tcrPrescaleValue); LPSPI_Enable(self->spi, true); if ((polarity == common_hal_busio_spi_get_polarity(self)) &&