Skip to content

Commit

Permalink
Merge branch 'bugfix-2.1.x' into pr/26502
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead committed May 21, 2024
2 parents 098a62e + 1845056 commit 72e4984
Show file tree
Hide file tree
Showing 161 changed files with 2,211 additions and 1,697 deletions.
11 changes: 10 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,18 @@ tests-single-local-docker:
$(CONTAINER_RT_BIN) run $(CONTAINER_RT_OPTS) $(CONTAINER_IMAGE) make tests-single-local TEST_TARGET=$(TEST_TARGET) VERBOSE_PLATFORMIO=$(VERBOSE_PLATFORMIO) GIT_RESET_HARD=$(GIT_RESET_HARD) ONLY_TEST="$(ONLY_TEST)"

tests-all-local:
@python -c "import yaml" 2>/dev/null || (echo 'pyyaml module is not installed. Install it with "python -m pip install pyyaml"' && exit 1)
export PATH="./buildroot/bin/:./buildroot/tests/:${PATH}" \
&& export VERBOSE_PLATFORMIO=$(VERBOSE_PLATFORMIO) \
&& for TEST_TARGET in $$($(SCRIPTS_DIR)/get_test_targets.py) ; do echo "Running tests for $$TEST_TARGET" ; run_tests . $$TEST_TARGET ; done
&& for TEST_TARGET in $$(python $(SCRIPTS_DIR)/get_test_targets.py) ; do \
if [ "$$TEST_TARGET" = "linux_native" ] && [ "$$(uname)" = "Darwin" ]; then \
echo "Skipping tests for $$TEST_TARGET on macOS" ; \
continue ; \
fi ; \
echo "Running tests for $$TEST_TARGET" ; \
run_tests . $$TEST_TARGET || exit 1 ; \
sleep 5; \
done

tests-all-local-docker:
@if ! $(CONTAINER_RT_BIN) images -q $(CONTAINER_IMAGE) > /dev/null ; then $(MAKE) setup-local-docker ; fi
Expand Down
4 changes: 2 additions & 2 deletions Marlin/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,7 @@
* MPCTEMP : Predictive Model temperature control. (~1.8K without auto-tune)
*/
#define PIDTEMP // See the PID Tuning Guide at https://reprap.org/wiki/PID_Tuning
//#define MPCTEMP // ** EXPERIMENTAL ** See https://marlinfw.org/docs/features/model_predictive_control.html
//#define MPCTEMP // See https://marlinfw.org/docs/features/model_predictive_control.html

#define PID_MAX 255 // Limit hotend current while PID is active (see PID_FUNCTIONAL_RANGE below); 255=full current
#define PID_K1 0.95 // Smoothing factor within any PID loop
Expand Down Expand Up @@ -2218,7 +2218,7 @@
#if ENABLED(LCD_BED_TRAMMING)
#define BED_TRAMMING_INSET_LFRB { 30, 30, 30, 30 } // (mm) Left, Front, Right, Back insets
#define BED_TRAMMING_HEIGHT 0.0 // (mm) Z height of nozzle at tramming points
#define BED_TRAMMING_Z_HOP 4.0 // (mm) Z height of nozzle between tramming points
#define BED_TRAMMING_Z_HOP 4.0 // (mm) Z raise between tramming points
//#define BED_TRAMMING_INCLUDE_CENTER // Move to the center after the last corner
//#define BED_TRAMMING_USE_PROBE
#if ENABLED(BED_TRAMMING_USE_PROBE)
Expand Down
9 changes: 7 additions & 2 deletions Marlin/Configuration_adv.h
Original file line number Diff line number Diff line change
Expand Up @@ -1202,7 +1202,8 @@
*/
//#define INPUT_SHAPING_X
//#define INPUT_SHAPING_Y
#if ANY(INPUT_SHAPING_X, INPUT_SHAPING_Y)
//#define INPUT_SHAPING_Z
#if ANY(INPUT_SHAPING_X, INPUT_SHAPING_Y, INPUT_SHAPING_Z)
#if ENABLED(INPUT_SHAPING_X)
#define SHAPING_FREQ_X 40.0 // (Hz) The default dominant resonant frequency on the X axis.
#define SHAPING_ZETA_X 0.15 // Damping ratio of the X axis (range: 0.0 = no damping to 1.0 = critical damping).
Expand All @@ -1211,6 +1212,10 @@
#define SHAPING_FREQ_Y 40.0 // (Hz) The default dominant resonant frequency on the Y axis.
#define SHAPING_ZETA_Y 0.15 // Damping ratio of the Y axis (range: 0.0 = no damping to 1.0 = critical damping).
#endif
#if ENABLED(INPUT_SHAPING_Z)
#define SHAPING_FREQ_Z 40.0 // (Hz) The default dominant resonant frequency on the Z axis.
#define SHAPING_ZETA_Z 0.15 // Damping ratio of the Z axis (range: 0.0 = no damping to 1.0 = critical damping).
#endif
//#define SHAPING_MIN_FREQ 20.0 // (Hz) By default the minimum of the shaping frequencies. Override to affect SRAM usage.
//#define SHAPING_MAX_STEPRATE 10000 // By default the maximum total step rate of the shaped axes. Override to affect SRAM usage.
//#define SHAPING_MENU // Add a menu to the LCD to set shaping parameters.
Expand Down Expand Up @@ -1584,7 +1589,7 @@
#if HAS_MARLINUI_U8GLIB
//#define BOOT_MARLIN_LOGO_ANIMATED // Animated Marlin logo. Costs ~3260 (or ~940) bytes of flash.
#endif
#if ANY(HAS_MARLINUI_U8GLIB, TOUCH_UI_FTDI_EVE)
#if ANY(HAS_MARLINUI_U8GLIB, TOUCH_UI_FTDI_EVE, HAS_MARLINUI_HD44780)
//#define SHOW_CUSTOM_BOOTSCREEN // Show the bitmap in Marlin/_Bootscreen.h on startup.
#endif
#endif
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 "2024-04-23"
//#define STRING_DISTRIBUTION_DATE "2024-05-21"

