Skip to content

Instantly share code, notes, and snippets.

@mateuscelio
Last active July 14, 2021 22:24
Show Gist options
  • Save mateuscelio/a064eeae6fc7431e8256eb458be8a33b to your computer and use it in GitHub Desktop.
Save mateuscelio/a064eeae6fc7431e8256eb458be8a33b to your computer and use it in GitHub Desktop.

PlatformIO + vim

Requiriments

PlatformIO Core (CLI)

ccls Language Server

Vim Plugins

Configuring ccls Language Server

Afer installing all required softwares, configure ccls language server in coc.nvim. For this, open vim and type :CocConfig and add ccls config to languageserver

  "languageserver": {
    "ccls": {
      "command": "ccls",
      "filetypes": ["c", "cpp", "objc", "objcpp"],
      "rootPatterns": [".ccls", "compile_commands.json", ".vim/", ".git/", ".hg/"],
      "initializationOptions": {
         "cache": {
           "directory": "/tmp/ccls"
         }
       }
    }
  }

Generating a new PlatformIO project

Find your board ID using the command pio boards board_alias. For example, result searching for bluepill:

$ pio boards bluepill

Platform: ststm32
========================================================================================
ID                    MCU            Frequency    Flash    RAM    Name
--------------------  -------------  -----------  -------  -----  ----------------------
bluepill_f103c6       STM32F103C6T6  72MHz        32KB     10KB   BluePill F103C6
bluepill_f103c8       STM32F103C8T6  72MHz        64KB     20KB   BluePill F103C8
bluepill_f103c8_128k  STM32F103C8T6  72MHz        128KB    20KB   BluePill F103C8 (128k)

Create a directory to your project, go inside and execute the command using your board ID found in previous command:

pio project init --ide vim --board <ID>

This command will create the project structure with .ccls file. This file is used to specifie compiler flags necessary to index the code. For ex. include search path for directory related to board framework and toolchain managed by platformIO.

After installing a library is necessary update the .ccls file running the following command:

pio init --ide vim 

Create a Makefile in the project and put the following in:

# Uncomment lines below if you have problems with $PATH
#SHELL := /bin/bash
#PATH := /usr/local/bin:$(PATH)

all:
        pio -f -c vim run

upload:
        pio -f -c vim run --target upload

clean:
        pio -f -c vim run --target clean

program:
        pio -f -c vim run --target program

uploadfs:
        pio -f -c vim run --target uploadfs

update:
        pio -f -c vim update

Now inside vim, just type :make upload for build and upload to the board.

References

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment