Page 1 of 1

IDF console example code questions

Posted: Sat May 15, 2021 1:48 am
by zliudr
I just discovered the console_example today while searching for a way to turn off console. What a hidden gem the console is! My original goal to turn off console print is to focus on using the UART0 as a UART so I can send things from PC to ESP32. But if I can make use of the console feature that takes and parses commands, I can do so much more!

So I have some questions:

1) In order to have PC interact with the console, I'd like to disable prompt and echo. Are these things possible? If not, I will have to make my PC Python script strip off the echo and prompt so it would be able to analyze the response to its command.

2) Why does the console_example code initialize UART0 and install its driver? Aren't those steps already taken otherwise how would ESP_LOGx() and printf() work without the main initializing UART0 before printing to console?

https://github.com/espressif/esp-idf/bl ... main.c#L82

Re: IDF console example code questions

Posted: Mon May 17, 2021 2:09 am
by ESP_Sprite
Can't answer 1, but for 2: the 'normal' (ROM) driver you get on startup is a driver that does polling to figure out if it can send more data or if data is already received; in an interactive system like this, it would be inefficient as one task is only polling the UART over and over again to see if a key has been pressed on the console. The IDF driver is a 'blocking' one: if something like getch() is called, the driver will suspend the task until an UART receive interrupt has been received.

Re: IDF console example code questions

Posted: Mon May 17, 2021 4:16 am
by zliudr
Thank you!

Your information on how bootloader handles UART is precise and appreciated. So once the app starts running and we're using printf and ESP_LOGx(), are we still using polling or has the buffer-driven UART0 mechanism been set up already say be the second-stage bootloader? Why would this sample code have to install the UART driver manually?

By the way, I've decided to not disable echo because I can handle it if I have a specific prompt that can be searched by the PC host so it knows that the device has entered the command line and can accept commands. Then after sending a command, the PC can wait until another prompt is received to know the command has finished. It's all useful now. I just have to disable all possible printf() from say wifi and rest part of my app to make the command line quiet enough.

What I'm trying to do is to incorporate this terminal command line into an existing project. Do I really need to install UART0?

Re: IDF console example code questions

Posted: Tue May 18, 2021 4:23 am
by zliudr
Is there any reason the wifi commands aren't turned into their own components like the nvs and system commands?

Re: IDF console example code questions

Posted: Tue May 18, 2021 5:55 am
by ESP_Sprite
I'm not too familiar with the console code, but I'll answer what I can: It may work with the ROM driver as well, but if it does, it's pretty certain you'll get better performance out of it if you install the (interrupt-driven) driver. Note that this driver isn't installed until your program explicitly calls uart_driver_install, if it never does (and lots of programs don't) the ESP32 will keep on using the ROM driver.

Re: IDF console example code questions

Posted: Tue May 18, 2021 5:36 pm
by zliudr
I see! So I've been not doing the efficient way all along! Maybe some example code has installed driver on UART0 but I missed them because I didn't go through as many as I should and dived in head first. ESP-IDF is so extensive. I bet if I put down everything I'm working on and just keep learning it, it will take me months to get through the hardware reference manual of ESP32, data sheet of WROVER, then ESP-IDF doc with every example out there.

I'm glad that people like you are here to provide guidance.

Re: IDF console example code questions

Posted: Thu May 19, 2022 5:25 am
by LC2047
console_example_main.c
(3.16 KiB) Downloaded 285 times
Complie_error.jpg
Complie_error.jpg (635.86 KiB) Viewed 4165 times
Hi All

I use VS code with PlatformIO to comply ESP-IDF example(esp-idf-master\examples\system\console\basic\main.c), but no success. Please share your comments to fix it.

Why the original example(demo) has an error in compile?

BR