-
-
Notifications
You must be signed in to change notification settings - Fork 938
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hang in TwiMaster::Read #79
Comments
tt_392 on Matrix said:
|
From our talk in the chat room, it looks like the TWI device is buggy and locks itself from time to time. |
Here is how I ended up fixing it btw As far as I understood from the nordic forums (allthough I can't seem to find the specific thread anymore). It seems that you specifically have to forcefully reset your SCL and SDA pins. |
@TT-392 Thanks for the fix! It looks like the TWI drivers hangs when SPI and TWI are heavily used at the same time... I guess you couldn't find another solution that would prevent the device from locking? |
Investigating this issue, I think it could be related to Nordic's hardware anomaly 109. Moreover, it could be also the same problem described on issue lupyuen/pinetime-rust-mynewt#24 affecting SPIM. There are some workarounds in the mentioned document. Handling peripheral IRQ to wake up seems the best one in this case. See example code in 3.8.3 TWIM workaround subsection. |
I've just had a look at the anomaly referenced by @rafacouto. This is pretty bad : a race condition inside the CPU. And the workaround are quite complex to put in place. However, the anomaly specifies that SPIM TX and TWIM TX are affected by the anomaly. TWIM RX is not referenced. But RX could be locked because TX caused the anomaly just before? Anyway, I'm trying to reproduce it so that I can analyze that issue further... with no result for now Soooo... can you help me find a way to reproduce this issue more or less reliably? |
Ok, I can reproduce it! I just have to wait longer. For info, the 5000 loop iterations correspond to ~160550 CPU cycles, which corresponds to ~2.5ms @64mhz. Now, I need to check that the code behaves correctly when the twi transaction is aborted. |
When the driver is stuck in an infinite loop for more than ~2.5ms, the TWI device is re-init and the transaction is retried. Read() and Write() return an error code.
I've implemented the fix recommended by @TT-392, it's running fine for more than 4 hours with the pong game developed by Electrolyte. |
Fixed in #111 |
I just encountered a situation where the PT froze on line 91 of
void TwiMaster::Read(uint8_t deviceAddress, uint8_t *buffer, size_t size, bool stop)
.Line in question:
while(!twiBaseAddress->EVENTS_LASTRX && !twiBaseAddress->EVENTS_ERROR);
It probably should have a timeout counter of some sort because such a freeze is not good when someone has a sealed PineTime.
The text was updated successfully, but these errors were encountered: