From b10b3317d22dc47c8c48c1cfcc97ed0e6f35af22 Mon Sep 17 00:00:00 2001 From: Terje Io Date: Sun, 18 May 2025 08:03:51 +0200 Subject: [PATCH] Fix for custom M-code commands claiming all axis words even when not using any. Added setting $680 for configuring delay from stepper enable to first dir/step pulse. Adds to fixed ~2ms delay provided by most drivers. --- changelog.md | 24 ++++++++++++++++++++++++ config.h | 13 +++++++++++-- gcode.c | 17 +++++++++-------- gcode.h | 16 ++++++++++++++-- grbl.h | 2 +- nvs_buffer.c | 2 +- settings.c | 7 +++++-- settings.h | 4 +++- stepper.c | 3 +++ system.c | 5 +++-- 10 files changed, 74 insertions(+), 19 deletions(-) diff --git a/changelog.md b/changelog.md index 0519487..4ccc2b7 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,27 @@ ## grblHAL changelog +Build 20250518 + +Core: + +* Fix for custom M-code commands claiming all axis words even when not using any. + +* Added setting `$680` for configuring delay from stepper enable to first dir/step pulse. Added to fixed ~2ms delay provided by most drivers. + +Drivers: + +* STM32F4xx: added OpenPNP plugin. + +* STM32F4xx, STM32F7xx: fix for second PWM spindle failing to compile and reading analog inputs returning the value from the last configured. + +Plugins: + +* OpenPNP: added support for reading/scaling analog inputs via `M123`, `M124` and `M125` custom M-codes. + +* Keypad: changed to report itself even if no keypad is connected, added delay before probing the I2C bus to allow the keypad time to boot. + +--- + Build 20250514 Core: @@ -15,6 +37,8 @@ When more than one probe is available `PROBES:` is added to the `NEWOPTS` Drivers: +* iMXRT1062: added `$BL` command for entering bootloader mode, allows use of the _Teensy Loader_ when access to the programming button is restricted. + * All: fix for potential/actual hard fault when a basic on/off spindle is configured. Ref. ESP32 issue [#164](https://github.com/grblHAL/ESP32/issues/164). * STM32 drivers: fix for incorrect PWM output at max RPM when PWM output is inverted. diff --git a/config.h b/config.h index 98c808d..b2ec394 100644 --- a/config.h +++ b/config.h @@ -1925,8 +1925,8 @@ Specify at least \ref X_AXIS_BIT if a common enable signal is used. #endif ///@} -/*! @name $376 - Settings_Axis_Rotational -Designate ABC axes as rotational by \ref axismask. This will disable scaling (to mm) in inches mode. +/*! @name $376 - Settings_RotaryAxes +Designate ABC axes as rotary by \ref axismask. This will disable scaling (to mm) in inches mode. Set steps/mm for the axes to the value that represent the desired movement per unit. For the controller the distance is unitless and and can be in degrees, radians, rotations, ... */ @@ -1936,6 +1936,15 @@ For the controller the distance is unitless and and can be in degrees, radians, #endif ///@} +/*! @name $680 - Setting_StepperEnableDelay +Allowed range 0 - 250 milliseconds. Driver adds ~2 milliseconds. +*/ +///@{ +#if !defined DEFAULT_STEPPER_ENABLE_DELAY || defined __DOXYGEN__ +#define DEFAULT_STEPPER_ENABLE_DELAY 0 +#endif +///@} + /*! @name $742 - Setting_MotorWarningsEnable \brief \ref axismask controlling the which motor warning signals to enable. Set this value to -1 or AXES_BITMASK to enable for all axes or specify which by mask. diff --git a/gcode.c b/gcode.c index 8e40900..a2573ff 100644 --- a/gcode.c +++ b/gcode.c @@ -1776,14 +1776,16 @@ status_code_t gc_execute_block (char *block) user_words.mask = gc_block.words.mask; if((int_value = (uint_fast16_t)grbl.user_mcode.validate(&gc_block))) FAIL((status_code_t)int_value); - user_words.mask ^= gc_block.words.mask; // Flag "taken" words for execution - if(user_words.i) - ijk_words.i = Off; - if(user_words.j) - ijk_words.j = Off; - if(user_words.k) - ijk_words.k = Off; + parameter_words_t taken_words; + + user_words.mask ^= gc_block.words.mask; // Flag "taken" words for user M-code execution + + if((taken_words.mask = user_words.mask & axis_words_mask.mask)) + axis_words.mask &= ~gc_paramwords_to_axes(taken_words).mask; + + ijk_words.mask &= ~(uint8_t)((user_words.mask >> 4) & 0b111); + if(user_words.f) { single_meaning_value.f = gc_block.values.f; gc_block.values.f = 0.0f; @@ -1800,7 +1802,6 @@ status_code_t gc_execute_block (char *block) single_meaning_value.t = gc_block.values.t; gc_block.values.t = (tool_id_t)0; } - axis_words.mask = 0; } // [1. Comments ]: MSG's may be supported by driver layer. Comment handling performed by protocol. diff --git a/gcode.h b/gcode.h index 0b8b992..e477f9c 100644 --- a/gcode.h +++ b/gcode.h @@ -242,7 +242,6 @@ typedef enum { UserMCode_Generic2 = 102, //!< 102 - For private use only UserMCode_Generic3 = 103, //!< 103 - For private use only UserMCode_Generic4 = 104, //!< 104 - For private use only - OpenPNP_GetADCReading = 105, //!< 105 - M105 Fan_On = 106, //!< 106 - M106, Marlin format Fan_Off = 107, //!< 107 - M107, Marlin format OpenPNP_GetCurrentPosition = 114, //!< 114 - M114 @@ -254,6 +253,9 @@ typedef enum { LaserPPI_Rate = 127, //!< 127 - M127 LaserPPI_PulseLength = 128, //!< 128 - M128 Laser_Overdrive = 129, //!< 129 - M129 + OpenPNP_GetADCRaw = 143, //!< 143 - M143 + OpenPNP_GetADCScaled = 144, //!< 144 - M144 + OpenPNP_SetADCScaling = 145, //!< 145 - M145 RGB_WriteLEDs = 150, //!< 150 - M150, Marlin format Plasma_SelectMaterial = 190, //!< 150 - M190, LinuxCNC format OpenPNP_SetJerk = 20130, //!< 20130 - M201.3 @@ -457,7 +459,7 @@ typedef struct { uint8_t l; //!< G10 or canned cycles parameters } gc_values_t; -//! Parameter words found by parser - do not change order! +//! Parameter words found by parser - do NOT change order! typedef union { uint32_t mask; //!< All flags as a bitmap. uint32_t value; //!< Synonymous with \a mask. @@ -676,6 +678,16 @@ typedef struct { #endif } parser_block_t; + +static inline axes_signals_t gc_paramwords_to_axes (parameter_words_t p_words) +{ +#if N_AXIS == 3 + return (axes_signals_t){ (uint8_t)(p_words.mask >> 24) }; +#else + return (axes_signals_t){ (uint8_t)(((p_words.mask >> 24) | ((p_words.mask << 2) & 0b00111000) | ((p_words.mask >> (21 - 6)) & 0b11000000)) & AXES_BITMASK) }; +#endif +} + // Initialize the parser void gc_init (bool stop); diff --git a/grbl.h b/grbl.h index 4eab895..dba03d6 100644 --- a/grbl.h +++ b/grbl.h @@ -42,7 +42,7 @@ #else #define GRBL_VERSION "1.1f" #endif -#define GRBL_BUILD 20250514 +#define GRBL_BUILD 20250518 #define GRBL_URL "https://github.com/grblHAL" diff --git a/nvs_buffer.c b/nvs_buffer.c index 74b464a..ec81970 100644 --- a/nvs_buffer.c +++ b/nvs_buffer.c @@ -404,7 +404,7 @@ nvs_io_t *nvs_buffer_get_physical (void) return hal.nvs.type == NVS_Emulated ? &physical_nvs : &hal.nvs; } -#ifdef DEBUGOUT +#ifdef DEBUG #include "report.h" diff --git a/settings.c b/settings.c index c79cf3d..e02bbf5 100644 --- a/settings.c +++ b/settings.c @@ -99,6 +99,7 @@ PROGMEM const settings_t defaults = { .probe.invert_toolsetter_input = DEFAULT_TOOLSETTER_SIGNAL_INVERT, .probe.disable_toolsetter_pullup = DEFAULT_TOOLSETTER_SIGNAL_DISABLE_PULLUP, + .stepper_enable_delay = DEFAULT_STEPPER_ENABLE_DELAY, .steppers.pulse_microseconds = DEFAULT_STEP_PULSE_MICROSECONDS, .steppers.pulse_delay_microseconds = DEFAULT_STEP_PULSE_DELAY, .steppers.idle_lock_time = DEFAULT_STEPPER_IDLE_LOCK_TIME, @@ -2152,7 +2153,8 @@ PROGMEM static const setting_detail_t setting_detail[] = { { Setting_MotorWarningsInvert, Group_Stepper, "Invert motor warning inputs", NULL, Format_AxisMask, NULL, NULL, NULL, Setting_IsExtended, &settings.motor_warning_invert, NULL, is_setting_available }, { Setting_MotorFaultsEnable, Group_Stepper, "Motor fault inputs enable", NULL, Format_AxisMask, NULL, NULL, NULL, Setting_IsExtended, &settings.motor_fault_enable, NULL, is_setting_available }, { Setting_MotorFaultsInvert, Group_Stepper, "Invert motor fault inputs", NULL, Format_AxisMask, NULL, NULL, NULL, Setting_IsExtended, &settings.motor_fault_invert, NULL, is_setting_available }, - { Setting_ResetActions, Group_General, "Reset actions", NULL, Format_Bitfield, "Clear homed status if position was lost,Clear offsets (except G92)", NULL, NULL, Setting_IsExtendedFn, set_reset_actions, get_int, NULL } + { Setting_ResetActions, Group_General, "Reset actions", NULL, Format_Bitfield, "Clear homed status if position was lost,Clear offsets (except G92)", NULL, NULL, Setting_IsExtendedFn, set_reset_actions, get_int, NULL }, + { Setting_StepperEnableDelay, Group_Stepper, "Stepper enable delay", "ms", Format_Int16, "##0", NULL, "250", Setting_IsExtended, &settings.stepper_enable_delay, NULL, NULL }, }; #ifndef NO_SETTINGS_DESCRIPTIONS @@ -2357,7 +2359,8 @@ PROGMEM static const setting_descr_t setting_descr[] = { { Setting_FSOptions, "Auto mount SD card on startup." }, { Setting_HomePinsInvertMask, "Inverts the axis home input signals." }, { Setting_CoolantOnDelay, "Delay to allow coolant to start. 0 or 0.5 - 20s." }, - { Setting_ResetActions, "Controls actions taken on a soft reset." } + { Setting_ResetActions, "Controls actions taken on a soft reset." }, + { Setting_StepperEnableDelay, "Delay from stepper enable to first step output. The driver typically adds ~2ms to this." } /* { Setting_MotorWarningsEnable, "Motor warning enable" }, { Setting_MotorWarningsInvert, "Invert motor warning inputs" }, diff --git a/settings.h b/settings.h index af935ed..ea2b4e7 100644 --- a/settings.h +++ b/settings.h @@ -458,6 +458,7 @@ typedef enum { Setting_StepperSpindle_Options = 677, Setting_RelayPortToolsetter = 678, Setting_RelayPortProbe2 = 679, + Setting_StepperEnableDelay = 680, Setting_SpindlePWMOptions1 = 709, @@ -895,7 +896,8 @@ typedef struct { axes_signals_t motor_fault_invert; macro_atc_flags_t macro_atc_flags; stepper_spindle_settings_flags_t stepper_spindle_flags; - char reserved[18]; // Reserved For future expansion + uint16_t stepper_enable_delay; // Move to stepper_settings_t + char reserved[16]; // Reserved For future expansion } settings_t; typedef enum { diff --git a/stepper.c b/stepper.c index f5021f1..218b2b9 100644 --- a/stepper.c +++ b/stepper.c @@ -201,6 +201,9 @@ void st_wake_up (void) hal.stepper.go_idle(true); // Reset step & dir outputs hal.stepper.wake_up(); + + if(settings.stepper_enable_delay) // TODO: do not add delay if deenergize is pending? + hal.delay_ms(settings.stepper_enable_delay, NULL); } // Stepper shutdown diff --git a/system.c b/system.c index 8975c6e..b154f2a 100644 --- a/system.c +++ b/system.c @@ -762,7 +762,7 @@ static status_code_t rtc_action (sys_state_t state, char *args) return retval; } -#ifdef DEBUGOUT +#ifdef DEBUG #include "nvs_buffer.h" @@ -772,6 +772,7 @@ static status_code_t output_memmap (sys_state_t state, char *args) return Status_OK; } + #endif const char *help_rst (const char *cmd) @@ -972,7 +973,7 @@ PROGMEM static const sys_command_t sys_commands[] = { { "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 +#ifdef DEBUG { "Q", output_memmap, { .noargs = On }, { .str = "output NVS memory allocation" } }, #endif };