meshtastic / firmware

Meshtastic device firmware
https://meshtastic.org
GNU General Public License v3.0
3.62k stars 904 forks source link

Windows Support - Trunk and Platformio #5397

Open ThatKalle opened 2 days ago

ThatKalle commented 2 days ago

Ths PR aims to extend the support for Windows users by leveraging the devcontainer feature.

It's targeted towards the tft-gui-work branch as I've used a T-Deck Plus to test and validate, that said, the changes are not really tft-gui specific persay, so maybe it would be better suited somewhere else.

The two issues with developing using Windows is that Trunk.io and Platformio is not fully supported.

Trunk.io

Trunk.io works nicely within the devcontainer simply by installing the vscode extension during build.

  "customizations": {
    "vscode": {
      "extensions": [
        "Trunk.io"
      ]
    }
  },

It finds and uses the configuration within /.trunk/.

Installing the same extension on Windows natively results in all kinds of errors.

PlatformIO

PlatformIO does have very much the same sort of issue as Trunk.io, it does not play nicely on Windows native, but does work from within the devcontainer.

  "customizations": {
    "vscode": {
      "extensions": [
        "platformio.platformio-ide"
      ]
    }
  },

A feature that needs a bit of a helping hand however is the ability to Upload the built firmware to the device using the serial connection (in the case of T-Deck Plus).

Due to how the forwarding of devices work from Windows to WSL2 to Devcontainer not only do we need to make some changes to the container itself, but also to Windows and WSL.

Windows

Using usbipd-win we're able to send a connected device down WSL2.

> usbipd list
Connected:
BUSID  VID:PID    DEVICE
4-7    303a:1001  USB Serial Device (COM18), USB JTAG/serial debug unit
> usbipd bind --busid=4-7
> usbipd attach --wsl --busid=4-7 --auto-attach

WSL2

Within WSL2 we'll see the device

$ lsusb
Bus 001 Device 005: ID 303a:1001 Espressif USB JTAG/serial debug unit
$ sudo dmesg | grep tty
[ 2944.930440] cdc_acm 1-1:1.0: ttyACM0: USB ACM device

But, we also need to setup udev rules for PlatformIO supported boards/devices. ref

$ sudo apt-get install udev -y
$ curl -fsSL https://raw.githubusercontent.com/platformio/platformio-core/develop/platformio/assets/system/99-platformio-udev.rules | sudo tee /etc/udev/rules.d/99-platformio-udev.rules
$ sudo service udev restart

The ttyACM0 device should now be ready to be sent over to the devcontainer to be used by Platformio from within VSCode.

devcontainer

The "runArgs": ["--device=/dev/ttyACM0"], needs to be adjusted to match your system. On my machine it ended up being /dev/ttyACM0, It's probably not the case for every system, hence commented out.

The same udev rules for PlatformIO is also added to the devcontainer via Dockerfile.

GPG

The devcontainer needs the gpg and gnupg2 packages to allow for GPG signed commits to be created.

CLAassistant commented 2 days ago

CLA assistant check
All committers have signed the CLA.

CLAassistant commented 2 days ago

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

koga73 commented 2 days ago

Related to Windows support, I built the tft-gui-work branch on Windows with PlatformIO but was getting this error:

lto-wrapper.exe: fatal error: CreateProcess: No such file or directory

As a workaround I removed the -flto compile flag from my local and this resolved the problem. Will this PR address lto-wrapper.exe missing?

ThatKalle commented 2 days ago

Related to Windows support, I built the tft-gui-work branch on Windows with PlatformIO but was getting this error:

lto-wrapper.exe: fatal error: CreateProcess: No such file or directory

As a workaround I removed the -flto compile flag from my local and this resolved the problem. Will this PR address lto-wrapper.exe missing?

The error message looks very familiar.

This PR will not resolve the fact that lto-wrapper.exe is missing, can't be found, or can't find what it's looking for.

However, it does allow Windows users to do the building and uploading using a devcontainer with some setup, rather than locally. The devcontainer does not experience the lto-wrapper.exe ralated error during my testing, most likely due to it being a more supported Linux box, rather than a Windows one.

mverch67 commented 1 day ago

Is this the same that was already added to the device-ui repo?