Skip to content

interruptFunctional should be placed in IRAM #5779

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

Closed
6 tasks done
OttoWinter opened this issue Feb 18, 2019 · 0 comments · Fixed by #5995
Closed
6 tasks done

interruptFunctional should be placed in IRAM #5779

OttoWinter opened this issue Feb 18, 2019 · 0 comments · Fixed by #5995

Comments

@OttoWinter
Copy link

Basic Infos

  • This issue complies with the issue POLICY doc.
  • I have read the documentation at readthedocs and the issue is not addressed there.
  • I have tested that the issue is present in current master branch (aka latest git).
  • I have searched the issue tracker for a similar issue.
  • If there is a stack dump, I have decoded it.
  • I have filled out all fields below.

Platform / Settings in IDE

Deleted because doesn't matter here (any of these should lead to the same result AFAIK, but happy to provide if necessary.)

Problem Description

interruptFunctional in FunctionInterrupt should probably have the ICACHE_RAM_ATTR attribute set. Right now it appears the function is linked into the normal flash section. And because this is (always) called from an ISR that will fail.

void interruptFunctional(void* arg)
{
ArgStructure* localArg = (ArgStructure*)arg;
if (localArg->functionInfo->reqScheduledFunction)
{
schedule_function(std::bind(localArg->functionInfo->reqScheduledFunction,InterruptInfo(*(localArg->interruptInfo))));
// scheduledInterrupts->scheduleFunctionReg(std::bind(localArg->functionInfo->reqScheduledFunction,InterruptInfo(*(localArg->interruptInfo))), false, true);
}
if (localArg->functionInfo->reqFunction)
{
localArg->functionInfo->reqFunction();
}
}

MCVE Sketch

#include <Arduino.h>
#include <FunctionalInterrupt.h>

void setup() {
  // doesn't work reliably, my guess the function is pre-cached somehow and so
  // no interrupt for reading it into cache needs to be called?
  // I don't have the experience to say.
  attachInterrupt(D1, [](){}, CHANGE);
}

void loop() {}

Exception decode

See full stacktrace here: esphome/issues#61 (comment) (original report)

The important part is here:

[15:17:04]Exception (0):
WARNING Exception type: unknown
[15:17:04]epc1=0x4020a208 epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000000 depc=0x00000000
WARNING Decoded 0x4020a208: interruptFunctional(void*)
  1. Exception type 0 likely means the usual ICACHE_RAM_ATTR error.
  2. epc1 is 0x4020a208 - not 0x4010C000 as seen here.
  3. epc1 also gets decoded to interruptFunctional - so the error is likely there (I don't think the compiler can inline anything here)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant