Unstable/frozen console using linenoise()

chris33
Posts: 9
Joined: Wed Dec 22, 2021 10:35 am

Unstable/frozen console using linenoise()

Postby chris33 » 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 !
  1. // Borrowed from :
  2. //  https://github.com/espressif/esp-idf/blob/8153bfe4125e6a608abccf1561fd10285016c90a/components/console/esp_console_repl.c#L201
  3. //  https://github.com/espressif/esp-idf/blob/e899edd7933e0f7ef98a93a24d11d28f519955c8/components/console/esp_console.h#L88
  4.     fflush(stdout);
  5.     fsync(fileno(stdout));
  6.     esp_vfs_dev_uart_port_set_rx_line_endings(CONFIG_ESP_CONSOLE_UART_NUM, ESP_LINE_ENDINGS_CR);
  7.     esp_vfs_dev_uart_port_set_tx_line_endings(CONFIG_ESP_CONSOLE_UART_NUM, ESP_LINE_ENDINGS_CRLF);
  8.     const uart_config_t uart_config = {
  9.         .baud_rate = CONFIG_ESP_CONSOLE_UART_BAUDRATE,
  10.         .data_bits = UART_DATA_8_BITS,
  11.         .parity = UART_PARITY_DISABLE,
  12.         .stop_bits = UART_STOP_BITS_1,
  13.         .source_clk = UART_SCLK_REF_TICK,  // #if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32S2
  14.     };
  15.     ESP_ERROR_CHECK(uart_param_config(CONFIG_ESP_CONSOLE_UART_NUM, &uart_config));
  16.     ESP_ERROR_CHECK(uart_set_pin(CONFIG_ESP_CONSOLE_UART_NUM, -1, -1, -1, -1));
  17.     ESP_ERROR_CHECK(uart_driver_install(CONFIG_ESP_CONSOLE_UART_NUM, 256, 0, 0, NULL, 0));
  18.     esp_vfs_dev_uart_use_driver(CONFIG_ESP_CONSOLE_UART_NUM);
  19.     setvbuf(stdin, NULL, _IONBF, 0);
  20.  
  21.     linenoiseHistorySetMaxLen(25);
  22.     linenoiseSetMaxLineLen(32);
  23.     linenoiseAllowEmpty(false);
  24.     while (true) {
  25.         char* line = linenoise(">");
  26.         if (strlen(line) > 0) {
  27. // do some stuff with the line
  28.             linenoiseFree(line);
  29.         }
  30.     }

chris33
Posts: 9
Joined: Wed Dec 22, 2021 10:35 am

Re: Unstable/frozen console using linenoise()

Postby chris33 » Mon Feb 21, 2022 4:06 pm

Still having problems from time to time...

Any clue ?

Who is online

Users browsing this forum: No registered users and 87 guests