Skip to main content
Tobe
Senior III
April 22, 2023
Solved

Implementing Arduino into CubeIDE

I have already spent hours trying to get the Arduino library working in my CubeIDE (1.12.0 IDE; latest STM32duino; Firmware F3 1.11.4). I set up all the include paths, and changed the arduino stuff, to point to the CubeIDE generated files.

I had some issues, that the Serial was not declared, but this could be fixxed, when i changed my user_man file to *.cpp. But now it says " undefined reference to `setup' ".

main.c:

/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "main.h"
 
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
 
#include "user_main.h"

user_man.cpp:

#include "user_main.h"
 
#include "stdio.h"
#include "stm32f3xx_nucleo_32.h"
#include <stdbool.h>
 
#include "arduino.h"
 
void setup(){
  
}
 
void loop(){
}

user_main.h:

extern void setup();
extern void loop();

What has to be done in order to make it work?

This topic has been closed for replies.
Tobe
TobeBest answer
Senior III
April 22, 2023

IT FINALLY WORKS! Woohoo!


_legacyfs_online_stmicro_images_0693W00000bid0kQAA.png
_legacyfs_online_stmicro_images_0693W00000bid0VQAQ.png
_legacyfs_online_stmicro_images_0693W00000bid0QQAQ.png
_legacyfs_online_stmicro_images_0693W00000bid0LQAQ.png

6 replies

Tesla DeLorean
Guru
April 22, 2023

Use extern "C" void setup(.. forms to stop it mangling the name

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
Tobe
TobeAuthor
Senior III
April 22, 2023

Then i get this:

../Core/Src/user_main.h:1:8: error: expected identifier or '(' before string constant
1 | extern "C" void setup();
 | ^~~

AScha.3
Super User
April 22, 2023

As I understand, you try running Arduino program in cubeIDE , -- good luck!

​

I also needed a library from Arduino for driving the 4"TFT, but I just made my program in cubeIDE and including the library from Arduino. After some adapting the ​function call and variables name, it's running fine. All is in C .

If you feel a post has answered your question, please click on " Best Answer ".
Tobe
TobeAuthorBest answer
Senior III
April 22, 2023

IT FINALLY WORKS! Woohoo!


_legacyfs_online_stmicro_images_0693W00000bid0kQAA.png
_legacyfs_online_stmicro_images_0693W00000bid0VQAQ.png
_legacyfs_online_stmicro_images_0693W00000bid0QQAQ.png
_legacyfs_online_stmicro_images_0693W00000bid0LQAQ.png

Tobe
TobeAuthor
Senior III
April 22, 2023

That seems to work:

#ifdef __cplusplus
extern "C" {
#endif
 
void setup();
void loop();
 
 
#ifdef __cplusplus
}
#endif

I still got other errors though.

Associate II
March 9, 2024

Can you elaborate on how you get the Arduino vendor to work in CubelDE?