Timer interrupt during spi_flash causes crash

joostn
Posts: 19
Joined: Thu Jan 22, 2015 5:00 pm

Timer interrupt during spi_flash causes crash

Postby joostn » Thu Jan 22, 2015 9:29 pm

Here's a small bug in the SDK I've run into (esp_iot_sdk_v0.9.5_b1):

I'm using a timer interrupt on Timer1:

Code: Select all

ETS_FRC_TIMER1_INTR_ATTACH(...);
TM1_EDGE_INT_ENABLE();
ETS_FRC1_INTR_ENABLE();

running every millisecond or so.

If I do a flash erase/flash write at the same time:

Code: Select all

spi_flash_erase_sector(...);
spi_flash_write(...);

the ESP seems to crash and reboot if a timer interrupt occurs during the flash access.

Of course this can be worked around by disabling interrupts whenever I access flash. But I'm having similar problems if I start the timer interrupt already in user_init(): the esp will reboot if I do so. Only if I enable the timer interrupt after the ESP has connected to a wifi network things work fine. I'm guessing this is caused by the same problem: the firmware reads stored configuration data from flash pages 7c-7f. Unfortunately I'm not able to disable interrupts temporarily while this happens, because it happens inside your SDK code.

jackon
Posts: 28
Joined: Thu Oct 23, 2014 9:05 am

Re: Timer interrupt during spi_flash causes crash

Postby jackon » Tue Jan 27, 2015 3:57 pm

hi joostn,
spi_flash_xxxx apis will firstly disable cache, then enable cache.
so if your isr codes use ICACHE_FLASH_ATTR, it will crash, because cache is disabled when interrupt occur.
Pls don't use ICACHE_FLASH_ATTR in any functions isr calls and isr self.

joostn
Posts: 19
Joined: Thu Jan 22, 2015 5:00 pm

Re: Timer interrupt during spi_flash causes crash

Postby joostn » Tue Jan 27, 2015 5:40 pm

Ah! Thanks, I'll check my code.

younger
Posts: 39
Joined: Mon Dec 29, 2014 1:49 pm

Re: Timer interrupt during spi_flash causes crash

Postby younger » Thu Feb 12, 2015 10:18 am

joostn wrote:Ah! Thanks, I'll check my code.

Do you have resolved this bug?

I just delete the ICACHE_FLASH_ATTR,but it still remains.

joostn
Posts: 19
Joined: Thu Jan 22, 2015 5:00 pm

Re: Timer interrupt during spi_flash causes crash

Postby joostn » Fri Feb 13, 2015 2:57 pm

Yes for me that solved the issue.
In my project all code was in Flash by default, so I had to explicitly move it to IRAM.
Also check all functions called from your ISR. And I had a (c++) function declared as inline which the compiler didn't inline but placed in flash instead.

Who is online

Users browsing this forum: No registered users and 82 guests