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.
This commit is contained in:
Jeff Epler 2021-03-24 13:07:07 -05:00
parent c81007afb0
commit b440883fe5
1 changed files with 2 additions and 0 deletions

View File

@ -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)) &&