tmc2130: error handling stack overflow fix

pull/76/head
Alex Voinea 2021-07-25 20:59:44 +03:00 committed by DRracer
parent d071a6abf6
commit 364f1bcb0d
2 changed files with 6 additions and 27 deletions

View File

@ -20,8 +20,8 @@ bool TMC2130::Init(const MotorParams &params) {
if (((IOIN >> 24) != 0x11) | !(IOIN & (1 << 6))) ///if the version is incorrect or an always 1 bit is 0 (the supposed SD_MODE pin that doesn't exist on this driver variant) if (((IOIN >> 24) != 0x11) | !(IOIN & (1 << 6))) ///if the version is incorrect or an always 1 bit is 0 (the supposed SD_MODE pin that doesn't exist on this driver variant)
return true; // @todo return some kind of failure return true; // @todo return some kind of failure
///clear reset flag as we are (re)initializing ///clear reset_flag as we are (re)initializing
errorFlags.reset = false; errorFlags.reset_flag = false;
///apply chopper parameters ///apply chopper parameters
uint32_t chopconf = 0; uint32_t chopconf = 0;
@ -110,25 +110,8 @@ void TMC2130::_spi_tx_rx(const MotorParams &params, uint8_t (&pData)[5]) {
} }
void TMC2130::_handle_spi_status(const MotorParams &params, uint8_t status) { void TMC2130::_handle_spi_status(const MotorParams &params, uint8_t status) {
status &= 0x03; errorFlags.reset_flag |= status & (1 << 0);
if (status) { errorFlags.driver_error |= status & (1 << 1);
uint32_t GSTAT = ReadRegister(params, Registers::GSTAT);
if (GSTAT & (1 << 0))
errorFlags.reset |= true;
if (GSTAT & (1 << 1)) {
uint32_t DRV_STATUS = ReadRegister(params, Registers::DRV_STATUS);
if (DRV_STATUS & (1ul << 25))
errorFlags.ot |= true;
if (DRV_STATUS & (1ul << 26))
errorFlags.otpw |= true;
if (DRV_STATUS & (1ul << 27))
errorFlags.s2ga |= true;
if (DRV_STATUS & (1ul << 28))
errorFlags.s2gb |= true;
}
if (GSTAT & (1 << 2))
errorFlags.uv_cp |= true;
}
} }
} // namespace tmc2130 } // namespace tmc2130

View File

@ -36,12 +36,8 @@ class TMC2130 {
MotorMode mode; MotorMode mode;
MotorCurrents currents; MotorCurrents currents;
struct __attribute__((packed)) { struct __attribute__((packed)) {
uint8_t reset : 1; uint8_t reset_flag : 1;
uint8_t uv_cp : 1; uint8_t driver_error : 1;
uint8_t s2ga : 1;
uint8_t s2gb : 1;
uint8_t otpw : 1;
uint8_t ot : 1;
} errorFlags; } errorFlags;
bool enabled = false; bool enabled = false;