esp-idf: Looks like IRAM_ATTR doesn't works for c++ lambda (IDFGH-6345)
This code doesn’t works as expected:
timer_isr_register( TIMER_GROUP_0, TIMER_0, [](void* obj)IRAM_ATTR{ static_cast<Protection*>
(obj)->ProtectionISR(); }, this, ESP_INTR_FLAG_IRAM, NULL )
Where ProtectionISR() is method of Protection class.
Probably, IRAM addres check failed in esp_intr_alloc_intrstatus() This is not 100%, but 95% reason. Not 100, because functions return ESP_ERR_INVALID_ARG, that can be returned because of other reasons. But, because if replace lambda to “normal” function - all works fine, i suppose, problem in not working IRAM_ATTR for lambda.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 15 (8 by maintainers)
Hi @FoxKeys, indeed GCC does not support section attributes on lambdas. However, even if this could be made to work, it still doesn’t guarantee that all the functions used to dispatch this lambda call would also be placed into IRAM.
For your original requirement, to handle an interrupt from a member function, the usual pattern would look like this:
Note that the functions involved in interrupt handling are not defined inline (in class definition), and IRAM_ATTR are used to place them into the correct section.