From f18b3712ec14c44a398e63cc24b4e78706a0acf1 Mon Sep 17 00:00:00 2001
From: rominetb44 <32679436+rominetb44@users.noreply.github.com>
Date: Sun, 28 May 2023 18:30:15 +0200
Subject: [PATCH 1/8] Swap Mutex for Semaphore to manage multithreading.
---
Grbl_Esp32/src/Serial.cpp | 47 ++++++++++++++++++++++++++++++---------
1 file changed, 37 insertions(+), 10 deletions(-)
diff --git a/Grbl_Esp32/src/Serial.cpp b/Grbl_Esp32/src/Serial.cpp
index 633893e96..e3d757361 100644
--- a/Grbl_Esp32/src/Serial.cpp
+++ b/Grbl_Esp32/src/Serial.cpp
@@ -63,19 +63,40 @@
// testing is complete.
// #define REVERT_TO_ARDUINO_SERIAL
-portMUX_TYPE myMutex = portMUX_INITIALIZER_UNLOCKED;
static TaskHandle_t clientCheckTaskHandle = 0;
WebUI::InputBuffer client_buffer[CLIENT_COUNT]; // create a buffer for each client
+//Semaphore to protect data exchange when multithreading
+SemaphoreHandle_t bufferSemaphore;
+void createSemaphore(){
+ bufferSemaphore = xSemaphoreCreateMutex();
+ xSemaphoreGive( ( bufferSemaphore) );
+}
+
+// Lock the variable indefinietly. ( wait for it to be accessible )
+BaseType_t lockVariable(){
+ return xSemaphoreTake(bufferSemaphore, portMAX_DELAY);
+}
+
+// give back the semaphore.
+void unlockVariable(){
+ xSemaphoreGive(bufferSemaphore);
+}
+
// Returns the number of bytes available in a client buffer.
uint8_t client_get_rx_buffer_available(uint8_t client) {
+ uint8_t avalaiblebuffer = 0;
+ if (lockVariable() == pdTRUE ) {
#ifdef REVERT_TO_ARDUINO_SERIAL
- return 128 - Serial.available();
+ avalaiblebuffer = 128 - Serial.available();
#else
- return 128 - Uart0.available();
+ avalaiblebuffer = 128 - Uart0.available();
#endif
+ unlockVariable();
+ }
+ return avalaiblebuffer;
// return client_buffer[client].availableforwrite();
}
@@ -101,7 +122,7 @@ void client_init() {
// For a 2000-word stack, uxTaskGetStackHighWaterMark reports 288 words available
xTaskCreatePinnedToCore(heapCheckTask, "heapTask", 2000, NULL, 1, NULL, 1);
#endif
-
+ createSemaphore();
#ifdef REVERT_TO_ARDUINO_SERIAL
Serial.begin(BAUD_RATE, SERIAL_8N1, 3, 1, false);
client_reset_read_buffer(CLIENT_ALL);
@@ -182,9 +203,10 @@ void clientCheckTask(void* pvParameters) {
#if defined(ENABLE_SD_CARD)
if (get_sd_state(false) < SDState::Busy) {
#endif //ENABLE_SD_CARD
- vTaskEnterCritical(&myMutex);
+ if (lockVariable() == pdTRUE ) {
client_buffer[client].write(data);
- vTaskExitCritical(&myMutex);
+ unlockVariable();
+ }
#if defined(ENABLE_SD_CARD)
} else {
if (data == '\r' || data == '\n') {
@@ -217,16 +239,21 @@ void clientCheckTask(void* pvParameters) {
void client_reset_read_buffer(uint8_t client) {
for (uint8_t client_num = 0; client_num < CLIENT_COUNT; client_num++) {
if (client == client_num || client == CLIENT_ALL) {
- client_buffer[client_num].begin();
+ if (lockVariable() == pdTRUE ) {
+ client_buffer[client_num].begin();
+ unlockVariable();
+ }
}
}
}
// Fetches the first byte in the client read buffer. Called by protocol loop.
int client_read(uint8_t client) {
- vTaskEnterCritical(&myMutex);
- int data = client_buffer[client].read();
- vTaskExitCritical(&myMutex);
+ int data = 0;
+ if (lockVariable() == pdTRUE ) {
+ data = client_buffer[client].read();
+ unlockVariable();
+ }
return data;
}
From 13d64be5312c73004a05842b58fdaf9233aaa8c4 Mon Sep 17 00:00:00 2001
From: rominetb44 <32679436+rominetb44@users.noreply.github.com>
Date: Mon, 29 May 2023 19:39:34 +0200
Subject: [PATCH 2/8] Changing avalaible to available.
---
Grbl_Esp32/src/Serial.cpp | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/Grbl_Esp32/src/Serial.cpp b/Grbl_Esp32/src/Serial.cpp
index e3d757361..cfbe6f330 100644
--- a/Grbl_Esp32/src/Serial.cpp
+++ b/Grbl_Esp32/src/Serial.cpp
@@ -87,16 +87,16 @@ void unlockVariable(){
// Returns the number of bytes available in a client buffer.
uint8_t client_get_rx_buffer_available(uint8_t client) {
- uint8_t avalaiblebuffer = 0;
+ uint8_t availablebuffer = 0;
if (lockVariable() == pdTRUE ) {
#ifdef REVERT_TO_ARDUINO_SERIAL
- avalaiblebuffer = 128 - Serial.available();
+ availablebuffer = 128 - Serial.available();
#else
- avalaiblebuffer = 128 - Uart0.available();
+ availablebuffer = 128 - Uart0.available();
#endif
unlockVariable();
}
- return avalaiblebuffer;
+ return availablebuffer;
// return client_buffer[client].availableforwrite();
}
From cc1193f2f5ad49e7eb7593b5f29d51279482ef1c Mon Sep 17 00:00:00 2001
From: rominetb44 <32679436+rominetb44@users.noreply.github.com>
Date: Mon, 29 May 2023 19:44:07 +0200
Subject: [PATCH 3/8] Update RS-CNC32.
---
Grbl_Esp32/src/Machines/makerfr_v2_XYYZ.h | 68 +++++++++++++++++++++++
Grbl_Esp32/src/Machines/makerfr_v2_XYZA.h | 66 ++++++++++++++++++++++
2 files changed, 134 insertions(+)
create mode 100644 Grbl_Esp32/src/Machines/makerfr_v2_XYYZ.h
create mode 100644 Grbl_Esp32/src/Machines/makerfr_v2_XYZA.h
diff --git a/Grbl_Esp32/src/Machines/makerfr_v2_XYYZ.h b/Grbl_Esp32/src/Machines/makerfr_v2_XYYZ.h
new file mode 100644
index 000000000..9b9c48a0e
--- /dev/null
+++ b/Grbl_Esp32/src/Machines/makerfr_v2_XYYZ.h
@@ -0,0 +1,68 @@
+#pragma once
+// clang-format off
+
+/*
+ makerfr_v2_XYYZ.h
+ Part of Grbl_ESP32
+
+ Pin assignments for the RS-CNC32 board (4 axis with external drivers)
+ https://github.com/bdring/4_Axis_SPI_CNC
+
+ 2018 - Bart Dring
+ 2020 - Mitch Bradley
+
+ Grbl_ESP32 is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Grbl is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Grbl_ESP32. If not, see .
+*/
+
+#define MACHINE_NAME "MakerFr GRBL 32 bits Board V2 XYYZ"
+
+#ifdef N_AXIS
+ #undef N_AXIS
+#endif
+#define N_AXIS 4
+
+#define X_STEP_PIN GPIO_NUM_33
+#define X_DIRECTION_PIN GPIO_NUM_25
+#define Y_STEP_PIN GPIO_NUM_26
+#define Y_DIRECTION_PIN GPIO_NUM_27
+#define Z_STEP_PIN GPIO_NUM_14
+#define Z_DIRECTION_PIN GPIO_NUM_12
+#define Y2_STEP_PIN GPIO_NUM_13 // ganged motor
+#define Y2_DIRECTION_PIN GPIO_NUM_32 // ganged motor
+#define STEPPERS_DISABLE_PIN GPIO_NUM_15
+
+#define USE_GANGED_AXES
+#define Y_AXIS_SQUARING
+
+#define SPINDLE_OUTPUT_PIN GPIO_NUM_2 // labeled SpinPWM
+#define SPINDLE_ENABLE_PIN GPIO_NUM_17 // labeled SpinEnbl
+#define LASER_OUTPUT_PIN GPIO_NUM_21
+
+#define X_LIMIT_PIN GPIO_NUM_36
+#define Y_LIMIT_PIN GPIO_NUM_39
+#define Z_LIMIT_PIN GPIO_NUM_34
+//#define A_LIMIT_PIN GPIO_NUM_35
+
+#define PROBE_PIN GPIO_NUM_16
+#define COOLANT_MIST_PIN GPIO_NUM_22
+
+#ifdef INVERT_CONTROL_PIN_MASK
+ #undef INVERT_CONTROL_PIN_MASK
+#endif
+
+#define INVERT_CONTROL_PIN_MASK B1110
+
+#define CONTROL_RESET_PIN GPIO_NUM_4 //4 labeled Reset
+#define CONTROL_FEED_HOLD_PIN GPIO_NUM_21 //21 labeled Hold
+#define CONTROL_CYCLE_START_PIN GPIO_NUM_0 //0 labeled Start
\ No newline at end of file
diff --git a/Grbl_Esp32/src/Machines/makerfr_v2_XYZA.h b/Grbl_Esp32/src/Machines/makerfr_v2_XYZA.h
new file mode 100644
index 000000000..fba055b73
--- /dev/null
+++ b/Grbl_Esp32/src/Machines/makerfr_v2_XYZA.h
@@ -0,0 +1,66 @@
+#pragma once
+// clang-format off
+
+/*
+ makerfr_v2_XYZA.h
+ Part of Grbl_ESP32
+
+ Pin assignments for the RS-CNC32 board (4 axis with external drivers)
+ https://github.com/bdring/4_Axis_SPI_CNC
+
+ 2018 - Bart Dring
+ 2020 - Mitch Bradley
+
+ Grbl_ESP32 is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Grbl is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Grbl_ESP32. If not, see .
+*/
+
+#define MACHINE_NAME "MakerFr GRBL 32 bits Board V2 XYZA"
+
+#ifdef N_AXIS
+ #undef N_AXIS
+#endif
+#define N_AXIS 4
+
+#define X_STEP_PIN GPIO_NUM_33
+#define X_DIRECTION_PIN GPIO_NUM_25
+#define Y_STEP_PIN GPIO_NUM_26
+#define Y_DIRECTION_PIN GPIO_NUM_27
+#define Z_STEP_PIN GPIO_NUM_14
+#define Z_DIRECTION_PIN GPIO_NUM_12
+#define A_STEP_PIN GPIO_NUM_13
+#define A_DIRECTION_PIN GPIO_NUM_32
+#define STEPPERS_DISABLE_PIN GPIO_NUM_15
+
+#define SPINDLE_OUTPUT_PIN GPIO_NUM_2 // labeled SpinPWM
+#define SPINDLE_ENABLE_PIN GPIO_NUM_17 // labeled SpinEnbl
+#define LASER_OUTPUT_PIN GPIO_NUM_2
+
+#define X_LIMIT_PIN GPIO_NUM_36
+#define Y_LIMIT_PIN GPIO_NUM_39
+#define Z_LIMIT_PIN GPIO_NUM_34
+#define A_LIMIT_PIN GPIO_NUM_35
+
+#define PROBE_PIN GPIO_NUM_16
+#define COOLANT_MIST_PIN GPIO_NUM_22
+
+#ifdef INVERT_CONTROL_PIN_MASK
+ #undef INVERT_CONTROL_PIN_MASK
+#endif
+
+#define INVERT_CONTROL_PIN_MASK B1110
+
+#define CONTROL_RESET_PIN GPIO_NUM_4 //4 labeled Reset
+#define CONTROL_FEED_HOLD_PIN GPIO_NUM_21 //21 labeled Hold
+#define CONTROL_CYCLE_START_PIN GPIO_NUM_0 //0 labeled Start
+
From f9e682668ca95f13683faab6338947a1c27530f9 Mon Sep 17 00:00:00 2001
From: rominetb44 <32679436+rominetb44@users.noreply.github.com>
Date: Mon, 29 May 2023 19:45:18 +0200
Subject: [PATCH 4/8] Update RS-CNC32.
---
Grbl_Esp32/src/Defaults.h | 66 +++++++++++++++++++--------------------
1 file changed, 33 insertions(+), 33 deletions(-)
diff --git a/Grbl_Esp32/src/Defaults.h b/Grbl_Esp32/src/Defaults.h
index ace8e55a1..3742c37b6 100644
--- a/Grbl_Esp32/src/Defaults.h
+++ b/Grbl_Esp32/src/Defaults.h
@@ -39,7 +39,7 @@
// Grbl generic default settings. Should work across different machines.
#ifndef DEFAULT_STEP_PULSE_MICROSECONDS
-# define DEFAULT_STEP_PULSE_MICROSECONDS 3 // $0
+# define DEFAULT_STEP_PULSE_MICROSECONDS 5 // $0
#endif
#ifndef DEFAULT_STEP_ENABLE_DELAY
@@ -51,7 +51,7 @@
#endif
#ifndef DEFAULT_STEPPER_IDLE_LOCK_TIME
-# define DEFAULT_STEPPER_IDLE_LOCK_TIME 250 // $1 msec (0-254, 255 keeps steppers enabled)
+# define DEFAULT_STEPPER_IDLE_LOCK_TIME 255 // $1 msec (0-254, 255 keeps steppers enabled)
#endif
#ifndef DEFAULT_STEPPING_INVERT_MASK
@@ -71,7 +71,7 @@
#endif
#ifndef DEFAULT_INVERT_PROBE_PIN
-# define DEFAULT_INVERT_PROBE_PIN 0 // $6 boolean
+# define DEFAULT_INVERT_PROBE_PIN 1 // $6 boolean
#endif
#ifndef DEFAULT_STATUS_REPORT_MASK
@@ -99,11 +99,11 @@
#endif
#ifndef DEFAULT_HARD_LIMIT_ENABLE
-# define DEFAULT_HARD_LIMIT_ENABLE 0 // $21 false
+# define DEFAULT_HARD_LIMIT_ENABLE 1 // $21 false
#endif
#ifndef DEFAULT_HOMING_ENABLE
-# define DEFAULT_HOMING_ENABLE 0 // $22 false
+# define DEFAULT_HOMING_ENABLE 1 // $22 false
#endif
#ifndef DEFAULT_HOMING_DIR_MASK
@@ -123,7 +123,7 @@
#endif
#ifndef DEFAULT_HOMING_PULLOFF
-# define DEFAULT_HOMING_PULLOFF 1.0 // $27 mm
+# define DEFAULT_HOMING_PULLOFF 3.0 // $27 mm
#endif
#ifndef DEFAULT_HOMING_SQUARED_AXES
@@ -156,11 +156,11 @@
// ======== SPINDLE STUFF ====================
#ifndef SPINDLE_TYPE
-# define SPINDLE_TYPE SpindleType::NONE
+# define SPINDLE_TYPE SpindleType::PWM
#endif
#ifndef DEFAULT_SPINDLE_RPM_MIN // $31
-# define DEFAULT_SPINDLE_RPM_MIN 0.0 // rpm
+# define DEFAULT_SPINDLE_RPM_MIN 1.0 // rpm
#endif
#ifndef DEFAULT_LASER_MODE // $32
@@ -172,11 +172,11 @@
#endif
#ifndef DEFAULT_SPINDLE_RPM_MAX // $30
-# define DEFAULT_SPINDLE_RPM_MAX 1000.0 // rpm
+# define DEFAULT_SPINDLE_RPM_MAX 24000.0 // rpm
#endif
#ifndef DEFAULT_SPINDLE_FREQ
-# define DEFAULT_SPINDLE_FREQ 5000.0 // $33 Hz (extended set)
+# define DEFAULT_SPINDLE_FREQ 1000.0 // $33 Hz (extended set)
#endif
#ifndef DEFAULT_SPINDLE_OFF_VALUE
@@ -259,13 +259,13 @@
// =========== AXIS RESOLUTION ======
#ifndef DEFAULT_X_STEPS_PER_MM
-# define DEFAULT_X_STEPS_PER_MM 100.0
+# define DEFAULT_X_STEPS_PER_MM 60.0
#endif
#ifndef DEFAULT_Y_STEPS_PER_MM
-# define DEFAULT_Y_STEPS_PER_MM 100.0
+# define DEFAULT_Y_STEPS_PER_MM 60.0
#endif
#ifndef DEFAULT_Z_STEPS_PER_MM
-# define DEFAULT_Z_STEPS_PER_MM 100.0
+# define DEFAULT_Z_STEPS_PER_MM 400.0
#endif
#ifndef DEFAULT_A_STEPS_PER_MM
# define DEFAULT_A_STEPS_PER_MM 100.0
@@ -280,10 +280,10 @@
// ============ AXIS MAX SPPED =========
#ifndef DEFAULT_X_MAX_RATE
-# define DEFAULT_X_MAX_RATE 1000.0 // mm/min
+# define DEFAULT_X_MAX_RATE 2500.0 // mm/min
#endif
#ifndef DEFAULT_Y_MAX_RATE
-# define DEFAULT_Y_MAX_RATE 1000.0 // mm/min
+# define DEFAULT_Y_MAX_RATE 2500.0 // mm/min
#endif
#ifndef DEFAULT_Z_MAX_RATE
# define DEFAULT_Z_MAX_RATE 1000.0 // mm/min
@@ -302,13 +302,13 @@
#define SEC_PER_MIN_SQ (60.0 * 60.0) // Seconds Per Minute Squared, for acceleration conversion
// Default accelerations are expressed in mm/sec^2
#ifndef DEFAULT_X_ACCELERATION
-# define DEFAULT_X_ACCELERATION 200.0
+# define DEFAULT_X_ACCELERATION 80.0
#endif
#ifndef DEFAULT_Y_ACCELERATION
-# define DEFAULT_Y_ACCELERATION 200.0
+# define DEFAULT_Y_ACCELERATION 80.0
#endif
#ifndef DEFAULT_Z_ACCELERATION
-# define DEFAULT_Z_ACCELERATION 200.0
+# define DEFAULT_Z_ACCELERATION 50.0
#endif
#ifndef DEFAULT_A_ACCELERATION
# define DEFAULT_A_ACCELERATION 200.0
@@ -323,13 +323,13 @@
// ========= AXIS MAX TRAVEL ============
#ifndef DEFAULT_X_MAX_TRAVEL
-# define DEFAULT_X_MAX_TRAVEL 300.0 // $130 mm NOTE: Must be a positive value.
+# define DEFAULT_X_MAX_TRAVEL 550.0 // $130 mm NOTE: Must be a positive value.
#endif
#ifndef DEFAULT_Y_MAX_TRAVEL
-# define DEFAULT_Y_MAX_TRAVEL 300.0 // mm NOTE: Must be a positive value.
+# define DEFAULT_Y_MAX_TRAVEL 570.0 // mm NOTE: Must be a positive value.
#endif
#ifndef DEFAULT_Z_MAX_TRAVEL
-# define DEFAULT_Z_MAX_TRAVEL 300.0 // mm NOTE: Must be a positive value.
+# define DEFAULT_Z_MAX_TRAVEL 100.0 // mm NOTE: Must be a positive value.
#endif
#ifndef DEFAULT_A_MAX_TRAVEL
# define DEFAULT_A_MAX_TRAVEL 300.0 // mm NOTE: Must be a positive value.
@@ -386,43 +386,43 @@
// ========== Motor current (SPI Drivers ) =============
#ifndef DEFAULT_X_CURRENT
-# define DEFAULT_X_CURRENT 0.8 // $140 current in amps (extended set)
+# define DEFAULT_X_CURRENT 0.25 // $140 current in amps (extended set)
#endif
#ifndef DEFAULT_Y_CURRENT
-# define DEFAULT_Y_CURRENT 0.8 // $141 current in amps (extended set)
+# define DEFAULT_Y_CURRENT 0.25 // $141 current in amps (extended set)
#endif
#ifndef DEFAULT_Z_CURRENT
-# define DEFAULT_Z_CURRENT 0.8 // $142 current in amps (extended set)
+# define DEFAULT_Z_CURRENT 0.25 // $142 current in amps (extended set)
#endif
#ifndef DEFAULT_A_CURRENT
-# define DEFAULT_A_CURRENT 0.8 // $143 current in amps (extended set)
+# define DEFAULT_A_CURRENT 0.25 // $143 current in amps (extended set)
#endif
#ifndef DEFAULT_B_CURRENT
-# define DEFAULT_B_CURRENT 0.8 // $144 current in amps (extended set)
+# define DEFAULT_B_CURRENT 0.25 // $144 current in amps (extended set)
#endif
#ifndef DEFAULT_C_CURRENT
-# define DEFAULT_C_CURRENT 0.8 // $145 current in amps (extended set)
+# define DEFAULT_C_CURRENT 0.25 // $145 current in amps (extended set)
#endif
// ========== Motor hold current (SPI Drivers ) =============
#ifndef DEFAULT_X_HOLD_CURRENT
-# define DEFAULT_X_HOLD_CURRENT 0.4 // $150 current in amps (extended set)
+# define DEFAULT_X_HOLD_CURRENT 0.125 // $150 current in amps (extended set)
#endif
#ifndef DEFAULT_Y_HOLD_CURRENT
-# define DEFAULT_Y_HOLD_CURRENT 0.4 // $151 current in amps (extended set)
+# define DEFAULT_Y_HOLD_CURRENT 0.125 // $151 current in amps (extended set)
#endif
#ifndef DEFAULT_Z_HOLD_CURRENT
-# define DEFAULT_Z_HOLD_CURRENT 0.4 // $152 current in amps (extended set)
+# define DEFAULT_Z_HOLD_CURRENT 0.125 // $152 current in amps (extended set)
#endif
#ifndef DEFAULT_A_HOLD_CURRENT
-# define DEFAULT_A_HOLD_CURRENT 0.4 // $153 current in amps (extended set)
+# define DEFAULT_A_HOLD_CURRENT 0.125 // $153 current in amps (extended set)
#endif
#ifndef DEFAULT_B_HOLD_CURRENT
-# define DEFAULT_B_HOLD_CURRENT 0.4 // $154 current in amps (extended set)
+# define DEFAULT_B_HOLD_CURRENT 0.125 // $154 current in amps (extended set)
#endif
#ifndef DEFAULT_C_HOLD_CURRENT
-# define DEFAULT_C_HOLD_CURRENT 0.4 // $154 current in amps (extended set)
+# define DEFAULT_C_HOLD_CURRENT 0.125 // $154 current in amps (extended set)
#endif
// ========== Microsteps (SPI Drivers ) ================
From 546401935cd9c67412c014e6cc51358b17aec11c Mon Sep 17 00:00:00 2001
From: rominetb44 <32679436+rominetb44@users.noreply.github.com>
Date: Mon, 29 May 2023 19:46:02 +0200
Subject: [PATCH 5/8] Update RS-CNC32.
---
Grbl_Esp32/src/Machine.h | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/Grbl_Esp32/src/Machine.h b/Grbl_Esp32/src/Machine.h
index 11ab84065..09f9b71fd 100644
--- a/Grbl_Esp32/src/Machine.h
+++ b/Grbl_Esp32/src/Machine.h
@@ -8,11 +8,12 @@
// !!! For initial testing, start with test_drive.h which disables
// all I/O pins
// #include "Machines/atari_1020.h"
-# include "Machines/test_drive.h"
+//# include "Machines/test_drive.h"
// !!! For actual use, change the line above to select a board
// from Machines/, for example:
-// #include "Machines/3axis_v4.h"
+ #include "Machines/makerfr_v2_XYZA.h"
+
// === OEM Single File Configuration Option
// OEMs that wish to publish source code that is configured for a
From f5150d6cdcd4533c33fa2c52eafb98bb14df0b89 Mon Sep 17 00:00:00 2001
From: rominetb44 <32679436+rominetb44@users.noreply.github.com>
Date: Mon, 29 May 2023 19:47:01 +0200
Subject: [PATCH 6/8] Update RS-CNC32.
---
Grbl_Esp32/src/Config.h | 38 +++++++++++++++++++++++++-------------
1 file changed, 25 insertions(+), 13 deletions(-)
diff --git a/Grbl_Esp32/src/Config.h b/Grbl_Esp32/src/Config.h
index ffba41485..a18e90f48 100644
--- a/Grbl_Esp32/src/Config.h
+++ b/Grbl_Esp32/src/Config.h
@@ -56,7 +56,7 @@ Some features should not be changed. See notes below.
// For example B1101 will invert the function of the Reset pin.
#define INVERT_CONTROL_PIN_MASK B00001111
-// #define ENABLE_CONTROL_SW_DEBOUNCE // Default disabled. Uncomment to enable.
+#define ENABLE_CONTROL_SW_DEBOUNCE // Default disabled. Uncomment to enable.
#define CONTROL_SW_DEBOUNCE_PERIOD 32 // in milliseconds default 32 microseconds
#define USE_RMT_STEPS
@@ -202,7 +202,7 @@ enum class Cmd : uint8_t {
// If homing is enabled, homing init lock sets Grbl into an alarm state upon power up. This forces
// the user to perform the homing cycle (or override the locks) before doing anything else. This is
// mainly a safety feature to remind the user to home, since position is unknown to Grbl.
-#define HOMING_INIT_LOCK // Comment to disable
+//#define HOMING_INIT_LOCK // Comment to disable
// Number of homing cycles performed after when the machine initially jogs to limit switches.
// This help in preventing overshoot and should improve repeatability. This value should be one or
@@ -264,7 +264,7 @@ static const uint8_t NHomingLocateCycle = 1; // Integer (1-128)
// will be applied to all of them. This is useful when a user has a mixed set of limit pins with both
// normally-open(NO) and normally-closed(NC) switches installed on their machine.
// NOTE: PLEASE DO NOT USE THIS, unless you have a situation that needs it.
-// #define INVERT_LIMIT_PIN_MASK (bit(X_AXIS)|bit(Y_AXIS)) // Default disabled. Uncomment to enable.
+#define INVERT_LIMIT_PIN_MASK (bit(X_AXIS)|bit(Y_AXIS)|bit(Z_AXIS)) // Default disabled. Uncomment to enable.
// Inverts the selected coolant pin from low-disabled/high-enabled to low-enabled/high-disabled. Useful
// for some pre-built electronic boards.
@@ -486,7 +486,7 @@ const int DWELL_TIME_STEP = 50; // Integer (1-255) (milliseconds)
// A simple software debouncing feature for hard limit switches. When enabled, the limit
// switch interrupt unblock a waiting task which will recheck the limit switch pins after
// a short delay. Default disabled
-//#define ENABLE_SOFTWARE_DEBOUNCE // Default disabled. Uncomment to enable.
+#define ENABLE_SOFTWARE_DEBOUNCE // Default disabled. Uncomment to enable.
const int DEBOUNCE_PERIOD = 32; // in milliseconds default 32 microseconds
// Configures the position after a probing cycle during Grbl's check mode. Disabled sets
@@ -523,7 +523,7 @@ const int DEBOUNCE_PERIOD = 32; // in milliseconds default 32 microseconds
// Some senders may not be able to parse anything different from the original set
// You can still set these like $33=5000, but you cannot read them back.
// Default is off to limit support issues...you can enable here or in your machine definition file
-// #define SHOW_EXTENDED_SETTINGS
+#define SHOW_EXTENDED_SETTINGS
// Writing to non-volatile storage (NVS) can take a long time and interfere with timely instruction
// execution, causing problems for the stepper ISRs and serial comm ISRs and subsequent loss of
@@ -590,19 +590,31 @@ const double PARKING_PULLOUT_INCREMENT = 5.0; // Spindle pull-out and plunge
// Enables a piecewise linear model of the spindle PWM/speed output. Requires a solution by the
// 'fit_nonlinear_spindle.py' script in the /doc/script folder of the repo. See file comments
// on how to gather spindle data and run the script to generate a solution.
-// #define ENABLE_PIECEWISE_LINEAR_SPINDLE // Default disabled. Uncomment to enable.
+//#define ENABLE_PIECEWISE_LINEAR_SPINDLE // Not implemented yet
// N_PIECES, RPM_MAX, RPM_MIN, RPM_POINTxx, and RPM_LINE_XX constants are all set and given by
// the 'fit_nonlinear_spindle.py' script solution. Used only when ENABLE_PIECEWISE_LINEAR_SPINDLE
// is enabled. Make sure the constant values are exactly the same as the script solution.
// NOTE: When N_PIECES < 4, unused RPM_LINE and RPM_POINT defines are not required and omitted.
+
+
/*
-#define N_PIECES 4 // Integer (1-4). Number of piecewise lines used in script solution.
-#define RPM_MAX 11686.4 // Max RPM of model. $30 > RPM_MAX will be limited to RPM_MAX.
-#define RPM_MIN 202.5 // Min RPM of model. $31 < RPM_MIN will be limited to RPM_MIN.
+#define N_PIECES 4
+#define RPM_MAX 24162.9
+#define RPM_MIN 118.4
+#define RPM_POINT12 3177.2
+#define RPM_POINT23 13581.6
+#define RPM_POINT34 21467.2
+#define RPM_LINE_A1 5.878084e-01
+#define RPM_LINE_B1 6.759473e+01
+#define RPM_LINE_A2 9.803514e-01
+#define RPM_LINE_B2 1.314789e+03
+#define RPM_LINE_A3 1.014510e+00
+#define RPM_LINE_B3 1.778715e+03
+#define RPM_LINE_A4 1.483485e+00
+#define RPM_LINE_B4 1.184633e+04
*/
-const int N_PIECES = 3;
-
-const double RPM_MAX = 23935.2;
-const double RPM_MIN = 2412.2;
+//const int N_PIECES = 4;
+//const double RPM_MAX = 24513.2;
+//const double RPM_MIN = 125.2;
From 303a812575ee2136714407aba6caca2596d45d0a Mon Sep 17 00:00:00 2001
From: rominetb44 <32679436+rominetb44@users.noreply.github.com>
Date: Mon, 26 Jun 2023 08:07:49 +0200
Subject: [PATCH 7/8] Update Config.h
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Wifi en mode STA par défaut.
---
Grbl_Esp32/src/Config.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/Grbl_Esp32/src/Config.h b/Grbl_Esp32/src/Config.h
index a18e90f48..956cd7d59 100644
--- a/Grbl_Esp32/src/Config.h
+++ b/Grbl_Esp32/src/Config.h
@@ -93,8 +93,8 @@ const int MAX_N_AXIS = 6;
#define BAUD_RATE 115200
//Connect to your local AP with these credentials
-//#define CONNECT_TO_SSID "your SSID"
-//#define SSID_PASSWORD "your SSID password"
+#define CONNECT_TO_SSID "your SSID"
+#define SSID_PASSWORD "your SSID password"
//CONFIGURE_EYECATCH_BEGIN (DO NOT MODIFY THIS LINE)
#define ENABLE_BLUETOOTH // enable bluetooth
From 2150ebaaf6ad13588fda0a8532c801aa1d3022b9 Mon Sep 17 00:00:00 2001
From: rominetb44 <32679436+rominetb44@users.noreply.github.com>
Date: Sun, 3 Sep 2023 18:06:21 +0200
Subject: [PATCH 8/8] Fix assertion "pbuf_free: p->ref > 0"
---
Grbl_Esp32/src/Serial.cpp | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)
diff --git a/Grbl_Esp32/src/Serial.cpp b/Grbl_Esp32/src/Serial.cpp
index cfbe6f330..3bc0b907b 100644
--- a/Grbl_Esp32/src/Serial.cpp
+++ b/Grbl_Esp32/src/Serial.cpp
@@ -85,6 +85,23 @@ void unlockVariable(){
xSemaphoreGive(bufferSemaphore);
}
+//Semaphore to protect the TelnetServer class which are not thread safe (see wifiCient class)
+SemaphoreHandle_t telnetSemaphore;
+void createtelnetSemaphore(){
+ telnetSemaphore = xSemaphoreCreateMutex();
+ xSemaphoreGive( ( telnetSemaphore) );
+}
+
+// Lock the variable
+BaseType_t locktelnetVariable(){
+ return xSemaphoreTake(telnetSemaphore, ( TickType_t ) 500/*portMAX_DELAY*/);
+}
+
+// give back the semaphore.
+void unlocktelnetVariable(){
+ xSemaphoreGive(telnetSemaphore);
+}
+
// Returns the number of bytes available in a client buffer.
uint8_t client_get_rx_buffer_available(uint8_t client) {
uint8_t availablebuffer = 0;
@@ -123,6 +140,7 @@ void client_init() {
xTaskCreatePinnedToCore(heapCheckTask, "heapTask", 2000, NULL, 1, NULL, 1);
#endif
createSemaphore();
+ createtelnetSemaphore();
#ifdef REVERT_TO_ARDUINO_SERIAL
Serial.begin(BAUD_RATE, SERIAL_8N1, 3, 1, false);
client_reset_read_buffer(CLIENT_ALL);
@@ -219,7 +237,10 @@ void clientCheckTask(void* pvParameters) {
} // if something available
WebUI::COMMANDS::handle();
#ifdef ENABLE_WIFI
+ if (locktelnetVariable() == pdTRUE ) {
WebUI::wifi_config.handle();
+ unlocktelnetVariable();
+ }
#endif
#ifdef ENABLE_BLUETOOTH
WebUI::bt_config.handle();
@@ -390,7 +411,10 @@ void client_write(uint8_t client, const char* text) {
#endif
#if defined(ENABLE_WIFI) && defined(ENABLE_TELNET)
if (client == CLIENT_TELNET || client == CLIENT_ALL) {
+ if (locktelnetVariable() == pdTRUE ) {
WebUI::telnet_server.write((const uint8_t*)text, strlen(text));
+ unlocktelnetVariable();
+ }
}
#endif
if (client == CLIENT_SERIAL || client == CLIENT_ALL) {