rwmingis / InterruptButton

This is an interrupt based button event library for the ESP32. It enables binding user defined actions to button events including 'Key Down', Key Up' , 'Key Press', 'Long Key Press' 'AutoRepeat Press' and 'Double-Click'. The actions associated it these events may be executed Asynchronously, Synchronously, or a Hybrid between the two.
MIT License
30 stars 8 forks source link

High Heap memory consumption ? Is it normal ? #18

Open mathieucarbou opened 11 months ago

mathieucarbou commented 11 months ago

@rwmingis : I am following with interest issue https://github.com/rwmingis/InterruptButton/issues/17: I am using your library which is pretty cool. I found that when I activate it in my project, the heap memory usage bumps a lot (I don't know the reason). I am using Event_KeyPress and Event_LongKeyPress with no special configuration.

Should I also disable some events like shown in issue #17 to get some memory back ?

Here is the heap consumption of my ESP, when the button option is activated, I am creating a button like this:

  button = new InterruptButton(pin, LOW);
  button->setLongPressInterval(8000);
  button->bind(events::Event_KeyPress, [this]()
               { _callback(ButtonConfig.getPressAction()); });
  button->bind(events::Event_LongKeyPress, [this]()
               { _callback(ButtonConfig.getLongPressAction()); });
  InterruptButton::setMode(Mode_Asynchronous);

image

Thanks!

mathieucarbou commented 11 months ago

Please note that I have replaced

typedef void (*func_ptr_t)(void);       // Typedef to faciliate managing pointers to external action functions

with

typedef std::function<void()> func_ptr_t;
rwmingis commented 11 months ago

HI Mathieu,

Good question. If you choose to use Mode_Synchronous, then all actions are carried out in main loop hook, ie:

void main () [
  button1.processSyncEvents();      
}

And shouldn't require much additional memory.

But, using Mode_Synchronous, you have to wait for the code execution to reach this hook in the main loop for the action to happen. Which can take some time for some main loops, and be unpredictable timing and lead to a clunky user experience.

If you choose Mode_Asynchronous or Mode_Hybrid then the action (procedure) bound to your particular event (Event_KeyPress, Event_DoubleClick, etc) is run in an RTOS task which sorta happens outside of the main loop in parallel like a new thread. So it happens nearly instantaneously but not inside the interrupt itself. This is a good thing because you can do MUCH more inside this task than you can inside an interrupt. But the cost of this is that you have to reserve some memory when creating this space for this parallel task to run, this is probably what you are seeing as increased heap usage but I think it's actually reserved stack.. Note that Mode_Hybrid processes most events syncronously in the main loop hook, but Event_KeyUp and Event_KeyDown are processed immediately Asynchronously.

Now, you can reduce the default amount of reserved stack by changing the default value of the stack reservation (currently 2048 bytes)

ie:

InterruptButton::m_RTOSservicerStackDepth = 1024;

But do this before you call 'setMode' for it to work properly, because it uses that value to reserve the required amount of memory. And I think you can only set it once, ie once it's reserved, its reserved, but i suppose that needs to be confirmed.

And that change above will halve the stack usage, or more if you like to take risks. 😁 But if any of the routines you intend on running require more than this, well, it may lead to instabilities. So in this case I went a little bigger. Ie "when in doubt, build it stout"

Hope this helps 👍

rwmingis commented 11 months ago

But looking back at your graph, it's only 5 parts out of 130, so you get a lot for only about 3-4% of your memory.

rwmingis commented 11 months ago

also with your comment regarding:

typedef void (*func_ptr_t)(void); // Typedef to faciliate managing pointers to external action functions

with

typedef std::function<void()> func_ptr_t;

Im a bit rusty on some of the more modern stuff. Is it worth updating the library and why?

Cheers.

mathieucarbou commented 11 months ago

also with your comment regarding:

typedef void (*func_ptr_t)(void); // Typedef to faciliate managing pointers to external action functions with typedef std::function<void()> func_ptr_t;

Im a bit rusty on some of the more modern stuff. Is it worth updating the library and why?

Cheers.

Thanks a lot for your awesome reply! Yes it should be stack size for a task: I will try decrease it. The way I have wired the library, I want async mode in order to not slow down the press detection process, but as soon as I've captured an event, I am setting an action to execute, which will be executed as part of the main loop (so a few ms later), which is ok in my case. What I really want is to not slowdown the capture. Execution can be delayed.

So in this context, I don't need a big stack size. So I will try to decrease it.

For the callback, yes this change is required in order to use non static callbacks, as part of a C++ class. Here, I am scoping the references to [this] which allows the callback to access the class variables.

Note that I had to wrap your InterruptButton in a class because I am allowing the user to change pins. So I can only create the button once I read the pin from my configuration.

If we look at how your constructor is made, I am not sure you need a constructor at all:

InterruptButton(uint8_t pin,                                      // Class Constructor, pin to monitor
                    uint8_t pressedState,                             // State of the pin when pressed (HIGH or LOW)
                    gpio_mode_t pinMode = GPIO_MODE_INPUT,
                    uint16_t longKeyPressMS = 750,
                    uint16_t autoRepeatMS =   250,
                    uint16_t doubleClickMS =  333,
                    uint32_t debounceUS =     8000);

could become

void setPinMode(...);
void setLongKeyPressMS(...);
[...]
void init(uint8_t pin, uint8_t pressedState);

This would allow to decouple class instantiation, configuration and initialisation, especially that most of the settings have default values.

mathieucarbou commented 11 months ago

Ok so reducing the stack size did not help and crashed when I pressed the button:

Guru Meditation Error: Core  1 panic'ed (Double exception). 

Core  1 register dump:
PC      : 0x4008e2a6  PS      : 0x00040936  A0      : 0x801cf5b8  A1      : 0x3ffd2a60  
A2      : 0x4012463c  A3      : 0x00000180  A4      : 0x3ffd2cac  A5      : 0x00000000  
A6      : 0x3ffd2dfc  A7      : 0x000000ff  A8      : 0x40080080  A9      : 0x3ffd2b80  
A10     : 0x00060b36  A11     : 0x00040026  A12     : 0x3ffd2cac  A13     : 0x00000020  
A14     : 0x00ff0000  A15     : 0xff000000  SAR     : 0x00000014  EXCCAUSE: 0x00000002  
EXCVADDR: 0xffffffe0  LBEG    : 0x4008b981  LEND    : 0x4008b992  LCOUNT  : 0xfffffffd  

Backtrace: 0x4008e2a3:0x3ffd2a60 0x401cf5b5:0x3ffd2a80 0x4008e2a3:0x3ffd2ab0 0x4008e2a3:0x3ffd2ad0 0x4008e2a3:0x3ffd2af0 0x4008e2a3:0x3ffd2b10 0x4008e2a3:0x3ffd2b50 0x4008e2a3:0x3ffd2b80 0x4008007d:0x3ffd2a60 0x40082ab7:0x3ffd2a80 0x4008e2a3:0x3ffd2ab0 0x4008e2a3:0x3ffd2ad0 0x4008e2a3:0x3ffd2af0 0x4008e2a3:0x3ffd2b10 0x4008e2a3:0x3ffd2b50 0x4008e2a3:0x3ffd2b80 0x4008007d:0x3ffd2a60 0x40082ab7:0x3ffd2a80 0x4008e2a3:0x3ffd2ab0 0x4008e2a3:0x3ffd2ad0 0x4008e2a3:0x3ffd2af0 0x4008e2a3:0x3ffd2b10 0x4008e2a3:0x3ffd2b50 0x4008e2a3:0x3ffd2b80 0x4008007d:0x3ffd2a60 0x40082ab7:0x3ffd2a80 0x4008e2a3:0x3ffd2ab0 0x4008e2a3:0x3ffd2ad0 0x4008e2a3:0x3ffd2af0 0x4008e2a3:0x3ffd2b10 0x4008e2a3:0x3ffd2b50 0x4008e2a3:0x3ffd2b80 0x4008007d:0x3ffd2a60 0x40082ab7:0x3ffd2a80 0x4008e2a3:0x3ffd2ab0 0x4008e2a3:0x3ffd2ad0 0x4008e2a3:0x3ffd2af0 0x4008e2a3:0x3ffd2b10 0x4008e2a3:0x3ffd2b50 0x4008e2a3:0x3ffd2b80 0x4008007d:0x3ffd2a60 0x40082ab7:0x3ffd2a80 0x4008e2a3:0x3ffd2ab0 0x4008e2a3:0x3ffd2ad0 0x4008e2a3:0x3ffd2af0 0x4008e2a3:0x3ffd2b10 0x4008e2a3:0x3ffd2b50 0x4008e2a3:0x3ffd2b80 0x4008007d:0x3ffd2a60 0x40082ab7:0x3ffd2a80 0x4008e2a3:0x3ffd2ab0 0x4008e2a3:0x3ffd2ad0 0x4008e2a3:0x3ffd2af0 0x4008e2a3:0x3ffd2b10 0x4008e2a3:0x3ffd2b50 0x4008e2a3:0x3ffd2b80 0x4008007d:0x3ffd2a60 0x40082ab7:0x3ffd2a80 0x4008e2a3:0x3ffd2ab0 0x4008e2a3:0x3ffd2ad0 0x4008e2a3:0x3ffd2af0 0x4008e2a3:0x3ffd2b10 0x4008e2a3:0x3ffd2b50 0x4008e2a3:0x3ffd2b80 0x4008007d:0x3ffd2a60 0x40082ab7:0x3ffd2a80 0x4008e2a3:0x3ffd2ab0 0x4008e2a3:0x3ffd2ad0 0x4008e2a3:0x3ffd2af0 0x4008e2a3:0x3ffd2b10 0x4008e2a3:0x3ffd2b50 0x4008e2a3:0x3ffd2b80 0x4008007d:0x3ffd2a60 0x40082ab7:0x3ffd2a80 0x4008e2a3:0x3ffd2ab0 0x4008e2a3:0x3ffd2ad0 0x4008e2a3:0x3ffd2af0 0x4008e2a3:0x3ffd2b10 0x4008e2a3:0x3ffd2b50 0x4008e2a3:0x3ffd2b80 0x4008007d:0x3ffd2a60 0x40082ab7:0x3ffd2a80 0x4008e2a3:0x3ffd2ab0 0x4008e2a3:0x3ffd2ad0 0x4008e2a3:0x3ffd2af0 0x4008e2a3:0x3ffd2b10 0x4008e2a3:0x3ffd2b50 0x4008e2a3:0x3ffd2b80 0x4008007d:0x3ffd2a60 0x40082ab7:0x3ffd2a80 0x4008e2a3:0x3ffd2ab0 0x4008e2a3:0x3ffd2ad0 0x4008e2a3:0x3ffd2af0 0x4008e2a3:0x3ffd2b10 0x4008e2a3:0x3ffd2b50 0x4008e2a3:0x3ffd2b80 0x4008007d:0x3ffd2a60 0x40082ab7:0x3ffd2a80 0x4008e2a3:0x3ffd2ab0 0x4008e2a3:0x3ffd2ad0 0x4008e2a3:0x3ffd2af0 |<-CONTINUES

  #0  0x4008e2a3:0x3ffd2a60 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194
  #1  0x401cf5b5:0x3ffd2a80 in nvs::Page::readEntry(unsigned int, nvs::Item&) const at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/nvs_flash/src/nvs_page.cpp:879
  #2  0x4008e2a3:0x3ffd2ab0 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194
  #3  0x4008e2a3:0x3ffd2ad0 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194
  #4  0x4008e2a3:0x3ffd2af0 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194
  #5  0x4008e2a3:0x3ffd2b10 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194
  #6  0x4008e2a3:0x3ffd2b50 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194
  #7  0x4008e2a3:0x3ffd2b80 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194
  #8  0x4008007d:0x3ffd2a60 in _xt_alloca_exc at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_vectors.S:1802
  #9  0x40082ab7:0x3ffd2a80 in spi_flash_disable_interrupts_caches_and_other_cpu at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/spi_flash/cache_utils.c:139
  #10 0x4008e2a3:0x3ffd2ab0 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194
  #11 0x4008e2a3:0x3ffd2ad0 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194
  #12 0x4008e2a3:0x3ffd2af0 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194
  #13 0x4008e2a3:0x3ffd2b10 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194
  #14 0x4008e2a3:0x3ffd2b50 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194
  #15 0x4008e2a3:0x3ffd2b80 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194
  #16 0x4008007d:0x3ffd2a60 in _xt_alloca_exc at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_vectors.S:1802
  #17 0x40082ab7:0x3ffd2a80 in spi_flash_disable_interrupts_caches_and_other_cpu at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/spi_flash/cache_utils.c:139
  #18 0x4008e2a3:0x3ffd2ab0 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194
  #19 0x4008e2a3:0x3ffd2ad0 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194
  #20 0x4008e2a3:0x3ffd2af0 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194
  #21 0x4008e2a3:0x3ffd2b10 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194
  #22 0x4008e2a3:0x3ffd2b50 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194
  #23 0x4008e2a3:0x3ffd2b80 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194
  #24 0x4008007d:0x3ffd2a60 in _xt_alloca_exc at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_vectors.S:1802
  #25 0x40082ab7:0x3ffd2a80 in spi_flash_disable_interrupts_caches_and_other_cpu at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/spi_flash/cache_utils.c:139
  #26 0x4008e2a3:0x3ffd2ab0 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194
  #27 0x4008e2a3:0x3ffd2ad0 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194
  #28 0x4008e2a3:0x3ffd2af0 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194
  #29 0x4008e2a3:0x3ffd2b10 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194
  #30 0x4008e2a3:0x3ffd2b50 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194
  #31 0x4008e2a3:0x3ffd2b80 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194
  #32 0x4008007d:0x3ffd2a60 in _xt_alloca_exc at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_vectors.S:1802
  #33 0x40082ab7:0x3ffd2a80 in spi_flash_disable_interrupts_caches_and_other_cpu at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/spi_flash/cache_utils.c:139
  #34 0x4008e2a3:0x3ffd2ab0 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194
  #35 0x4008e2a3:0x3ffd2ad0 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194
  #36 0x4008e2a3:0x3ffd2af0 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194
  #37 0x4008e2a3:0x3ffd2b10 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194
  #38 0x4008e2a3:0x3ffd2b50 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194
  #39 0x4008e2a3:0x3ffd2b80 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194
  #40 0x4008007d:0x3ffd2a60 in _xt_alloca_exc at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_vectors.S:1802
  #41 0x40082ab7:0x3ffd2a80 in spi_flash_disable_interrupts_caches_and_other_cpu at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/spi_flash/cache_utils.c:139
  #42 0x4008e2a3:0x3ffd2ab0 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194
  #43 0x4008e2a3:0x3ffd2ad0 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194
  #44 0x4008e2a3:0x3ffd2af0 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194
  #45 0x4008e2a3:0x3ffd2b10 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194
  #46 0x4008e2a3:0x3ffd2b50 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194
  #47 0x4008e2a3:0x3ffd2b80 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194
  #48 0x4008007d:0x3ffd2a60 in _xt_alloca_exc at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_vectors.S:1802
  #49 0x40082ab7:0x3ffd2a80 in spi_flash_disable_interrupts_caches_and_other_cpu at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/spi_flash/cache_utils.c:139
  #50 0x4008e2a3:0x3ffd2ab0 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194
  #51 0x4008e2a3:0x3ffd2ad0 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194
  #52 0x4008e2a3:0x3ffd2af0 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194
  #53 0x4008e2a3:0x3ffd2b10 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194
  #54 0x4008e2a3:0x3ffd2b50 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194
  #55 0x4008e2a3:0x3ffd2b80 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194
  #56 0x4008007d:0x3ffd2a60 in _xt_alloca_exc at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_vectors.S:1802
  #57 0x40082ab7:0x3ffd2a80 in spi_flash_disable_interrupts_caches_and_other_cpu at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/spi_flash/cache_utils.c:139
  #58 0x4008e2a3:0x3ffd2ab0 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194
  #59 0x4008e2a3:0x3ffd2ad0 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194
  #60 0x4008e2a3:0x3ffd2af0 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194
  #61 0x4008e2a3:0x3ffd2b10 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194
  #62 0x4008e2a3:0x3ffd2b50 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194
  #63 0x4008e2a3:0x3ffd2b80 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194
  #64 0x4008007d:0x3ffd2a60 in _xt_alloca_exc at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_vectors.S:1802
  #65 0x40082ab7:0x3ffd2a80 in spi_flash_disable_interrupts_caches_and_other_cpu at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/spi_flash/cache_utils.c:139
  #66 0x4008e2a3:0x3ffd2ab0 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194
  #67 0x4008e2a3:0x3ffd2ad0 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194
  #68 0x4008e2a3:0x3ffd2af0 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194
  #69 0x4008e2a3:0x3ffd2b10 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194
  #70 0x4008e2a3:0x3ffd2b50 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194
  #71 0x4008e2a3:0x3ffd2b80 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194
  #72 0x4008007d:0x3ffd2a60 in _xt_alloca_exc at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_vectors.S:1802
  #73 0x40082ab7:0x3ffd2a80 in spi_flash_disable_interrupts_caches_and_other_cpu at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/spi_flash/cache_utils.c:139
  #74 0x4008e2a3:0x3ffd2ab0 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194
  #75 0x4008e2a3:0x3ffd2ad0 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194
  #76 0x4008e2a3:0x3ffd2af0 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194
  #77 0x4008e2a3:0x3ffd2b10 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194
  #78 0x4008e2a3:0x3ffd2b50 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194
  #79 0x4008e2a3:0x3ffd2b80 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194
  #80 0x4008007d:0x3ffd2a60 in _xt_alloca_exc at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_vectors.S:1802
  #81 0x40082ab7:0x3ffd2a80 in spi_flash_disable_interrupts_caches_and_other_cpu at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/spi_flash/cache_utils.c:139
  #82 0x4008e2a3:0x3ffd2ab0 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194
  #83 0x4008e2a3:0x3ffd2ad0 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194
  #84 0x4008e2a3:0x3ffd2af0 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194
  #85 0x4008e2a3:0x3ffd2b10 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194
  #86 0x4008e2a3:0x3ffd2b50 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194
  #87 0x4008e2a3:0x3ffd2b80 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194
  #88 0x4008007d:0x3ffd2a60 in _xt_alloca_exc at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_vectors.S:1802
  #89 0x40082ab7:0x3ffd2a80 in spi_flash_disable_interrupts_caches_and_other_cpu at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/spi_flash/cache_utils.c:139
  #90 0x4008e2a3:0x3ffd2ab0 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194
  #91 0x4008e2a3:0x3ffd2ad0 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194
  #92 0x4008e2a3:0x3ffd2af0 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194
  #93 0x4008e2a3:0x3ffd2b10 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194
  #94 0x4008e2a3:0x3ffd2b50 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194
  #95 0x4008e2a3:0x3ffd2b80 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194
  #96 0x4008007d:0x3ffd2a60 in _xt_alloca_exc at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_vectors.S:1802
  #97 0x40082ab7:0x3ffd2a80 in spi_flash_disable_interrupts_caches_and_other_cpu at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/spi_flash/cache_utils.c:139
  #98 0x4008e2a3:0x3ffd2ab0 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194
  #99 0x4008e2a3:0x3ffd2ad0 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194
  #100 0x4008e2a3:0x3ffd2af0 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194

Also, the memory usage was similar. So there is something else using about 5000 bytes

rwmingis commented 11 months ago

Thanks I will update the pointer definition.

I will need to review your second recommendation, may have some merit, though would change functionality for some users.

If you are only working in the main loop, definitely try Mode_Synchronous because the mode doesn't affect capturing the event which is always done the same in the interrupt. It's how the actions are executed that changes.

Async actions are pushed onto an RTOS queue and actioned by the RTOS task immediately. Synchronous actions are pushed onto a normal queue (array of function pointers) and are processed at the main loop hook.

You click detection shouldn't change in any mode.

Let me know if that changes your heap usage.

Cheers Rob.

On Fri, 24 Nov 2023, 1:30 am Mathieu Carbou, @.***> wrote:

Ok so reducing the stack size did not help and crashed when I pressed the button:

Guru Meditation Error: Core 1 panic'ed (Double exception).

Core 1 register dump: PC : 0x4008e2a6 PS : 0x00040936 A0 : 0x801cf5b8 A1 : 0x3ffd2a60 A2 : 0x4012463c A3 : 0x00000180 A4 : 0x3ffd2cac A5 : 0x00000000 A6 : 0x3ffd2dfc A7 : 0x000000ff A8 : 0x40080080 A9 : 0x3ffd2b80 A10 : 0x00060b36 A11 : 0x00040026 A12 : 0x3ffd2cac A13 : 0x00000020 A14 : 0x00ff0000 A15 : 0xff000000 SAR : 0x00000014 EXCCAUSE: 0x00000002 EXCVADDR: 0xffffffe0 LBEG : 0x4008b981 LEND : 0x4008b992 LCOUNT : 0xfffffffd

Backtrace: 0x4008e2a3:0x3ffd2a60 0x401cf5b5:0x3ffd2a80 0x4008e2a3:0x3ffd2ab0 0x4008e2a3:0x3ffd2ad0 0x4008e2a3:0x3ffd2af0 0x4008e2a3:0x3ffd2b10 0x4008e2a3:0x3ffd2b50 0x4008e2a3:0x3ffd2b80 0x4008007d:0x3ffd2a60 0x40082ab7:0x3ffd2a80 0x4008e2a3:0x3ffd2ab0 0x4008e2a3:0x3ffd2ad0 0x4008e2a3:0x3ffd2af0 0x4008e2a3:0x3ffd2b10 0x4008e2a3:0x3ffd2b50 0x4008e2a3:0x3ffd2b80 0x4008007d:0x3ffd2a60 0x40082ab7:0x3ffd2a80 0x4008e2a3:0x3ffd2ab0 0x4008e2a3:0x3ffd2ad0 0x4008e2a3:0x3ffd2af0 0x4008e2a3:0x3ffd2b10 0x4008e2a3:0x3ffd2b50 0x4008e2a3:0x3ffd2b80 0x4008007d:0x3ffd2a60 0x40082ab7:0x3ffd2a80 0x4008e2a3:0x3ffd2ab0 0x4008e2a3:0x3ffd2ad0 0x4008e2a3:0x3ffd2af0 0x4008e2a3:0x3ffd2b10 0x4008e2a3:0x3ffd2b50 0x4008e2a3:0x3ffd2b80 0x4008007d:0x3ffd2a60 0x40082ab7:0x3ffd2a80 0x4008e2a3:0x3ffd2ab0 0x4008e2a3:0x3ffd2ad0 0x4008e2a3:0x3ffd2af0 0x4008e2a3:0x3ffd2b10 0x4008e2a3:0x3ffd2b50 0x4008e2a3:0x3ffd2b80 0x4008007d:0x3ffd2a60 0x40082ab7:0x3ffd2a80 0x4008e2a3:0x3ffd2ab0 0x4008e2a3:0x3ffd2ad0 0x4008e2a3:0x3ffd2af0 0x4008e2a3:0x3ffd2b10 0x4008e2a3:0x3ffd2b50 0x4008e2a3:0x3ffd2b80 0x4008007d:0x3ffd2a60 0x40082ab7:0x3ffd2a80 0x4008e2a3:0x3ffd2ab0 0x4008e2a3:0x3ffd2ad0 0x4008e2a3:0x3ffd2af0 0x4008e2a3:0x3ffd2b10 0x4008e2a3:0x3ffd2b50 0x4008e2a3:0x3ffd2b80 0x4008007d:0x3ffd2a60 0x40082ab7:0x3ffd2a80 0x4008e2a3:0x3ffd2ab0 0x4008e2a3:0x3ffd2ad0 0x4008e2a3:0x3ffd2af0 0x4008e2a3:0x3ffd2b10 0x4008e2a3:0x3ffd2b50 0x4008e2a3:0x3ffd2b80 0x4008007d:0x3ffd2a60 0x40082ab7:0x3ffd2a80 0x4008e2a3:0x3ffd2ab0 0x4008e2a3:0x3ffd2ad0 0x4008e2a3:0x3ffd2af0 0x4008e2a3:0x3ffd2b10 0x4008e2a3:0x3ffd2b50 0x4008e2a3:0x3ffd2b80 0x4008007d:0x3ffd2a60 0x40082ab7:0x3ffd2a80 0x4008e2a3:0x3ffd2ab0 0x4008e2a3:0x3ffd2ad0 0x4008e2a3:0x3ffd2af0 0x4008e2a3:0x3ffd2b10 0x4008e2a3:0x3ffd2b50 0x4008e2a3:0x3ffd2b80 0x4008007d:0x3ffd2a60 0x40082ab7:0x3ffd2a80 0x4008e2a3:0x3ffd2ab0 0x4008e2a3:0x3ffd2ad0 0x4008e2a3:0x3ffd2af0 0x4008e2a3:0x3ffd2b10 0x4008e2a3:0x3ffd2b50 0x4008e2a3:0x3ffd2b80 0x4008007d:0x3ffd2a60 0x40082ab7:0x3ffd2a80 0x4008e2a3:0x3ffd2ab0 0x4008e2a3:0x3ffd2ad0 0x4008e2a3:0x3ffd2af0 0x4008e2a3:0x3ffd2b10 0x4008e2a3:0x3ffd2b50 0x4008e2a3:0x3ffd2b80 0x4008007d:0x3ffd2a60 0x40082ab7:0x3ffd2a80 0x4008e2a3:0x3ffd2ab0 0x4008e2a3:0x3ffd2ad0 0x4008e2a3:0x3ffd2af0 |<-CONTINUES

