2024-11-16 05:29 AM
Hi there,
first of all: I'm a software engineer and working with electronics only as a hobbyist. Therefore expect *** errors :)
I'm trying to use a ST25R3916B in my ESP32 project. The I2C communication to the ST25R3916B is working.
The call to rfalNfcInitialize succeeds but the next call to rfalFieldOnAndStartGT causes the ESP32 to crash with a " Core 1 panic'ed (Interrupt wdt timeout on CPU1).". The interrupt is taking too long.
Looking into the code, I found this function:
/*******************************************************************************/
void RfalRfST25R3916Class::st25r3916CheckForReceivedInterrupts(void)
{
uint8_t iregs[ST25R3916_INT_REGS_LEN];
uint32_t irqStatus;
/* Initialize iregs */
irqStatus = ST25R3916_IRQ_MASK_NONE;
ST_MEMSET(iregs, (int32_t)(ST25R3916_IRQ_MASK_ALL & 0xFFU), ST25R3916_INT_REGS_LEN);
/* In case the IRQ is Edge (not Level) triggered read IRQs until done */
while (digitalRead(int_pin) == HIGH) {
st25r3916ReadMultipleRegisters(ST25R3916_REG_IRQ_MAIN, iregs, ST25R3916_INT_REGS_LEN);
irqStatus |= (uint32_t)iregs[0];
irqStatus |= (uint32_t)iregs[1] << 8;
irqStatus |= (uint32_t)iregs[2] << 16;
irqStatus |= (uint32_t)iregs[3] << 24;
}
/* Forward all interrupts, even masked ones to application */
st25r3916interrupt.status |= irqStatus;
}
Commenting out the call to st25r3916ReadMultipleRegisters solves the crash but will also cause the interrupt to not work anymore (not a surprise).
This function is called by the interrupt and the call to st25r3916ReadMultipleRegisters does some I2C communication which (as far as I understand) should not be done in an interrupt handler.
Is this an incompatibility issue between the STM32duino ST25R3916 library and ESP32? Or am I doing something wrong? Has anyone gotten this IC to work on a ESP32?
Thanks for your time and your help :)
2024-11-18 01:03 AM
Hi,
"Interrupt wdt timeout on CPU1" means a watchdog timeout has occurred. I would suggest to increase the watchdog timeout.
What is the I2C speed? Using Fast Mode may also help
Rgds
BT
2024-11-18 02:54 PM
Thanks for the response. Increasing the watchdog timeout is probably not the best way to fix this. A function called by an interrupt should only run for a minimal time and should not do any complex task. I have moved the I2C handling outside the interrrupt function and now it works as expected.
Someone else has also observed the same issue and fixed it in this fork:
https://github.com/mcqn/ST25R3916
Additionally, I created my own fork https://github.com/rbuehlma/ST25R3916 based this one which fixes an issue when using I2C. It also allows to set the I2C address allowing multiple ICs to be used concurrently.