Skip to content

Commit

Permalink
Added $SDS command for outputting Stepper Driver Status.
Browse files Browse the repository at this point in the history
  • Loading branch information
terjeio committed Jan 20, 2025
1 parent ff0903f commit c7c7d5a
Show file tree
Hide file tree
Showing 11 changed files with 98 additions and 12 deletions.
30 changes: 30 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,35 @@
## grblHAL changelog

<a name="20250120">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:<axisletters>{,<axisletters>}]` and/or
`[MOTORFAULT:<axisletters>{,<axisletters>}]`

The first set of `<axisletters>` 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).

---

<a name="20250118">Build 20250118

Core:
Expand Down
15 changes: 15 additions & 0 deletions crossbar.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 1 addition & 2 deletions errors.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Expand Down
4 changes: 2 additions & 2 deletions gcode.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion grbl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
2 changes: 1 addition & 1 deletion hal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;


Expand Down
4 changes: 2 additions & 2 deletions nuts_bolts.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions planner.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
33 changes: 33 additions & 0 deletions report.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions report.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
6 changes: 6 additions & 0 deletions system.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit c7c7d5a

Please sign in to comment.