Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/bugfix-2.1.x' into BTT_OctoPro…
Browse files Browse the repository at this point in the history
…-2.1.x
  • Loading branch information
smiksky committed Aug 15, 2023
2 parents 72b3ee7 + 79f6d9b commit 1eb4812
Show file tree
Hide file tree
Showing 42 changed files with 445 additions and 273 deletions.
2 changes: 1 addition & 1 deletion Marlin/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -1513,7 +1513,7 @@
*
* Tune and Adjust
* - Probe Offsets can be tuned at runtime with 'M851', LCD menus, babystepping, etc.
* - PROBE_OFFSET_WIZARD (configuration_adv.h) can be used for setting the Z offset.
* - PROBE_OFFSET_WIZARD (Configuration_adv.h) can be used for setting the Z offset.
*
* Assuming the typical work area orientation:
* - Probe to RIGHT of the Nozzle has a Positive X offset
Expand Down
12 changes: 8 additions & 4 deletions Marlin/Configuration_adv.h
Original file line number Diff line number Diff line change
Expand Up @@ -4228,13 +4228,17 @@
#endif

/**
* WiFi Support (Espressif ESP32 WiFi)
* Native ESP32 board with WiFi or add-on ESP32 WiFi-101 module
*/
//#define WIFISUPPORT // Marlin embedded WiFi management
//#define WIFISUPPORT // Marlin embedded WiFi management. Not needed for simple WiFi serial port.
//#define ESP3D_WIFISUPPORT // ESP3D Library WiFi management (https://github.com/luc-github/ESP3DLib)

#if ANY(WIFISUPPORT, ESP3D_WIFISUPPORT)
//#define WEBSUPPORT // Start a webserver (which may include auto-discovery)
/**
* Extras for an ESP32-based motherboard with WIFISUPPORT
* These options don't apply to add-on WiFi modules based on ESP32 WiFi101.
*/
#if ENABLED(WIFISUPPORT)
//#define WEBSUPPORT // Start a webserver (which may include auto-discovery) using SPIFFS
//#define OTASUPPORT // Support over-the-air firmware updates
//#define WIFI_CUSTOM_COMMAND // Accept feature config commands (e.g., WiFi ESP3D) from the host

Expand Down
2 changes: 1 addition & 1 deletion Marlin/Version.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
* here we define this default string as the date where the latest release
* version was tagged.
*/
//#define STRING_DISTRIBUTION_DATE "2023-08-05"
//#define STRING_DISTRIBUTION_DATE "2023-08-14"

