- This topic has 3 replies, 2 voices, and was last updated 8 years, 3 months ago by .
Viewing 4 posts - 1 through 4 (of 4 total)
Viewing 4 posts - 1 through 4 (of 4 total)
- You must be logged in to reply to this topic.
Home › Forums › Mastering STM32 book support forum › Mixing C and C++
Hello. I just wanted to ask, how do i used the C HAL functions in a C++ class? And generally how do i mix the two languages together?
Hi,
I’ve no direct experience with programming in C++ with the STM32 platform, but I cannot see obstacles to this. The HAL is ready to be compiled with G++ (the extern “C” declarations in headers file are there for this reason), and you just have to rename your main.c to main.cpp to start programming in C++.
You can obviously use HAL routine from C++ methods unless them are reentrant (that is, don’t access concurrently to HAL resources).
At the expense of code size 😉
This worked very well. You just need to define the processor macro (example: STM32F103xB) in the Cross ARM C++ Compiler->Preprocessor and in the Cross ARM C Compiler->Preprocessor. Thank you for the quick response 🙂
One more thing, i had problems with the line HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0); It was compiling correctly, but the Code Analysis from Eclipse was saying something about Invalid arguments. I just changed it to HAL_NVIC_SetPriority((IRQn_Type)SysTick_IRQn, 0, 0); and now it works fine.