IDF console example code questions

zliudr
Posts: 360
Joined: Thu Oct 03, 2019 5:15 am

IDF console example code questions

Postby zliudr » Sat May 15, 2021 1:48 am

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

ESP_Sprite
Posts: 9727
Joined: Thu Nov 26, 2015 4:08 am

Re: IDF console example code questions

Postby ESP_Sprite » Mon May 17, 2021 2:09 am

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.

zliudr
Posts: 360
Joined: Thu Oct 03, 2019 5:15 am

Re: IDF console example code questions

Postby zliudr » Mon May 17, 2021 4:16 am

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?

zliudr
Posts: 360
Joined: Thu Oct 03, 2019 5:15 am

Re: IDF console example code questions

Postby zliudr » Tue May 18, 2021 4:23 am

Is there any reason the wifi commands aren't turned into their own components like the nvs and system commands?

ESP_Sprite
Posts: 9727
Joined: Thu Nov 26, 2015 4:08 am

Re: IDF console example code questions

Postby ESP_Sprite » Tue May 18, 2021 5:55 am

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.

zliudr
Posts: 360
Joined: Thu Oct 03, 2019 5:15 am

Re: IDF console example code questions

Postby zliudr » Tue May 18, 2021 5:36 pm

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.

LC2047
Posts: 2
Joined: Thu May 19, 2022 5:11 am

Re: IDF console example code questions

Postby LC2047 » Thu May 19, 2022 5:25 am

console_example_main.c
(3.16 KiB) Downloaded 285 times
Complie_error.jpg
Complie_error.jpg (635.86 KiB) Viewed 4170 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

Who is online

Users browsing this forum: No registered users and 100 guests