Unstable/frozen console using linenoise()
Posted: Mon Jan 31, 2022 11:35 am
Hi all, I'm trying to get linenoise working (over usb and idf monitor, nothing fancy)
I'm getting unstable behaviour that might be caused by the way I initialize the uart driver, can someone tell me if there's something wrong with this code ?
By "unstable behaviour" I mean : working as intended OR linenoise frozen OR core dump crashes
THat might be related with some other parts of my code, but being sure that this one is ok would be very helpful !
I'm getting unstable behaviour that might be caused by the way I initialize the uart driver, can someone tell me if there's something wrong with this code ?
By "unstable behaviour" I mean : working as intended OR linenoise frozen OR core dump crashes
THat might be related with some other parts of my code, but being sure that this one is ok would be very helpful !
- // Borrowed from :
- // https://github.com/espressif/esp-idf/blob/8153bfe4125e6a608abccf1561fd10285016c90a/components/console/esp_console_repl.c#L201
- // https://github.com/espressif/esp-idf/blob/e899edd7933e0f7ef98a93a24d11d28f519955c8/components/console/esp_console.h#L88
- fflush(stdout);
- fsync(fileno(stdout));
- esp_vfs_dev_uart_port_set_rx_line_endings(CONFIG_ESP_CONSOLE_UART_NUM, ESP_LINE_ENDINGS_CR);
- esp_vfs_dev_uart_port_set_tx_line_endings(CONFIG_ESP_CONSOLE_UART_NUM, ESP_LINE_ENDINGS_CRLF);
- const uart_config_t uart_config = {
- .baud_rate = CONFIG_ESP_CONSOLE_UART_BAUDRATE,
- .data_bits = UART_DATA_8_BITS,
- .parity = UART_PARITY_DISABLE,
- .stop_bits = UART_STOP_BITS_1,
- .source_clk = UART_SCLK_REF_TICK, // #if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32S2
- };
- ESP_ERROR_CHECK(uart_param_config(CONFIG_ESP_CONSOLE_UART_NUM, &uart_config));
- ESP_ERROR_CHECK(uart_set_pin(CONFIG_ESP_CONSOLE_UART_NUM, -1, -1, -1, -1));
- ESP_ERROR_CHECK(uart_driver_install(CONFIG_ESP_CONSOLE_UART_NUM, 256, 0, 0, NULL, 0));
- esp_vfs_dev_uart_use_driver(CONFIG_ESP_CONSOLE_UART_NUM);
- setvbuf(stdin, NULL, _IONBF, 0);
- linenoiseHistorySetMaxLen(25);
- linenoiseSetMaxLineLen(32);
- linenoiseAllowEmpty(false);
- while (true) {
- char* line = linenoise(">");
- if (strlen(line) > 0) {
- // do some stuff with the line
- linenoiseFree(line);
- }
- }