Skip to content

mimxrt1011: Only re-init SPI when it's actually needed #2747

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 1 commit into from
Apr 6, 2020
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
17 changes: 12 additions & 5 deletions ports/mimxrt10xx/common-hal/busio/SPI.c
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,18 @@ void common_hal_busio_spi_deinit(busio_spi_obj_t *self) {

bool common_hal_busio_spi_configure(busio_spi_obj_t *self,
uint32_t baudrate, uint8_t polarity, uint8_t phase, uint8_t bits) {

LPSPI_Enable(self->spi, false);
uint32_t tcrPrescaleValue;
self->baudrate = LPSPI_MasterSetBaudRate(self->spi, baudrate, LPSPI_MASTER_CLK_FREQ, &tcrPrescaleValue);
LPSPI_Enable(self->spi, true);

if ((polarity == common_hal_busio_spi_get_polarity(self)) &&
(phase == common_hal_busio_spi_get_phase(self)) &&
(bits == ((self->spi->TCR & LPSPI_TCR_FRAMESZ_MASK) >> LPSPI_TCR_FRAMESZ_SHIFT)) + 1) {
return true;
}

lpspi_master_config_t config = { 0 };
LPSPI_MasterGetDefaultConfig(&config);

Expand All @@ -221,11 +233,6 @@ bool common_hal_busio_spi_configure(busio_spi_obj_t *self,
LPSPI_Deinit(self->spi);
LPSPI_MasterInit(self->spi, &config, LPSPI_MASTER_CLK_FREQ);

LPSPI_Enable(self->spi, false);
uint32_t tcrPrescaleValue;
self->baudrate = LPSPI_MasterSetBaudRate(self->spi, config.baudRate, LPSPI_MASTER_CLK_FREQ, &tcrPrescaleValue);
LPSPI_Enable(self->spi, true);

return true;
}

Expand Down