-
Notifications
You must be signed in to change notification settings - Fork 13.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Interruptions + SPIFFS + std::bind crash #7788
Comments
You can't use std::bind and interrupts, they don't mix. If memory serves, it's because bind creates an anonymous class that wraps your call in its operator()() method. All code in an ISR must be in IRAM (readthedocs), but this wrapper isn't, so you may get a crash. Instead, I suggest either std::function (there's a pattern in place to handle the case) or a lambda with the IRAM attr (requires gcc 10.x, so latest master branch. I'm not sure this has been tried for interrupts, it's a rather new thing thanks to the new gcc version merged recently, but it should work). Closing due to not supported. |
Many thanks @devyte for your reply! I have tried with the master branch, a lambda and IRAM atttribute but still got a crash: #include "Arduino.h"
#include <LittleFS.h>
#include <FunctionalInterrupt.h>
// ---------
class Sandbox {
public:
void init();
void loop();
volatile uint32_t counter = 0;
private:
};
// ---------
void Sandbox::loop() {
Serial.println(counter);
}
void Sandbox::init() {
// Note: use a pin where there is a lot data (I have 8000 changes/second)
pinMode(D7, INPUT);
attachInterrupt(D7, [this](void)ICACHE_RAM_ATTR{ counter++; }, CHANGE);
}
// ---------
Sandbox sandbox;
void setup() {
Serial.begin(74880);
LittleFS.begin();
sandbox.init();
}
void loop() {
File fd = LittleFS.open("/test", "w");
fd.close();
sandbox.loop();
delay(1000);
} For reference, I use platformio and had to add this to platformio.ini to use the master branch:
So I got the following packages:
I will really appreciate any help as it seems that nobody has a clean solution for now and why not update the documentation accordingly. I saw multiple forums threads where people are looking for a way to do it an issues too (#1925, arduino/ArduinoCore-API#99, arduino/ArduinoCore-avr#58). |
Platform
Problem Description
Hi,
I'm trying to use interruptions in a class and use
std::bind(&...::..., this)
for this purpose.Unfortunately, when I try to access to the flash using LittleFS, the ESP crashes:
Here is the decoded stack trace:
Here is a MCVE:
Note that it happens when I have some interruptions (8000/seconds in my case but it should crashed with less I suppose).
When I suspend interrupts during the FS access, the ESP doesn't crash.
When I declare
interruptHandler
as static and don't usestd::bind
it works too (but I'll have to declare all my variables as static which I would like to avoid).I tried a lot of things to find a solution but nothing worked and I would like to avoid to use a plain classical function as a callback to
attachInterrupt
.If you have any idea... 🙏
The text was updated successfully, but these errors were encountered: