For my project I found a way how to use PlatformIO inside WSL2. The main reason to do so is compilation time: 102 sec for Windows OS (Defender Antivirus Real-time protection is off) vs 35 sec for WSL2 (the same desktop, the same Windows OS).
The only issue was to get debugging working as usb devices support currently is not present in WSL2. Thanks Segger they have ability to use JLink via network. The whole developing process (editing, uploading firmware, debugging) works as expected and I just would like to have platformio.ini neat.
I ended up with this configuration in [env] section:
Is it possible to set debug_server via advanced scripting? Because ini-file is not the right place for the temporary value of ip address. For the uploader it can be done with quite simple post-script:
Import('env')
from os import environ
wslip = environ.get('WSLIP')
if wslip is not None:
flags = env['UPLOADERFLAGS']
flags.append('-nogui')
flags.append('1')
flags.append('-ip')
flags.append(wslip)
env.Replace(UPLOADERFLAGS=flags)
WSLIP is the environment variable. I set it in .bashrc file as: export WSLIP=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2; exit;}')
Thanks! I overlooked that system environment variables can be used as a section. Now I am almost happy. The ideal solution for me would be if I could set debug_server on the fly as UPLOADERFLAGS. In that case it doesn’t matter whether I use JLink via USB or WSL network, in both cases I don’t have to change platformio.ini. But it looks like I don’t have access to debug_server from pre/post scripts.
I’m also trying to use PlatformIO in WSL2 with JLink Remote Server. To flash the code from WSL2 to the board connected to the host machine, I followed your configuration for debug_server.
What I did are:
At host:
Connect the board with Jlink to laptop
Start JLink Remote Server
In the WSL2:
Edit the platformio.ini as below
Press upload in PlatformIO
A pop-up window shows up to ask for some credential stuff for JLink Server connection.
Console shows the target is connected, also the Remote Server at the host
Nothing happens afterward. The Build stucks, I can neither debug nor upload the code anymore.
Could you pls share what are the right steps to make this work?
Import('env')
from os import environ
wslip = environ.get('WSLIP')
if wslip is not None:
flags = env['UPLOADERFLAGS']
flags.append('-nogui')
flags.append('1')
flags.append('-ip')
flags.append(wslip)
env.Replace(UPLOADERFLAGS=flags)
WSLIP is the environment variable with JLink server ip address. Hope this helps.