Skip to content

Commit ade55da

Browse files
ric96fpistm
authored andcommitted
wire: add fix for toggling NoStretch
On a few devboards running linux, dragonboard410c, pi4 etc, I am seeing issues with i2cdetect and other i2c bash utilities where the stm32 holds the SCL line low and hangs the bus. This seems to fix the issue. Signed-off-by: Sahaj Sarup <[email protected]>
1 parent 73e67e8 commit ade55da

File tree

4 files changed

+9
-6
lines changed

4 files changed

+9
-6
lines changed

libraries/Wire/src/Wire.cpp

+5-3
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ void TwoWire::begin(bool generalCall)
5959
begin(MASTER_ADDRESS, generalCall);
6060
}
6161

62-
void TwoWire::begin(uint8_t address, bool generalCall)
62+
void TwoWire::begin(uint8_t address, bool generalCall, bool NoStretchMode)
6363
{
6464
rxBufferIndex = 0;
6565
rxBufferLength = 0;
@@ -83,6 +83,8 @@ void TwoWire::begin(uint8_t address, bool generalCall)
8383

8484
_i2c.generalCall = (generalCall == true) ? 1 : 0;
8585

86+
_i2c.NoStretchMode = (NoStretchMode == true) ? 1 : 0;
87+
8688
recoverBus(); // in case I2C bus (device) is stuck after a reset for example
8789

8890
i2c_custom_init(&_i2c, 100000, I2C_ADDRESSINGMODE_7BIT, ownAddress);
@@ -96,9 +98,9 @@ void TwoWire::begin(uint8_t address, bool generalCall)
9698
}
9799
}
98100

99-
void TwoWire::begin(int address, bool generalCall)
101+
void TwoWire::begin(int address, bool generalCall, bool NoStretchMode)
100102
{
101-
begin((uint8_t)address, generalCall);
103+
begin((uint8_t)address, generalCall, NoStretchMode);
102104
}
103105

104106
void TwoWire::end(void)

libraries/Wire/src/Wire.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ class TwoWire : public Stream {
9090
};
9191
void begin(bool generalCall = false);
9292
void begin(uint32_t, uint32_t);
93-
void begin(uint8_t, bool generalCall = false);
94-
void begin(int, bool generalCall = false);
93+
void begin(uint8_t, bool generalCall = false, bool NoStretchMode = false);
94+
void begin(int, bool generalCall = false, bool NoStretchMode = false);
9595
void end();
9696
void setClock(uint32_t);
9797
void beginTransmission(uint8_t);

libraries/Wire/src/utility/twi.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,7 @@ void i2c_custom_init(i2c_t *obj, uint32_t timing, uint32_t addressingMode, uint3
766766
handle->Init.AddressingMode = addressingMode;
767767
handle->Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
768768
handle->Init.GeneralCallMode = (obj->generalCall == 0) ? I2C_GENERALCALL_DISABLE : I2C_GENERALCALL_ENABLE;
769-
handle->Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;
769+
handle->Init.NoStretchMode = (obj->NoStretchMode == 0) ? I2C_NOSTRETCH_DISABLE : I2C_NOSTRETCH_ENABLE;
770770

771771
handle->State = HAL_I2C_STATE_RESET;
772772

libraries/Wire/src/utility/twi.h

+1
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ struct i2c_s {
122122
volatile uint8_t slaveMode;
123123
uint8_t isMaster;
124124
uint8_t generalCall;
125+
uint8_t NoStretchMode;
125126
};
126127

127128
///@brief I2C state

0 commit comments

Comments
 (0)