0 0x4008e2a3:0x3ffd2a60 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194

1 0x401cf5b5:0x3ffd2a80 in nvs::Page::readEntry(unsigned int, nvs::Item&) const at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/nvs_flash/src/nvs_page.cpp:879

2 0x4008e2a3:0x3ffd2ab0 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194

3 0x4008e2a3:0x3ffd2ad0 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194

4 0x4008e2a3:0x3ffd2af0 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194

5 0x4008e2a3:0x3ffd2b10 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194

6 0x4008e2a3:0x3ffd2b50 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194

7 0x4008e2a3:0x3ffd2b80 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194

8 0x4008007d:0x3ffd2a60 in _xt_alloca_exc at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_vectors.S:1802

9 0x40082ab7:0x3ffd2a80 in spi_flash_disable_interrupts_caches_and_other_cpu at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/spi_flash/cache_utils.c:139

10 0x4008e2a3:0x3ffd2ab0 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194

11 0x4008e2a3:0x3ffd2ad0 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194

12 0x4008e2a3:0x3ffd2af0 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194

13 0x4008e2a3:0x3ffd2b10 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194

14 0x4008e2a3:0x3ffd2b50 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194

15 0x4008e2a3:0x3ffd2b80 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194

16 0x4008007d:0x3ffd2a60 in _xt_alloca_exc at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_vectors.S:1802

17 0x40082ab7:0x3ffd2a80 in spi_flash_disable_interrupts_caches_and_other_cpu at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/spi_flash/cache_utils.c:139

18 0x4008e2a3:0x3ffd2ab0 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194

19 0x4008e2a3:0x3ffd2ad0 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194

20 0x4008e2a3:0x3ffd2af0 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194

