# MCUs flashing from ui console

**URL:** <https://klipper.discourse.group/t/mcus-flashing-from-ui-console/18315>\
**Category:** Features\
**Created:** [August 16, 2024, 8:03pm UTC](https://klipper.discourse.group/t/mcus-flashing-from-ui-console/18315 "2024-08-16T20:03:02Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![damlobster](https://avatars.discourse-cdn.com/v4/letter/d/3bc359/32.png) [@damlobster](https://klipper.discourse.group/u/damlobster)\
**Post date:** [August 16, 2024, 8:03pm UTC](https://klipper.discourse.group/t/mcus-flashing-from-ui-console/18315/1 "2024-08-16T20:03:02Z")

</div>

Hello everyone,

I’ve created a simple Moonraker component that lets you flash MCUs directly using a G-code command.

You can find the source code here: [moonraker-mcu-flasher repo](https://github.com/juliapythoncpp/moonraker-mcu-flasher).

It works quite well, fell free to check it out.

 ![Mainsail console](https://global.discourse-cdn.com/free1/uploads/klipper/original/2X/e/eb972a164627e66a31d5c9d9f6d6fa570c697966.jpeg)

---

<div class="post-metadata">

**Author:** ![mykepredko](https://yyz2.discourse-cdn.com/free1/user_avatar/klipper.discourse.group/mykepredko/32/2085_2.png) [@mykepredko](https://klipper.discourse.group/u/mykepredko)\
**Post date:** [August 16, 2024, 8:29pm UTC](https://klipper.discourse.group/t/mcus-flashing-from-ui-console/18315/2 "2024-08-16T20:29:14Z")

</div>

This looks very cool.

I’d like to understand a bit more about it.

First, when you say “directly using a G-Code command”, I presume you’re talking about using the Mainsail/Fluidd console?

Or, are you talking about using G-Code “D5” which is:

 ![image](https://global.discourse-cdn.com/free1/uploads/klipper/original/2X/b/b373ac52353915445cd80e29e2434033a448f037.png)

Does Katapult or any other low-level/bootloader firmware need to be in place?

Finally, could you give some specific examples of the Console instructions?

---

<div class="post-metadata">

**Author:** ![damlobster](https://avatars.discourse-cdn.com/v4/letter/d/3bc359/32.png) [@damlobster](https://klipper.discourse.group/u/damlobster)\
**Post date:** [August 16, 2024, 9:13pm UTC](https://klipper.discourse.group/t/mcus-flashing-from-ui-console/18315/3 "2024-08-16T21:13:56Z")

</div>

Thank you! I’m glad you find it interesting.

### Configuration

The setup is done in the `moonraker.conf` file by adding `[mcu_flasher mcu_name]` sections. There are two required parameters:

- **kconfig** : Contains the `menuconfig` options for the specific `mcu_name`.

- **flash\_cmd** : These are the exact commands you would typically type in your SSH shell to flash the MCU.  
Some examples:

### Flashing

When I mentioned “flashing via a G-code command,” it was a bit misleading.

You need to add a Klipper macro to enable flashing. Then you can use the `FLASH_MCU` macro directly from the Mainsail/Fluidd console.

- To flash a specific MCU:

- To flash all MCUs in sequence:

The stdout/stderr output will be displayed live in the console.

---

<div class="post-metadata">

**Author:** ![mykepredko](https://yyz2.discourse-cdn.com/free1/user_avatar/klipper.discourse.group/mykepredko/32/2085_2.png) [@mykepredko](https://klipper.discourse.group/u/mykepredko)\
**Post date:** [August 16, 2024, 9:50pm UTC](https://klipper.discourse.group/t/mcus-flashing-from-ui-console/18315/4 "2024-08-16T21:50:53Z")

</div>

Sorry, I must be really thick but I need more information.

I get everything you’ve put up so far, but I have no idea of the workflow nor do I have a good handle on what’s required in terms of the setup.

Is this for the first time Flashing or for doing updates without having to get your hands dirty by going into SSH?

* * *

What are the `kconfig` options and what format are they in? Should they be poached from `~/klipper/.confg`:

```auto
CONFIG_BOARD_DIRECTORY="stm32"
CONFIG_MCU="stm32g0b1xx"
CONFIG_CLOCK_FREQ=64000000
CONFIG_USBSERIAL=y
CONFIG_FLASH_SIZE=0x20000
CONFIG_FLASH_BOOT_ADDRESS=0x8000000
CONFIG_RAM_START=0x20000000
CONFIG_RAM_SIZE=0x24000
CONFIG_STACK_SIZE=512
CONFIG_FLASH_APPLICATION_ADDRESS=0x8002000
CONFIG_STM32_SELECT=y

```

or the strings displayed in `make menuconfig`:

 ![image](https://global.discourse-cdn.com/free1/uploads/klipper/original/2X/5/584879c9286045f7d606f10f28dee11a99dcb245.png)

* * *

What is this Klipper macro that’s required to enable flashing? I’m guessing it’s called “FLASH\_MCU” but what does it consist of? I’m guessing it stops Klipper service and then restarts it when the klipper image build is complete?

* * *

Finally, what is the workflow? That will probably help me understand what you’re doing here.

Thanx.

---

<div class="post-metadata">

**Author:** ![damlobster](https://avatars.discourse-cdn.com/v4/letter/d/3bc359/32.png) [@damlobster](https://klipper.discourse.group/u/damlobster)\
**Post date:** [August 16, 2024, 10:38pm UTC](https://klipper.discourse.group/t/mcus-flashing-from-ui-console/18315/5 "2024-08-16T22:38:31Z")

</div>

No problems, happy to help.

> [@mykepredko](#):
>
> Is this for the first time Flashing or for doing updates without having to get your hands dirty by going into SSH?

Mainly for flashing klipper updates without the need to connect via SSH

> [@mykepredko](#):
>
> What are the `kconfig` options and what format are they in? Should they be poached from `~/klipper/.confg`

Correct, you can even copy the whole `~/klipper/.config` file content there.

> [@mykepredko](#):
>
> What is this Klipper macro that’s required to enable flashing? I’m guessing it’s called “FLASH\_MCU” but what does it consist of? I’m guessing it stops Klipper service and then restarts it when the klipper image build is complete?

The macro is pretty simple, it simply check that the printer is not currently printing, and then call the moonraker remote command provided by my component.

```ini
[gcode_macro FLASH_MCU]
description: Compile klipper and flash the MCU
gcode:
  {% set _mcu = params.MCU|string %}
  {% if printer.idle_timeout.state != "Printing" %}
    {action_call_remote_method("flash_mcu", mcu=_mcu)}
  {% else %}
    {action_respond_info("MCU flashing disabled during printing")}
  {% endif %}

```

Klipper enter the shutdown state as soon as the first mcu is flashed, but the flashing of the others mcus continue hopefully without errors. Then my component issue a `FIRMWARE_RESTART` at the end.

> [@mykepredko](#):
>
> Finally, what is the workflow? That will probably help me understand what you’re doing here.

1. you install and configure the component according the readme in the repo and your specific printer (I know the doc can be improved, an install.sh script created, …).
2. you update klipper with moonraker Update Manager
3. if needed/wanted: you flash all you MCUs by typing the command `FLASH_MCU mcu=all` in your client console.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/free1/uploads/klipper/original/1X/64419bf2aac6639e6ef5cef200dcd456b0a01ac3.png) [@system](https://klipper.discourse.group/u/system)\
**Post date:** [October 15, 2024, 10:38pm UTC](https://klipper.discourse.group/t/mcus-flashing-from-ui-console/18315/6 "2024-10-15T22:38:37Z")

</div>

Closed on October 15, 2024, 10:38pm UTC

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
