mirror of https://github.com/ARMmbed/mbed-os.git
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 ```pull/2092/head
parent
07958da38b
commit
b09a87ffb8
|
@ -36,8 +36,7 @@ SPI::SPI(PinName mosi, PinName miso, PinName sclk, PinName ssel) :
|
||||||
// No lock needed in the constructor
|
// No lock needed in the constructor
|
||||||
|
|
||||||
spi_init(&_spi, mosi, miso, sclk, ssel);
|
spi_init(&_spi, mosi, miso, sclk, ssel);
|
||||||
spi_format(&_spi, _bits, _mode, 0);
|
aquire();
|
||||||
spi_frequency(&_spi, _hz);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SPI::format(int bits, int mode) {
|
void SPI::format(int bits, int mode) {
|
||||||
|
|
Loading…
Reference in New Issue