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

IntelliSense auto-generation does not add correct -mmcu compiler argument #1246

Closed
dumbasPL opened this issue Apr 30, 2021 · 1 comment
Closed

Comments

@dumbasPL
Copy link

As requested here I would like to reopen this issue.

MCU-specific code like inline assembly or direct register access will generate false-positive error messages in IntelliSense.

Example of problematic code:

//example 1: PRGMEM access
//based on https://www.arduino.cc/reference/en/language/variables/utilities/progmem/
const char signMessage[] PROGMEM = {"This is a test"};
char myChar;
void foo() {
  // read back a char
  for (byte k = 0; k < strlen_P(signMessage); k++) {
    myChar = pgm_read_byte_near(signMessage + k); // this will throw `unknown register name 'r0' C/C++(1118)` but compile just fine
    Serial.print(myChar);
  }
  Serial.println();
}

//example 2: register access
//based on https://www.arduino.cc/en/Reference/PortManipulation
void bar() {
  // sets Arduino pins 1 to 7 as outputs, pin 0 as input
  DDRD = B11111110; // this will throw `identifier "DDRD" is undefined C/C++(20)` but compile just fine

  // sets digital pins 7,5,3 HIGH
  PORTD = B10101000; // this will throw `identifier "PORTD" is undefined C/C++(20)` but compile just fine
}

Proposed solution add correct -mmcu flag based on currently selected board.
Example for an Arduino UNO board: -mmcu=atmega328p

Adding this flag solves all the above-mentioned issues.

@egcris
Copy link

egcris commented Oct 21, 2021

Duplicate of #1279

vscode-arduino uses cocopa to parse Arduino's avr-g++ command-line and get the defines.

But cocopa doesn't include -mmcu (nor other flags) in the search scope for defines, as per elektronikworkshop/cocopa#7 :(

Pull request #8 at cocopa that solves this, still awaiting approval...

@dumbasPL dumbasPL closed this as not planned Won't fix, can't repro, duplicate, stale Oct 24, 2022
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

2 participants