STM32: SPI: Do not enable SPI during Init if 3W

Enabling SPI causes the clock to be output by default.

Most devices will not care about extra clock cycles, especially as long
as chip select is not active, nevertheless this may cause side issues
with other devices especially during init phase.

This was actually the case with a 3 wire device (LPS22HB sensor).
pull/4975/head
Laurent MEUNIER 2017-07-21 15:24:59 +02:00
parent 4f20cfc0be
commit 57371ea591
1 changed files with 8 additions and 1 deletions

View File

@ -75,7 +75,14 @@ void init_spi(spi_t *obj)
error("Cannot initialize SPI");
}
__HAL_SPI_ENABLE(handle);
/* In case of standard 4 wires SPI,PI can be kept enabled all time
* and SCK will only be generated during the write operations. But in case
* of 3 wires, it should be only enabled during rd/wr unitary operations,
* which is handled inside STM32 HAL layer.
*/
if (handle->Init.Direction == SPI_DIRECTION_2LINES) {
__HAL_SPI_ENABLE(handle);
}
}
void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel)