Skip to content

ESP8266 / ESP32: Place ISR in IRAM#38

Open
mcspr wants to merge 3 commits intoPaulStoffregen:masterfrom
mcspr:esp/isr-in-iram
Open

ESP8266 / ESP32: Place ISR in IRAM#38
mcspr wants to merge 3 commits intoPaulStoffregen:masterfrom
mcspr:esp/isr-in-iram

Conversation

@mcspr
Copy link

@mcspr mcspr commented Apr 29, 2019

supercede #15

Update is for both ESP8266 and ESP32, by combining attribute define.
ESP8266 Core will crash when used without this attribute on current git version (future 2.5.1). And it's likely to crash anyways with more complex examples / fast encoders, even without that check.
ref:
https://arduino-esp8266.readthedocs.io/en/latest/faq/a02-my-esp-crashes.html#other-causes-for-crashes
https://docs.espressif.com/projects/esp-idf/en/latest/api-guides/general-notes.html#iram-instruction-ram
esp8266/Arduino#5995

Things are moved around because just adding IRAM_ATTR does not work. For example, adding it to the ::update causes this issue:

$ pio platform show espressif32
Version: 2.10002.190416
Original version: 1.0.2
$ PLATFORMIO_CI_SRC=examples/Basic/Basic.pde pio ci --lib . -b lolin32
...
Linking .pioenvs/lolin32/firmware.elf
.pioenvs/lolin32/src/Basic.pde.cpp.o: In function `Encoder::update(Encoder_internal_state_t*)':
Basic.pde.cpp:(.iram1[Encoder::update(Encoder_internal_state_t*)]+0x3d): dangerous relocation: l32r: literal placed after use: .literal._ZN7Encoder6updateEP24Encoder_internal_state_t

(same for each isrN)

*This PR would also allow to add Functional Interrupt support (ESP8266&32 Cores feature)
attach_interrupt could be replaced with just:

static uint8_t attach_interrupt(uint8_t pin, Encoder_internal_state_t *state) {
    attachInterrupt(pin, std::bind(&update, state), CHANGE);
    return 1;
}

Loading
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 this pull request may close these issues.

5 participants