From 6fde4bcc70bb31d6cefe3baaa1b9682ca6e5fbf1 Mon Sep 17 00:00:00 2001 From: lamauny Date: Sun, 12 Oct 2025 18:46:29 +0200 Subject: [PATCH 1/2] [ln882h] improve flash read speed by changing baudrate --- ltchiptool/soc/ln882h/flash.py | 5 +++-- ltchiptool/soc/ln882h/util/ln882htool.py | 11 +++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/ltchiptool/soc/ln882h/flash.py b/ltchiptool/soc/ln882h/flash.py index 95cb3be..beee7fc 100644 --- a/ltchiptool/soc/ln882h/flash.py +++ b/ltchiptool/soc/ln882h/flash.py @@ -14,8 +14,9 @@ "Connect UART1 of the LN882h to the USB-TTL adapter:", [ ("PC", "LN882h"), - ("RX", "TX1 (GPIOA2 / P2)"), - ("TX", "RX1 (GPIOA3 / P3)"), + ("RX", "TX0 (GPIOA2 / P2)"), + ("TX", "RX0 (GPIOA3 / P3)"), + ("GND", "BOOT (GPIOA9 / P9)"), ("", ""), ("GND", "GND"), ], diff --git a/ltchiptool/soc/ln882h/util/ln882htool.py b/ltchiptool/soc/ln882h/util/ln882htool.py index 99f5381..c038168 100644 --- a/ltchiptool/soc/ln882h/util/ln882htool.py +++ b/ltchiptool/soc/ln882h/util/ln882htool.py @@ -169,6 +169,7 @@ def flash_read( chunk_size: int = 256, # maximum supported chunk size ) -> Generator[bytes, None, None]: self.link() + prev_baudrate = self.s.baudrate if not self.ramcode: self.ram_boot() @@ -177,6 +178,10 @@ def flash_read( f"Chunk size {chunk_size} exceeds the maximum allowed (256)" ) + self.change_baudrate(LN882H_YM_BAUDRATE) + self.link() + self.push_timeout(0.02) + for start in range(offset, offset + length, chunk_size): count = min(start + chunk_size, offset + length) - start debug(f"Dumping bytes: start=0x{start:X}, count=0x{count:X}") @@ -186,10 +191,16 @@ def flash_read( valid, data = self.ym._verify_recv_checksum(True, data) if verify and not valid: + self.change_baudrate(prev_baudrate) + self.pop_timeout() raise RuntimeError(f"Invalid checksum") yield data + self.change_baudrate(prev_baudrate) + self.pop_timeout() + info("Flash Read Successful.") + def flash_write( self, offset: int, From 9f018dc3b95f059e8942896c699825df5fc9b3a4 Mon Sep 17 00:00:00 2001 From: lamauny Date: Sun, 12 Oct 2025 18:52:01 +0200 Subject: [PATCH 2/2] [ln882h] fix UART number in help tip --- ltchiptool/soc/ln882h/flash.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ltchiptool/soc/ln882h/flash.py b/ltchiptool/soc/ln882h/flash.py index beee7fc..57b4fc6 100644 --- a/ltchiptool/soc/ln882h/flash.py +++ b/ltchiptool/soc/ln882h/flash.py @@ -11,7 +11,7 @@ from .util.ln882htool import LN882hTool LN882H_GUIDE = [ - "Connect UART1 of the LN882h to the USB-TTL adapter:", + "Connect UART0 of the LN882h to the USB-TTL adapter:", [ ("PC", "LN882h"), ("RX", "TX0 (GPIOA2 / P2)"),