/**
* Defines a generic printer name to be output to the LCD after booting Marlin.
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/HAL/DUE/fastio/G2_PWM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
#else
#define G2_PWM_Z 0
#endif
#if PIN_EXISTS(MOTOR_CURRENT_PWM_E)
#if HAS_MOTOR_CURRENT_PWM_E
#define G2_PWM_E 1
#else
#define G2_PWM_E 0
Expand Down
21 changes: 20 additions & 1 deletion Marlin/src/HAL/HC32/HAL.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,31 @@
// ADC
//
#define HAL_ADC_VREF_MV 3300
#define HAL_ADC_RESOLUTION 10
#define HAL_ADC_RESOLUTION 12

#define GET_PIN_MAP_PIN(index) index
#define GET_PIN_MAP_INDEX(pin) pin
#define PARSED_PIN_INDEX(code, dval) parser.intval(code, dval)

//
// Debug port disable
// JTMS / SWDIO = PA13
// JTCK / SWCLK = PA14
// JTDI = PA15
// JTDO = PB3
// NJTRST = PB4
//
#define DBG_SWCLK _BV(0)
#define DBG_SWDIO _BV(1)
#define DBG_TDO _BV(2)
#define DBG_TDI _BV(3)
#define DBG_TRST _BV(4)
#define DBG_ALL (DBG_SWCLK | DBG_SWDIO | DBG_TDO | DBG_TDI | DBG_TRST)

#define JTAGSWD_RESET() PORT_DebugPortSetting(DBG_ALL, Enable);
#define JTAG_DISABLE() PORT_DebugPortSetting(DBG_TDO | DBG_TDI | DBG_TRST, Disable);
#define JTAGSWD_DISABLE() PORT_DebugPortSetting(DBG_ALL, Disable);

//
// MarlinHAL implementation
//
Expand Down
4 changes: 3 additions & 1 deletion Marlin/src/HAL/HC32/MarlinHAL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,9 @@ int MarlinHAL::freeMemory() {
return &top - _sbrk(0);
}

void MarlinHAL::adc_init() {}
void MarlinHAL::adc_init() {
analogReadResolution(HAL_ADC_RESOLUTION);
}

void MarlinHAL::adc_enable(const pin_t pin) {
#if TEMP_SENSOR_SOC
Expand Down
9 changes: 7 additions & 2 deletions Marlin/src/HAL/HC32/app_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,12 @@
// redirect printf to host serial
#define REDIRECT_PRINTF_TO_SERIAL 1

// FIXME override F_CPU to PCLK1, as marlin freaks out otherwise
#define F_CPU (SYSTEM_CLOCK_FREQUENCIES.pclk1)
// F_CPU must be known at compile time, but on HC32F460 it's not.
// Thus we assume HCLK to be 200MHz, as that's what is configured in
// 'core_hook_sysclock_init' in 'sysclock.cpp'.
// If you face issues with this assumption, please double-check with the values
// printed by 'MarlinHAL::HAL_clock_frequencies_dump'.
// see also: HAL_TIMER_RATE in timers.h
#define F_CPU 200000000 // 200MHz HCLK

#endif // _HC32_APP_CONFIG_H_
33 changes: 24 additions & 9 deletions Marlin/src/HAL/HC32/sysclock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,29 +96,44 @@ void core_hook_sysclock_init() {
#endif
#endif

// Setup clock divisors for sysclk = 200 MHz:
// sysclk is now configured according to F_CPU (i.e., 200MHz PLL output)
constexpr uint32_t sysclock = F_CPU;

// Setup clock divisors for sysclk = 200 MHz
// Note: PCLK1 is used for step+temp timers, and need to be kept at 50 MHz (until there is a better solution)
stc_clk_sysclk_cfg_t sysClkConf = {
constexpr stc_clk_sysclk_cfg_t sysClkConf = {
.enHclkDiv = ClkSysclkDiv1, // HCLK = 200 MHz (CPU)
.enExclkDiv = ClkSysclkDiv2, // EXCLK = 100 MHz (SDIO)
.enPclk0Div = ClkSysclkDiv1, // PCLK0 = 200 MHz (Timer6 (not used))
.enPclk0Div = ClkSysclkDiv2, // PCLK0 = 100 MHz (Timer6 (not used))
.enPclk1Div = ClkSysclkDiv4, // PCLK1 = 50 MHz (USART, SPI, I2S, Timer0 (step+temp), TimerA (Servo))
.enPclk2Div = ClkSysclkDiv4, // PCLK2 = 50 MHz (ADC)
.enPclk3Div = ClkSysclkDiv4, // PCLK3 = 50 MHz (I2C, WDT)
.enPclk2Div = ClkSysclkDiv8, // PCLK2 = 25 MHz (ADC)
.enPclk3Div = ClkSysclkDiv8, // PCLK3 = 25 MHz (I2C, WDT)
.enPclk4Div = ClkSysclkDiv2, // PCLK4 = 100 MHz (ADC ctl)
};

#if ARDUINO_CORE_VERSION_INT >= GET_VERSION_INT(1, 2, 0)
assert_system_clocks_valid<
sysclock,
sysClkConf.enHclkDiv,
sysClkConf.enPclk0Div,
sysClkConf.enPclk1Div,
sysClkConf.enPclk2Div,
sysClkConf.enPclk3Div,
sysClkConf.enPclk4Div,
sysClkConf.enExclkDiv
>();
#endif

sysclock_set_clock_dividers(&sysClkConf);

// Set power mode
#define POWER_MODE_SYSTEM_CLOCK 200000000 // 200 MHz
power_mode_update_pre(POWER_MODE_SYSTEM_CLOCK);
power_mode_update_pre(sysclock);

// Switch to MPLL as sysclk source
CLK_SetSysClkSource(CLKSysSrcMPLL);

// Set power mode
power_mode_update_post(POWER_MODE_SYSTEM_CLOCK);
#undef POWER_MODE_SYSTEM_CLOCK
power_mode_update_post(sysclock);
}

#endif // ARDUINO_ARCH_HC32
58 changes: 31 additions & 27 deletions Marlin/src/HAL/HC32/timers.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,44 +38,48 @@ extern Timer0 step_timer;
// Timer Configurations
//

// TODO: some calculations (step irq min_step_rate) require the timer rate to be known at compile time
// this is not possible with the HC32F460, as the timer rate depends on PCLK1
// as a workaround, PCLK1 = 50MHz is assumed (check with clock dump in MarlinHAL::init())
#define HAL_TIMER_RATE 50000000 // 50MHz
// #define HAL_TIMER_RATE TIMER0_BASE_FREQUENCY

// TODO: CYCLES_PER_MICROSECOND seems to be used by Marlin to calculate the number of cycles per microsecond in the timer ISRs
// by default, it uses F_CPU, but since that is not known at compile time for HC32, we overwrite it here
#undef CYCLES_PER_MICROSECOND
#define CYCLES_PER_MICROSECOND (HAL_TIMER_RATE / 1000000UL)
/**
* HAL_TIMER_RATE must be known at compile time since it's used to calculate
* STEPPER_TIMER_RATE, which is used in 'constexpr' calculations.
* On the HC32F460 the timer rate depends on PCLK1, which is derived from the
* system clock configured at runtime. As a workaround, we use the existing
* assumption of a 200MHz clock, defining F_CPU as 200000000, then configure PCLK1
* as F_CPU with a divider of 4 in 'sysclock.cpp::core_hook_sysclock_init'.
*
* If you face issues with this assumption, please double-check with the values
* printed by 'MarlinHAL::HAL_clock_frequencies_dump'.
*
* TODO: If the 'constexpr' requirement is ever lifted, use TIMER0_BASE_FREQUENCY instead
*/
#define HAL_TIMER_RATE (F_CPU / 4) // i.e., 50MHz
//#define HAL_TIMER_RATE TIMER0_BASE_FREQUENCY

