diff --git a/Grbl_Esp32/motion_control.cpp b/Grbl_Esp32/motion_control.cpp index 304c545d..4e08e74c 100644 --- a/Grbl_Esp32/motion_control.cpp +++ b/Grbl_Esp32/motion_control.cpp @@ -435,8 +435,8 @@ void mc_reset() { // Kill spindle and coolant. spindle->stop(); coolant_stop(); - // turn off all digital I/O - sys_io_control(0xFF, false); + // turn off all digital I/O immediately + fast_sys_io_control(0xFF, false); #ifdef ENABLE_SD_CARD // do we need to stop a running SD job? if (get_sd_state(false) == SDCARD_BUSY_PRINTING) { diff --git a/Grbl_Esp32/system.cpp b/Grbl_Esp32/system.cpp index b74e889f..7870bf50 100644 --- a/Grbl_Esp32/system.cpp +++ b/Grbl_Esp32/system.cpp @@ -339,8 +339,15 @@ int32_t system_convert_corexy_to_y_axis_steps(int32_t* steps) { // io_num is the virtual pin# and has nothing to do with the actual esp32 GPIO_NUM_xx // It uses a mask so all can be turned of in ms_reset +// This version waits until realtime commands have been executed void sys_io_control(uint8_t io_num_mask, bool turnOn) { protocol_buffer_synchronize(); + fast_sys_io_control(io_num_mask, turnOn); +} + +// This version works immediately, without waiting, to prevent deadlocks. +// It is used when resetting via mc_reset() +void fast_sys_io_control(uint8_t io_num_mask, bool turnOn) { #ifdef USER_DIGITAL_PIN_1 if (io_num_mask & bit(1)) { digitalWrite(USER_DIGITAL_PIN_1, turnOn); diff --git a/Grbl_Esp32/system.h b/Grbl_Esp32/system.h index 1a36f6b1..aa102c24 100644 --- a/Grbl_Esp32/system.h +++ b/Grbl_Esp32/system.h @@ -226,6 +226,7 @@ void controlCheckTask(void* pvParameters); void system_exec_control_pin(uint8_t pin); void sys_io_control(uint8_t io_num_mask, bool turnOn); +void fast_sys_io_control(uint8_t io_num_mask, bool turnOn); // int8_t sys_get_next_RMT_chan_num();