21 0x4008e2a3:0x3ffd2b10 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194

22 0x4008e2a3:0x3ffd2b50 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194

23 0x4008e2a3:0x3ffd2b80 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194

24 0x4008007d:0x3ffd2a60 in _xt_alloca_exc at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_vectors.S:1802

25 0x40082ab7:0x3ffd2a80 in spi_flash_disable_interrupts_caches_and_other_cpu at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/spi_flash/cache_utils.c:139

26 0x4008e2a3:0x3ffd2ab0 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194

27 0x4008e2a3:0x3ffd2ad0 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194

28 0x4008e2a3:0x3ffd2af0 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194

29 0x4008e2a3:0x3ffd2b10 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194

30 0x4008e2a3:0x3ffd2b50 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194

31 0x4008e2a3:0x3ffd2b80 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194

32 0x4008007d:0x3ffd2a60 in _xt_alloca_exc at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_vectors.S:1802

33 0x40082ab7:0x3ffd2a80 in spi_flash_disable_interrupts_caches_and_other_cpu at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/spi_flash/cache_utils.c:139

34 0x4008e2a3:0x3ffd2ab0 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194

35 0x4008e2a3:0x3ffd2ad0 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194

36 0x4008e2a3:0x3ffd2af0 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194

37 0x4008e2a3:0x3ffd2b10 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194

38 0x4008e2a3:0x3ffd2b50 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194

39 0x4008e2a3:0x3ffd2b80 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194

40 0x4008007d:0x3ffd2a60 in _xt_alloca_exc at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_vectors.S:1802

41 0x40082ab7:0x3ffd2a80 in spi_flash_disable_interrupts_caches_and_other_cpu at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/spi_flash/cache_utils.c:139

42 0x4008e2a3:0x3ffd2ab0 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194

43 0x4008e2a3:0x3ffd2ad0 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194

44 0x4008e2a3:0x3ffd2af0 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194

45 0x4008e2a3:0x3ffd2b10 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194

46 0x4008e2a3:0x3ffd2b50 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194

47 0x4008e2a3:0x3ffd2b80 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194

48 0x4008007d:0x3ffd2a60 in _xt_alloca_exc at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_vectors.S:1802

49 0x40082ab7:0x3ffd2a80 in spi_flash_disable_interrupts_caches_and_other_cpu at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/spi_flash/cache_utils.c:139

50 0x4008e2a3:0x3ffd2ab0 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194

51 0x4008e2a3:0x3ffd2ad0 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194

52 0x4008e2a3:0x3ffd2af0 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194

53 0x4008e2a3:0x3ffd2b10 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194

54 0x4008e2a3:0x3ffd2b50 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194

55 0x4008e2a3:0x3ffd2b80 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194

56 0x4008007d:0x3ffd2a60 in _xt_alloca_exc at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_vectors.S:1802

57 0x40082ab7:0x3ffd2a80 in spi_flash_disable_interrupts_caches_and_other_cpu at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/spi_flash/cache_utils.c:139

58 0x4008e2a3:0x3ffd2ab0 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194

59 0x4008e2a3:0x3ffd2ad0 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194

60 0x4008e2a3:0x3ffd2af0 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194

61 0x4008e2a3:0x3ffd2b10 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194

62 0x4008e2a3:0x3ffd2b50 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194

63 0x4008e2a3:0x3ffd2b80 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194

64 0x4008007d:0x3ffd2a60 in _xt_alloca_exc at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_vectors.S:1802

65 0x40082ab7:0x3ffd2a80 in spi_flash_disable_interrupts_caches_and_other_cpu at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/spi_flash/cache_utils.c:139

66 0x4008e2a3:0x3ffd2ab0 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194

67 0x4008e2a3:0x3ffd2ad0 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194

68 0x4008e2a3:0x3ffd2af0 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194

69 0x4008e2a3:0x3ffd2b10 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194

70 0x4008e2a3:0x3ffd2b50 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194

71 0x4008e2a3:0x3ffd2b80 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194

72 0x4008007d:0x3ffd2a60 in _xt_alloca_exc at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_vectors.S:1802

73 0x40082ab7:0x3ffd2a80 in spi_flash_disable_interrupts_caches_and_other_cpu at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/spi_flash/cache_utils.c:139

74 0x4008e2a3:0x3ffd2ab0 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194

75 0x4008e2a3:0x3ffd2ad0 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194

76 0x4008e2a3:0x3ffd2af0 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194

77 0x4008e2a3:0x3ffd2b10 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194

78 0x4008e2a3:0x3ffd2b50 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194

79 0x4008e2a3:0x3ffd2b80 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194