// Temperature timer
#define TEMP_TIMER_NUM (&temp_timer)
#define TEMP_TIMER_PRIORITY DDL_IRQ_PRIORITY_02
#define TEMP_TIMER_PRESCALE 16ul
#define TEMP_TIMER_RATE 1000 // 1kHz
#define TEMP_TIMER_FREQUENCY TEMP_TIMER_RATE // Alias for Marlin
#define TEMP_TIMER_NUM (&temp_timer)
#define TEMP_TIMER_PRIORITY DDL_IRQ_PRIORITY_02
#define TEMP_TIMER_PRESCALE 16UL // 12.5MHz
#define TEMP_TIMER_RATE 1000 // 1kHz
#define TEMP_TIMER_FREQUENCY TEMP_TIMER_RATE // 1kHz also

// Stepper timer
#define STEP_TIMER_NUM (&step_timer)
#define STEP_TIMER_PRIORITY DDL_IRQ_PRIORITY_01
#define STEPPER_TIMER_PRESCALE 16ul
#define STEP_TIMER_NUM (&step_timer)
#define STEP_TIMER_PRIORITY DDL_IRQ_PRIORITY_00 // Top priority, nothing else uses it
#define STEPPER_TIMER_PRESCALE 16UL // 12.5MHz

// TODO: STEPPER_TIMER_RATE seems to work fine like this, but requires further testing...
#define STEPPER_TIMER_RATE (HAL_TIMER_RATE / STEPPER_TIMER_PRESCALE) // 50MHz / 16 = 3.125MHz
#define STEPPER_TIMER_TICKS_PER_US (STEPPER_TIMER_RATE / 1000000)
#define STEPPER_TIMER_RATE (HAL_TIMER_RATE / STEPPER_TIMER_PRESCALE) // 50MHz / 16 = 3.125MHz
#define STEPPER_TIMER_TICKS_PER_US (STEPPER_TIMER_RATE / 1000000UL) // Integer 3

// Pulse timer (== stepper timer)
#define PULSE_TIMER_NUM STEP_TIMER_NUM
#define PULSE_TIMER_PRESCALE STEPPER_TIMER_PRESCALE
#define PULSE_TIMER_TICKS_PER_US STEPPER_TIMER_TICKS_PER_US
#define PULSE_TIMER_NUM STEP_TIMER_NUM
#define PULSE_TIMER_PRESCALE STEPPER_TIMER_PRESCALE
#define PULSE_TIMER_TICKS_PER_US STEPPER_TIMER_TICKS_PER_US

//
// Channel aliases
//
#define MF_TIMER_TEMP TEMP_TIMER_NUM
#define MF_TIMER_STEP STEP_TIMER_NUM
#define MF_TIMER_PULSE PULSE_TIMER_NUM
#define MF_TIMER_TEMP TEMP_TIMER_NUM
#define MF_TIMER_STEP STEP_TIMER_NUM
#define MF_TIMER_PULSE PULSE_TIMER_NUM

//
// HAL functions
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/MarlinCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ PGMSTR(M112_KILL_STR, "M112 Shutdown");
MarlinState marlin_state = MF_INITIALIZING;

// For M109 and M190, this flag may be cleared (by M108) to exit the wait loop
bool wait_for_heatup = true;
bool wait_for_heatup = false;

// For M0/M1, this flag may be cleared (by M108) to exit the wait-for-user loop
#if HAS_RESUME_CONTINUE
Expand Down
6 changes: 3 additions & 3 deletions Marlin/src/core/boards.h
Original file line number Diff line number Diff line change
Expand Up @@ -383,9 +383,9 @@
#define BOARD_CREALITY_V452 5050 // Creality v4.5.2 (STM32F103RC / STM32F103RE)
#define BOARD_CREALITY_V453 5051 // Creality v4.5.3 (STM32F103RC / STM32F103RE)
#define BOARD_CREALITY_V521 5052 // Creality v5.2.1 (STM32F103VE) as found in the SV04
#define BOARD_CREALITY_V24S1 5053 // Creality v2.4.S1 (STM32F103RC / STM32F103RE) v101 as found in the Ender-7
#define BOARD_CREALITY_V24S1_301 5054 // Creality v2.4.S1_301 (STM32F103RC / STM32F103RE) v301 as found in the Ender-3 S1
#define BOARD_CREALITY_V25S1 5055 // Creality v2.5.S1 (STM32F103RE) as found in the CR-10 Smart Pro
#define BOARD_CREALITY_V24S1 5053 // Creality v2.4.S1 (STM32F103RC / STM32F103RE) CR-FDM-v2.4.S1_v101 as found in the Ender-7
#define BOARD_CREALITY_V24S1_301 5054 // Creality v2.4.S1_301 (STM32F103RC / STM32F103RE) CR-FDM-v24S1_301 as found in the Ender-3 S1
#define BOARD_CREALITY_V25S1 5055 // Creality v2.5.S1 (STM32F103RE) CR-FDM-v2.5.S1_100 as found in the CR-10 Smart Pro
#define BOARD_TRIGORILLA_PRO 5056 // Trigorilla Pro (STM32F103ZE)
#define BOARD_FLY_MINI 5057 // FLYmaker FLY MINI (STM32F103RC)
#define BOARD_FLSUN_HISPEED 5058 // FLSUN HiSpeedV1 (STM32F103VE)
Expand Down
1 change: 1 addition & 0 deletions Marlin/src/core/language.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@
#define STR_BUSY_PAUSED_FOR_USER "busy: paused for user"
#define STR_BUSY_PAUSED_FOR_INPUT "busy: paused for input"
#define STR_Z_MOVE_COMP "Z_move_comp"
#define STR_LINE_NO "Line: "
#define STR_RESEND "Resend: "
#define STR_UNKNOWN_COMMAND "Unknown command: \""
#define STR_ACTIVE_EXTRUDER "Active Extruder: "
Expand Down
3 changes: 2 additions & 1 deletion Marlin/src/core/macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@
#define HYPOT2(x,y) (sq(x)+sq(y))
#define NORMSQ(x,y,z) (sq(x)+sq(y)+sq(z))

