Skip to content

Update Prusa MMU3 #27719

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 20 commits into
base: bugfix-2.1.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Marlin/src/feature/mmu3/mmu3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -814,7 +814,7 @@ namespace MMU3 {
default: break;
}
break;
case Buttons::TuneMMU:
case Buttons::TuneMMU: // TODO: May go unutilized, but it's here for now
tune();
break;
case Buttons::Load:
Expand Down Expand Up @@ -1049,7 +1049,7 @@ namespace MMU3 {
lastErrorSource = res;
LogErrorEvent(PrusaErrorTitle(PrusaErrorCodeIndex(ec)));

if (ec != ErrorCode::OK && ec != ErrorCode::FILAMENT_EJECTED && ec != ErrorCode::FILAMENT_CHANGE) {
if (ec != ErrorCode::OK && ec != ErrorCode::FILAMENT_EJECTED) {
IncrementMMUFails();

// Check if it is a "power" failure. TMC-related errors are considered power failures.
Expand Down
75 changes: 29 additions & 46 deletions Marlin/src/feature/mmu3/mmu3_error_converter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ namespace MMU3 {

static ButtonOperations buttonSelectedOperation = ButtonOperations::NoOperation;

// we don't have a constexpr find_if in C++17/STL yet
// No constexpr find_if in C++17/STL so use our own
template <class InputIt, class UnaryPredicate>
constexpr InputIt find_if_cx(InputIt first, InputIt last, UnaryPredicate p) {
for (; first != last; ++first) {
Expand All @@ -46,25 +46,19 @@ namespace MMU3 {
return last;
}

// Making a constexpr FindError should instruct the compiler to optimize the
// PrusaErrorCodeIndex in such a way that no searching will ever be done at
// runtime. A call to FindError then compiles to a single instruction even on
// the AVR.
// static constexpr uint8_t FindErrorIndex(uint16_t pec) {
static uint8_t FindErrorIndex(uint16_t pec) {
constexpr uint16_t errorCodesSize = sizeof(errorCodes) / sizeof(errorCodes[0]);
// Find the error index statically to save on runtime overhead
static uint8_t FindErrorIndex(const uint16_t pec) {
constexpr uint16_t errorCodesSize = COUNT(errorCodes);
constexpr const auto *errorCodesEnd = errorCodes + errorCodesSize;
const auto *i = find_if_cx(errorCodes, errorCodesEnd, [pec](uint16_t ed) {
return ed == pec;
});
const auto *i = find_if_cx(errorCodes, errorCodesEnd, [pec](const uint16_t ed) { return ed == pec; });
return (i != errorCodesEnd) ? (i - errorCodes) : (errorCodesSize - 1);
}

// check that the searching algoritm works
// static_assert( FindErrorIndex(ERR_MECHANICAL_FINDA_DIDNT_TRIGGER) == 0);
// static_assert( FindErrorIndex(ERR_MECHANICAL_FINDA_FILAMENT_STUCK) == 1);
// static_assert( FindErrorIndex(ERR_MECHANICAL_FSENSOR_DIDNT_TRIGGER) == 2);
// static_assert( FindErrorIndex(ERR_MECHANICAL_FSENSOR_FILAMENT_STUCK) == 3);
// Check that the search algorithm works
//static_assert( FindErrorIndex(ERR_MECHANICAL_FINDA_DIDNT_TRIGGER) == 0);
//static_assert( FindErrorIndex(ERR_MECHANICAL_FINDA_FILAMENT_STUCK) == 1);
//static_assert( FindErrorIndex(ERR_MECHANICAL_FSENSOR_DIDNT_TRIGGER) == 2);
//static_assert( FindErrorIndex(ERR_MECHANICAL_FSENSOR_FILAMENT_STUCK) == 3);

constexpr ErrorCode operator&(ErrorCode a, ErrorCode b) {
return (ErrorCode)((uint16_t)a & (uint16_t)b);
Expand Down Expand Up @@ -92,8 +86,6 @@ namespace MMU3 {
return FindErrorIndex(ERR_MECHANICAL_LOAD_TO_EXTRUDER_FAILED);
case ErrorCode::FILAMENT_EJECTED:
return FindErrorIndex(ERR_SYSTEM_FILAMENT_EJECTED);
case ErrorCode::FILAMENT_CHANGE:
return FindErrorIndex(ERR_SYSTEM_FILAMENT_CHANGE);

case ErrorCode::STALLED_PULLEY:
case ErrorCode::MOVE_PULLEY_FAILED:
Expand Down Expand Up @@ -126,7 +118,7 @@ namespace MMU3 {
case ErrorCode::FINDA_VS_EEPROM_DISREPANCY:
return FindErrorIndex(ERR_SYSTEM_UNLOAD_MANUALLY);
case ErrorCode::MCU_UNDERVOLTAGE_VCC:
return FindErrorIndex(ERR_ELECTRICAL_MMU_MCU_ERROR);
return FindErrorIndex(ERR_ELECTRICAL_MMU_MCU_UNDERVOLTAGE_VCC);
default: break;
}

Expand Down Expand Up @@ -192,7 +184,7 @@ namespace MMU3 {
return FindErrorIndex(ERR_TEMPERATURE_TMC_IDLER_OVERHEAT_ERROR);
}

// if nothing got caught, return a generic runtime error
// If nothing got caught, return a generic runtime error
return FindErrorIndex(ERR_OTHER_UNKNOWN_ERROR);
}

Expand Down Expand Up @@ -237,7 +229,7 @@ namespace MMU3 {
case ERR_MECHANICAL_PULLEY_CANNOT_MOVE:
case ERR_SYSTEM_UNLOAD_MANUALLY:
switch (buttonSelectedOperation) {
// may be allow move selector right and left in the future
// Maybe allow move selector right and left in the future
case ButtonOperations::Retry: // "Repeat action"
return Buttons::Middle;
default:
Expand All @@ -247,10 +239,10 @@ namespace MMU3 {
case ERR_MECHANICAL_SELECTOR_CANNOT_HOME:
case ERR_MECHANICAL_IDLER_CANNOT_HOME:
switch (buttonSelectedOperation) {
// may be allow move selector right and left in the future
case ButtonOperations::Tune: // Tune Stallguard threshold
return Buttons::TuneMMU;
case ButtonOperations::Retry: // "Repeat action"
// Maybe allow move selector right and left in the future
//case ButtonOperations::Tune: // Tune Stallguard threshold
// return Buttons::TuneMMU; // Goes unused, possibility for future use
case ButtonOperations::Retry: // "Repeat action"
return Buttons::Middle;
default:
break;
Expand All @@ -259,29 +251,19 @@ namespace MMU3 {
case ERR_MECHANICAL_LOAD_TO_EXTRUDER_FAILED:
case ERR_SYSTEM_FILAMENT_EJECTED:
switch (buttonSelectedOperation) {
case ButtonOperations::Continue: // User solved the serious mechanical problem by hand - there is no other way around
case ButtonOperations::Continue: // User solved the serious mechanical problem by hand - there is no other way around
return Buttons::Middle;
default:
break;
}
break;
case ERR_SYSTEM_FILAMENT_CHANGE:
switch (buttonSelectedOperation) {
case ButtonOperations::Load:
return Buttons::Load;
case ButtonOperations::Eject:
return Buttons::Eject;
default:
break;
}
break;
case ERR_TEMPERATURE_WARNING_TMC_PULLEY_TOO_HOT:
case ERR_TEMPERATURE_WARNING_TMC_SELECTOR_TOO_HOT:
case ERR_TEMPERATURE_WARNING_TMC_IDLER_TOO_HOT:
switch (buttonSelectedOperation) {
case ButtonOperations::Continue: // "Continue"
case ButtonOperations::Continue: // "Continue"
return Buttons::Left;
case ButtonOperations::ResetMMU: // "Reset MMU"
case ButtonOperations::ResetMMU: // "Reset MMU"
return Buttons::ResetMMU;
default:
break;
Expand Down Expand Up @@ -314,9 +296,10 @@ namespace MMU3 {

case ERR_SYSTEM_QUEUE_FULL:
case ERR_SYSTEM_FW_RUNTIME_ERROR:
case ERR_ELECTRICAL_MMU_MCU_ERROR:
case ERR_ELECTRICAL_MMU_MCU_POWER_ERROR:
case ERR_ELECTRICAL_MMU_MCU_UNDERVOLTAGE_VCC:
switch (buttonSelectedOperation) {
case ButtonOperations::ResetMMU: // "Reset MMU"
case ButtonOperations::ResetMMU: // "Reset MMU"
return Buttons::ResetMMU;
default:
break;
Expand All @@ -326,19 +309,19 @@ namespace MMU3 {
case ERR_CONNECT_COMMUNICATION_ERROR:
case ERR_SYSTEM_FW_UPDATE_NEEDED:
switch (buttonSelectedOperation) {
case ButtonOperations::DisableMMU: // "Disable"
case ButtonOperations::DisableMMU: // "Disable"
return Buttons::DisableMMU;
case ButtonOperations::ResetMMU: // "ResetMMU"
case ButtonOperations::ResetMMU: // "ResetMMU"
return Buttons::ResetMMU;
default:
break;
}
break;
case ERR_SYSTEM_FILAMENT_ALREADY_LOADED:
switch (buttonSelectedOperation) {
case ButtonOperations::Unload: // "Unload"
case ButtonOperations::Unload: // "Unload"
return Buttons::Left;
case ButtonOperations::Continue: // "Proceed/Continue"
case ButtonOperations::Continue: // "Proceed/Continue"
return Buttons::Right;
default:
break;
Expand All @@ -347,9 +330,9 @@ namespace MMU3 {

case ERR_SYSTEM_INVALID_TOOL:
switch (buttonSelectedOperation) {
case ButtonOperations::StopPrint: // "Stop print"
case ButtonOperations::StopPrint: // "Stop print"
return Buttons::StopPrint;
case ButtonOperations::ResetMMU: // "Reset MMU"
case ButtonOperations::ResetMMU: // "Reset MMU"
return Buttons::ResetMMU;
default:
break;
Expand Down
18 changes: 9 additions & 9 deletions Marlin/src/feature/mmu3/mmu3_reporting.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@

namespace MMU3 {

enum CommandInProgress : uint8_t {
NoCommand = 0,
CutFilament = 'K',
EjectFilament = 'E',
Homing = 'H',
LoadFilament = 'L',
Reset = 'X',
ToolChange = 'T',
UnloadFilament = 'U',
enum CommandInProgress : unsigned char {
NoCommand = '\0',
CutFilament = 'K',
EjectFilament = 'E',
Homing = 'H',
LoadFilament = 'L',
Reset = 'X',
ToolChange = 'T',
UnloadFilament = 'U'
};

/**
Expand Down
7 changes: 4 additions & 3 deletions Marlin/src/feature/mmu3/mmu_hw/buttons.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,10 @@ enum class ButtonOperations : uint8_t {
Load = 5,
Eject = 6,
Tune = 7,
StopPrint = 8,
DisableMMU = 9,
MoreInfo = 10,
StopPrint = 5,
DisableMMU = 6,
Skip = 7,
MoreInfo = 8
};

// Button codes + extended actions performed on the printer's side
Expand Down
26 changes: 13 additions & 13 deletions Marlin/src/feature/mmu3/mmu_hw/check-pce.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,29 @@

# download Prusa Error Codes for MMU
#wget https://raw.githubusercontent.com/3d-gussner/Prusa-Error-Codes/master/04_MMU/error-codes.yaml --output-document=error-codes.yaml
wget https://raw.githubusercontent.com/prusa3d/Prusa-Error-Codes/master/04_MMU/error-codes.yaml --output-document=error-codes.yaml
wget https://raw.githubusercontent.com/prusa3d/Prusa-Error-Codes/master/yaml/mmu-error-codes.yaml --output-document=error-codes.yaml

oifs="$IFS" ## save original IFS
IFS=$'\n' ## set IFS to break on newline
codes=($(cat error-codes.yaml |grep "code:" |cut -d '"' -f2))
titles=($(cat error-codes.yaml |grep 'title:' |cut -d '"' -f2))
texts=($(cat error-codes.yaml |grep "text:" |cut -d '"' -f2))
actions=($(cat error-codes.yaml |grep "action:" |cut -d ':' -f2))
ids=($(cat error-codes.yaml |grep "id:" |cut -d '"' -f2))
codes=($(cat error-codes.yaml | grep "code:" | cut -d '"' -f2))
titles=($(cat error-codes.yaml | grep "title:" | cut -d '"' -f2))
texts=($(cat error-codes.yaml | grep "text:" | cut -d '"' -f2))
actions=($(cat error-codes.yaml | grep "action:" | cut -d ':' -f2))
ids=($(cat error-codes.yaml | grep "id:" | cut -d '"' -f2))
IFS="$oifs" ## restore original IFS

filename=errors_list.h

clear
for ((i = 0; i < ${#codes[@]}; i++)) do
code=${codes[i]}
id=$(cat $filename |grep "${code#04*}" | cut -d "=" -f1 | cut -d "_" -f3- |cut -d " " -f1)
title=$(cat $filename |grep "${id}" |grep --max-count=1 "MSG_TITLE" |cut -d '"' -f2)
text=$(cat $filename |grep "${id}" |grep --max-count=1 "MSG_DESC" |cut -d '"' -f2)
action1=$(cat $filename |grep "),//$id"| cut -d "," -f1)
action2=$(cat $filename |grep "),//$id"| cut -d "," -f2)
action1=$(echo $action1 | cut -d ":" -f2- |cut -d ":" -f2)
action2=$(echo $action2 | cut -d ":" -f2- |cut -d ":" -f2 |cut -d ")" -f1)
id=$(cat $filename | grep "${code#04*}" | cut -d "=" -f1 | cut -d "_" -f3- | cut -d " " -f1)
title=$(cat $filename | grep "${id}" | grep --max-count=1 "MSG_TITLE" | cut -d '"' -f2)
text=$(cat $filename | grep "${id}" | grep --max-count=1 "MSG_DESC" | cut -d '"' -f2)
action1=$(cat $filename | grep "),//$id"| cut -d "," -f1)
action2=$(cat $filename | grep "),//$id"| cut -d "," -f2)
action1=$(echo $action1 | cut -d ":" -f2- | cut -d ":" -f2)
action2=$(echo $action2 | cut -d ":" -f2- | cut -d ":" -f2 | cut -d ")" -f1)
if [ "$action2" == "NoOperation" ]; then
action=" [$action1]"
else
Expand Down
1 change: 0 additions & 1 deletion Marlin/src/feature/mmu3/mmu_hw/error_codes.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ enum class ErrorCode : uint_fast16_t {

MCU_UNDERVOLTAGE_VCC = 0x800D, //!< MCU VCC rail undervoltage.

FILAMENT_CHANGE = 0x8029, //!< E32809 internal error of the printer - try-load-unload sequence detected missing filament -> failed load into the nozzle
LOAD_TO_EXTRUDER_FAILED = 0x802A, //!< E32810 internal error of the printer - try-load-unload sequence detected missing filament -> failed load into the nozzle
QUEUE_FULL = 0x802B, //!< E32811 internal logic error - attempt to move with a full queue
VERSION_MISMATCH = 0x802C, //!< E32812 internal error of the printer - incompatible version of the MMU FW
Expand Down
Loading