From 6827586d33d2d91f4859383192f053ca36823b2e Mon Sep 17 00:00:00 2001 From: Scott Gauche Date: Sat, 19 Feb 2022 08:46:02 -0500 Subject: [PATCH] add setting SPI CLK pin pull up/down based on SPI polarity config --- ports/stm/common-hal/busio/SPI.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/ports/stm/common-hal/busio/SPI.c b/ports/stm/common-hal/busio/SPI.c index 6061046890..f7961f8cef 100644 --- a/ports/stm/common-hal/busio/SPI.c +++ b/ports/stm/common-hal/busio/SPI.c @@ -293,6 +293,15 @@ bool common_hal_busio_spi_configure(busio_spi_obj_t *self, self->handle.Init.CLKPolarity = (polarity) ? SPI_POLARITY_HIGH : SPI_POLARITY_LOW; self->handle.Init.CLKPhase = (phase) ? SPI_PHASE_2EDGE : SPI_PHASE_1EDGE; + // Set SCK pull up or down based on SPI CLK Polarity + GPIO_InitTypeDef GPIO_InitStruct = {0}; + GPIO_InitStruct.Pin = pin_mask(self->sck->pin->number); + GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; + GPIO_InitStruct.Pull = (polarity) ? GPIO_PULLUP : GPIO_PULLDOWN; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; + GPIO_InitStruct.Alternate = self->sck->altfn_index; + HAL_GPIO_Init(pin_port(self->sck->pin->port), &GPIO_InitStruct); + self->handle.Init.BaudRatePrescaler = stm32_baud_to_spi_div(baudrate, &self->prescaler, get_busclock(self->handle.Instance));