mirror of
https://github.com/dw-0/kiauh.git
synced 2025-12-17 20:44:28 +05:00
feat(flashing): Flash RP2040 in Boot Mode (#580)
* feat(flashing): Flash RP2040 in Boot Mode * docs: add info about STM32 DFU and RP2040 boot modes
This commit is contained in:
@@ -90,6 +90,21 @@ def find_usb_dfu_device() -> List[str]:
|
|||||||
return []
|
return []
|
||||||
|
|
||||||
|
|
||||||
|
def find_usb_rp2_boot_device() -> List[str]:
|
||||||
|
try:
|
||||||
|
output = check_output("lsusb", shell=True, text=True, stderr=DEVNULL)
|
||||||
|
device_list = []
|
||||||
|
if output:
|
||||||
|
devices = output.splitlines()
|
||||||
|
device_list = [d.split(" ")[5] for d in devices if "RP2 Boot" in d]
|
||||||
|
return device_list
|
||||||
|
|
||||||
|
except CalledProcessError as e:
|
||||||
|
Logger.print_error("Unable to find a USB RP2 Boot device!")
|
||||||
|
Logger.print_error(e, prefix=False)
|
||||||
|
return []
|
||||||
|
|
||||||
|
|
||||||
def get_sd_flash_board_list() -> List[str]:
|
def get_sd_flash_board_list() -> List[str]:
|
||||||
if not KLIPPER_DIR.exists() or not SD_FLASH_SCRIPT.exists():
|
if not KLIPPER_DIR.exists() or not SD_FLASH_SCRIPT.exists():
|
||||||
return []
|
return []
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ class FlashCommand(Enum):
|
|||||||
class ConnectionType(Enum):
|
class ConnectionType(Enum):
|
||||||
USB = "USB"
|
USB = "USB"
|
||||||
USB_DFU = "USB (DFU)"
|
USB_DFU = "USB (DFU)"
|
||||||
|
USB_RP2040 = "USB (RP2040)"
|
||||||
UART = "UART"
|
UART = "UART"
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -143,6 +143,8 @@ class KlipperMcuConnectionHelpMenu(BaseMenu):
|
|||||||
count = 62 - len(color) - len(RESET_FORMAT)
|
count = 62 - len(color) - len(RESET_FORMAT)
|
||||||
subheader1 = f"{COLOR_CYAN}USB:{RESET_FORMAT}"
|
subheader1 = f"{COLOR_CYAN}USB:{RESET_FORMAT}"
|
||||||
subheader2 = f"{COLOR_CYAN}UART:{RESET_FORMAT}"
|
subheader2 = f"{COLOR_CYAN}UART:{RESET_FORMAT}"
|
||||||
|
subheader3 = f"{COLOR_CYAN}USB DFU:{RESET_FORMAT}"
|
||||||
|
subheader4 = f"{COLOR_CYAN}USB RP2040 Boot:{RESET_FORMAT}"
|
||||||
menu = textwrap.dedent(
|
menu = textwrap.dedent(
|
||||||
f"""
|
f"""
|
||||||
╔═══════════════════════════════════════════════════════╗
|
╔═══════════════════════════════════════════════════════╗
|
||||||
@@ -164,6 +166,19 @@ class KlipperMcuConnectionHelpMenu(BaseMenu):
|
|||||||
║ port your controller board is connected to when using ║
|
║ port your controller board is connected to when using ║
|
||||||
║ this connection method. ║
|
║ this connection method. ║
|
||||||
║ ║
|
║ ║
|
||||||
|
║ {subheader3:<62} ║
|
||||||
|
║ Selecting USB DFU as the connection method will scan ║
|
||||||
|
║ the USB ports for connected controller boards in ║
|
||||||
|
║ STM32 DFU mode, which is usually done by holding down ║
|
||||||
|
║ the BOOT button or setting a special jumper on the ║
|
||||||
|
║ board before powering up. ║
|
||||||
|
║ ║
|
||||||
|
║ {subheader4:<62} ║
|
||||||
|
║ Selecting USB RP2 Boot as the connection method will ║
|
||||||
|
║ scan the USB ports for connected RP2040 controller ║
|
||||||
|
║ boards in Boot mode, which is usually done by holding ║
|
||||||
|
║ down the BOOT button before powering up. ║
|
||||||
|
║ ║
|
||||||
╟───────────────────────────────────────────────────────╢
|
╟───────────────────────────────────────────────────────╢
|
||||||
"""
|
"""
|
||||||
)[1:]
|
)[1:]
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ from components.klipper_firmware.firmware_utils import (
|
|||||||
find_uart_device,
|
find_uart_device,
|
||||||
find_usb_device_by_id,
|
find_usb_device_by_id,
|
||||||
find_usb_dfu_device,
|
find_usb_dfu_device,
|
||||||
|
find_usb_rp2_boot_device,
|
||||||
get_sd_flash_board_list,
|
get_sd_flash_board_list,
|
||||||
start_flash_process,
|
start_flash_process,
|
||||||
)
|
)
|
||||||
@@ -177,6 +178,7 @@ class KlipperSelectMcuConnectionMenu(BaseMenu):
|
|||||||
"1": Option(method=self.select_usb),
|
"1": Option(method=self.select_usb),
|
||||||
"2": Option(method=self.select_dfu),
|
"2": Option(method=self.select_dfu),
|
||||||
"3": Option(method=self.select_usb_dfu),
|
"3": Option(method=self.select_usb_dfu),
|
||||||
|
"4": Option(method=self.select_usb_rp2040),
|
||||||
}
|
}
|
||||||
|
|
||||||
def print_menu(self) -> None:
|
def print_menu(self) -> None:
|
||||||
@@ -193,6 +195,7 @@ class KlipperSelectMcuConnectionMenu(BaseMenu):
|
|||||||
║ 1) USB ║
|
║ 1) USB ║
|
||||||
║ 2) UART ║
|
║ 2) UART ║
|
||||||
║ 3) USB (DFU mode) ║
|
║ 3) USB (DFU mode) ║
|
||||||
|
║ 4) USB (RP2040 mode) ║
|
||||||
╟───────────────────────────┬───────────────────────────╢
|
╟───────────────────────────┬───────────────────────────╢
|
||||||
"""
|
"""
|
||||||
)[1:]
|
)[1:]
|
||||||
@@ -210,6 +213,10 @@ class KlipperSelectMcuConnectionMenu(BaseMenu):
|
|||||||
self.flash_options.connection_type = ConnectionType.USB_DFU
|
self.flash_options.connection_type = ConnectionType.USB_DFU
|
||||||
self.get_mcu_list()
|
self.get_mcu_list()
|
||||||
|
|
||||||
|
def select_usb_rp2040(self, **kwargs):
|
||||||
|
self.flash_options.connection_type = ConnectionType.USB_RP2040
|
||||||
|
self.get_mcu_list()
|
||||||
|
|
||||||
def get_mcu_list(self, **kwargs):
|
def get_mcu_list(self, **kwargs):
|
||||||
conn_type = self.flash_options.connection_type
|
conn_type = self.flash_options.connection_type
|
||||||
|
|
||||||
@@ -222,6 +229,9 @@ class KlipperSelectMcuConnectionMenu(BaseMenu):
|
|||||||
elif conn_type is ConnectionType.USB_DFU:
|
elif conn_type is ConnectionType.USB_DFU:
|
||||||
Logger.print_status("Identifying MCU connected via USB in DFU mode ...")
|
Logger.print_status("Identifying MCU connected via USB in DFU mode ...")
|
||||||
self.flash_options.mcu_list = find_usb_dfu_device()
|
self.flash_options.mcu_list = find_usb_dfu_device()
|
||||||
|
elif conn_type is ConnectionType.USB_RP2040:
|
||||||
|
Logger.print_status("Identifying MCU connected via USB in RP2 Boot mode ...")
|
||||||
|
self.flash_options.mcu_list = find_usb_rp2_boot_device()
|
||||||
|
|
||||||
if len(self.flash_options.mcu_list) < 1:
|
if len(self.flash_options.mcu_list) < 1:
|
||||||
Logger.print_warn("No MCUs found!")
|
Logger.print_warn("No MCUs found!")
|
||||||
|
|||||||
Reference in New Issue
Block a user