At some point in the last year (because it was working at some point), the Visual Studio Code setup I use to edit a firmware project based on Zephyr ( https://zephyrproject.org/ - the actual project is the ZMK keyboard firmware https://zmkfirmware.dev/ ) stopped presenting me with code completion options, the ability to "Go to Definition/Go to Declaration", etc - I definitely had these working at some point, then they stopped. I noticed it a while ago, but it hasn't been high enough priority to fix.
Unfortunately, like a lot of modern software, the settings which affect this seem to be scattered over a lot of different places, and it's not really clear to me where they all are and how they should be set. I have the C/C++ extension installed, as well as the "C/C++ extension pack", because the primary language in use is C.
On my primary repository (the one under active development), I see "Loading..." indefinitely when I hover over things in a C window. If I check out a completely new project (from the ZMK github repo), I see errors because certain #include files (like #include <kernel.h>) can't find other files included within - I assume because some paths are not set properly. I vaguely recall setting some include paths once upon a time in my main repo, but I can't find those settings now. (see "scattered over a lot of different places", above)
The main difference in the .vscode dir between the two seems to be that the eternally "Loading" one has .vscode/c_cpp_properties.json and the one that gives errors does not. Here's what's in the file:
{
"configurations": [
{
"name": "Mac",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [],
"macFrameworkPath": [],
"cStandard": "gnu17",
"cppStandard": "gnu++17",
"intelliSenseMode": "${default}",
"compilerPath": "/usr/local/bin/arm-none-eabi-gcc",
"compileCommands": "${workspaceFolder}/app/build/compile_commands.json"
}
],
"version": 4
}
So, questions:
how do I see what error is being encountered when "Loading..." never goes away?
what can I do to fix this problem on MacOS?
where do I configure the include paths that Intellisense uses for include files to find their further includes?
is there a list of all the different places things can be configured in VSCode, and what they are?!?
Related
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(?
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.
I recently started doing some programming with C/C++. I was using Dev-C++ and today
i changed to Visual Studio Code because later on i'll need to work in other programming languages too, like Python, R etc. I successfully installed it and i added the extensions of C/C++ and Code runner. Although am having some problems when i try to run the following two basic programs:
#include <stdio.h>
int main(void){
printf("hello world\n");
return 0;
}
and
#include <stdio.h>
int main(void){
int x;
printf("Give a number: ");
scanf("%d",&x);
printf("Your number is: %d\n",x);
return 0;
}
In the first program i get the following output in the integrated terminal of VS code:
My first question is a matter of appearance, how can i remove the path that shows above the "hello world" output? Also, notice that i am on the terminal option, if i switch to the output option, nothing is being displayed there, although i have seen in some tutorials that they can display their results in the output option which is more minimalistic than the terminal, in addition it displays the run time of the program which is a nice feature.
In the second program when i press the Run Code button it opens my cmd first and asking to give a number, after i give the number and press Enter i can type the asked number also in the integrated terminal of VS and get the result. Is there anyway to surpass my cmd? I.e. to run the program only in VS without running it also through the cmd? Note that i have already checked the option "Run In Terminal" in the settings of the code runner extension.
Thanks in advance!
So I believe you are on windows, simply installing the extension wont help, there are a few more steps to this.
You'll create a tasks.json file to tell VS Code how to build (compile) the program. This task will invoke the g++ compiler to create an executable file based on the source code.
From the main menu, choose Terminal > Configure Default Build Task. In the dropdown, which will display a tasks dropdown listing various predefined build tasks for C++ compilers. Choose g++.exe build active file, which will build the file that is currently displayed (active) in the editor.
This will create a tasks.json file in a .vscode folder and open it in the editor.
Your new tasks.json file should look similar to the JSON below:
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "C/C++: g++.exe build active file",
"command": "C:\\Program Files\\mingw-w64\\x86_64-8.1.0-posix-seh-rt_v6-rev0\\mingw64\\bin\\g++.exe",
"args": ["-g", "${file}", "-o", "${fileDirname}\\${fileBasenameNoExtension}.exe"],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": ["$gcc"],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
To run the build task defined in tasks.json, press Ctrl+Shift+B or from the Terminal main menu choose Run Build Task.
You can run your program in the terminal by typing .exe (or .<your program name.exe if you use a PowerShell terminal).
Hello you should try to install the Code Runner extension. You will run your future C and Python code easily.
I've been using VSCode for C language professionally almost everyday for +1 year. Right now, I hit with something that is really affecting my productivity.
When I open a big project, the features "Go to definition, Go to declaration, Peek..." etc don't work. I don't know how to describe how 'big' the project is. There are source files with +26k lines and it can take up to 45 min to compile. When I work with a more reasonably sized project, I have no issues, so until now I assumed this was a limitation of the program due to the size of my project and resigned myself. Now, I'm really bothered at this point and would like to find a solution.
What strikes me is that searching in the whole project (Ctrl + Shift + F) is blazing fast and works brilliantly, so VS seems to be capable of 'handling' this big project.
C/C++ extension from Microsoft last version v0.28.3
VSCode last version 1.46.1
Windows 10
Do you think there is a solution for this? Have you used VSCode with massive projects?
Edit: by 'don't work' I mean, it tries to perform the action but stays 'thinking' indefinitely.
Most propably it is not "Not working" but just "pretty slow". This is a known problem for C/C++ projects using the C/C++ extension for Visual studio code. The Indexer for intellisense needs some time (especially if you are not limiting it via limitSymbolsToIncludedHeaders or something like that). You could try reducing the amount of parsed files by using explizit browse paths in your c_cpp_properties.json like
"browse": {
"path": [
"/usr/include/",
"/usr/local/include/",
"${workspaceRoot}/../include",
"${workspaceRoot}/dir1",
"${workspaceRoot}/dir2",
"${workspaceRoot}/dir3/src/c++",
"${workspaceRoot}/dir5",
"${workspaceRoot}/dir6/src",
"${workspaceRoot}/dir7/src",
"${workspaceRoot}/dir4"
],
and excluding for example IDE/SDK files where you do not need autocompletion/Go To Symbol/Go to definition.
For more explanation see: https://github.com/microsoft/vscode-cpptools/issues/1695
I'm working in VSCode with the C/C++ extension on Ubuntu 18.04.
I'm trying to include gmodule.h and it raises the error gmodule.h: No such file or directory on line 2, character 10 of the main file.
So, the problem lies with gmodule.h being not in /usr/include but in /usr/include/glib-2.0. Realizing this, I added this folder to the includePath variable in c_cpp_properties.json. However, it still raises the same error.
When using #include <glib-2.0/gmodule.h> instead of #include <gmodule.h>, it does work but this only shifts the problem to gmodule.h itself, as other includes that lie in the glib-2.0 folder still don't work inside of gmodule.h.
All in all, the problem is that add to the includePath in c_cpp_properties.json doesn't change anything and I want to know how to make this work, since I would like to use gmodule.
c_cpp_properties.json:
{
"configurations": [
{
"name": "Linux",
"defines": [],
"compilerPath": "/usr/bin/gcc",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "clang-x64",
"includePath": [
"/usr/include/glib-2.0/*"
]
}
],
"version": 4
}
for now I'm just trying to include gmodule.h and not do anything with it yet, so this is my main file:
#include <stdio.h>
#include <gmodule.h>
int main() {
printf("hai\n");
return 0;
}
The c_cpp_properties.json controls, among other things, where intellisense in the IDE resolves include files. The IDE and the build tasks are independent things and as a result, configured and operate independently in VS Code.
The solution to your problem is to add the include path to your tasks.json file, as follows:
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}",
"--include-directory=/usr/include/glib-2.0/"
],
I managed to make IntelliSense work by adding two paths for glib as reported by pkg-config:
$ pkg-config --cflags glib-2.0
-I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include
.vscode/c_cpp_properties.json
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**",
"/usr/include/glib-2.0/**",
"/usr/lib/x86_64-linux-gnu/glib-2.0/include/**"
],
"defines": [],
...
}
],
...
}
I had the same issue, and it was caused by the configurationProvider option in the c_cpp_properties.json file pointing to a disabled makefile-tools plugin. The makefile-tools plugin was correctly generating the list of include paths, but these paths were not included in the final list of include paths for Intellisense, because the plugin was disabled. In my case, the solution was either remove that configuration option or enable the makefile-tools plugin.
What solved it for me was to just type folder path without /* or /**
Then it prompted me if I want to enable Intellisense for this folder and I allowed it and it worked.
Issue:
Thanks all! This pointed me in the right directions. I was getting an error not finding the WxWidgets library. The "configurationProvider" issue seems to be the problem.
I do have "makefile-tools" installed and the "configurationProvider" pointed to it, so not sure why there was an issue.
For this solution, I also had tried forcing the include directories in the "includePath" with no success as per the original issue.
My project is using CMake, but the "configurationProvider" was pointing to "makefile-tools" for whatever reason. I removed the forced "includePath" paths and pointed "configurationProvider" to "ms-vscode.cmake-tools". This seemed to fix my issue after reopening the project.
Solution:
ctrl-shift-p
C/C++: Change Configuration Provider...
Select "CMake Tools"
Exit VSCode
Start VSCode
I am trying to implement the use of DSP in the STM32 F411RE board, but I cannot seem to include the necessary files without invoking numerous errors.
Background
I have previously had CMSIS and CMSIS-DSP working in Keil uVision, but given the code limit of 32k that puts me over the evaluation limit rather quickly. As such I have been attempting to include CMSIS-DSP into Atollic TrueStudio but this seemingly is difficult to accomplish: there is limited documentation available on the CMSIS-DSP to begin with and even less so for implementation in Atollic TrueStudio.
Some related resources can be found in the
Atollic TrueStudio User Guide
as well as
StackOverflow topic #1
and
StackOverflow topic #2
. Most other related topics I could find just refer to the use of Keil uVision or the User Guide without much further help.
Atollic TrueStudio does incorporate a in-built package manager where the base CMSIS is available for download, but it does not provide this option for the CMSIS-DSP pack.
Attempted solution
I have attempted to manually download the corresponding CMSIS package (STM32Cube_FW_F4_V1.24.0) and place the corresponding DSP package into the project file structure. This then permits the use of the DSP functions such as
#include arm_math.h or arm_rfft_fast_instance_f32 S; which can also be invoked with the use of the autocomplete functionality and as such are thus recognized by the IDE.
However, this process also invokes many errors as the included functions fail to recognize their header dependencies (such as the #include arm_math.h). I find it confusing that the main.c is able to recognize the #include arm_math.h command yet the functions included are not, but I nevertheless try to fix this by adding the CMSIS DSP to the included directories (found at 'Build properties --> C/C++ Build --> Settings --> Tool Settings --> C Compiler --> Directories`). However, this does also not remedy the issue at hand.
Code results
The function cannot find the header
However the main can find the exact same header
And the header is included in the build options -> directories
Just verified that it is also included in the 'path and symbols', which it should do automagically AFAIK once you include it in the build options:
Update
Since my OP I have made some progress, mostly via messing around with the includes, symbols and linker. I have now managed to defeat the original error (though unfortunately I have no idea how), but I have now incurred a large amount of additional errors for the startup_stm32 files.
These all appear to be bad instruction errors referring to the template files included in CMSIS (CMSIS / Device / ST / STM32F4xx / Source / Templates / ARM / ...), which somehow cannot interpret the various commands listed in these templates.
Example errors: bad instruction __heap_base
I have since figured out the issue for my project: including the CMSIS folder as available from the Github repo means that a lot of templates are present throughout the entire folder structure. When attempting to build / compile whilst these templates are still present it causes a lot of issues with invalidated types and re-defining errors.
Most of these templates are in a logical location, but some are buried quite deep down and may thus be difficult to find. I will try to make a video soon describing the process of adding CMSIS (DSP) from the github repo to your project in TrueStudio.
In the meantime, the following steps should make CMSIS and CMSIS-DSP work in your STM32 TrueStudio ProjecT:
Ensure that all templates (folders) are removed from the CMSIS folder. This may require some searching and experimenting: the particularly noxious ones are hidden in
../STM32Cube_FW_xx_Vx.xx/Drivers/CMSIS/Device/ST/STM32xxxx/Source/{Templates}
whilst there are also other sets at ../STM32Cube_FW_xx_Vx.xx/Drivers/CMSIS/DSP/{Examples} and ../STM32Cube_FW_xx_Vx.xx/Drivers/CMSIS/DSP/{Projects} that I had removed for my project to compile / build succesfully.
Include all the folders that are named include in the folders. AFAIK you cannot just include the main ../Drivers folder, as includes do not appear to also include the underlying structure and it also seems to include errors for my project. Best to just include the folders manually: you can so so by right-clicking on the intended folder to include, click the option near the bottom "Add/Remove include path" and tick both boxes for release and debug before pressing 'OK' to include this folder. Repeat for the other 'include' folders.
Fish up the RTE_Components.h file located at ../STM32Cube_FW_xx_Vx/STM32xxxx-Nucleo\Templates\MDK-ARM\RTE. There are also files with this name (RTE_Components.h) available in the NN (Neural Networks) CMSIS-pack folder, do not touch those. Copy this file to any location that you have previously included (placed mine in ../Drivers/CMSIS/Include), and open it up in your IDE of choice. Add the line #define CMSIS_device_header " DEVICE_NAME.h " before any of the other statements and replace device name with your STM32 board name. For example, my RTE_Components.h file looks like
/*
* Auto generated Run-Time-Environment Component Configuration File
* *** Do not modify ! ***
* Project: 'Project'
* Target: 'STM32F410Tx_Nucleo'
*/
#define CMSIS_device_header "stm32f4xx.h" // define own board header, eg stm32f4xx.h or stm32f7xx.h
#ifndef RTE_COMPONENTS_H
#define RTE_COMPONENTS_H
#endif /* RTE_COMPONENTS_H */
Make sure that the device name for the CMSIS_device_header corresponds to the header .h
file located in ../Drivers/CMSIS/Device/ST/DEVICE_NAME/Include/DEVICE_NAME.h
Add the required symbols (right-click your project, go to properties, C/C++ General, Paths and Symbols; then go to the #Symbols tab) to define the FPU and your Cortex Core type. For me I need to add __FPU_PRESENT (either with no value or value '1') and because I have the Cortex M4 chip on the STM32F411RE I add ARM_MATH_CM4. This means that my list of Symbols looks like:
__FPU_PRESENT
__packed with value __attribute__((__packed__))
__weak with value __attribute__((weak))
-ARM_MATH_CM4
STM32F411xE
USE_HAL_DRIVER though this depends if you want to use the HAL or not
Again make sure that the necessary includes are well defined, as not including only 1 directory can lead to a large amount of errors. These can be found by going to project properties (right-click your project, option at the bottom), going to the C/C++ Build, Settings, then the Tool Settings tab, C Compiler dropdown and to the Directories option.
For my project I have the following include path's inside the project properties:
../Inc (should be by default)
../Drivers/CMSIS/Device/ST/STM32F4xx/Include (should be by default)
../Drivers/STM32F4xx_HAL_Driver/Inc (should be by default)
../Drivers/STM32F4xx_HAL_Driver/Inc/Legacy (should be by default)
../Drivers/CMSIS/Include (should be by default)
"${workspace_loc:/${ProjName}/Drivers/Device/ST/STM32F4xx/Include}"
"${workspace_loc:/${ProjName}/Drivers/CMSIS/Core/Include}"
"${workspace_loc:/${ProjName}/Drivers/CMSIS/Core_A/Include}"
"${workspace_loc:/${ProjName}/Drivers/CMSIS/DSP/Include}"
Hopefully this helps and works for you too!