esp_console_repl.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528
  1. /*
  2. * SPDX-FileCopyrightText: 2016-2021 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #include <stdint.h>
  7. #include <stdio.h>
  8. #include <fcntl.h>
  9. #include <sys/cdefs.h>
  10. #include "sdkconfig.h"
  11. #include "esp_err.h"
  12. #include "esp_log.h"
  13. #include "esp_console.h"
  14. #include "esp_vfs_dev.h"
  15. #include "esp_vfs_cdcacm.h"
  16. #include "esp_vfs_usb_serial_jtag.h"
  17. #include "freertos/FreeRTOS.h"
  18. #include "freertos/task.h"
  19. #include "driver/uart.h"
  20. #include "driver/usb_serial_jtag.h"
  21. #include "linenoise/linenoise.h"
  22. static const char *TAG = "console.repl";
  23. #define CONSOLE_PROMPT_MAX_LEN (32)
  24. #define CONSOLE_PATH_MAX_LEN (ESP_VFS_PATH_MAX)
  25. typedef enum {
  26. CONSOLE_REPL_STATE_DEINIT,
  27. CONSOLE_REPL_STATE_INIT,
  28. CONSOLE_REPL_STATE_START,
  29. } repl_state_t;
  30. typedef struct {
  31. esp_console_repl_t repl_core; // base class
  32. char prompt[CONSOLE_PROMPT_MAX_LEN]; // Prompt to be printed before each line
  33. repl_state_t state;
  34. const char *history_save_path;
  35. TaskHandle_t task_hdl; // REPL task handle
  36. size_t max_cmdline_length; // Maximum length of a command line. If 0, default value will be used.
  37. } esp_console_repl_com_t;
  38. typedef struct {
  39. esp_console_repl_com_t repl_com; // base class
  40. int uart_channel; // uart channel number
  41. } esp_console_repl_universal_t;
  42. static void esp_console_repl_task(void *args);
  43. static esp_err_t esp_console_repl_uart_delete(esp_console_repl_t *repl);
  44. static esp_err_t esp_console_repl_usb_cdc_delete(esp_console_repl_t *repl);
  45. #if CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG
  46. static esp_err_t esp_console_repl_usb_serial_jtag_delete(esp_console_repl_t *repl);
  47. #endif //CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG
  48. static esp_err_t esp_console_common_init(size_t max_cmdline_length, esp_console_repl_com_t *repl_com);
  49. static esp_err_t esp_console_setup_prompt(const char *prompt, esp_console_repl_com_t *repl_com);
  50. static esp_err_t esp_console_setup_history(const char *history_path, uint32_t max_history_len, esp_console_repl_com_t *repl_com);
  51. esp_err_t esp_console_new_repl_usb_cdc(const esp_console_dev_usb_cdc_config_t *dev_config, const esp_console_repl_config_t *repl_config, esp_console_repl_t **ret_repl)
  52. {
  53. esp_err_t ret = ESP_OK;
  54. esp_console_repl_universal_t *cdc_repl = NULL;
  55. if (!repl_config | !dev_config | !ret_repl) {
  56. ret = ESP_ERR_INVALID_ARG;
  57. goto _exit;
  58. }
  59. // allocate memory for console REPL context
  60. cdc_repl = calloc(1, sizeof(esp_console_repl_universal_t));
  61. if (!cdc_repl) {
  62. ret = ESP_ERR_NO_MEM;
  63. goto _exit;
  64. }
  65. /* Minicom, screen, idf_monitor send CR when ENTER key is pressed */
  66. esp_vfs_dev_cdcacm_set_rx_line_endings(ESP_LINE_ENDINGS_CR);
  67. /* Move the caret to the beginning of the next line on '\n' */
  68. esp_vfs_dev_cdcacm_set_tx_line_endings(ESP_LINE_ENDINGS_CRLF);
  69. /* Enable non-blocking mode on stdin and stdout */
  70. fcntl(fileno(stdout), F_SETFL, 0);
  71. fcntl(fileno(stdin), F_SETFL, 0);
  72. // initialize console, common part
  73. ret = esp_console_common_init(repl_config->max_cmdline_length, &cdc_repl->repl_com);
  74. if (ret != ESP_OK) {
  75. goto _exit;
  76. }
  77. // setup history
  78. ret = esp_console_setup_history(repl_config->history_save_path, repl_config->max_history_len, &cdc_repl->repl_com);
  79. if (ret != ESP_OK) {
  80. goto _exit;
  81. }
  82. // setup prompt
  83. esp_console_setup_prompt(repl_config->prompt, &cdc_repl->repl_com);
  84. /* Fill the structure here as it will be used directly by the created task. */
  85. cdc_repl->uart_channel = CONFIG_ESP_CONSOLE_UART_NUM;
  86. cdc_repl->repl_com.state = CONSOLE_REPL_STATE_INIT;
  87. cdc_repl->repl_com.repl_core.del = esp_console_repl_usb_cdc_delete;
  88. /* spawn a single thread to run REPL */
  89. if (xTaskCreate(esp_console_repl_task, "console_repl", repl_config->task_stack_size,
  90. cdc_repl, repl_config->task_priority, &cdc_repl->repl_com.task_hdl) != pdTRUE) {
  91. ret = ESP_FAIL;
  92. goto _exit;
  93. }
  94. *ret_repl = &cdc_repl->repl_com.repl_core;
  95. return ESP_OK;
  96. _exit:
  97. if (cdc_repl) {
  98. esp_console_deinit();
  99. free(cdc_repl);
  100. }
  101. if (ret_repl) {
  102. *ret_repl = NULL;
  103. }
  104. return ret;
  105. }
  106. #if CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG
  107. esp_err_t esp_console_new_repl_usb_serial_jtag(const esp_console_dev_usb_serial_jtag_config_t *dev_config, const esp_console_repl_config_t *repl_config, esp_console_repl_t **ret_repl)
  108. {
  109. esp_console_repl_universal_t *usb_serial_jtag_repl = NULL;
  110. if (!repl_config | !dev_config | !ret_repl) {
  111. return ESP_ERR_INVALID_ARG;
  112. }
  113. esp_err_t ret = ESP_OK;
  114. // allocate memory for console REPL context
  115. usb_serial_jtag_repl = calloc(1, sizeof(esp_console_repl_universal_t));
  116. if (!usb_serial_jtag_repl) {
  117. ret = ESP_ERR_NO_MEM;
  118. goto _exit;
  119. }
  120. /* Disable buffering on stdin */
  121. setvbuf(stdin, NULL, _IONBF, 0);
  122. /* Minicom, screen, idf_monitor send CR when ENTER key is pressed */
  123. esp_vfs_dev_usb_serial_jtag_set_rx_line_endings(ESP_LINE_ENDINGS_CR);
  124. /* Move the caret to the beginning of the next line on '\n' */
  125. esp_vfs_dev_usb_serial_jtag_set_tx_line_endings(ESP_LINE_ENDINGS_CRLF);
  126. /* Enable non-blocking mode on stdin and stdout */
  127. fcntl(fileno(stdout), F_SETFL, 0);
  128. fcntl(fileno(stdin), F_SETFL, 0);
  129. usb_serial_jtag_driver_config_t usb_serial_jtag_config = USB_SERIAL_JTAG_DRIVER_CONFIG_DEFAULT();
  130. /* Install USB-SERIAL-JTAG driver for interrupt-driven reads and writes */
  131. ret = usb_serial_jtag_driver_install(&usb_serial_jtag_config);
  132. if (ret != ESP_OK) {
  133. goto _exit;
  134. }
  135. // initialize console, common part
  136. ret = esp_console_common_init(repl_config->max_cmdline_length, &usb_serial_jtag_repl->repl_com);
  137. if (ret != ESP_OK) {
  138. goto _exit;
  139. }
  140. /* Tell vfs to use usb-serial-jtag driver */
  141. esp_vfs_usb_serial_jtag_use_driver();
  142. // setup history
  143. ret = esp_console_setup_history(repl_config->history_save_path, repl_config->max_history_len, &usb_serial_jtag_repl->repl_com);
  144. if (ret != ESP_OK) {
  145. goto _exit;
  146. }
  147. // setup prompt
  148. esp_console_setup_prompt(repl_config->prompt, &usb_serial_jtag_repl->repl_com);
  149. /* spawn a single thread to run REPL */
  150. if (xTaskCreate(esp_console_repl_task, "console_repl", repl_config->task_stack_size,
  151. &usb_serial_jtag_repl->repl_com, repl_config->task_priority, &usb_serial_jtag_repl->repl_com.task_hdl) != pdTRUE) {
  152. ret = ESP_FAIL;
  153. goto _exit;
  154. }
  155. usb_serial_jtag_repl->uart_channel = CONFIG_ESP_CONSOLE_UART_NUM;
  156. usb_serial_jtag_repl->repl_com.state = CONSOLE_REPL_STATE_INIT;
  157. usb_serial_jtag_repl->repl_com.repl_core.del = esp_console_repl_usb_serial_jtag_delete;
  158. *ret_repl = &usb_serial_jtag_repl->repl_com.repl_core;
  159. return ESP_OK;
  160. _exit:
  161. if (usb_serial_jtag_repl) {
  162. esp_console_deinit();
  163. free(usb_serial_jtag_repl);
  164. }
  165. if (ret_repl) {
  166. *ret_repl = NULL;
  167. }
  168. return ret;
  169. }
  170. #endif // CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG
  171. esp_err_t esp_console_new_repl_uart(const esp_console_dev_uart_config_t *dev_config, const esp_console_repl_config_t *repl_config, esp_console_repl_t **ret_repl)
  172. {
  173. esp_err_t ret = ESP_OK;
  174. esp_console_repl_universal_t *uart_repl = NULL;
  175. if (!repl_config | !dev_config | !ret_repl) {
  176. ret = ESP_ERR_INVALID_ARG;
  177. goto _exit;
  178. }
  179. // allocate memory for console REPL context
  180. uart_repl = calloc(1, sizeof(esp_console_repl_universal_t));
  181. if (!uart_repl) {
  182. ret = ESP_ERR_NO_MEM;
  183. goto _exit;
  184. }
  185. /* Drain stdout before reconfiguring it */
  186. fflush(stdout);
  187. fsync(fileno(stdout));
  188. /* Minicom, screen, idf_monitor send CR when ENTER key is pressed */
  189. esp_vfs_dev_uart_port_set_rx_line_endings(dev_config->channel, ESP_LINE_ENDINGS_CR);
  190. /* Move the caret to the beginning of the next line on '\n' */
  191. esp_vfs_dev_uart_port_set_tx_line_endings(dev_config->channel, ESP_LINE_ENDINGS_CRLF);
  192. /* Configure UART. Note that REF_TICK/XTAL is used so that the baud rate remains
  193. * correct while APB frequency is changing in light sleep mode.
  194. */
  195. const uart_config_t uart_config = {
  196. .baud_rate = dev_config->baud_rate,
  197. .data_bits = UART_DATA_8_BITS,
  198. .parity = UART_PARITY_DISABLE,
  199. .stop_bits = UART_STOP_BITS_1,
  200. #if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32S2
  201. .source_clk = UART_SCLK_REF_TICK,
  202. #else
  203. .source_clk = UART_SCLK_XTAL,
  204. #endif
  205. };
  206. uart_param_config(dev_config->channel, &uart_config);
  207. uart_set_pin(dev_config->channel, dev_config->tx_gpio_num, dev_config->rx_gpio_num, -1, -1);
  208. /* Install UART driver for interrupt-driven reads and writes */
  209. ret = uart_driver_install(dev_config->channel, 256, 0, 0, NULL, 0);
  210. if (ret != ESP_OK) {
  211. goto _exit;
  212. }
  213. /* Tell VFS to use UART driver */
  214. esp_vfs_dev_uart_use_driver(dev_config->channel);
  215. // initialize console, common part
  216. ret = esp_console_common_init(repl_config->max_cmdline_length, &uart_repl->repl_com);
  217. if (ret != ESP_OK) {
  218. goto _exit;
  219. }
  220. // setup history
  221. ret = esp_console_setup_history(repl_config->history_save_path, repl_config->max_history_len, &uart_repl->repl_com);
  222. if (ret != ESP_OK) {
  223. goto _exit;
  224. }
  225. // setup prompt
  226. esp_console_setup_prompt(repl_config->prompt, &uart_repl->repl_com);
  227. /* Fill the structure here as it will be used directly by the created task. */
  228. uart_repl->uart_channel = dev_config->channel;
  229. uart_repl->repl_com.state = CONSOLE_REPL_STATE_INIT;
  230. uart_repl->repl_com.repl_core.del = esp_console_repl_uart_delete;
  231. /* Spawn a single thread to run REPL, we need to pass `uart_repl` to it as
  232. * it also requires the uart channel. */
  233. if (xTaskCreate(esp_console_repl_task, "console_repl", repl_config->task_stack_size,
  234. uart_repl, repl_config->task_priority, &uart_repl->repl_com.task_hdl) != pdTRUE) {
  235. ret = ESP_FAIL;
  236. goto _exit;
  237. }
  238. *ret_repl = &uart_repl->repl_com.repl_core;
  239. return ESP_OK;
  240. _exit:
  241. if (uart_repl) {
  242. esp_console_deinit();
  243. uart_driver_delete(dev_config->channel);
  244. free(uart_repl);
  245. }
  246. if (ret_repl) {
  247. *ret_repl = NULL;
  248. }
  249. return ret;
  250. }
  251. esp_err_t esp_console_start_repl(esp_console_repl_t *repl)
  252. {
  253. esp_err_t ret = ESP_OK;
  254. esp_console_repl_com_t *repl_com = __containerof(repl, esp_console_repl_com_t, repl_core);
  255. // check if already initialized
  256. if (repl_com->state != CONSOLE_REPL_STATE_INIT) {
  257. ret = ESP_ERR_INVALID_STATE;
  258. goto _exit;
  259. }
  260. repl_com->state = CONSOLE_REPL_STATE_START;
  261. xTaskNotifyGive(repl_com->task_hdl);
  262. return ESP_OK;
  263. _exit:
  264. return ret;
  265. }
  266. static esp_err_t esp_console_setup_prompt(const char *prompt, esp_console_repl_com_t *repl_com)
  267. {
  268. /* set command line prompt */
  269. const char *prompt_temp = "esp>";
  270. if (prompt) {
  271. prompt_temp = prompt;
  272. }
  273. snprintf(repl_com->prompt, CONSOLE_PROMPT_MAX_LEN - 1, LOG_COLOR_I "%s " LOG_RESET_COLOR, prompt_temp);
  274. /* Figure out if the terminal supports escape sequences */
  275. int probe_status = linenoiseProbe();
  276. if (probe_status) {
  277. /* zero indicates success */
  278. linenoiseSetDumbMode(1);
  279. #if CONFIG_LOG_COLORS
  280. /* Since the terminal doesn't support escape sequences,
  281. * don't use color codes in the s_prompt.
  282. */
  283. snprintf(repl_com->prompt, CONSOLE_PROMPT_MAX_LEN - 1, "%s ", prompt_temp);
  284. #endif //CONFIG_LOG_COLORS
  285. }
  286. return ESP_OK;
  287. }
  288. static esp_err_t esp_console_setup_history(const char *history_path, uint32_t max_history_len, esp_console_repl_com_t *repl_com)
  289. {
  290. esp_err_t ret = ESP_OK;
  291. repl_com->history_save_path = history_path;
  292. if (history_path) {
  293. /* Load command history from filesystem */
  294. linenoiseHistoryLoad(history_path);
  295. }
  296. /* Set command history size */
  297. if (linenoiseHistorySetMaxLen(max_history_len) != 1) {
  298. ESP_LOGE(TAG, "set max history length to %d failed", max_history_len);
  299. ret = ESP_FAIL;
  300. goto _exit;
  301. }
  302. return ESP_OK;
  303. _exit:
  304. return ret;
  305. }
  306. static esp_err_t esp_console_common_init(size_t max_cmdline_length, esp_console_repl_com_t *repl_com)
  307. {
  308. esp_err_t ret = ESP_OK;
  309. /* Initialize the console */
  310. esp_console_config_t console_config = ESP_CONSOLE_CONFIG_DEFAULT();
  311. repl_com->max_cmdline_length = console_config.max_cmdline_length;
  312. /* Replace the default command line length if passed as a parameter */
  313. if (max_cmdline_length != 0) {
  314. console_config.max_cmdline_length = max_cmdline_length;
  315. repl_com->max_cmdline_length = max_cmdline_length;
  316. }
  317. #if CONFIG_LOG_COLORS
  318. console_config.hint_color = atoi(LOG_COLOR_CYAN);
  319. #endif
  320. ret = esp_console_init(&console_config);
  321. if (ret != ESP_OK) {
  322. goto _exit;
  323. }
  324. ret = esp_console_register_help_command();
  325. if (ret != ESP_OK) {
  326. goto _exit;
  327. }
  328. /* Configure linenoise line completion library */
  329. /* Enable multiline editing. If not set, long commands will scroll within single line */
  330. linenoiseSetMultiLine(1);
  331. /* Tell linenoise where to get command completions and hints */
  332. linenoiseSetCompletionCallback(&esp_console_get_completion);
  333. linenoiseSetHintsCallback((linenoiseHintsCallback *)&esp_console_get_hint);
  334. return ESP_OK;
  335. _exit:
  336. return ret;
  337. }
  338. static esp_err_t esp_console_repl_uart_delete(esp_console_repl_t *repl)
  339. {
  340. esp_err_t ret = ESP_OK;
  341. esp_console_repl_com_t *repl_com = __containerof(repl, esp_console_repl_com_t, repl_core);
  342. esp_console_repl_universal_t *uart_repl = __containerof(repl_com, esp_console_repl_universal_t, repl_com);
  343. // check if already de-initialized
  344. if (repl_com->state == CONSOLE_REPL_STATE_DEINIT) {
  345. ESP_LOGE(TAG, "already de-initialized");
  346. ret = ESP_ERR_INVALID_STATE;
  347. goto _exit;
  348. }
  349. repl_com->state = CONSOLE_REPL_STATE_DEINIT;
  350. esp_console_deinit();
  351. esp_vfs_dev_uart_use_nonblocking(uart_repl->uart_channel);
  352. uart_driver_delete(uart_repl->uart_channel);
  353. free(uart_repl);
  354. _exit:
  355. return ret;
  356. }
  357. static esp_err_t esp_console_repl_usb_cdc_delete(esp_console_repl_t *repl)
  358. {
  359. esp_err_t ret = ESP_OK;
  360. esp_console_repl_com_t *repl_com = __containerof(repl, esp_console_repl_com_t, repl_core);
  361. esp_console_repl_universal_t *cdc_repl = __containerof(repl_com, esp_console_repl_universal_t, repl_com);
  362. // check if already de-initialized
  363. if (repl_com->state == CONSOLE_REPL_STATE_DEINIT) {
  364. ESP_LOGE(TAG, "already de-initialized");
  365. ret = ESP_ERR_INVALID_STATE;
  366. goto _exit;
  367. }
  368. repl_com->state = CONSOLE_REPL_STATE_DEINIT;
  369. esp_console_deinit();
  370. free(cdc_repl);
  371. _exit:
  372. return ret;
  373. }
  374. #if CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG
  375. static esp_err_t esp_console_repl_usb_serial_jtag_delete(esp_console_repl_t *repl)
  376. {
  377. esp_err_t ret = ESP_OK;
  378. esp_console_repl_com_t *repl_com = __containerof(repl, esp_console_repl_com_t, repl_core);
  379. esp_console_repl_universal_t *usb_serial_jtag_repl = __containerof(repl_com, esp_console_repl_universal_t, repl_com);
  380. // check if already de-initialized
  381. if (repl_com->state == CONSOLE_REPL_STATE_DEINIT) {
  382. ESP_LOGE(TAG, "already de-initialized");
  383. ret = ESP_ERR_INVALID_STATE;
  384. goto _exit;
  385. }
  386. repl_com->state = CONSOLE_REPL_STATE_DEINIT;
  387. esp_console_deinit();
  388. esp_vfs_usb_serial_jtag_use_nonblocking();
  389. usb_serial_jtag_driver_uninstall();
  390. free(usb_serial_jtag_repl);
  391. _exit:
  392. return ret;
  393. }
  394. #endif // CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG
  395. static void esp_console_repl_task(void *args)
  396. {
  397. esp_console_repl_universal_t *repl_conf = (esp_console_repl_universal_t *) args;
  398. esp_console_repl_com_t *repl_com = &repl_conf->repl_com;
  399. const int uart_channel = repl_conf->uart_channel;
  400. /* Waiting for task notify. This happens when `esp_console_start_repl()`
  401. * function is called. */
  402. ulTaskNotifyTake(pdTRUE, portMAX_DELAY);
  403. /* Change standard input and output of the task if the requested UART is
  404. * NOT the default one. This block will replace stdin, stdout and stderr.
  405. */
  406. if (uart_channel != CONFIG_ESP_CONSOLE_UART_NUM) {
  407. char path[CONSOLE_PATH_MAX_LEN] = { 0 };
  408. snprintf(path, CONSOLE_PATH_MAX_LEN, "/dev/uart/%d", uart_channel);
  409. stdin = fopen(path, "r");
  410. stdout = fopen(path, "w");
  411. stderr = stdout;
  412. }
  413. /* Disable buffering on stdin of the current task.
  414. * If the console is ran on a different UART than the default one,
  415. * buffering shall only be disabled for the current one. */
  416. setvbuf(stdin, NULL, _IONBF, 0);
  417. /* This message shall be printed here and not earlier as the stdout
  418. * has just been set above. */
  419. printf("\r\n"
  420. "Type 'help' to get the list of commands.\r\n"
  421. "Use UP/DOWN arrows to navigate through command history.\r\n"
  422. "Press TAB when typing command name to auto-complete.\r\n");
  423. if (linenoiseIsDumbMode()) {
  424. printf("\r\n"
  425. "Your terminal application does not support escape sequences.\n\n"
  426. "Line editing and history features are disabled.\n\n"
  427. "On Windows, try using Putty instead.\r\n");
  428. }
  429. linenoiseSetMaxLineLen(repl_com->max_cmdline_length);
  430. while (repl_com->state == CONSOLE_REPL_STATE_START) {
  431. char *line = linenoise(repl_com->prompt);
  432. if (line == NULL) {
  433. ESP_LOGD(TAG, "empty line");
  434. /* Ignore empty lines */
  435. continue;
  436. }
  437. /* Add the command to the history */
  438. linenoiseHistoryAdd(line);
  439. /* Save command history to filesystem */
  440. if (repl_com->history_save_path) {
  441. linenoiseHistorySave(repl_com->history_save_path);
  442. }
  443. /* Try to run the command */
  444. int ret;
  445. esp_err_t err = esp_console_run(line, &ret);
  446. if (err == ESP_ERR_NOT_FOUND) {
  447. printf("Unrecognized command\n");
  448. } else if (err == ESP_ERR_INVALID_ARG) {
  449. // command was empty
  450. } else if (err == ESP_OK && ret != ESP_OK) {
  451. printf("Command returned non-zero error code: 0x%x (%s)\n", ret, esp_err_to_name(ret));
  452. } else if (err != ESP_OK) {
  453. printf("Internal error: %s\n", esp_err_to_name(err));
  454. }
  455. /* linenoise allocates line buffer on the heap, so need to free it */
  456. linenoiseFree(line);
  457. }
  458. ESP_LOGD(TAG, "The End");
  459. vTaskDelete(NULL);
  460. }