# Bootloader aware Klipper MCU

**URL:** <https://klipper.discourse.group/t/bootloader-aware-klipper-mcu/89>\
**Category:** General Discussion\
**Created:** [April 4, 2021, 5:41pm UTC](https://klipper.discourse.group/t/bootloader-aware-klipper-mcu/89 "2021-04-04T17:41:57Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![revilo196](https://avatars.discourse-cdn.com/v4/letter/r/ed8c4c/32.png) [@revilo196](https://klipper.discourse.group/u/revilo196)\
**Post date:** [April 4, 2021, 5:41pm UTC](https://klipper.discourse.group/t/bootloader-aware-klipper-mcu/89/1 "2021-04-04T17:41:57Z")

</div>

Hi everyone,

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](https://electronics.stackexchange.com/questions/49411/is-can-bus-communications-enough-to-update-firmware)

Thanks, Klipper is AWESOME!

---

<div class="post-metadata">

**Author:** ![revilo196](https://avatars.discourse-cdn.com/v4/letter/r/ed8c4c/32.png) [@revilo196](https://klipper.discourse.group/u/revilo196)\
**Post date:** [April 5, 2021, 6:06pm UTC](https://klipper.discourse.group/t/bootloader-aware-klipper-mcu/89/2 "2021-04-05T18:06:21Z")

</div>

I’ve done some more research and experimentation.

And did come up with a proof of concept that works for my system using CANbus, using this bootloader [cvra can-bootloader](https://github.com/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?

My Code:  
[can-bootloader platform can-3d-tool](https://github.com/revilo196/can-bootloader)  
[my klipper changes](https://github.com/revilo196/klipper) (bootloader.py, stm32f103.c, stm32/Kconfig)

> **Example Usage**
>
> ![can_flash_example_eng](https://global.discourse-cdn.com/free1/uploads/klipper/original/1X/049238381dc9520ee69acec92b0e9d75fbcd2679.png)

---

<div class="post-metadata">

**Author:** ![revilo196](https://avatars.discourse-cdn.com/v4/letter/r/ed8c4c/32.png) [@revilo196](https://klipper.discourse.group/u/revilo196)\
**Post date:** [April 6, 2021, 7:24pm UTC](https://klipper.discourse.group/t/bootloader-aware-klipper-mcu/89/3 "2021-04-06T19:24:07Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![koconnor](https://avatars.discourse-cdn.com/v4/letter/k/aca169/32.png) [@koconnor](https://klipper.discourse.group/u/koconnor)\
**Post date:** [April 9, 2021, 3:03pm UTC](https://klipper.discourse.group/t/bootloader-aware-klipper-mcu/89/4 "2021-04-09T15:03:52Z")

</div>

Interesting. I can say there is interest in a CAN bootloader. I’m also aware that @Arksine put together a prototype for one - [GitHub - Arksine/CanBoot: Can Bootloader for Klipper MCUs](https://github.com/Arksine/CanBoot) .

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](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.)

-Kevin

---

<div class="post-metadata">

**Author:** ![NAPCAL](https://yyz2.discourse-cdn.com/free1/user_avatar/klipper.discourse.group/napcal/32/1794_2.png) [@NAPCAL](https://klipper.discourse.group/u/NAPCAL)\
**Post date:** [February 1, 2024, 2:18pm UTC](https://klipper.discourse.group/t/bootloader-aware-klipper-mcu/89/5 "2024-02-01T14:18:20Z")

</div>

@revilo196 as Kevin has posted, Katapult bootloader (formerly known as CanBoot) does this already. Kevin has aided in a lot of the code for Katapult.

Katapult can update itself and Klipper via the CAN bus, UART, or USB via it’s make menuconfig.

---

<div class="post-metadata">

**Author:** ![EddyMI3D](https://yyz2.discourse-cdn.com/free1/user_avatar/klipper.discourse.group/eddymi3d/32/1981_2.png) [@EddyMI3D](https://klipper.discourse.group/u/EddyMI3D)\
**Post date:** [February 1, 2024, 3:56pm UTC](https://klipper.discourse.group/t/bootloader-aware-klipper-mcu/89/6 "2024-02-01T15:56:25Z")

</div>

Do you think, I mean:

![grafik](https://global.discourse-cdn.com/free1/uploads/klipper/original/2X/4/4e8c3d8c04728cbb29b67421ef8780f25541863d.png)

---

<div class="post-metadata">

**Author:** ![NAPCAL](https://yyz2.discourse-cdn.com/free1/user_avatar/klipper.discourse.group/napcal/32/1794_2.png) [@NAPCAL](https://klipper.discourse.group/u/NAPCAL)\
**Post date:** [February 1, 2024, 4:10pm UTC](https://klipper.discourse.group/t/bootloader-aware-klipper-mcu/89/7 "2024-02-01T16:10:49Z")

</div>

Oops, it just popped up as a new conversation on mine.

---

<div class="post-metadata">

**Author:** ![EddyMI3D](https://yyz2.discourse-cdn.com/free1/user_avatar/klipper.discourse.group/eddymi3d/32/1981_2.png) [@EddyMI3D](https://klipper.discourse.group/u/EddyMI3D)\
**Post date:** [February 1, 2024, 5:49pm UTC](https://klipper.discourse.group/t/bootloader-aware-klipper-mcu/89/8 "2024-02-01T17:49:53Z")

</div>

No worries.

I close it then.

---

<div class="post-metadata">

**Author:** ![EddyMI3D](https://yyz2.discourse-cdn.com/free1/user_avatar/klipper.discourse.group/eddymi3d/32/1981_2.png) [@EddyMI3D](https://klipper.discourse.group/u/EddyMI3D)\
**Post date:** [February 1, 2024, 5:49pm UTC](https://klipper.discourse.group/t/bootloader-aware-klipper-mcu/89/9 "2024-02-01T17:49:57Z")

</div>


