Panic with Wifi and Timer Interrupt

gr1483
Posts: 1
Joined: Sat Aug 11, 2018 2:36 pm

Panic with Wifi and Timer Interrupt

Postby gr1483 » Sat Aug 11, 2018 2:44 pm

Hi All,

Sorry if this is a silly question, i have been working with my ESP32 and GPIO, and i have just started to add wifi to it. However, it keeps Panic'ing.

I have tracked it down to setting a pin level in the timer interrupt:

I have put my code below:

Code: Select all

void IRAM_ATTR timer_group0_isr0(void *para) {
  int timer_idx = (int) para;

    /* Retrieve the interrupt status and the counter value
       from the timer that reported the interrupt */

  	  uint32_t intr_status = TIMERG0.int_st_timers.val;


    /* Clear the interrupt
       and update the alarm time for the timer with without reload */

  if ((intr_status & BIT(timer_idx)) && timer_idx == TIMER_0) {

	  timer10us |= (option0);
	  cnt++;
	  if (cnt > 2499) {
		  cnt = 0;
		  timer25ms |= (option0 | option1);
	  }

	  TIMERG0.int_clr_timers.t0 = 1;
	  TIMERG0.hw_timer[0].config.alarm_en = TIMER_ALARM_EN;
  } else if ((intr_status & BIT(timer_idx)) && timer_idx == TIMER_1) {
	 //38khz
	if (IRCarrierWave==0) {
			gpio_set_level(IRCarrierPin, 1);
			IRCarrierWave = 1;
			} else {
			gpio_set_level(IRCarrierPin, 0);
			IRCarrierWave = 0;
			}
			TIMERG0.int_clr_timers.t1 = 1;
		/* After the alarm has been triggered
		  we need enable it again, so it is triggered the next time */
			TIMERG0.hw_timer[1].config.alarm_en = TIMER_ALARM_EN;
	}
}



void inittimers() {

			      	  timer_config_t config;
			          config.divider = TIMER_DIVIDER;
			          config.counter_dir = TIMER_COUNT_UP;
			          config.counter_en = TIMER_PAUSE;
			          config.alarm_en = TIMER_ALARM_EN;
			          config.intr_type = TIMER_INTR_LEVEL;
			          config.auto_reload = TIMER_AUTORELOAD_EN;
			          timer_init(TIMER_GROUP_0, 0, &config);
			          timer_init(TIMER_GROUP_0, 1, &config);

			          /* Timer's counter will initially start from value below.
			             Also, if auto_reload is set, this value will be automatically reload on alarm */
			          timer_set_counter_value(TIMER_GROUP_0, 0, 0x00000000ULL);
			          timer_set_counter_value(TIMER_GROUP_0, 1, 0x00000000ULL);


			      	//Setting up Timer 0.0 for 25ms

			          /* Configure the alarm value and the interrupt on alarm. */
			          timer_set_alarm_value(TIMER_GROUP_0, 0, (TIMER_INTERVAL0x0_SEC * TIMER_SCALE));
			          timer_enable_intr(TIMER_GROUP_0,0);
			          //										Function	Parameters	Run in Iram			Null
			          timer_isr_register(TIMER_GROUP_0, 0, timer_group0_isr0,(void *) 0, ESP_INTR_FLAG_IRAM, NULL);
			          timer_start(TIMER_GROUP_0, 0);

	//Setting up Timer 0.1 for 38khz

		          /* Configure the alarm value and the interrupt on alarm. */
		          timer_set_alarm_value(TIMER_GROUP_0, 1, (TIMER_INTERVAL0x1_SEC * TIMER_SCALE));
		          timer_enable_intr(TIMER_GROUP_0, 1);
		          //										Function	Parameters	Run in Iram			Null
		          timer_isr_register(TIMER_GROUP_0, 1, timer_group0_isr0,(void *) 1, ESP_INTR_FLAG_IRAM, NULL);
		          timer_start(TIMER_GROUP_0, 1);

}

Code: Select all

void app_main()
{


	 //   Initialize NVS
	    esp_err_t ret = nvs_flash_init();
	  if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
	     ESP_ERROR_CHECK(nvs_flash_erase());
	    ret = nvs_flash_init();
	  }
	  ESP_ERROR_CHECK(ret);

	  printf("Setting up Wifi\n");
	    vTaskDelay(500 / portTICK_PERIOD_MS);
	  wifi_init_sta();

	    inittimers();
	    vTaskDelay(25 / portTICK_PERIOD_MS);
}

If i comment out the inittimers() function the module connects to wifi, if i comment out the wifi_init_sta(); the timer runs fine, but when i have both, they panic, with the following:

Code: Select all

