khoih-prog / ESP_DoubleResetDetector

ESP_DoubleResetDetector is a library for the ESP32/ESP8266 Arduino platform to enable trigger configure mode by resetting twice.
MIT License
48 stars 18 forks source link

Strange Incompatibility when DRD is in a xTask #7

Closed DeeJayMX closed 4 years ago

DeeJayMX commented 4 years ago

Hi, to start thanks for your good good lib.

I need to delegate the DRD in a task to completly separate from loop(), I tried with a xTask but when DEBUG is enabled, the board crash:

Connecting.......Stop doubleResetDetecting
Guru Meditation Error: Core  0 panic'ed (Unhandled debug exception)
Debug exception reason: Stack canary watchpoint triggered (DbleRstCheckr) 
Core 0 register dump:
PC      : 0x400893b3  PS      : 0x00060e36  A0      : 0x80089558  A1      : 0x3ffb2080  
A2      : 0x3ffbac0c  A3      : 0x00000000  A4      : 0xffffffff  A5      : 0x00000000  
A6      : 0x000000ff  A7      : 0x3ffb22bc  A8      : 0x8008a565  A9      : 0x3ffb2090  
A10     : 0x00000003  A11     : 0x00060e23  A12     : 0x00060e20  A13     : 0x0000007e  
A14     : 0x00000002  A15     : 0x3ffb22bc  SAR     : 0x00000010  EXCCAUSE: 0x00000001  
EXCVADDR: 0x00000000  LBEG    : 0x40001609  LEND    : 0x4000160d  LCOUNT  : 0x00000000  

Backtrace: 0x400893b3:0x3ffb2080 0x40089555:0x3ffb20c0 0x4014c9e1:0x3ffb20e0 0x40087622:0x3ffb2100 0x40087bea:0x3ffb2120 0x400ffffd:0x3ffb2190 0x400fe8c5:0x3ffb21b0 0x400fed13:0x3ffb21d0 0x400fd659:0x3ffb2240 0x400fdc3d:0x3ffb2290 0x400fd0e9:0x3ffb2300 0x400e63d6:0x3ffb2340 0x400d29c3:0x3ffb2360 0x400d2a94:0x3ffb23a0 0x400896e5:0x3ffb23c0

If you want to keep debug mode enabled: Just add more space for it with 1500 byte of stack size to the default stack size of a new task. here is my code if you want to publish an example:

Define:

//------------------------------------------------------------Double Reset Detector
#define ESP_DRD_USE_EEPROM      true
#define DOUBLERESETDETECTOR_DEBUG       true  //false
#include <ESP_DoubleResetDetector.h>      //https://github.com/khoih-prog/ESP_DoubleResetDetector

// Number of seconds after reset during which a 
// subseqent reset will be considered a double reset.
#define DRD_TIMEOUT 5

// RTC Memory Address for the DoubleResetDetector to use
#define DRD_ADDRESS 0

DoubleResetDetector* drd;

// For ESP32 LED Builtin
#ifndef LED_BUILTIN
#define LED_BUILTIN       2         // Pin D2 mapped to pin GPIO2/ADC12 of ESP32, control on-board LED
#endif

#define LED_OFF     LOW
#define LED_ON      HIGH
//------------------------------------------------------------Double Reset Detector

Func to declare before setup:

void DoubleResetCheck(void * parameter){
  for(;;){ // infinite loop

drd->loop(); // Double Reset Detector

    // Pause the task for 5ms
    vTaskDelay(5 / portTICK_PERIOD_MS);
  }
}

In Setup():

//------------------------------------------------------------Double Reset Detector
  drd = new DoubleResetDetector(DRD_TIMEOUT, DRD_ADDRESS);
  if (drd->detectDoubleReset()) 
  {
    Serial.println("");Serial.println("Double Reset Detected");Serial.println("");
    digitalWrite(LED_BUILTIN, LED_ON);
  } 
  else 
  {
    Serial.println("");Serial.println("No Double Reset Detected");Serial.println("");
    digitalWrite(LED_BUILTIN, LED_OFF);
  }

    xTaskCreate(DoubleResetCheck,    // Function that should be called
    "DbleRstCheckr",   // Name of the task (for debugging)
    1500,            // Stack size (bytes)
    NULL,            // Parameter to pass
    1,               // Task priority
    NULL             // Task handle
  );
//------------------------------------------------------------Double Reset Detector
khoih-prog commented 4 years ago

Hi @DeeJayMX

Thanks for using the library and your encouraging words. I'll certainly include your novel solution in a new example, and and credit you contribution in next release.

Regards,

DeeJayMX commented 4 years ago

My example is wrote for ESP32 but I think it's convertible for ESP8266 and/or Microcontroler with FreeRTOS... Thanks 👍😁

khoih-prog commented 4 years ago

If possible, please make the complete example for both ESP32 and ESP8266. Then I'll post on the Master repo so that other people can use, without waiting for next release. Thanks,

DeeJayMX commented 4 years ago

I don't have ESP8266 to test...

khoih-prog commented 4 years ago

I can test here if you send the code for ESP8266.