Skip to content

Commit d889f96

Browse files
committed
Reenable TOFF=1 when using M569 Cnnn
1 parent 21d8edb commit d889f96

File tree

3 files changed

+30
-14
lines changed

3 files changed

+30
-14
lines changed

src/Movement/StepperDrivers/TMC22xx.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ class TmcDriverState
275275
void UartTmcHandler(); // core of the ISR for this driver
276276

277277
private:
278-
bool SetChopConf(uint32_t newVal);
278+
bool SetChopConf(uint32_t newVal, bool raw = false);
279279
void UpdateRegister(size_t regIndex, uint32_t regVal);
280280
void UpdateChopConfRegister(); // calculate the chopper control register and flag it for sending
281281
void UpdateCurrent();
@@ -547,7 +547,7 @@ bool TmcDriverState::SetRegister(SmartDriverRegister reg, uint32_t regVal)
547547
switch(reg)
548548
{
549549
case SmartDriverRegister::chopperControl:
550-
return SetChopConf(regVal);
550+
return SetChopConf(regVal, true);
551551

552552
case SmartDriverRegister::toff:
553553
return SetChopConf((configuredChopConfReg & ~CHOPCONF_TOFF_MASK) | ((regVal << CHOPCONF_TOFF_SHIFT) & CHOPCONF_TOFF_MASK));
@@ -602,10 +602,16 @@ uint32_t TmcDriverState::GetRegister(SmartDriverRegister reg) const
602602
}
603603

604604
// Set the chopper control register to the settings provided by the user. We allow only the lowest 17 bits to be set.
605-
bool TmcDriverState::SetChopConf(uint32_t newVal)
605+
bool TmcDriverState::SetChopConf(uint32_t newVal, bool raw)
606606
{
607607
const uint32_t offTime = (newVal & CHOPCONF_TOFF_MASK) >> CHOPCONF_TOFF_SHIFT;
608-
if (offTime == 0 || (offTime == 1 && (newVal & CHOPCONF_TBL_MASK) < (2 << CHOPCONF_TBL_SHIFT)))
608+
// TOFF = 0 turns the driver off so it is not allowed unless given via Cnnn parameter.
609+
if (!raw && offTime == 0)
610+
{
611+
return false;
612+
}
613+
// TOFF = 1 is not allowed if TBL = 0.
614+
if (offTime == 1 && (newVal & CHOPCONF_TBL_MASK) < (2 << CHOPCONF_TBL_SHIFT))
609615
{
610616
return false;
611617
}

src/Movement/StepperDrivers/TMC2660.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ class TmcDriverState
210210
uint32_t ReadMicrostepPosition() const { return mstepPosition; }
211211

212212
private:
213-
bool SetChopConf(uint32_t newVal);
213+
bool SetChopConf(uint32_t newVal, bool raw = false);
214214

215215
void ResetLoadRegisters()
216216
{
@@ -419,7 +419,7 @@ bool TmcDriverState::SetRegister(SmartDriverRegister reg, uint32_t regVal)
419419
switch(reg)
420420
{
421421
case SmartDriverRegister::chopperControl:
422-
return SetChopConf(regVal);
422+
return SetChopConf(regVal, true);
423423

424424
case SmartDriverRegister::coolStep:
425425
registers[SmartEnable] = TMC_REG_SMARTEN | (regVal & 0xFFFF);
@@ -482,12 +482,16 @@ uint32_t TmcDriverState::GetRegister(SmartDriverRegister reg) const
482482
}
483483

484484
// Check the new chopper control register, update it and return true if it is legal
485-
bool TmcDriverState::SetChopConf(uint32_t newVal)
485+
bool TmcDriverState::SetChopConf(uint32_t newVal, bool raw)
486486
{
487-
// TOFF = 0 turns the driver off so it is not allowed.
488-
// TOFF = 1 is not allowed if TBL = 0.
489487
const uint32_t toff = (newVal & TMC_CHOPCONF_TOFF_MASK) >> TMC_CHOPCONF_TOFF_SHIFT;
490-
if (toff == 0 || (toff == 1 && ((newVal & TMC_CHOPCONF_TBL_MASK) == 0)))
488+
// TOFF = 0 turns the driver off so it is not allowed unless given via Cnnn parameter.
489+
if (!raw && toff == 0)
490+
{
491+
return false;
492+
}
493+
// TOFF = 1 is not allowed if TBL = 0.
494+
if (toff == 1 && ((newVal & TMC_CHOPCONF_TBL_MASK) == 0))
491495
{
492496
return false;
493497
}

src/Movement/StepperDrivers/TMC51xx.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ class TmcDriverState
290290
void TransferFailed();
291291

292292
private:
293-
bool SetChopConf(uint32_t newVal);
293+
bool SetChopConf(uint32_t newVal, bool raw = false);
294294
void UpdateRegister(size_t regIndex, uint32_t regVal);
295295
void UpdateChopConfRegister(); // calculate the chopper control register and flag it for sending
296296
void UpdateCurrent();
@@ -485,7 +485,7 @@ bool TmcDriverState::SetRegister(SmartDriverRegister reg, uint32_t regVal)
485485
switch(reg)
486486
{
487487
case SmartDriverRegister::chopperControl:
488-
return SetChopConf(regVal);
488+
return SetChopConf(regVal, true);
489489

490490
case SmartDriverRegister::toff:
491491
return SetChopConf((configuredChopConfReg & ~CHOPCONF_TOFF_MASK) | ((regVal << CHOPCONF_TOFF_SHIFT) & CHOPCONF_TOFF_MASK));
@@ -552,10 +552,16 @@ uint32_t TmcDriverState::GetRegister(SmartDriverRegister reg) const
552552
}
553553

554554
// Set the chopper control register to the settings provided by the user. We allow only the lowest 17 bits to be set.
555-
bool TmcDriverState::SetChopConf(uint32_t newVal)
555+
bool TmcDriverState::SetChopConf(uint32_t newVal, bool raw)
556556
{
557557
const uint32_t offTime = (newVal & CHOPCONF_TOFF_MASK) >> CHOPCONF_TOFF_SHIFT;
558-
if (offTime == 0 || (offTime == 1 && (newVal & CHOPCONF_TBL_MASK) < (2 << CHOPCONF_TBL_SHIFT)))
558+
// TOFF = 0 turns the driver off so it is not allowed unless given via Cnnn parameter.
559+
if (!raw && offTime == 0)
560+
{
561+
return false;
562+
}
563+
// TOFF = 1 is not allowed if TBL = 0.
564+
if (offTime == 1 && (newVal & CHOPCONF_TBL_MASK) < (2 << CHOPCONF_TBL_SHIFT))
559565
{
560566
return false;
561567
}

0 commit comments

Comments
 (0)