[color=#008000]I (0) cpu_start: App cpu up.
I (376) heap_init: Initializing. RAM available for dynamic allocation:
I (383) heap_init: At 3FFAE6E0 len 00001920 (6 KiB): DRAM
I (389) heap_init: At 3FFB94F0 len 00026B10 (154 KiB): DRAM
I (395) heap_init: At 3FFE0440 len 00003BC0 (14 KiB): D/IRAM
I (401) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
I (408) heap_init: At 40090548 len 0000FAB8 (62 KiB): IRAM
I (414) cpu_start: Pro cpu start user code
I (96) cpu_start: Starting scheduler on PRO CPU.
I (0) cpu_start: Starting scheduler on APP CPU.
Setting up Wifi
I (1185) wifi: wifi driver task: 3ffc0474, prio:23, stack:3584, core=0
I (1186) wifi: wifi firmware version: 202823a
I (1186) wifi: config NVS flash: enabled
I (1188) wifi: config nano formating: disabled
I (1193) system_api: Base MAC address is not set, read default base MAC address from BLK0 of EFUSE
I (1202) system_api: Base MAC address is not set, read default base MAC address from BLK0 of EFUSE
I (1235) wifi: Init dynamic tx buffer num: 32
I (1235) wifi: Init data frame dynamic rx buffer num: 32
I (1235) wifi: Init management frame dynamic rx buffer num: 32
I (1239) wifi: Init static rx buffer size: 1600
I (1243) wifi: Init static rx buffer num: 10
I (1247) wifi: Init dynamic rx buffer num: 32
I (1335) phy: phy_version: 3960, 5211945, Jul 18 2018, 10:40:07, 0, 0
I (1337) wifi: mode : sta (30:ae:a4:06:3d:ec)
I (1338) simple wifi: wifi_init_sta finished.
I (1340) simple wifi: connect to ap SSID:Veqtor password:Veqtor01428!
I (1348) gpio: GPIO[12]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0
I (1357) gpio: GPIO[13]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0
I (1366) gpio: GPIO[14]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0
I (1376) gpio: GPIO[17]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0
I (1385) gpio: GPIO[27]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0
I (1394) gpio: GPIO[32]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0
Initialising Timers!
I (1461) wifi: n:11 0, o:1 0, ap:255 255, sta:11 0, prof:1
I (3560) wifi: state: init -> auth (b0)
I (3570) wifi: state: auth -> assoc (0)
I (3575) wifi: state: assoc -> run (10)
I (3591) wifi: connected with Veqtor, channel 11
Guru Meditation Error: Core  0 panic'ed (Cache disabled but cached memory region accessed)
Core 0 register dump:
PC      : 0x400e6b70  PS      : 0x00060034  A0      : 0x40082538  A1      : 0x3ffb05f0
0x400e6b70: gpio_set_level at D:/msys32/home/Simon/esp/esp-idf/components/driver/gpio.c:238

0x40082538: _xt_lowint1 at D:/msys32/home/Simon/esp/esp-idf/components/freertos/xtensa_vectors.S:1105

A2      : 0x00000001  A3      : 0x3ffc01e0  A4      : 0x00000020  A5      : 0x4008cf98
0x4008cf98: _frxt_int_enter at D:/msys32/home/Simon/esp/esp-idf/components/freertos/portasm.S:119

A6      : 0x00000001  A7      : 0x00000000  A8      : 0x80082cca  A9      : 0x00000000
A10     : 0x00000011  A11     : 0x00000000  A12     : 0x80083ac9  A13     : 0x3ffbff70
A14     : 0x00000026  A15     : 0x3ffb43d0  SAR     : 0x00000001  EXCCAUSE: 0x00000007
EXCVADDR: 0x00000000  LBEG    : 0x4000164d  LEND    : 0x40001667  LCOUNT  : 0xfffffffd
Core 0 was running in ISR context:
EPC1    : 0x400835a9  EPC2    : 0x00000000  EPC3    : 0x00000000  EPC4    : 0x400e6b70
0x400835a9: esp_ptr_internal at D:/msys32/home/Simon/esp/esp-idf/components/soc/include/soc/soc_memory_layout.h:136 (discriminator 4)
 (inlined by) spi_flash_read at D:/msys32/home/Simon/esp/esp-idf/components/spi_flash/flash_ops.c:527 (discriminator 4)

0x400e6b70: gpio_set_level at D:/msys32/home/Simon/esp/esp-idf/components/driver/gpio.c:238


Backtrace: 0x400e6b70:0x3ffb05f0 0x40082535:0x3ffb0610 0x400835a6:0x00000000
0x400e6b70: gpio_set_level at D:/msys32/home/Simon/esp/esp-idf/components/driver/gpio.c:238

0x40082535: _xt_lowint1 at D:/msys32/home/Simon/esp/esp-idf/components/freertos/xtensa_vectors.S:1105

0x400835a6: esp_ptr_internal at D:/msys32/home/Simon/esp/esp-idf/components/soc/include/soc/soc_memory_layout.h:136 (discriminator 4)
 (inlined by) spi_flash_read at D:/msys32/home/Simon/esp/esp-idf/components/spi_flash/flash_ops.c:527 (discriminator 4)


Rebooting...
ets Jun  8 2016 00:22:57[/color]

Any help would be much appreciated.

Thanks

Return to “ESP32 IDF”

Who is online

Users browsing this forum: colman, Google [Bot] and 12 guests