I set all the pins in CubeMx,
added a class to a .h file
renamed main.c to main.cpp
included the .h
and "class" is undefined.
is there a switch in Cube for this ?
using an '091
Needs to be a .CPP file that does the including, or you need to add the --cpp to enable compiler support. ie compile .C as C++
Hey it worked.
Project options c/c++
in Misc Controls
One has to watch for C++ name mangling, functions you wish to export to the vector table, for example, need extern "C" prefix so they bind properly in the linker, rather than the WEAK ones. The SysTick Handler being one to watch in CubeMX/HAL
extern "C" void USART1_IRQHandler(void)
I am a new C programmer
do you mean in the .cpp file :
and in the .h file:
extern "C" void USART1_IRQHandler(void);
I am totally unsure about the syntax/implementation of your advice.
Yes, for functions that must be called from C or assembler, and when compiled as C++, you must use this syntax so the name is exported cleanly, otherwise it will be mangled. The name mangling process used by the compiler causes a unique name based on the parameters input to and returned by a function.
Name mangling - Wikipedia
Name Mangling and extern "C" in C++ - GeeksforGeeks
In the STM32 case what would happen is that the weak/default functions would get linked into the vector table if the functions you compiled as C++ remained mangled. The result would be that your interrupts would go into the Default_Handler and get stuck in a while(1) loop, instead of the IRQHandler body code you supplied.
Retrieving data ...