#define CIRCLE_AREA(R) (float(M_PI) * sq(float(R)))
#define FLOAT_SQ(I) sq(float(I))
#define CIRCLE_AREA(R) (float(M_PI) * FLOAT_SQ(R))
#define CIRCLE_CIRC(R) (2 * float(M_PI) * float(R))

#define SIGN(a) ({__typeof__(a) _a = (a); (_a>0)-(_a<0);})
Expand Down
10 changes: 5 additions & 5 deletions Marlin/src/core/mstring.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,13 @@ class MString {

// Set with format string and arguments, like printf
template<typename... Args>
MString& setf_P(PGM_P const fmt, Args... more) { SNPRINTF_P(str, SIZE, fmt, more...); debug(F("setf_P")); return *this; }
MString& setf_P(PGM_P const pfmt, Args... more) { SNPRINTF_P(str, SIZE, pfmt, more...); debug(F("setf_P")); return *this; }

template<typename... Args>
MString& setf(const char *fmt, Args... more) { SNPRINTF(str, SIZE, fmt, more...); debug(F("setf")); return *this; }
MString& setf(const char *fmt, Args... more) { SNPRINTF(str, SIZE, fmt, more...); debug(F("setf")); return *this; }

template<typename... Args>
MString& setf(FSTR_P const fmt, Args... more) { return setf_P(FTOP(fmt), more...); }
MString& setf(FSTR_P const ffmt, Args... more) { return setf_P(FTOP(ffmt), more...); }

// Chainable String appenders
MString& append() { debug(F("nil")); return *this; } // for macros that might emit no output
Expand Down Expand Up @@ -206,9 +206,9 @@ class MString {
MString& append(const spaces_t &s) { return append(repchr_t(' ', s.count)); }

template<typename... Args>
MString& appendf_P(PGM_P const fmt, Args... more) {
MString& appendf_P(PGM_P const pfmt, Args... more) {
int sz = length();
if (sz < SIZE) SNPRINTF_P(str + sz, SIZE - sz, fmt, more...);
if (sz < SIZE) SNPRINTF_P(str + sz, SIZE - sz, pfmt, more...);
debug(F("appendf_P"));
return *this;
}
Expand Down
6 changes: 3 additions & 3 deletions Marlin/src/core/serial.h
Original file line number Diff line number Diff line change
Expand Up @@ -271,13 +271,13 @@ class SString : public MString<SIZE> {
SString& set() { super::set(); return *this; }

template<typename... Args>
SString& setf_P(PGM_P const fmt, Args... more) { super::setf_P(fmt, more...); return *this; }
SString& setf_P(PGM_P const pfmt, Args... more) { super::setf_P(pfmt, more...); return *this; }

template<typename... Args>
SString& setf(const char *fmt, Args... more) { super::setf(fmt, more...); return *this; }
SString& setf(const char *fmt, Args... more) { super::setf(fmt, more...); return *this; }

template<typename... Args>
SString& setf(FSTR_P const fmt, Args... more) { super::setf(fmt, more...); return *this; }
SString& setf(FSTR_P const ffmt, Args... more) { super::setf(ffmt, more...); return *this; }

template <typename T>
SString& set(const T &v) { super::set(v); return *this; }
Expand Down
Loading

0 comments on commit 72e4984

Please sign in to comment.