|
Prusa-MMU-Private
PrusaMultiMaterialUpgradev3firmwareforMK3SMK4
|
This is the new firmware for the Multi Material Unit (MMU).
The key motivation for developing a new firmware structure were as follows:
The whole firmware is composed of simple state machines which run all at once - it is a kind of simple cooperative multi-tasking while not eating up any significant resources by deploying generic task switching solutions like RTOS or similar. The general rule is to avoid waiting inside these state machines, no state machine is allowed to block execution of others. That implies making separate waiting states which only check for some condition to be true before proceeding further.
The firmware is separated into 4 layers:
The whole architecture becomes obvious from the following picture:
Sidenote: due to avr-gcc 5.4 limitations we cannot use proper Singleton patterns but have to rely on global variables of each state machine.
The communication protocol between the printer and the MMU has only been extended to minimize the influence on existing MMU interface implementation. However, the backwards compatibility has not been kept and at least some changes are necessary. The good news is that the Slicer's MMU code is fully backwards compatible.
There are several different types/sources of errors in the MMU:
For a list of currently supported error states please see error_codes.h .
Errors like this are abnormal operational states resulting from the fact, that some of the sensors didn't report an expected state. E.g. FINDA didn't trigger or the printer didn't send a trigger command from its filament sensor. These failures cannot be predicted and can be only resolved partially by the MMU.
The logic layer state machines check for these failures and act upon:
This kind of errors represents unhandled states of state machines - which should not happen ;) or at least the ocurrance can be mitigated by careful testing of the firmware code base. Logic layer state machines check their internal state and if they by chance get into an unhandled state, they switch into an error state INTERNAL.
This kind of errors is extremely hard to tackle in full scale. Basically any HW component can fail (including the HW chips on the mainboard) and we only have limited knowledge about such situations. So under hardware failures we consider only stuff which can be detected by any means
There are basically 2 ways of reporting an error to the user
The USART communication can report errors of the currently running command (see response to Q0).
LEDs' blinking is to be defined yet, the previous firmware used elaborate blinking schemes to report all kinds of errors which most users were unable to decipher/act upon.
The firmware architecture was designed with unit testing in mind, thus each firmware layer has only the least amount of necessary dependencies to surrounding code. This approach greatly simplified the definition of unit testing procedures with only a small amount stubs necessary.
Each firmware layer has its own subdirectory, the directory tree follows the firmware structure
The usage of stubs at each layer
Upon startup, the board tries to initialize all the necessary peripherals. The progress of initialization is visualized by individual LEDs turning green. That includes:
Ideally, the board has all the green LEDs on after startup - that signalizes all the peripherals started correctly.