Skip to content

interruptFunctional should be placed in IRAM #5779

Closed
@OttoWinter

Description

@OttoWinter

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions