2024-09-23 02:05 AM - last edited on 2024-09-23 07:29 AM by Amel NASRI
Dear community,
We are currently developing custom firmware for an upcoming device based on STM32WB55. It's written from scratch, including a very simple cooperative scheduler. Recently, we rewrote our I2C driver. Ever since, we occasionally see one of our asserts failing.
The bug sequence is as follows:
Occasionally, the assert that current transaction is non-NULL fails. I am pretty sure that the code is semantically correct and I have ruled out the usual suspects.
I have observed the following:
I have read ARM AN321 and my current theory is that when I clear the interrupt pending at the peripheral (via I2C_ICR), it takes some time for this to propagate to the NVIC_ISPRx. When we leave the i2c_handle_event ISR too quickly (or perhaps just at the unfortunate moment), the interrupt is still pending and the ISR is called again (for the same NACK occurrence) finds the current transaction set to NULL.
Is this possible? The AN recommends (4.9 Disabling interrupts at peripherals) to contact the manufacturer directly for recommendations how to make sure that the interrupt at the peripheral is cleared before leaving the ISR. So, here I am.
I have two questions:
Thanks!
2024-09-23 05:37 AM
You should clear the flag as soon as possible. A few clock cycles is typically sufficient to avoid the interrupt being re-entered. You can also poll the NVIC pending interrupt bits, which may work.
if (NACKF) {
// clear NACKF here, first
// other code
}
However, you should also be checking for flags within the interrupt before acting (i.e. before checking for a NULL transaction), which should obviate this from being an issue. You will not find any flags set when the interrupt re-enters like this.