How can I change the stdout baud rate in ESP-IDF?
Asked Answered
S

4

5

I wrote a small program on PlatformIO for an ESP32 with ESP-IDF framework.

Currently this is connected to my PC with USB cable. I receive lots of data from a CAN-BUS and I print this data with printf()

It seems the output with the standard baud rate 115200 is too slow. This is why I want to set this to a higher value.

I changed this in the platformio.ini without success.

monitor_speed = 115200

I searched and did not find where I can change this baud rate.

If possible my idea is to add some code, maybe just a line or two, to set the value i.e. to 230400

I mention the ESP32, PlatformIO and ESP-IDF because I am not sure where this setting is supposed to be.

Seraph answered 21/9, 2019 at 6:32 Comment(0)
I
5

It is a setting of esp-idf framework. You can set the console baud rate in sdkconfig.defaults (at project root directory):

CONFIG_CONSOLE_UART_BAUDRATE=230400

You can also configure it via menuconfig (idf.py menuconfig or pio run -t menuconfig):

  • Component config
    • Common ESP-related
      • UART console baud rate
Idioglossia answered 6/4, 2020 at 17:45 Comment(3)
On ESP32 S3 there is no such option, and if I change sdkconfig manually, it restored to 115200 after build.Harald
This setting was renamed to ESP_CONSOLE_UART_BAUDRATE in new versions of esp-idf framework.Idioglossia
I've succeeded to open baud rate option by selecting "Custom" / UART0Harald
L
4

If you are using VSC and ESP-IDF extension, go to settings (default CTRL+,) -> Extensions -> ESP-IDF -> Flash Baud Rate enter image description here

Laquanda answered 10/5, 2023 at 3:18 Comment(0)
C
0

On VSCode: Open Settings and search vor "baud". Don' t change "Flash Baud Rate", it is "Monitor Baud Rate" you want to adjust! Screenshot

Chromogen answered 15/5, 2023 at 11:49 Comment(0)
S
0

Here is how you can do this with ESP-IDF directly (VSCode ESP-IDF extension) or PlatformIO.

I tested it on a ESP32-S3.

There are two thing you want to change:

  • IDE serial monitor baudrate - the baudrate the IDE monitor is expecting.
  • ESP32 console output baudrate - the baudrate of the ESP32 device for the UART used for console output.

Setting the IDE Serial Monitor Baudrate

For ESP-IDF extension, go to the settings, type esp-ifd baud rate in the search box, you will get two results: "ESP-IDF Flash Baud rate" and "ESP-IDF Monitor Baud rate". The monitor is the one you are looking for. Set it the value you want e.g. 230400.

For PlatformIO extension, you can set the monitor speed by adding/changing the monitor_speed option in platformio.ini, e.g. monitor_speed = 230400.

Setting the ESP32 Console Output Baudrate

There are two ways I found.

1. Configure ESP-IDF sdkconfig File

To open a configuration editor, for ESP-IDF you can use the command ESP-IDF: SDK Configuration editor (or the corresponding icon) or type idf.py menuconfig (for PlatformIO pio run -t menuconfig) in the terminal.

The configurations you want to change are:

  1. Component config -> ESP System Settings -> Channel for console output:
    Set it to Custom UART.
  2. Component config -> ESP System Settings -> UART peripheral to use for console output (0-1):
    Set it to UART0.
  3. Component config -> ESP System Settings -> UART console baud rate:
    Set it to the value you want e.g. 230400.

P.S. The CONFIG_CONSOLE_UART_BAUDRATE option of the sdkconfig is no longer supported, see ESP-IDF Monitor.

2. Hard code the baudrate

The default console output is UART0, so right at the beginning of the program add: uart_set_baudrate(UART_NUM_0, 230400):

#include "driver/uart.h"

void app_main() 
{
    uart_set_baudrate(UART_NUM_0, 230400);
    
    // ...
}

When using this option, the serial monitor may output some garbage before the code reaches this line do to some init code logs that are sent before changing the baudrate to what the monitor is expecting.

Southey answered 31/3 at 11:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.