robotthoughts

Build PlatformIO on Windows Subsystem for Linux (Ubuntu)

I usually prefer running platformio from command line so I can stream the build process into my backup and recovery processes. With versioning, I can roll back to a know good working build. I am most often building Marlin firmware for my 3D print farm so there is a small example of the build commands used for Marlin at the end.

The first step is to make sure you have Windows Subsystem for Linux installed.

Open settings on Windows 10 and select Apps:

From there make sure you are in Apps & Features:

Scroll to the bottom and select the related settings:

Once the Programs and Features windows opens, on the left hand pane choose “Turn Windows features on or off”:

That will bring up a dialog that allows you to select Windows Subsystems for Linux.

Once selected and you hit ok, you will need to reboot.

Once you log back in, open the Microsoft Store, search for Ubuntu and install it.

Once Ubuntu is installed, you can open the application and assign a username and password for your use. The user will have ‘sudo’ access so you can update and run application as a super user in the Ubuntu environment.

When the setup completes type ‘cd’ to move into your home directory

cd

Now update the environment before beginning:

sudo apt update && sudo apt upgrade

We will install a few pre-requisites before beginning:

sudo apt install python3
sudo apt install python3-distutils
sudo apt install wget
sudo apt install unzip

Once updates are complete and the pre-requisites are installed, we can begin installing platformio.

We will start with downloading the platformio.

wget https://raw.githubusercontent.com/platformio/platformio-core-installer/master/get-platformio.py -O get-platformio.py

Once it downloads, we can install it with python.

python3 get-platformio.py

After that installs, we need to update the $PATH variable to find the platformio /bin directory. To do that and make it permanent, we will modify your .profile.

vi .profile

Move to the bottom of the .profile file and add this line:

PATH="~/.platformio/penv/bin:$PATH"

Now you can logout of the Ubuntu environment and log back in to add that path os simply type this command:

source .profile

That will tell your current shell to update the $PATH variable.

Now you should be able to type ‘platformio” on the command line and it will work without specifying a full path.

Let’s download Marlin and build it real quick.

Either copy your Marlin working folder to the home directory you are working in or get a new copy from the Marlin github:

wget https://github.com/MarlinFirmware/Marlin/archive/2.0.x.zip

From here you need to modify your build files and your platformio.ini that are specific to your board. See the instructions for your board vendor.

I am building today for a BigtreeTech SKR Mini E3 so my build commands will reflect that board below. Please substitute your correct board.

After you have made the recommended changes to the Marlin folder for your specific board, you can clean and build the environment.

To clean the environment:

platformio run -s --target clean -e STM32F103RC_bigtree (or your specific board that you set in the platformio.ini file)

To build the environment:

platformio run -s -e STM32F103RC_bigtree (or your specific board that you set in the platformio.ini file)

Remember once the build is done, your firmware bin file can be found in the ~/Marlin/.pio/build/YOURSPECIFICBOARDfirmware.bin

Place that .bin file on your SD card and reboot your 3D printer. You can also upload that file to many types of 3D printers over Octoprint.

Mastodon

Next Post

Previous Post

Leave a Reply

© 2024 robotthoughts

Theme by Follow Me on Mastodon

Bitnami