80 0x4008007d:0x3ffd2a60 in _xt_alloca_exc at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_vectors.S:1802

81 0x40082ab7:0x3ffd2a80 in spi_flash_disable_interrupts_caches_and_other_cpu at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/spi_flash/cache_utils.c:139

82 0x4008e2a3:0x3ffd2ab0 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194

83 0x4008e2a3:0x3ffd2ad0 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194

84 0x4008e2a3:0x3ffd2af0 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194

85 0x4008e2a3:0x3ffd2b10 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194

86 0x4008e2a3:0x3ffd2b50 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194

87 0x4008e2a3:0x3ffd2b80 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194

88 0x4008007d:0x3ffd2a60 in _xt_alloca_exc at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_vectors.S:1802

89 0x40082ab7:0x3ffd2a80 in spi_flash_disable_interrupts_caches_and_other_cpu at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/spi_flash/cache_utils.c:139

90 0x4008e2a3:0x3ffd2ab0 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194

91 0x4008e2a3:0x3ffd2ad0 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194

92 0x4008e2a3:0x3ffd2af0 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194

93 0x4008e2a3:0x3ffd2b10 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194

94 0x4008e2a3:0x3ffd2b50 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194

95 0x4008e2a3:0x3ffd2b80 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194

96 0x4008007d:0x3ffd2a60 in _xt_alloca_exc at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_vectors.S:1802

97 0x40082ab7:0x3ffd2a80 in spi_flash_disable_interrupts_caches_and_other_cpu at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/spi_flash/cache_utils.c:139

98 0x4008e2a3:0x3ffd2ab0 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194

99 0x4008e2a3:0x3ffd2ad0 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194

100 0x4008e2a3:0x3ffd2af0 in _xt_context_save at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/xtensa_context.S:194

Also, the memory usage was similar. So there is something else using about 5000 bytes

— Reply to this email directly, view it on GitHub https://github.com/rwmingis/InterruptButton/issues/18#issuecomment-1824532003, or unsubscribe https://github.com/notifications/unsubscribe-auth/ALW24EYAOJTGO56DHEJ5SPTYF5MZFAVCNFSM6AAAAAA7XRW3SCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQMRUGUZTEMBQGM . You are receiving this because you were mentioned.Message ID: @.***>

mathieucarbou commented 11 months ago

because the mode doesn't affect capturing the event which is always done the same in the interrupt. It's how the actions are executed that changes.

Oh, nice! So I will definitely try that!

mathieucarbou commented 11 months ago

because the mode doesn't affect capturing the event which is always done the same in the interrupt. It's how the actions are executed that changes.

Oh, nice! So I will definitely try that!

So I've switched to sync mode, calling InterruptButton::processSyncEvents(); in a loop.

mathieucarbou commented 10 months ago

Please note that I have replaced

typedef void (*func_ptr_t)(void);       // Typedef to faciliate managing pointers to external action functions

with

typedef std::function<void()> func_ptr_t;

So funny ! That's the change we've talked about ;-)

rwmingis commented 10 months ago
  • It is even better because it solves some random issues: sometimes, a button press was crashing the code in some esp32 code vector.c. I never found the problem, but it's gone. I was suspecting a concurrent issue like some lack of volatile keywork somehwere. The EasyButton library also seems to have such random issues.

Yes, the Sync mode skips using RTOS stuff, so a bit more stable without the concurrent tasks. Comes at a cost of latentcy of course.

rwmingis commented 10 months ago

Note that I had to wrap your InterruptButton in a class because I am allowing the user to change pins. So I can only create the button once I read the pin from my configuration.

If we look at how your constructor is made, I am not sure you need a constructor at all:

InterruptButton(uint8_t pin,                                      // Class Constructor, pin to monitor
                    uint8_t pressedState,                             // State of the pin when pressed (HIGH or LOW)
                    gpio_mode_t pinMode = GPIO_MODE_INPUT,
                    uint16_t longKeyPressMS = 750,
                    uint16_t autoRepeatMS =   250,
                    uint16_t doubleClickMS =  333,
                    uint32_t debounceUS =     8000);

could become

void setPinMode(...);
void setLongKeyPressMS(...);
[...]
void init(uint8_t pin, uint8_t pressedState);

This would allow to decouple class instantiation, configuration and initialisation, especially that most of the settings have default values.

If you want to do a pull request around this one, I am willing to consider adding an alternate path for instantiation and configuration. IE, leave the user the option to do as it is, or alternatively using a overloaded constructor with a different signature and use your method.

mathieucarbou commented 10 months ago

@rwmingis : oh, yes definitely if you accept such api I will be glad to do it because I will then be able to just initialize the button once in the class as a private field and either use it or not and change its pin. I'll send a PR soon :-)