Skip to content

Commit 8373982

Browse files
committed
Fixed regression introduced with PR#673.
Added G30 as optional position for tool change. Moved new tool change mode from PR#673 to $346 - Tool change options. Moved Modbus RTU code from spindle plugin to the core. Fixed bug in delayed task handler, might occasionally hang the controller.
1 parent 77b65c6 commit 8373982

24 files changed

+1041
-238
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ target_sources(grbl INTERFACE
1010
${CMAKE_CURRENT_LIST_DIR}/machine_limits.c
1111
${CMAKE_CURRENT_LIST_DIR}/messages.c
1212
${CMAKE_CURRENT_LIST_DIR}/modbus.c
13+
${CMAKE_CURRENT_LIST_DIR}/modbus_rtu.c
1314
${CMAKE_CURRENT_LIST_DIR}/motion_control.c
1415
${CMAKE_CURRENT_LIST_DIR}/my_plugin.c
1516
${CMAKE_CURRENT_LIST_DIR}/nuts_bolts.c

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
## grblHAL ##
22

3-
Latest build date is 20250415, see the [changelog](changelog.md) for details.
3+
Latest build date is 20250419, see the [changelog](changelog.md) for details.
44

55
> [!NOTE]
66
> A settings reset will be performed on an update of builds prior to 20241208. Backup and restore of settings is recommended.
@@ -89,4 +89,4 @@ G/M-codes not supported by [legacy Grbl](https://github.com/gnea/grbl/wiki) are
8989
Some [plugins](https://github.com/grblHAL/plugins) implements additional M-codes.
9090

9191
---
92-
20250413
92+
20250419

changelog.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,26 @@
11
## grblHAL changelog
22

3+
<a name="20250419">20250419
4+
5+
Core:
6+
7+
* Fixed regression introduced with [PR#673](https://github.com/grblHAL/core/pull/673), added G30 as optional position for tool change and moved new tool change mode from PR#673 to `$346` - _Tool change options_.
8+
9+
* Moved Modbus RTU code from spindle plugin to the core.
10+
11+
* For developers: deprecated `protocol_enqueue_foreground_task()`, replaced by `task_run_on_startup()` - added alias for the deprecated version.
12+
Changed signature of `modbus_isup()` to return capabilities flag instead of boolean.
13+
14+
* Fixed bug in delayed task handler, might occasionally hang the controller. May be part of keypad issue [#17](https://github.com/grblHAL/Plugin_keypad/issues/17).
15+
16+
Plugins:
17+
18+
Keypad and spindle: updated for core changes.
19+
20+
Keypad, I2C display interface: fixed alignment issue that caused hardfault on WCO changes on some platforms. May resolve issue [#17](https://github.com/grblHAL/Plugin_keypad/issues/17).
21+
22+
---
23+
324
<a name="20250415">20250415
425

526
Core:

config.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1351,7 +1351,7 @@ and less range over the total 255 PWM levels to signal different spindle speeds.
13511351
// Tool change settings (Group_Toolchange)
13521352

13531353
/*! @name $341 - Setting_ToolChangeMode
1354-
0 = Normal mode, 1 = Manual change, 2 = Manual change @ G59.3, 3 = Manual change and probe sensor @ G59.3 - sets TLO
1354+
0 = Normal mode, 1 = Manual change, 2 = Manual change @ G59.3, 3 = Manual change and probe tolsetter @ G59.3, 4 = Ignore M6
13551355
*/
13561356
///@{
13571357
#if !defined DEFAULT_TOOLCHANGE_MODE || defined __DOXYGEN__
@@ -1392,12 +1392,18 @@ and less range over the total 255 PWM levels to signal different spindle speeds.
13921392
#endif
13931393
///@}
13941394

1395-
/*! @name $346 - Setting_ToolChangeRestorePosition
1395+
/*! @name $346 - Setting_ToolChangeOptions
13961396
*/
13971397
///@{
13981398
#if !defined DEFAULT_TOOLCHANGE_NO_RESTORE_POSITION || defined __DOXYGEN__
13991399
#define DEFAULT_TOOLCHANGE_NO_RESTORE_POSITION Off
14001400
#endif
1401+
#if !defined DEFAULT_TOOLCHANGE_AT_G30 || defined __DOXYGEN__
1402+
#define DEFAULT_TOOLCHANGE_AT_G30 Off
1403+
#endif
1404+
#if !defined DEFAULT_TOOLCHANGE_FAST_PROBE_PULLOFF || defined __DOXYGEN__
1405+
#define DEFAULT_TOOLCHANGE_FAST_PROBE_PULLOFF Off
1406+
#endif
14011407
///@}
14021408

14031409
// Homing settings (Group_Homing)

core_handlers.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ typedef void (*on_state_change_ptr)(sys_state_t state);
8989
typedef void (*on_override_changed_ptr)(override_changed_t override);
9090
typedef void (*on_spindle_programmed_ptr)(spindle_ptrs_t *spindle, spindle_state_t state, float rpm, spindle_rpm_mode_t mode);
9191
typedef void (*on_wco_changed_ptr)(void);
92+
typedef void (*on_wco_saved_ptr)(coord_system_id_t id, coord_data_t *data);
9293
typedef void (*on_program_completed_ptr)(program_flow_t program_flow, bool check_mode);
9394
typedef void (*on_execute_realtime_ptr)(sys_state_t state);
9495
typedef void (*on_unknown_accessory_override_ptr)(uint8_t cmd);
@@ -220,6 +221,7 @@ typedef struct {
220221
on_report_handlers_init_ptr on_report_handlers_init;
221222
on_spindle_programmed_ptr on_spindle_programmed;
222223
on_wco_changed_ptr on_wco_changed;
224+
on_wco_saved_ptr on_wco_saved;
223225
on_program_completed_ptr on_program_completed;
224226
on_execute_realtime_ptr on_execute_realtime;
225227
on_execute_realtime_ptr on_execute_delay;

grbl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
#else
4343
#define GRBL_VERSION "1.1f"
4444
#endif
45-
#define GRBL_BUILD 20250415
45+
#define GRBL_BUILD 20250419
4646

4747
#define GRBL_URL "https://github.com/grblHAL"
4848

grbllib.c

Lines changed: 64 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ typedef union {
7676
} driver_startup_t;
7777

7878
#ifndef CORE_TASK_POOL_SIZE
79-
#define CORE_TASK_POOL_SIZE 30
79+
#define CORE_TASK_POOL_SIZE 40
8080
#endif
8181

8282
typedef struct core_task {
@@ -92,7 +92,7 @@ DCRAM grbl_hal_t hal;
9292

9393
DCRAM static core_task_t task_pool[CORE_TASK_POOL_SIZE];
9494
static driver_startup_t driver = { .ok = 0xFF };
95-
static core_task_t *next_task = NULL, *immediate_task = NULL, *systick_task = NULL, *last_freed = NULL;
95+
static core_task_t *next_task = NULL, *immediate_task = NULL, *on_booted = NULL, *systick_task = NULL, *last_freed = NULL;
9696
static on_linestate_changed_ptr on_linestate_changed;
9797
static settings_changed_ptr hal_settings_changed;
9898

@@ -181,8 +181,10 @@ static void output_welcome_message (void *data)
181181

182182
static void onLinestateChanged (serial_linestate_t state)
183183
{
184-
if(state.dtr)
184+
if(state.dtr) {
185+
task_delete(output_welcome_message, NULL);
185186
task_add_delayed(output_welcome_message, NULL, 200);
187+
}
186188

187189
if(on_linestate_changed)
188190
on_linestate_changed(state);
@@ -343,7 +345,7 @@ int grbl_enter (void)
343345

344346
if(driver.ok != 0xFF) {
345347
sys.alarm = Alarm_SelftestFailed;
346-
protocol_enqueue_foreground_task(report_driver_error, NULL);
348+
task_run_on_startup(report_driver_error, NULL);
347349
}
348350

349351
hal.stepper.enable(settings.steppers.energize, true);
@@ -465,6 +467,7 @@ __attribute__((always_inline)) static inline core_task_t *task_alloc (void)
465467
__attribute__((always_inline)) static inline void task_free (core_task_t *task)
466468
{
467469
task->fn = NULL;
470+
task->next = NULL;
468471
if(last_freed == NULL)
469472
last_freed = task;
470473
}
@@ -541,7 +544,7 @@ ISR_CODE bool ISR_FUNC(task_add_delayed)(foreground_task_ptr fn, void *data, uin
541544

542545
if(next_task == NULL)
543546
next_task = task;
544-
else if((int32_t)(task->time - next_task->time) < 0) {
547+
else if((int32_t)(task->time - next_task->time) <= 0) {
545548
task->next = next_task;
546549
next_task = task;
547550
} else {
@@ -662,3 +665,59 @@ ISR_CODE bool ISR_FUNC(task_add_immediate)(foreground_task_ptr fn, void *data)
662665

663666
return task != NULL;
664667
}
668+
669+
/*! \brief Enqueue a function to be called once by the foreground process after the boot sequence is completed.
670+
\param fn pointer to a \a foreground_task_ptr type of function.
671+
\param data pointer to data to be passed to the callee.
672+
\returns true if successful, false otherwise.
673+
*/
674+
ISR_CODE bool ISR_FUNC(task_run_on_startup)(foreground_task_ptr fn, void *data)
675+
{
676+
if(sys.cold_start) {
677+
678+
core_task_t *task = NULL;
679+
680+
hal.irq_disable();
681+
682+
if(fn && (task = task_alloc())) {
683+
684+
task->fn = fn;
685+
task->data = data;
686+
task->next = NULL;
687+
688+
if(on_booted == NULL)
689+
on_booted = task;
690+
else {
691+
core_task_t *t = on_booted;
692+
while(t->next)
693+
t = t->next;
694+
t->next = task;
695+
}
696+
}
697+
698+
hal.irq_enable();
699+
700+
return task != NULL;
701+
702+
} else
703+
return task_add_immediate(fn, data); // TODO: for now, to be removed...
704+
}
705+
706+
// for core use only, called once from protocol.c on cold start
707+
void task_execute_on_startup (void)
708+
{
709+
if(on_booted) do {
710+
711+
core_task_t *task = on_booted;
712+
foreground_task_ptr fn = task->fn;
713+
void *data = task->data;
714+
715+
on_booted = task->next;
716+
task_free(task);
717+
fn(data);
718+
719+
} while(on_booted);
720+
721+
if(!sys.driver_started)
722+
while(true);
723+
}

kinematics/delta.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
44
Part of grblHAL
55
6-
Copyright (c) 2023-2024 Terje Io
6+
Copyright (c) 2023-2025 Terje Io
77
Transforms derived from mzavatsky at Trossen Robotics
88
https://hypertriangle.com/~alex/delta-robot-tutorial/
99
get_cuboid_envelope() derived from javascript code in
@@ -541,7 +541,7 @@ static void delta_homing_complete (axes_signals_t cycle, bool success)
541541
: machine.home_z - settings.homing.pulloff;
542542

543543
if(machine.cfg.flags.home_to_cuboid_top)
544-
protocol_enqueue_foreground_task(delta_go_home, NULL);
544+
task_add_immediate(delta_go_home, NULL);
545545
}
546546

547547
if(on_homing_completed)

messages.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,10 @@ PROGMEM static const message_t messages[] = {
4444
{ .id = Message_CycleStart2Continue, .text = "Press cycle start to continue." },
4545
{ .id = Message_TPCycleStart2Continue, .text = "Remove any touch plate and press cycle start to continue." },
4646
{ .id = Message_ProbeFailedRetry, .text = "Probe failed, try again." },
47-
{ .id = Message_ExecuteTPW, .text = "Perform a probe with $TPW first!", .type = Message_Warning},
48-
{ .id = Message_ProbeProtected, .text = "Probe protection activated."},
49-
{ .id = Message_Stop, .text = "Stop"}
47+
{ .id = Message_ExecuteTPW, .text = "Perform a probe with $TPW first!", .type = Message_Warning },
48+
{ .id = Message_ProbeProtected, .text = "Probe protection activated." },
49+
{ .id = Message_Stop, .text = "Stop" },
50+
{ .id = Message_CycleStart2TouchOff, .text = "Press cycle start to position for touch-off." }
5051
};
5152

5253
const message_t *message_get (message_code_t id)

messages.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ typedef enum {
4747
Message_ExecuteTPW = 20, //!< 20
4848
Message_ProbeProtected = 21, //!< 21
4949
Message_Stop = 22, //!< 22
50-
Message_NextMessage //!< 23 - next unassigned message number.
50+
Message_CycleStart2TouchOff = 23, //!< 23
51+
Message_NextMessage //!< 24 - next unassigned message number.
5152
} message_code_t;
5253

5354
typedef enum {

modbus.c

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,42 +4,58 @@
44
55
Part of grblHAL
66
7-
Copyright (c) 2023 Terje Io
7+
Copyright (c) 2023-2025 Terje Io
88
9-
Grbl is free software: you can redistribute it and/or modify
9+
grblHAL is free software: you can redistribute it and/or modify
1010
it under the terms of the GNU General Public License as published by
1111
the Free Software Foundation, either version 3 of the License, or
1212
(at your option) any later version.
1313
14-
Grbl is distributed in the hope that it will be useful,
14+
grblHAL is distributed in the hope that it will be useful,
1515
but WITHOUT ANY WARRANTY; without even the implied warranty of
16-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1717
GNU General Public License for more details.
1818
1919
You should have received a copy of the GNU General Public License
20-
along with Grbl. If not, see <http://www.gnu.org/licenses/>.
20+
along with grblHAL. If not, see <http://www.gnu.org/licenses/>.
2121
2222
*/
2323

2424
#include "modbus.h"
2525

2626
#include <string.h>
2727

28+
#include "nuts_bolts.h"
29+
2830
#define N_MODBUS_API 2
2931

3032
static uint_fast16_t n_api = 0, tcp_api = N_MODBUS_API, rtu_api = N_MODBUS_API;
3133
static modbus_api_t modbus[N_MODBUS_API] = {0};
3234

33-
bool modbus_isup (void)
35+
modbus_cap_t modbus_isup (void)
3436
{
35-
bool ok = n_api > 0;
3637
uint_fast16_t idx = n_api;
38+
modbus_cap_t cap = {};
3739

3840
if(idx) do {
39-
ok &= modbus[--idx].is_up();
41+
idx--;
42+
if(modbus[idx].is_up()) switch(modbus[idx].interface) {
43+
44+
case Modbus_InterfaceRTU:
45+
cap.rtu = On;
46+
break;
47+
48+
case Modbus_InterfaceASCII:
49+
cap.ascii = On;
50+
break;
51+
52+
case Modbus_InterfaceTCP:
53+
cap.tcp = On;
54+
break;
55+
}
4056
} while(idx);
4157

42-
return ok;
58+
return cap;
4359
}
4460

4561
bool modbus_enabled (void)

modbus.h

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,20 @@
44
55
Part of grblHAL
66
7-
Copyright (c) 2023 Terje Io
7+
Copyright (c) 2023-2025 Terje Io
88
9-
Grbl is free software: you can redistribute it and/or modify
9+
grblHAL is free software: you can redistribute it and/or modify
1010
it under the terms of the GNU General Public License as published by
1111
the Free Software Foundation, either version 3 of the License, or
1212
(at your option) any later version.
1313
14-
Grbl is distributed in the hope that it will be useful,
14+
grblHAL is distributed in the hope that it will be useful,
1515
but WITHOUT ANY WARRANTY; without even the implied warranty of
16-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1717
GNU General Public License for more details.
1818
1919
You should have received a copy of the GNU General Public License
20-
along with Grbl. If not, see <http://www.gnu.org/licenses/>.
20+
along with grblHAL. If not, see <http://www.gnu.org/licenses/>.
2121
2222
*/
2323

@@ -83,6 +83,16 @@ typedef union {
8383
};
8484
} modbus_silence_timeout_t;
8585

86+
typedef union {
87+
uint8_t ok;
88+
struct {
89+
uint8_t rtu :1,
90+
ascii :1,
91+
tcp :1,
92+
unassigned :6;
93+
};
94+
} modbus_cap_t;
95+
8696
typedef bool (*modbus_is_up_ptr)(void);
8797
typedef void (*modbus_flush_queue_ptr)(void);
8898
typedef void (*modbus_set_silence_ptr)(const modbus_silence_timeout_t *timeout);
@@ -96,7 +106,7 @@ typedef struct {
96106
modbus_send_ptr send;
97107
} modbus_api_t;
98108

99-
bool modbus_isup (void);
109+
modbus_cap_t modbus_isup (void);
100110
bool modbus_enabled (void);
101111
void modbus_flush_queue (void);
102112
void modbus_set_silence (const modbus_silence_timeout_t *timeout);

0 commit comments

Comments
 (0)