![]() Void EventLoopCpp() // Cpp function to call into main event loop This round about way of calling the C++ EventLoop() function is needed since main.c cannot call directly into a C++ function. main.c will call into the C version and the C version will call into the C++ version. The extern “C” block allows the creation of C code embedded within a C++ file. Within EventLoop.hpp, create a C and C++ version of the EventLoop() function as shown below. Create a new header file named “EventLoop.hpp” and a new source file named “EventLoop.cpp”. Since the HAL generates a main.c file, we need to call into a C++ function in order to leverage C++ features. ![]() ![]() The “event loop” will act as our C++ entry point when mixing C++ with STM32. This is the GPIO pin we will wrap into our C++ project. Note that this is based on an older version of the tool but should still apply.Īs shown in the GPIO view above, The B-L475E-IOT01A defines the on board green LED as GPIO PB14 named, LED2. The following link gives a more in depth exploration of the. This is where any peripherals that will be used in the project are configured.įor this tutorial, we will be looking at the GPIO view, as shown above, and the Timer view. ioc file should automatically open at this point. STM32CubeIDE will ask if you would like to initialize all peripherals as default and generate, click yes. Next, be sure to click “C++” as the targeted language, “Executable” as the binary type and “STM32Cube” as the project type. Name the project and place it in the desired workspace location. Search the specific development kit or processor that will be used for the project and click next. Within STM32CubeIDE, click file->new->STM32 Project. I will be completing this tutorial with the STM32L475, specifically the B-L475E-IOT01A development kit, but the same principles should apply to any STM32 board capable of leveraging the HAL.įirst, open a new project and generate the HAL for whatever peripherals that will be used in the project. All of the code used in this tutorial can be found in the following GitHub repository, stm32-hal-with-cpp. After this, I will give a brief outline of interrupt handling for Timer Modules and UARTs/SPI using the HAL in C++. Then a C++ GPIO wrapper class is created in order to control the GPIO pins through the HAL from the C++ event loop. In order to do this, a “C++ event loop” is created which will act as the C++ entry point called from main.c. This post is one of the most comprehensive tutorials showing how to mix C++ with STM32 HAL.Īt a high level, this tutorial shows how to control the HAL GPIOs and Timers from C++. What if you want to use C++ in a project? C++ is becoming more popular in embedded environments as memory gets larger / cheaper, programs get more complicated and code re-use is essential. Using the HAL can create bloat, give a false sense of understanding the hardware and only generates embedded C code. The STM32 HAL can be a very useful tool but there are also downsides. The HAL can be thought of as a highly abstracted library which is almost universal between STM32 processors. The HAL is part of the STM32CubeIDE tool set which allows users to auto-generate code for various STM32 peripherals. The STM32 HAL (Hardware Abstraction Layer) speeds up development cycles, makes switching between STM32 processors a breeze and has a huge support community.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |