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

identifier "Serial" is undefined with version 0.4.0 #1216

Open
lozziboy opened this issue Mar 25, 2021 · 24 comments
Open

identifier "Serial" is undefined with version 0.4.0 #1216

lozziboy opened this issue Mar 25, 2021 · 24 comments

Comments

@lozziboy
Copy link

lozziboy commented Mar 25, 2021

This is to open again the same issue discussed here
#866
and there
#808

IntelliSense has still some problem in finding the following keywords
"Serial"
"TCCR2A"
"TCCR2B"
"OCIE0A"

To manually solve this, I added the following defines to c_cpp_properties.json:
"USBCON", "__AVR_ATmega328P__"

to do this is required to disable Intelli Sense Auto Gen from the vscode extension settings

@adiazulay
Copy link
Contributor

This is odd, I tested this with the uno and it was working before we released.

I'm able to repro this on my Machine now, looking into what changed.

@zeroamps
Copy link

zeroamps commented Apr 3, 2021

Hi guys,
I can confirm the same issue on a WIN10 machine.

image

@adiazulay
Copy link
Contributor

so it looks like removing the "-MMD" complier arg from c_cpp_properties.json is culprit. We removed it because it was creating file erroneously on mac and linux.

Will revert to including it in the next release

@iFreilicht
Copy link

And we were like "What could possibly go wrong?" Good find! Maybe we can find another solution for the null.d-problem then.

@adiazulay
Copy link
Contributor

#1231 forces USBCON to be included in all config files.

@adiazulay
Copy link
Contributor

This should be fixed in v0.4.1 do you mind giving it a try and letting me know if it works?
https://github.com/microsoft/vscode-arduino/releases/tag/v0.4.1-rc1

@ccramer
Copy link

ccramer commented Apr 15, 2021

Awesome, workes like a charm for me now with v0.4.1. It added the "USBCON".

@coertg
Copy link

coertg commented Apr 17, 2021

Hoping this update will ship soon!

@Peter707-try
Copy link

Peter707-try commented Apr 18, 2021

0.4.1.rc1 works fine for me: USBCON is automatically added to c_cpp_properties.json
The Serial (not defined) issue is solved.
Thank You very much :)

@lozziboy
Copy link
Author

lozziboy commented Apr 19, 2021

This should be fixed in v0.4.1 do you mind giving it a try and letting me know if it works?
https://github.com/microsoft/vscode-arduino/releases/tag/v0.4.1-rc1

Unfortunately the problem is still partially present.

Updated to 0.4.1-rc1
image

Still having problems with other keywords
image

To workaround this, I added the following define to c_cpp_properties.json:
"__AVR_ATmega328P__"

PS: as usual, to do that, is required to disable Intelli Sense Auto Gen from the vscode extension settings

@iFreilicht
Copy link

Thank you so much for the screenshot! Now I realize why we didn't see this during testing, we only ever tried using the Arduino API, not the chip registers. Can you check whether the -MMD flag is added to the compiler options by the auto generation?

@lozziboy
Copy link
Author

Thank you so much for the screenshot! Now I realize why we didn't see this during testing, we only ever tried using the Arduino API, not the chip registers. Can you check whether the -MMD flag is added to the compiler options by the auto generation?

Where can I check it?

@adiazulay
Copy link
Contributor

adiazulay commented Apr 19, 2021

@iFreilicht I looked into it, and instead of adding back -MMD I added USBCON to defines. Which reliably fixes the serial issues.
@lozziboy I'm going to take the second part of this as a backlog item and open a new issue for it.

@Yszty
Copy link

Yszty commented May 10, 2021

Hello, same problem with EEPROM

image
image
image

"defines": [ "USBCON" ],

@lozziboy
Copy link
Author

lozziboy commented Jun 1, 2021

Hello, same problem with EEPROM

image
image
image

"defines": [ "USBCON" ],

I don't have this problem with EEPROM.

Did you installed EEPROM library from IDE?
Please check if you have EEPROM library include path in file c_cpp_properties.json
image

PS: at my side version 0.4.3 automatically generates USBCON, check also this

@itopaloglu83
Copy link

itopaloglu83 commented Dec 2, 2021

Okay. Here's another strange behavior. Defining "USBCON" and "__AVR_ATmega328P__" causes the following error on Arduino.h line 326.

#error directive: "Targets with both UART0 and CDC serial not supported"C/C++(35)

Maybe not every board require USBCON by default. I added the following code block to my sketch to check if USBCON is defined at compile time and it wasn't.

#ifdef USBCON
#error "What, what?"
#endif

