Suspend Servos for STM32+NeoPixel (#19963)

This commit is contained in:
Jason Smith 2020-12-04 22:02:58 -08:00 committed by GitHub
parent 21ee7b1c86
commit 2c8f566231
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 15 additions and 14 deletions

View file

@ -29,6 +29,7 @@
#include "../shared/math_32bit.h" #include "../shared/math_32bit.h"
#include "../shared/HAL_SPI.h" #include "../shared/HAL_SPI.h"
#include "fastio.h" #include "fastio.h"
#include "Servo.h"
#include "watchdog.h" #include "watchdog.h"
#include "MarlinSerial.h" #include "MarlinSerial.h"
@ -110,6 +111,8 @@
typedef int16_t pin_t; typedef int16_t pin_t;
#define HAL_SERVO_LIB libServo #define HAL_SERVO_LIB libServo
#define PAUSE_SERVO_OUTPUT() libServo::pause_all_servos()
#define RESUME_SERVO_OUTPUT() libServo::resume_all_servos()
// ------------------------ // ------------------------
// Public Variables // Public Variables

View file

@ -28,15 +28,6 @@
#include "../shared/eeprom_api.h" #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 * The STM32 HAL supports chips that deal with "pages" and some with "sectors" and some that
* even have multiple "banks" of flash. * even have multiple "banks" of flash.
@ -172,11 +163,11 @@ bool PersistentStore::access_finish() {
current_slot = EEPROM_SLOTS - 1; current_slot = EEPROM_SLOTS - 1;
UNLOCK_FLASH(); UNLOCK_FLASH();
PAUSE_SERVO_OUTPUT(); TERN_(HAS_PAUSE_SERVO_OUTPUT, PAUSE_SERVO_OUTPUT());
DISABLE_ISRS(); DISABLE_ISRS();
status = HAL_FLASHEx_Erase(&EraseInitStruct, &SectorError); status = HAL_FLASHEx_Erase(&EraseInitStruct, &SectorError);
ENABLE_ISRS(); ENABLE_ISRS();
RESUME_SERVO_OUTPUT(); TERN_(HAS_PAUSE_SERVO_OUTPUT, RESUME_SERVO_OUTPUT());
if (status != HAL_OK) { if (status != HAL_OK) {
DEBUG_ECHOLNPAIR("HAL_FLASHEx_Erase=", status); DEBUG_ECHOLNPAIR("HAL_FLASHEx_Erase=", status);
DEBUG_ECHOLNPAIR("GetError=", HAL_FLASH_GetError()); DEBUG_ECHOLNPAIR("GetError=", HAL_FLASH_GetError());
@ -227,11 +218,11 @@ bool PersistentStore::access_finish() {
// Interrupts during this time can have unpredictable results, such as killing Servo // Interrupts during this time can have unpredictable results, such as killing Servo
// output. Servo output still glitches with interrupts disabled, but recovers after the // output. Servo output still glitches with interrupts disabled, but recovers after the
// erase. // erase.
PAUSE_SERVO_OUTPUT(); TERN_(HAS_PAUSE_SERVO_OUTPUT, PAUSE_SERVO_OUTPUT());
DISABLE_ISRS(); DISABLE_ISRS();
eeprom_buffer_flush(); eeprom_buffer_flush();
ENABLE_ISRS(); ENABLE_ISRS();
RESUME_SERVO_OUTPUT(); TERN_(HAS_PAUSE_SERVO_OUTPUT, RESUME_SERVO_OUTPUT());
eeprom_data_written = false; eeprom_data_written = false;
#endif #endif

View file

@ -105,6 +105,8 @@ public:
} }
static inline void show() { 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(); adaneo1.show();
#if PIN_EXISTS(NEOPIXEL2) #if PIN_EXISTS(NEOPIXEL2)
#if CONJOINED_NEOPIXEL #if CONJOINED_NEOPIXEL
@ -115,6 +117,7 @@ public:
adaneo1.setPin(NEOPIXEL_PIN); adaneo1.setPin(NEOPIXEL_PIN);
#endif #endif
#endif #endif
TERN_(HAS_PAUSE_SERVO_OUTPUT, RESUME_SERVO_OUTPUT());
} }
#if 0 #if 0

View file

@ -1997,6 +1997,9 @@
#if NUM_SERVOS > 0 #if NUM_SERVOS > 0
#define HAS_SERVOS 1 #define HAS_SERVOS 1
#endif #endif
#if HAS_SERVOS && defined(PAUSE_SERVO_OUTPUT) && defined(RESUME_SERVO_OUTPUT)
#define HAS_PAUSE_SERVO_OUTPUT 1
#endif
// Sensors // Sensors
#if PIN_EXISTS(FILWIDTH) #if PIN_EXISTS(FILWIDTH)

View file

@ -23,7 +23,8 @@ opt_set E1_AUTO_FAN_PIN PC11
opt_set E2_AUTO_FAN_PIN PC12 opt_set E2_AUTO_FAN_PIN PC12
opt_set X_DRIVER_TYPE TMC2208 opt_set X_DRIVER_TYPE TMC2208
opt_set Y_DRIVER_TYPE TMC2130 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
opt_enable FILAMENT_RUNOUT_SENSOR NOZZLE_PARK_FEATURE ADVANCED_PAUSE_FEATURE opt_enable FILAMENT_RUNOUT_SENSOR NOZZLE_PARK_FEATURE ADVANCED_PAUSE_FEATURE
opt_set FIL_RUNOUT_PIN 3 opt_set FIL_RUNOUT_PIN 3
opt_set FIL_RUNOUT2_PIN 4 opt_set FIL_RUNOUT2_PIN 4