Bug in softwire library

Working libraries, libraries being ported and related hardware
Phono
Posts: 68
Joined: Thu Mar 19, 2020 9:32 am

Bug in softwire library

Post 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.
stevestrong
Posts: 502
Joined: Fri Dec 27, 2019 4:53 pm
Answers: 8
Location: Munich, Germany
Contact:

Re: Bug in softwire library

Post 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?
User avatar
fpiSTM
Posts: 1745
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: Bug in softwire library

Post by fpiSTM »

I thought Phono talks about the one implemented in your core. I read too quickly and probably too tired. Sorry.
Phono
Posts: 68
Joined: Thu Mar 19, 2020 9:32 am

Re: Bug in softwire library

Post 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".
User avatar
fpiSTM
Posts: 1745
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: Bug in softwire library

Post by fpiSTM »

Looking at opened issue, I guess this is what you met:
https://github.com/stevemarple/SoftWire/issues/9
Phono
Posts: 68
Joined: Thu Mar 19, 2020 9:32 am

Re: Bug in softwire library

Post 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.
User avatar
fpiSTM
Posts: 1745
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: Bug in softwire library

Post 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.
Phono
Posts: 68
Joined: Thu Mar 19, 2020 9:32 am

Re: Bug in softwire library

Post 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.
User avatar
fpiSTM
Posts: 1745
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: Bug in softwire library

Post by fpiSTM »

I talk about the library mentioned in this comment
https://github.com/stevemarple/SoftWire ... -578027425
Phono
Posts: 68
Joined: Thu Mar 19, 2020 9:32 am

Re: Bug in softwire library

Post by Phono »

So the answer is yes. The library I use, and which exhibits this bug, it the one you mention.
Post Reply

Return to “Libraries & Hardware”