1 /* Console example — various system commands
3 This example code is in the Public Domain (or CC0 licensed, at your option).
5 Unless required by applicable law or agreed to in writing, this
6 software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
7 CONDITIONS OF ANY KIND, either express or implied.
15 #include "esp_console.h"
16 #include "esp_system.h"
17 #include "esp_sleep.h"
18 #include "driver/rtc_io.h"
19 #include "argtable3/argtable3.h"
21 #include "ble_mesh_console_decl.h"
24 #define CONFIG_ESPTOOLPY_PORT "Which is choosen by Users for CMake"
27 static void register_free();
28 static void register_restart();
29 static void register_make();
31 void register_system()
38 /** 'restart' command restarts the program */
40 static int restart(int argc, char **argv)
42 printf("%s, %s", __func__, "Restarting");
46 static void register_restart()
48 const esp_console_cmd_t cmd = {
50 .help = "Restart the program",
54 ESP_ERROR_CHECK( esp_console_cmd_register(&cmd) );
57 /** 'free' command prints available heap memory */
59 static int free_mem(int argc, char **argv)
61 printf("%d\n", esp_get_free_heap_size());
65 static void register_free()
67 const esp_console_cmd_t cmd = {
69 .help = "Get the total size of heap memory available",
73 ESP_ERROR_CHECK( esp_console_cmd_register(&cmd) );
76 static int make(int argc, char **argv)
78 int count = REG_READ(RTC_CNTL_STORE0_REG);
80 printf("This is not the console you are looking for.\n");
83 REG_WRITE(RTC_CNTL_STORE0_REG, count);
85 const char *make_output =
86 R"(LD build/console.elf
90 const char* flash_output[] = {
91 R"(Flashing binaries to serial port )" CONFIG_ESPTOOLPY_PORT R"( (app at offset 0x10000)...
95 R"(Chip is ESP32D0WDQ6 (revision 0)
99 Changing baud rate to 921600
101 Configuring flash size...
102 Auto-detected Flash size: 4MB
103 Flash params set to 0x0220
104 Compressed 15712 bytes to 9345...
106 R"(Wrote 15712 bytes (9345 compressed) at 0x00001000 in 0.1 seconds (effective 1126.9 kbit/s)...
107 Hash of data verified.
108 Compressed 333776 bytes to 197830...
110 R"(Wrote 333776 bytes (197830 compressed) at 0x00010000 in 3.3 seconds (effective 810.3 kbit/s)...
111 Hash of data verified.
112 Compressed 3072 bytes to 82...
114 R"(Wrote 3072 bytes (82 compressed) at 0x00008000 in 0.0 seconds (effective 1588.4 kbit/s)...
115 Hash of data verified.
121 const char* monitor_output =
123 )" LOG_COLOR_W R"(--- idf_monitor on )" CONFIG_ESPTOOLPY_PORT R"( 115200 ---
124 --- Quit: Ctrl+] | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H --
127 bool need_make = false;
128 bool need_flash = false;
129 bool need_monitor = false;
130 for (int i = 1; i < argc; ++i) {
131 if (strcmp(argv[i], "all") == 0) {
133 } else if (strcmp(argv[i], "flash") == 0) {
136 } else if (strcmp(argv[i], "monitor") == 0) {
138 } else if (argv[i][0] == '-') {
139 /* probably -j option */
140 } else if (isdigit((int) argv[i][0])) {
141 /* might be an argument to -j */
143 printf("make: *** No rule to make target `%s'. Stop.\n", argv[i]);
144 /* Technically this is an error, but let's not spoil the output */
152 printf("%s", make_output);
155 size_t n_items = sizeof(flash_output) / sizeof(flash_output[0]);
156 for (int i = 0; i < n_items; ++i) {
157 printf("%s", flash_output[i]);
158 vTaskDelay(200/portTICK_PERIOD_MS);
162 printf("%s", monitor_output);
168 static void register_make()
170 const esp_console_cmd_t cmd = {
172 .help = NULL, /* Do not include in 'help' output */
173 .hint = "all | flash | monitor",
176 ESP_ERROR_CHECK( esp_console_cmd_register(&cmd) );