Skip to content

Commit 417cb4f

Browse files
authored
Merge pull request stm32duino#2549 from fpistm/spi_init
fix(spi): ensure spi_t structure properly init
2 parents 021d321 + 22157db commit 417cb4f

File tree

2 files changed

+11
-19
lines changed

2 files changed

+11
-19
lines changed

libraries/SPI/src/SPI.cpp

+10-17
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,18 @@
1414
SPIClass SPI;
1515

1616
/**
17-
* @brief Default constructor. Uses pin configuration of variant.h.
18-
*/
19-
SPIClass::SPIClass()
20-
{
21-
_spi.pin_miso = digitalPinToPinName(MISO);
22-
_spi.pin_mosi = digitalPinToPinName(MOSI);
23-
_spi.pin_sclk = digitalPinToPinName(SCK);
24-
_spi.pin_ssel = NC;
25-
}
26-
27-
/**
28-
* @brief Constructor to create another SPI instance attached to another SPI
29-
* peripheral different of the default SPI. All pins must be attached to
30-
* the same SPI peripheral. See datasheet of the microcontroller.
17+
* @brief Default Constructor. Uses pin configuration of default SPI
18+
* defined in the variant*.h.
19+
* To create another SPI instance attached to another SPI
20+
* peripheral gave the pins as parameters to the constructor.
21+
* @note All pins must be attached to the same SPI peripheral.
22+
* See datasheet of the microcontroller.
3123
* @param mosi: SPI mosi pin. Accepted format: number or Arduino format (Dx)
32-
* or ST format (Pxy).
24+
* or ST format (Pxy). Default is MOSI pin of the default SPI peripheral.
3325
* @param miso: SPI miso pin. Accepted format: number or Arduino format (Dx)
34-
* or ST format (Pxy).
26+
* or ST format (Pxy). Default is MISO pin of the default SPI peripheral.
3527
* @param sclk: SPI clock pin. Accepted format: number or Arduino format (Dx)
36-
* or ST format (Pxy).
28+
* or ST format (Pxy). Default is SCK pin of the default SPI peripheral.
3729
* @param ssel: SPI ssel pin (optional). Accepted format: number or
3830
* Arduino format (Dx) or ST format (Pxy). By default is set to NC.
3931
* This pin must correspond to a hardware CS pin which can be managed
@@ -45,6 +37,7 @@ SPIClass::SPIClass()
4537
*/
4638
SPIClass::SPIClass(uint32_t mosi, uint32_t miso, uint32_t sclk, uint32_t ssel)
4739
{
40+
memset((void *)&_spi, 0, sizeof(_spi));
4841
_spi.pin_miso = digitalPinToPinName(miso);
4942
_spi.pin_mosi = digitalPinToPinName(mosi);
5043
_spi.pin_sclk = digitalPinToPinName(sclk);

libraries/SPI/src/SPI.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,7 @@ class SPISettings {
8484

8585
class SPIClass {
8686
public:
87-
SPIClass();
88-
SPIClass(uint32_t mosi, uint32_t miso, uint32_t sclk, uint32_t ssel = PNUM_NOT_DEFINED);
87+
SPIClass(uint32_t mosi = MISO, uint32_t miso = MOSI, uint32_t sclk = SCK, uint32_t ssel = PNUM_NOT_DEFINED);
8988

9089
// setMISO/MOSI/SCLK/SSEL have to be called before begin()
9190
void setMISO(uint32_t miso)

0 commit comments

Comments
 (0)