Skip to content
This repository was archived by the owner on Oct 1, 2024. It is now read-only.

please add "__AVR_ATmega328P__" to c_cpp_properties.json when the selected board is arduino uno #1279

Open
lozziboy opened this issue Jun 1, 2021 · 8 comments

Comments

@lozziboy
Copy link

lozziboy commented Jun 1, 2021

I open this ticket to make a request: add the following define to the automatically generated file c_cpp_properties.json when the selected board is arduino uno
"__AVR_ATmega328P__"

this is required to avoid intellisense wrong errors detection with the chip registers name
image

@EKlatt
Copy link

EKlatt commented Jun 3, 2021

Does Not work, because cpp.properties.json will be overwritten from Verifying.

@lozziboy
Copy link
Author

lozziboy commented Jun 3, 2021

Does Not work, because cpp.properties.json will be overwritten from Verifying.

That's the obvious reason why I opened this ticket, I ask for "AVR_ATmega328P" automatic generation.
PS: if you like, the overwrite option you mean can be disabled from plug-in settings

@BelKed
Copy link
Contributor

BelKed commented Jul 1, 2021

I suggest adding that for all boards... For example: For ATtiny85 should be added __AVR_ATtiny85__

@tonymitchell
Copy link

tonymitchell commented Jul 4, 2021

This needs to be fixed in the cocopa package this code uses. See issue elektronikworkshop/cocopa#7
The problem is the compiler options (such as -mmcu=atmega328p) aren't included in the command that gets parsed to produce the list of defines. Once the options are passed through, the -mmcu option will ensure that the appropriate defines are generated.

@dasfdlinux
Copy link

This needs to be fixed in the cocopa package this code uses. See issue elektronikworkshop/cocopa#7

The repo you referenced hasn't been updated in over a year, but has a pull request which you mentioned may fix the issue. Wouldn't it be worth pulling that code into this extension, or forking the repo, applying the pull request, and then closing out this issue?

@EverlastEngineering
Copy link

I'm having this issue too. I have a humble suggestion: could we add ${default} entries to both includePath and forcedInclude?

This affords a lot of freedom by allow the end user to specify entries in the settings.json in C_Cpp.default.includePath and C_Cpp.default.forcedInclude and should afford a very low chance of a regression IMO.

@NetworkAndSoftware
Copy link

A workaround is to first create your project, pick your board and allow the intellisense to generate the .vscode/c_cpp_properties.json and then disable the overwriting of it by setting "intelliSenseGen": "disable" in .vscode/arduino.json. After this you can just add AVR_ATmega328P or whatever you need for your board to .vscode/c_cpp_properties.json.

It's what @lozziboy already suggested above, but I thought people might like the detailed steps.

@0xAl3xH
Copy link

0xAl3xH commented Nov 21, 2022

I came back to this issue again after many months and forgot how to do the workaround so I'll leave this more detailed walkthrough of the workaround @NetworkAndSoftware and @lozziboy mentioned here just in case I or anyone else need it in the future:

You can have c_cpp_properties.json generated automatically initially by searching and running Arduino: Rebuild IntelliSense Configuration in View->Command Palette or cmd+shift+p for mac. After this, check .vscode/arduino.json to ensure a configuration with name Arduino has been generated and also make sure C/C++. .vscode/c_cpp_properties.json should look something like the snippet below. If you don't get this make sure you don't have Arduino: Disable Intelli Sense Auto gen checked/disabled in the extension settings.

{
    "version": 4,
    "configurations": [
        {
            "name": "Mac",
            "compilerPath": "/usr/bin/clang",
            ...
        },
        {
            "name": "Arduino",
            ...
        }

Make sure you use the configuration we just generated by searching and running C/C++: Select a Configuration... in command palette as above or alternatively clicking on the bottom bar as shown in this screenshot
Screen Shot 2022-11-21 at 10 29 13 AM

At this point, most of your intellisense errors should be fixed but if you're using any IO port definitions you'll still get an error. To fix this, add a line to defines referencing your specific board under the Arduino C++ configuration. As of writing this edit, I am using an ATTiny85 and the definition is "__AVR_ATtiny85__". You can find a list of these defines at <avr/io.h>. So your .vscode/c_cpp_properties.json should look something like this:

{
    "version": 4,
    "configurations": [
        {
            "name": "Mac",
            "compilerPath": "/usr/bin/clang",
            ...
        },
        {
            "name": "Arduino",
            ...
            "defines": [
                "__AVR_ATtiny85__", <---- or your board's define
                "F_CPU=1000000L",
                "ARDUINO=10819",
                "ARDUINO_attiny",
                ...
                ],
            ...
        }

Lastly, add "intelliSenseGen": "disable" to .vscode/arduino.json to prevent your changes from being overwritten. Note that you need to set this to true if you need to update the generated c_cpp_properties.json configuration in the future.

Your intellisense should now work!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants