VSCode + AVR Programming

Date: 2021-12-15

Here are the steps I took to get Visual Studio Code set up for AVR programming (specifically with avr-gcc). Note: this is raw AVR programming, not Arduino. Also, these instructions are for Linux (Fedora 35 in my case).

  1. Install the recommended C++ extensions for VSCode. I installed the whole pack.
  2. VSCode will probably create this file automatically, but if it doesn't you'll need to create .vscode/c_cpp_properties.json.
  3. The following configuration worked well for me. You'll need to modify the defines for the chip with which you're working (find them in <avr/io.h>).

Note: This setup doesn't include anything for compile/build/flash from the VSCode GUI. Call me old-fashioned, but I think there's a lot to be said for seeing and understanding the commandline. (I've even been known to type commands I could easily automate just to force them to stick in my brain.) Writing a script/Makefile is a happy median: documents the process while also automating it.

.vscode/c_cpp_properties.json:

{
    "configurations": [
        {
            "name": "Linux",
            "includePath": [
                "${workspaceFolder}/**",
                "/usr/avr/include/**"
            ],
            "defines": [
                "__AVR_ATtiny85__"
            ],
            "compilerPath": "/usr/bin/avr-gcc",
            "cStandard": "c99",
            "cppStandard": "c++03",
            "intelliSenseMode": "gcc-x64"
        }
    ],
    "version": 4
}