Page 1 of 2

Bug in softwire library

Posted: Thu Apr 23, 2020 6:31 pm
by Phono
Hi all,
I reported an issue in the github of stevemarple, the author of this library, but it seems that he is not involved any more in this section. So I put it here, to open a discussion about the best way to fix it. Here is my report:
I have implemented a I2C master on a STM32F103 and it works correctly.
However, while performing tests, I did an experiment: I shorted the scl line to ground, to see whether this was correctly handled. My application then crashed. After a long examination, I found that in such a case there is an infinite indirect recursion, thus the crash.
The problem lies in the function sclHighAndStretch. In case of a timeout, it calls the function stop which itself calls sclHighAndStretch . We need a way to break this recursion. I see two ways:

add an extra parameter to sclHighAndStretch to hold it from calling stop again.
or
write a special stop2 code for this instance, that does not call sclHighAndStretch again.
PS : advice : in the description of the library, it would be useful to specify that the user needs to supply a read and a write buffer at initialisation time. I had a hard time figuring out what was wrong until I discovered this. I used to use a library from Roger Clark's package that was very close, but that did not require buffers to be supplied, so I was not aware of the need of buffers.

Re: Bug in softwire library

Posted: Thu Apr 23, 2020 7:54 pm
by stevestrong
@Phono,
I don't think that @stevemarple (author of this library) is registered in this forum, neither has any connection to the libmaple core supported in this forum.
Why do you think that this is relevant here?

The Libmaple core (Roger's any mine) has already support for SoftWire library. Have you tried it?

Re: Bug in softwire library

Posted: Thu Apr 23, 2020 9:02 pm
by fpiSTM
I thought Phono talks about the one implemented in your core. I read too quickly and probably too tired. Sorry.

Re: Bug in softwire library

Posted: Fri Apr 24, 2020 8:47 am
by Phono
I am not sure of which library you are talking about. I am using the official STM32duino core (that I installed on Arduino IDE from the "add board" option), and the softwire library that I found in the Arduino IDE using the option "manage libraries".

Re: Bug in softwire library

Posted: Fri Apr 24, 2020 8:58 am
by fpiSTM
Looking at opened issue, I guess this is what you met:
https://github.com/stevemarple/SoftWire/issues/9

Re: Bug in softwire library

Posted: Fri Apr 24, 2020 2:23 pm
by Phono
Not exactly. I do not get incorrect readings, I get a crash in the case there is a hardware failure on the I2C bus that holds the scl line down too long.

Re: Bug in softwire library

Posted: Fri Apr 24, 2020 2:25 pm
by fpiSTM
So this probably means the library has a bug and do not managed this state.
Did you test the library referenced in the issue ?

As it is a soft Wire then it have to handle all those case.

Re: Bug in softwire library

Posted: Fri Apr 24, 2020 2:46 pm
by Phono
Do you mean this link :
?
If yes, this is the very library I am using and which has the problem for which I have open the issue #11 that describes it in details.

Re: Bug in softwire library

Posted: Fri Apr 24, 2020 3:28 pm
by fpiSTM
I talk about the library mentioned in this comment
https://github.com/stevemarple/SoftWire ... -578027425

Re: Bug in softwire library

Posted: Fri Apr 24, 2020 4:25 pm
by Phono
So the answer is yes. The library I use, and which exhibits this bug, it the one you mention.