void my_timer_init(void)
{
timer_config_t timer_config_str;
timer_config_str.divider = timer_divider; //分频值,默认时钟是80mhz,80mhz/80=1mhz=1us
timer_config_str.counter_dir = TIMER_COUNT_UP;//向上计数模式
timer_config_str.counter_en = TIMER_PAUSE;//定时器计数失能
timer_config_str.alarm_en = TIMER_ALARM_EN;//使能定时器报警
timer_config_str.intr_type = TIMER_INTR_LEVEL;//定时器中断模式为电平模式
timer_config_str.auto_reload = 1; //使能自动装载
/*!<Hw timer group 0*/
/*!<Select timer0 of GROUPx*/
timer_init(TIMER_GROUP_0,TIMER_0,&timer_config_str);//esp32定时器共有两组,每组两个
timer_set_counter_value(TIMER_GROUP_0, TIMER_0, 0);//设置定时器的计数值
timer_set_alarm_value(TIMER_GROUP_0, TIMER_0, timer_go_handler);//设置定时器的报警值(进入中断的值)
timer_enable_intr(TIMER_GROUP_0, TIMER_0);//使能定时器中断
timer_isr_callback_add(TIMER_GROUP_0, TIMER_0, my_isr_handler, NULL,0);//添加定时器中断回调
timer_start(TIMER_GROUP_0, TIMER_0);//打开定时器
}
void IRAM_ATTR my_isr_handler(void)
{
timer_count++;
timer_count_value = timer_group_get_counter_value_in_isr(TIMER_GROUP_0,TIMER_0);
}
这个使用的时候编译没有错误,下载进板子之后就会一直报错,一直重启,报错内容如下
Guru Meditation Error: Core 0 panic'ed (Interrupt wdt timeout on CPU0).
Core 0 register dump:
PC : 0x400881b2 PS : 0x00060034 A0 : 0x80083e94 A1 : 0x3ffb07e0
0x400881b2: spinlock_acquire at D:/ESP32_IDF/components/esp_hw_support/include/soc/spinlock.h:122
(inlined by) vPortCPUAcquireMutex at D:/ESP32_IDF/components/freertos/port/xtensa/include/freertos/portmacro.h:158
(inlined by) vPortEnterCritical at D:/ESP32_IDF/components/freertos/port/xtensa/port.c:448
A2 : 0x3ffb0f00 A3 : 0x3ffe3b80 A4 : 0x800d5450 A5 : 0x3ffb5e60
A6 : 0x00000000 A7 : 0xe00a0c00 A8 : 0xb33fffff A9 : 0x0000cdcd
A10 : 0x4cc00001 A11 : 0xb33fffff A12 : 0x00060021 A13 : 0x00060023
A14 : 0x00000001 A15 : 0x600a0800 SAR : 0x00000020 EXCCAUSE: 0x00000005
EXCVADDR: 0x00000000 LBEG : 0x4000c46c LEND : 0x4000c477 LCOUNT : 0x00000000
Core 0 was running in ISR context:
EPC1 : 0x400d12df EPC2 : 0x00000000 EPC3 : 0x00000000 EPC4 : 0x400881b2
0x400d12df: uart_hal_write_txfifo at D:/ESP32_IDF/components/hal/uart_hal_iram.c:35
0x400881b2: spinlock_acquire at D:/ESP32_IDF/components/esp_hw_support/include/soc/spinlock.h:122
(inlined by) vPortCPUAcquireMutex at D:/ESP32_IDF/components/freertos/port/xtensa/include/freertos/portmacro.h:158
(inlined by) vPortEnterCritical at D:/ESP32_IDF/components/freertos/port/xtensa/port.c:448
Backtrace:0x400881af:0x3ffb07e0 0x40083e91:0x3ffb0800 0x4008241d:0x3ffb0820 0x400d53ae:0x3ffb5ed0 0x400e4fc4:0x3ffb5ef0 0x40088049:0x3ffb5f10
0x400881af: spinlock_acquire at D:/ESP32_IDF/components/esp_hw_support/include/soc/spinlock.h:122
(inlined by) vPortCPUAcquireMutex at D:/ESP32_IDF/components/freertos/port/xtensa/include/freertos/portmacro.h:158
(inlined by) vPortEnterCritical at D:/ESP32_IDF/components/freertos/port/xtensa/port.c:448
0x40083e91: vPortEnterCriticalSafe at D:/ESP32_IDF/components/freertos/port/xtensa/include/freertos/portmacro.h:222
(inlined by) timer_isr_default at D:/ESP32_IDF/components/driver/timer.c:211
0x4008241d: _xt_lowint1 at D:/ESP32_IDF/components/freertos/port/xtensa/xtensa_vectors.S:1105
0x400d53ae: app_main at C:\Users\zhaidayu\Desktop\esp32code\4.timer\build/../main/main.c:17
0x400e4fc4: main_task at D:/ESP32_IDF/components/freertos/port/port_common.c:133 (discriminator 2)
0x40088049: vPortTaskWrapper at D:/ESP32_IDF/components/freertos/port/xtensa/port.c:168
Core 1 register dump:
PC : 0x400e49a6 PS : 0x00060834 A0 : 0x800d4bc6 A1 : 0x3ffb7370
0x400e49a6: esp_pm_impl_waiti at D:/ESP32_IDF/components/esp_pm/pm_impl.c:829
A2 : 0x00000000 A3 : 0x00000000 A4 : 0x00000001 A5 : 0x80000001
A6 : 0x00000003 A7 : 0x00060023 A8 : 0x800d7442 A9 : 0x3ffb7340
A10 : 0x00000000 A11 : 0x00060823 A12 : 0x00060820 A13 : 0x00060823
A14 : 0x00000001 A15 : 0x00000000 SAR : 0x00000018 EXCCAUSE: 0x00000005
EXCVADDR: 0x00000000 LBEG : 0x00000000 LEND : 0x00000000 LCOUNT : 0x00000000
Backtrace:0x400e49a3:0x3ffb7370 0x400d4bc3:0x3ffb7390 0x40086a02:0x3ffb73b0 0x40088049:0x3ffb73d0
0x400e49a3: cpu_ll_waiti at D:/ESP32_IDF/components/hal/esp32/include/hal/cpu_ll.h:183
(inlined by) esp_pm_impl_waiti at D:/ESP32_IDF/components/esp_pm/pm_impl.c:827
0x400d4bc3: esp_vApplicationIdleHook at D:/ESP32_IDF/components/esp_common/src/freertos_hooks.c:63
0x40086a02: prvIdleTask at D:/ESP32_IDF/components/freertos/tasks.c:3846 (discriminator 1)
0x40088049: vPortTaskWrapper at D:/ESP32_IDF/components/freertos/port/xtensa/port.c:168
ELF file SHA256: 11b82529bf1c7412
Rebooting...
ets Jul 29 2019 12:21:46
rst:0xc (SW_CPU_RESET),boot:0x12 (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:0x3fff0030,len:7264
load:0x40078000,len:14912
load:0x40080400,len:3688
0x40080400: _init at ??:?
entry 0x4008067c
求解答
关于ESP32定时器运行报错的问题
-
- Posts: 290
- Joined: Wed Sep 05, 2018 6:23 am
Re: 关于ESP32定时器运行报错的问题
callback 应该是要求返回的bool类型的,不知道为什么你的代码居然能够编译通过。另外建议你参考master上的example,代码有清理过,比以前清晰简单:https://github.com/espressif/esp-idf/tr ... acy_driver
Who is online
Users browsing this forum: Google [Bot] and 70 guests