cancel
Showing results for 
Search instead for 
Did you mean: 

Implementing Arduino into CubeIDE

Tobe
Senior III

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?

1 ACCEPTED SOLUTION

Accepted Solutions

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

View solution in original post

6 REPLIES 6

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

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

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
Chief II

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 "Accept as Solution".
Tobe
Senior III

That seems to work:

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

I still got other errors though.

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

ChenJingtai
Associate

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