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

mgos_gpio_set_button_handler causes a core dump on ESP8266 #519

Open Nothing3000 opened 4 years ago

Nothing3000 commented 4 years ago

When setting GPIO 2 to act as a button the program always crashes before the configuration function is completed. In the core dump the last called function is esp8266_gpio_isr.

#include "mgos.h"

struct mgos_uart_config ucfg;

static void switch_cb(int pin, void *arg)
{
    LOG(LL_INFO, ("Switch got pressed"));
    (void) pin;
    (void) arg;
}

enum mgos_app_init_result mgos_app_init(void) {
    int uart_no = 0;
    int sw1Pin = mgos_sys_config_get_GPIO_sw1Pin();

    mgos_uart_config_set_defaults(uart_no, &ucfg);

    ucfg.baud_rate = 115200;
    ucfg.rx_buf_size = 1500;
    ucfg.tx_buf_size = 1500;

    if (!mgos_uart_configure(uart_no, &ucfg)) {
    LOG(LL_ERROR, ("Failed to configure UART%d", uart_no));
    }

    LOG(LL_INFO, ("Switch on pin: %d", sw1Pin));

    mgos_gpio_set_button_handler(sw1Pin, MGOS_GPIO_PULL_UP, MGOS_GPIO_INT_EDGE_POS, 50, switch_cb, NULL);
    mgos_gpio_enable_int(sw1Pin);
    LOG(LL_INFO, ("Configured button interrupt"));
  return MGOS_APP_INIT_SUCCESS;
}

When mgos_gpio_set_button_handler gets replaced with:

mgos_gpio_setup_input(sw1Pin, MGOS_GPIO_PULL_UP);
mgos_gpio_set_int_handler_isr(sw1Pin, MGOS_GPIO_INT_EDGE_POS, switch_cb, NULL);

The same problem occurs.

Only when mgos_gpio_setup_input gets replaced by mgos_gpio_setup_output the above example starts working as expected. coredump.log