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

Conversation

mikee47
Copy link
Contributor

@mikee47 mikee47 commented Jun 5, 2024

WSL2 doesn't natively support USB devices such as serial ports, so Sming uses runs the python terminal application inside Windows natively using powershell.

However, as discussed in #2789 this prevents software such as usbipd from working.

This PR adds an additional check when running inside WSL2 to see if the nominated port, via COM_PORT, is actually present. If so, then it runs the python terminal application normally. If the path isn't present then it is assumed to be a Windows port and powershell is invoked as usual.

Because the TERMINAL environment variable is cached by Sming this can cause issues. To maintain existing behaviour this variable is still cached but left empty to indicate default behaviour. If TERMINAL has been redefined then that will be run instead. This will require make config-clean to clear the existing cached value.

Copy link

what-the-diff bot commented Jun 5, 2024

PR Summary

  • Update Terminal Configuration in Smimg/Components
    The update in the system involves changing the designated Terminal from default Python setup to powershell.exe but only if the Windows Subsystem for Linux (WSL_ROOT) is activated. If not, the system continues to use Python.

  • Add Variable for Serial Device Availability Check
    A new variable named WSL_COMPORT_POWERSHELL was introduced in the build file. This is specifically designed to check if a serial device is connected or not. If no device is detected, this variable switches to 1 to signify the absence.

  • Modification of Flash Target in System Components
    The process of flashing targets has been revised. Instead of using the former configurations - $(GDB_CMDLINE) and $(TERMINAL), the system now utilizes $(MAKE) gdb and $(MAKE) terminal. These changes have been implemented to allow for conditional execution of these operations.

  • Adaptation of TCP-Serial-Redirect for Windows Subsystem for Linux
    The system has been adjusted to use Microsoft's Command Prompt (cmd.exe) and Python 3 when WSL_COMPORT_POWERSHELL is activated (i.e., stands at value 1). This enhances compatibility with the Windows Subsystem for Linux when redirecting TCP-serial connections.

@mikee47 mikee47 changed the title Use physical port if present on WSL2, otherwise via powershell Use physical serial port if present on WSL2 Jun 6, 2024
@slaff slaff added this to the 5.2.0 milestone Jun 6, 2024
@slaff
Copy link
Contributor

slaff commented Jun 6, 2024

@mikee47 This PR is approved. Waiting for @callimero to confirm that this fix works also for him.

@slaff slaff self-requested a review June 6, 2024 07:55
@callimero
Copy link

callimero commented Jun 6, 2024

Still...

@mikee47 This PR is approved. Waiting for @callimero to confirm that this fix works also for him.

I could not make it work. Maybe I did something wrong or just don't understand enough. What I did:

checked out the PR branch
used installer.sh and export.sh
enter a sample
make (works)
make flash

`
cw@DESKTOP-PCKKJN6:~/smingwslser/Sming/samples/Basic_Blink$ make flash
ifwildcard: ''
WSL_COMPORT_POWERSHELL: ''
COM_PORT : '/dev/ttyUSB0'

Basic_Blink: Invoking 'flash' for Esp8266 (debug) architecture
make components application

. . .

powershell.exe -Command "/usr/bin/python3 /home/cw/smingwslser/Sming/Sming/Components/esptool/esptool/esptool.py -p /dev/ttyUSB0 -b 115200 --chip esp8266 --before default_reset --after hard_reset write_flash -z -fs 1MB -ff 40m -fm dio 0x00000 out/Esp8266/debug/firmware/rboot.bin 0x000fa000 out/Esp8266/debug/firmware/partitions.bin 0x00002000 out/Esp8266/debug/firmware/rom0.bin 0x000fc000 /home/cw/smingwslser/Sming/Sming/Arch/Esp8266/Components/esp8266/sdk/bin/esp_init_data_default.bin "
`

I put some debug output in, WSL_COMPORT_POWERSHELL is not 1

still powershell.exe is used.

Where should I look/what todo, to provide you with the information you need?

Cheers,
Carsten

@callimero
Copy link

@mikee47 This PR is approved. Waiting for @callimero to confirm that this fix works also for him.

I tried hard this morning. Sorry. Could not get it to work. (see edited answer).

Carsten

@callimero
Copy link

callimero commented Jun 6, 2024

@mikee47 This PR is approved. Waiting for @callimero to confirm that this fix works also for him.

Heads up!

make terminal works

So I changed (just poking around here...) Components/esptool/component.mk

`
. . .

ifdef TERMINAL
$(TERMINAL)
else ifeq ($(WSL_COMPORT_POWERSHELL),1)
ESPTOOL_EXECUTE = powershell.exe -Command "$(ESPTOOL_CMDLINE) $1"
else
ESPTOOL_EXECUTE = $(ESPTOOL_CMDLINE) $1
endif

. . .
`

Works like a charm so far.

All the best,
Carsten

@slaff slaff merged commit 307d6db into SmingHub:develop Jun 6, 2024
38 checks passed
@mikee47
Copy link
Contributor Author

mikee47 commented Jun 6, 2024

@mikee47 mikee47 deleted the feature/wsl-serial branch June 6, 2024 11:45
@callimero
Copy link

NB. Note triple backtick for block code quotes!

Ahhhh! Why is the menu called "code" if it still formats as md...

Cheers,
Carsten

@mikee47
Copy link
Contributor Author

mikee47 commented Jun 6, 2024

Single backticks are for inline quoted code

slaff pushed a commit that referenced this pull request Jun 7, 2024
Further to #2790 esptool of course uses COM ports and same issue applies when physical ports available in WSL2.
@slaff slaff mentioned this pull request Jul 4, 2024
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants