question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

cppcheck code inspect fails on samd boards

See original GitHub issue

Configuration

Operating system: Ubuntu 20.04 5.4.0-73-generic #82-Ubuntu x86_64 x

PlatformIO Version (platformio --version): PlatformIO Core, version 5.1.1

Description of problem

When Inspect (pio check -v) is run against a SAMD based project the cppcheck code analysis fails with the following error:

Error: Found a breaking defect 'failed to expand 'SAMD_SERIES', Invalid ## usage when expanding 'part_is_defined'.' in /home/jimh/.platformio/packages/framework-cmsis-atmel/CMSIS/Device/ATMEL/sam.h:32
Please note: check results might not be valid!
Try adding --skip-packages

"severity=error<&PIO&>message=failed to expand 'SAMD_SERIES', Invalid ## usage when expanding 'part_is_defined'.<&PIO&>file=/home/jimh/.platformio/packages/framework-cmsis-atmel/CMSIS/Device/ATMEL/sam.h<&PIO&>line=32<&PIO&>column=0<&PIO&>callstack=[/home/jimh/.platformio/packages/framework-cmsis-atmel/CMSIS/Device/ATMEL/sam.h:32]<&PIO&>cwe=0<&PIO&>id=preprocessorErrorDirective"

Running check with --skip-packages works (pio check -v --skip-packages):

Component     HIGH    MEDIUM    LOW
-----------  ------  --------  -----
*/.pio         0        0        1
nofile         0        0        1
src            0        0        4

Total          0        0        6

Environment          Tool      Status    Duration
-------------------  --------  --------  ------------
uno                  cppcheck  PASSED    00:00:00.711
adafruit_feather_m0  cppcheck  PASSED    00:00:00.714

Attached zip file has a minimal project that is able to reproduce the problem. It has two environments setup; one for an UNO and one for a SAMD (Adafruit Feather M0).

Uno env wil pass cppcheck / SAMD fails.

Steps to Reproduce

  1. Open attached project
  2. Run Inspect or pio check
  3. Error occurs on SAMD

Actual Results

See above

Expected Results

Expect check using cppcheck to complete without failure

If problems with PlatformIO Build System:

The content of platformio.ini:

; PlatformIO Project Configuration File
;
;   Build options: build flags, source filter
;   Upload options: custom upload port, speed and extra flags
;   Library options: dependencies, extra library storages
;   Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html

[env:uno]
platform = atmelavr
board = uno
framework = arduino
check_tool = cppcheck

[env:adafruit_feather_m0]
platform = atmelsam
board = adafruit_feather_m0
framework = arduino
check_tool = cppcheck

Source file to reproduce issue:

/**
 * Blink
 *
 * Turns on an LED on for one second,
 * then off for one second, repeatedly.
 */
#include "Arduino.h"

const int delayTime =1000;

// Set LED_BUILTIN if it is not defined by Arduino framework
// #define LED_BUILTIN 13

void setup()
{
  // initialize LED digital pin as an output.
  pinMode(LED_BUILTIN, OUTPUT);
}

void loop()
{
  // turn the LED on (HIGH is the voltage level)
  digitalWrite(LED_BUILTIN, HIGH);

  // wait for a second
  delay(delayTime);

  // turn the LED off by making the voltage LOW
  digitalWrite(LED_BUILTIN, LOW);

   // wait for a second
  delay(delayTime);
}

Additional info

Test Project:

Test2.tar.gz

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
maxgerhardtcommented, Dec 14, 2021

The fact it can be worked around has been fixed by adding a platformio.ini instruction per https://github.com/platformio/platformio-docs/issues/217 --> https://docs.platformio.org/en/latest/projectconf/section_env_check.html#check-skip-packages.

The fact that code inspection fails has not been fixed yet.

1reaction
maxgerhardtcommented, May 23, 2021

And also the same for any ESP8266 project per community topic

Error: Found a breaking defect ‘syntax error’ in %userprofile%.platformio\packages\toolchain-xtensa\xtensa-lx106-elf\include\c++\4.8.2\bits\random.h:69
Please note: check results might not be valid!
Read more comments on GitHub >

github_iconTop Results From Across the Web

Code inspection fails at 96% - PlatformIO Community
I have a (fairly) complex ESP8266 project (running on an ESP-01 module modified with 4MB flash), but the code inspection fails at 96%....
Read more >
Cppcheck manual
Cppcheck is an analysis tool for C/C++ code. It provides unique code analysis to detect bugs and focuses on detecting undefined behaviour and...
Read more >
Cppcheck inline suppression not working - Stack Overflow
This way: class Foo { // cppcheck-suppress noExplicitConstructor Foo(int foo) { } }; It requires --inline-suppr as command line argument.
Read more >
A Static Analysis Tool for C++ - CodeProject
Having a tool that could serve as an automated Scott Meyers code inspector would go a long way to addressing these issues.
Read more >
"Function X is never used" for shared libraries : CPP-13342
Taw Moto suppressing the inspection is simply wrap the code with next construction: ... because I am the only one using clang-format and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found