Converting to C++
Hi Richard,
The problem is that, if you are compiling C++ code, you must be careful about argument types. In your code you try to call a function having prototypevoid HAL_GPIO_WritePin(GPIO_TypeDef* GPIOx, int GPIO_Pin,int PinState);while the effective function is
void HAL_GPIO_WritePin(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, GPIO_PinState PinState);.
The second parameter can be converted from int to uint16_t without any problem, especially as it is a constant; however the C++ compiler can’t convert an int to an enum (while the C compiler can). This is one of the few differences between C and C++.
You should then correctly use the enum constants each time a parameter is an enum; for example you should correct your code to readHAL_GPIO_WritePin(GPIOD,GPIO_PIN_2,GPIO_PIN_SET);
Regarding the include of beta.h, this is a bit more tricky and is related to th eway CubeMX generates the System Workbench project.
#include "beta.h"when written in main.c will search in the directory where main.c is located (out of the project...) but not where it seems to be, that is in User...
You must then add ${ProjDirPath}/Applications/User to the search path for the compiler, in project >> Properties >> C/C++ General >> Paths and Symbols >> Includes; don’t forget to create the path for all languages and all configurations.
By the way, how did you rename main.c in main.cpp? the straightforward way of doing so will usually not work correctly; the best way is to create a new file, named main.cpp, copy the content of main.c in it then delete main.c.However, in this case, you can’t re-regenerate your project code under CubeMX if ever you have to change pin assignments or device initialization.
I would then advise you to keep main.c in C, just adding a few function calls in it (in the user code areas so they will not be overwritten by CubeMX) and code them in C++.
Bernard