diff --git a/changelog.md b/changelog.md index 5cca9d8..3fddbc6 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,35 @@ ## grblHAL changelog +Build 20250120 + +Core: + +Added `$SDS` command for outputting **S**tepper **D**river **S**tatus. +If not available an error is returned, if no driver errors/warnings then just `ok` else one or two status lines followed by `ok`: + +`[MOTORWARNING:{,}]` and/or +`[MOTORFAULT:{,}]` + +The first set of `` is for the primary drivers and the second for any secondary \(ganged\) drivers. + +Drivers: + +* ESP32: fixed board map for Fysetc E4. Ref discussion [#136](https://github.com/grblHAL/ESP32/discussions/136). + +* STM32F4xx: added tentative support for stepper driver status data for SuperLongBoard EXT, untested! + +Plugins: + +* SD card: changed status/error code retured when attempting to access card when no card is mounted to `64`. + +* Trinamic: added initial support for stepper driver status data that can be used for the `$SDS` command. +Currently fault status is returned for failure to initialize drivers and warning for overtemperature pre warning \(OTPW\). +OTPW status is only checked for on `M122` report commands or if driver polling is enabled. +Changed initialization sequence to check all drivers instead of exiting on first failure in order to provide per driver data for `$SDS`. +Fixed copy/paste error for `M913` command. Ref. discussion [#107](https://github.com/grblHAL/ESP32/discussions/107#discussioncomment-11886197). + +--- + Build 20250118 Core: diff --git a/crossbar.h b/crossbar.h index 2bfc9e5..e0e1843 100644 --- a/crossbar.h +++ b/crossbar.h @@ -719,6 +719,21 @@ static inline uint8_t xbar_fault_pin_to_axis (pin_function_t fn) return fn >= Input_MotorFaultX && fn <= Input_MotorFaultV ? fn - Input_MotorFaultX : (fn >= Input_MotorFaultX_2 && fn <= Input_MotorFaultZ_2 ? fn - Input_MotorFaultX_2 : 0); } +static inline stepper_state_t xbar_stepper_state_set (stepper_state_t *state, uint8_t axis, bool b) +{ + if(b) + state->details.b.bits |= bit(axis); + else + state->details.a.bits |= bit(axis); + + return *state; +} + +static inline bool xbar_stepper_state_get (stepper_state_t state, uint8_t axis, bool b) +{ + return bit_istrue(b ? state.details.b.bits : state.details.a.bits, bit(axis)); +} + void xbar_set_homing_source (void); limit_signals_t xbar_get_homing_source (void); limit_signals_t xbar_get_homing_source_from_cycle (axes_signals_t homing_cycle); diff --git a/errors.h b/errors.h index dd42e16..00c015c 100644 --- a/errors.h +++ b/errors.h @@ -88,12 +88,11 @@ typedef enum { Status_GCodeCoordSystemLocked = 56, Status_UnexpectedDemarcation = 57, -// Some error codes as defined in bdring's ESP32 port Status_SDMountError = 60, Status_SDReadError = 61, Status_SDFailedOpenDir = 62, Status_SDDirNotFound = 63, - Status_SDFileEmpty = 64, + Status_SDNotMounted = 64, Status_BTInitError = 70, diff --git a/gcode.c b/gcode.c index ac1561f..916d8ed 100644 --- a/gcode.c +++ b/gcode.c @@ -1362,7 +1362,7 @@ status_code_t gc_execute_block (char *block) case 63: case 64: case 65: - if(hal.port.digital_out == NULL || hal.port.num_digital_out == 0) + if(ioports_unclaimed(Port_Digital, Port_Output) == 0) FAIL(Status_GcodeUnsupportedCommand); // [Unsupported M command] word_bit.modal_group.M5 = On; port_command = (io_mcode_t)int_value; @@ -1936,7 +1936,7 @@ status_code_t gc_execute_block (char *block) FAIL(Status_GcodeValueWordMissing); if(gc_block.values.p < 0.0f) FAIL(Status_NegativeValue); - if((uint32_t)gc_block.values.p + 1 > hal.port.num_digital_out) + if((uint32_t)gc_block.values.p + 1 > ioports_unclaimed(Port_Digital, Port_Output)) FAIL(Status_GcodeValueOutOfRange); gc_block.output_command.is_digital = true; gc_block.output_command.port = (uint8_t)gc_block.values.p; diff --git a/grbl.h b/grbl.h index bd9b79c..3134db6 100644 --- a/grbl.h +++ b/grbl.h @@ -42,7 +42,7 @@ #else #define GRBL_VERSION "1.1f" #endif -#define GRBL_BUILD 20250118 +#define GRBL_BUILD 20250120 #define GRBL_URL "https://github.com/grblHAL" diff --git a/hal.h b/hal.h index 5411e53..046d7ba 100644 --- a/hal.h +++ b/hal.h @@ -340,7 +340,7 @@ typedef struct { stepper_claim_motor_ptr claim_motor; //!< Optional handler for claiming/releasing motor(s) from normal step/dir control. stepper_output_step_ptr output_step; //!< Optional handler for outputting a single step pulse. _Experimental._ Called from interrupt context. motor_iterator_ptr motor_iterator; //!< Optional handler iteration over motor vs. axis mappings. Required for the motors plugin (Trinamic drivers). - stepper_status_ptr stepper_status; //!< Optional handler handler for querying steppper driver status or attempting to reset it. + stepper_status_ptr status; //!< Optional handler handler for querying steppper driver status or attempting to reset it. } stepper_ptrs_t; diff --git a/nuts_bolts.h b/nuts_bolts.h index 2f019f5..255d8e0 100644 --- a/nuts_bolts.h +++ b/nuts_bolts.h @@ -210,8 +210,8 @@ typedef enum { #define bit_false(x, mask) (x) &= ~(mask) #define BIT_SET(x, bit, v) { if (v) { x |= (bit); } else { x &= ~(bit); } } -#define bit_istrue(x, mask) ((x & (mask)) != 0) -#define bit_isfalse(x, mask) ((x & (mask)) == 0) +#define bit_istrue(x, mask) (((x) & (mask)) != 0) +#define bit_isfalse(x, mask) (((x) & (mask)) == 0) // Converts an uint32 variable to string. char *uitoa (uint32_t n); diff --git a/planner.c b/planner.c index e072782..0a9492c 100644 --- a/planner.c +++ b/planner.c @@ -3,7 +3,7 @@ Part of grblHAL - Copyright (c) 2017-2024 Terje Io + Copyright (c) 2017-2025 Terje Io Copyright (c) 2011-2016 Sungeun K. Jeon for Gnea Research LLC Copyright (c) 2009-2011 Simen Svale Skogsrud Copyright (c) 2011 Jens Geisler @@ -234,10 +234,10 @@ bool plan_reset (void) else break; } - } - if(block_buffer_size != settings.planner_buffer_blocks) - protocol_enqueue_foreground_task(report_plain, "Planner buffer size was reduced!"); + if(block_buffer_size != settings.planner_buffer_blocks) + protocol_enqueue_foreground_task(report_plain, "Planner buffer size was reduced!"); + } if(block_buffer == NULL) return false; diff --git a/report.c b/report.c index 8aa7915..a193ad7 100644 --- a/report.c +++ b/report.c @@ -2624,6 +2624,39 @@ status_code_t report_spindles (bool machine_readable) return Status_OK; } +status_code_t report_stepper_status (sys_state_t state, char *args) +{ + if(hal.stepper.status) { + + char *append = buf; + stepper_status_t status = hal.stepper.status(false); + + if(status.warning.state) { + hal.stream.write("[MOTORWARNING:"); + append = axis_signals_tostring(buf, status.warning.details.a); + if(status.warning.details.b.bits) { + *append++ = ','; + axis_signals_tostring(append, status.warning.details.b); + } + hal.stream.write(buf); + hal.stream.write("]" ASCII_EOL); + } + + if(status.fault.state) { + hal.stream.write("[MOTORFAULT:"); + append = axis_signals_tostring(buf, status.fault.details.a); + if(status.fault.details.b.bits) { + *append++ = ','; + axis_signals_tostring(append, status.fault.details.b); + } + hal.stream.write(buf); + hal.stream.write("]" ASCII_EOL); + } + } + + return hal.stepper.status ? Status_OK : Status_InvalidStatement; +} + void report_pid_log (void) { #ifdef PID_LOG diff --git a/report.h b/report.h index 1a7d99f..820fc33 100644 --- a/report.h +++ b/report.h @@ -118,6 +118,9 @@ status_code_t report_pin_states (sys_state_t state, char *args); // Prints registered spindles. status_code_t report_spindles (bool machine_readable); +// Prints current stepper (motor) status. +status_code_t report_stepper_status (sys_state_t state, char *args); + // Prints current RTC datetime in ISO8601 format (when available) status_code_t report_time (void); diff --git a/system.c b/system.c index 77b1b5c..8fd96ea 100644 --- a/system.c +++ b/system.c @@ -798,6 +798,11 @@ const char *help_spindle (const char *cmd) return NULL; } +const char *help_steppers (const char *cmd) +{ + return hal.stepper.status ? "output stepper driver status" : NULL; +} + const char *help_pins (const char *cmd) { return hal.enumerate_pins ? "enumerate pin bindings" : NULL; @@ -943,6 +948,7 @@ PROGMEM static const sys_command_t sys_commands[] = { { "LIM", report_current_limit_state, { .noargs = On, .allow_blocking = On }, { .str = "output current limit pins" } }, { "SD", report_spindle_data, { .help_fn = On }, { .fn = help_spindle } }, { "SR", spindle_reset_data, { .help_fn = On }, { .fn = help_spindle } }, + { "SDS", report_stepper_status, { .noargs = On, .allow_blocking = On, .help_fn = On }, { .fn = help_steppers } }, { "RTC", rtc_action, { .allow_blocking = On, .help_fn = On }, { .fn = help_rtc } }, { "DWNGRD", settings_downgrade, { .noargs = On, .allow_blocking = On }, { .str = "toggle setting flags for downgrade" } }, #ifdef DEBUGOUT