Skip to content

shell bypass sample not outputting to serial #97722

@roni1234321

Description

@roni1234321

Describe the bug

when running the shell bypass sample the shell gets stuck and to text is not printed to terminal, and shell is locked.
after short inspection it seems that shell_fprintf() fails to take the internal shell mutex (sh->ctx->lock_sem) and printing is dropped.

possible fix is to unlock shell before and re-lock after calling bypass cb. snippet from shell.c:

		if (bypass) {
#if defined(CONFIG_SHELL_BACKEND_RTT) && defined(CONFIG_SEGGER_RTT_BUFFER_SIZE_DOWN)
			uint8_t buf[CONFIG_SEGGER_RTT_BUFFER_SIZE_DOWN];
#else
			uint8_t buf[16];
#endif

			(void)sh->iface->api->read(sh->iface, buf,
							sizeof(buf), &count);
			if (count) {
				z_flag_cmd_ctx_set(sh, true);
				z_shell_unlock(sh); // add this 
				bypass(sh, buf, count);
				z_shell_lock(sh); //and this
				z_flag_cmd_ctx_set(sh, false);
				/* Check if bypass mode ended. */
				if (!(volatile shell_bypass_cb_t *)sh->ctx->bypass) {
					state_set(sh, SHELL_STATE_ACTIVE);
				} else {
					continue;
				}
			}

			return;
		}

this fix was tested and seems to fix the issue.

Regression

  • This is a regression.

Steps to reproduce

  1. build shell_module sample
  2. flash and run on nucleo_l476rg
  3. type 'bypass' cmd in shell.
  4. shell will freeze

Relevant log output

uart:~$ bypass
Bypass started, press ctrl-x ctrl-q to escape
0a |

at this point shell freezes

Impact

Showstopper – Prevents release or major functionality; system unusable.

Environment

Windows 11
zephyr 4.2.0

Additional Context

this regression started after updating zephyr from v4.0.0 to 4.2.0

Metadata

Metadata

Assignees

Labels

area: ShellShell subsystembugThe issue is a bug, or the PR is fixing a bugpriority: lowLow impact/importance bug

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions