cesanta / mongoose-os

Mongoose OS - an IoT Firmware Development Framework. Supported microcontrollers: ESP32, ESP8266, CC3220, CC3200, STM32F4, STM32L4, STM32F7. Amazon AWS IoT, Microsoft Azure, Google IoT Core integrated. Code in C or JavaScript.
https://mongoose-os.com
Other
2.51k stars 429 forks source link

WDT resets on ESP8266 if mgos_gpio_enable_int is not called #528

Closed zdila closed 4 years ago

zdila commented 4 years ago

On ESP8266 if mgos_gpio_set_int_handler(4, MGOS_GPIO_INT_EDGE_ANY, handler, NULL); is called without calling mgos_gpio_enable_int(4); then after making a pulse on GPIO4 system freezes and WDT is triggered. After that WDT reset it freezes on boot and loops forever: https://pastebin.com/6RdT0txh

To prevent freeze on following boot there is an workaround:

void mgos_app_preinit(void) {
   mgos_gpio_enable_int(4);
}

Calling mgos_gpio_set_int_handlerwithout mgos_gpio_enable_int has probably no sense but I think it should not freeze the system.

pkjq commented 4 years ago

I have the same issue with disabled interrupt on any pin. I create pin interrupt handler and enable interrupt for it. When he triggered i disable interrupt for pin for any time and then set timer. When timer is fired i enable interrupt for this pin. Some times after disable pin interrupt mcu is hang: wifi connection lost and etc. If i comment code with disabling interrupt for pin and use boolean variable for filtering interrupts mcu working correctly. Problem reporducing if many interrupts triggered when it's disabled.

pkjq commented 4 years ago

I was made some experiments on ESP8266 and i have next theory: In code of int-handler exceutes:

GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, 1 << pin);

by calls function mgos_gpio_hal_clear_int. see. But if we disable interrupt in it's handler race-condition may be occured and nobody clear interrupt bit. I think you must call mgos_gpio_hal_clear_int too when interrupt of current pin is disabled.

rojer commented 4 years ago

yes, i think you're right. thank you!

pkjq commented 4 years ago

@rojer , maybe it's actual and for esp32 too.