Skip to content

calling millis() in an interrupt service routine causes a panic #2758

Closed
@judge2005

Description

@judge2005

Compile and run the code below - you will get a panic in the serial monitor. This is surprising, given that millis() is tagged with IRAM_ATTR. If I call esp_timer_get_time(), there is no crash. I am using release 1.0.2

#include "Arduino.h"
#include "esp_spi_flash.h"
#include "nvs.h"
#include "nvs_flash.h"

hw_timer_t *timer;

void IRAM_ATTR isr() {
	millis();
}

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

    nvs_flash_init();

    timer = timerBegin(0, 80, true); // timer_id = 0; divider=80; countUp = true; So at 80MHz, we have a granularity of 1MHz
	timerAttachInterrupt(timer, isr, true); // edge = true
	timerAlarmWrite(timer, 100, true); // Period = 100 micro seconds
	timerAlarmEnable(timer);
}

void loop() {
	const uint32_t n = SPI_FLASH_SEC_SIZE;
	uint32_t val_read;
	for (uint32_t offset = 0; offset < n; offset += 4) {
		if (spi_flash_read(offset, (uint8_t *) &val_read, 4) != ESP_OK) {
			break;
		}
	}

	delay(10);
}

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