Using the Console in VSCode

MichaelS
Posts: 18
Joined: Mon Jul 08, 2024 12:08 am

Using the Console in VSCode

Postby MichaelS » Mon Jul 15, 2024 4:48 am

Hi
I am very new to Espressif ESP32 dev.
I have a simple test application which outputs diagnostics using ESP_LOGI which I can see in the monitor in the IDE.
I now want to expand on this to develop a simple command line interface where I can end command in the terminal and receive them on my ESP32 and execute them for additional testing.
I found the "Console" in the system API page but am struggling at the first steps.
The doc states:
To declare that your component depends on console, add the following to your CMakeLists.txt:
REQUIRES console
or
PRIV_REQUIRES console
I never know which CMakesLists.txt file to add things into but have tried both unsuccessfully. If some could explain their use.

Using REQUIRES console I get Parse error. Expected "(", got identifier with text "console" on build
Using REQUIRES (console) I get Unknown CMake command "REQUIRES" on build
Using PRIV_REQUIRES I get Unknown CMake command "PRIV_REQUIRES".

So ignoring this I tried calling esp_console_init as follows:
/* Initialize the console */
esp_console_config_t console_config;
console_config.max_cmdline_args = 8;
console_config.max_cmdline_length = 256;
console_config.hint_color = atoi(LOG_COLOR_CYAN);
ESP_ERROR_CHECK( esp_console_init(&console_config) );

When I build and run it, in the monitor I get:
ESP_ERROR_CHECK failed: esp_err_t 0x101 (ESP_ERR_NO_MEM) at 0x400d58de
0x400d58de: app_main at C:/Users/micha/Documents/Cybertek/Software/blink/main/blink_example_main.cpp:127 (discriminator 2)

file: "./main/blink_example_main.cpp" line 127
func: void app_main()
expression: esp_console_init(&console_config)

Line 127 has: ESP_ERROR_CHECK( esp_console_init(&console_config) );

So I tried adding 10000 to the heap_alloc_caps as follows:

/* Initialize the console */
esp_console_config_t console_config;
console_config.max_cmdline_args = 8;
console_config.max_cmdline_length = 256;
console_config.hint_color = atoi(LOG_COLOR_CYAN);
console_config.heap_alloc_caps = 10000;
ESP_ERROR_CHECK( esp_console_init(&console_config) );

but no difference.

I have looked at the example https://github.com/espressif/esp-idf/bl ... ple_main.c but this doesn't do anything different to me at this first esp_console_init() stage.

MichaelS
Posts: 18
Joined: Mon Jul 08, 2024 12:08 am

Re: Using the Console in VSCode

Postby MichaelS » Wed Jul 17, 2024 7:52 am

I got this sorted. Wrong syntax in CMakeLists.txt This is new to me and not well documented

For anyone else who has the problem, the correct syntax is REQUIRES should be inside the idf_component_register section eg

idf_component_register(
SRCS "main.c"
INCLUDE_DIRS "."
REQUIRES console
)

Who is online

Users browsing this forum: No registered users and 7 guests