cancel
Showing results for 
Search instead for 
Did you mean: 

MCSDK compilation error

Ofer
Senior

hi,

I created a project by the MCSDK, i tried running it as a C++ project, but im getting an error compilation that i cant solve:

 

../../MCSDK_v6.4.2-Full/MotorControl/MCSDK/MCLib/Any/Inc/revup_ctrl.h: In function 'void RUC_Stop(RevUpCtrl_Handle_t*)':

../../Inc/mc_type.h:77:32: error: invalid conversion from 'void*' to 'RevUpCtrl_PhaseParams_t*' [-fpermissive]

77 | #define MC_NULL (void *)(0x0)

| ^

| |

| void*

 

 

it seems that there is a wrong casting issue.

I tried to solve it in some fifferent wauys like:

pHandle->pCurrentPhaseParams = (RevUpCtrl_PhaseParams_t*)(malloc(MC_NULL));

or

pHandle->pCurrentPhaseParams = static_cast<RevUpCtrl_PhaseParams_t *>malloc(sizeof(MC_NULL));

 

but its not solving the issue.

but when i tried to delete this line it keeps having the same error !!!!!!

what could be the problem

10 REPLIES 10
mfgkw
Senior III

> but when i tried to delete this line it keeps having the same error !!!!!!

 

When you remove the line and the error remains then the problem will be somewhere else.

Maybe the line(s) before.

 

You should provide some more info...

this is the function which the error happen inside of it:

at the line:

pHandle->pCurrentPhaseParams = MC_NULL;

/**

* @brief Allow to exit from Rev-Up process at the current rotor speed.

* @PAram pHandle: Pointer on Handle structure of RevUp controller.

*/

static inline void RUC_Stop(RevUpCtrl_Handle_t *pHandle)

{

#ifdef NULL_PTR_CHECK_REV_UP_CTL

if (MC_NULL == pHandle)

{

/* Nothing to do */

}

else

{

#endif

VirtualSpeedSensor_Handle_t *pVSS = pHandle->pVSS;

pHandle->pCurrentPhaseParams = MC_NULL;

pHandle->hPhaseRemainingTicks = 0U;

VSS_SetMecAcceleration(pVSS, SPD_GetAvrgMecSpeedUnit(&pVSS->_Super), 0U);

#ifdef NULL_PTR_CHECK_REV_UP_CTL

}

#endif

 

mfgkw
Senior III

Maybe it helps to change the line to:

pHandle->pCurrentPhaseParams = (RevUpCtrl_PhaseParams_t *)MC_NULL;
mfgkw
Senior III

A note on this:  The correct way to use a null ptr in C++ is null_ptr.

 

In C NULL is defined like your MC_NULL, e.g. as ((void*)0).

In C++ implicit conversion from void* to another pointer is not allowed and because of this NULL is not a pointer, but an int 0. Your definition of MC_NULL is still void*, which causes your problem.

 

I don't know if you can change the definition of MC_NULL. If yes, you can change it like this:

#ifdef __cplusplus
#define MC_NULL null_ptr
#else
#define MC_NULL ((void*)0)
#endif // def __cplusplus

After this you can write things like  pHandle->pCurrentPhaseParams = MC_NULL; in C++ (and in C).

 

If you can not change MC_NULL you can use pHandle->pCurrentPhaseParams = null_ptr; or define an additional MC_NULL_PP as null_ptr and use it in your C++ code like pHandle->pCurrentPhaseParams = MC_NULL_PP;

thank you for your answers but it seems a much bigger problem.

I got this code generated by the MCSDK for motor cntrol, and any change im doing at this code

doesnt change the compilation results. i tried to clean the project, but it keeps happening

In C++, the correct keyword is nullptr (not null_ptr).

It looks like the MCSDK does not support C++ as is, so the easiest way to deal with it is just using plain C for related parts of the program. People who aren't sure how to combine C++ and C files in one app, are invited to revise their C++ classes records. (spoiler: easier than you think).

The main issue is that the error cant be fixed by te user.

The generated code disable any attemp to fix it so the project will be compiled by g++ compilation.

Its seems as a simple fix that ST should do.

Are the generated source files .c or .cpp ?

 

the MCSDK generates .c files