Skip to content

Commit 57371ea

Browse files
committed
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).
1 parent 4f20cfc commit 57371ea

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

targets/TARGET_STM/stm_spi_api.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,14 @@ void init_spi(spi_t *obj)
7575
error("Cannot initialize SPI");
7676
}
7777

78-
__HAL_SPI_ENABLE(handle);
78+
/* In case of standard 4 wires SPI,PI can be kept enabled all time
79+
* and SCK will only be generated during the write operations. But in case
80+
* of 3 wires, it should be only enabled during rd/wr unitary operations,
81+
* which is handled inside STM32 HAL layer.
82+
*/
83+
if (handle->Init.Direction == SPI_DIRECTION_2LINES) {
84+
__HAL_SPI_ENABLE(handle);
85+
}
7986
}
8087

8188
void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel)

0 commit comments

Comments
 (0)