Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use physical serial port if present on WSL2 #2790

Merged
merged 2 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Sming/Arch/Rp2040/Components/uf2/component.mk
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ DEBUG_VARS += UF2CONV_PY
UF2CONV_PY := $(COMPONENT_PATH)/uf2conv.py


# Invoke uf2conf utility
# Invoke uf2conv utility
# $1 -> Parameters
ifdef WSL_ROOT
Uf2Conv = powershell.exe -Command "$(PYTHON) $(UF2CONV_PY) $(if $V,--verbose) $1"
Expand Down
1 change: 1 addition & 0 deletions Sming/Components/terminal/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Options
.. envvar:: TERMINAL

Command line to use when running ``make terminal``.
This is normally empty (undefined) which causes the default python terminal application to run.
Redefine if you want to use a different terminal application.

.. envvar:: KILL_TERM
Expand Down
11 changes: 6 additions & 5 deletions Sming/Components/terminal/component.mk
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@ endif
CACHE_VARS += COM_OPTS KILL_TERM TERMINAL
COM_OPTS ?= --raw --encoding ascii --rts 0 --dtr 0
KILL_TERM ?= pkill -9 -f "$(COM_PORT) $(COM_SPEED_SERIAL)" || exit 0
ifdef WSL_ROOT
TERMINAL ?= powershell.exe -Command "python -m serial.tools.miniterm $(COM_OPTS) $(COM_PORT) $(COM_SPEED_SERIAL)"
else
TERMINAL ?= $(PYTHON) -m serial.tools.miniterm $(COM_OPTS) $(COM_PORT) $(COM_SPEED_SERIAL)
endif


##@Tools
Expand All @@ -33,4 +28,10 @@ kill_term:

.PHONY: terminal
terminal: kill_term ##Open the serial terminal
ifdef TERMINAL
$(TERMINAL)
else ifeq ($(WSL_COMPORT_POWERSHELL),1)
powershell.exe -Command "python -m serial.tools.miniterm $(COM_OPTS) $(COM_PORT) $(COM_SPEED_SERIAL)"
else
$(PYTHON) -m serial.tools.miniterm $(COM_OPTS) $(COM_PORT) $(COM_SPEED_SERIAL)
endif
2 changes: 2 additions & 0 deletions Sming/build.mk
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ else ifeq ($(UNAME), Linux)
ifdef WSL_DISTRO_NAME
DEBUG_VARS += WSL_ROOT
WSL_ROOT := //wsl$$/$(WSL_DISTRO_NAME)
# If serial device is available, use it directly, otherwise via powershell
WSL_COMPORT_POWERSHELL = $(if $(wildcard $(COM_PORT)),,1)
endif
else ifeq ($(UNAME), Darwin)
#OS X
Expand Down
4 changes: 2 additions & 2 deletions Sming/component.mk
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,9 @@ flash: all kill_term ##Write the boot loader and all defined partition images
$(Q) $(call CheckPartitionChunks,$(FLASH_PARTITION_CHUNKS))
$(call WriteFlash,$(FLASH_BOOT_CHUNKS) $(FLASH_MAP_CHUNK) $(FLASH_PARTITION_CHUNKS))
ifeq ($(ENABLE_GDB), 1)
$(GDB_CMDLINE)
$(MAKE) gdb
else ifneq ($(SMING_ARCH),Host)
$(TERMINAL)
$(MAKE) terminal
endif

.PHONY: mergeflash
Expand Down
2 changes: 1 addition & 1 deletion Sming/project.mk
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ TCP_SERIAL_REDIRECT = $(SMING_HOME)/../Tools/tcp_serial_redirect.py $(COM_PORT)
.PHONY: tcp-serial-redirect
tcp-serial-redirect: ##Redirect COM port to TCP port
$(info Starting serial redirector)
ifdef WSL_ROOT
ifeq ($(WSL_COMPORT_POWERSHELL),1)
$(Q) cmd.exe /c start /MIN python3 $(WSL_ROOT)/$(TCP_SERIAL_REDIRECT)
else
$(Q) $(call DetachCommand,$(PYTHON) $(TCP_SERIAL_REDIRECT))
Expand Down
13 changes: 12 additions & 1 deletion docs/source/getting-started/windows/wsl.rst
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,25 @@ This will ensure that the build system can run python scripts either in WSL2 or
Flashing devices
----------------

WSL2 does not currently support access to USB serial devices, so the Sming build system runs
WSL2 does not natively support access to USB serial devices, so the Sming build system runs
the appropriate application directly under Windows using ``powershell.exe``.

Therefore, use the normal Windows COM port name rather than the linux ones (such as /dev/ttyUSB0)::

make flash COM_PORT=COM4


Some USB serial adapters are supported by the `usbipd <https://github.com/dorssel/usbipd-win>`__ project.
If so, then devices such as ``/dev/ttyUSB0``, etc. will be present as usual.
If Sming sees that ``COM_PORT`` actually exists when running in WSL2 then the above powershell workaround
will not be used.

.. note::

The :envvar:`TERMINAL` environment variable is cached by Sming so if the terminal isn't running as expected
try ``make config-clean`` to clear the cached value.


Serial debugging
----------------

Expand Down
Loading