From d765c452e4e84f56439808d2e7f8edbeedb47256 Mon Sep 17 00:00:00 2001 From: Jason Smith Date: Wed, 28 Oct 2020 21:50:14 -0700 Subject: [PATCH 1/3] Disable PWM output while updating NeoPixels. --- Marlin/src/HAL/STM32/HAL.h | 4 ++++ Marlin/src/HAL/STM32/eeprom_flash.cpp | 9 --------- Marlin/src/feature/leds/neopixel.h | 3 +++ Marlin/src/inc/Conditionals_post.h | 3 +++ 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/Marlin/src/HAL/STM32/HAL.h b/Marlin/src/HAL/STM32/HAL.h index a1f7515d6b..8d3b24cf73 100644 --- a/Marlin/src/HAL/STM32/HAL.h +++ b/Marlin/src/HAL/STM32/HAL.h @@ -29,6 +29,7 @@ #include "../shared/math_32bit.h" #include "../shared/HAL_SPI.h" #include "fastio.h" +#include "Servo.h" #include "watchdog.h" #include "MarlinSerial.h" @@ -110,6 +111,9 @@ typedef int16_t pin_t; #define HAL_SERVO_LIB libServo +#define PAUSE_SERVO_OUTPUT() libServo::pause_all_servos() +#define RESUME_SERVO_OUTPUT() libServo::resume_all_servos() +#define HAS_PAUSE_SERVO_OUTPUT HAS_SERVOS // ------------------------ // Public Variables diff --git a/Marlin/src/HAL/STM32/eeprom_flash.cpp b/Marlin/src/HAL/STM32/eeprom_flash.cpp index c83376d265..857144fd5f 100644 --- a/Marlin/src/HAL/STM32/eeprom_flash.cpp +++ b/Marlin/src/HAL/STM32/eeprom_flash.cpp @@ -28,15 +28,6 @@ #include "../shared/eeprom_api.h" -#if HAS_SERVOS - #include "Servo.h" - #define PAUSE_SERVO_OUTPUT() libServo::pause_all_servos() - #define RESUME_SERVO_OUTPUT() libServo::resume_all_servos() -#else - #define PAUSE_SERVO_OUTPUT() - #define RESUME_SERVO_OUTPUT() -#endif - /** * The STM32 HAL supports chips that deal with "pages" and some with "sectors" and some that * even have multiple "banks" of flash. diff --git a/Marlin/src/feature/leds/neopixel.h b/Marlin/src/feature/leds/neopixel.h index 42046fa563..471257e96a 100644 --- a/Marlin/src/feature/leds/neopixel.h +++ b/Marlin/src/feature/leds/neopixel.h @@ -105,6 +105,8 @@ public: } static inline void show() { + // Some platforms cannot maintain PWM output when NeoPixel disables interrupts for long durations. + TERN_(HAS_PAUSE_SERVO_OUTPUT, PAUSE_SERVO_OUTPUT()); adaneo1.show(); #if PIN_EXISTS(NEOPIXEL2) #if CONJOINED_NEOPIXEL @@ -115,6 +117,7 @@ public: adaneo1.setPin(NEOPIXEL_PIN); #endif #endif + TERN_(HAS_PAUSE_SERVO_OUTPUT, RESUME_SERVO_OUTPUT()); } #if 0 diff --git a/Marlin/src/inc/Conditionals_post.h b/Marlin/src/inc/Conditionals_post.h index bbbcf6fb2f..a3a0054498 100644 --- a/Marlin/src/inc/Conditionals_post.h +++ b/Marlin/src/inc/Conditionals_post.h @@ -1999,6 +1999,9 @@ #if NUM_SERVOS > 0 #define HAS_SERVOS 1 #endif +#if !HAS_SERVOS || !defined(HAS_PAUSE_SERVO_OUTPUT) + #define HAS_PAUSE_SERVO_OUTPUT 0 +#endif // Sensors #if PIN_EXISTS(FILWIDTH) From cde553790ef49aff2dd43ba596037655ddc920db Mon Sep 17 00:00:00 2001 From: Jason Smith Date: Fri, 30 Oct 2020 19:28:03 -0700 Subject: [PATCH 2/3] Fix Malyan M300 build, which does not have BLTOUCH, and add NeoPixel and BLTOUCH to one GTR build --- Marlin/src/HAL/STM32/eeprom_flash.cpp | 4 ++-- Marlin/src/inc/Conditionals_post.h | 2 +- buildroot/tests/BIGTREE_GTR_V1_0-tests | 3 ++- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Marlin/src/HAL/STM32/eeprom_flash.cpp b/Marlin/src/HAL/STM32/eeprom_flash.cpp index 857144fd5f..5b9590b467 100644 --- a/Marlin/src/HAL/STM32/eeprom_flash.cpp +++ b/Marlin/src/HAL/STM32/eeprom_flash.cpp @@ -218,11 +218,11 @@ bool PersistentStore::access_finish() { // Interrupts during this time can have unpredictable results, such as killing Servo // output. Servo output still glitches with interrupts disabled, but recovers after the // erase. - PAUSE_SERVO_OUTPUT(); + TERN_(HAS_PAUSE_SERVO_OUTPUT, PAUSE_SERVO_OUTPUT()); DISABLE_ISRS(); eeprom_buffer_flush(); ENABLE_ISRS(); - RESUME_SERVO_OUTPUT(); + TERN_(HAS_PAUSE_SERVO_OUTPUT, RESUME_SERVO_OUTPUT()); eeprom_data_written = false; #endif diff --git a/Marlin/src/inc/Conditionals_post.h b/Marlin/src/inc/Conditionals_post.h index a3a0054498..ba16b9e39f 100644 --- a/Marlin/src/inc/Conditionals_post.h +++ b/Marlin/src/inc/Conditionals_post.h @@ -1999,7 +1999,7 @@ #if NUM_SERVOS > 0 #define HAS_SERVOS 1 #endif -#if !HAS_SERVOS || !defined(HAS_PAUSE_SERVO_OUTPUT) +#ifndef HAS_PAUSE_SERVO_OUTPUT #define HAS_PAUSE_SERVO_OUTPUT 0 #endif diff --git a/buildroot/tests/BIGTREE_GTR_V1_0-tests b/buildroot/tests/BIGTREE_GTR_V1_0-tests index e8d47562aa..40ed4b697d 100644 --- a/buildroot/tests/BIGTREE_GTR_V1_0-tests +++ b/buildroot/tests/BIGTREE_GTR_V1_0-tests @@ -23,7 +23,8 @@ opt_set E1_AUTO_FAN_PIN PC11 opt_set E2_AUTO_FAN_PIN PC12 opt_set X_DRIVER_TYPE TMC2208 opt_set Y_DRIVER_TYPE TMC2130 -opt_enable REPRAP_DISCOUNT_FULL_GRAPHIC_SMART_CONTROLLER +opt_set NEOPIXEL_PIN PF13 +opt_enable REPRAP_DISCOUNT_FULL_GRAPHIC_SMART_CONTROLLER BLTOUCH NEOPIXEL_LED Z_SAFE_HOMING exec_test $1 $2 "BigTreeTech GTR 8 Extruders with Auto-Fan and Mixed TMC Drivers" restore_configs From 58c82d541df1e05756f6bab3e45ac8c5fc60fe1f Mon Sep 17 00:00:00 2001 From: Jason Smith Date: Fri, 30 Oct 2020 20:08:01 -0700 Subject: [PATCH 3/3] Add missing TERN_ --- Marlin/src/HAL/STM32/HAL.h | 1 - Marlin/src/HAL/STM32/eeprom_flash.cpp | 4 ++-- Marlin/src/inc/Conditionals_post.h | 4 ++-- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/Marlin/src/HAL/STM32/HAL.h b/Marlin/src/HAL/STM32/HAL.h index 8d3b24cf73..c10f910699 100644 --- a/Marlin/src/HAL/STM32/HAL.h +++ b/Marlin/src/HAL/STM32/HAL.h @@ -113,7 +113,6 @@ typedef int16_t pin_t; #define HAL_SERVO_LIB libServo #define PAUSE_SERVO_OUTPUT() libServo::pause_all_servos() #define RESUME_SERVO_OUTPUT() libServo::resume_all_servos() -#define HAS_PAUSE_SERVO_OUTPUT HAS_SERVOS // ------------------------ // Public Variables diff --git a/Marlin/src/HAL/STM32/eeprom_flash.cpp b/Marlin/src/HAL/STM32/eeprom_flash.cpp index 5b9590b467..95b7938618 100644 --- a/Marlin/src/HAL/STM32/eeprom_flash.cpp +++ b/Marlin/src/HAL/STM32/eeprom_flash.cpp @@ -163,11 +163,11 @@ bool PersistentStore::access_finish() { current_slot = EEPROM_SLOTS - 1; UNLOCK_FLASH(); - PAUSE_SERVO_OUTPUT(); + TERN_(HAS_PAUSE_SERVO_OUTPUT, PAUSE_SERVO_OUTPUT()); DISABLE_ISRS(); status = HAL_FLASHEx_Erase(&EraseInitStruct, &SectorError); ENABLE_ISRS(); - RESUME_SERVO_OUTPUT(); + TERN_(HAS_PAUSE_SERVO_OUTPUT, RESUME_SERVO_OUTPUT()); if (status != HAL_OK) { DEBUG_ECHOLNPAIR("HAL_FLASHEx_Erase=", status); DEBUG_ECHOLNPAIR("GetError=", HAL_FLASH_GetError()); diff --git a/Marlin/src/inc/Conditionals_post.h b/Marlin/src/inc/Conditionals_post.h index ba16b9e39f..268d7839f1 100644 --- a/Marlin/src/inc/Conditionals_post.h +++ b/Marlin/src/inc/Conditionals_post.h @@ -1999,8 +1999,8 @@ #if NUM_SERVOS > 0 #define HAS_SERVOS 1 #endif -#ifndef HAS_PAUSE_SERVO_OUTPUT - #define HAS_PAUSE_SERVO_OUTPUT 0 +#if HAS_SERVOS && defined(PAUSE_SERVO_OUTPUT) && defined(RESUME_SERVO_OUTPUT) + #define HAS_PAUSE_SERVO_OUTPUT 1 #endif // Sensors