Skip to content

micros() is not IRAM_ATTR safe in staging #1410

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
brainsucker-na opened this issue May 15, 2018 · 1 comment
Closed

micros() is not IRAM_ATTR safe in staging #1410

brainsucker-na opened this issue May 15, 2018 · 1 comment

Comments

@brainsucker-na
Copy link

Hardware:

Board: ESP-WROOM32
Updating espressif32 @ a45da6a [Up-to-date]
Updating framework-arduinoespressif32 @ dd639c4 [Up-to-date]
IDE name: Platform.io

Description:

micros() is not IRAM_ATTR safe in current staging version.
Just get a frequent interrupt source (connect pins 18 and 21 to test my sample, that'll generate interrupts at 500hz) and it will go into infinite reboot cycle.

rst:0x3 (SW_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0018,len:4
load:0x3fff001c,len:812
load:0x40078000,len:0
load:0x40078000,len:11584
entry 0x40078a60
Setting up PWM...
Attaching interrupt...
Connecting to WIFI...
Guru Meditation Error: Core  1 panic'ed (Cache disabled but cached memory region accessed)

Core 1 register dump:
PC      : 0x4010fd10  PS      : 0x00060034  A0      : 0x80080e72  A1      : 0x3ffc0bb0
A2      : 0x3ffc3934  A3      : 0x00000004  A4      : 0x3ffc1044  A5      : 0x3ffd0a90
A6      : 0x00000000  A7      : 0x00000005  A8      : 0x8008119d  A9      : 0x00000001
A10     : 0x00000004  A11     : 0x3ffd0c7c  A12     : 0x00000000  A13     : 0x00000002
A14     : 0x3ff42000  A15     : 0x700000bb  SAR     : 0x00000018  EXCCAUSE: 0x00000007
EXCVADDR: 0x00000000  LBEG    : 0x4000164d  LEND    : 0x40001667  LCOUNT  : 0xfffffffd
Core 1 was running in ISR context:
EPC1    : 0x4008f451  EPC2    : 0x00000000  EPC3    : 0x00000000  EPC4    : 0x4010fd10

Backtrace: 0x4010fd10:0x3ffc0bb0 0x40080e6f:0x3ffc0bd0 0x40080ead:0x3ffc0bf0 0x400816cd:0x3ffc0c10 0x4008f44e:0x00000000

Rebooting...

Decoded:

0x40078000: ?? ??:0
0x40078000: ?? ??:0
0x40078a60: ?? ??:0
0x4010fd10: pthread_getspecific at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/pthread/./pthread_local_storage.c:173
0x4000164d: ?? ??:0
0x40001667: ?? ??:0
0x4008f451: esp_rom_spiflash_read_data at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/spi_flash/./spi_flash_rom_patch.c:412
0x4010fd10: pthread_getspecific at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/pthread/./pthread_local_storage.c:173
0x4010fd10: pthread_getspecific at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/pthread/./pthread_local_storage.c:173
0x40080e6f: handleInterrupt() at C:\.Dev\Sources\IOT\platformio\esp32\esp32_micros_in_interrupt_test/src/main.cpp:12
0x40080ead: __onPinInterrupt at C:\users\brainsucker\.platformio\packages\framework-arduinoespressif32@src-537c58760dafe7fcc8a1d9bbcf00b6f6\cores\esp32/esp32-hal-gpio.c:211
0x400816cd: _xt_lowint1 at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/freertos/./xtensa_vectors.S:1105
0x4008f44e: esp_rom_spiflash_read_data at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/spi_flash/./spi_flash_rom_patch.c:412

Sketch:

#include <Arduino.h>
#include <WiFi.h>

static const int PIN_INTERRUPT = 21;
static const int PIN_PWM = 18;

int freq = 500;
int ledChannel = 0;
int resolution = 8;

 void IRAM_ATTR handleInterrupt() {
   micros();//millis();
}

void setup() {
  Serial.begin(115200);

  Serial.println("Setting up PWM...");

  ledcSetup(ledChannel, freq, resolution);
  ledcAttachPin(PIN_PWM, ledChannel);
  ledcWrite(ledChannel, 33);

  Serial.println("Attaching interrupt...");

   pinMode(PIN_INTERRUPT, INPUT_PULLUP);
   attachInterrupt(digitalPinToInterrupt(PIN_INTERRUPT), handleInterrupt, CHANGE);

   Serial.println("Connecting to WIFI...");

   WiFi.mode(WIFI_STA);
   WiFi.begin("111", "111");
   while (WiFi.waitForConnectResult() != WL_CONNECTED) {
     Serial.println("Connection Failed! Rebooting...");
     delay(5000);
     ESP.restart();
   }
}

void loop() {
 }
@igrr
Copy link
Member

igrr commented May 22, 2018

#1424 solves this issue.

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

No branches or pull requests

3 participants