Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

First project for STM32 with HAL in C++

Tags:

c++

hal

stm32

I would like to create a project for STM32 with HAL in C++. Unfortunately, CubeMX supports only projects in C. However, HAL support C++.

I have created a project in CubeMX and I was trying to import it to any of the IDEs above but without any success because it is imported as a C project. So it doesn't look like a good solution.

Also, I have tried creating a C++ project in the mentioned IDE and adding to it files from CubeMX. It seems to be more logic but I can't do it in the right way because my configuration is still wrong.

Could anyone explain me how should I configure new C++ projects in Eclipse or Atollic TrueSTUDIO in order to use HAL?

like image 570
unitatem Avatar asked Feb 09 '16 09:02

unitatem


People also ask

How do I start a STM32 project?

To start a new project, go to [File]>[New]>[STM32 Project].

Can I use C++ in STM32?

You should be ready to build your STM32 project in C++ with all of the object-oriented programming you so desire. Please note that you can generally call C functions from within a C++ program and vice versa. You will need to add extern “C” to your functions, which is detailed in this article.

What is Hal library STM32?

The STM32 Hardware Abstraction Layer (HAL) provides a simple, generic multi-instance set of APIs (application programming interfaces) to interact with the upper layers like the user application, libraries and stacks.

Does STM32CubeIDE include STM32CubeMX?

One of the distinguishing features of STM32CubeIDE is its integration of STM32CubeMX. Developers can select their board or microcontroller and start a project after configuring the pinout and clock tree.


1 Answers

there is very simple way to build a cpp project in stm32cubeide

  1. after making new stm32 project check the c++ box
  2. do the initialize
  3. compile the code in main folder
  4. press right click and select source folder
  5. put your cpp file in it
  6. for call this cpp functions in main.c in cpp file make a simple function like main2()
  7. that you call it from main.c now you can use cpp function through main2() function
like image 187
ali sa Avatar answered Oct 13 '22 03:10

ali sa