Skip to content

Commit 04bea72

Browse files
GMagicianthinkyhead
authored andcommitted
🐛 Fix MMU compile with >5 EXTRUDERS (MarlinFirmware#22036)
1 parent ce95f56 commit 04bea72

File tree

10 files changed

+33
-28
lines changed

10 files changed

+33
-28
lines changed

Marlin/src/MarlinCore.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ void disable_e_steppers() {
317317
void disable_e_stepper(const uint8_t e) {
318318
#define _CASE_DIS_E(N) case N: DISABLE_AXIS_E##N(); break;
319319
switch (e) {
320-
REPEAT(EXTRUDERS, _CASE_DIS_E)
320+
REPEAT(E_STEPPERS, _CASE_DIS_E)
321321
}
322322
}
323323

@@ -1423,10 +1423,7 @@ void setup() {
14231423
#endif
14241424

14251425
#if HAS_PRUSA_MMU1
1426-
SETUP_LOG("Prusa MMU1");
1427-
SET_OUTPUT(E_MUX0_PIN);
1428-
SET_OUTPUT(E_MUX1_PIN);
1429-
SET_OUTPUT(E_MUX2_PIN);
1426+
SETUP_RUN(mmu_init());
14301427
#endif
14311428

14321429
#if HAS_FANMUX

Marlin/src/feature/mmu/mmu.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,14 @@
2424

2525
#if HAS_PRUSA_MMU1
2626

27-
#include "../module/stepper.h"
27+
#include "../MarlinCore.h"
28+
#include "../module/planner.h"
29+
30+
void mmu_init() {
31+
SET_OUTPUT(E_MUX0_PIN);
32+
SET_OUTPUT(E_MUX1_PIN);
33+
SET_OUTPUT(E_MUX2_PIN);
34+
}
2835

2936
void select_multiplexed_stepper(const uint8_t e) {
3037
planner.synchronize();

Marlin/src/feature/mmu/mmu.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,5 @@
2121
*/
2222
#pragma once
2323

24+
void mmu_init();
2425
void select_multiplexed_stepper(const uint8_t e);

Marlin/src/inc/Conditionals_LCD.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@
517517
#define HAS_PRUSA_MMU2 1
518518
#define HAS_PRUSA_MMU2S 1
519519
#endif
520-
#if MMU_MODEL == EXTENDABLE_EMU_MMU2 || MMU_MODEL == EXTENDABLE_EMU_MMU2S
520+
#if MMU_MODEL >= EXTENDABLE_EMU_MMU2
521521
#define HAS_EXTENDABLE_MMU 1
522522
#endif
523523
#endif

Marlin/src/inc/SanityCheck.h

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -954,9 +954,11 @@ static_assert(Y_MAX_LENGTH >= Y_BED_SIZE, "Movement bounds (Y_MIN_POS, Y_MAX_POS
954954
* Multi-Material-Unit 2 / EXTENDABLE_EMU_MMU2 requirements
955955
*/
956956
#if HAS_PRUSA_MMU2
957-
#if EXTRUDERS != 5
957+
#if !HAS_EXTENDABLE_MMU && EXTRUDERS != 5
958958
#undef SINGLENOZZLE
959959
#error "PRUSA_MMU2(S) requires exactly 5 EXTRUDERS. Please update your Configuration."
960+
#elif HAS_EXTENDABLE_MMU && EXTRUDERS > 15
961+
#error "EXTRUDERS is too large for MMU(S) emulation mode. The maximum value is 15."
960962
#elif DISABLED(NOZZLE_PARK_FEATURE)
961963
#error "PRUSA_MMU2(S) requires NOZZLE_PARK_FEATURE. Enable it to continue."
962964
#elif HAS_PRUSA_MMU2S && DISABLED(FILAMENT_RUNOUT_SENSOR)
@@ -969,18 +971,19 @@ static_assert(Y_MAX_LENGTH >= Y_BED_SIZE, "Movement bounds (Y_MIN_POS, Y_MAX_POS
969971
static_assert(nullptr == strstr(MMU2_FILAMENT_RUNOUT_SCRIPT, "M600"), "ADVANCED_PAUSE_FEATURE is required to use M600 with PRUSA_MMU2(S) / HAS_EXTENDABLE_MMU(S).");
970972
#endif
971973
#endif
972-
#if HAS_EXTENDABLE_MMU && EXTRUDERS > 15
973-
#error "Too many extruders for MMU(S) emulation mode. (15 maximum)."
974-
#endif
975974

976975
/**
977976
* Options only for EXTRUDERS > 1
978977
*/
979978
#if HAS_MULTI_EXTRUDER
980979

981-
#if EXTRUDERS > 8
982-
#error "Marlin supports a maximum of 8 EXTRUDERS."
980+
#if HAS_EXTENDABLE_MMU
981+
#define MAX_EXTRUDERS 15
982+
#else
983+
#define MAX_EXTRUDERS 8
983984
#endif
985+
static_assert(EXTRUDERS <= MAX_EXTRUDERS, "Marlin supports a maximum of " STRINGIFY(MAX_EXTRUDERS) " EXTRUDERS.");
986+
#undef MAX_EXTRUDERS
984987

985988
#if ENABLED(HEATERS_PARALLEL)
986989
#error "EXTRUDERS must be 1 with HEATERS_PARALLEL."

Marlin/src/module/planner.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ xyze_float_t Planner::previous_speed;
213213
float Planner::previous_nominal_speed_sqr;
214214

215215
#if ENABLED(DISABLE_INACTIVE_EXTRUDER)
216-
last_move_t Planner::g_uc_extruder_last_move[EXTRUDERS] = { 0 };
216+
last_move_t Planner::g_uc_extruder_last_move[E_STEPPERS] = { 0 };
217217
#endif
218218

219219
#ifdef XY_FREQUENCY_LIMIT
@@ -2105,11 +2105,13 @@ bool Planner::_populate_block(block_t * const block, bool split_move,
21052105

21062106
#if ENABLED(DISABLE_INACTIVE_EXTRUDER) // Enable only the selected extruder
21072107

2108-
LOOP_L_N(i, EXTRUDERS)
2108+
LOOP_L_N(i, E_STEPPERS)
21092109
if (g_uc_extruder_last_move[i]) g_uc_extruder_last_move[i]--;
21102110

2111+
#define E_STEPPER_INDEX(E) TERN(SWITCHING_EXTRUDER, (E) / 2, E)
2112+
21112113
#define ENABLE_ONE_E(N) do{ \
2112-
if (extruder == N) { \
2114+
if (E_STEPPER_INDEX(extruder) == N) { \
21132115
ENABLE_AXIS_E##N(); \
21142116
g_uc_extruder_last_move[N] = (BLOCK_BUFFER_SIZE) * 2; \
21152117
if ((N) == 0 && TERN0(HAS_DUPLICATION_MODE, extruder_duplication_enabled)) \
@@ -2128,7 +2130,7 @@ bool Planner::_populate_block(block_t * const block, bool split_move,
21282130

21292131
#endif
21302132

2131-
REPEAT(EXTRUDERS, ENABLE_ONE_E); // (ENABLE_ONE_E must end with semicolon)
2133+
REPEAT(E_STEPPERS, ENABLE_ONE_E); // (ENABLE_ONE_E must end with semicolon)
21322134
}
21332135
#endif // EXTRUDERS
21342136

Marlin/src/module/planner.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -450,8 +450,8 @@ class Planner {
450450
#endif
451451

452452
#if ENABLED(DISABLE_INACTIVE_EXTRUDER)
453-
// Counters to manage disabling inactive extruders
454-
static last_move_t g_uc_extruder_last_move[EXTRUDERS];
453+
// Counters to manage disabling inactive extruder steppers
454+
static last_move_t g_uc_extruder_last_move[E_STEPPERS];
455455
#endif
456456

457457
#if HAS_WIRED_LCD

Marlin/src/module/stepper/indirection.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ void reset_stepper_drivers(); // Called by settings.load / settings.reset
418418
#define REV_E_DIR(E) do{ E0_DIR_WRITE(E ? !INVERT_E0_DIR : INVERT_E0_DIR); }while(0)
419419
#endif
420420

421-
#elif HAS_PRUSA_MMU2
421+
#elif HAS_PRUSA_MMU2 // One multiplexed stepper driver
422422

423423
#define E_STEP_WRITE(E,V) E0_STEP_WRITE(V)
424424
#define NORM_E_DIR(E) E0_DIR_WRITE(!INVERT_E0_DIR)

Marlin/src/pins/pins.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,6 @@
3535
* These numbers are the same in any pin mapping.
3636
*/
3737

38-
#if HAS_EXTENDABLE_MMU
39-
#define MAX_EXTRUDERS 15
40-
#else
41-
#define MAX_EXTRUDERS 8
42-
#endif
4338
#define MAX_E_STEPPERS 8
4439

4540
#if MB(RAMPS_13_EFB, RAMPS_14_EFB, RAMPS_PLUS_EFB, RAMPS_14_RE_ARM_EFB, RAMPS_SMART_EFB, RAMPS_DUO_EFB, RAMPS4DUE_EFB)

Marlin/src/pins/stm32f4/pins_BTT_GTR_V1_0.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@
2323

2424
#include "env_validate.h"
2525

26-
#if HOTENDS > 8 || E_STEPPERS > 8
27-
#error "BIGTREE GTR V1.0 supports up to 8 hotends / E-steppers."
28-
#elif HOTENDS > MAX_E_STEPPERS || E_STEPPERS > MAX_E_STEPPERS
26+
#if E_STEPPERS > MAX_E_STEPPERS
2927
#error "Marlin extruder/hotends limit! Increase MAX_E_STEPPERS to continue."
28+
#elif HOTENDS > 8 || E_STEPPERS > 8
29+
#error "BIGTREE GTR V1.0 supports up to 8 hotends / E-steppers."
3030
#endif
3131

3232
#define BOARD_INFO_NAME "BTT GTR V1.0"

0 commit comments

Comments
 (0)