Are there some Ideas how to make Klipper bootloader aware? So the MCU could be send into Bootloader mode with a command from the Host device and than flashed without ever touching hardware in the System.
I’m currently working on a multi MCU system, all connected by an CANbus.
My MCU-Boards only use CAN to communicate, no UART or USB. Currently I have to remove every Board and connect it to an ST-Link programmer to flash a new firmware version.
I’m thinking about a custom bootloader that could flash via CAN. Similar to this first anwser
And did come up with a proof of concept that works for my system using CANbus, using this bootloader cvra can-bootloader with some custom adjustments to support my stm32F103 platform.
This is a 12k bootloader so I added an option to the klipper Kconfig file.
The bootloader waits 10s before starting application code. In this timeframe, I can now flash my Board over CAN (can-bootloader contains a flash client tool), but this works only 10s after a restart.
The next step for me was to make klipper firmware aware how to set the MCU into bootloader mode without timeout.
I added bootloader mcu command to klipper firmware that loads a magic+argument value into the beginning of the RAM and resets the MCU. This tells the bootloader to stay.
I also added a bootloader extra to klippy to enable this comand for a given MCU.
This is just a proof of concept for my project. This is my first time developing a part of klipper, advice is very welcome.
Are there similar bootloaders out there, that we could include?
How could this be integrated into klipper?
To build the Bootloader you have to also load the submodules.
git submodule update --init --recursive
and change the platform.c for your needs (CAN Pins and Oscillator settings)
Then follow the steps for build in the readme.markdown
Example klipper config for using can-bootloader
[mcu]
canbus_uuid=bc3974f09157
canbus_interface=can0
# This enables the BOOTLOADER MCU=mcu GCode to send the main mcu into can-bootloader without timeout
[bootloader mcu]
[mcu my_ctl2]
canbus_uuid=6a8c980354dd
canbus_interface=can0
# This enables the BOOTLOADER MCU=my_ctl2 GCode to send the mcu:my_ctl2 into can-bootloader without timeout
[bootloader my_ctl2]
Also see the can-bootloader/client readme to see how to send commands/firmware to the bootloader over CAN
There has also been some background discussions for a mechanism to enter the bootloader from Klipper. What was previously discussed was adding a CANbus command (as in https://www.klipper3d.org/CANBUS_protocol.html#admin-messages) to instruct Klipper to reboot into the bootloader. (The reason using a CANbus command vs a normal Klipper command was discussed was to make it easier for an external script to trigger the bootloader.)