From e50533da644889747390d711d8d6656c26a0c715 Mon Sep 17 00:00:00 2001 From: Jason Smith Date: Sun, 21 Jun 2020 11:12:41 -0700 Subject: [PATCH 1/2] Increase STM32 default timer interrupt priority This improves sound quality when SPEAKER is enabled, since it allows the tone interrupt to preempt the temperature ISR --- Marlin/src/HAL/STM32/timers.cpp | 9 +++++++++ platformio.ini | 1 + 2 files changed, 10 insertions(+) diff --git a/Marlin/src/HAL/STM32/timers.cpp b/Marlin/src/HAL/STM32/timers.cpp index 1228c465d3ec..a4149f9d3c99 100644 --- a/Marlin/src/HAL/STM32/timers.cpp +++ b/Marlin/src/HAL/STM32/timers.cpp @@ -36,6 +36,15 @@ #define TEMP_TIMER_IRQ_PRIO 14 // 14 = after hardware ISRs #endif +// Ensure the default timer priority is somewhere between the STEP and TEMP priorities. +// The STM32 framework defaults to interrupt 14 for all timers. This should be increased so that +// timing-sensitive operations such as speaker output are note impacted by the long-running +// temperature ISR. This must be defined in the platformio.ini file or the board's variant.h, +// so that it will be consumed by framework code. +#if TIM_IRQ_PRIO <= STEP_TIMER_IRQ_PRIO || TIM_IRQ_PRIO >= TEMP_TIMER_IRQ_PRIO + #error "Default timer interrupt priority is unspecified or set to a value which may degrade performance." +#endif + #if HAS_TMC_SW_SERIAL #include #ifndef SWSERIAL_TIMER_IRQ_PRIO diff --git a/platformio.ini b/platformio.ini index ee6bebb4dca4..8d049cc23954 100644 --- a/platformio.ini +++ b/platformio.ini @@ -329,6 +329,7 @@ build_flags = ${common.build_flags} -IMarlin/src/HAL/STM32 -std=gnu++14 -DUSBCON -DUSBD_USE_CDC -DUSBD_VID=0x0483 + -DTIM_IRQ_PRIO=13 build_unflags = -std=gnu++11 src_filter = ${common.default_src_filter} + From 5b445bd504c46f6a5e0ef81ee3859dac6598651b Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Mon, 22 Jun 2020 15:28:44 -0500 Subject: [PATCH 2/2] Update timers.cpp --- Marlin/src/HAL/STM32/timers.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Marlin/src/HAL/STM32/timers.cpp b/Marlin/src/HAL/STM32/timers.cpp index a4149f9d3c99..5383c82212d4 100644 --- a/Marlin/src/HAL/STM32/timers.cpp +++ b/Marlin/src/HAL/STM32/timers.cpp @@ -41,7 +41,7 @@ // timing-sensitive operations such as speaker output are note impacted by the long-running // temperature ISR. This must be defined in the platformio.ini file or the board's variant.h, // so that it will be consumed by framework code. -#if TIM_IRQ_PRIO <= STEP_TIMER_IRQ_PRIO || TIM_IRQ_PRIO >= TEMP_TIMER_IRQ_PRIO +#if !(TIM_IRQ_PRIO > STEP_TIMER_IRQ_PRIO && TIM_IRQ_PRIO < TEMP_TIMER_IRQ_PRIO) #error "Default timer interrupt priority is unspecified or set to a value which may degrade performance." #endif