Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Core creates main.cpp file for STM8 Arduino core which needs main.c #3872

Closed
1 task done
maxgerhardt opened this issue Mar 6, 2021 · 0 comments
Closed
1 task done

Comments

@maxgerhardt
Copy link
Contributor

What kind of issue is this?

  • PlatformIO Core.
    If you’ve found a bug, please provide an information below.

You can erase any parts of this template not applicable to your Issue.


Configuration

Operating system: Win10 x64

PlatformIO Version (platformio --version): version 5.1.1a3

Description of problem

When a new project for any STM8 board with the Arduino framework is created, the PlatformIO core logic at

def _generate_project_main(project_dir, framework):
main_content = None
if framework == "arduino":
main_content = "\n".join(
[
"#include <Arduino.h>",
"",
"void setup() {",
" // put your setup code here, to run once:",
"}",
"",
"void loop() {",
" // put your main code here, to run repeatedly:",
"}",
"",
]
)
elif framework == "mbed":
main_content = "\n".join(
[
"#include <mbed.h>",
"",
"int main() {",
"",
" // put your setup code here, to run once:",
"",
" while(1) {",
" // put your main code here, to run repeatedly:",
" }",
"}",
"",
]
)
if not main_content:
return project_dir
with fs.cd(project_dir):
config = ProjectConfig()
src_dir = config.get_optional_dir("src")
main_path = os.path.join(src_dir, "main.cpp")

will always create a src/main.cpp file. This however is wrong since for the STM8, the implementation is written in C and users must also use C files (The SDCC compiler does not support C++). All the examples use .c files.

Refer to topic https://community.platformio.org/t/unable-to-compile-new-created-project-for-stm8s-board/19766 and platformio/platform-ststm8#21 (comment)

Maybe this change is also needed in other platforms. Besides STM8 I can't think of other C-only Arduino core implementations (Intel 8080 doesn't have a core)

Steps to Reproduce

  1. Open PlatformIO Home
  2. Create new project
  3. Select e.g. "sduino UNO" as board and "Arduino" as framework
  4. Create project

Actual Results

A src/main.cpp file with template code is generated and compilation fails because the it attempts to use the system's CXX / C++ compiler.

Expected Results

A src/main.c file is generated.

Due to a quirk in the SDCC compiler however, a semantically empty sketch fails to link, so a linking error after that is expected.. maybe a different template can be used there.

If problems with PlatformIO Build System:

-/-

Additional info

-/-

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

No branches or pull requests

2 participants