This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TMS320F280037: Universal motorcontrol lab code casts away the volatile on MOTOR_Vars_t objects

Part Number: TMS320F280037

Tool/software:

I am running MISRA 2012 compliance on a motor project we are doing and have found that the code provided as example in the motorcontrolsdk seems to violate MISRA 11.8.  For example:

motorVars_M1 is defined as volatile MOTOR_Vars_t motorVars_M1; and declared as extern volatile MOTOR_Vars_t motorVars_M1;

But when this variable is accessed in motor1_drive.c is always done like this: 

MOTOR_Vars_t *obj = (MOTOR_Vars_t *)handle;


This cast effectively ignores/removes the 'volatile' from the newly created pointer which is a MISRA 11.8 violation.  I am wondering why the code is written in this way?  The C2000 compiler seems to be treating the original object as volatile in some instances, or not in other instances, depending on the optimization level and the code in question; this makes bringing the code into MISRA compliance much more difficult - or maybe I am missing something?

thanks,
Jeremy
  • Hi Jeremy,

    MISRA requirements were not considered when writing this reference code solution. It's the user's responsibility to meet their quality requirements themselves and our SW solutions are just intended for reference / evaluation purposes.

    Best,

    Kevin