Loading...
 

STM32MP1 support available in SW4STM32

   With System Workbench for Linux, Embedded Linux on the STM32MP1 family of MPUs from ST was never as simple to build and maintain, even for newcomers in the Linux world.
And, if you install System Workbench for Linux in System Workbench for STM32 you can seamlessly develop and debug asymmetric applications running partly on Linux, partly on the Cortex-M4; you can download a short video showcasing this on the ac6-tools website (registration required).

System Workbench for STM32


You are viewing a reply to Converting to C++  

Converting to C++

France

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 prototype
void 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 read
HAL_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.

The problem is that main.c is a link to a file located elsewhere, while the beta.h file you’ve created is in the User directory... Thus
#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