+ - 0:00:00
Notes for current slide
Notes for next slide

ELECTENG 209

Analog & Embedded Software Design

An Introduction to PlatformIO

David Cole

1

David Cole, Department of Electrical, Computer and Software Engineering (2022)

What is PlatformIO?

  • PlatformIO is a cross-platform, cross-architecture platform for microcontroller development
    • Runs inside Visual Studio Code
    • Supports Windows, Mac and Linux
    • Vast microcontroller support, including Atmel AVR
  • Alternative to Atmel Studio - especially for macOS and Linux users

1

David Cole, Department of Electrical, Computer and Software Engineering (2022)

Installation

  1. Download and Install Visual Studio Code
  2. Install the PlatformIO extension

2

David Cole, Department of Electrical, Computer and Software Engineering (2022)

Demo Project

  • We have provided a demo PlatformIO project for use in ELECTENG 209 this year
    • avr-platformio-example
    • Clone the repository via Git, or download as a zip file if you want to use it as a template.
  • Open the project in Visual Studio Code (File -> Open Folder)

3

David Cole, Department of Electrical, Computer and Software Engineering (2022)

Project Layout

Key files/folders are highlighted here:

  • include - Put your C header files in this folder (uart.h, adc.h etc.)
  • src - Put your C source files in this folder (main.c, uart.c, adc.c etc.)
  • platformio.ini - PlatformIO configuration file
    • The provided copy will work for the Xplained Mini boards provided to you

4

David Cole, Department of Electrical, Computer and Software Engineering (2022)

Command Palette

  • Most PlatformIO actions happen via the Visual Studio Code Command Palette
  • Open it via one of the following shortcuts:
    • macOS - ⌘ + Shift + P
    • Windows and Linux - Ctrl + Shift + P

5

David Cole, Department of Electrical, Computer and Software Engineering (2022)

Building the Project

  • Open the command palette and run "PlatformIO: Build"
  • This will compile your project which will produce a .elf and .hex file
    • .elf can be used in Proteus
    • .hex can be uploaded onto your Xplained Mini
  • Any errors will be highlighted in the terminal which will appear at the bottom of your screen
    • Good for verifying your C code syntax (not behaviour!) without an Xplained Mini board

6

David Cole, Department of Electrical, Computer and Software Engineering (2022)

Uploading to Xplained Mini

  • Ensure your Xplained Mini is plugged in via USB
  • Open the command palette and run "PlatformIO: Upload"
    • This will build your project first if you have changed any source files since the last build
  • Any upload errors will be highlighted in a terminal which will appear at the bottom of your screen

7

David Cole, Department of Electrical, Computer and Software Engineering (2022)

Using Proteus via FlexIT (Part I)

These steps have only been tested on Mac.

  1. Follow the setup guide to install Horizon Client
  2. Mount your labs/project folder so it is accessible in FlexIT
    • Make sure your PlatformIO and Proteus project(s) are in this folder

8

David Cole, Department of Electrical, Computer and Software Engineering (2022)

Using Proteus via FlexIT (Part II)

  1. Start Labcenter Proteus by navigating to FlexIT and searching for Proteus
    • You may be prompted for credentials - these are listed on the course home page on Canvas
  2. File -> Open Project
  3. Select This PC and choose your mounted folder
  4. Use Proteus like you would in the labs
    • Your files in the folder you selected earlier will be available in FlexIT via the mount
    • Firmware for your AVR can be found at build/xplainedmini/firmware.elf in your PlatformIO project

9

David Cole, Department of Electrical, Computer and Software Engineering (2022)

Extra: simavr

  • simavr is an AVR simulator for Linux and macOS (not Windows)
  • Simulate and debug basic behaviour of your program (UART, logic, algorithms)
  • No out of the box support for most AVR peripherals
    • However it does support most peripherals if you dig deeper
  • Press F5 in Visual Studio Code to start a debugging session

10

David Cole, Department of Electrical, Computer and Software Engineering (2022)

Fixing Upload Issues on Windows

  • The drivers installed by Microchip Studio may not work with PlatformIO
  1. Install Zadig
  2. Click Options > List All Devices
  3. Select mEDBG CMSIS-DAP (Interface 0)
  4. Change the driver to libusbK or libusb-win32
  5. Click Replace Driver
  6. Try to upload with PlatformIO again

11

David Cole, Department of Electrical, Computer and Software Engineering (2022)

Resources

Reach out on your Slack channel for any other questions

12

End

12

David Cole, Department of Electrical, Computer and Software Engineering (2022)

What is PlatformIO?

  • PlatformIO is a cross-platform, cross-architecture platform for microcontroller development
    • Runs inside Visual Studio Code
    • Supports Windows, Mac and Linux
    • Vast microcontroller support, including Atmel AVR
  • Alternative to Atmel Studio - especially for macOS and Linux users

1
Paused

Help

Keyboard shortcuts

, , Pg Up, k Go to previous slide
, , Pg Dn, Space, j Go to next slide
Home Go to first slide
End Go to last slide
Number + Return Go to specific slide
b / m / f Toggle blackout / mirrored / fullscreen mode
c Clone slideshow
p Toggle presenter mode
t Restart the presentation timer
?, h Toggle this help
Esc Back to slideshow