diff --git a/components/step_motor_ctrl_module/step_motor_ctrl_module.cpp b/components/step_motor_ctrl_module/step_motor_ctrl_module.cpp index aa0ef6b..90d6cef 100644 --- a/components/step_motor_ctrl_module/step_motor_ctrl_module.cpp +++ b/components/step_motor_ctrl_module/step_motor_ctrl_module.cpp @@ -357,9 +357,8 @@ void StepMotorCtrlModule::dump(TMC4361AMotorEventState_t val) { ZLOGI(TAG, "RST_EV : %d", val.RST_EV); } -void StepMotorCtrlModule::setErrorFlag(int32_t ecode, uint32_t motorStatue) { +void StepMotorCtrlModule::setErrorFlag(int32_t ecode) { creg.module_errorcode = ecode; - // m_state.motorStatus = motorStatue; } bool StepMotorCtrlModule::check_when_run() { @@ -375,16 +374,16 @@ bool StepMotorCtrlModule::check_when_run() { auto devStatus = tmc5130->getDevStatus(); if (state.reset) { ZLOGE(TAG, "motor reset when run"); - setErrorFlag(err::kstep_motor_subic_reset, (*(uint32_t*)&devStatus)); + setErrorFlag(err::kstep_motor_subic_reset); return false; } else if (state.uv_cp) { ZLOGE(TAG, "motor uv_cp when run"); dumpTMC5130Status(&devStatus); - setErrorFlag(err::kstep_motor_uv_cp, (*(uint32_t*)&devStatus)); + setErrorFlag(err::kstep_motor_uv_cp); return false; } else if (state.drv_err) { ZLOGE(TAG, "motor drv_err when run"); - setErrorFlag(err::kstep_motor_drv_err, (*(uint32_t*)&devStatus)); + setErrorFlag(err::kstep_motor_drv_err); dumpTMC5130Status(&devStatus); return false; } @@ -428,7 +427,7 @@ bool StepMotorCtrlModule::exec_move_to_io_task(int32_t ioindex, int32_t directio // 失败返回 if (!xreach_io) { ZLOGE(TAG, "x reach io failed"); - setErrorFlag(err::kstep_motor_not_found_zero_point, 0); + setErrorFlag(err::kstep_motor_not_found_zero_point); return false; } } @@ -457,7 +456,7 @@ bool StepMotorCtrlModule::exec_move_to_io_task(int32_t ioindex, int32_t directio if (!reach_edge) { ZLOGE(TAG, "leave away zero failed"); - setErrorFlag(err::kstep_motor_not_found_point_edge, 0); + setErrorFlag(err::kstep_motor_not_found_point_edge); return false; } } @@ -486,7 +485,7 @@ bool StepMotorCtrlModule::exec_move_to_io_task(int32_t ioindex, int32_t directio if (!reach_edge) { ZLOGE(TAG, " bak to gpio trigger edge fail"); - setErrorFlag(err::kstep_motor_not_found_point_edge, 0); + setErrorFlag(err::kstep_motor_not_found_point_edge); return false; } } diff --git a/components/step_motor_ctrl_module/step_motor_ctrl_module.hpp b/components/step_motor_ctrl_module/step_motor_ctrl_module.hpp index 7da3094..2123fb2 100644 --- a/components/step_motor_ctrl_module/step_motor_ctrl_module.hpp +++ b/components/step_motor_ctrl_module/step_motor_ctrl_module.hpp @@ -129,7 +129,7 @@ class StepMotorCtrlModule : public ZIModule, public ZIStepMotor { private: void dumpTMC5130Status(TMC51X0::DevStatusReg_t* status); - void setErrorFlag(int32_t ecode, uint32_t motorStatue); + void setErrorFlag(int32_t ecode); void dump(TMC2160MotorDriverStatus_t val); void dump(TMC4361AMotorStatus_t val); diff --git a/components/tmc/ic/ztmc5130.hpp b/components/tmc/ic/ztmc5130.hpp index bc66b10..f0bea68 100644 --- a/components/tmc/ic/ztmc5130.hpp +++ b/components/tmc/ic/ztmc5130.hpp @@ -3,6 +3,7 @@ #include #include #include +#include #include "../basic/tmc_ic_interface.hpp" #include "sdk/os/zos.hpp" @@ -149,12 +150,16 @@ class TMC51X0 : public IStepperMotor { DevStatusReg_t getDevStatus() { // R 读后不清 static_assert(sizeof(DevStatusReg_t) == 4); uint32_t value = readInt(TMC5130_DRVSTATUS); - return *(DevStatusReg_t *)&value; + DevStatusReg_t val; + memcpy(&val, &value, sizeof(DevStatusReg_t)); + return val; } GState_t getGState() { // R+C 读后自动清除 static_assert(sizeof(GState_t) == 4); uint32_t value = readInt(TMC5130_GSTAT); - return *(GState_t *)&value; + GState_t val; + memcpy(&val, &value, sizeof(GState_t)); + return val; } bool isTMC5130();