Skip to content

Commit 6827586

Browse files
committed
add setting SPI CLK pin pull up/down based on SPI polarity config
1 parent 918145f commit 6827586

File tree

1 file changed

+9
-0
lines changed
  • ports/stm/common-hal/busio

1 file changed

+9
-0
lines changed

ports/stm/common-hal/busio/SPI.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,15 @@ bool common_hal_busio_spi_configure(busio_spi_obj_t *self,
293293
self->handle.Init.CLKPolarity = (polarity) ? SPI_POLARITY_HIGH : SPI_POLARITY_LOW;
294294
self->handle.Init.CLKPhase = (phase) ? SPI_PHASE_2EDGE : SPI_PHASE_1EDGE;
295295

296+
// Set SCK pull up or down based on SPI CLK Polarity
297+
GPIO_InitTypeDef GPIO_InitStruct = {0};
298+
GPIO_InitStruct.Pin = pin_mask(self->sck->pin->number);
299+
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
300+
GPIO_InitStruct.Pull = (polarity) ? GPIO_PULLUP : GPIO_PULLDOWN;
301+
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
302+
GPIO_InitStruct.Alternate = self->sck->altfn_index;
303+
HAL_GPIO_Init(pin_port(self->sck->pin->port), &GPIO_InitStruct);
304+
296305
self->handle.Init.BaudRatePrescaler = stm32_baud_to_spi_div(baudrate, &self->prescaler,
297306
get_busclock(self->handle.Instance));
298307

0 commit comments

Comments
 (0)