From 73932855609aa949fa13e3570659ce26c43b0ab8 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Fri, 20 Jan 2023 21:17:13 -0600 Subject: [PATCH] SDIO retry, hsd clock, etc. --- Marlin/src/HAL/STM32/sdio.cpp | 8 +++++++- Marlin/src/feature/stepper_driver_safety.cpp | 2 +- Marlin/src/gcode/config/M220.cpp | 15 +++++++-------- Marlin/src/sd/usb_flashdrive/lib-uhs2/settings.h | 10 +++++----- docs/Serial.md | 4 ++-- 5 files changed, 22 insertions(+), 17 deletions(-) diff --git a/Marlin/src/HAL/STM32/sdio.cpp b/Marlin/src/HAL/STM32/sdio.cpp index 41fe90b825..72518ef1cc 100644 --- a/Marlin/src/HAL/STM32/sdio.cpp +++ b/Marlin/src/HAL/STM32/sdio.cpp @@ -286,6 +286,9 @@ void HAL_SD_MspInit(SD_HandleTypeDef *hsd) { go_to_transfer_speed(); + hsd.Init.ClockPowerSave = SDIO_CLOCK_POWER_SAVE_ENABLE; + hsd.Init.ClockDiv = 8; + #if PINS_EXIST(SDIO_D1, SDIO_D2, SDIO_D3) // go to 4 bit wide mode if pins are defined retry_Cnt = retryCnt; for (;;) { @@ -433,7 +436,10 @@ bool SDIO_WriteBlock(uint32_t block, const uint8_t *src) { #else uint8_t retries = SDIO_READ_RETRIES; - while (retries--) if (SDIO_ReadWriteBlock_DMA(block, src, nullptr)) return true; + while (retries--) { + if (SDIO_ReadWriteBlock_DMA(block, src, nullptr)) return true; + delay(10); + } return false; #endif diff --git a/Marlin/src/feature/stepper_driver_safety.cpp b/Marlin/src/feature/stepper_driver_safety.cpp index b8762da9b0..d3fc161486 100644 --- a/Marlin/src/feature/stepper_driver_safety.cpp +++ b/Marlin/src/feature/stepper_driver_safety.cpp @@ -43,7 +43,7 @@ void stepper_driver_backward_check() { SET_INPUT(AXIS##_ENABLE_PIN); \ OUT_WRITE(AXIS##_STEP_PIN, false); \ delay(20); \ - if (READ(AXIS##_ENABLE_PIN) == false) { \ + if (READ(AXIS##_ENABLE_PIN) == LOW) { \ SBI(axis_plug_backward, BIT); \ stepper_driver_backward_error(F(STRINGIFY(AXIS))); \ } \ diff --git a/Marlin/src/gcode/config/M220.cpp b/Marlin/src/gcode/config/M220.cpp index c9070df803..6797df25d5 100644 --- a/Marlin/src/gcode/config/M220.cpp +++ b/Marlin/src/gcode/config/M220.cpp @@ -36,16 +36,15 @@ * R : Flag to restore the last-saved factor */ void GcodeSuite::M220() { + if (!parser.seen_any()) { + SERIAL_ECHOLNPGM("FR:", feedrate_percentage, "%"); + return; + } static int16_t backup_feedrate_percentage = 100; - if (parser.seen('B')) backup_feedrate_percentage = feedrate_percentage; - if (parser.seen('R')) feedrate_percentage = backup_feedrate_percentage; - + const int16_t now_feedrate_perc = feedrate_percentage; + if (parser.seen_test('R')) feedrate_percentage = backup_feedrate_percentage; + if (parser.seen_test('B')) backup_feedrate_percentage = now_feedrate_perc; if (parser.seenval('S')) feedrate_percentage = parser.value_int(); - if (!parser.seen_any()) { - SERIAL_ECHOPGM("FR:", feedrate_percentage); - SERIAL_CHAR('%'); - SERIAL_EOL(); - } } diff --git a/Marlin/src/sd/usb_flashdrive/lib-uhs2/settings.h b/Marlin/src/sd/usb_flashdrive/lib-uhs2/settings.h index 7ce7b5e6ba..268c0e1d1d 100644 --- a/Marlin/src/sd/usb_flashdrive/lib-uhs2/settings.h +++ b/Marlin/src/sd/usb_flashdrive/lib-uhs2/settings.h @@ -65,12 +65,12 @@ * multiple serial ports are available. * For example Serial3. */ -#if ENABLED(USB_FLASH_DRIVE_SUPPORT) - #define USB_HOST_SERIAL MYSERIAL1 -#endif - #ifndef USB_HOST_SERIAL - #define USB_HOST_SERIAL Serial + #if ENABLED(USB_FLASH_DRIVE_SUPPORT) + #define USB_HOST_SERIAL MYSERIAL1 + #else + #define USB_HOST_SERIAL Serial + #endif #endif //////////////////////////////////////////////////////////////////////////////// diff --git a/docs/Serial.md b/docs/Serial.md index be3b23e87d..88846e1bb4 100644 --- a/docs/Serial.md +++ b/docs/Serial.md @@ -64,9 +64,9 @@ The following macros are defined (in `serial.h`) to output data to the serial po | `SERIAL_ECHOLNPGM_P` | Same as `SERIAL_ECHOPGM_P` | Do `SERIAL_ECHOPGM_P`, adding a newline | `SERIAL_ECHOLNPGM_P(PSTR("Alice"), 78);` | `alice78\n` | | `SERIAL_ECHOLIST` | String literal, values | Print a string literal and a list of values | `SERIAL_ECHOLIST(F("Key "), 1, 2, 3);` | `Key 1, 2, 3` | | `SERIAL_ECHO_START` | None | Prefix an echo line | `SERIAL_ECHO_START();` | `echo:` | -| `SERIAL_ECHO_MSG` | Same as `SERIAL_ECHOLN_PAIR` | Print a full echo line | `SERIAL_ECHO_MSG("Count is ", count);` | `echo:Count is 3` | +| `SERIAL_ECHO_MSG` | Same as `SERIAL_ECHOLNPGM` | Print a full echo line | `SERIAL_ECHO_MSG("Count is ", count);` | `echo:Count is 3` | | `SERIAL_ERROR_START`| None | Prefix an error line | `SERIAL_ERROR_START();` | `Error:` | -| `SERIAL_ERROR_MSG` | Same as `SERIAL_ECHOLN_PAIR` | Print a full error line | `SERIAL_ERROR_MSG("Not found");` | `Error:Not found` | +| `SERIAL_ERROR_MSG` | Same as `SERIAL_ECHOLNPGM` | Print a full error line | `SERIAL_ERROR_MSG("Not found");` | `Error:Not found` | | `SERIAL_ECHO_SP` | Number of spaces | Print one or more spaces | `SERIAL_ECHO_SP(3)` | ` ` | | `SERIAL_EOL` | None | Print an end of line | `SERIAL_EOL();` | `\n` | | `SERIAL_OUT` | `SERIAL_OUT(myMethod)` | Call a custom serial method | `SERIAL_OUT(msgDone);` | ... |