espressif / esp-idf

Espressif IoT Development Framework. Official development framework for Espressif SoCs.
Apache License 2.0
13.58k stars 7.27k forks source link

the idf.py monitor baudrate setting in sdkconfig has no effect or is ignored (IDFGH-7120) #8726

Closed moefear85 closed 2 years ago

moefear85 commented 2 years ago

Environment

Problem Description

setting the idf.py monitor baudrate in sdkconfig has to effect. All entries still cause the serial output to be at 115200. So even if I choose 921600bps, the output remains at 115200. If I use an external monitor that I set to 115200, I can see the output normally. But when launching the idf.py monitor, since it expects 921600, all I get is junk. There is absolutely nothing in my code that is modifying the baudrate or touching the uart in any way. I only use ESP_LOG and printf functions. I never set any environment variables that would change the baudrate. MONITORBAUD is not set. It seems the chip doesn't respect this sdkconfig entry and ignores it.

dobairoland commented 2 years ago

Hi @moefear85. The expected behavior has been recently changed (https://docs.espressif.com/projects/esp-idf/en/latest/esp32/migration-guides/tools.html#idf-monitor) which will be the case for ESP-IDF v5.0 and later.

So staying with v4.4, please explain what would you like to achieve? Do you want to increase the console baud rate or you are just bothered that there are so many different baudrates?

CONFIG_ESPTOOLPY_BAUD is the baudrate used for flashing. I think this is not related your question. I expect that you are not changing this.

CONFIG_ESPTOOLPY_MONITOR_BAUD - are you saying that this doesn't have effect? This has been recently removed and idf.py -b <baud> is the preferred way to use instead. But even in v4.4, I would use the command line argument instead as it makes more sense.

CONFIG_ESP_CONSOLE_UART_BAUDRATE - this is the baudrate of your ESP application. You will see junk characters if the CONFIG_ESPTOOLPY_MONITOR_BAUD value is not the same.

dobairoland commented 2 years ago

setting the idf.py monitor baudrate in sdkconfig has to effect. All entries still cause the serial output to be at 115200.

Custom UART needs to be selected for the console and CONFIG_ESP_CONSOLE_UART_BAUDRATE set for the desired baudrate. This will change the speed of text sent from the ESP device.

You set CONFIG_ESPTOOLPY_BAUD to the same value of CONFIG_ESP_CONSOLE_UART_BAUDRATE or ESPTOOLPY_MONITOR_BAUD_CONSOLE in order to follow the console baud rate. This will set the IDF Monitor speed.

moefear85 commented 2 years ago

I'm setting CONFIG_ESPTOOLPY_MONITOR_BAUD to 921600. But this is not having an effect. When I open any serial console @115200, it works fine. When I do so with @921600, I see jibberish. So when idf.py tries to open the monitor @921600, I see jibberish. I don't understand why setting CONFIG_ESPTOOLPY_MONITOR_BAUD is being ignored by the esp chip/app/uart (while idf.py monitor correctly opens in 921600).

However, CONFIG_ESP_CONSOLE_UART_BAUDRATE is set to 115200 in my sdkconfig, even though I never set it anywhere in menuconfig. In menuconfig, under "serial flasher config->idf.py monitor baud rate" I'm choosing "921600". Thus the variable CONFIG_ESPTOOLPY_MONITOR_BAUD is correctly being set to 921600, but when I inspect the sdkconfig file itself, I realize CONFIG_ESP_CONSOLE_UART_BAUDRATE is set to 115200, even though I never chose this. Could this be the source of the problem? I'm going to test it right now.

moefear85 commented 2 years ago

@dobairoland

I just realized, CONFIG_ESP_CONSOLE_UART_BAUDRATE is automatically being set to 115200 in the sdkconfig file everytime I flash the application. Even if I delete it or comment it out, once I hit the flash button, the file gets instantly modified and it reappears. So i have no way to test things with this option off. Is there a logical reason for this?

dobairoland commented 2 years ago

115200 is the default baudrate for the console application. The logical reason is that it has to have some default value. Without a default value we should expect a build error because the ESP application cannot communicate with an undefined speed.

dobairoland commented 2 years ago

I don't understand why setting CONFIG_ESPTOOLPY_MONITOR_BAUD is being ignored by the esp chip/app/uart

Because changing the monitor baud rate doesn't imply or change the console baud rate.

dobairoland commented 2 years ago

So I think the solution for your problem is to set the monitor baud rate to follow the console baud rate; and change the desired baud rate for the console only.

This is the default behavior for ESP-IDF v5.0. You will not have to set it there.

moefear85 commented 2 years ago

@dobairoland

If CONFIG_ESP_CONSOLE_UART_BAUDRATE has to be set anyways for any application, no matter what, then where is this setting in menuconfig? I can't find it anywhere. Moreover, I tried changing its value to 921600 directly in the sdkconfig file... But something, I don't know if it is the IDE or idf.py, is automatically changing it back to 115200 every time I flash. So how do I get the chip's default uart tx speed to bet set to 921600?

dobairoland commented 2 years ago

First, you have to set custom UART. Then it will appear. If you don't enable it then custom baud-rate is hidden in the menu (if you set it manually then it will ignore it).

moefear85 commented 2 years ago

@dobairoland

I tried that... that only affects CONFIG_ESPTOOLPY_MONITOR_BAUD. It doesn't change CONFIG_ESP_CONSOLE_UART_BAUDRATE. What I need is a way to persistently change CONFIG_ESP_CONSOLE_UART_BAUDRATE. What exactly is changing it back to 115200 on every flash?

dobairoland commented 2 years ago
CONFIG_ESP_CONSOLE_UART_CUSTOM=y
CONFIG_ESP_CONSOLE_UART_BAUDRATE=921600
dobairoland commented 2 years ago

What exactly is changing it back to 115200 on every flash?

... is what I mentioned earlier. If you don't set custom UART then reconfiguration will ignore the baud-rate change.

moefear85 commented 2 years ago

@dobairoland that gives an error. the build system doesn't accept when I define it manually. it just overwrites both lines

moefear85 commented 2 years ago

there must be some other option that has to be set first to allow CONFIG_ESP_CONSOLE_UART_CUSTOM to be set to "y".

moefear85 commented 2 years ago

I have no idea what changed... but all of a sudden it is working, but it automatically overwrote my sdkconfig file to this:

CONFIG_ESP_CONSOLE_UART_CUSTOM=y

CONFIG_ESP_CONSOLE_NONE is not set

CONFIG_ESP_CONSOLE_UART=y CONFIG_ESP_CONSOLE_MULTIPLE_UART=y CONFIG_ESP_CONSOLE_UART_CUSTOM_NUM_0=y

CONFIG_ESP_CONSOLE_UART_CUSTOM_NUM_1 is not set

CONFIG_ESP_CONSOLE_UART_NUM=0 CONFIG_ESP_CONSOLE_UART_TX_GPIO=43 CONFIG_ESP_CONSOLE_UART_RX_GPIO=44 CONFIG_ESP_CONSOLE_UART_BAUDRATE=921600

moefear85 commented 2 years ago

@dobairoland can you please tell me the exact path from the top of menuconfig do I have to navigate to reach the option that allows me to set this from menuconfig? because doing so directly in the sdkconfig file.... just to have it throw errors in the menuconfig window, then overwrite stuff, then allow it strangely to work, is ofcourse not a systematic solution.

dobairoland commented 2 years ago

"Component config" -> "ESP system settings" -> "Channel for console output (Default: UART0)"

moefear85 commented 2 years ago

oooooh ok... I found it...

For anyone wondering... Under ESP System Settings... .where it says "Channel for console output"... you have to change this from "Default Uart0" to "custom UART"... only then do submenu options appear that let you keep or change the uart number, its pins, and also set its output baudrate.

dobairoland commented 2 years ago

only then do submenu options appear that let you keep or change the uart number, its pins, and also set its output baudrate.

Yes, that is what I was trying to tell you. I'm sorry if it wasn't clear enough.