I have recently ported a very well-tested code that has been working out in the field for several years on a P1 to a P2 and have encountered the following issues that I am struggling to solve. Any help would be highly appreciated.
-
Under Device OS 5.1.0, after a non-deterministic period of continuous operation (it can be anything from two days to several weeks), the P2 hangs with a solid LED and it is unrecoverable until you power cycle the device (it is not enough to press the reset button).
-
With the release of the Hardware Watchdog with Device OS 5.3.0, we thought it could be a temporary solution to mitigate the issue and buy us some time to discover the underlying problem. However, after upgrading to Device OS 5.3.0, the P2 hangs before even finishing the setup() function. In case it is of any interest, the same happens with Device OS 5.2.0. I have read in the changelog that this release introduced an experimental modification to how threads are handled in FreeRTOS, and I wonder if my problem could be related.
We have conducted extensive testing to try to track down the issue with Device OS 5.3.0 and this is the minimal non-working code that we have managed to find. There seems to be something wrong with Serial1, because we can run a fairly complex code with three threads perfectly, but as soon we call Serial1.begin(), the program freezes. Interestingly, if you add more code to the setup() function it sometimes starts up correctly, but we have been unable to find a pattern.
Without the SYSTEM_THREAD enabled:
SYSTEM_MODE(AUTOMATIC);
void setup() {
Serial1.begin(9600, SERIAL_8N1);
}
void loop() {
}
With the SYSTEM_THREAD enabled the situation is a bit more difficult to diagnose. Depending on the code you add to the setup, it may or may not block, but it does hang often. If you remove the Serial1 initialization, this code works and if you don’t use WITH_LOCK, it works too, so I wonder if the issue has something to do with Serial1 using the Serial mutex inappropriately and creating a deadlock.
SYSTEM_THREAD(ENABLED);
SYSTEM_MODE(AUTOMATIC);
void setup() {
Serial.begin(115200);
WITH_LOCK(Serial) {
Serial.printf("\n%s - Hello", (const char*)Time.timeStr());
}
Serial1.begin(9600, SERIAL_8N1);
}
void loop() {
}
Thank you in advance for your help,
Jaime