2021-03-30 02:46 PM
I'm using an x_nucleo_ihm03a1 powerSTEP01 module. I'm trying to understand the library ST has already made (X-CUBE_SPN3). Using ctrl+leftclick in CubeIDE, im tracing function calls to the files they were declared in. In the main.c file of the library i've traced a function called 'BSP_MotorControl_Move()' to the 'x_nucleo_ihmxxx,c' file. The function then uses a handler to call a function pointer:
motorDrvHandle->Move(deviceId, direction, stepCount);
Tracing the handler again to its decleration of the function pointer, I find this in a file called 'motor.h' (contains all the functions for the motor driver):
/// Function pointer to Move
void (*Move)(uint8_t, motorDir_t, uint32_t );
The problem is I actually cant trace any further with ctrl+left click and so I am unable to understand how this function works at the register level. Does anyone have any guidance as to how I can actually find the origin of the function that this pointer points towards so i can see how the function actually works?
2021-03-30 02:56 PM
Go to the place where it initizes the function table, likely a list of names going in a structure. MOTOR_VTable_t ??
Perhaps try greping the source for the motorDir_t type and the functions using it as a parameter?
2021-03-30 03:21 PM
motorDrvHandle is a structure pointer. Its Move member is the function pointer. To learn the function, you must search the code for Move's assignment. It may initialise it directly, e.g. motorDrvHandle->Move = someFunction, or it may be with motorDrvHandle's initialisation, e.g. motorDrvHandle = &someStructure.
2021-04-22 07:25 AM
Hello @ZHama.1
the above tips were helpful to you to solve the problem?
If yes please "Select as Best" button in the proper answer.
2021-11-08 10:28 PM
I agree that X-CUBE-SPN3 is not simple. Also it is not reentrant! And also problem is X-CUBE-SPN3 use
"union powerstep01_Init_u initDeviceParameters" but SPINFamily use a lot of defines in powerstep01_target_config.h. It is hard to copy from SPINFamily to X-CUBE-SPN3.
@ZHama.1 If you are looking bodies of functions see powerstep01.c
@Cristiana SCARAMEL did you plan to fix SPINFamily ?
2021-11-12 07:29 AM
Hello @dungeonlords789 ,
We do not have in roadmap an update of the SPINFamily.
For the integration of the "powerstep01_target_config.h" into the X-CUBE-SPN3 you replace the struct initialization part in main.c with following code:
#ifdef CURRENT_MODE
/* Initialization parameters for current mode */
union powerstep01_Init_u initDeviceParameters =
{
/* common parameters */
.vm.cp.cmVmSelection = POWERSTEP01_CONF_PARAM_CM_VM_DEVICE_0, // enum powerstep01_CmVm_t
POWERSTEP01_CONF_PARAM_ACC_DEVICE_0, // Acceleration rate in step/s2, range 14.55 to 59590 steps/s^2
POWERSTEP01_CONF_PARAM_DEC_DEVICE_0, // Deceleration rate in step/s2, range 14.55 to 59590 steps/s^2
POWERSTEP01_CONF_PARAM_MAX_SPEED_DEVICE_0, // Maximum speed in step/s, range 15.25 to 15610 steps/s
POWERSTEP01_CONF_PARAM_MIN_SPEED_DEVICE_0, // Minimum speed in step/s, range 0 to 976.3 steps/s
POWERSTEP01_CONF_PARAM_LSPD_BIT_DEVICE_0, // Low speed optimization bit, enum powerstep01_LspdOpt_t
POWERSTEP01_CONF_PARAM_FS_SPD_DEVICE_0, // Full step speed in step/s, range 7.63 to 15625 steps/s
POWERSTEP01_CONF_PARAM_BOOST_MODE_DEVICE_0, // Boost of the amplitude square wave, enum powerstep01_BoostMode_t
281.25, // Overcurrent threshold settings via enum powerstep01_OcdTh_t
POWERSTEP01_CONF_PARAM_STEP_MODE_DEVICE_0, // Step mode settings via enum motorStepMode_t
POWERSTEP01_CONF_PARAM_SYNC_MODE_DEVICE_0, // Synch. Mode settings via enum powerstep01_SyncSel_t
POWERSTEP01_CONF_PARAM_ALARM_EN_DEVICE_0, // Alarm settings via bitmap enum powerstep01_AlarmEn_t
POWERSTEP01_CONF_PARAM_IGATE_DEVICE_0, // Gate sink/source current via enum powerstep01_Igate_t
POWERSTEP01_CONF_PARAM_TBOOST_DEVICE_0, // Duration of the overboost phase during gate turn-off via enum powerstep01_Tboost_t
POWERSTEP01_CONF_PARAM_TCC_DEVICE_0, // Controlled current time via enum powerstep01_Tcc_t
POWERSTEP01_CONF_PARAM_WD_EN_DEVICE_0, // External clock watchdog, enum powerstep01_WdEn_t
POWERSTEP01_CONF_PARAM_TBLANK_DEVICE_0, // Duration of the blanking time via enum powerstep01_TBlank_t
POWERSTEP01_CONF_PARAM_TDT_DEVICE_0, // Duration of the dead time via enum powerstep01_Tdt_t
/* current mode parameters */
POWERSTEP01_CONF_PARAM_TVAL_HOLD_DEVICE_0, // Hold torque in mV, range from 7.8mV to 1000 mV
POWERSTEP01_CONF_PARAM_TVAL_RUN_DEVICE_0, // Running torque in mV, range from 7.8mV to 1000 mV
POWERSTEP01_CONF_PARAM_TVAL_ACC_DEVICE_0, // Acceleration torque in mV, range from 7.8mV to 1000 mV
POWERSTEP01_CONF_PARAM_TVAL_DEC_DEVICE_0, // Deceleration torque in mV, range from 7.8mV to 1000 mV
POWERSTEP01_CONF_PARAM_TOFF_FAST_DEVICE_0, //Maximum fast decay time , enum powerstep01_ToffFast_t
POWERSTEP01_CONF_PARAM_FAST_STEP_DEVICE_0, //Maximum fall step time , enum powerstep01_FastStep_t
POWERSTEP01_CONF_PARAM_TON_MIN_DEVICE_0, // Minimum on-time in us, range 0.5us to 64us
POWERSTEP01_CONF_PARAM_TOFF_MIN_DEVICE_0, // Minimum off-time in us, range 0.5us to 64us
POWERSTEP01_CONF_PARAM_CLOCK_SETTING_DEVICE_0, // Clock setting , enum powerstep01_ConfigOscMgmt_t
POWERSTEP01_CONF_PARAM_SW_MODE_DEVICE_0, // External switch hard stop interrupt mode, enum powerstep01_ConfigSwMode_t
POWERSTEP01_CONF_PARAM_TQ_REG_DEVICE_0, // External torque regulation enabling , enum powerstep01_ConfigEnTqReg_t
POWERSTEP01_CONF_PARAM_VS_COMP_DEVICE_0, // Motor Supply Voltage Compensation enabling , enum powerstep01_ConfigEnVscomp_t
POWERSTEP01_CONF_PARAM_OC_SD_DEVICE_0, // Over current shutwdown enabling, enum powerstep01_ConfigOcSd_t
POWERSTEP01_CONF_PARAM_UVLOVAL_DEVICE_0, // UVLO Threshold via powerstep01_ConfigUvLoVal_t
POWERSTEP01_CONF_PARAM_VCCVAL_DEVICE_0, // VCC Val, enum powerstep01_ConfigVccVal_t
POWERSTEP01_CONF_PARAM_TSW_DEVICE_0, // Switching period, enum powerstep01_ConfigTsw_t
POWERSTEP01_CONF_PARAM_PRED_DEVICE_0, // Predictive current enabling , enum powerstep01_ConfigPredEn_t
};
#endif //CURRENT_MODE
#ifdef VOLTAGE_MODE
/* Initialization parameters for voltage mode */
union powerstep01_Init_u initDeviceParameters =
{
/* common parameters */
.vm.cp.cmVmSelection = POWERSTEP01_CONF_PARAM_CM_VM_DEVICE_0, // enum powerstep01_CmVm_t
POWERSTEP01_CONF_PARAM_ACC_DEVICE_0, // Acceleration rate in step/s2, range 14.55 to 59590 steps/s^2
POWERSTEP01_CONF_PARAM_DEC_DEVICE_0, // Deceleration rate in step/s2, range 14.55 to 59590 steps/s^2
POWERSTEP01_CONF_PARAM_MAX_SPEED_DEVICE_0, // Maximum speed in step/s, range 15.25 to 15610 steps/s
POWERSTEP01_CONF_PARAM_MIN_SPEED_DEVICE_0, // Minimum speed in step/s, range 0 to 976.3 steps/s
POWERSTEP01_CONF_PARAM_LSPD_BIT_DEVICE_0, // Low speed optimization bit, enum powerstep01_LspdOpt_t
POWERSTEP01_CONF_PARAM_FS_SPD_DEVICE_0, // Full step speed in step/s, range 7.63 to 15625 steps/s
POWERSTEP01_CONF_PARAM_BOOST_MODE_DEVICE_0, // Boost of the amplitude square wave, enum powerstep01_BoostMode_t
281.25, // Overcurrent threshold settings via enum powerstep01_OcdTh_t
POWERSTEP01_CONF_PARAM_STEP_MODE_DEVICE_0, // Step mode settings via enum motorStepMode_t
POWERSTEP01_CONF_PARAM_SYNC_MODE_DEVICE_0, // Synch. Mode settings via enum powerstep01_SyncSel_t
POWERSTEP01_CONF_PARAM_ALARM_EN_DEVICE_0, // Alarm settings via bitmap enum powerstep01_AlarmEn_t
POWERSTEP01_CONF_PARAM_IGATE_DEVICE_0, // Gate sink/source current via enum powerstep01_Igate_t
POWERSTEP01_CONF_PARAM_TBOOST_DEVICE_0, // Duration of the overboost phase during gate turn-off via enum powerstep01_Tboost_t
POWERSTEP01_CONF_PARAM_TCC_DEVICE_0, // Controlled current time via enum powerstep01_Tcc_t
POWERSTEP01_CONF_PARAM_WD_EN_DEVICE_0, // External clock watchdog, enum powerstep01_WdEn_t
POWERSTEP01_CONF_PARAM_TBLANK_DEVICE_0, // Duration of the blanking time via enum powerstep01_TBlank_t
POWERSTEP01_CONF_PARAM_TDT_DEVICE_0, // Duration of the dead time via enum powerstep01_Tdt_t
/* voltage mode parameters */
POWERSTEP01_CONF_PARAM_KVAL_HOLD_DEVICE_0, // Hold duty cycle (torque) in %, range 0 to 99.6%
POWERSTEP01_CONF_PARAM_KVAL_RUN_DEVICE_0, // Run duty cycle (torque) in %, range 0 to 99.6%
POWERSTEP01_CONF_PARAM_KVAL_ACC_DEVICE_0, // Acceleration duty cycle (torque) in %, range 0 to 99.6%
POWERSTEP01_CONF_PARAM_KVAL_DEC_DEVICE_0, // Deceleration duty cycle (torque) in %, range 0 to 99.6%
POWERSTEP01_CONF_PARAM_INT_SPD_DEVICE_0, // Intersect speed settings for BEMF compensation in steps/s, range 0 to 3906 steps/s
POWERSTEP01_CONF_PARAM_ST_SLP_DEVICE_0, // BEMF start slope settings for BEMF compensation in % step/s, range 0 to 0.4% s/step
POWERSTEP01_CONF_PARAM_FN_SLP_ACC_DEVICE_0, // BEMF final acc slope settings for BEMF compensation in % step/s, range 0 to 0.4% s/step
POWERSTEP01_CONF_PARAM_FN_SLP_DEC_DEVICE_0, // BEMF final dec slope settings for BEMF compensation in % step/s, range 0 to 0.4% s/step
POWERSTEP01_CONF_PARAM_K_THERM_DEVICE_0, // Thermal compensation param, range 1 to 1.46875
POWERSTEP01_CONF_PARAM_STALL_TH_DEVICE_0, // Stall threshold settings in mV, range 31.25mV to 1000mV
POWERSTEP01_CONF_PARAM_CLOCK_SETTING_DEVICE_0, // Clock setting , enum powerstep01_ConfigOscMgmt_t
POWERSTEP01_CONF_PARAM_SW_MODE_DEVICE_0, // External switch hard stop interrupt mode, enum powerstep01_ConfigSwMode_t
POWERSTEP01_CONF_PARAM_VS_COMP_DEVICE_0, // Motor Supply Voltage Compensation enabling , enum powerstep01_ConfigEnVscomp_t
POWERSTEP01_CONF_PARAM_OC_SD_DEVICE_0, // Over current shutwdown enabling, enum powerstep01_ConfigOcSd_t
POWERSTEP01_CONF_PARAM_UVLOVAL_DEVICE_0, // UVLO Threshold via powerstep01_ConfigUvLoVal_t
POWERSTEP01_CONF_PARAM_VCCVAL_DEVICE_0, // VCC Val, enum powerstep01_ConfigVccVal_t
POWERSTEP01_CONF_PARAM_PWM_DIV_DEVICE_0, // PWM Frequency Integer division, enum powerstep01_ConfigFPwmInt_t
POWERSTEP01_CONF_PARAM_PWM_MUL_DEVICE_0, // PWM Frequency Integer Multiplier, enum powerstep01_ConfigFPwmDec_t
};
#endif //VOLTAGE_MODE
Then you only need to include the "powerstep01_target_config.h"
#include "powerstep01_target_config.h"
The mapping is quite straight forward with the only exception of the Overcurrent Threshold that is in float format in the X-CUBE-SPN3 and enumerated in the SPINFamily config file.