I am working in ArduinoIDE with ESP32 and TFP625A fingerprint sensor. The sensor is connected to UART2 and served by the FPM library using HardwareSerial
. Everything works fine until a programmatically reboot is performed - ESP.restart()
. After this command, the microcontroller reboots and stucks at the place of sensor initialization. I inserted some Serial.print()
into the HardwareSerial source code file and saw that in the HardwareSerial::begin()
function, the code does not go further than this place
_uart = uartBegin(_uart_nr, baud ? baud : 9600, config, rxPin, txPin, 256, invert);
As I understand it, after rebooting the microcontroller, information about the previously configured UART2 remains in its registers. Attempts to zero the UART before rebooting the microcontroller do not correct the situation. If I make hardware restart the microcontroller by the reset button, then everything works fine.
How to overcome ESP32 stuck?
Snippets of code:
#include <HardwareSerial.h>
#include <FPM.h>
HardwareSerial mySerial(2);
FPM fpm(&mySerial);
...
void freeFPM()
{
fpm = 0;
mySerial.end();
mySerial = 0;
}
bool fpm_setup()
{
freeFPM();
mySerial = HardwareSerial(2);
finger = FPM(&mySerial);
mySerial.begin(57600);
fpm.begin(0);
}
void restartESP()
{
freeFPM();
ESP.restart();
}