TARGET_STM: SPI: update pull up config depending on clk polarity

Fix #10589

Signed-off-by: Vincent Veron <vincent.veron@st.com>
pull/10804/head
Vincent Veron 2019-06-06 17:06:04 +02:00
parent 16475829f1
commit 82979f6415
1 changed files with 14 additions and 0 deletions

View File

@ -216,6 +216,12 @@ void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel
handle->Init.FifoThreshold = SPI_FIFO_THRESHOLD_01DATA;
#endif
/*
* According the STM32 Datasheet for SPI peripheral we need to PULLDOWN
* or PULLUP the SCK pin according the polarity used.
*/
pin_mode(spiobj->pin_sclk, (handle->Init.CLKPolarity == SPI_POLARITY_LOW) ? PullDown: PullUp);
init_spi(obj);
}
@ -290,6 +296,7 @@ void spi_format(spi_t *obj, int bits, int mode, int slave)
{
struct spi_s *spiobj = SPI_S(obj);
SPI_HandleTypeDef *handle = &(spiobj->handle);
PinMode pull = 0;
DEBUG_PRINTF("spi_format, bits:%d, mode:%d, slave?:%d\r\n", bits, mode, slave);
@ -331,6 +338,13 @@ void spi_format(spi_t *obj, int bits, int mode, int slave)
handle->Init.Direction = SPI_DIRECTION_2LINES;
}
/*
* According the STM32 Datasheet for SPI peripheral we need to PULLDOWN
* or PULLUP the SCK pin according the polarity used.
*/
pull = (handle->Init.CLKPolarity == SPI_POLARITY_LOW) ? PullDown: PullUp;
pin_mode(spiobj->pin_sclk, pull);
init_spi(obj);
}