Hello,
I have TIMER_0 ISR:
void IRAM_ATTR timer_group0_isr(void *para)
{
gpio_set_level(GPO_LED,1);//set pin High (see it on oscilloscope)
timer_spinlock_take(TIMER_GROUP_0);
//some variables that i will use in this ISR
static unsigned char negbit=0;
static unsigned char smSHR2 = IDDLE;
static unsigned char RfBuffer_new2[9]={};
static unsigned char *RfBufferPtr2=RfBuffer_new2;
static unsigned char bitpos2;
uint64_t tmr1_value=0;
//reset TIMER_1 value (it's not timer caused this interrupt - it's free-running TIMER_1)
timer_set_counter_value(TIMER_GROUP_0, TIMER_1, 0x00000000ULL);
//clear interrupt status and turn TIMER_0 alarm on
timer_group_clr_intr_status_in_isr(TIMER_GROUP_0, TIMER_0);
timer_group_enable_alarm_in_isr(TIMER_GROUP_0, TIMER_0);
timer_spinlock_give(TIMER_GROUP_0);
//set LOW (see it on oscilloscope)
gpio_set_level(GPO_LED,0);
}
I observe GPO_LED on oscilloscope so know how long it spend inside ISR and how often ISR comes.
TIMER_0 configuration is:
timer_config_t config0 = {
.divider = TIMER_DIVIDER,
.counter_dir = TIMER_COUNT_UP,
.counter_en = TIMER_PAUSE,
.alarm_en = TIMER_ALARM_EN,
.auto_reload = 1,
}; // default clock source is APB
When TIMER_DIVIDER = 1024, i see that:
- time spent in the interrupt: 4,1us
- interrupt period: 320us
When TIMER_DIVIDER = 512, i see that:
- time spent in the interrupt: 4,1us
- interrupt period: 160us
When TIMER_DIVIDER = 256, i see… crash, BUT ONLY FOR A MINUTE, than starts work:
abort() was called at PC 0x4008263a on core 0
0x4008263a: lock_acquire_generic at F:/GitHub/esp-idf/components/newlib/locks.c:140
Backtrace:0x4008f707:0x3ffbe160 0x4008fe4d:0x3ffbe180 0x40094c46:0x3ffbe1a0 0x4008263a:0x3ffbe210 0x40082785:0x3ffbe240 0x4013cac2:0x3ffbe260 0x4013fb21:0x3ffbe570 0x4014a7f9:0x3ffbe5a0 0x40094ad9:0x3ffbe5d0 0x4012973d:0x3ffbe620 0x400828a1:0x3ffbe650 0x40082476:0x3ffbe670 0x4000bfed:0x3ffb7390 0x40091e9d:0x3ffb73a0 0x400d4ddf:0x3ffb73c0 0x40129bc3:0x3ffb73e0 0x400d94b4:0x3ffb7410 0x400d9548:0x3ffb7460 0x400d985e:0x3ffb7490 0x4014a31f:0x3ffb7500 0x40091cb1:0x3ffb7520
0x4008f707: panic_abort at F:/GitHub/esp-idf/components/esp_system/panic.c:367
0x4008fe4d: esp_system_abort at F:/GitHub/esp-idf/components/esp_system/system_api.c:108
0x40094c46: abort at F:/GitHub/esp-idf/components/newlib/abort.c:46
0x4008263a: lock_acquire_generic at F:/GitHub/esp-idf/components/newlib/locks.c:140
0x40082785: _lock_acquire_recursive at F:/GitHub/esp-idf/components/newlib/locks.c:168
0x4013cac2: _vfprintf_r at /builds/idf/crosstool-NG/.build/HOST-x86_64-w64-mingw32/xtensa-esp32-elf/src/newlib/newlib/libc/stdio/vfprintf.c:853 (discriminator 2)
0x4013fb21: vprintf at /builds/idf/crosstool-NG/.build/HOST-x86_64-w64-mingw32/xtensa-esp32-elf/src/newlib/newlib/libc/stdio/vprintf.c:34 (discriminator 5)
0x4014a7f9: esp_log_writev at F:/GitHub/esp-idf/components/log/log.c:189
0x40094ad9: esp_log_write at F:/GitHub/esp-idf/components/log/log.c:199
0x4012973d: timer_set_counter_value at F:/GitHub/esp-idf/components/driver/timer.c:99 (discriminator 5)
0x400828a1: timer_group0_isr at f:\github\ble_spp_server\build/../main/ble_spp_server_demo.c:1159
0x40082476: _xt_lowint1 at F:/GitHub/esp-idf/components/freertos/port/xtensa/xtensa_vectors.S:1105
0x40091e9d: vPortExitCritical at F:/GitHub/esp-idf/components/freertos/port/xtensa/port.c:469
0x400d4ddf: vPortExitCriticalSafe at F:/GitHub/esp-idf/components/freertos/port/xtensa/include/freertos/portmacro.h:233
(inlined by) periph_module_enable at F:/GitHub/esp-idf/components/driver/periph_ctrl.c:30
0x40129bc3: timer_init at F:/GitHub/esp-idf/components/driver/timer.c:282 (discriminator 2)
0x400d94b4: example_tg0_timer_init at f:\github\ble_spp_server\build/../main/ble_spp_server_demo.c:1056
0x400d9548: main_task_init at f:\github\ble_spp_server\build/../main/ble_spp_server_demo.c:677
0x400d985e: app_main at f:\github\ble_spp_server\build/../main/ble_spp_server_demo.c:967
0x4014a31f: main_task at F:/GitHub/esp-idf/components/freertos/port/port_common.c:133 (discriminator 2)
0x40091cb1: vPortTaskWrapper at F:/GitHub/esp-idf/components/freertos/port/xtensa/port.c:168
ELF file SHA256: 7f6f4ca23e29a8ef
Rebooting...
After while, i see (TIMER_DIVIDER = 256):
- time spent in the interrupt: 4,1us
- interrupt period: 80us
When TIMER_DIVIDER = 128, also crash, but this time doesn’t start working after few minutes.
You can see that ISR period could be still much more than spending inside ISR, it should be 40us, so ten times more than time spent inside interrupt. So what is going wrong with it?
And the last, when I comment out:
//timer_set_counter_value(TIMER_GROUP_0, TIMER_1, 0x00000000ULL);
it starts working with expected period 40us and lower time spent inside - 2,5us