Tutorial: PlatformIO in VSCode

Tutorial: PlatformIO in VSCode

In this class, we are going to use VS Code to program firmware on STM32f4.

Part 1: Installation

Step 1: Install Python

You can install Python in Window by following the instruction here:

Install Python 3.x in Win OS

How to check if you already have Python

  • Open Window Command Prompt > Type python --version

  • If you see the version, then you already have python installed.

    image

Step 2: Install VS Code

Refer to Installation-guide: VS CDOE

Step 3: Install PlatformIO Core

You may not need this step if you are going to use VS Code. But, install anyway.

  1. Download python file of PlatformIO Core: Save as (다른이름으로 링크저장): get-platformio.py

  • Download and save it as in py file

WIN OS: In command prompt

MAC OS

Step 4: Install PlatformIO IDE extension in VS Code

  1. Open VS Code

  1. Open VSCode Package Manager

  2. Search for the official PlatformIO IDE in extension.

  3. Install PlatformIO IDE

Part 2: Configure Project (STM32f4) / One-time only

Step 1: Create a Project in PlatformIO

  1. Go to PlatformIO Home by clicking on the PlatformIO Icon

  2. Create New Project

  1. Name the project as EC

  2. Select setting as follows

  • Board: ST Nucleo F411RE

  • Framework: CMSIS

  • Location: Your EC workspace

Step 2: Project Configuration (platformio.ini)

For every new TU or LAB, you can create a new environment that shares the MCU configuration. You do not need to re-configure the MCU setup everytime you create a new project.

You only need one configuration file platformio.ini for all tutorial and assigments.

Copy this platformio.ini in the workspace folder

image

Step 3: Adding Library

You can add your EC library header files under the directory of \include

You can add it under the directory of \include. But you need to modify the include_dir folder in platformio.ini

Part 3: Create and Add New Environment

You can start your Tutorial or LAB by following this Part 3.

Each Lab and Tutorial session will have a unique environment.

Step 1: Create a new environment and program file

  1. Open VSCode and select the EC workspace folder

  • i.e. : \repos\EC\

  1. Go to PlatformIO Home by clicking on the PlatformIO Icon

  1. For this tutorial, create the project folder and program source file as

  • Folder: repos\EC\tutorial\TU_CreateProject_VSC\

  • Main src: TU_CreateProject_Example1_main.c

TU_CreateProject_Example1_main.c

Step 2. Modify the Configuration

Simply, add the new environment that links your new program main file.

Modify platformio.ini , to add new environment

Step 3: Selecting Environment, Build and Run

  1. Click on Switch the environment on VSCode

  2. Select the Environment you want to build.

    • For this tutorial, select [env:TU_CreateProject_Example1]

  3. BUILD

  4. If you have MCU connected, you can also UPLOAD

image

Exercise - Add another environment

In this Exercise, we are going to add another environment, and add more library header files.

For every time you do a new LAB or Tutorial, you do NOT need to create a project.

Just add a new environment in platformio.ini and select this environment to build.

Preparation

First, download the library header files

Save them in the include folder

See here for more information on header files: https://ykkim.gitbook.io/ec/ec-course/tutorial/tutorial-library-header-files#ec-header-files

Procedure

Repeat Part 3 (Step 1 to Step 3).

  • Folder: repos\EC\tutorial\TU_CreateProject_VSC\

  • Main src : TU_CreateProject_Example2_main.c

  • Environment: [env:TU_CreateProject_Example2]

TU_CreateProject_Example2_main.c

Appendix

PlatformIO Toolbar

Read more about it here

image

PlatformIO IDE Toolbar is located in VSCode Status Bar (left corner) and contains quick access buttons for the popular commands. Each button contains hint (delay mouse on it).

  1. PlatformIO: Build

  2. PlatformIO: Upload

  3. PlatformIO: Clean

  4. Project environment switcher (if more than one environment is available). See [Section env] of “platformio.ini” (Project Configuration File) .

Last updated

Was this helpful?