Skip to content

Commit

Permalink
Use physical port if present on WSL2, otherwise via powershell
Browse files Browse the repository at this point in the history
  • Loading branch information
mikee47 committed Jun 5, 2024
1 parent 90511f1 commit d4c0231
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 8 deletions.
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

0 comments on commit d4c0231

Please sign in to comment.