The K1 MCU Flasher Management Script is a tool designed to manage firmware flashing and service configuration for microcontrollers used in Creality K1 devices. It simplifies the process of installing, uninstalling, and flashing firmware while providing options for bootloader mode, Klipper firmware building, and log viewing.
This script is specifically intended for use with the nozzle onboard MCU. In normal mode, it enforces the startup of Klipper on the MCU, which can help speed up the printer's initialization process by ensuring that Klipper on the MCU is ready before the main Klipper service starts on the SBC (Single Board Computer).
- Install and uninstall the MCU flasher service.
- Flash firmware files directly or through service mode.
- Enter bootloader mode for manual flashing.
- Build Klipper firmware with predefined or manual configurations.
- View logs for troubleshooting.
- Operating System: Linux-based systems (e.g., Ubuntu, Debian).
- Dependencies:
gitbuild-essentiallibncurses-devpython3
-
Clone the repository or download the script:
git clone https://github.com/your-repo/k1-mcu-flasher.git cd k1-mcu-flasher -
Run the script with appropriate options (see below).
./k1_mcu_flasher.sh [OPTION]| Option | Description |
|---|---|
--install |
Install the MCU Flasher service. |
--uninstall |
Uninstall the MCU Flasher service. |
--bootloader |
Enter bootloader mode for manual flashing. |
--flash FILE |
Flash a specific firmware file. |
--build-klipper |
Build Klipper firmware with predefined or manual configurations. |
--view-log |
View the last 50 lines of the MCU flasher log file. |
--help |
Display help information about script usage. |
To install the MCU Flasher service:
sudo ./k1_mcu_flasher.sh --installThis command will:
- Check for existing installations and handle them if found.
- Copy necessary files to system directories.
- Create a configuration file and prompt you to select an MCU port.
- Set up a systemd service that ensures Klipper starts on the nozzle onboard MCU before starting the main Klipper service on the SBC.
- Enable the service to run on system startup.
This setup ensures that your printer initializes faster and more reliably by guaranteeing that Klipper on the MCU is ready before communication with the SBC begins.
To flash a specific firmware file:
sudo ./k1_mcu_flasher.sh --flash /path/to/firmware.binThis command will:
- Verify that the specified firmware file exists.
- Extract and display the firmware version from the binary file.
- Prompt you to choose between two flashing modes:
- Bootloader Mode: Flash directly via a selected COM port.
- Service Mode: Update configuration and reboot to flash automatically.
For Bootloader Mode:
- Detect available COM ports and prompt you to select one.
- Stop any running Klipper services to avoid conflicts.
- Enter bootloader mode, upload the firmware, and restart Klipper if desired.
For Service Mode:
- Save the firmware path in the configuration file.
- Shut down your system, after which you must disconnect and reconnect power to complete flashing.
To enter bootloader mode for manual flashing:
sudo ./k1_mcu_flasher.sh --bootloaderThis command will:
- Update the configuration file to set "bootloader" as the current mode.
- Shut down your system safely.
- Prompt you to disconnect and reconnect power to enter bootloader mode.
This is useful when performing manual operations or troubleshooting issues with your MCU.
To build Klipper firmware:
sudo ./k1_mcu_flasher.sh --build-klipperThis command will:
- Check if required tools (
git,make) are installed. - Clone a custom Klipper repository from GitHub into a temporary build directory.
- Prompt you to select your GD32 microcontroller variant or configure manually using
menuconfig. - Compile Klipper firmware based on your selected configuration.
- Copy the resulting
klipper.binfile into your script directory for easy access. - Offer to flash this newly compiled firmware immediately.
This feature allows you to customize and build Klipper firmware tailored specifically for your device's hardware.
To view recent logs from the MCU Flasher service:
sudo ./k1_mcu_flasher.sh --view-logThis command will:
- Display the last 50 lines of logs from
/var/log/mcu_flasher.log. - Continuously show new log entries in real-time (using
tail -f).
This is helpful for debugging issues related to flashing or monitoring service activity.
To display help information about available options:
./k1_mcu_flasher.sh --helpThis command provides a summary of all available options, their descriptions, and usage examples.
- Always run this script with superuser privileges (
sudo) when performing installation or flashing operations. - After entering bootloader mode or flashing in service mode, disconnect and reconnect power to complete initialization.
- The script automatically detects available COM ports during installation and bootloader operations, simplifying port selection.
This script is open-source and distributed under the MIT License.
Feel free to modify it according to your needs!
# Instructions for mcu_tools.py
---
This utility is a pure Python implementation for flashing firmware on Creality K1 series printers (K1, K1C, K1 MAX). Designed to be fully compatible with the official mcu_util tool, it supports operations such as handshake initiation, firmware version retrieval, firmware updates, application startup, and even direct bootloader requests (requires a custom Klipper build).
- The bootloader waits for a handshake for 15 seconds after MCU power up.
- A handshake is required only once per session before performing any operation.
- For firmware flashing, ensure you power cycle the MCU before initiating the update or include the update command within your initialization script.
| Option | Description | Example Command |
|---|---|---|
-v, --verbose |
Enable debug output for detailed log messages. | mcu_util.py -v -c -i /dev/ttyS1 |
-c, --handshake |
Send a handshake signal (0x75) to the MCU. This step must be completed before any other operation. | mcu_util.py -c -i /dev/ttyS1 |
-i, --port |
Specify the serial device to connect to (this option is required). | -i /dev/ttyS1 |
-f, --file |
Provide the firmware file for the update process. | -f /usr/data/klipper/fw/K1/bed_klipper.bin |
-u, --update |
Update (flash) the firmware using the file provided with the -f option. |
mcu_util.py -c -i /dev/ttyS1 -u -f /path/to/firmware.bin |
-s, --appstart |
Attempt to start the firmware application if it has not already started. | mcu_util.py -c -i /dev/ttyS1 -s |
-g, --version |
Retrieve and display the combined hardware and firmware version information from the MCU. | mcu_util.py -c -i /dev/ttyS1 -g |
-r, --request-bootloader |
Request that the MCU enters bootloader mode. (custom Klipper build required). | mcu_util.py -r -i /dev/ttyS1 |
-b, --baud |
Set the serial baud rate for bootloader requests. The default baud rate is 230400. |
-b 230400 |
-
Initiate Handshake Only
Initiate communication with the MCU by sending the handshake signal (0x75). Once the handshake is confirmed, no further handshake is required during that session.mcu_util.py -c -i /dev/ttyS1
-
Retrieve Hardware and Firmware Version
Check the combined hardware and firmware version available on the MCU.mcu_util.py -c -i /dev/ttyS1 -g
-
Flash Firmware
Update the firmware after ensuring the MCU has been properly power cycled or the update command is placed in the initialization routine.mcu_util.py -c -i /dev/ttyS1 -u -f /usr/data/klipper/fw/K1/bed_klipper.bin
-
Start Firmware Application
If the firmware application hasn't started yet, use this command to trigger the startup process.mcu_util.py -c -i /dev/ttyS1 -s
-
Bootloader Request Feature
The-ror--request-bootloaderoption allows you to request that the MCU enters bootloader mode. This feature is useful for initiating the bootloader without needing to restart the printer.Important Note: This option is only supported in a special build of Klipper available at https://github.com/Fiddl3/klipper-creality-k1.
To use this feature:
- Specify the serial port with the
-iflag. - Optionally set a custom baud rate using the
-bflag (default is 230400).mcu_util.py -r -i /dev/ttyS1 -b 230400
- Specify the serial port with the
-
Handshake:
The tool initiates communication by sending a handshake byte (0x75) to the MCU. The bootloader will await this acknowledgment (also0x75) within 15 seconds of power-up. -
Version Retrieval:
A version request is sent (using the bytes0x00and0xff). The MCU responds with a 25-byte string (plus a CRC validation byte) that combines both hardware and firmware version details. -
Firmware Update Process:
- Sector Size Request: Retrieves the sector size, which is used as a multiplier for dividing the firmware into correctly sized chunks.
- Update Request: Sends a request (byte
0x01followed by0xfe) to initiate the flashing sequence, followed by the firmware file size and its corresponding CRC. - Firmware Transfer: The firmware is transmitted in chunks (each validated with a CRC) until the entire file is successfully flashed to the device.
-
Application Start:
A startup command (using the bytes0x02and0xfd) is sent to initiate the newly flashed firmware. The MCU validates this command via CRC before starting the application. -
Bootloader Request:
This feature is useful for initiating the bootloader without needing to restart the printer, the-roption requests that the MCU enters bootloader mode. Once the request is acknowledged, the script confirms the mode entry by re-initiating a handshake and version check.
This utility is provided under its applicable license. Use this tool at your own risk; the author is not liable for any damage or data loss due to improper use.
For additional information, troubleshooting, or contributions, please refer to the project repository or contact the maintainer.