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.
It works quite well, fell free to check it out.
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.
It works quite well, fell free to check it out.
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:
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?
Thank you! I’m glad you find it interesting.
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:
make flash FLASH_DEVICE=/dev/serial/by-id/ID
python3 ~/katapult/scripts/flashtool.py -i can0 -f ~/klipper/out/klipper.bin -u e3e8e93f53df
make flash FLASH_DEVICE=/dev/serial/by-id/ID1
make flash FLASH_DEVICE=/dev/serial/by-id/ID2
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:
FLASH_MCU mcu=mcu_name
To flash all MCUs in sequence:
FLASH_MCU mcu=all
The stdout/stderr output will be displayed live in the console.
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
:
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
:
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.
No problems, happy to help.
Mainly for flashing klipper updates without the need to connect via SSH
Correct, you can even copy the whole ~/klipper/.config
file content there.
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.
[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.
FLASH_MCU mcu=all
in your client console.This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.