mirror of
https://github.com/espressif/esp-idf.git
synced 2026-09-22 13:01:16 +03:00
fix(nvs_console): use esp_stdio for console peripheral init
This commit is contained in:
@@ -13,9 +13,13 @@ This example can run on any ESP32 family development board.
|
||||
|
||||
The example can be configured through `menuconfig`:
|
||||
1. Enable/disable command history storage (`CONFIG_CONSOLE_STORE_HISTORY`)
|
||||
2. Configure UART parameters
|
||||
2. Select the console channel under **Component config → ESP-STDIO → Channel for console output**
|
||||
(UART0 by default, or **USB Serial/JTAG** / **USB CDC** on supported chips)
|
||||
3. Configure console prompt color settings
|
||||
|
||||
On chips with USB Serial/JTAG, set the channel to **USB Serial/JTAG Controller**,
|
||||
connect the USB cable to that interface, then monitor that port.
|
||||
|
||||
## How to Use
|
||||
|
||||
### Build and Flash
|
||||
@@ -26,7 +30,7 @@ Build the project and flash it to the board, then run monitor tool to view seria
|
||||
idf.py -p PORT flash monitor
|
||||
```
|
||||
|
||||
(Replace PORT with the name of the serial port to use.)
|
||||
(Replace PORT with the serial port that matches the console channel selected above.)
|
||||
|
||||
### Console Commands
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
idf_component_register(SRCS "nvs_console_main.c"
|
||||
"console_settings.c"
|
||||
REQUIRES cmd_nvs cmd_system esp_driver_uart fatfs
|
||||
REQUIRES cmd_nvs cmd_system esp_stdio fatfs
|
||||
INCLUDE_DIRS ".")
|
||||
|
||||
# Create a NVS image from the contents of the `nvs_data` CSV file
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2025-2026 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Unlicense OR CC0-1.0
|
||||
*/
|
||||
@@ -10,9 +10,7 @@
|
||||
#include "esp_system.h"
|
||||
#include "esp_log.h"
|
||||
#include "esp_console.h"
|
||||
#include "esp_vfs_dev.h"
|
||||
#include "driver/uart.h"
|
||||
#include "driver/uart_vfs.h"
|
||||
#include "esp_stdio.h"
|
||||
#include "linenoise/linenoise.h"
|
||||
#include "argtable3/argtable3.h"
|
||||
#include "console_settings.h"
|
||||
@@ -30,34 +28,11 @@ void initialize_console_peripheral(void)
|
||||
fflush(stdout);
|
||||
fsync(fileno(stdout));
|
||||
|
||||
/* Install UART / USB Serial/JTAG / USB CDC driver based on menuconfig */
|
||||
ESP_ERROR_CHECK(esp_stdio_install_io_driver());
|
||||
|
||||
/* Disable buffering on stdin */
|
||||
setvbuf(stdin, NULL, _IONBF, 0);
|
||||
|
||||
/* Minicom, screen, idf_monitor send CR when ENTER key is pressed */
|
||||
uart_vfs_dev_port_set_rx_line_endings(CONFIG_ESP_CONSOLE_UART_NUM, ESP_LINE_ENDINGS_CR);
|
||||
/* Move the caret to the beginning of the next line on '\n' */
|
||||
uart_vfs_dev_port_set_tx_line_endings(CONFIG_ESP_CONSOLE_UART_NUM, ESP_LINE_ENDINGS_CRLF);
|
||||
|
||||
/* Configure UART */
|
||||
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,
|
||||
#if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32S2
|
||||
.source_clk = UART_SCLK_REF_TICK,
|
||||
#else
|
||||
.source_clk = UART_SCLK_XTAL,
|
||||
#endif
|
||||
};
|
||||
|
||||
/* Install UART driver for interrupt-driven reads and writes */
|
||||
ESP_ERROR_CHECK(uart_driver_install(CONFIG_ESP_CONSOLE_UART_NUM,
|
||||
256, 0, 0, NULL, 0));
|
||||
ESP_ERROR_CHECK(uart_param_config(CONFIG_ESP_CONSOLE_UART_NUM, &uart_config));
|
||||
|
||||
/* Tell VFS to use UART driver */
|
||||
uart_vfs_dev_use_driver(CONFIG_ESP_CONSOLE_UART_NUM);
|
||||
}
|
||||
|
||||
void initialize_console_library(const char *history_path)
|
||||
|
||||
Reference in New Issue
Block a user