Some Configuration facts of my current setup:
IDE: VScode
OS: Windows 11
"idf.py --version" is v1.0.3
Component config -> ESP System Settings -> Channel for console output is "USB Serial/JTAG Controller"
baud: 115200
Component config -> Application Level Tracing -> Data Destination 2 is "USB_CDC" -- I feel my issue lies here, as in I do not think this is enabling "CDC on Boot" (not quite sure what that is)
(please do ask for more if needed, I am not exactly sure what is needed for this)
------------------------------------
What am I trying to accomplish (i.e. learn):
1. How to use UART for "uart_read_bytes" and "uart_write_bytes" in an echo-task type format
2. How to read user input using "fgets" or some other 'built in' function such as "getchar" (in such a format that the monitor "waits" for input), in a fashion similar to the console using "printf" to prompt user for data and then waiting for user input.
*those two things are not the same, but I feel that as long as I can do one of them, I can figure the other out on my own. My question here is focused on the first task and we can ignore second thing
-------------------------------------
Currently I tried following the UART echo example and came up with the following program:
- #include <stdio.h>
- #include "freertos/FreeRTOS.h"
- #include "freertos/task.h"
- #include "driver/uart.h"
- #include "driver/gpio.h"
- #include "sdkconfig.h"
- #include "esp_log.h"
- #define ECHO_TEST_TXD (21)
- #define ECHO_TEST_RXD (20)
- #define ECHO_TEST_RTS (UART_PIN_NO_CHANGE)
- #define ECHO_TEST_CTS (UART_PIN_NO_CHANGE)
- #define ECHO_UART_PORT_NUM (UART_NUM_1)
- #define ECHO_UART_BAUD_RATE 115200
- #define ECHO_TASK_STACK_SIZE (2048)
- static const char *TAG = "UART TEST";
- #define BUF_SIZE (1024)
- static void echo_task(void *arg)
- {
- /* Configure parameters of an UART driver,
- * communication pins and install the driver */
- uart_config_t uart_config = {
- .baud_rate = ECHO_UART_BAUD_RATE,
- .data_bits = UART_DATA_8_BITS,
- .parity = UART_PARITY_DISABLE,
- .stop_bits = UART_STOP_BITS_1,
- .flow_ctrl = UART_HW_FLOWCTRL_DISABLE,
- .source_clk = UART_SCLK_DEFAULT,
- };
- int intr_alloc_flags = 0;
- #if CONFIG_UART_ISR_IN_IRAM
- intr_alloc_flags = ESP_INTR_FLAG_IRAM;
- #endif
- ESP_ERROR_CHECK(uart_driver_install(ECHO_UART_PORT_NUM, BUF_SIZE * 2, 0, 0, NULL, intr_alloc_flags));
- ESP_ERROR_CHECK(uart_param_config(ECHO_UART_PORT_NUM, &uart_config));
- ESP_ERROR_CHECK(uart_set_pin(ECHO_UART_PORT_NUM, ECHO_TEST_TXD, ECHO_TEST_RXD, ECHO_TEST_RTS, ECHO_TEST_CTS));
- // Configure a temporary buffer for the incoming data
- uint8_t *data = (uint8_t *) malloc(BUF_SIZE);
- while (1) {
- // Read data from the UART
- int len = uart_read_bytes(ECHO_UART_PORT_NUM, data, (BUF_SIZE - 1), 20 / portTICK_PERIOD_MS);
- // Write data back to the UART
- uart_write_bytes(ECHO_UART_PORT_NUM, (const char *) data, len);
- if (len) {
- data[len] = '\0';
- ESP_LOGI(TAG, "Recv str: %s", (char *) data);
- }
- }
- }
- void app_main(void)
- {
- xTaskCreate(echo_task, "uart_echo_task", ECHO_TASK_STACK_SIZE, NULL, 10, NULL);
- }
- --- WARNING: GDB cannot open serial ports accessed as COMx
- --- Using \\.\COM4 instead...
- --- esp-idf-monitor 1.4.0 on \\.\COM4 115200 ---
- --- Quit: Ctrl+] | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---
- ESP-ROM:esp32c3-api1-20210207
- Build:Feb 7 2021
- rst:0x15 (USB_UART_CHIP_RESET),boot:0x5 (DOWNLOAD(USB/UART0/1))
- Saved PC:0x400462e2
- 0x400462e2: ets_efuse_get_wp_pad in ROM
- waiting for download
My question: how do I make it so that I can begin writing (perhaps on PuTTY) and seeing the "ESP_LOGI" messages on the monitor? If anything here that I have given is misguided, please correct me and absolutely let me know if more information is needed, my entire methodology is wrong, or anything else of the sort.
Thank you so much for bearing with my nonsense!