Some random guy
Some random guy

Reputation: 17

How to set up intellisense in vscode for the rp2040

I'm aware there are some questions just like this one out there, but I wasn't able to get any value out of them (bc there's probably something I'm missing here).

I'm trying to set up intellisense in VScode to work with the rp2040 (pico). I am already able to build the project with cmake which was the first huge wall I was struggling to get across, but I'm now having difficulties trying to set up the intellisense to work just like it would with a normal C/C++ file when using VScode, but I can't get it to find or recognize the libraries in the pico-sdk directory, even if pointing directly at it (like giving it the exact path to the .h and .c files)

{
    "configurations": [
        {
            "name": "RP2040",
            "includePath": [
                "${workspaceFolder}/**",
                "C:/Users/Julio/VSARM/sdk/pico/pico-sdk/src/**",
                "${env:PICO_SDK_PATH}/**",
                "${workspaceFolder}/build/pico-sdk/**"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "windowsSdkVersion": "10.0.22000.0",
            "compilerPath": "C:/Users/Julio/VSARM/armcc/10 2021.10/bin/arm-none-eabi-gcc.exe",
            "intelliSenseMode": "gcc-arm",
            "cStandard": "c11",
            "cppStandard": "c++17",
            "configurationProvider": "ms-vscode.makefile-tools"
        }
    ],
    "version": 4
}

That's what's inside my c_cpp_properties.json file for this project, I attempted various calls to what I used to believe was the location of the libraries, but maybe I misunderstood that as well because it doesn't seem to care. "${workspaceFolder}/build/pico-sdk/**" is there because when I build with cmake it creates a pico-sdk folder inside the build folder as well, so I thought maybe doing that would work, but it didn't.

cmake_minimum_required(VERSION 3.12)

# Pull in SDK (must be before project)
include(pico_sdk_import.cmake)

project(blink C CXX ASM)
set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)

# Initialize the SDK and include the libraries
pico_sdk_init()

# Tell CMake where to find the executable source file
add_executable(${PROJECT_NAME} 
    main.c
)

# Create map/bin/hex/uf2 files
pico_add_extra_outputs(${PROJECT_NAME})

# Link to pico_stdlib (gpio, time, etc. functions)
target_link_libraries(${PROJECT_NAME} 
    pico_stdlib
)

# Enable usb output, disable uart output
pico_enable_stdio_usb(${PROJECT_NAME} 1)
pico_enable_stdio_uart(${PROJECT_NAME} 0)

add_compile_options(-Wall
        -Wno-format          # int != int32_t as far as the compiler is concerned because gcc has int32_t as long int
        -Wno-unused-function # we have some for the docs that aren't called
        -Wno-maybe-uninitialized
        )

That's the content of my CMakeLists.txt just in case it's important to know. Is there maybe a way to make VScode intellisense work with CMake? Perhaps that could work better I don't know. I know for a fact the project builds successfully because I uploaded the file to the MCU and it works just fine, it's more of a VScode problem I think rather than CMake(?

the contents of the project after building

UPDATE: I was able to get intellisense to detect the libraries for the Pico before actually trying to set CMake to be the intellisense provider as I was advised to do. The problem with that is that I'm not really sure how I managed it, I opened an unrelated cpp project in parallel to the RP2040 project and some automatic configuration from one of the extensions kicked in and fixed it. I assume this is a bad practice since I'm not aware of the reason why it works now. So I'm going to try the CMake way in short regardless.

Upvotes: 0

Views: 1362

Answers (1)

Lionel Sanderson
Lionel Sanderson

Reputation: 51

Those red underlines in the includes only recognised at compile time drove me nuts. I copied your c_cpp_properties.json and just modified the include path to mine and now they're recognised. Yay

{
    "configurations": [
        {
            "name": "RP2040",
            "includePath": [
                "${workspaceFolder}/**",  // edit this too, or the includes in your project directory instead become unrecognised
                "C:/Users/lfsan/pico/pico-sdk/**",
                "${env:PICO_SDK_PATH}/**"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "windowsSdkVersion": "10.0.22000.0",
            "intelliSenseMode": "gcc-arm",
            "cStandard": "c11",
            "cppStandard": "c++17",
            "configurationProvider": "ms-vscode.makefile-tools"
        }
    ],
    "version": 4
}

I just deleted some lines that didn't seem to be needed.

Upvotes: 2

Related Questions