1
0
mirror of https://github.com/bdring/Grbl_Esp32.git synced 2025-09-02 10:53:01 +02:00

- Fixed initialization bug in trinamic drivers

- Added better error handling for validation of pin changes
This commit is contained in:
Stefan de Bruijn
2020-12-17 21:52:22 +01:00
parent e0e9fcc3ab
commit 3f73f5214b
4 changed files with 24 additions and 7 deletions

View File

@@ -202,6 +202,14 @@ namespace Motors {
*/
void TrinamicDriver::read_settings() {
// When 'test' is called and no actual trinamic is there, _has_errors will evaluate to 'true'. The
// result of that is that the check below will fail. And the result of that is that the step/dir pin
// is not initialized if we don't do it here. Unstep actually uses that pin -- and then you will get
// an assertion for using a pin that's not initialized.
//
// So... I moved init_step_dir_pins here, which basically solves that.
init_step_dir_pins();
if (_has_errors) {
return;
}
@@ -218,8 +226,6 @@ namespace Motors {
}
tmcstepper->microsteps(axis_settings[_axis_index]->microsteps->get());
tmcstepper->rms_current(run_i_ma, hold_i_percent);
init_step_dir_pins();
}
bool TrinamicDriver::set_homing_mode(bool isHoming) {

View File

@@ -165,7 +165,17 @@ Pin Pin::create(const String& str) {
bool Pin::validate(const String& str) {
Pins::PinDetail* pinImplementation;
auto valid = parse(str, pinImplementation);
bool valid = false;
try {
valid = parse(str, pinImplementation);
} catch (const AssertionFailed& e) {
// If an assertion happens, it's definitely invalid.
#ifdef ESP32
grbl_msg_sendf(CLIENT_ALL, MsgLevel::Warning, "Validation for pin spec %s failed: %s", str.c_str(), e.error.c_str());
#endif
valid = false;
}
if (pinImplementation) {
delete pinImplementation;
}

View File

@@ -23,7 +23,7 @@ AssertionFailed AssertionFailed::create(const char* condition, const char* msg,
st += " at: ";
st += esp_backtrace_print(10);
return AssertionFailed(st);
return AssertionFailed(st, tmp);
}
#else

View File

@@ -6,11 +6,12 @@
class AssertionFailed {
public:
String stackTrace;
String error;
AssertionFailed(String st) : stackTrace(st) {}
AssertionFailed(String st, String err) : stackTrace(st), error(err) {}
static AssertionFailed create(const char* condition) {
return create(condition, "Assertion failed");
return create(condition, "Unknown error (assertion failed).");
}
static AssertionFailed create(const char* condition, const char* msg, ...);
@@ -24,7 +25,7 @@ public:
String stackTrace;
static std::exception create(const char* condition) {
return create(condition, "Assertion failed");
return create(condition, "Unknown error (assertion failed).");
}
static std::exception create(const char* condition, const char* msg, ...);
};