mirror of
https://github.com/espressif/esp-protocols.git
synced 2025-07-29 18:27:31 +02:00
feat(console): Added runtime component registration support in console_simple_init
This commit is contained in:
@ -32,6 +32,28 @@ It also provides an api to register an user provided command.
|
||||
// This allows you to execute the do_user_cmd function when the "user" command is invoked
|
||||
ESP_ERROR_CHECK(console_cmd_user_register("user", do_user_cmd));
|
||||
|
||||
// Register any other plugin command added to your project
|
||||
ESP_ERROR_CHECK(console_cmd_all_register());
|
||||
|
||||
ESP_ERROR_CHECK(console_cmd_start()); // Start console
|
||||
```
|
||||
|
||||
### Automatic registration of console commands
|
||||
The `console_simple_init` component includes a utility function named `console_cmd_all_register()`. This function automates the registration of all commands that are linked into the application. To use this functionality, the application can call `console_cmd_all_register()` as demonstrated above.
|
||||
|
||||
When creating a new component, you can ensure that its commands are registered automatically by placing the registration function into the `.console_cmd_desc` section within the output binary.
|
||||
|
||||
To achieve this, follow these steps:
|
||||
1. Add the following lines to the main file of the component
|
||||
```
|
||||
static const console_cmd_plugin_desc_t __attribute__((section(".console_cmd_desc"), used)) PLUGIN = {
|
||||
.name = "cmd_name_string",
|
||||
.plugin_regd_fn = &cmd_registration_function
|
||||
};̌
|
||||
```
|
||||
2. Add the `WHOLE_ARCHIVE` flag to CMakeLists.txt of the component.
|
||||
|
||||
|
||||
For more details refer:
|
||||
* [IDF Component Manager](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/tools/idf-component-manager.html)
|
||||
* [Linker Script Generation](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/linker-script-generation.html)
|
||||
|
Reference in New Issue
Block a user