Skip to content

Commit b09a87f

Browse files
committed
SPI: Properly aquire peripheral in constructor
Prevent mismatch between _owner and peripheral configuration. In the previous implementation, the following code would leave the peripheral in an inconsistent state: ``` SPI spi1(...); // _owner is NULL, peripheral config is 1 spi1.transfer(...); // _owner is 1, config is 1 SPI spi2(...); // _owner is 1, config is 2 spi1.transfer(...) // 1 thinks it still owns peripheral, doesn't reconfigure ```
1 parent 07958da commit b09a87f

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

hal/common/SPI.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ SPI::SPI(PinName mosi, PinName miso, PinName sclk, PinName ssel) :
3636
// No lock needed in the constructor
3737

3838
spi_init(&_spi, mosi, miso, sclk, ssel);
39-
spi_format(&_spi, _bits, _mode, 0);
40-
spi_frequency(&_spi, _hz);
39+
aquire();
4140
}
4241

4342
void SPI::format(int bits, int mode) {

0 commit comments

Comments
 (0)