From 580211c97c026a2aa422a2a8aa46aed94093ddbb Mon Sep 17 00:00:00 2001 From: WillyJL Date: Tue, 22 Jul 2025 17:10:41 +0200 Subject: [PATCH] CLI: Fix long delay with quick connect/disconnect noticeable with qflipper, for some reason it sets DTR on/off/on again so flipper starts CLI, stops it, then starts again but cli shell is trying to print motd, and pipe is already broken so each character of motd times out for 100ms changing pipe timeout to 10ms works too, but is just a workaround it didnt always happen, i think that variable time of loading ext cmds made it so on ofw it usually manages to print motd before pipe is broken on cfw with more ext commands it always hung, on ofw only sometimes important part is bailing early in cli shell in cli vcp i made it cleanup cli shell on disconnect so it doesnt stay around after disconnecting usb, might free a little ram maybe --- CHANGELOG.md | 1 + applications/services/cli/cli_vcp.c | 14 +++++--------- lib/toolbox/cli/shell/cli_shell.c | 5 +++++ 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 22438f80e..f9bf5f5ed 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,6 +30,7 @@ - UL: Docs: Update Sub-GHz DoorHan programming instructions (by @li0ard) ### Fixed: +- CLI: Fix long delay with quick connect/disconnect, qFlipper should connect faster as expected again (by @WillyJL) - Bad KB: Fix modifier keys with HOLD/RELEASE commands (by @WillyJL) - Desktop: Fix lock screen hang (#438 by @aaronjamt) - NFC: Fix incorrect Saflok year formula (#433 by @Eltrick) diff --git a/applications/services/cli/cli_vcp.c b/applications/services/cli/cli_vcp.c index f65722241..6a8afe184 100644 --- a/applications/services/cli/cli_vcp.c +++ b/applications/services/cli/cli_vcp.c @@ -217,7 +217,11 @@ static void cli_vcp_internal_event_happened(FuriEventLoopObject* object, void* c // disconnect our side of the pipe pipe_detach_from_event_loop(cli_vcp->own_pipe); pipe_free(cli_vcp->own_pipe); - cli_vcp->own_pipe = NULL; + + // wait for shell to stop + cli_shell_join(cli_vcp->shell); + cli_shell_free(cli_vcp->shell); + pipe_free(cli_vcp->shell_pipe); break; } @@ -226,14 +230,6 @@ static void cli_vcp_internal_event_happened(FuriEventLoopObject* object, void* c FURI_LOG_D(TAG, "Connected"); cli_vcp->is_connected = true; - // wait for previous shell to stop - furi_check(!cli_vcp->own_pipe); - if(cli_vcp->shell) { - cli_shell_join(cli_vcp->shell); - cli_shell_free(cli_vcp->shell); - pipe_free(cli_vcp->shell_pipe); - } - // start shell thread PipeSideBundle bundle = pipe_alloc(VCP_BUF_SIZE, 1); cli_vcp->own_pipe = bundle.alices_side; diff --git a/lib/toolbox/cli/shell/cli_shell.c b/lib/toolbox/cli/shell/cli_shell.c index 8663577e3..05aecc444 100644 --- a/lib/toolbox/cli/shell/cli_shell.c +++ b/lib/toolbox/cli/shell/cli_shell.c @@ -469,11 +469,16 @@ static int32_t cli_shell_thread(void* context) { cli_shell_init(shell); FURI_LOG_D(TAG, "Started"); + if(pipe_state(shell->pipe) == PipeStateBroken) goto bail; + shell->motd(shell->callback_context); cli_shell_line_prompt(shell->components[CliShellComponentLine]); + if(pipe_state(shell->pipe) == PipeStateBroken) goto bail; + furi_event_loop_run(shell->event_loop); +bail: FURI_LOG_D(TAG, "Stopped"); cli_shell_deinit(shell); return 0;