/**
* Defines a generic printer name to be output to the LCD after booting Marlin.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
#include "../../shared/HAL_SPI.h"

#ifndef LCD_SPI_SPEED
#define LCD_SPI_SPEED SPI_QUARTER_SPEED
#define LCD_SPI_SPEED SPI_HALF_SPEED
#endif

void u8g_SetPIOutput(u8g_t *u8g, uint8_t pin_index) {
Expand All @@ -85,7 +85,6 @@ void u8g_SetPILevel(u8g_t *u8g, uint8_t pin_index, uint8_t level) {

uint8_t u8g_com_samd21_st7920_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) {

static SPISettings lcdSPIConfig;

switch (msg) {
case U8G_COM_MSG_STOP:
Expand All @@ -99,7 +98,6 @@ uint8_t u8g_com_samd21_st7920_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val
u8g_SetPILevel(u8g, U8G_PI_CS, LOW);

spiBegin();
lcdSPIConfig = SPISettings(900000, MSBFIRST, SPI_MODE0);
u8g->pin_list[U8G_PI_A0_STATE] = 0;
break;

Expand All @@ -117,7 +115,7 @@ uint8_t u8g_com_samd21_st7920_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val
break;

case U8G_COM_MSG_WRITE_BYTE:
SPI.beginTransaction(lcdSPIConfig);
spiBeginTransaction(LCD_SPI_SPEED, MSBFIRST, SPI_MODE0);

if (u8g->pin_list[U8G_PI_A0_STATE] == 0) { // command
SPI.transfer(0x0f8); u8g->pin_list[U8G_PI_A0_STATE] = 2;
Expand All @@ -132,7 +130,7 @@ uint8_t u8g_com_samd21_st7920_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val
break;

case U8G_COM_MSG_WRITE_SEQ:
SPI.beginTransaction(lcdSPIConfig);
spiBeginTransaction(LCD_SPI_SPEED, MSBFIRST, SPI_MODE0);

if (u8g->pin_list[U8G_PI_A0_STATE] == 0 ) { // command
SPI.transfer(0x0f8); u8g->pin_list[U8G_PI_A0_STATE] = 2;
Expand Down
66 changes: 45 additions & 21 deletions Marlin/src/HAL/STM32/msc_sd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@
#define BLOCK_SIZE 512
#define PRODUCT_ID 0x29

#ifndef SD_MULTIBLOCK_RETRY_CNT
#define SD_MULTIBLOCK_RETRY_CNT 1
#elif SD_MULTIBLOCK_RETRY_CNT < 1
#error "SD_MULTIBLOCK_RETRY_CNT must be greater than or equal to 1."
#endif

class Sd2CardUSBMscHandler : public USBMscHandler {
public:
DiskIODriver* diskIODriver() {
Expand All @@ -58,44 +64,62 @@ class Sd2CardUSBMscHandler : public USBMscHandler {
// single block
if (blkLen == 1) {
hal.watchdog_refresh();
sd2card->writeBlock(blkAddr, pBuf);
return true;
return sd2card->writeBlock(blkAddr, pBuf);
}

// multi block optimization
sd2card->writeStart(blkAddr, blkLen);
while (blkLen--) {
hal.watchdog_refresh();
sd2card->writeData(pBuf);
pBuf += BLOCK_SIZE;
bool done = false;
for (uint16_t rcount = SD_MULTIBLOCK_RETRY_CNT; !done && rcount--;) {
uint8_t *cBuf = pBuf;
sd2card->writeStart(blkAddr);
bool okay = true; // Assume success
for (uint32 i = blkLen; i--;) {
hal.watchdog_refresh();
if (!sd2card->writeData(cBuf)) { // Write. Did it fail?
sd2card->writeStop(); // writeStop for new writeStart
okay = false; // Failed, so retry
break; // Go to while... below
}
cBuf += BLOCK_SIZE;
}
done = okay; // Done if no error occurred
}
sd2card->writeStop();
return true;

if (done) sd2card->writeStop();
return done;
}

bool Read(uint8_t *pBuf, uint32_t blkAddr, uint16_t blkLen) {
auto sd2card = diskIODriver();
// single block
if (blkLen == 1) {
hal.watchdog_refresh();
sd2card->readBlock(blkAddr, pBuf);
return true;
return sd2card->readBlock(blkAddr, pBuf);
}

// multi block optimization
sd2card->readStart(blkAddr);
while (blkLen--) {
hal.watchdog_refresh();
sd2card->readData(pBuf);
pBuf += BLOCK_SIZE;
bool done = false;
for (uint16_t rcount = SD_MULTIBLOCK_RETRY_CNT; !done && rcount--;) {
uint8_t *cBuf = pBuf;
sd2card->readStart(blkAddr);
bool okay = true; // Assume success
for (uint32 i = blkLen; i--;) {
hal.watchdog_refresh();
if (!sd2card->readData(cBuf)) { // Read. Did it fail?
sd2card->readStop(); // readStop for new readStart
okay = false; // Failed, so retry
break; // Go to while... below
}
cBuf += BLOCK_SIZE;
}
done = okay; // Done if no error occurred
}
sd2card->readStop();
return true;
}

bool IsReady() {
return diskIODriver()->isReady();
if (done) sd2card->readStop();
return done;
}

bool IsReady() { return diskIODriver()->isReady(); }
};

Sd2CardUSBMscHandler usbMscHandler;
Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/core/boards.h
Original file line number Diff line number Diff line change
Expand Up @@ -318,9 +318,9 @@
//

#define BOARD_BTT_EBB42_V1_1 4000 // BigTreeTech EBB42 V1.1 (STM32G0B1CB)
#define BOARD_BTT_SKR_MINI_E3_V3_0 4001 // BigTreeTech SKR Mini E3 V3.0 (STM32G0B1RE)
#define BOARD_BTT_SKR_MINI_E3_V3_0 4001 // BigTreeTech SKR Mini E3 V3.0 (STM32G0B0RE / STM32G0B1RE)
#define BOARD_BTT_MANTA_E3_EZ_V1_0 4002 // BigTreeTech Manta E3 EZ V1.0 (STM32G0B1RE)
#define BOARD_BTT_MANTA_M4P_V1_0 4003 // BigTreeTech Manta M4P V1.0 (STM32G0B1RE)
#define BOARD_BTT_MANTA_M4P_V1_0 4003 // BigTreeTech Manta M4P V1.0 (STM32G0B0RE)
#define BOARD_BTT_MANTA_M5P_V1_0 4004 // BigTreeTech Manta M5P V1.0 (STM32G0B1RE)
#define BOARD_BTT_MANTA_M8P_V1_0 4005 // BigTreeTech Manta M8P V1.0 (STM32G0B1VE)
#define BOARD_BTT_MANTA_M8P_V1_1 4006 // BigTreeTech Manta M8P V1.1 (STM32G0B1VE)
Expand Down
27 changes: 15 additions & 12 deletions Marlin/src/feature/bedlevel/bdl/bdl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ bool BDS_Leveling::check(const uint16_t data, const bool raw_data/*=false*/, con
return true; // error
}
if (raw_data == true) {
if (hicheck && (data & 0x3FF) > 550)
SERIAL_ECHOLNPGM("BD Sensor mounted too high!");
if (hicheck && (data & 0x3FF) > 400)
SERIAL_ECHOLNPGM("Bad BD Sensor height! Recommended distance 0.5-2.0mm");
else if (!good_data(data))
SERIAL_ECHOLNPGM("Invalid data, please calibrate.");
else
Expand Down Expand Up @@ -109,7 +109,8 @@ void BDS_Leveling::process() {
static float zpos = 0.0f;
const millis_t ms = millis();
if (ELAPSED(ms, next_check_ms)) { // timed out (or first run)
next_check_ms = ms + (config_state < BDS_IDLE ? 200 : 50); // check at 5Hz or 20Hz
// Check at 1KHz, 5Hz, or 20Hz
next_check_ms = ms + (config_state == BDS_HOMING_Z ? 1 : (config_state < BDS_IDLE ? 200 : 50));

uint16_t tmp = 0;
const float cur_z = planner.get_axis_position_mm(Z_AXIS) - pos_zero_offset;
Expand All @@ -127,16 +128,14 @@ void BDS_Leveling::process() {
babystep.set_mm(Z_AXIS, cur_z - z_sensor);
DEBUG_ECHOLNPGM("BD:", z_sensor, ", Z:", cur_z, "|", current_position.z);
}
else {
babystep.set_mm(Z_AXIS, 0); //if (old_cur_z <= cur_z) Z_DIR_WRITE(HIGH);
//stepper.apply_directions(); // TODO: Remove this line as probably not needed
}
else
babystep.set_mm(Z_AXIS, 0);
}
#endif

old_cur_z = cur_z;
old_buf_z = current_position.z;
endstops.bdp_state_update(z_sensor <= 0.01f);
endstops.bdp_state_update(z_sensor <= BD_SENSOR_HOME_Z_POSITION);

#if HAS_STATUS_MESSAGE
static float old_z_sensor = 0;
Expand All @@ -149,8 +148,10 @@ void BDS_Leveling::process() {
}
#endif
}
else
stepper.apply_directions();
else if (config_state == BDS_HOMING_Z) {
SERIAL_ECHOLNPGM("Read:", tmp);
kill(F("BDsensor connect Err!"));
}

DEBUG_ECHOLNPGM("BD:", tmp & 0x3FF, " Z:", cur_z, "|", current_position.z);
if (TERN0(DEBUG_OUT_BD, BD_I2C_SENSOR.BD_Check_OddEven(tmp) == 0)) DEBUG_ECHOLNPGM("CRC error");
Expand Down Expand Up @@ -233,11 +234,13 @@ void BDS_Leveling::process() {
sprintf_P(tmp_1, PSTR("G1Z%d.%d"), int(zpos), int(zpos * 10) % 10);
gcode.process_subcommands_now(tmp_1);
SERIAL_ECHO(tmp_1); SERIAL_ECHOLNPGM(", Z:", current_position.z);
for (float tmp_k = 0; abs(zpos - tmp_k) > 0.004f;) {
uint16_t failcount = 300;
for (float tmp_k = 0; abs(zpos - tmp_k) > 0.006f && failcount--;) {
tmp_k = planner.get_axis_position_mm(Z_AXIS) - pos_zero_offset;
safe_delay(10);
if (!failcount--) break;
}
safe_delay(zpos <= 0.4f ? 600 : 100);
safe_delay(600);
tmp = uint16_t((zpos + 0.00001f) * 10);
BD_I2C_SENSOR.BD_i2c_write(tmp);
SERIAL_ECHOLNPGM("w:", tmp, ", Z:", zpos);
Expand Down
4 changes: 4 additions & 0 deletions Marlin/src/feature/bedlevel/bdl/bdl.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@

#include <stdint.h>

#ifndef BD_SENSOR_HOME_Z_POSITION
#define BD_SENSOR_HOME_Z_POSITION 0.5
#endif

enum BDS_State : int8_t {
BDS_IDLE,
BDS_VERSION = -1,
Expand Down
10 changes: 8 additions & 2 deletions Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -786,14 +786,18 @@ void unified_bed_leveling::shift_mesh_height() {
}
#endif

best = do_furthest
#ifndef HUGE_VALF
#define HUGE_VALF (10e100F)
#endif

best = do_furthest // Points with valid data or HUGE_VALF are skipped
? find_furthest_invalid_mesh_point()
: find_closest_mesh_point_of_type(INVALID, nearby, true);

if (best.pos.x >= 0) { // mesh point found and is reachable by probe
TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(best.pos, ExtUI::G29_POINT_START));
const float measured_z = probe.probe_at_point(best.meshpos(), stow_probe ? PROBE_PT_STOW : PROBE_PT_RAISE, param.V_verbosity);
z_values[best.pos.x][best.pos.y] = measured_z;
z_values[best.pos.x][best.pos.y] = isnan(measured_z) ? HUGE_VALF : measured_z; // Mark invalid point already probed with HUGE_VALF to omit it in the next loop
#if ENABLED(EXTENSIBLE_UI)
ExtUI::onMeshUpdate(best.pos, ExtUI::G29_POINT_FINISH);
ExtUI::onMeshUpdate(best.pos, measured_z);
Expand All @@ -803,6 +807,8 @@ void unified_bed_leveling::shift_mesh_height() {

} while (best.pos.x >= 0 && --count);

GRID_LOOP(x, y) if (z_values[x][y] == HUGE_VALF) z_values[x][y] = NAN; // Restore NAN for HUGE_VALF marks

TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(best.pos, ExtUI::G29_FINISH));

// Release UI during stow to allow for PAUSE_BEFORE_DEPLOY_STOW
Expand Down
1 change: 1 addition & 0 deletions Marlin/src/gcode/bedlevel/abl/G29.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,7 @@ G29_TYPE GcodeSuite::G29() {
}
//if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM_P(axis == Y_AXIS ? PSTR("Y=") : PSTR("X=", pos);

safe_delay(4);
abl.measured_z = current_position.z - bdl.read();
if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPGM("x_cur ", planner.get_axis_position_mm(X_AXIS), " z ", abl.measured_z);

Expand Down
16 changes: 8 additions & 8 deletions Marlin/src/gcode/calibrate/G33.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ void ac_setup(const bool reset_bed) {
#endif
}

void ac_cleanup(TERN_(HAS_MULTI_HOTEND, const uint8_t old_tool_index)) {
void ac_cleanup() {
TERN_(DELTA_HOME_TO_SAFE_ZONE, do_blocking_move_to_z(delta_clip_start_height));
TERN_(HAS_BED_PROBE, probe.stow());
restore_feedrate_and_scaling();
Expand All @@ -97,7 +97,7 @@ void print_signed_float(FSTR_P const prefix, const_float_t f) {
}

/**
* - Print the delta settings
* - Print the delta settings
*/
static void print_calibration_settings(const bool end_stops, const bool tower_angles) {
SERIAL_ECHOPGM(".Height:", delta_height);
Expand All @@ -123,7 +123,7 @@ static void print_calibration_settings(const bool end_stops, const bool tower_an
}

/**
* - Print the probe results
* - Print the probe results
*/
static void print_calibration_results(const float z_pt[NPP + 1], const bool tower_points, const bool opposite_points) {
SERIAL_ECHOPGM(". ");
Expand All @@ -147,7 +147,7 @@ static void print_calibration_results(const float z_pt[NPP + 1], const bool towe
}

/**
* - Calculate the standard deviation from the zero plane
* - Calculate the standard deviation from the zero plane
*/
static float std_dev_points(float z_pt[NPP + 1], const bool _0p_cal, const bool _1p_cal, const bool _4p_cal, const bool _4p_opp) {
if (!_0p_cal) {
Expand All @@ -165,7 +165,7 @@ static float std_dev_points(float z_pt[NPP + 1], const bool _0p_cal, const bool
}

/**
* - Probe a point
* - Probe a point
*/
static float calibration_probe(const xy_pos_t &xy, const bool stow, const bool probe_at_offset) {
#if HAS_BED_PROBE
Expand All @@ -177,7 +177,7 @@ static float calibration_probe(const xy_pos_t &xy, const bool stow, const bool p
}

/**
* - Probe a grid
* - Probe a grid
*/
static bool probe_calibration_points(float z_pt[NPP + 1], const int8_t probe_points, const float dcr, const bool towers_set, const bool stow_after_each, const bool probe_at_offset) {
const bool _0p_calibration = probe_points == 0,
Expand Down Expand Up @@ -501,7 +501,7 @@ void GcodeSuite::G33() {
zero_std_dev_old = zero_std_dev;
if (!probe_calibration_points(z_at_pt, probe_points, dcr, towers_set, stow_after_each, probe_at_offset)) {
SERIAL_ECHOLNPGM("Correct delta settings with M665 and M666");
return ac_cleanup(TERN_(HAS_MULTI_HOTEND, old_tool_index));
return ac_cleanup();
}
zero_std_dev = std_dev_points(z_at_pt, _0p_calibration, _1p_calibration, _4p_calibration, _4p_opposite_points);

Expand Down Expand Up @@ -678,7 +678,7 @@ void GcodeSuite::G33() {
}
while (((zero_std_dev < test_precision && iterations < 31) || iterations <= force_iterations) && zero_std_dev > calibration_precision);

ac_cleanup(TERN_(HAS_MULTI_HOTEND, old_tool_index));
ac_cleanup();

TERN_(FULL_REPORT_TO_HOST_FEATURE, set_and_report_grblstate(M_IDLE));
#if HAS_DELTA_SENSORLESS_PROBING
Expand Down
Loading

0 comments on commit 1eb4812

Please sign in to comment.