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

is pio working? #77

Closed
camelator opened this issue Jul 8, 2023 · 2 comments
Closed

is pio working? #77

camelator opened this issue Jul 8, 2023 · 2 comments

Comments

@camelator
Copy link

I just created a new project following the instructions here:
https://crates.io/crates/cargo-pio

my plateform.ini file is the following one, and the compilation fails with this error message:
/home/christian/.platformio/packages/toolchain-gccarmnoneeabi/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld: .pio/build/debug/libFrameworkArduino.a(main.cpp.o): in function main': /home/christian/.platformio/packages/framework-arduinoststm32/cores/arduino/main.cpp:52: undefined reference to setup'
/home/christian/.platformio/packages/toolchain-gccarmnoneeabi/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld: /home/christian/.platformio/packages/framework-arduinoststm32/cores/arduino/main.cpp:58: undefined reference to `loop'
collect2: error: ld returned 1 exit status
*** [.pio/build/debug/firmware.elf] Error 1

but the function is found in file main.cpp and lib.rs:

//
// Arduino main stub file. Calls into Rust.
//

extern "C" void arduino_setup();
extern "C" void arduino_loop();

void setup() {
arduino_setup();
}

void loop() {
arduino_loop();
}

lib.rs:
// Remove if STD is supported for your platform and you plan to use it
#![no_std]

// Remove if STD is supported for your platform and you plan to use it
#[panic_handler]
fn panic(_info: &core::panic::PanicInfo) -> ! {
loop {}
}

//
// Entry points
//

#[no_mangle]
extern "C" fn arduino_setup() {
}

#[no_mangle]
extern "C" fn arduino_loop() {
}

; PlatformIO Project Configuration File
;
; Please visit documentation for options and examples
; https://docs.platformio.org/page/projectconf.html
[platformio]
default_envs = debug

[env]
extra_scripts = pre:platformio.git.py, pre:platformio.patch.py, platformio.cargo.py
board = genericSTM32F410C8
platform = ststm32
framework = arduino
rust_lib = test_rust
rust_target = thumbv7em-none-eabihf

[env:debug]
build_type = debug

[env:release]
build_type = release

@camelator
Copy link
Author

camelator commented Jul 8, 2023

ok... Found the issue:
main.cpp is not complete:
#include <Arduino.h> is required at the beginning of the file.
Then compilation works like a charm.

ivmarkov added a commit that referenced this issue Jul 9, 2023
@ivmarkov
Copy link
Collaborator

ivmarkov commented Jul 9, 2023

I've added the #include <Arduino.h> statement. The reason why it is necessary is because the Arduino framework for some MCUs have setup/loop defined as "C" functions, while for other frameworks, these are defined as "C++" functions. Hence the linkage errors.

@ivmarkov ivmarkov closed this as completed Jul 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants