Bug in softwire library
Posted: Thu Apr 23, 2020 6:31 pm
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 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.