USBCON is usually defined in the device header files to signal that the board is capable of USB. Force adding such a parameter to all board might be an erroneous action. I think the root cause is the fact that -mmcu=atmega328p command line parameter to the compiler is not being parsed properly to crease the c_cpp_properties.json file which in turn fails to parse the device header file properly.

@iFreilicht
Copy link

iFreilicht commented Dec 2, 2021 via email

@itopaloglu83
Copy link

@iFreilicht

The v0.4.1 release is manually adding the USBCON to all boards, regardless of their capabilities. That is the issue I'm trying to show.

runner.result.defines.push("USBCON")

@itopaloglu83
Copy link

For anyone using Arduino Uno. After the c_cpp_properties.json file is created, just disable to automated update and add the following definitions to it. These are coming from AVR-GCC command line parameter of -mmcu=atmega328p. The details can be found on https://www.nongnu.org/avr-libc/user-manual/using_tools.html website where options are explained.

// AVR-GCC is used.
"AVR=1",
"__AVR=1",

// The architecture of ATmega328P is AVR5.
"__AVR_ARCH__=5",
"__AVR_MEGA__",
"__AVR_ENHANCED__",
"__AVR_HAVE_JMP_CALL__",
"__AVR_HAVE_MOVW__",
"__AVR_HAVE_LPMX__",
"__AVR_HAVE_MUL__",
"__AVR_2_BYTE_PC__",

// The MCU type is ATmega328P.
"__AVR_ATmega328P__",

// Additional command line define statements.
"F_CPU=16000000L",
"ARDUINO=10607",
"ARDUINO_AVR_UNO",
"ARDUINO_ARCH_AVR"

@iFreilicht
Copy link

Oh boy. Looking at the history of this ticket, forcing USBCON was supposed to work around IntelliSense not finding Serial, but if USBCON can't be used on some devices, then that workaround only works inside IntelliSense.

I think we have to go back to using -MMD and fix the issue of null.d getting created on Unix instead. That is likely more reliable than stacking workarounds on top of workarounds.

@itopaloglu83
Copy link

I later realized that adding "-mmcu=atmega328p" to the compilerArgs part also resolves the errors for Arduino Uno as well.

{
    "version": 4,
    "configurations": [
        {
            "name": "Arduino",
            "compilerPath": "/home/pi/.arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/bin/avr-gcc",
            "compilerArgs": [
                "-w",
                "-std=gnu++11",
                "-fpermissive",
                "-fno-exceptions",
                "-ffunction-sections",
                "-fdata-sections",
                "-fno-threadsafe-statics",
                "-Wno-error=narrowing",
                // Microcontroller: ATmega328P
                "-mmcu=atmega328p"
            ],
            "intelliSenseMode": "gcc-x64",
            "includePath": [
                "/home/pi/.arduino15/packages/arduino/hardware/avr/1.8.4/cores/arduino",
                "/home/pi/.arduino15/packages/arduino/hardware/avr/1.8.4/variants/standard",
                "/home/pi/.arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/lib/gcc/avr/7.3.0/include",
                "/home/pi/.arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/lib/gcc/avr/7.3.0/include-fixed",
                "/home/pi/.arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/avr/include"
            ],
            "forcedInclude": [
                "/home/pi/.arduino15/packages/arduino/hardware/avr/1.8.4/cores/arduino/Arduino.h"
            ],
            "cStandard": "c11",
            "cppStandard": "c++11",
            "defines": [
                // Arduino Uno Specific Definitions
                "F_CPU=16000000L",
                "ARDUINO=10607",
                "ARDUINO_AVR_UNO",
                "ARDUINO_ARCH_AVR"
            ]
        }
    ]
}

@apws
Copy link

apws commented Jan 17, 2022

hi guys, I just stared to test vscode+arduino and have problem with intellisense around Serial too, but only using "megaTinyCore" boards-package and Microchip Curiosity Nano Tiny1627 - on original Leonardo and Infineon XMC2Go (cortex m0+) board packages, it doesnt happen. Code normally builds/uploads/runs, but there is only reported problem... that board uses nEDBG OB programmer (XMC2Go uses segger J-link lite).
image

@rednebmas
Copy link

rednebmas commented Jan 29, 2022

Add the following above the line#include <Arduino.h> to get the error to go away.

#define USBCON 1 // Prevents Serial errors from VSCode. MUST be above #include <Arduino.h>

The reason is that Serial is defined in CDC.cpp (in arduino/avr/cores/arduino) but the definition for Serial is hidden behind an #if defined(USBCON).

@lozziboy
Copy link
Author

#define USBCON 1

This don't works with the chip registers
image

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

No branches or pull requests